Search in sources :

Example 6 with Log

use of jetbrains.exodus.log.Log in project xodus by JetBrains.

the class GarbageCollectorTest method reclaimTreeWithRootInLastFile.

@Test
public void reclaimTreeWithRootInLastFile() {
    set1KbFileWithoutGC();
    final Log log = env.getLog();
    final long startAddress = createStore("store", 100);
    Assert.assertEquals(2, log.getNumberOfFiles());
    createStore("corrupted", 160);
    Assert.assertEquals(4, log.getNumberOfFiles());
    final long fileAddress = 2 * log.getFileSize() * LogUtil.LOG_BLOCK_ALIGNMENT;
    log.forgetFile(fileAddress);
    log.removeFile(fileAddress);
    final StoreImpl store = openStoreAutoCommit("store");
    final Iterator<RandomAccessLoggable> itr = log.getLoggableIterator(startAddress);
    final TransactionBase txn = env.beginTransaction();
    Assert.assertTrue(txn.getTree(store).getMutableCopy().reclaim(itr.next(), itr));
    txn.abort();
}
Also used : Log(jetbrains.exodus.log.Log) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 7 with Log

use of jetbrains.exodus.log.Log in project xodus by JetBrains.

the class StoreImpl method openImmutableTree.

ITree openImmutableTree(@NotNull final MetaTree metaTree) {
    final int structureId = getStructureId();
    final long upToDateRootAddress = metaTree.getRootAddress(structureId);
    final boolean hasDuplicates = metaInfo.hasDuplicates();
    final boolean treeIsEmpty = upToDateRootAddress == Loggable.NULL_ADDRESS;
    final Log log = environment.getLog();
    final ITree result;
    if (!metaInfo.isKeyPrefixing()) {
        final BTreeBalancePolicy balancePolicy = environment.getBTreeBalancePolicy();
        result = treeIsEmpty ? new BTreeEmpty(log, balancePolicy, hasDuplicates, structureId) : new BTree(log, balancePolicy, upToDateRootAddress, hasDuplicates, structureId);
    } else {
        if (treeIsEmpty) {
            result = new PatriciaTreeEmpty(log, structureId, hasDuplicates);
        } else {
            result = hasDuplicates ? new PatriciaTreeWithDuplicates(log, upToDateRootAddress, structureId) : new PatriciaTree(log, upToDateRootAddress, structureId);
        }
    }
    return result;
}
Also used : PatriciaTree(jetbrains.exodus.tree.patricia.PatriciaTree) BTreeBalancePolicy(jetbrains.exodus.tree.btree.BTreeBalancePolicy) Log(jetbrains.exodus.log.Log) BTree(jetbrains.exodus.tree.btree.BTree) BTreeEmpty(jetbrains.exodus.tree.btree.BTreeEmpty) ITree(jetbrains.exodus.tree.ITree) PatriciaTreeEmpty(jetbrains.exodus.tree.patricia.PatriciaTreeEmpty) PatriciaTreeWithDuplicates(jetbrains.exodus.tree.patricia.PatriciaTreeWithDuplicates)

Example 8 with Log

use of jetbrains.exodus.log.Log in project xodus by JetBrains.

the class GarbageCollectorInterleavingTest method testSimple.

@Test
public void testSimple() throws InterruptedException {
    set1KbFileWithoutGC();
    final Log log = env.getLog();
    final long fileSize = log.getFileSize() * 1024;
    fill("updateSameKey");
    Assert.assertEquals(1L, log.getNumberOfFiles());
    fill("updateSameKey");
    // but ends in second one
    Assert.assertEquals(2L, log.getNumberOfFiles());
    fill("another");
    // make cleaning of second file possible
    Assert.assertEquals(3L, log.getNumberOfFiles());
    // clean second file
    env.getGC().doCleanFile(fileSize);
    Thread.sleep(300);
    env.getGC().testDeletePendingFiles();
    // half of tree written out from second file
    Assert.assertEquals(3L, log.getNumberOfFiles());
    // clean first file
    env.getGC().doCleanFile(0);
    Thread.sleep(300);
    env.getGC().testDeletePendingFiles();
    // first file contained only garbage
    Assert.assertEquals(2L, log.getNumberOfFiles());
    check("updateSameKey");
    check("another");
}
Also used : Log(jetbrains.exodus.log.Log) Test(org.junit.Test)

Example 9 with Log

use of jetbrains.exodus.log.Log in project xodus by JetBrains.

the class GarbageCollectorLowCacheTest method collectExpiredPageWithKeyAddressPointingToDeletedFile.

@Test
public void collectExpiredPageWithKeyAddressPointingToDeletedFile() throws IOException, InterruptedException {
    /**
     * o. low cache, small file size
     * 1. create tree IP->BP(N1),BP(N2)
     * 2. save a lot of updates to last key of BP(N2),
     *    so ther're a lot of files with expired version of BP(N2) and
     *    links to min key of BP(N2), that was saved in a very first file
     * 3. clean first file, with min key of BP(N2)
     * 4. clean second file with expired version of BP(N2) and link to min key in removed file
     */
    printDiskUsage();
    set1KbFileWithoutGC();
    env.getEnvironmentConfig().setTreeMaxPageSize(16);
    env.getEnvironmentConfig().setMemoryUsage(0);
    reopenEnvironment();
    Store store = openStoreAutoCommit("duplicates", getConfig());
    putAutoCommit(store, IntegerBinding.intToEntry(1), StringBinding.stringToEntry("value1"));
    putAutoCommit(store, IntegerBinding.intToEntry(2), StringBinding.stringToEntry("value2"));
    putAutoCommit(store, IntegerBinding.intToEntry(3), StringBinding.stringToEntry("value3"));
    putAutoCommit(store, IntegerBinding.intToEntry(4), StringBinding.stringToEntry("value4"));
    putAutoCommit(store, IntegerBinding.intToEntry(5), StringBinding.stringToEntry("value5"));
    putAutoCommit(store, IntegerBinding.intToEntry(6), StringBinding.stringToEntry("value6"));
    for (int i = 0; i < 1000; ++i) {
        putAutoCommit(store, IntegerBinding.intToEntry(6), StringBinding.stringToEntry("value6"));
    }
    final Log log = getLog();
    final GarbageCollector gc = getEnvironment().getGC();
    final long highFileAddress = log.getHighFileAddress();
    long fileAddress = log.getLowAddress();
    while (fileAddress != highFileAddress) {
        gc.doCleanFile(fileAddress);
        fileAddress = log.getNextFileAddress(fileAddress);
        gc.testDeletePendingFiles();
    }
    printDiskUsage();
}
Also used : Log(jetbrains.exodus.log.Log) Store(jetbrains.exodus.env.Store) Test(org.junit.Test)

Example 10 with Log

use of jetbrains.exodus.log.Log in project xodus by JetBrains.

the class CleanWholeLogJob method execute.

@Override
protected void execute() throws Throwable {
    info("CleanWholeLogJob started");
    try {
        final Log log = gc.getLog();
        long lastNumberOfFiles = Long.MAX_VALUE;
        long numberOfFiles;
        // repeat cleaning until number of files stops decreasing
        while ((numberOfFiles = log.getNumberOfFiles()) != 1 && numberOfFiles < lastNumberOfFiles) {
            lastNumberOfFiles = numberOfFiles;
            final long highFileAddress = log.getHighFileAddress();
            long fileAddress = log.getLowAddress();
            while (fileAddress != highFileAddress) {
                gc.doCleanFile(fileAddress);
                fileAddress = log.getNextFileAddress(fileAddress);
            }
            gc.testDeletePendingFiles();
        }
    } finally {
        release();
        info("CleanWholeLogJob finished");
    }
}
Also used : Log(jetbrains.exodus.log.Log)

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