Apache9 commented on code in PR #5408: URL: https://github.com/apache/hbase/pull/5408#discussion_r1356842065
########## hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/LogRollProcedure.java: ########## @@ -0,0 +1,215 @@ +/* + * 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 java.util.Optional; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.NamespaceDescriptor; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.TableNotEnabledException; +import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableState; +import org.apache.hadoop.hbase.master.TableStateManager; +import org.apache.hadoop.hbase.master.procedure.CreateNamespaceProcedure; +import org.apache.hadoop.hbase.master.procedure.CreateTableProcedure; +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.hadoop.hbase.util.ModifyRegionUtils; +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; + [email protected] +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_PRE_CHECK_NAMESPACE: + // create backup namespace if not exists + if ( + !env.getMasterServices().getClusterSchema().getTableNamespaceManager() + .doesNamespaceExist(getTableName().getNamespaceAsString()) + ) { + NamespaceDescriptor desc = + NamespaceDescriptor.create(getTableName().getNamespaceAsString()).build(); + addChildProcedure(new CreateNamespaceProcedure(env, desc)); + } + setNextState(LogRollState.LOG_ROLL_PRE_CHECK_TABLES); + return Flow.HAS_MORE_STATE; + case LOG_ROLL_PRE_CHECK_TABLES: + // create backup system table and backup system bulkload table if not exists + List<CreateTableProcedure> toCreate = new ArrayList<>(); + TableStateManager tsm = env.getMasterServices().getTableStateManager(); + createIfNeeded(env, tsm, BackupSystemTable.getTableName(conf), + BackupSystemTable.getSystemTableDescriptor(conf)).ifPresent(toCreate::add); + createIfNeeded(env, tsm, BackupSystemTable.getTableNameForBulkLoadedData(conf), + BackupSystemTable.getSystemTableForBulkLoadedDataDescriptor(conf)) + .ifPresent(toCreate::add); + if (!toCreate.isEmpty()) { + addChildProcedure(toCreate.toArray(new CreateTableProcedure[0])); + } + setNextState(LogRollState.LOG_ROLL_ROLL_LOG_ON_EACH_RS); + return Flow.HAS_MORE_STATE; + case LOG_ROLL_ROLL_LOG_ON_EACH_RS: + final List<ServerName> onlineServers = + env.getMasterServices().getServerManager().getOnlineServersList(); Review Comment: We need to make sure there is no problem. Usually it is not fixed by locking, but something like fencing. For example, before rolling we have done some preparing, and when rolling, even if we miss some new region servers, it does not cause any problems. -- 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]
