コード例 #1
0
TEST_F(AntiCacheDBTest, BerkeleyReadBlock) {
    // This will create a tempdir that will automatically be cleaned up
    ChTempDir tempdir;

    AntiCacheDB* anticache = new BerkeleyAntiCacheDB(NULL, ".", BLOCK_SIZE, MAX_SIZE);

    string tableName("FAKE");
    string payload("Test Read");
    uint16_t blockId = anticache->nextBlockId();
	anticache->writeBlock(tableName,
						 blockId,
						 1,
						 const_cast<char*>(payload.data()),
						 static_cast<int>(payload.size())+1);

	AntiCacheBlock* block = anticache->readBlock(blockId);

	ASSERT_EQ(block->getTableName(), tableName);
	ASSERT_EQ(block->getBlockId(), blockId);
	ASSERT_EQ(0, payload.compare(block->getData()));
	long expected_size = payload.size()+1;
	ASSERT_EQ(block->getSize(), expected_size);
    delete block;
    delete anticache;
}
コード例 #2
0
TEST_F(AntiCacheEvictionManagerTest, MigrateBlock) {
    ChTempDir tempdir;

    string temp = tempdir.name();

    ExecutorContext* ctx = m_engine->getExecutorContext();
    ctx->setAntiCacheLevels(2);

    AntiCacheEvictionManager* acem = new AntiCacheEvictionManager(m_engine);
    AntiCacheDB* nvmdb = new NVMAntiCacheDB(ctx, temp, BLOCK_SIZE, MAX_SIZE);
    AntiCacheDB* berkeleydb = new BerkeleyAntiCacheDB(ctx, temp, BLOCK_SIZE, MAX_SIZE);
    nvmdb->setBlockMerge(true);
    berkeleydb->setBlockMerge(true);

    int16_t nvm_acid = acem->addAntiCacheDB(nvmdb);
    int16_t berkeley_acid = acem->addAntiCacheDB(berkeleydb);
    
    ASSERT_EQ(nvm_acid, nvmdb->getACID());
    ASSERT_EQ(berkeley_acid, berkeleydb->getACID());
    ASSERT_EQ(0, nvm_acid);
    ASSERT_EQ(1, berkeley_acid);

    string tableName("TEST");
    string payload("Test payload");

    int32_t blockId = nvmdb->nextBlockId();
    nvmdb->writeBlock(tableName,
        blockId,
        1,
        const_cast<char*>(payload.data()),
        static_cast<int>(payload.size())+1,
        1);

    //int32_t fullBlockId = (nvm_acid << 16) | blockId;
    //VOLT_INFO("acid: %x, blockId: %x fullBlockId: %x\n", nvm_acid, blockId, fullBlockId);
    
    int32_t newBlockId = (int32_t) acem->migrateBlock(blockId, berkeleydb);
    int32_t _new_block_id = (int16_t) (newBlockId & 0x0000FFFF);
    VOLT_INFO("blockId: %x newBlockId: %x _new_block_id: %x", blockId, newBlockId, _new_block_id);
    AntiCacheBlock* berkeleyblock = berkeleydb->readBlock(_new_block_id, 1);
    VOLT_INFO("tableName: %s berkeleyblock name: %s", tableName.c_str(), berkeleyblock->getTableName().c_str());
    
    ASSERT_EQ(_new_block_id, berkeleyblock->getBlockId());
    ASSERT_EQ(payload.size()+1, berkeleyblock->getSize());
    ASSERT_EQ(0, tableName.compare(berkeleyblock->getTableName()));
    ASSERT_EQ(0, payload.compare(berkeleyblock->getData()));
    
    delete berkeleyblock;

    string tableNameLRU("LRU Table");
    string payloadLRU("LRU Test payload");

    VOLT_DEBUG("migrating LRU block..."); 
    
    int32_t blockIdLRU = nvmdb->nextBlockId();
    nvmdb->writeBlock(tableNameLRU,
        blockIdLRU,
        1,
        const_cast<char*>(payloadLRU.data()),
        static_cast<int>(payloadLRU.size())+1,
        1);

    blockId = nvmdb->nextBlockId();
    nvmdb->writeBlock(tableName,
        blockId,
        1,
        const_cast<char*>(payload.data()),
        static_cast<int>(payload.size())+1,
        1);
    
    newBlockId = (int32_t)acem->migrateLRUBlock(nvmdb, berkeleydb);
    
    _new_block_id = (int32_t) (newBlockId & 0x0FFFFFFF);

    berkeleyblock = berkeleydb->readBlock(_new_block_id, 1);
    VOLT_INFO("tableName: %s berkeleyblock name: %s\n", tableName.c_str(), berkeleyblock->getTableName().c_str());
    
    ASSERT_EQ(_new_block_id, berkeleyblock->getBlockId());
    ASSERT_EQ(payloadLRU.size()+1, berkeleyblock->getSize());
    ASSERT_EQ(0, payloadLRU.compare(berkeleyblock->getData()));
    
 
    //delete ctx;
    //delete nvmblock;
    delete berkeleyblock;
    delete berkeleydb;
    delete nvmdb;
    delete acem;
}