public override TrinityErrorCode LoadCell(long cellId, out byte[] cellBuff) { int index, cellSize; byte * cellPtr = null; TrinityErrorCode eResult = CLocalMemoryStorage.CGetLockedCellInfo4LoadCell(cellId, out cellSize, out cellPtr, out index); if (eResult == TrinityErrorCode.E_CELL_NOT_FOUND) { cellBuff = new byte[0]; return(eResult); } cellBuff = new byte[cellSize]; Memory.Copy(cellPtr, 0, cellBuff, 0, cellSize); CLocalMemoryStorage.CReleaseCellLock(cellId, index); return(TrinityErrorCode.E_SUCCESS); }
public override TrinityErrorCode SaveCell(long cellId, byte[] buff) { #if _TWO_PHASE_CELL_MANIPULATION_ byte *cellPtr; int entryIndex; CGetLockedCellInfo4SaveCell(cellId, buff.Length, TrinityConfig.UndefinedCellType, out cellPtr, out entryIndex); Memory.Copy(buff, cellPtr, buff.Length); CReleaseCellLock(cellId, entryIndex); return(TrinityErrorCode.E_SUCCESS); #else fixed(byte *p = buff) { return(CLocalMemoryStorage.CSaveCell(cellId, p, buff.Length, ushort.MaxValue)); } #endif }
public override TrinityErrorCode SaveCell(long cellId, byte[] buff, int offset, int cellSize, ushort cellType) { #if _TWO_PHASE_CELL_MANIPULATION_ byte *cellPtr; int entryIndex; CGetLockedCellInfo4SaveCell(cellId, cellSize, cellType, out cellPtr, out entryIndex); Memory.Copy(buff, offset, cellPtr, cellSize); CReleaseCellLock(cellId, entryIndex); return(TrinityErrorCode.E_SUCCESS); #else fixed(byte *p = buff) { return(CLocalMemoryStorage.CSaveCell(cellId, p + offset, cellSize, cellType)); } #endif }
public bool Contains(long cellId) { TrinityErrorCode eResult = CLocalMemoryStorage.CContains(cellId); switch (eResult) { case TrinityErrorCode.E_CELL_FOUND: return(true); case TrinityErrorCode.E_DEADLOCK: throw new DeadlockException(); case TrinityErrorCode.E_CELL_NOT_FOUND: default: return(false); } }
public TrinityErrorCode LoadCell(long cellId, out byte[] cellBuff, out ushort cellType) { int index, cellSize; byte * cellPtr = null; TrinityErrorCode eResult = CLocalMemoryStorage.CGetLockedCellInfo4CellAccessor(cellId, out cellSize, out cellType, out cellPtr, out index); if (eResult == TrinityErrorCode.E_CELL_NOT_FOUND) { cellBuff = new byte[0]; cellType = StorageConfig.c_UndefinedCellType; return(eResult); } cellBuff = new byte[cellSize]; Memory.Copy(cellPtr, 0, cellBuff, 0, cellSize); CLocalMemoryStorage.CReleaseCellLock(cellId, index); return(TrinityErrorCode.E_SUCCESS); }
public override TrinityErrorCode AddCell(long cellId, byte *buff, int cellSize, ushort cellType) { #if _TWO_PHASE_CELL_MANIPULATION_ byte * cellPtr; int entryIndex; TrinityErrorCode eResult; if ((eResult = CGetLockedCellInfo4AddCell(cellId, cellSize, cellType, out cellPtr, out entryIndex)) == TrinityErrorCode.E_DUPLICATED_CELL) { return(eResult); } Memory.Copy(buff, offset, cellPtr, 0, cellSize); CReleaseCellLock(cellId, entryIndex); return(TrinityErrorCode.E_SUCCESS); #else return(CLocalMemoryStorage.CAddCell(cellId, buff, cellSize, cellType)); #endif }
public bool ResetStorage() { string path = WriteAheadLogFilePath; bool ret = CLocalMemoryStorage.CResetStorage(); ResetWriteAheadLog(path); try { StorageReset(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "StorageReset event handler: {0}", ex.ToString()); } return(ret); }
/// <summary> /// Resets local memory storage to the initial state. The content in the memory storage will be cleared. And the memory storage will be shrunk to the initial size. /// </summary> /// <returns>true if resetting succeeds; otherwise, false.</returns> public bool ResetStorage() { lock (m_lock) { if (TrinityErrorCode.E_SUCCESS != CSynchronizeStorageRoot()) { return(false); } RaiseStorageEvent(StorageBeforeReset, nameof(StorageBeforeReset)); bool ret = CLocalMemoryStorage.CResetStorage(); RaiseStorageEvent(StorageReset, nameof(StorageReset)); return(ret); } }
public override TrinityErrorCode UpdateCell(long cellId, byte *buff, int cellSize) { #if _TWO_PHASE_CELL_MANIPULATION_ byte * cellPtr; int entryIndex; TrinityErrorCode eResult; if ((eResult = CGetLockedCellInfo4UpdateCell(cellId, cellSize, out cellPtr, out entryIndex)) == TrinityErrorCode.E_CELL_NOT_FOUND) { return(eResult); } Memory.Copy(buff, cellPtr, cellSize); CReleaseCellLock(cellId, entryIndex); return(TrinityErrorCode.E_SUCCESS); #else return(CLocalMemoryStorage.CUpdateCell(cellId, buff, cellSize)); #endif }
/// <summary> /// Initializes the LocalStorage instance. /// </summary> public LocalMemoryStorage() { if (TrinityErrorCode.E_SUCCESS != CLocalMemoryStorage.CInitialize()) { //TODO more specific exception type throw new Exception(); } // Register built-in storage event handlers StorageLoaded += InitializeWriteAheadLogFile; StorageLoaded += LoadCellTypeSignatures; StorageSaved += CreateWriteAheadLogFile; StorageSaved += SaveCellTypeSignatures; StorageReset += ResetWriteAheadLog; InitializeWriteAheadLogFile(); Thread.MemoryBarrier(); initialized = true; }
/// <summary> /// Dumps the in-memory key-value store to disk files. /// </summary> /// <returns> /// TrinityErrorCode.E_SUCCESS if saving succeeds; /// Other error codes indicate a failure. /// </returns> public TrinityErrorCode SaveStorage() { lock (m_lock) { TrinityErrorCode ret = CSynchronizeStorageRoot(); if (TrinityErrorCode.E_SUCCESS != ret) { return(ret); } ret = CLocalMemoryStorage.CSaveStorage(); if (TrinityErrorCode.E_SUCCESS != ret) { return(ret); } ret = RaiseStorageEvent(StorageSaved, nameof(StorageSaved)); return(ret); } }
public bool LoadStorage() { bool ret = CLocalMemoryStorage.CLoadStorage(); //TODO WAL and cell type signatures should migrate to KVStore extensions. InitializeWriteAheadLogFile(); LoadCellTypeSignatures(); try { StorageLoaded(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "StorageLoaded event handler: {0}", ex.ToString()); } return(ret); }
/// <summary> /// Dumps the in-memory key-value store to disk files. /// </summary> /// <returns>true if saving succeeds; otherwise, false.</returns> public bool SaveStorage() { lock (m_lock) { if (TrinityErrorCode.E_SUCCESS != CSynchronizeStorageRoot()) { return(false); } RaiseStorageEvent(StorageBeforeSave, nameof(StorageBeforeSave)); bool ret = CLocalMemoryStorage.CSaveStorage(); if (ret) { RaiseStorageEvent(StorageSaved, nameof(StorageSaved)); } return(ret); } }
public byte *ResizeCell(long cell_id, int cellEntryIndex, int offset, int delta) { byte * cellPtr; TrinityErrorCode code = CLocalMemoryStorage.CResizeCell(cell_id, cellEntryIndex, offset, delta, out cellPtr); if (code == TrinityErrorCode.E_SUCCESS) { return(cellPtr); } string err_msg = "ResizeCell encountered an error."; if (code == TrinityErrorCode.E_NOMEM) { throw new OutOfMemoryException(err_msg); } if (code == TrinityErrorCode.E_INVALID_ARGUMENTS) { throw new ArgumentException(err_msg); } throw new Exception(err_msg); }
public bool SaveStorage() { bool ret = CLocalMemoryStorage.CSaveStorage(); if (ret) { CreateWriteAheadLogFile(); SaveCellTypeSignatures(); try { StorageSaved(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "StorageSaved event handler: {0}", ex.ToString()); } } return(ret); }
/// <summary> /// Dumps the in-memory key-value store to disk files. /// </summary> /// <returns>true if saving succeeds; otherwise, false.</returns> public bool SaveStorage() { lock (m_lock) { try { StorageBeforeSave(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "An error oucurred in the StorageBeforeSave event handler: {0}", ex.ToString()); } if (TrinityErrorCode.E_SUCCESS != CSynchronizeStorageRoot()) { return(false); } bool ret = CLocalMemoryStorage.CSaveStorage(); if (ret) { CreateWriteAheadLogFile(); SaveCellTypeSignatures(); try { StorageSaved(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "An error oucurred in the StorageSaved event handler: {0}", ex.ToString()); } } return(ret); } }
/// <summary> /// Loads Trinity key-value store from disk to main memory. /// </summary> /// <returns>true if loading succeeds; otherwise, false.</returns> public bool LoadStorage() { lock (m_lock) { try { StorageBeforeLoad(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "An error oucurred in the StorageBeforeLoad event handler: {0}", ex.ToString()); } if (TrinityErrorCode.E_SUCCESS != CSynchronizeStorageRoot()) { return(false); } bool ret = CLocalMemoryStorage.CLoadStorage(); //TODO WAL and cell type signatures should migrate to KVStore extensions. InitializeWriteAheadLogFile(); LoadCellTypeSignatures(); try { StorageLoaded(); } catch (Exception ex) { Log.WriteLine(LogLevel.Error, "An error oucurred in the StorageLoaded event handler: {0}", ex.ToString()); } return(ret); } }
private ulong _CommitIndexMemoryWrapper() { return(CLocalMemoryStorage.CMTHashCommittedMemorySize()); }
private ulong _CommitTrunkMemoryWrapper() { return(CLocalMemoryStorage.CTrunkCommittedMemorySize()); }
internal TrinityErrorCode GetTrinityImageSignature(TRINITY_IMAGE_SIGNATURE *pSignature) { return(CLocalMemoryStorage.CGetTrinityImageSignature(pSignature)); }
public TrinityErrorCode SaveCell(LocalTransactionContext tx, CellAccessOptions writeAheadLogOptions, long cellId, byte *buff, int cellSize, ushort cellType) { TrinityErrorCode eResult = CLocalMemoryStorage.TxCLoggedSaveCell(tx.m_pctx, cellId, buff, cellSize, cellType, writeAheadLogOptions); return(eResult); }
public TrinityErrorCode AddCell(CellAccessOptions writeAheadLogOptions, long cellId, byte *buff, int cellSize) { TrinityErrorCode eResult = CLocalMemoryStorage.CLoggedAddCell(cellId, buff, cellSize, StorageConfig.c_UndefinedCellType, writeAheadLogOptions); return(eResult); }
public TrinityErrorCode UpdateCell(CellAccessOptions writeAheadLogOptions, long cellId, byte *buff, int cellSize) { TrinityErrorCode eResult = CLocalMemoryStorage.CLoggedUpdateCell(cellId, buff, cellSize, writeAheadLogOptions); return(eResult); }
private unsafe void _update_write_ahead_log_file(string path, void *fp) { m_logfile = fp; m_logfile_path = path; CLocalMemoryStorage.CSetWriteAheadLogFile(fp); }
public unsafe static void CWriteAheadLog(long cellId, byte *cellPtr, int cellSize, ushort cellType, CellAccessOptions options) { CLocalMemoryStorage.CWriteAheadLog(cellId, cellPtr, cellSize, cellType, options); }
public TrinityErrorCode AddCell(CellAccessOptions writeAheadLogOptions, long cellId, byte *buff, int offset, int cellSize, ushort cellType) { TrinityErrorCode eResult = CLocalMemoryStorage.CLoggedAddCell(cellId, buff + offset, cellSize, cellType, writeAheadLogOptions); return(eResult); }
private ulong _TotalCommittedMemoryWrapper() { return(CLocalMemoryStorage.CTotalCommittedMemorySize()); }
public TrinityErrorCode RemoveCell(CellAccessOptions writeAheadLogOptions, long cellId) { TrinityErrorCode eResult = CLocalMemoryStorage.CLoggedRemoveCell(cellId, writeAheadLogOptions); return(eResult); }
private ulong _TotalCellSizeWrapper() { return(CLocalMemoryStorage.CTotalCellSize()); }
public byte *ResizeCell(long cell_id, int cellEntryIndex, int offset, int delta) { return(CLocalMemoryStorage.CResizeCell(cell_id, cellEntryIndex, offset, delta)); }