-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2320469
commit 2addcdc
Showing
5 changed files
with
269 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
hbase-server/src/main/java/org/apache/hadoop/hbase/master/migrate/RollingUpgradeChore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* 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.migrate; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.HBaseIOException; | ||
import org.apache.hadoop.hbase.ScheduledChore; | ||
import org.apache.hadoop.hbase.Stoppable; | ||
import org.apache.hadoop.hbase.TableDescriptors; | ||
import org.apache.hadoop.hbase.client.TableDescriptor; | ||
import org.apache.hadoop.hbase.client.TableDescriptorBuilder; | ||
import org.apache.hadoop.hbase.master.MasterServices; | ||
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
import org.apache.hadoop.hbase.master.procedure.SilentModifyTableProcedure; | ||
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; | ||
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* To avoid too many migrating/upgrade threads to be submitted at the time during master | ||
* initialization, RollingUpgradeChore handler all rolling-upgrade tasks. | ||
* */ | ||
@InterfaceAudience.Private | ||
public class RollingUpgradeChore extends ScheduledChore { | ||
|
||
public static final String ROLLING_UPGRADE_CHORE_ENABLED_KEY = | ||
"hbase.master.rolling.upgrade.chore.enabled"; | ||
public static final boolean DEFAULT_ROLLING_UPGRADE_CHORE_ENABLED = true; | ||
|
||
static final String ROLLING_UPGRADE_CHORE_TIMEUNIT_KEY = | ||
"hbase.master.rolling.upgrade.chore.timeunit"; | ||
static final String DEFAULT_ROLLING_UPGRADE_CHORE_TIMEUNIT_KEY = TimeUnit.MILLISECONDS.name(); | ||
|
||
static final String ROLLING_UPGRADE_CHORE_PERIOD_KEY = "hbase.master.rolling.upgrade.chore.period"; | ||
static final int DFAULT_ROLLING_UPGRADE_CHORE_PERIOD = 1000 * 60 * 5; // 5 minutes in millis | ||
|
||
static final String ROLLING_UPGRADE_CHORE_DELAY_KEY = "hbase.master.mob.cleaner.period"; | ||
static final long DEFAULT_ROLLING_UPGRADE_CHORE_DELAY = 1000L * 60 * 10; // 10 minutes in millis | ||
|
||
private final static Logger LOG = LoggerFactory.getLogger(RollingUpgradeChore.class); | ||
private Map<String, Long> tableToProcId; | ||
ProcedureExecutor<MasterProcedureEnv> procedureExecutor; | ||
private Configuration conf; | ||
private TableDescriptors tableDescriptors; | ||
|
||
public RollingUpgradeChore(MasterServices masterServices) { | ||
this(masterServices.getConfiguration(), masterServices.getMasterProcedureExecutor(), masterServices.getTableDescriptors(), masterServices); | ||
} | ||
|
||
private RollingUpgradeChore(Configuration conf, ProcedureExecutor<MasterProcedureEnv> procedureExecutor, TableDescriptors tableDescriptors, Stoppable stopper){ | ||
super(RollingUpgradeChore.class.getSimpleName(), stopper, | ||
conf.getInt(ROLLING_UPGRADE_CHORE_PERIOD_KEY, DFAULT_ROLLING_UPGRADE_CHORE_PERIOD), | ||
conf.getLong(ROLLING_UPGRADE_CHORE_DELAY_KEY, DEFAULT_ROLLING_UPGRADE_CHORE_DELAY), | ||
TimeUnit.valueOf(conf.get(ROLLING_UPGRADE_CHORE_TIMEUNIT_KEY, DEFAULT_ROLLING_UPGRADE_CHORE_TIMEUNIT_KEY))); | ||
this.conf = conf; | ||
this.procedureExecutor = procedureExecutor; | ||
this.tableDescriptors = tableDescriptors; | ||
this.tableToProcId = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
protected void chore() { | ||
Map<String, TableDescriptor> migrateTables; | ||
try { | ||
migrateTables = tableDescriptors.getAll().entrySet().stream().filter(entry -> { | ||
TableDescriptor td = entry.getValue(); | ||
return StringUtils.isEmpty(td.getValue(StoreFileTrackerFactory.TRACKER_IMPL)); | ||
}).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); | ||
} catch (IOException e) { | ||
LOG.warn("Failed to migrate StoreFileTracker", e); | ||
return; | ||
} | ||
|
||
if (migrateTables.isEmpty()) { | ||
shutdown(); | ||
return; | ||
} | ||
|
||
for (Map.Entry<String, TableDescriptor> entry : migrateTables.entrySet()) { | ||
String tableName = entry.getKey(); | ||
TableDescriptor tableDescriptor = entry.getValue(); | ||
Long procId = tableToProcId.get(tableName); | ||
if (procId != null) { | ||
if (procedureExecutor.isFinished(procId)) { | ||
tableToProcId.remove(tableName); | ||
} | ||
continue; | ||
} | ||
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor); | ||
StoreFileTrackerFactory.persistTrackerConfig(conf, builder); | ||
SilentModifyTableProcedure procedure; | ||
try { | ||
procedure = new SilentModifyTableProcedure( | ||
procedureExecutor.getEnvironment(), builder.build()); | ||
} catch (HBaseIOException e) { | ||
LOG.warn("Failed to build a SilentModifyTableProcedure for {}", tableName); | ||
continue; | ||
} | ||
Long newProcId = procedureExecutor.submitProcedure(procedure); | ||
tableToProcId.put(tableName, newProcId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...er/src/main/java/org/apache/hadoop/hbase/master/procedure/SilentModifyTableProcedure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* 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 java.io.IOException; | ||
import org.apache.hadoop.hbase.DoNotRetryIOException; | ||
import org.apache.hadoop.hbase.HBaseIOException; | ||
import org.apache.hadoop.hbase.client.TableDescriptor; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ModifyTableState; | ||
|
||
@InterfaceAudience.Private | ||
/** | ||
* A extension of ModifyTableProcedure. Only update TableDescriptor of table and not reopen any regions. | ||
* After we introduced StoreFileTracker, update TableDescriptors directly become a dangerous action | ||
* because while ModifyTableProcedure reopening regions, update table descriptor would probably cause | ||
* different StoreFileTracker implementations online at the same time. | ||
* */ | ||
public class SilentModifyTableProcedure | ||
extends ModifyTableProcedure { | ||
private static final Logger LOG = LoggerFactory.getLogger(SilentModifyTableProcedure.class); | ||
|
||
public SilentModifyTableProcedure(final MasterProcedureEnv env, final TableDescriptor htd) throws HBaseIOException{ | ||
super(env, htd); | ||
preflightChecks(env, null); | ||
} | ||
|
||
@Override | ||
protected Flow executeFromState(final MasterProcedureEnv env, final ModifyTableState state) | ||
throws InterruptedException { | ||
LOG.trace("{} execute state={}", this, state); | ||
try { | ||
switch (state) { | ||
case MODIFY_TABLE_PREPARE: | ||
prepareModify(env); | ||
setNextState(ModifyTableState.MODIFY_TABLE_UPDATE_TABLE_DESCRIPTOR); | ||
break; | ||
case MODIFY_TABLE_UPDATE_TABLE_DESCRIPTOR: | ||
updateTableDescriptor(env); | ||
return Flow.NO_MORE_STATE; | ||
default: | ||
throw new UnsupportedOperationException("unhandled state=" + state); | ||
} | ||
} catch (IOException e) { | ||
if (isRollbackSupported(state)) { | ||
setFailure("master-silent-modify-table", e); | ||
} else { | ||
LOG.warn("Retriable error trying to silent-modify table={} (in state={})", getTableName(), state, | ||
e); | ||
} | ||
} | ||
return Flow.HAS_MORE_STATE; | ||
} | ||
|
||
@Override | ||
protected final void prepareModify(MasterProcedureEnv env) throws IOException { | ||
super.prepareModify(env); | ||
if (this.deleteColumnFamilyInModify) { | ||
throw new DoNotRetryIOException("Table " + getTableName().toString() | ||
+ " are using SilentModifyTableProcedure, which do not allow delete column family!"); | ||
} | ||
|
||
final int oldReplicaCount = unmodifiedTableDescriptor.getRegionReplication(); | ||
final int newReplicaCount = modifiedTableDescriptor.getRegionReplication(); | ||
if (newReplicaCount != oldReplicaCount) { | ||
throw new DoNotRetryIOException("Table " + getTableName().toString() | ||
+ " are using SilentModifyTableProcedure, which do not allow change replica count!"); | ||
} | ||
} | ||
|
||
@Override | ||
protected void rollbackState(final MasterProcedureEnv env, final ModifyTableState state) | ||
throws IOException { | ||
//Nothing to do. | ||
} | ||
|
||
@Override | ||
protected boolean isRollbackSupported(final ModifyTableState state) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected ModifyTableState getInitialState() { | ||
return ModifyTableState.MODIFY_TABLE_PREPARE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters