Browse Source

Simplify Serialization of ForceMergeRequest (#58470)

We can use a normal string for the uuid when we don't have any nodes in the cluster that could have
created the request with a `null` force merge uuid in it in the cluster any longer (nodes before 7.7).
Armin Braun 5 years ago
parent
commit
7d64b71a05

+ 9 - 10
server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeRequest.java

@@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.indices.forcemerge;
 import org.elasticsearch.Version;
 import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.support.broadcast.BroadcastRequest;
-import org.elasticsearch.common.Nullable;
 import org.elasticsearch.common.UUIDs;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
@@ -56,13 +55,12 @@ public class ForceMergeRequest extends BroadcastRequest<ForceMergeRequest> {
     private boolean onlyExpungeDeletes = Defaults.ONLY_EXPUNGE_DELETES;
     private boolean flush = Defaults.FLUSH;
 
-    private static final Version FORCE_MERGE_UUID_VERSION = Version.V_7_7_0;
+    private static final Version FORCE_MERGE_UUID_SIMPLE_VERSION = Version.V_8_0_0;
 
     /**
      * Force merge UUID to store in the live commit data of a shard under
      * {@link org.elasticsearch.index.engine.Engine#FORCE_MERGE_UUID_KEY} after force merging it.
      */
-    @Nullable
     private final String forceMergeUUID;
 
     /**
@@ -80,10 +78,11 @@ public class ForceMergeRequest extends BroadcastRequest<ForceMergeRequest> {
         maxNumSegments = in.readInt();
         onlyExpungeDeletes = in.readBoolean();
         flush = in.readBoolean();
-        if (in.getVersion().onOrAfter(FORCE_MERGE_UUID_VERSION)) {
-            forceMergeUUID = in.readOptionalString();
+        if (in.getVersion().onOrAfter(FORCE_MERGE_UUID_SIMPLE_VERSION)) {
+            forceMergeUUID = in.readString();
         } else {
-            forceMergeUUID = null;
+            forceMergeUUID = in.readOptionalString();
+            assert forceMergeUUID != null : "optional was just used as a BwC measure";
         }
     }
 
@@ -122,10 +121,8 @@ public class ForceMergeRequest extends BroadcastRequest<ForceMergeRequest> {
     }
 
     /**
-     * Force merge UUID to use when force merging or {@code null} if not using one in a mixed version cluster containing nodes older than
-     * {@link #FORCE_MERGE_UUID_VERSION}.
+     * Force merge UUID to use when force merging.
      */
-    @Nullable
     public String forceMergeUUID() {
         return forceMergeUUID;
     }
@@ -159,7 +156,9 @@ public class ForceMergeRequest extends BroadcastRequest<ForceMergeRequest> {
         out.writeInt(maxNumSegments);
         out.writeBoolean(onlyExpungeDeletes);
         out.writeBoolean(flush);
-        if (out.getVersion().onOrAfter(FORCE_MERGE_UUID_VERSION)) {
+        if (out.getVersion().onOrAfter(FORCE_MERGE_UUID_SIMPLE_VERSION)) {
+            out.writeString(forceMergeUUID);
+        } else {
             out.writeOptionalString(forceMergeUUID);
         }
     }

+ 1 - 1
server/src/main/java/org/elasticsearch/index/engine/Engine.java

@@ -1041,7 +1041,7 @@ public abstract class Engine implements Closeable {
      */
     public abstract void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes,
                                     boolean upgrade, boolean upgradeOnlyAncientSegments,
-                                    @Nullable String forceMergeUUID) throws EngineException, IOException;
+                                    String forceMergeUUID) throws EngineException, IOException;
 
     /**
      * Snapshots the most recent index and returns a handle to it. If needed will try and "commit" the