Class KeyValueContainer

java.lang.Object
org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer
All Implemented Interfaces:
Container<KeyValueContainerData>

public class KeyValueContainer extends Object implements Container<KeyValueContainerData>
Class to perform KeyValue Container operations. Any modifications to KeyValueContainer object should ideally be done via api exposed in KeyValueHandler class.
  • Constructor Details

    • KeyValueContainer

      public KeyValueContainer(KeyValueContainerData containerData, org.apache.hadoop.hdds.conf.ConfigurationSource ozoneConfig)
  • Method Details

    • setCheckChunksFilePath

      public void setCheckChunksFilePath(boolean bCheckChunksDirFilePath)
    • create

      public void create(VolumeSet volumeSet, VolumeChoosingPolicy volumeChoosingPolicy, String clusterId) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Creates a container.
      Specified by:
      create in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • createContainerMetaData

      protected void createContainerMetaData(File containerMetaDataPath, File chunksPath, File dbFile, String schemaVersion, org.apache.hadoop.hdds.conf.ConfigurationSource configuration) throws IOException
      The Static method call is wrapped in a protected instance method so it can be overridden in tests.
      Throws:
      IOException
    • populatePathFields

      public void populatePathFields(String clusterId, HddsVolume containerVolume)
      Set all of the path realted container data fields based on the name conventions.
      Parameters:
      clusterId -
      containerVolume -
    • delete

      public void delete() throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Deletes the container.
      Specified by:
      delete in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • hasBlocks

      public boolean hasBlocks() throws IOException
      Description copied from interface: Container
      Returns true if container has some block.
      Specified by:
      hasBlocks in interface Container<KeyValueContainerData>
      Returns:
      true if container has some block.
      Throws:
      IOException - if was unable to check container status.
    • markContainerForClose

      public void markContainerForClose() throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Marks the container for closing. Moves the container to CLOSING state.
      Specified by:
      markContainerForClose in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • markContainerUnhealthy

      public void markContainerUnhealthy() throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Marks the container replica as unhealthy.
      Specified by:
      markContainerUnhealthy in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • markContainerForDelete

      public void markContainerForDelete()
      Description copied from interface: Container
      Marks the container replica as deleted.
      Specified by:
      markContainerForDelete in interface Container<KeyValueContainerData>
    • quasiClose

      public void quasiClose() throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Quasi Closes a open container, if it is already closed or does not exist a StorageContainerException is thrown.
      Specified by:
      quasiClose in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • close

      public void close() throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Closes a open/quasi closed container, if it is already closed or does not exist a StorageContainerException is thrown.
      Specified by:
      close in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • updateDataScanTimestamp

      public void updateDataScanTimestamp(Instant time) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Specified by:
      updateDataScanTimestamp in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • getContainerData

      public KeyValueContainerData getContainerData()
      Description copied from interface: Container
      Get metadata about the container.
      Specified by:
      getContainerData in interface Container<KeyValueContainerData>
      Returns:
      ContainerData - Container Data.
    • getContainerState

      public org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State getContainerState()
      Description copied from interface: Container
      Get the Container Lifecycle state.
      Specified by:
      getContainerState in interface Container<KeyValueContainerData>
      Returns:
      ContainerLifeCycleState - Container State.
    • getContainerType

      public org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType getContainerType()
      Description copied from interface: Container
      Return the ContainerType for the container.
      Specified by:
      getContainerType in interface Container<KeyValueContainerData>
    • update

      public void update(Map<String,String> metadata, boolean forceUpdate) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Description copied from interface: Container
      Update the container.
      Specified by:
      update in interface Container<KeyValueContainerData>
      Parameters:
      metadata -
      forceUpdate - if true, update container forcibly.
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • update

      public void update(Map<String,String> metadata, boolean forceUpdate, String containerMetadataPath) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Specified by:
      update in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • updateDeleteTransactionId

      public void updateDeleteTransactionId(long deleteTransactionId)
      Description copied from interface: Container
      updates the DeleteTransactionId.
      Specified by:
      updateDeleteTransactionId in interface Container<KeyValueContainerData>
      Parameters:
      deleteTransactionId -
    • importContainerData

      public void importContainerData(InputStream input, ContainerPacker<KeyValueContainerData> packer) throws IOException
      Description copied from interface: Container
      Import the container from an external archive.
      Specified by:
      importContainerData in interface Container<KeyValueContainerData>
      Throws:
      IOException
    • importContainerData

      public void importContainerData(KeyValueContainerData originalContainerData) throws IOException
      Throws:
      IOException
    • exportContainerData

      public void exportContainerData(OutputStream destination, ContainerPacker<KeyValueContainerData> packer) throws IOException
      Description copied from interface: Container
      Export all the data of the container to one output archive with the help of the packer.
      Specified by:
      exportContainerData in interface Container<KeyValueContainerData>
      Throws:
      IOException
    • readLock

      public void readLock()
      Acquire read lock.
      Specified by:
      readLock in interface Container<KeyValueContainerData>
    • readUnlock

      public void readUnlock()
      Release read lock.
      Specified by:
      readUnlock in interface Container<KeyValueContainerData>
    • hasReadLock

      public boolean hasReadLock()
      Check if the current thread holds read lock.
      Specified by:
      hasReadLock in interface Container<KeyValueContainerData>
    • writeLock

      public void writeLock()
      Acquire write lock.
      Specified by:
      writeLock in interface Container<KeyValueContainerData>
    • writeUnlock

      public void writeUnlock()
      Release write lock.
      Specified by:
      writeUnlock in interface Container<KeyValueContainerData>
    • hasWriteLock

      public boolean hasWriteLock()
      Check if the current thread holds write lock.
      Specified by:
      hasWriteLock in interface Container<KeyValueContainerData>
    • readLockInterruptibly

      public void readLockInterruptibly() throws InterruptedException
      Acquire read lock, unless interrupted while waiting.
      Specified by:
      readLockInterruptibly in interface Container<KeyValueContainerData>
      Throws:
      InterruptedException
    • writeLockInterruptibly

      public void writeLockInterruptibly() throws InterruptedException
      Acquire write lock, unless interrupted while waiting.
      Specified by:
      writeLockInterruptibly in interface Container<KeyValueContainerData>
      Throws:
      InterruptedException
    • writeLockTryLock

      public boolean writeLockTryLock(long time, TimeUnit unit) throws InterruptedException
      Throws:
      InterruptedException
    • getContainerFile

      public File getContainerFile()
      Returns containerFile.
      Specified by:
      getContainerFile in interface Container<KeyValueContainerData>
      Returns:
      .container File name
    • getContainerFile

      public static File getContainerFile(String metadataPath, long containerId)
    • updateBlockCommitSequenceId

      public void updateBlockCommitSequenceId(long blockCommitSequenceId)
      Description copied from interface: Container
      updates the blockCommitSequenceId.
      Specified by:
      updateBlockCommitSequenceId in interface Container<KeyValueContainerData>
    • getBlockCommitSequenceId

      public long getBlockCommitSequenceId()
      Description copied from interface: Container
      Returns the blockCommitSequenceId.
      Specified by:
      getBlockCommitSequenceId in interface Container<KeyValueContainerData>
    • isBlockInPendingPutBlockCache

      public boolean isBlockInPendingPutBlockCache(long localID)
      Return whether the given localID of a block is present in the pendingPutBlockCache or not.
    • addToPendingPutBlockCache

      public void addToPendingPutBlockCache(long localID) throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Add the given localID of a block to the pendingPutBlockCache.
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • removeFromPendingPutBlockCache

      public void removeFromPendingPutBlockCache(long localID)
      Remove the given localID of a block from the pendingPutBlockCache.
    • getContainerReport

      public org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto getContainerReport() throws org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
      Returns KeyValueContainerReport for the KeyValueContainer.
      Specified by:
      getContainerReport in interface Container<KeyValueContainerData>
      Throws:
      org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException
    • getContainerDBFile

      public File getContainerDBFile()
      Returns container DB file.
    • scanMetaData

      public MetadataScanResult scanMetaData() throws InterruptedException
      Description copied from interface: Container
      check and report the structural integrity of the container.
      Specified by:
      scanMetaData in interface Container<KeyValueContainerData>
      Returns:
      A MetadataScanResult encapsulating the result of the scan.
      Throws:
      InterruptedException - if the scanning thread is interrupted before it completes.
    • shouldScanData

      public boolean shouldScanData()
      Description copied from interface: Container
      Return if the container data should be checksum verified to detect corruption. The result depends upon the current state of the container (e.g. if a container is accepting writes, it may not be a good idea to perform checksum verification to avoid concurrency issues).
      Specified by:
      shouldScanData in interface Container<KeyValueContainerData>
    • scanData

      public DataScanResult scanData(org.apache.hadoop.hdfs.util.DataTransferThrottler throttler, org.apache.hadoop.hdfs.util.Canceler canceler) throws InterruptedException
      Description copied from interface: Container
      Perform checksum verification for the container data.
      Specified by:
      scanData in interface Container<KeyValueContainerData>
      Parameters:
      throttler - A reference of DataTransferThrottler used to perform I/O bandwidth throttling
      canceler - A reference of Canceler used to cancel the I/O bandwidth throttling (e.g. for shutdown purpose).
      Returns:
      A DataScanResult encapsulating the result of the scan.
      Throws:
      InterruptedException - if the scanning thread is interrupted before it completes.