Skip to content

Commit

Permalink
HBASE-27311 The implementation of syncReplicationPeerLock is incomple…
Browse files Browse the repository at this point in the history
…te (#4715)

Signed-off-by: Xin Sun <[email protected]>
  • Loading branch information
Apache9 authored Aug 23, 2022
1 parent 00a719e commit 950ad8d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;
import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;
import org.apache.hadoop.hbase.replication.ReplicationException;
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
import org.apache.yetus.audience.InterfaceAudience;
Expand Down Expand Up @@ -91,13 +92,18 @@ protected void releaseLatch(MasterProcedureEnv env) {

@Override
protected void prePeerModification(MasterProcedureEnv env)
throws IOException, ReplicationException, InterruptedException {
throws IOException, ReplicationException, ProcedureSuspendedException {
MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
if (cpHost != null) {
cpHost.preAddReplicationPeer(peerId, peerConfig);
}
if (peerConfig.isSyncReplication()) {
env.getReplicationPeerManager().acquireSyncReplicationPeerLock();
if (!env.getReplicationPeerManager().tryAcquireSyncReplicationPeerLock()) {
throw suspend(env.getMasterConfiguration(),
backoff -> LOG.warn(
"Can not acquire sync replication peer lock for peer {}, sleep {} secs", peerId,
backoff / 1000));
}
}
env.getReplicationPeerManager().preAddPeer(peerId, peerConfig);
}
Expand All @@ -119,6 +125,20 @@ protected void postPeerModification(MasterProcedureEnv env)
}
}

@Override
protected void afterReplay(MasterProcedureEnv env) {
if (getCurrentState() == getInitialState()) {
// will try to acquire the lock when executing the procedure, no need to acquire it here
return;
}
if (peerConfig.isSyncReplication()) {
if (!env.getReplicationPeerManager().tryAcquireSyncReplicationPeerLock()) {
throw new IllegalStateException(
"Can not acquire sync replication peer lock for peer " + peerId);
}
}
}

@Override
protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
super.serializeStateData(serializer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected ModifyPeerProcedure(String peerId) {
* all checks passes then the procedure can not be rolled back any more.
*/
protected abstract void prePeerModification(MasterProcedureEnv env)
throws IOException, ReplicationException, InterruptedException;
throws IOException, ReplicationException, ProcedureSuspendedException;

protected abstract void updatePeerStorage(MasterProcedureEnv env) throws ReplicationException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ private boolean isStringEquals(String s1, String s2) {
return s1.equals(s2);
}

public void acquireSyncReplicationPeerLock() throws InterruptedException {
syncReplicationPeerLock.acquire();
public boolean tryAcquireSyncReplicationPeerLock() {
return syncReplicationPeerLock.tryAcquire();
}

public void releaseSyncReplicationPeerLock() {
Expand Down

0 comments on commit 950ad8d

Please sign in to comment.