ragarkar commented on code in PR #7058:
URL: https://github.com/apache/hbase/pull/7058#discussion_r2166672706


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RefreshMetaProcedure.java:
##########
@@ -0,0 +1,414 @@
+/*
+ * 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.hadoop.hbase.master.procedure;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RefreshMetaState;
+import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RefreshMetaStateData;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.hbase.util.RetryCounter;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
+import org.apache.hadoop.hbase.util.FSUtils;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
[email protected]
+public class RefreshMetaProcedure extends 
AbstractStateMachineTableProcedure<RefreshMetaState> {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RefreshMetaProcedure.class);
+
+  private List<RegionInfo> currentRegions;
+  private List<RegionInfo> latestRegions;
+  private static final int MUTATION_BATCH_SIZE = 100;
+
+  public RefreshMetaProcedure() {
+    super();
+  }
+
+  public RefreshMetaProcedure(MasterProcedureEnv env) {
+    super(env);
+  }
+
+  @Override
+  public TableName getTableName() {
+    return TableName.META_TABLE_NAME;
+  }
+
+  @Override
+  public TableOperationType getTableOperationType() {
+    return TableOperationType.EDIT;
+  }
+
+  @Override
+  protected Flow executeFromState(MasterProcedureEnv env, RefreshMetaState 
refreshMetaState) {
+    LOG.info("Executing RefreshMetaProcedure state: {}", refreshMetaState);
+
+    try {
+      return switch (refreshMetaState) {
+        case REFRESH_META_INIT -> executeInit(env);
+        case REFRESH_META_SCAN_STORAGE -> executeScanStorage(env);
+        case REFRESH_META_UPDATE -> executeUpdate(env);
+        case REFRESH_META_COMPLETE -> executeComplete();
+        default -> throw new UnsupportedOperationException("Unhandled state: " 
+ refreshMetaState);
+      };
+    } catch (Exception ex) {
+      LOG.error("Error in RefreshMetaProcedure state {}", refreshMetaState, 
ex);
+      setFailure("RefreshMetaProcedure", ex);
+      return Flow.NO_MORE_STATE;
+    }
+  }
+
+  private Flow executeInit(MasterProcedureEnv env) throws IOException {
+    LOG.trace("Getting current regions from hbase:meta table");
+    try {
+      currentRegions = 
getCurrentRegions(env.getMasterServices().getConnection());
+      LOG.info("Found {} current regions in meta table", 
currentRegions.size());
+      setNextState(RefreshMetaState.REFRESH_META_SCAN_STORAGE);
+      return Flow.HAS_MORE_STATE;
+    } catch (IOException ioe) {
+      LOG.error("Failed to get current regions from meta table", ioe);
+      throw ioe;
+    }
+  }
+
+  private Flow executeScanStorage(MasterProcedureEnv env) throws IOException {
+    try {
+      latestRegions = 
scanBackingStorage(env.getMasterServices().getConnection());
+      LOG.info("Found {} regions in backing storage", latestRegions.size());
+      setNextState(RefreshMetaState.REFRESH_META_UPDATE);
+      return Flow.HAS_MORE_STATE;
+    } catch (IOException ioe) {
+      LOG.error("Failed to scan backing storage", ioe);
+      throw ioe;
+    }
+  }
+
+  private Flow executeUpdate(MasterProcedureEnv env) throws IOException {
+    if (currentRegions == null || latestRegions == null) {
+      LOG.error("Can not execute update on null lists. "
+        + "Meta Table Regions - {}, Storage Regions - {}", currentRegions, 
latestRegions);
+      throw new IOException((currentRegions == null ? "current regions" : 
"latest regions") + "list is null");

Review Comment:
   nit: Add a space before "list is null". Otherwise, it will be concatenated 
with "current regions" or "latest regions" without a space between.



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

Reply via email to