Example #1
0
void Storage::DeleteData(LRUCache &rLRUCache, uint64 x)
{
    RecordIndexMap::accessor rWriteAccessor;
    if(m_dataIndexes.find(rWriteAccessor, x))
    {
        //delete from LRU
        rLRUCache.remove(x);
        
        //queue delete from disk
        m_pDiskWriter->QueueIndexDeletetion(rWriteAccessor);
        
        //release memory
        if(rWriteAccessor->second.m_pBlockManager)
        {
            //update memory usage
            uint64 memoryUsage = blman_get_memory_usage(rWriteAccessor->second.m_pBlockManager);
            m_memoryUsed -= memoryUsage;
            
            //clean memory
            blman_destroy(rWriteAccessor->second.m_pBlockManager);
            rWriteAccessor->second.m_pBlockManager = NULL;
        }
        
        //delete from main map
        m_dataIndexes.erase(rWriteAccessor);

		//debug log
		Log.Debug(__FUNCTION__, "Deleted data x:" I64FMTD, x);
    }

	//erase from disk queue
	m_pDiskWriter->Remove(x);
}
Example #2
0
void Storage::CheckMemory(LRUCache &rLRUCache)
{
    uint64 xToDelete;
    RecordIndexMap::accessor rWriteAccessor;
    
    while(m_memoryUsed > g_cfg.MemoryLimit)
    {
        if(!rLRUCache.get(&xToDelete))
            break;
        
        //get record index
        if(m_dataIndexes.find(rWriteAccessor, xToDelete))
        {
            //check if record does not wait in disk thread
			if(rWriteAccessor->second.m_flags & eRIF_InDiskWriteQueue)
                return;
            
            //can be NULL
            if(rWriteAccessor->second.m_pBlockManager)
            {
                //log
                Log.Debug(__FUNCTION__, "Memory usage: " I64FMTD ", memory limit: " I64FMTD ", removing x: " I64FMTD " from memory.", m_memoryUsed.load(), g_cfg.MemoryLimit, xToDelete);
                
                //update memory usage
                uint64 memoryUsage = blman_get_memory_usage(rWriteAccessor->second.m_pBlockManager);
                m_memoryUsed -= memoryUsage;
                
                //clean memory
                blman_destroy(rWriteAccessor->second.m_pBlockManager);
                rWriteAccessor->second.m_pBlockManager = NULL;
            }
        }
        
        //delete from LRU
        if(rLRUCache.remove(xToDelete) == false)
        {
            Log.Warning(__FUNCTION__, "m_pLRUCache->remove(" I64FMTD ") == false", xToDelete);
        }
    }
}