java.lang.Object
org.apache.hadoop.ozone.container.keyvalue.helpers.ChunkUtils

public final class ChunkUtils extends Object
Utility methods for chunk operations for KeyValue container.
  • Field Details

    • READ_OPTIONS

      public static final Set<? extends OpenOption> READ_OPTIONS
    • NO_ATTRIBUTES

      public static final FileAttribute<?>[] NO_ATTRIBUTES
    • DEFAULT_FILE_LOCK_STRIPED_SIZE

      public static final int DEFAULT_FILE_LOCK_STRIPED_SIZE
      See Also:
  • Method Details

    • setStripedLock

      public static void setStripedLock(com.google.common.util.concurrent.Striped<ReadWriteLock> stripedLock)
    • writeData

      public static void writeData(File file, org.apache.hadoop.ozone.common.ChunkBuffer data, long offset, long len, HddsVolume volume, boolean sync) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Writes the data in chunk Info to the specified location in the chunkfile.
      Parameters:
      file - - File to write data to.
      data - - The data buffer.
      offset -
      len -
      volume - for statistics and checker
      sync - whether to do fsync or not
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • writeData

      public static void writeData(FileChannel file, String filename, org.apache.hadoop.ozone.common.ChunkBuffer data, long offset, long len, HddsVolume volume) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • readData

      public static org.apache.hadoop.ozone.common.ChunkBuffer readData(long len, int bufferCapacity, File file, long off, HddsVolume volume, int readMappedBufferThreshold, boolean mmapEnabled, MappedBufferManager mappedBufferManager) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • readData

      public static org.apache.hadoop.ozone.common.ChunkBufferToByteString readData(File file, long chunkSize, long offset, long length, HddsVolume volume, DispatcherContext context) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • validateChunkForOverwrite

      public static boolean validateChunkForOverwrite(File chunkFile, org.apache.hadoop.ozone.container.common.helpers.ChunkInfo info)
      Validates chunk data and returns a file object to Chunk File that we are expected to write data to.
      Parameters:
      chunkFile - - chunkFile to write data into.
      info - - chunk info.
      Returns:
      true if the chunkFile exists and chunkOffset < chunkFile length, false otherwise.
    • validateChunkForOverwrite

      public static boolean validateChunkForOverwrite(FileChannel chunkFile, org.apache.hadoop.ozone.container.common.helpers.ChunkInfo info)
      Validates chunk data and returns a boolean value that indicates if the chunk data should be overwritten.
      Parameters:
      chunkFile - - FileChannel of the chunkFile to write data into.
      info - - chunk info.
      Returns:
      true if the chunkOffset is less than the chunkFile length, false otherwise.
    • isOverWriteRequested

      public static boolean isOverWriteRequested(File chunkFile, org.apache.hadoop.ozone.container.common.helpers.ChunkInfo chunkInfo)
      Checks if we are getting a request to overwrite an existing range of chunk.
      Parameters:
      chunkFile - - File
      chunkInfo - - Buffer to write
      Returns:
      bool
    • isOverWriteRequested

      public static boolean isOverWriteRequested(FileChannel channel, org.apache.hadoop.ozone.container.common.helpers.ChunkInfo chunkInfo)
      Checks if a request to overwrite an existing range of a chunk has been received.
      Parameters:
      channel - - FileChannel of the file to check
      chunkInfo - - Chunk information containing the offset
      Returns:
      true if the offset is less than the file length, indicating a request to overwrite an existing range; false otherwise
    • verifyChunkFileExists

      public static void verifyChunkFileExists(File file) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • validateBufferSize

      public static void validateBufferSize(long expected, long actual) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • limitReadSize

      public static void limitReadSize(long len) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • wrapInStorageContainerException

      public static org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException wrapInStorageContainerException(Exception e)
    • validateChunkSize

      public static void validateChunkSize(FileChannel fileChannel, org.apache.hadoop.ozone.container.common.helpers.ChunkInfo chunkInfo, String fileName) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Checks if the block file length is equal to the chunk offset.
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException