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();
}
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;
}
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");
}
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();
}
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");
}
}
Aggregations