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); }
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); }