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-26842 fix TestSnapshotProcedure for branch-2 #4225

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -2272,8 +2272,10 @@ default void snapshot(String snapshotName, TableName tableName,
* @throws SnapshotCreationException if snapshot failed to be taken
* @throws IllegalArgumentException if the snapshot request is formatted incorrectly
*/
void snapshot(SnapshotDescription snapshot)
throws IOException, SnapshotCreationException, IllegalArgumentException;
default void snapshot(SnapshotDescription snapshot)
throws IOException, SnapshotCreationException, IllegalArgumentException {
get(snapshotAsync(snapshot), getSyncWaitTimeout(), TimeUnit.MILLISECONDS);
}

/**
* Take a snapshot without waiting for the server to complete that snapshot (asynchronous) Only a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2512,87 +2512,51 @@ public CompactionState getCompactionStateForRegion(final byte[] regionName)
return null;
}

@Override
public void snapshot(SnapshotDescription snapshotDesc)
throws IOException, SnapshotCreationException, IllegalArgumentException {
// actually take the snapshot
SnapshotProtos.SnapshotDescription snapshot =
ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotDesc);
SnapshotResponse response = asyncSnapshot(snapshot);
final IsSnapshotDoneRequest request =
IsSnapshotDoneRequest.newBuilder().setSnapshot(snapshot).build();
IsSnapshotDoneResponse done = null;
long start = EnvironmentEdgeManager.currentTime();
long max = response.getExpectedTimeout();
long maxPauseTime = max / this.numRetries;
int tries = 0;
LOG.debug("Waiting a max of " + max + " ms for snapshot '" +
ClientSnapshotDescriptionUtils.toString(snapshot) + "'' to complete. (max " +
maxPauseTime + " ms per retry)");
while (tries == 0
|| ((EnvironmentEdgeManager.currentTime() - start) < max && !done.getDone())) {
try {
// sleep a backoff <= pauseTime amount
long sleep = getPauseTime(tries++);
sleep = sleep > maxPauseTime ? maxPauseTime : sleep;
LOG.debug("(#" + tries + ") Sleeping: " + sleep +
"ms while waiting for snapshot completion.");
Thread.sleep(sleep);
} catch (InterruptedException e) {
throw (InterruptedIOException)new InterruptedIOException("Interrupted").initCause(e);
}
LOG.debug("Getting current status of snapshot from master...");
done = executeCallable(new MasterCallable<IsSnapshotDoneResponse>(getConnection(),
getRpcControllerFactory()) {
@Override
protected IsSnapshotDoneResponse rpcCall() throws Exception {
return master.isSnapshotDone(getRpcController(), request);
}
});
}
if (!done.getDone()) {
throw new SnapshotCreationException("Snapshot '" + snapshot.getName()
+ "' wasn't completed in expectedTime:" + max + " ms", snapshotDesc);
}
}

@Override
public Future<Void> snapshotAsync(SnapshotDescription snapshotDesc)
throws IOException, SnapshotCreationException {
asyncSnapshot(ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotDesc));
return new ProcedureFuture<Void>(this, null) {
SnapshotResponse resp = asyncSnapshot(ProtobufUtil
.createHBaseProtosSnapshotDesc(snapshotDesc));
// This is for keeping compatibility with old implementation.
// If there is a procId field in the response, then the snapshot will be operated with a
// SnapshotProcedure, otherwise the snapshot will be coordinated by zk.
if (resp.hasProcId()) {
return new SnapshotFuture(this, snapshotDesc, resp.getProcId());
} else {
return new SnapshotFuture(this, snapshotDesc, null);
}
}

@Override
protected Void waitOperationResult(long deadlineTs) throws IOException, TimeoutException {
waitForState(deadlineTs, new WaitForStateCallable() {
private static final class SnapshotFuture extends TableFuture<Void> {
private final SnapshotDescription snapshotDesc;

@Override
public void throwInterruptedException() throws InterruptedIOException {
throw new InterruptedIOException(
"Interrupted while waiting for taking snapshot" + snapshotDesc);
}
public SnapshotFuture(HBaseAdmin admin, SnapshotDescription snapshotDesc, Long procId) {
super(admin, snapshotDesc.getTableName(), procId);
this.snapshotDesc = snapshotDesc;
}

@Override
public void throwTimeoutException(long elapsedTime) throws TimeoutException {
throw new TimeoutException("Snapshot '" + snapshotDesc.getName() +
"' wasn't completed in expectedTime:" + elapsedTime + " ms");
}
@Override
public String getOperationType() {
return "SNAPSHOT";
}

@Override
public boolean checkState(int tries) throws IOException {
return isSnapshotFinished(snapshotDesc);
}
});
return null;
}
};
@Override
protected Void waitOperationResult(long deadlineTs) throws IOException, TimeoutException {
waitForState(deadlineTs, new TableWaitForStateCallable() {
@Override
public boolean checkState(int tries) throws IOException {
return getAdmin().isSnapshotFinished(snapshotDesc);
}
});
return null;
}
}

private SnapshotResponse asyncSnapshot(SnapshotProtos.SnapshotDescription snapshot)
throws IOException {
ClientSnapshotDescriptionUtils.assertSnapshotRequestIsValid(snapshot);
final SnapshotRequest request = SnapshotRequest.newBuilder().setSnapshot(snapshot)
.build();
.setNonceGroup(ng.newNonce()).setNonce(ng.newNonce()).build();
// run the snapshot on the master
return executeCallable(new MasterCallable<SnapshotResponse>(getConnection(),
getRpcControllerFactory()) {
Expand Down

This file was deleted.

Loading