You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2022/04/28 16:31:16 UTC

[GitHub] [hbase] frostruan commented on a diff in pull request #4367: HBASE-26974 Introduce a LogRollProcedure

frostruan commented on code in PR #4367:
URL: https://github.com/apache/hbase/pull/4367#discussion_r861095099


##########
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/BackupUtils.java:
##########
@@ -746,4 +767,78 @@ public static String findMostRecentBackupId(String[] backupIds) {
     return BackupRestoreConstants.BACKUPID_PREFIX + recentTimestamp;
   }
 
+  public static void logRoll(Map<String, String> props, Configuration config) throws IOException {
+    get(logRollInternal(props, config));
+  }
+
+  private static CompletableFuture<Void> logRollInternal(Map<String, String> props,
+      Configuration config) {
+    CompletableFuture<Void> future = new CompletableFuture<>();
+    addListener(ConnectionFactory.createAsyncConnection(config), (asyncConn, error1) -> {
+      if (error1 != null) {
+        closeConnectionAndCompleteFuture(future, error1, asyncConn);
+      } else {
+        addListener(asyncConn.getAdmin()
+            .execProcedureWithReturn(ROLLLOG_PROCEDURE_SIGNATURE, ROLLLOG_PROCEDURE_NAME, props),
+          (res, error2) -> {
+            if (error2 != null) {
+              closeConnectionAndCompleteFuture(future, error2, asyncConn);
+            } else {
+              long pauseNs = TimeUnit.MILLISECONDS.toNanos(
+                config.getLong(HBASE_CLIENT_PAUSE, DEFAULT_HBASE_CLIENT_PAUSE));
+
+              if (res == null || res.length == 0) {
+                waitProcedureDone(props, asyncConn, future, pauseNs, 0);
+                return;
+              }
+              long procId;
+              try {
+                procId = Bytes.toLong(res);
+              } catch (RuntimeException e) {
+                closeConnectionAndCompleteFuture(future, e, asyncConn);
+                return;
+              }
+              props.put(ROLLLOG_PROCEDURE_ID, Long.toString(procId));

Review Comment:
   @Apache9  Here we put up the ROLLLOG_PROCEDURE_ID into the properties map.



##########
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/LogRollProcedure.java:
##########
@@ -0,0 +1,168 @@
+/**
+ * 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.backup.master;
+
+import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.BACKUP_ENABLE_DEFAULT;
+import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.BACKUP_ENABLE_KEY;
+import static org.apache.hadoop.hbase.backup.master.LogRollMasterProcedureManager.LOGROLL_PROCEDURE_ENABLED;
+import static org.apache.hadoop.hbase.backup.master.LogRollMasterProcedureManager.LOGROLL_PROCEDURE_ENABLED_DEFAULT;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.hadoop.hbase.master.procedure.TableProcedureInterface;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.LogRollData;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.LogRollState;
+
+@InterfaceAudience.Private
+public class LogRollProcedure
+  extends StateMachineProcedure<MasterProcedureEnv, LogRollState>
+  implements TableProcedureInterface {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RSLogRollProcedure.class);
+
+  private Configuration conf;
+
+  private String backupRoot;
+
+  public LogRollProcedure() {
+  }
+
+  public LogRollProcedure(final String backupRoot, final Configuration conf) {
+    this.backupRoot = backupRoot;
+    this.conf = conf;
+  }
+
+  @Override
+  protected Flow executeFromState(MasterProcedureEnv env, LogRollState state)
+    throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
+    LOG.info("{} execute state={}", this, state);
+
+    try {
+      switch (state) {
+        case LOG_ROLL_ROLL_LOG_ON_EACH_RS:

Review Comment:
   Thanks Duo.
   
   It's just a way to make the procedure idempotent. Because this procedure obviously has subprocedures, its execute method will be executed multiple times. We can think of the state here as a flag bit. If not make it StateMachineProcedure, we can use a boolean flag and persist it to the state data. In contrast, I think StateMachineProcedure is better. Maybe there are better solutions. What do you think is better here?



-- 
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: issues-unsubscribe@hbase.apache.org

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