Search in sources :

Example 1 with Log

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();
    }
}
Also used : Log(jetbrains.exodus.log.Log) EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) EnvironmentImpl(jetbrains.exodus.env.EnvironmentImpl)

Example 2 with Log

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)));
}
Also used : Log(jetbrains.exodus.log.Log) TooBigLoggableException(jetbrains.exodus.log.TooBigLoggableException) CompoundByteIterable(jetbrains.exodus.CompoundByteIterable) CompressedUnsignedLongByteIterable(jetbrains.exodus.log.CompressedUnsignedLongByteIterable) CompressedUnsignedLongArrayByteIterable(jetbrains.exodus.bindings.CompressedUnsignedLongArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) CompoundByteIterable(jetbrains.exodus.CompoundByteIterable)

Example 3 with Log

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);
}
Also used : Log(jetbrains.exodus.log.Log) Test(org.junit.Test)

Example 4 with Log

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);
}
Also used : Log(jetbrains.exodus.log.Log) StreamCipherProvider(jetbrains.exodus.crypto.StreamCipherProvider) LogConfig(jetbrains.exodus.log.LogConfig)

Example 5 with Log

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);
}
Also used : Log(jetbrains.exodus.log.Log) LogConfig(jetbrains.exodus.log.LogConfig)

Aggregations

Log (jetbrains.exodus.log.Log)10 Test (org.junit.Test)4 LogConfig (jetbrains.exodus.log.LogConfig)2 ByteIterable (jetbrains.exodus.ByteIterable)1 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)1 CompressedUnsignedLongArrayByteIterable (jetbrains.exodus.bindings.CompressedUnsignedLongArrayByteIterable)1 StreamCipherProvider (jetbrains.exodus.crypto.StreamCipherProvider)1 EnvironmentConfig (jetbrains.exodus.env.EnvironmentConfig)1 EnvironmentImpl (jetbrains.exodus.env.EnvironmentImpl)1 Store (jetbrains.exodus.env.Store)1 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)1 RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)1 TooBigLoggableException (jetbrains.exodus.log.TooBigLoggableException)1 ITree (jetbrains.exodus.tree.ITree)1 BTree (jetbrains.exodus.tree.btree.BTree)1 BTreeBalancePolicy (jetbrains.exodus.tree.btree.BTreeBalancePolicy)1 BTreeEmpty (jetbrains.exodus.tree.btree.BTreeEmpty)1 PatriciaTree (jetbrains.exodus.tree.patricia.PatriciaTree)1 PatriciaTreeEmpty (jetbrains.exodus.tree.patricia.PatriciaTreeEmpty)1 PatriciaTreeWithDuplicates (jetbrains.exodus.tree.patricia.PatriciaTreeWithDuplicates)1