sumitagrawl commented on code in PR #12139:
URL: https://github.com/apache/ozone/pull/12139#discussion_r4677369350
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -2539,21 +2542,24 @@ private void deleteInternal(Container container,
boolean force)
HddsVolume hddsVolume = keyValueContainerData.getVolume();
// Steps to delete
- // 1. container marked deleted
- // 2. container is removed from container set
+ // 1. witnessed container DB entry set to DELETED, container is
removed from container set
+ // 2. container marked deleted
// 3. container db handler and content removed from db
// 4. container moved to tmp folder
// 5. container content deleted from tmp folder
+ long waitTime = clock.millis() - startTime;
+ if (waitTime > maxDeleteLockWaitMs) {
+ LOG.warn("An attempt to delete container {} took {} ms acquiring
locks and pre-checks. " +
+ "The delete has been skipped and should be retried
automatically by SCM.",
+ containerLocked.getContainerData().getContainerID(), waitTime);
+ return;
+ }
+ // Step 1 is first and outside the try below. If the entry cannot be
written, nothing has changed yet: the
+ // delete fails with the witnessed container DB error and the replica
stays as it was. If the datanode stops
+ // after step 1, the replica on disk is intact and is loaded again at
startup.
+ containerSet.removeContainer(containerId);
Review Comment:
we do markContainerForDelete() first so that it will not get loaded during
startup. Disk based container state is given priority on restart.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/HddsDispatcher.java:
##########
@@ -348,6 +348,18 @@ && getMissingContainerSet().contains(containerID)) {
StorageContainerException sce = new StorageContainerException(
"ContainerID " + containerID + " does not exist",
ContainerProtos.Result.CONTAINER_NOT_FOUND);
+ if (isWriteCommitStage) {
+ // The write stage of this WriteChunk was refused if this datanode
held the container before and deleted it.
+ // Answer the commit stage the same way, as a closed replica does,
so that a late write does not close the
+ // pipeline.
+ try {
+ containerSet.ensureContainerNotWitnessed(containerID);
Review Comment:
are we having some scenario where this check is needed? as already exception
is thrown when container is trying to created if present in witnessedDBTable
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -504,6 +504,9 @@ ContainerCommandResponseProto handleCreateContainer(
containerIdLock.lock();
try {
if (containerSet.getContainer(containerID) == null) {
+ if (containerState != RECOVERING) {
Review Comment:
check is already there inside containerSet.addContainer**(), so this is
redundant.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerSet.java:
##########
@@ -148,6 +148,31 @@ public void ensureContainerNotMissing(long containerId,
State state) throws Stor
}
}
+ /**
+ * Fails if the witnessed container DB has an entry for the container: it
was already created on this datanode,
+ * possibly deleted since, and must not be created again by an ordinary
create.
+ * @param containerId ID of the container to be created
+ * @throws StorageContainerException with {@code CLOSED_CONTAINER_IO} if
there is an entry, or with
+ * {@code IO_EXCEPTION} if the entry
cannot be read
+ */
+ public void ensureContainerNotWitnessed(long containerId) throws
StorageContainerException {
+ if (containerMetadataStore == null) {
+ return;
+ }
+ final ContainerCreateInfo info;
+ try {
+ info =
containerMetadataStore.getContainerCreateInfoTable().get(ContainerID.valueOf(containerId));
+ } catch (IOException e) {
+ throw new StorageContainerException("Failed to read the witnessed
container DB for container " + containerId,
+ e, ContainerProtos.Result.IO_EXCEPTION);
+ }
+ if (info != null) {
+ throw new StorageContainerException("Container " + containerId + " was
already created on this datanode"
+ + " (witnessed state " + info.getState() + ") and cannot be created
again",
+ ContainerProtos.Result.CLOSED_CONTAINER_IO);
Review Comment:
can be open, closed or delete.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerSet.java:
##########
@@ -226,14 +259,30 @@ private boolean addContainer(Container<?> container,
boolean overwrite) throws
}
}
- private void updateContainerIdTable(long containerId, ContainerData
containerData) throws StorageContainerException {
+ /**
+ * Records the replica that is being added in the witnessed container DB.
The entry is written when:
+ * <ul>
+ * <li>there is none: this is the first replica of the container on this
datanode;</li>
+ * <li>it is DELETED: this datanode deleted its replica, and now loads one
from disk at startup or gets one through
+ * repair. An ordinary create does not get here for a DELETED entry,
KeyValueHandler refuses it;</li>
+ * <li>it has no replica index: it was written in the older table
format;</li>
+ * <li>{@code replaceReplicaIndex} is set and the replica has another
index than the entry: a repair replaces the
+ * replica that this datanode held.</li>
+ * </ul>
+ * In all other cases the entry is kept as it is.
+ */
+ private void updateContainerIdTable(long containerId, ContainerData
containerData, boolean replaceReplicaIndex)
+ throws StorageContainerException {
if (null != containerMetadataStore) {
try {
ContainerID containerIdObj = ContainerID.valueOf(containerId);
Table<ContainerID, ContainerCreateInfo> containerCreateInfoTable =
containerMetadataStore.getContainerCreateInfoTable();
ContainerCreateInfo containerCreateInfo =
containerCreateInfoTable.get(containerIdObj);
- if (containerCreateInfo == null ||
containerCreateInfo.getReplicaIndex() == INVALID_REPLICA_INDEX) {
+ if (containerCreateInfo == null
+ || containerCreateInfo.getState() == State.DELETED
Review Comment:
This check prevent creation of container,
1. not exist to avoid double open OR
2. exist but replica index -1 (for compatibility of old containers in DB) -
not part of double open
what scenario do other case as planned to get handled here ?
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerSet.java:
##########
@@ -384,11 +434,12 @@ private boolean removeContainer(long containerId, boolean
markMissing, boolean r
if (markMissing) {
missingContainerSet.add(containerId);
}
+ // Keep the witnessed entry as DELETED before anything is removed, so a
failed write leaves the replica loaded.
+ if (markDeleted) {
+ markDeletedInContainerTable(containerId);
Review Comment:
For delete of container being imported or moved to this DN can lead to add
to the table, as addition even it was not present earlier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]