dengzhhu653 commented on code in PR #6595: URL: https://github.com/apache/hive/pull/6595#discussion_r4320850817
########## 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: We don't need to stage the backup, as we will write a remote manifest at the end of backup to audit the event. If the last valid backup is corrupt, that doesn't matter, the leader Metastore will sync the backup in 10s, https://github.com/dengzhhu653/hive/blob/a51964ba08e8d3ff4eae5e85a8ceccdb32c87d0a/standalone-metastore/metastore-search/src/main/java/org/apache/hive/search/metastore/MetastoreIndexer.java#L277 For other Metastore instances, it will check the remote manifest during restoring the index, so a corrupted index is prevented until the remote index is ready again. Adding the stage and atomical publication would increase the complexity, it benefits less if we can restore the remote backup in a short period. -- 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]
