AntiCacheBlock AntiCacheDB::readBlockBerkeleyDB(std::string tableName, int16_t blockId) { Dbt key; key.set_data(&blockId); key.set_size(sizeof(int16_t)); Dbt value; value.set_flags(DB_DBT_MALLOC); VOLT_DEBUG("Reading evicted block with id %d", blockId); int ret_value = m_db->get(NULL, &key, &value, 0); if (ret_value != 0) { VOLT_ERROR("Invalid anti-cache blockId '%d' for table '%s'", blockId, tableName.c_str()); throw UnknownBlockAccessException(tableName, blockId); } else { // m_db->del(NULL, &key, 0); // if we have this the benchmark won't end assert(value.get_data() != NULL); } AntiCacheBlock block(blockId, static_cast<char*>(value.get_data()), value.get_size()); return (block); }
AntiCacheBlock AntiCacheDB::readBlockNVM(std::string tableName, int16_t blockId) { std::map<int16_t, std::pair<int, int32_t> >::iterator itr; itr = m_blockMap.find(blockId); if (itr == m_blockMap.end()) { VOLT_INFO("Invalid anti-cache blockId '%d' for table '%s'", blockId, tableName.c_str()); VOLT_ERROR("Invalid anti-cache blockId '%d' for table '%s'", blockId, tableName.c_str()); throw UnknownBlockAccessException(tableName, blockId); } int blockIndex = itr->second.first; // VOLT_INFO("Reading NVM block: ID = %d, index = %d, size = %ld.", blockId, blockIndex, itr->second.second); char* block_ptr = getNVMBlock(blockIndex); char* block = new char[itr->second.second]; memcpy(block, block_ptr, itr->second.second); AntiCacheBlock anticache_block(blockId, block, itr->second.second); freeNVMBlock(blockId); m_blockMap.erase(itr); return (anticache_block); }
AntiCacheBlock* NVMAntiCacheDB::readBlock(uint32_t blockId, bool isMigrate) { std::map<uint32_t, std::pair<uint32_t, int32_t> >::iterator itr; itr = m_blockMap.find(blockId); if (itr == m_blockMap.end()) { VOLT_INFO("Invalid anti-cache blockId '%u'", blockId); VOLT_ERROR("Invalid anti-cache blockId '%u'", blockId); //throw UnknownBlockAccessException(tableName, blockId); throw UnknownBlockAccessException(blockId); } uint32_t blockIndex = itr->second.first; int blockSize = itr->second.second; char* block_ptr = getNVMBlock(blockIndex); char* block = new char[blockSize]; memcpy(block, block_ptr, blockSize); VOLT_DEBUG("Reading NVM block: ID = %u, index = %u, size = %d, isMigrate = %d, data = %s", blockId, blockIndex, blockSize, isMigrate, block); AntiCacheBlock* anticache_block = new NVMAntiCacheBlock(blockId, block, blockSize); if (this->isBlockMerge()) { freeNVMBlock(blockIndex); m_blockMap.erase(itr); //FIXME: I'm hacking!!!!!!!!!!!!!!!!!!!!!!!!! removeBlockLRU(blockId); m_bytesUnevicted += blockSize; m_blocksUnevicted++; } else { if (isMigrate) { freeNVMBlock(blockIndex); m_blockMap.erase(itr); removeBlockLRU(blockId); m_bytesUnevicted += static_cast<int32_t>( (int64_t)blockSize - blockSize / tupleInBlock[blockId] * (tupleInBlock[blockId] - evictedTupleInBlock[blockId])); m_blocksUnevicted++; } else { m_bytesUnevicted += static_cast<int32_t>( blockSize / tupleInBlock[blockId]); evictedTupleInBlock[blockId]--; // FIXME: I'm hacking!!!!!!!!!!!!!!!!!!!!!!!!! if (rand() % 100 == 0) { removeBlockLRU(blockId); pushBlockLRU(blockId); } } } return (anticache_block); }