Skip to end of metadata
Go to start of metadata

The STSdb heap system is responsible for managing database space – space allocation, deallocation etc.

STSdb 4.0 has a replaceable heap system. The engine can work with any IHeap implementation:

    IStorageEngine engine = STSdb.FromHeap(heap);

The IHeap interface definition is simple:

public interface IHeap
{
    /// <summary>
    /// Register new handle. The returned handle must be always unique.
    /// </summary>
    long ObtainNewHandle();
    /// <summary>
    /// Release the allocated space behind the handle.
    /// </summary>
    void Release(long handle);
    /// <summary>
    /// Is there such handle in the heap
    /// </summary>
    bool Exists(long handle);
    /// <summary>
    /// Write data with the specified handle
    /// </summary>
    void Write(long handle, byte[] buffer, int index, int count);
    /// <summary>
    /// Read the current data behind the handle
    /// </summary>
    byte[] Read(long handle);
    /// <summary>
    /// Atomic commit ALL changes in the heap (all or nothing).
    /// </summary>
    void Commit();
    /// <summary>
    /// Close the heap and release any resources
    /// </summary>
    void Close();
    /// <summary>
    /// Small user data (usually less than one physical sector), atomic written with the Commit()
    /// </summary>
    byte[] Tag { get; set; }
    /// <summary>
    /// Total size in bytes of the user data
    /// </summary>
    long DataSize { get; }
    /// <summary>
    /// Total size in bytes of the heap.
    /// </summary>
    long HeapSize { get; }
}

The engine uses the heap implementation to store its tree nodes. The idea behind the interface is obvious – each IHeap implementation must provide functionality for writing and reading of blocks of data referenced by logical keys (handles). After sequence of writes and reads made by the engine, the heap must also provide the opportunity to commit all the changes (all or nothing). The engine expects that the heap implementation is also thread-safe.

The heap implementation can rely on the fact that the majority of blocks created by the engine are with relatively large size (> 2MB).

The current STSdb 4.0 heap system provides a default heap implementation (the Heap class). It can be created over any seekable stream:

    IHeap heap = new Heap(stream);
    IStorageEngine engine = STSdb.FromHeap(heap);

Thus, with the provided stream implementation the developer can have the needed behavior - database partitioning, backup strategies, data encodings etc. The default heap implementation does not provide any special behaviour – it is created over a simple FileStream/MemoryStream instance.

Memory Usage    Go to Home    RemoteHeap

  • No labels