use of jetbrains.exodus.log.Log in project xodus by JetBrains.
the class BackgroundCleaningJob method execute.
@Override
protected void execute() throws Throwable {
final GarbageCollector gc = this.gc;
if (gc == null) {
return;
}
final BackgroundCleaner cleaner = gc.getCleaner();
if (!cleaner.isCurrentThread()) {
return;
}
try {
if (canContinue()) {
final long minTimeToInvokeCleaner = gc.getStartTime();
if (minTimeToInvokeCleaner > System.currentTimeMillis()) {
gc.wakeAt(minTimeToInvokeCleaner);
return;
}
final EnvironmentImpl env = gc.getEnvironment();
final EnvironmentConfig ec = env.getEnvironmentConfig();
final Log log = env.getLog();
if (gc.getMinFileAge() < log.getNumberOfFiles()) {
cleaner.setCleaning(true);
try {
doCleanLog(log, gc);
if (gc.isTooMuchFreeSpace()) {
final int gcRunPeriod = ec.getGcRunPeriod();
if (gcRunPeriod > 0) {
gc.wakeAt(System.currentTimeMillis() + gcRunPeriod);
}
}
} finally {
cleaner.setCleaning(false);
}
}
}
} finally {
gc.deletePendingFiles();
}
}
use of jetbrains.exodus.log.Log in project xodus by JetBrains.
the class BasePageMutable method save.
/**
* Save page to log
*
* @return address of this page after save
*/
protected long save() {
// save leaf nodes
ReclaimFlag flag = saveChildren();
// save self. complementary to {@link load()}
final byte type = getType();
final BTreeBase tree = getTree();
final int structureId = tree.structureId;
final Log log = tree.log;
if (flag == ReclaimFlag.PRESERVE) {
// there is a chance to update the flag to RECLAIM
if (log.getWrittenHighAddress() % log.getFileSize() == 0) {
// page will be exactly on file border
flag = ReclaimFlag.RECLAIM;
} else {
final ByteIterable[] iterables = getByteIterables(flag);
long result = log.tryWrite(type, structureId, new CompoundByteIterable(iterables));
if (result < 0) {
iterables[0] = CompressedUnsignedLongByteIterable.getIterable((size << 1) + ReclaimFlag.RECLAIM.value);
result = log.writeContinuously(type, structureId, new CompoundByteIterable(iterables));
if (result < 0) {
throw new TooBigLoggableException();
}
}
return result;
}
}
return log.write(type, structureId, new CompoundByteIterable(getByteIterables(flag)));
}
use of jetbrains.exodus.log.Log in project xodus by JetBrains.
the class EnvironmentRecoveryTest method testLastLoggableIncomplete13.
@Test
public void testLastLoggableIncomplete13() throws IOException {
Log log = env.getLog();
final long fileSize = env.getEnvironmentConfig().getLogFileSize() * 1024;
log.beginWrite();
for (int i = 0; i < fileSize; ++i) {
log.write(NullLoggable.create());
}
log.endWrite();
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull Transaction txn) {
env.openStore("new_store", StoreConfig.WITHOUT_DUPLICATES, txn);
}
});
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull Transaction txn) {
env.openStore("another_store", StoreConfig.WITHOUT_DUPLICATES, txn);
}
});
env.close();
writer.openOrCreateBlock(fileSize, 0);
writer.close();
// recovery pending
env = newEnvironmentInstance(LogConfig.create(reader, writer).setFileSize(env.getEnvironmentConfig().getLogFileSize()));
assertLoggableTypes(B, env.getLog().getLoggableIterator(0), SEQ);
}
use of jetbrains.exodus.log.Log in project xodus by JetBrains.
the class LogRecoveryTest method cutAndCheckLastLoggableIncomplete.
private void cutAndCheckLastLoggableIncomplete(int cutSize, int max) {
openStoreAutoCommit("new_store", StoreConfig.WITHOUT_DUPLICATES);
/*final Iterator<Loggable> itr = getLog().getLoggablesIterator(0);
while (itr.hasNext()) {
final Loggable next = itr.next();
System.out.println(next.getType() + " @ " + next.getAddress());
}*/
assertLoggableTypes(getLog(), 0, seq);
env.close();
final StreamCipherProvider cipherProvider = env.getCipherProvider();
final byte[] cipherKey = env.getCipherKey();
final long cipherBasicIV = env.getCipherBasicIV();
env = null;
final long size = reader.getBlock(0).length();
writer.openOrCreateBlock(0, size - cutSize);
writer.close();
// only 'max' first loggables should remain
final LogConfig config = LogConfig.create(reader, writer).setCipherProvider(cipherProvider).setCipherKey(cipherKey).setCipherBasicIV(cipherBasicIV);
final Log newLog = Environments.newLogInstance(config);
newLog.setHighAddress(newLog.getTip(), newLog.getTip().approvedHighAddress);
assertLoggableTypes(max, newLog.getLoggableIterator(0), seq);
}
use of jetbrains.exodus.log.Log in project xodus by JetBrains.
the class TreeBaseTest method createLog.
private void createLog() {
LogConfig config = createLogConfig();
config.setDir(tempFolder);
log = new Log(config);
}
Aggregations