HBASE-26654 ModifyTableDescriptorProcedure shoud load TableDescriptor while executing (#4034)

Signed-off-by: GeorryHuang <huangzhuoyue@apache.org>
This commit is contained in:
Duo Zhang 2022-01-16 16:25:28 +08:00 committed by GitHub
parent bc5a5af1bc
commit c9bcd87b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 14 deletions

View File

@ -655,6 +655,6 @@ enum ModifyTableDescriptorState {
} }
message ModifyTableDescriptorStateData { message ModifyTableDescriptorStateData {
required TableSchema unmodified_table_schema = 1; required TableName table_name = 1;
optional TableSchema modified_table_schema = 2; optional TableSchema modified_table_schema = 2;
} }

View File

@ -121,7 +121,7 @@ public class RollingUpgradeChore extends ScheduledChore {
for (Map.Entry<String, TableDescriptor> entry : migrateSFTTables.entrySet()) { for (Map.Entry<String, TableDescriptor> entry : migrateSFTTables.entrySet()) {
TableDescriptor tableDescriptor = entry.getValue(); TableDescriptor tableDescriptor = entry.getValue();
InitializeStoreFileTrackerProcedure proc = new InitializeStoreFileTrackerProcedure( InitializeStoreFileTrackerProcedure proc = new InitializeStoreFileTrackerProcedure(
procedureExecutor.getEnvironment(), tableDescriptor); procedureExecutor.getEnvironment(), tableDescriptor.getTableName());
procedureExecutor.submitProcedure(proc); procedureExecutor.submitProcedure(proc);
processingProcs.add(proc); processingProcs.add(proc);
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.master.procedure; package org.apache.hadoop.hbase.master.procedure;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptor;
@ -44,20 +45,21 @@ public abstract class ModifyTableDescriptorProcedure
private static final Logger LOG = LoggerFactory.getLogger(ModifyTableDescriptorProcedure.class); private static final Logger LOG = LoggerFactory.getLogger(ModifyTableDescriptorProcedure.class);
private TableDescriptor unmodifiedTableDescriptor; private TableName tableName;
private TableDescriptor modifiedTableDescriptor; private TableDescriptor modifiedTableDescriptor;
protected ModifyTableDescriptorProcedure() { protected ModifyTableDescriptorProcedure() {
} }
protected ModifyTableDescriptorProcedure(MasterProcedureEnv env, TableDescriptor unmodified) { protected ModifyTableDescriptorProcedure(MasterProcedureEnv env, TableName tableName) {
super(env); super(env);
this.unmodifiedTableDescriptor = unmodified; this.tableName = Objects.requireNonNull(tableName);
} }
@Override @Override
public TableName getTableName() { public TableName getTableName() {
return unmodifiedTableDescriptor.getTableName(); return tableName;
} }
@Override @Override
@ -82,7 +84,12 @@ public abstract class ModifyTableDescriptorProcedure
try { try {
switch (state) { switch (state) {
case MODIFY_TABLE_DESCRIPTOR_PREPARE: case MODIFY_TABLE_DESCRIPTOR_PREPARE:
Optional<TableDescriptor> modified = modify(env, unmodifiedTableDescriptor); TableDescriptor current = env.getMasterServices().getTableDescriptors().get(tableName);
if (current == null) {
LOG.info("Table {} does not exist, skip modifying", tableName);
return Flow.NO_MORE_STATE;
}
Optional<TableDescriptor> modified = modify(env, current);
if (modified.isPresent()) { if (modified.isPresent()) {
modifiedTableDescriptor = modified.get(); modifiedTableDescriptor = modified.get();
setNextState(ModifyTableDescriptorState.MODIFY_TABLE_DESCRIPTOR_UPDATE); setNextState(ModifyTableDescriptorState.MODIFY_TABLE_DESCRIPTOR_UPDATE);
@ -108,6 +115,15 @@ public abstract class ModifyTableDescriptorProcedure
return Flow.HAS_MORE_STATE; return Flow.HAS_MORE_STATE;
} }
@Override
protected boolean holdLock(MasterProcedureEnv env) {
// here we want to make sure that our modification result will not be overwrite by other MTPs,
// so we set holdLock to true. Since we do not need to schedule any sub procedures, especially
// no remote procedures, so it is OK for us a hold the lock all the time, it will not hurt the
// availability too much.
return true;
}
@Override @Override
protected void rollbackState(MasterProcedureEnv env, ModifyTableDescriptorState state) protected void rollbackState(MasterProcedureEnv env, ModifyTableDescriptorState state)
throws IOException, InterruptedException { throws IOException, InterruptedException {
@ -141,7 +157,7 @@ public abstract class ModifyTableDescriptorProcedure
protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
super.serializeStateData(serializer); super.serializeStateData(serializer);
ModifyTableDescriptorStateData.Builder builder = ModifyTableDescriptorStateData.newBuilder() ModifyTableDescriptorStateData.Builder builder = ModifyTableDescriptorStateData.newBuilder()
.setUnmodifiedTableSchema(ProtobufUtil.toTableSchema(unmodifiedTableDescriptor)); .setTableName(ProtobufUtil.toProtoTableName(tableName));
if (modifiedTableDescriptor != null) { if (modifiedTableDescriptor != null) {
builder.setModifiedTableSchema(ProtobufUtil.toTableSchema(modifiedTableDescriptor)); builder.setModifiedTableSchema(ProtobufUtil.toTableSchema(modifiedTableDescriptor));
} }
@ -153,7 +169,7 @@ public abstract class ModifyTableDescriptorProcedure
super.deserializeStateData(serializer); super.deserializeStateData(serializer);
ModifyTableDescriptorStateData data = ModifyTableDescriptorStateData data =
serializer.deserialize(ModifyTableDescriptorStateData.class); serializer.deserialize(ModifyTableDescriptorStateData.class);
unmodifiedTableDescriptor = ProtobufUtil.toTableDescriptor(data.getUnmodifiedTableSchema()); tableName = ProtobufUtil.toTableName(data.getTableName());
if (data.hasModifiedTableSchema()) { if (data.hasModifiedTableSchema()) {
modifiedTableDescriptor = ProtobufUtil.toTableDescriptor(data.getModifiedTableSchema()); modifiedTableDescriptor = ProtobufUtil.toTableDescriptor(data.getModifiedTableSchema());
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.regionserver.storefiletracker; package org.apache.hadoop.hbase.regionserver.storefiletracker;
import java.util.Optional; import java.util.Optional;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
@ -33,8 +34,8 @@ public class InitializeStoreFileTrackerProcedure extends ModifyTableDescriptorPr
public InitializeStoreFileTrackerProcedure(){} public InitializeStoreFileTrackerProcedure(){}
public InitializeStoreFileTrackerProcedure(MasterProcedureEnv env, TableDescriptor unmodified) { public InitializeStoreFileTrackerProcedure(MasterProcedureEnv env, TableName tableName) {
super(env, unmodified); super(env, tableName);
} }
@Override @Override

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.rsgroup;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
@ -38,8 +39,8 @@ public class MigrateRSGroupProcedure extends ModifyTableDescriptorProcedure {
public MigrateRSGroupProcedure() { public MigrateRSGroupProcedure() {
} }
public MigrateRSGroupProcedure(MasterProcedureEnv env, TableDescriptor unmodified) { public MigrateRSGroupProcedure(MasterProcedureEnv env, TableName tableName) {
super(env, unmodified); super(env, tableName);
} }
@Override @Override

View File

@ -528,7 +528,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
// master first and then region server, so after all the region servers has been reopened, // master first and then region server, so after all the region servers has been reopened,
// the new TableDescriptor will be loaded. // the new TableDescriptor will be loaded.
MigrateRSGroupProcedure proc = MigrateRSGroupProcedure proc =
new MigrateRSGroupProcedure(procExec.getEnvironment(), oldTd); new MigrateRSGroupProcedure(procExec.getEnvironment(), tableName);
procExec.submitProcedure(proc); procExec.submitProcedure(proc);
procs.add(proc); procs.add(proc);
} }