Ejemplo n.º 1
0
void Storage::DeleteData(HANDLE rDataFileHandle, LRUCache &rLRUCache, uint64 x, uint64 y)
{
    RecordIndexMap::accessor rWriteAccessor;
    if(m_dataIndexes.find(rWriteAccessor, x))
    {
        //update LRU
        rLRUCache.put(x);
        
        //check manager - load from disk if not in memory
        CheckBlockManager(rDataFileHandle, x, rWriteAccessor);
        
        //save memory usage before delete
        uint64 memoryUsageBeforeDelete = blman_get_memory_usage(rWriteAccessor->second.m_pBlockManager);
        
        //delete
        blman_delete_record_by_key(rWriteAccessor->second.m_pBlockManager, y);
        
        //update memory usage
        uint64 memoryUsageAfterDelete = blman_get_memory_usage(rWriteAccessor->second.m_pBlockManager);
        m_memoryUsed += (memoryUsageAfterDelete - memoryUsageBeforeDelete);
        
        //queue write to disk
        m_pDiskWriter->Queue(rWriteAccessor);
        
		//debug log
		Log.Debug(__FUNCTION__, "Deleted data [x:" I64FMTD ", y:" I64FMTD "]", x, y);
    }
}
Ejemplo n.º 2
0
void Storage::LoadFromDisk(const HANDLE &rDataFileHandle, LRUCache &rLRUCache, uint64 x)
{
    RecordIndexMap::accessor rWriteAccessor;
    if(m_dataIndexes.find(rWriteAccessor, x))
    {
        //update LRU
        rLRUCache.put(x);
        
        //check manager - load from disk if not in memory
        CheckBlockManager(rDataFileHandle, x, rWriteAccessor);
    }
}
Ejemplo n.º 3
0
void Storage::DefragmentData(HANDLE rDataFileHandle, LRUCache &rLRUCache, uint64 x)
{
    RecordIndexMap::accessor rWriteAccessor;
    if(m_dataIndexes.find(rWriteAccessor, x))
    {
        //update LRU
        rLRUCache.put(x);
        
        //check manager - load from disk if not in memory
        CheckBlockManager(rDataFileHandle, x, rWriteAccessor);
     
        //defragment
        DefragmentDataInternal(rWriteAccessor);
    }
}
Ejemplo n.º 4
0
void Storage::GetAllY(HANDLE rDataFileHandle, LRUCache &rLRUCache, uint64 x, bbuff *pY)
{
    RecordIndexMap::accessor rWriteAccessor;
    if(m_dataIndexes.find(rWriteAccessor, x))
    {
        //update LRU
        rLRUCache.put(x);
        
        //check manager - load from disk if not in memory
        CheckBlockManager(rDataFileHandle, x, rWriteAccessor);
        
        //read data
        blman_get_all_record_keys(rWriteAccessor->second.m_pBlockManager, pY);
    }
}
Ejemplo n.º 5
0
uint32 Storage::WriteData(HANDLE rDataFileHandle, LRUCache &rLRUCache, uint64 x, uint64 y, const uint8 *pRecord, uint16 recordSize)
{
    //ret value
    uint32 status;
    
    //write accesor
	RecordIndexMap::accessor rWriteAccesor;
    
    //update LRU
    rLRUCache.put(x);
    
    //try insert - returns false if record is existing
    if(m_dataIndexes.insert(rWriteAccesor, x))
    {
        //allocate blockmanager
        //create block manager + add new block for write + update num of blocks
        rWriteAccesor->second.m_pBlockManager = blman_create(NULL, 0);
        rWriteAccesor->second.m_blockCount = rWriteAccesor->second.m_pBlockManager->blockCount;
        
        //init index block
        rWriteAccesor->second.m_IB_blockNumber = 0;
        rWriteAccesor->second.m_IB_recordOffset = -1;
        //set flags to eRIF_RealocateBlocks
        rWriteAccesor->second.m_flags = eRIF_RelocateBlocks | eRIF_Dirty;
        //write data to block
        status = blman_write_record(rWriteAccesor->second.m_pBlockManager, y, pRecord, recordSize);
        
        //set record start to -1 (data are not written on disk)
        rWriteAccesor->second.m_recordStart = -1;
            
        //update memory usage
        uint64 blockManMemoryUsage = blman_get_memory_usage(rWriteAccesor->second.m_pBlockManager);
        m_memoryUsed += blockManMemoryUsage;
               
        //queue write to disk
        m_pDiskWriter->Queue(rWriteAccesor);
    }
	else
	{
        //now we have locked write access, just update data
        //check manager - load from disk if not in memory
        CheckBlockManager(rDataFileHandle, x, rWriteAccesor);
        
        //save memory usage before write
        uint64 memoryUsageBeforeWrite = blman_get_memory_usage(rWriteAccesor->second.m_pBlockManager);
        
        //try to write record
        status = blman_write_record(rWriteAccesor->second.m_pBlockManager, y, pRecord, recordSize);
        if(status == eBMS_FailRecordTooBig)
        {
            Log.Warning(__FUNCTION__, "Record [x:" I64FMTD ", y:" I64FMTD "] size: %u is too big, max record size is: %u.", x, y, recordSize, MAX_RECORD_SIZE);
        }
        else if(status & eBMS_OldRecord)
        {
            //update memory usage
            uint64 memoryUsageAfterWrite = blman_get_memory_usage(rWriteAccesor->second.m_pBlockManager);
            m_memoryUsed += (memoryUsageAfterWrite - memoryUsageBeforeWrite);
            
            //log warning
            Log.Warning(__FUNCTION__, "Record [x:" I64FMTD ", y:" I64FMTD "] size: %u attempt to save old y.", x, y, recordSize);
        }
        else if(status & eBMS_NeedDefrag)
        {
            //if data needs defrag
            //this function takes care about freespace, memory usage, disk writer, sets correct flags
            DefragmentDataInternal(rWriteAccesor);
        }
        else if(status & eBMS_ReallocatedBlocks)
        {
            if(!(rWriteAccesor->second.m_flags & eRIF_RelocateBlocks))
            {
                //set flag reallocate blocks so diskwrite must find new place for data
                rWriteAccesor->second.m_flags |= eRIF_RelocateBlocks;
            }
            
            //set dirty
            rWriteAccesor->second.m_flags |= eRIF_Dirty;
            
            //update memory usage
            uint64 memoryUsageAfterWrite = blman_get_memory_usage(rWriteAccesor->second.m_pBlockManager);
            m_memoryUsed += (memoryUsageAfterWrite - memoryUsageBeforeWrite);
            
            //queue write to disk
            m_pDiskWriter->Queue(rWriteAccesor);
        }
        else
        {
            //update memory usage
            uint64 memoryUsageAfterWrite = blman_get_memory_usage(rWriteAccesor->second.m_pBlockManager);
            m_memoryUsed += (memoryUsageAfterWrite - memoryUsageBeforeWrite);
            
            //queue write to disk
            m_pDiskWriter->Queue(rWriteAccesor);
        }
	}
    
    //log
    Log.Debug(__FUNCTION__, "Written data [x:" I64FMTD ", y:" I64FMTD "] size: %u with status: %u", x, y, recordSize, status);

    return status;
}