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 15:31:59 UTC

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

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


##########
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:
   As long as it only has one state, do we really need to make it StateMachineProcedure?



##########
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/RSLogRollProcedure.java:
##########
@@ -0,0 +1,175 @@
+/**
+ * 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 java.io.IOException;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.hadoop.hbase.master.procedure.ServerProcedureInterface;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
+import org.apache.hadoop.hbase.util.RetryCounter;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.RSLogRollData;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.RSLogRollState;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState;
+
+@InterfaceAudience.Private
+public class RSLogRollProcedure
+  extends StateMachineProcedure<MasterProcedureEnv, RSLogRollState>
+  implements ServerProcedureInterface {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RSLogRollProcedure.class);
+
+  private ServerName targetServer;
+
+  private String backupRoot;
+
+  private long lastLogRollResult;
+
+  private RetryCounter retryCounter;
+
+  public RSLogRollProcedure() {
+  }
+
+  public RSLogRollProcedure(ServerName targetServer, String backupRoot, long lastLogRollResult) {
+    this.targetServer = targetServer;
+    this.backupRoot = backupRoot;
+    this.lastLogRollResult = lastLogRollResult;
+  }
+
+  @Override
+  protected Flow executeFromState(MasterProcedureEnv env, RSLogRollState state)
+    throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
+    LOG.info("{} execute state={}", this, state);
+
+    switch (state) {
+      case RS_LOG_ROLL_ROLL_LOG_REMOTE:
+        addChildProcedure(new RSLogRollRemoteProcedure(targetServer, backupRoot));
+        setNextState(RSLogRollState.RS_LOG_ROLL_CONFIRM_RESULT);
+        return Flow.HAS_MORE_STATE;
+      case RS_LOG_ROLL_CONFIRM_RESULT:
+        // if server is crashed. skip the rest steps.
+        if (!env.getMasterServices().getServerManager().isServerOnline(targetServer)) {
+          return Flow.NO_MORE_STATE;
+        }
+        try {
+          BackupSystemTable table =

Review Comment:
   Not very familiar with the code before, so I guess the update of this system table is done at RS side? We will check the updated record in it to determine whether we have done the log roll?



##########
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/regionserver/LogRollCallable.java:
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.regionserver;
+
+import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
+import org.apache.hadoop.hbase.executor.EventType;
+import org.apache.hadoop.hbase.procedure2.BaseRSProcedureCallable;
+import org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos;
+
+@InterfaceAudience.Private
+public class LogRollCallable extends BaseRSProcedureCallable {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LogRollCallable.class);
+
+  private String backupRoot;
+
+  @Override
+  protected void doCall() throws Exception {
+    long highest = rs.getWALs().stream()
+      .mapToLong(wal -> ((AbstractFSWAL<?>) wal).getFilenum()).max().orElse(-1L);
+    AbstractFSWAL<?> fsWAL = (AbstractFSWAL<?>) rs.getWAL(null);
+    long filenum = fsWAL.getFilenum();
+
+    LOG.info("Trying to roll log. Current log number={}, highest={}", filenum, highest);
+    rs.getWalRoller().requestRollAll();
+    rs.getWalRoller().waitUntilWalRollFinished();
+    LOG.info("After roll log, Current log number={}", fsWAL.getFilenum());
+
+    final String server = rs.getServerName().getAddress().toString();
+    final BackupSystemTable table = new BackupSystemTable(rs.getConnection());
+    Long sts = table.getRegionServerLastLogRollResult(server, backupRoot);

Review Comment:
   The return value is Long or long? If it is a Long, do we need a null check here?



##########
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/LogRollMasterProcedureManager.java:
##########
@@ -171,7 +199,20 @@ private boolean isBackupEnabled() {
   }
 
   @Override
-  public boolean isProcedureDone(ProcedureDescription desc) {
-    return done;
+  public boolean isProcedureDone(ProcedureDescription desc) throws IOException {

Review Comment:
   Mind explaining a bit here?
   
   So at upper layer, we do not know whether you are using the new procedure or the old 'procedure', and based on different implementation, we have different ways to determine whether it is finished.
   
   Where do we put the ROLLLOG_PROCEDURE_ID into the ProcedureDescription? I haven't found the code.



##########
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/RSLogRollProcedure.java:
##########
@@ -0,0 +1,175 @@
+/**
+ * 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 java.io.IOException;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
+import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
+import org.apache.hadoop.hbase.master.procedure.ServerProcedureInterface;
+import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
+import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
+import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
+import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
+import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
+import org.apache.hadoop.hbase.util.RetryCounter;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.RSLogRollData;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.RSLogRollState;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState;
+
+@InterfaceAudience.Private
+public class RSLogRollProcedure
+  extends StateMachineProcedure<MasterProcedureEnv, RSLogRollState>
+  implements ServerProcedureInterface {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RSLogRollProcedure.class);
+
+  private ServerName targetServer;
+
+  private String backupRoot;
+
+  private long lastLogRollResult;
+
+  private RetryCounter retryCounter;
+
+  public RSLogRollProcedure() {
+  }
+
+  public RSLogRollProcedure(ServerName targetServer, String backupRoot, long lastLogRollResult) {
+    this.targetServer = targetServer;
+    this.backupRoot = backupRoot;
+    this.lastLogRollResult = lastLogRollResult;
+  }
+
+  @Override
+  protected Flow executeFromState(MasterProcedureEnv env, RSLogRollState state)
+    throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
+    LOG.info("{} execute state={}", this, state);
+
+    switch (state) {
+      case RS_LOG_ROLL_ROLL_LOG_REMOTE:
+        addChildProcedure(new RSLogRollRemoteProcedure(targetServer, backupRoot));
+        setNextState(RSLogRollState.RS_LOG_ROLL_CONFIRM_RESULT);
+        return Flow.HAS_MORE_STATE;
+      case RS_LOG_ROLL_CONFIRM_RESULT:
+        // if server is crashed. skip the rest steps.
+        if (!env.getMasterServices().getServerManager().isServerOnline(targetServer)) {
+          return Flow.NO_MORE_STATE;
+        }
+        try {
+          BackupSystemTable table =
+            new BackupSystemTable(env.getMasterServices().getConnection());
+          long newestLogRollResult = table
+            .getRegionServerLastLogRollResult(targetServer.getAddress().toString(), backupRoot);
+          LOG.debug("newestLogRollResult={}, lastLogRollResult={}",
+            newestLogRollResult, lastLogRollResult);
+          if (newestLogRollResult > lastLogRollResult) {

Review Comment:
   The 'result' is just a timestamp?



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