Class ContainerData
java.lang.Object
org.apache.hadoop.ozone.container.common.impl.ContainerData
- Direct Known Subclasses:
KeyValueContainerData
ContainerData is the in-memory representation of container metadata and is
represented on disk by the .container file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBlock byte used, block count and pending deletion count.static classRead/write/block statistics of a container. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedContainerData(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.protectedContainerData(ContainerData source) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMetadata(String key, String value) Add/Update metadata.voidMarks this container as closed.voidadd available space in the container to the committed space in the volume.voidcomputeAndSetContainerFileChecksum(org.yaml.snakeyaml.Yaml yaml) Compute the checksum for ContainerData using the specified Yaml (based on ContainerType) and set the checksum.abstract longReturns the blockCommitSequenceId.longFor testing only.longGet the number of bytes used by the container.Get chunks path.longReturns the containerID.abstract StringReturns the path to base dir of the container.org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerTypeReturns the type of the container.longReturns the layoutVersion of the actual container data format.longReturn's maximum size of the container in bytes.Returns metadata of the container.abstract StringReturns container metadata path.Returns the origin node Id of this container.Returns the origin pipeline Id of this container.abstract org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProtoReturns a ProtoBuf Message from ContainerData.intorg.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.StategetState()Returns the state of the container.Returns the volume of the Container.booleanisClosed()checks if the container is closed.booleanchecks if the container is closing.booleanbooleanisEmpty()booleanisOpen()checks if the container is open.booleanchecks if the container is quasi closed.booleanchecks if the container is unhealthy.booleanisValid()checks if the container is invalid.voidIndicates that this container has no more data, and is eligible for deletion.booleanvoidMarks this container as quasi closed.voidvoidsetChunksPath(String chunkPath) Set chunks Path.voidsetCommittedSpace(boolean committed) voidsetContainerFileChecksum(String checkSum) voidsetDataChecksum(long dataChecksum) voidsetDataScanTimestamp(Long timestamp) voidsetMetadata(Map<String, String> metadataMap) Set metadata.voidsetReplicaIndex(int replicaIndex) voidsetState(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State state) Set the state of the container.voidsetVolume(HddsVolume hddsVolume) Set the Volume for the Container.toString()voidupdateDataScanTime(Instant time) voidupdateWriteStats(long bytesWritten, boolean overwrite)
-
Field Details
-
CHARSET_ENCODING
-
ZERO_CHECKSUM
-
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- - ContainerTypecontainerId- - ContainerIdlayoutVersion- - Container layoutVersionsize- - Container maximum size in bytesoriginPipelineId- - Pipeline Id where this container is/was createdoriginNodeId- - Node Id where this container is/was created
-
ContainerData
-
-
Method Details
-
getContainerID
public long getContainerID()Returns the containerID. -
getImmediateCloseActionSent
-
getContainerPath
Returns the path to base dir of the container.- Returns:
- Path to base dir.
-
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
Returns the layoutVersion of the actual container data format.- Returns:
- layoutVersion
-
getChunksPath
Get chunks path.- Returns:
- - Path where chunks are stored
-
setChunksPath
Set chunks Path.- Parameters:
chunkPath- - File path.
-
addMetadata
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
Returns metadata of the container.- Returns:
- metadata
-
setMetadata
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
-
getBytesUsed
public long getBytesUsed()Get the number of bytes used by the container.- Returns:
- the number of bytes used by the container.
-
setVolume
Set the Volume for the Container. This should be called only from the createContainer.- Parameters:
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
-
getContainerFileChecksum
-
lastDataScanTime
- Returns:
Optionalwith the timestamp of last data scan.absentif not yet scanned or timestamp was not recorded.
-
updateDataScanTime
-
setDataScanTimestamp
-
getDataScanTimestamp
-
getOriginPipelineId
Returns the origin pipeline Id of this container.- Returns:
- origin node Id
-
getOriginNodeId
Returns the origin node Id of this container.- Returns:
- origin node Id
-
computeAndSetContainerFileChecksum
Compute the checksum for ContainerData using the specified Yaml (based on ContainerType) and set the checksum. Checksum of ContainerData is calculated by setting thechecksumfield 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
-