Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-26867 Introduce a FlushProcedure #4246

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
import org.apache.hadoop.hbase.ClusterMetricsBuilder;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.NamespaceDescriptor;
Expand Down Expand Up @@ -178,6 +179,8 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushTableRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushTableResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest;
Expand Down Expand Up @@ -927,33 +930,59 @@ public CompletableFuture<Void> flush(TableName tableName) {

@Override
public CompletableFuture<Void> flush(TableName tableName, byte[] columnFamily) {
// This is for keeping compatibility with old implementation.
// If the server version is lower than the client version, it's possible that the
// flushTable method is not present in the server side, if so, we need to fall back
// to the old implementation.
FlushTableRequest request = RequestConverter
.buildFlushTableRequest(tableName, columnFamily, ng.getNonceGroup(), ng.newNonce());
CompletableFuture<Void> procFuture =
this.<FlushTableRequest, FlushTableResponse>procedureCall(tableName, request,
(s, c, req, done) -> s.flushTable(c, req, done), (resp) -> resp.getProcId(),
new FlushTableProcedureBiConsumer(tableName));
// here we use another new CompletableFuture because the
// procFuture is not fully controlled by ourselves.
CompletableFuture<Void> future = new CompletableFuture<>();
addListener(tableExists(tableName), (exists, err) -> {
if (err != null) {
future.completeExceptionally(err);
} else if (!exists) {
future.completeExceptionally(new TableNotFoundException(tableName));
} else {
addListener(isTableEnabled(tableName), (tableEnabled, err2) -> {
if (err2 != null) {
future.completeExceptionally(err2);
} else if (!tableEnabled) {
future.completeExceptionally(new TableNotEnabledException(tableName));
} else {
Map<String, String> props = new HashMap<>();
if (columnFamily != null) {
props.put(HConstants.FAMILY_KEY_STR, Bytes.toString(columnFamily));
}
addListener(execProcedure(FLUSH_TABLE_PROCEDURE_SIGNATURE, tableName.getNameAsString(),
props), (ret, err3) -> {
if (err3 != null) {
future.completeExceptionally(err3);
addListener(procFuture, (ret, error) -> {
if (error != null) {
if (error instanceof DoNotRetryIOException) {
// usually this is caused by the method is not present on the server or
// the hbase hadoop version does not match the running hadoop version.
// if that happens, we need fall back to the old flush implementation.
LOG.info("Unrecoverable error in master side. Fallback to FlushTableProcedure V1", error);
addListener(tableExists(tableName), (exists, err) -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better abstract this to a seprated method and call it legacyFlush(or something else, I'm not good at naming in English...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks Duo.

if (err != null) {
future.completeExceptionally(err);
} else if (!exists) {
future.completeExceptionally(new TableNotFoundException(tableName));
} else {
addListener(isTableEnabled(tableName), (tableEnabled, err2) -> {
if (err2 != null) {
future.completeExceptionally(err2);
} else if (!tableEnabled) {
future.completeExceptionally(new TableNotEnabledException(tableName));
} else {
future.complete(ret);
Map<String, String> props = new HashMap<>();
if (columnFamily != null) {
props.put(HConstants.FAMILY_KEY_STR, Bytes.toString(columnFamily));
}
addListener(execProcedure(FLUSH_TABLE_PROCEDURE_SIGNATURE,
tableName.getNameAsString(), props), (ret2, err3) -> {
if (err3 != null) {
future.completeExceptionally(err3);
} else {
future.complete(ret2);
}
});
}
});
}
});
}
});
} else {
future.completeExceptionally(error);
}
} else {
future.complete(ret);
}
});
return future;
Expand Down Expand Up @@ -2628,6 +2657,18 @@ String getOperationType() {
}
}

private static class FlushTableProcedureBiConsumer extends TableProcedureBiConsumer {

FlushTableProcedureBiConsumer(TableName tableName) {
super(tableName);
}

@Override
String getOperationType() {
return "FLUSH";
}
}

private static class ModifyTableProcedureBiConsumer extends TableProcedureBiConsumer {

ModifyTableProcedureBiConsumer(AsyncAdmin admin, TableName tableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DisableTableRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableCatalogJanitorRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.EnableTableRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushTableRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest;
Expand Down Expand Up @@ -813,6 +814,16 @@ public static GetOnlineRegionRequest buildGetOnlineRegionRequest() {
return GetOnlineRegionRequest.newBuilder().build();
}

public static FlushTableRequest buildFlushTableRequest(final TableName tableName,
final byte[] columnFamily, final long nonceGroup, final long nonce) {
FlushTableRequest.Builder builder = FlushTableRequest.newBuilder();
builder.setTableName(ProtobufUtil.toProtoTableName(tableName));
if (columnFamily != null) {
builder.setColumnFamily(UnsafeByteOperations.unsafeWrap(columnFamily));
}
return builder.setNonceGroup(nonceGroup).setNonce(nonce).build();
}

/**
* Create a protocol buffer FlushRegionRequest for a given region name
* @param regionName the name of the region to get info
Expand Down
14 changes: 14 additions & 0 deletions hbase-protocol-shaded/src/main/protobuf/server/master/Master.proto
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ message ModifyTableResponse {
optional uint64 proc_id = 1;
}

message FlushTableRequest {
required TableName table_name = 1;
optional bytes column_family = 2;
optional uint64 nonce_group = 3 [default = 0];
optional uint64 nonce = 4 [default = 0];
}

message FlushTableResponse {
optional uint64 proc_id = 1;
}

/* Namespace-level protobufs */

message CreateNamespaceRequest {
Expand Down Expand Up @@ -1197,6 +1208,9 @@ service MasterService {

rpc ModifyColumnStoreFileTracker(ModifyColumnStoreFileTrackerRequest)
returns(ModifyColumnStoreFileTrackerResponse);

rpc FlushTable(FlushTableRequest)
returns(FlushTableResponse);
}

// HBCK Service definitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ message RestoreParentToChildRegionsPair {
required string child2_region_name = 3;
}

enum FlushTableState {
FLUSH_TABLE_PREPARE = 1;
FLUSH_TABLE_FLUSH_REGIONS = 2;
}

message FlushTableProcedureStateData {
required TableName table_name = 1;
optional bytes column_family = 2;
}

message FlushRegionProcedureStateData {
required RegionInfo region = 1;
optional bytes column_family = 2;
}

message FlushRegionParameter {
required RegionInfo region = 1;
optional bytes column_family = 2;
}

enum SnapshotState {
SNAPSHOT_PREPARE = 1;
SNAPSHOT_PRE_OPERATION = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,14 @@ public enum EventType {
*
* RS_VERIFY_SNAPSHOT
*/
RS_VERIFY_SNAPSHOT(88, ExecutorType.RS_SNAPSHOT_OPERATIONS);
RS_VERIFY_SNAPSHOT(88, ExecutorType.RS_SNAPSHOT_OPERATIONS),

/**
* RS flush regions.<br>
*
* RS_FLUSH_OPERATIONS
*/
RS_FLUSH_REGIONS(89, ExecutorType.RS_FLUSH_OPERATIONS);

private final int code;
private final ExecutorType executor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public enum ExecutorType {
RS_SWITCH_RPC_THROTTLE(33),
RS_IN_MEMORY_COMPACTION(34),
RS_CLAIM_REPLICATION_QUEUE(35),
RS_SNAPSHOT_OPERATIONS(36);
RS_SNAPSHOT_OPERATIONS(36),
RS_FLUSH_OPERATIONS(37);

ExecutorType(int value) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import org.apache.hadoop.hbase.master.procedure.DeleteTableProcedure;
import org.apache.hadoop.hbase.master.procedure.DisableTableProcedure;
import org.apache.hadoop.hbase.master.procedure.EnableTableProcedure;
import org.apache.hadoop.hbase.master.procedure.FlushTableProcedure;
import org.apache.hadoop.hbase.master.procedure.InitMetaProcedure;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
Expand Down Expand Up @@ -2619,6 +2620,35 @@ protected String getDescription() {
});
}

@Override
public long flushTable(TableName tableName,
byte[] columnFamily, long nonceGroup, long nonce) throws IOException {
checkInitialized();

if (!getConfiguration().getBoolean(
MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED,
MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED_DEFAULT)) {
throw new DoNotRetryIOException("FlushProcedure is DISABLED");
}

return MasterProcedureUtil.submitProcedure(
new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
@Override
protected void run() throws IOException {
getMaster().getMasterCoprocessorHost().preTableFlush(tableName);
LOG.info(getClientIdAuditPrefix() + " flush " + tableName);
submitProcedure(new FlushTableProcedure(procedureExecutor.getEnvironment(),
tableName, columnFamily));
getMaster().getMasterCoprocessorHost().postTableFlush(tableName);
}

@Override
protected String getDescription() {
return "FlushTableProcedure";
}
});
}

private long modifyTable(final TableName tableName,
final TableDescriptorGetter newDescriptorGetter, final long nonceGroup, final long nonce,
final boolean shouldCheckDescriptor) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushTableRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FlushTableResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest;
Expand Down Expand Up @@ -3541,4 +3543,17 @@ public ReplicateWALEntryResponse replicateToReplica(RpcController controller,
ReplicateWALEntryRequest request) throws ServiceException {
throw new ServiceException(new DoNotRetryIOException("Unsupported method on master"));
}

@Override
public FlushTableResponse flushTable(RpcController controller,
FlushTableRequest req) throws ServiceException {
TableName tableName = ProtobufUtil.toTableName(req.getTableName());
byte[] columnFamily = req.hasColumnFamily() ? req.getColumnFamily().toByteArray() : null;
try {
long procId = server.flushTable(tableName, columnFamily, req.getNonceGroup(), req.getNonce());
return FlushTableResponse.newBuilder().setProcId(procId).build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ long disableTable(
final long nonceGroup,
final long nonce) throws IOException;

/**
* Flush an existing table
* @param tableName The table name
* @param columnFamily The column family
* @param nonceGroup the nonce group
* @param nonce the nonce
* @return the flush procedure id
*/
long flushTable(
final TableName tableName,
final byte[] columnFamily,
final long nonceGroup,
final long nonce) throws IOException;

/**
* Add a new column to an existing table
Expand Down
Loading