Class FileBlock<K extends>

  • Type Parameters:
    K - the key type of its partitions.
    All Implemented Interfaces:

    public final class FileBlock<K extends>
    extends java.lang.Object
    implements Block<K>
    This class represents a block which is stored in (local or remote) file. Concurrent read is supported, but concurrent write is not supported.
    • Constructor Detail

      • FileBlock

        public FileBlock​(java.lang.String blockId,
                         Serializer serializer,
                         java.lang.String filePath,
                         FileMetadata<K> metadata,
                         MemoryPoolAssigner memoryPoolAssigner)
        blockId - the ID of this block.
        serializer - the Serializer.
        filePath - the path of the file that this block will be stored.
        metadata - the metadata for this block.
        memoryPoolAssigner - the MemoryPoolAssigner for memory allocation.
    • Method Detail

      • write

        public void write​(K key,
                          java.lang.Object element)
        Writes an element to non-committed block. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.
        Specified by:
        write in interface Block<K extends>
        key - the key.
        element - the element to write.
        BlockWriteException - for any error occurred while trying to write a block.
      • readPartitions

        public java.lang.Iterable<NonSerializedPartition<K>> readPartitions​(KeyRange keyRange)
        Retrieves the partitions of this block from the file in a specific key range and deserializes it.
        Specified by:
        readPartitions in interface Block<K extends>
        keyRange - the key range.
        an iterable of NonSerializedPartitions.
        BlockFetchException - for any error occurred while trying to fetch a block.
      • asFileAreas

        public java.util.List<FileArea> asFileAreas​(KeyRange keyRange)
        Retrieves the list of FileAreas for the specified KeyRange.
        keyRange - the key range
        list of the file areas
        Throws: - if failed to open a file channel
      • deleteFile

        public void deleteFile()
        Deletes the file that contains this block data. This method have to be called after all read is completed (or failed).
        Throws: - if failed to delete.
      • commit

        public java.util.Optional<java.util.Map<K,​java.lang.Long>> commit()
        Commits this block to prevent further write.
        Specified by:
        commit in interface Block<K extends>
        the size of each partition.
        BlockWriteException - for any error occurred while trying to write a block.
      • commitPartitions

        public void commitPartitions()
        Commits all un-committed partitions. The committed partitions will be flushed to the storage.
        Specified by:
        commitPartitions in interface Block<K extends>
      • getId

        public java.lang.String getId()
        Specified by:
        getId in interface Block<K extends>
        the ID of this block.
      • isCommitted

        public boolean isCommitted()
        Specified by:
        isCommitted in interface Block<K extends>
        whether this block is committed or not.