Class ContainerData

java.lang.Object
org.apache.hadoop.ozone.container.common.impl.ContainerData
Direct Known Subclasses:
KeyValueContainerData

public abstract class ContainerData extends Object
ContainerData is the in-memory representation of container metadata and is represented on disk by the .container file.
  • Field Details

    • CHARSET_ENCODING

      public static final Charset CHARSET_ENCODING
    • ZERO_CHECKSUM

      public static final String ZERO_CHECKSUM
    • YAML_FIELDS

      protected static final List<String> YAML_FIELDS
  • Constructor Details

    • ContainerData

      protected ContainerData(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType type, long containerId, ContainerLayoutVersion layoutVersion, long size, String originPipelineId, String originNodeId)
      Creates a ContainerData Object, which holds metadata of the container.
      Parameters:
      type - - ContainerType
      containerId - - ContainerId
      layoutVersion - - Container layoutVersion
      size - - Container maximum size in bytes
      originPipelineId - - Pipeline Id where this container is/was created
      originNodeId - - Node Id where this container is/was created
    • ContainerData

      protected ContainerData(ContainerData source)
  • Method Details

    • getContainerID

      public long getContainerID()
      Returns the containerID.
    • getImmediateCloseActionSent

      public AtomicBoolean getImmediateCloseActionSent()
    • getContainerPath

      public abstract String getContainerPath()
      Returns the path to base dir of the container.
      Returns:
      Path to base dir.
    • getMetadataPath

      public abstract String getMetadataPath()
      Returns container metadata path.
      Returns:
      - Physical path where container file and checksum is stored.
    • getContainerType

      public org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType getContainerType()
      Returns the type of the container.
      Returns:
      ContainerType
    • getState

      public org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State getState()
      Returns the state of the container.
      Returns:
      ContainerLifeCycleState
    • getReplicaIndex

      public int getReplicaIndex()
    • setReplicaIndex

      public void setReplicaIndex(int replicaIndex)
    • setState

      public void setState(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State state)
      Set the state of the container.
      Parameters:
      state -
    • isCommittedSpace

      public boolean isCommittedSpace()
    • setCommittedSpace

      public void setCommittedSpace(boolean committed)
    • getMaxSize

      public long getMaxSize()
      Return's maximum size of the container in bytes.
      Returns:
      maxSize in bytes
    • getLayoutVersion

      public ContainerLayoutVersion getLayoutVersion()
      Returns the layoutVersion of the actual container data format.
      Returns:
      layoutVersion
    • getChunksPath

      public String getChunksPath()
      Get chunks path.
      Returns:
      - Path where chunks are stored
    • setChunksPath

      public void setChunksPath(String chunkPath)
      Set chunks Path.
      Parameters:
      chunkPath - - File path.
    • addMetadata

      public void addMetadata(String key, String value)
      Add/Update metadata. We should hold the container lock before updating the metadata as this will be persisted on disk. Unless, we are reconstructing ContainerData from protoBuf or from on disk .container file in which case lock is not required.
    • getMetadata

      public Map<String,String> getMetadata()
      Returns metadata of the container.
      Returns:
      metadata
    • setMetadata

      public void setMetadata(Map<String,String> metadataMap)
      Set metadata. We should hold the container lock before updating the metadata as this will be persisted on disk. Unless, we are reconstructing ContainerData from protoBuf or from on disk .container file in which case lock is not required.
    • isOpen

      public boolean isOpen()
      checks if the container is open.
      Returns:
      - boolean
    • isClosing

      public boolean isClosing()
      checks if the container is closing.
      Returns:
      - boolean
    • isValid

      public boolean isValid()
      checks if the container is invalid.
      Returns:
      - boolean
    • isClosed

      public boolean isClosed()
      checks if the container is closed.
      Returns:
      - boolean
    • isQuasiClosed

      public boolean isQuasiClosed()
      checks if the container is quasi closed.
      Returns:
      - boolean
    • isUnhealthy

      public boolean isUnhealthy()
      checks if the container is unhealthy.
      Returns:
      - boolean
    • quasiCloseContainer

      public void quasiCloseContainer()
      Marks this container as quasi closed.
    • closeContainer

      public void closeContainer()
      Marks this container as closed.
    • releaseCommitSpace

      public void releaseCommitSpace()
    • commitSpace

      public void commitSpace()
      add available space in the container to the committed space in the volume. available space is the number of bytes remaining till max capacity.
    • getStatistics

      public ContainerData.Statistics getStatistics()
    • getBytesUsed

      public long getBytesUsed()
      Get the number of bytes used by the container.
      Returns:
      the number of bytes used by the container.
    • setVolume

      public void setVolume(HddsVolume hddsVolume)
      Set the Volume for the Container. This should be called only from the createContainer.
      Parameters:
      hddsVolume -
    • getVolume

      public HddsVolume getVolume()
      Returns the volume of the Container.
      Returns:
      HddsVolume
    • getBlockCount

      public long getBlockCount()
      For testing only.
    • isEmpty

      public boolean isEmpty()
    • markAsEmpty

      public void markAsEmpty()
      Indicates that this container has no more data, and is eligible for deletion. Once this flag is set on a container, it cannot leave this state.
    • setContainerFileChecksum

      public void setContainerFileChecksum(String checkSum)
    • getContainerFileChecksum

      public String getContainerFileChecksum()
    • lastDataScanTime

      public Optional<Instant> lastDataScanTime()
      Returns:
      Optional with the timestamp of last data scan. absent if not yet scanned or timestamp was not recorded.
    • updateDataScanTime

      public void updateDataScanTime(@Nullable Instant time)
    • setDataScanTimestamp

      public void setDataScanTimestamp(Long timestamp)
    • getDataScanTimestamp

      public Long getDataScanTimestamp()
    • getOriginPipelineId

      public String getOriginPipelineId()
      Returns the origin pipeline Id of this container.
      Returns:
      origin node Id
    • getOriginNodeId

      public String getOriginNodeId()
      Returns the origin node Id of this container.
      Returns:
      origin node Id
    • computeAndSetContainerFileChecksum

      public void computeAndSetContainerFileChecksum(org.yaml.snakeyaml.Yaml yaml) throws IOException
      Compute the checksum for ContainerData using the specified Yaml (based on ContainerType) and set the checksum. Checksum of ContainerData is calculated by setting the checksum field to a 64-byte array with all 0's - ZERO_CHECKSUM. After the checksum is calculated, the checksum field is updated with this value.
      Parameters:
      yaml - Yaml for ContainerType to get the ContainerData as Yaml String
      Throws:
      IOException
    • setDataChecksum

      public void setDataChecksum(long dataChecksum)
    • getDataChecksum

      public long getDataChecksum()
    • needsDataChecksum

      public boolean needsDataChecksum()
    • getProtoBufMessage

      public abstract org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto getProtoBufMessage()
      Returns a ProtoBuf Message from ContainerData.
      Returns:
      Protocol Buffer Message
    • getBlockCommitSequenceId

      public abstract long getBlockCommitSequenceId()
      Returns the blockCommitSequenceId.
    • updateWriteStats

      public void updateWriteStats(long bytesWritten, boolean overwrite)
    • toString

      public String toString()
      Overrides:
      toString in class Object