use of org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo in project bookkeeper by apache.
the class IndexPersistenceMgrTest method testGetFileInfoWriteBeforeRead.
@Test
public void testGetFileInfoWriteBeforeRead() throws Exception {
IndexPersistenceMgr indexPersistenceMgr = null;
try {
indexPersistenceMgr = createIndexPersistenceManager(1);
CachedFileInfo writeFileInfo = indexPersistenceMgr.getFileInfo(lid, masterKey);
assertEquals(2, writeFileInfo.getRefCount());
assertEquals(1, indexPersistenceMgr.writeFileInfoCache.size());
assertEquals(0, indexPersistenceMgr.readFileInfoCache.size());
writeFileInfo.release();
CachedFileInfo readFileInfo = indexPersistenceMgr.getFileInfo(lid, null);
assertEquals(3, readFileInfo.getRefCount());
assertEquals(1, indexPersistenceMgr.writeFileInfoCache.size());
assertEquals(1, indexPersistenceMgr.readFileInfoCache.size());
readFileInfo.release();
assertEquals(2, writeFileInfo.getRefCount());
assertEquals(2, readFileInfo.getRefCount());
} finally {
if (null != indexPersistenceMgr) {
indexPersistenceMgr.close();
}
}
}
use of org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo in project bookkeeper by apache.
the class IndexPersistenceMgrTest method testGetFileInfoReadBeforeWrite.
@Test
public void testGetFileInfoReadBeforeWrite() throws Exception {
IndexPersistenceMgr indexPersistenceMgr = null;
try {
indexPersistenceMgr = createIndexPersistenceManager(1);
// get the file info for read
try {
indexPersistenceMgr.getFileInfo(lid, null);
fail("Should fail get file info for reading if the file doesn't exist");
} catch (Bookie.NoLedgerException nle) {
// exepcted
}
assertEquals(0, indexPersistenceMgr.writeFileInfoCache.size());
assertEquals(0, indexPersistenceMgr.readFileInfoCache.size());
CachedFileInfo writeFileInfo = indexPersistenceMgr.getFileInfo(lid, masterKey);
assertEquals(2, writeFileInfo.getRefCount());
assertEquals(1, indexPersistenceMgr.writeFileInfoCache.size());
assertEquals(0, indexPersistenceMgr.readFileInfoCache.size());
writeFileInfo.release();
assertEquals(1, writeFileInfo.getRefCount());
} finally {
if (null != indexPersistenceMgr) {
indexPersistenceMgr.close();
}
}
}
use of org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo in project bookkeeper by apache.
the class IndexPersistenceMgrTest method testEvictBeforeReleaseRace.
@Test
public void testEvictBeforeReleaseRace() throws Exception {
IndexPersistenceMgr indexPersistenceMgr = null;
Watcher<LastAddConfirmedUpdateNotification> watcher = notification -> notification.recycle();
try {
indexPersistenceMgr = createIndexPersistenceManager(1);
indexPersistenceMgr.getFileInfo(1L, masterKey);
indexPersistenceMgr.getFileInfo(2L, masterKey);
indexPersistenceMgr.getFileInfo(3L, masterKey);
indexPersistenceMgr.getFileInfo(4L, masterKey);
CachedFileInfo fi = indexPersistenceMgr.getFileInfo(1L, masterKey);
// trigger eviction
indexPersistenceMgr.getFileInfo(2L, masterKey);
indexPersistenceMgr.getFileInfo(3L, null);
indexPersistenceMgr.getFileInfo(4L, null);
Thread.sleep(1000);
fi.setFenced();
fi.release();
assertTrue(indexPersistenceMgr.isFenced(1));
} finally {
if (null != indexPersistenceMgr) {
indexPersistenceMgr.close();
}
}
}
use of org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo in project bookkeeper by apache.
the class LedgerCacheTest method testLedgerCacheFlushFailureOnDiskFull.
/**
* Test Ledger Cache flush failure.
*/
@Test
public void testLedgerCacheFlushFailureOnDiskFull() throws Exception {
File ledgerDir1 = createTempDir("bkTest", ".dir");
File ledgerDir2 = createTempDir("bkTest", ".dir");
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setLedgerDirNames(new String[] { ledgerDir1.getAbsolutePath(), ledgerDir2.getAbsolutePath() });
Bookie bookie = new Bookie(conf);
InterleavedLedgerStorage ledgerStorage = ((InterleavedLedgerStorage) bookie.ledgerStorage);
LedgerCacheImpl ledgerCache = (LedgerCacheImpl) ledgerStorage.ledgerCache;
// Create ledger index file
ledgerStorage.setMasterKey(1, "key".getBytes());
CachedFileInfo fileInfo = ledgerCache.getIndexPersistenceManager().getFileInfo(Long.valueOf(1), null);
// Add entries
ledgerStorage.addEntry(generateEntry(1, 1));
ledgerStorage.addEntry(generateEntry(1, 2));
ledgerStorage.flush();
ledgerStorage.addEntry(generateEntry(1, 3));
// add the dir to failed dirs
bookie.getIndexDirsManager().addToFilledDirs(fileInfo.getLf().getParentFile().getParentFile().getParentFile());
File before = fileInfo.getLf();
// flush after disk is added as failed.
ledgerStorage.flush();
File after = fileInfo.getLf();
assertFalse("After flush index file should be changed", before.equals(after));
// Verify written entries
Assert.assertEquals(generateEntry(1, 1), ledgerStorage.getEntry(1, 1));
Assert.assertEquals(generateEntry(1, 2), ledgerStorage.getEntry(1, 2));
Assert.assertEquals(generateEntry(1, 3), ledgerStorage.getEntry(1, 3));
}
use of org.apache.bookkeeper.bookie.FileInfoBackingCache.CachedFileInfo in project bookkeeper by apache.
the class IndexPersistenceMgrTest method testReadFileInfoCacheEviction.
@Test
public void testReadFileInfoCacheEviction() throws Exception {
IndexPersistenceMgr indexPersistenceMgr = null;
try {
indexPersistenceMgr = createIndexPersistenceManager(1);
for (int i = 0; i < 3; i++) {
CachedFileInfo fileInfo = indexPersistenceMgr.getFileInfo(lid + i, masterKey);
// We need to make sure index file is created, otherwise the test case can be flaky
fileInfo.checkOpen(true);
fileInfo.release();
// load into read cache also
indexPersistenceMgr.getFileInfo(lid + i, null).release();
}
indexPersistenceMgr.getFileInfo(lid, masterKey);
assertEquals(1, indexPersistenceMgr.writeFileInfoCache.size());
assertEquals(2, indexPersistenceMgr.readFileInfoCache.size());
// trigger file info eviction on read file info cache
for (int i = 1; i <= 2; i++) {
indexPersistenceMgr.getFileInfo(lid + i, null);
}
assertEquals(1, indexPersistenceMgr.writeFileInfoCache.size());
assertEquals(2, indexPersistenceMgr.readFileInfoCache.size());
CachedFileInfo fileInfo = indexPersistenceMgr.writeFileInfoCache.asMap().get(lid);
assertNotNull(fileInfo);
assertEquals(2, fileInfo.getRefCount());
fileInfo = indexPersistenceMgr.writeFileInfoCache.asMap().get(lid + 1);
assertNull(fileInfo);
fileInfo = indexPersistenceMgr.writeFileInfoCache.asMap().get(lid + 2);
assertNull(fileInfo);
fileInfo = indexPersistenceMgr.readFileInfoCache.asMap().get(lid);
assertNull(fileInfo);
fileInfo = indexPersistenceMgr.readFileInfoCache.asMap().get(lid + 1);
assertNotNull(fileInfo);
assertEquals(2, fileInfo.getRefCount());
fileInfo = indexPersistenceMgr.readFileInfoCache.asMap().get(lid + 2);
assertNotNull(fileInfo);
assertEquals(2, fileInfo.getRefCount());
} finally {
if (null != indexPersistenceMgr) {
indexPersistenceMgr.close();
}
}
}
Aggregations