Example #1
0
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);
}
Example #2
0
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);
}
Example #3
0
void AntiCacheDB::writeBlockNVM(const std::string tableName,
                             int16_t blockId,
                             const int tupleCount,
			     const char* data,
                             const long size)  {
   
  //int index = getFreeNVMBlockIndex();
  //char* block = getNVMBlock(index);
    char* block = getNVMBlock(m_totalBlocks); 
    memcpy(block, data, size);                      
   //m_NVMBlocks[m_totalBlocks] = new char[size]; 
   //memcpy(m_NVMBlocks[m_totalBlocks], data, size); 

    VOLT_INFO("Writing NVM Block: ID = %d, index = %d, size = %ld", blockId, m_totalBlocks, size); 
    m_blockMap.insert(std::pair<int16_t, std::pair<int, int32_t> >(blockId, std::pair<int, int32_t>(m_totalBlocks, static_cast<int32_t>(size))));
    m_totalBlocks++; 
}
Example #4
0
void NVMAntiCacheDB::writeBlock(const std::string tableName,
                                uint32_t blockId,
                                const int tupleCount,
                                const char* data,
                                const long size,
                                const int evictedTupleCount)  {
   
    VOLT_TRACE("free blocks: %d", getFreeBlocks());
    if (getFreeBlocks() == 0) {
        VOLT_WARN("No free space in ACID %d for blockid %u with blocksize %ld",
                m_ACID, blockId, size);
        throw FullBackingStoreException(((int32_t)m_ACID << 16) & blockId, 0);
    }
    uint32_t index = getFreeNVMBlockIndex();
    VOLT_TRACE("block index: %u", index);
    char* block = getNVMBlock(index); 
    long bufsize; 
    char* buffer = new char [tableName.size() + 1 + size];
    memset(buffer, 0, tableName.size() + 1 + size);
    bufsize = tableName.size() + 1;
    memcpy(buffer, tableName.c_str(), bufsize);
    memcpy(buffer + bufsize, data, size);
    bufsize += size;
    memcpy(block, buffer, bufsize); 
    delete[] buffer;

    VOLT_DEBUG("Writing NVM Block: ID = %u, index = %u, tupleCount = %d, size = %ld, tableName = %s",
            blockId, index, tupleCount, bufsize, tableName.c_str()); 

    m_blocksEvicted++;
    if (!isBlockMerge()) {
        tupleInBlock[blockId] = tupleCount;
        evictedTupleInBlock[blockId] = evictedTupleCount;
        blockSize[blockId] = bufsize;
        m_bytesEvicted += static_cast<int32_t>((int64_t)bufsize * evictedTupleCount / tupleCount);
    }
    else {
        m_bytesEvicted += static_cast<int32_t>(bufsize);
    }

    m_blockMap.insert(std::pair<uint32_t, std::pair<int, int32_t> >(blockId, std::pair<uint32_t, int32_t>(index, static_cast<int32_t>(bufsize))));
    m_monoBlockID++;
    
    // FIXME: I'm hacking!!!!!!!!!!!!!!!!!!!!!!!!!
    pushBlockLRU(blockId);
}