Class AbstractBlockBasedDataStore

  • All Implemented Interfaces:
    DataStore, LinkedDataStore
    Direct Known Subclasses:
    BlockBasedDataStore, JournalingBlockBasedDataStore

    public abstract class AbstractBlockBasedDataStore
    extends AbstractDataStore
    Block-based data store with journal support

    Implements a mix between a block-based file system structure and a doubly-linked list.

    Disk layout of the allocation table :

      blockCount               | 4 bytes (int)     | Number of blocks in store
      blockSize                | 4 bytes (int)     | Size of a storage block
      firstClusterIndex        | 4 bytes (int)     | Index of the first block
      allocationTable  (*blockCount allocation entries)
          flags                | 1 byte            | Flags indicating the block usage
          allocatedSize        | 4 bytes (int)     | Size of the actual data stored in this block
          previousClusterIndex | 4 bytes (int)     | Index of the previous block
          nextClusterIndex     | 4 bytes (int)     | Index of the next block
     

    Disk layout of the data store :

      blocks (*blockCount blocks of size blockSize)
     

    Computing a block offset from its index :
    blockOffset = blockIndex*blockSize

    • Field Detail

      • AT_HEADER_BLOCKCOUNT_OFFSET

        public static final int AT_HEADER_BLOCKCOUNT_OFFSET
        See Also:
        Constant Field Values
      • AT_HEADER_FIRSTBLOCK_OFFSET

        protected static final int AT_HEADER_FIRSTBLOCK_OFFSET
        See Also:
        Constant Field Values
      • blockSize

        protected int blockSize
      • blockCount

        protected int blockCount
      • flags

        protected byte[] flags
      • allocatedSize

        protected int[] allocatedSize
      • nextBlock

        protected int[] nextBlock
      • previousBlock

        protected int[] previousBlock
      • firstBlock

        protected int firstBlock
      • allocationTableFile

        protected File allocationTableFile
      • dataFile

        protected File dataFile
      • allocationTableRandomAccessFile

        protected RandomAccessFile allocationTableRandomAccessFile
    • Method Detail

      • next

        public final int next​(int handle)
                       throws DataStoreException
        Description copied from interface: LinkedDataStore
        Get the next data handle after the given one
        Parameters:
        handle - block handle
        Returns:
        the next entry handle or -1 if their is no successor
        Throws:
        DataStoreException
      • previous

        public final int previous​(int handle)
                           throws DataStoreException
        Description copied from interface: LinkedDataStore
        Get the previous data handle after the given one
        Parameters:
        handle - block handle
        Returns:
        the previous entry handle or -1 if their is no predecessor
        Throws:
        DataStoreException
      • size

        public final int size()
        Description copied from interface: DataStore
        Get the number of entries in the store
      • delete

        public final int delete​(int handle)
                         throws DataStoreException
        Description copied from interface: LinkedDataStore
        Delete data associated to the given handle from the store
        Returns:
        the previous handle or -1
        Throws:
        DataStoreException - on storage error or invalid handle
      • store

        public final int store​(Object obj,
                               int previousHandle)
                        throws DataStoreException
        Description copied from interface: LinkedDataStore
        Put some data under in the store after the previous handle data
        previousHandle - previous entry handle, use 0 if the store is empty
        Throws:
        DataStoreException
      • close

        public void close()
        Description copied from interface: DataStore
        Close the store releasing associated system resources
      • integrityCheck

        protected void integrityCheck()
                               throws DataStoreException
        Run an integrity check on the store files and fix them as necessary
        Throws:
        DataStoreException - if the files could not be fixed
      • getBlockSize

        public final int getBlockSize()
      • writeDataBlock

        protected abstract void writeDataBlock​(byte[] data,
                                               int offset,
                                               int len,
                                               int blockHandle)
                                        throws DataStoreException
        Write a data block to disk
        Throws:
        DataStoreException
      • readDataBlock

        protected abstract void readDataBlock​(byte[] data,
                                              int offset,
                                              int len,
                                              int blockHandle)
                                       throws DataStoreException
        Read a data block to disk
        Throws:
        DataStoreException
      • extendStoreFiles

        protected abstract void extendStoreFiles​(int oldBlockCount,
                                                 int newBlockCount)
                                          throws DataStoreException
        Extend the store files to newBlockCount
        Throws:
        DataStoreException
      • serializeAllocationBlock

        protected final byte[] serializeAllocationBlock​(int blockIndex)
        Serialize allocation block at index blockIndex
        Parameters:
        blockIndex - the block index
        Returns:
        the serialized allocation block
      • getStoreUsage

        public final int getStoreUsage()
        Description copied from interface: DataStore
        Get the store usage amount (%) (Ratio of used space over currently allocated space)
      • getAbsoluteStoreUsage

        public int getAbsoluteStoreUsage()
        Description copied from interface: DataStore
        Get the absolute store usage amount (%) (Ratio of used space over maximum allocatable space)