F64116045 commented on code in PR #11012:
URL: https://github.com/apache/ozone/pull/11012#discussion_r3776185531
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java:
##########
@@ -386,6 +386,36 @@ public boolean contains(ContainerID id) {
}
}
+ @Deprecated
+ @Override
+ public void updateContainerState(final HddsProtos.ContainerID containerID,
+ final LifeCycleEvent event)
+ throws IOException, InvalidStateTransitionException {
+ // TODO: Remove the protobuf conversion after fixing ContainerStateMap.
+ final ContainerID id = ContainerID.getFromProtobuf(containerID);
+
+ try (AutoCloseableLock ignored = writeLock(id)) {
+ if (containers.contains(id)) {
+ final ContainerInfo oldInfo = containers.getContainerInfo(id);
+ final LifeCycleState oldState = oldInfo.getState();
+ final LifeCycleState newState = stateMachine.getNextState(
+ oldInfo.getState(), event);
+ if (newState.getNumber() > oldState.getNumber()) {
+ ExecutionUtil.create(() -> {
+ containers.updateState(id, oldState, newState);
+ transactionBuffer.addToBuffer(containerStore, id,
+ containers.getContainerInfo(id));
+ }).onException(() -> {
+ transactionBuffer.addToBuffer(containerStore, id, oldInfo);
Review Comment:
I think these two operations should be reversed? (`addToBuffer` and
`updateState`)
If `containers.updateState(id, oldState, newState)` at `line:405` succeeds
but `addToBuffer` throws, `oldInfo` already contains `newState`.
The cleanup adds `newState` to the transaction buffer, then changes the
in-memory container back to `oldState`, leaving the buffered and in-memory
states inconsistent.
Could we follow `updateContainerStateWithSequenceId` below like:
```java
containers.updateState(id, newState, oldState);
ContainerInfo currentInfo = containers.getContainerInfo(id);
transactionBuffer.addToBuffer(containerStore, id, currentInfo);
```
--
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]