dengzhhu653 commented on code in PR #6595:
URL: https://github.com/apache/hive/pull/6595#discussion_r4595030599


##########
standalone-metastore/metastore-search/src/main/java/org/apache/hive/search/index/store/IndexBackupUtils.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.search.index.store;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hive.search.config.IndexStoreOptions;
+import org.apache.hive.search.exception.IndexIOException;
+
+public final class IndexBackupUtils {
+  private IndexBackupUtils() {}
+
+  /** Push local index state to the backup (remote) location. */
+  public static boolean syncToBackup(IndexStateClient local, IndexStateClient 
remote)
+      throws IOException {
+    Optional<IndexManifest> localManifest = local.readManifest();
+    if (localManifest.isEmpty()) {
+      return false;
+    }
+    Optional<IndexManifest> remoteManifest = remote.readManifest();
+    IndexManifest localM = localManifest.get();
+    if (remoteManifest.isPresent()) {
+      IndexManifest remoteM = remoteManifest.get();
+      if (remoteM.lastEventId() > localM.lastEventId()) {
+        return false;
+      }
+      if (remoteM.lastEventId() == localM.lastEventId() && 
localM.sameFilesAs(remoteM)) {
+        return false;
+      }
+    }
+    applyDiff(local, remote, localM.diff(remoteManifest.orElse(null)));

Review Comment:
   Only one leader writes to remote index, and followers use the remote backup 
for recovery, so let's discuss the recovery.
   
   The leader is syncing the snapshot, while the follower is recovering:
   - If the leader `clearLocalIndex` is triggered, means the backup is stale, 
it will delete the backup as a consequence as well, the follower either detects 
this staleness issue as well or recovers from failure and try next cycle. 
   - If the leader delete an index file, the follower should either read the 
deleted index file successfully or hit IOException(FileNotFound), the follower 
will try next read of the snapshot in 10s if it sees exception, and client will 
be routed to healthy index nodes.
   - If the leader crashes, the follower still reads the backup, and throws 
exception if an index file cannot find, wait until a new leader wakes up and 
continues the syncing of full snapshot.
   
   In both cases, the follower won't read the partial snapshot, either full 
snapshot or waiting for next cycle of recovery.
   



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

Reply via email to