kowshik commented on a change in pull request #10218:
URL: https://github.com/apache/kafka/pull/10218#discussion_r595492577



##########
File path: 
clients/src/main/java/org/apache/kafka/server/log/remote/storage/RemoteLogSegmentState.java
##########
@@ -87,4 +89,27 @@ public byte id() {
     public static RemoteLogSegmentState forId(byte id) {
         return STATE_TYPES.get(id);
     }
+
+    public static boolean isValidTransition(RemoteLogSegmentState srcState, 
RemoteLogSegmentState targetState) {
+        Objects.requireNonNull(targetState, "targetState can not be null");
+
+        if (srcState == null) {
+            // If the source state is null, check the target state as the 
initial state viz DELETE_PARTITION_MARKED
+            // Wanted to keep this logic simple here by taking null for 
srcState, instead of creating one more state like
+            // COPY_SEGMENT_NOT_STARTED and have the null check by caller and 
pass that state.
+            return targetState == COPY_SEGMENT_STARTED;
+        } else if (srcState == targetState) {

Review comment:
       1. Will it be useful to place the implementation of this validation in a 
separate module, so that it can be reused with `RLMMWithTopicStorage` in the 
future?
   2. Suggestion from the standpoint of code readability/efficiency: Would it 
make sense to replace the `if-else` logic by looking up from a `Map< 
RemoteLogSegmentState, Set< RemoteLogSegmentState>>` where key is the source 
state and value is a set of allowed target states?
   
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to