HBASE-19936 Introduce a new base class for replication peer procedure
This commit is contained in:
parent
abaa80f26e
commit
d1e775e35e
|
@ -401,7 +401,7 @@ message RefreshPeerParameter {
|
||||||
required ServerName target_server = 3;
|
required ServerName target_server = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ModifyPeerStateData {
|
message PeerProcedureStateData {
|
||||||
required string peer_id = 1;
|
required string peer_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
/**
|
||||||
|
* 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.replication;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
|
||||||
|
import org.apache.hadoop.hbase.master.procedure.PeerProcedureInterface;
|
||||||
|
import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;
|
||||||
|
import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
|
||||||
|
import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
|
||||||
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerProcedureStateData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base class for all replication peer related procedure.
|
||||||
|
*/
|
||||||
|
@InterfaceAudience.Private
|
||||||
|
public abstract class AbstractPeerProcedure<TState>
|
||||||
|
extends StateMachineProcedure<MasterProcedureEnv, TState> implements PeerProcedureInterface {
|
||||||
|
|
||||||
|
protected String peerId;
|
||||||
|
|
||||||
|
private volatile boolean locked;
|
||||||
|
|
||||||
|
// used to keep compatible with old client where we can only returns after updateStorage.
|
||||||
|
protected ProcedurePrepareLatch latch;
|
||||||
|
|
||||||
|
protected AbstractPeerProcedure() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AbstractPeerProcedure(String peerId) {
|
||||||
|
this.peerId = peerId;
|
||||||
|
this.latch = ProcedurePrepareLatch.createLatch(2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProcedurePrepareLatch getLatch() {
|
||||||
|
return latch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPeerId() {
|
||||||
|
return peerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LockState acquireLock(MasterProcedureEnv env) {
|
||||||
|
if (env.getProcedureScheduler().waitPeerExclusiveLock(this, peerId)) {
|
||||||
|
return LockState.LOCK_EVENT_WAIT;
|
||||||
|
}
|
||||||
|
locked = true;
|
||||||
|
return LockState.LOCK_ACQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void releaseLock(MasterProcedureEnv env) {
|
||||||
|
locked = false;
|
||||||
|
env.getProcedureScheduler().wakePeerExclusiveLock(this, peerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean holdLock(MasterProcedureEnv env) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean hasLock(MasterProcedureEnv env) {
|
||||||
|
return locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
|
||||||
|
super.serializeStateData(serializer);
|
||||||
|
serializer.serialize(PeerProcedureStateData.newBuilder().setPeerId(peerId).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException {
|
||||||
|
super.deserializeStateData(serializer);
|
||||||
|
peerId = serializer.deserialize(PeerProcedureStateData.class).getPeerId();
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,52 +19,30 @@ package org.apache.hadoop.hbase.master.replication;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
|
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
|
||||||
import org.apache.hadoop.hbase.master.procedure.PeerProcedureInterface;
|
|
||||||
import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;
|
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.procedure2.ProcedureSuspendedException;
|
||||||
import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
|
import org.apache.hadoop.hbase.procedure2.ProcedureYieldException;
|
||||||
import org.apache.hadoop.hbase.procedure2.StateMachineProcedure;
|
|
||||||
import org.apache.hadoop.hbase.replication.ReplicationException;
|
import org.apache.hadoop.hbase.replication.ReplicationException;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ModifyPeerStateData;
|
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationState;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class for all replication peer related procedure.
|
* The base class for all replication peer related procedure except sync replication state
|
||||||
|
* transition.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public abstract class ModifyPeerProcedure
|
public abstract class ModifyPeerProcedure extends AbstractPeerProcedure<PeerModificationState> {
|
||||||
extends StateMachineProcedure<MasterProcedureEnv, PeerModificationState>
|
|
||||||
implements PeerProcedureInterface {
|
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ModifyPeerProcedure.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ModifyPeerProcedure.class);
|
||||||
|
|
||||||
protected String peerId;
|
|
||||||
|
|
||||||
private volatile boolean locked;
|
|
||||||
|
|
||||||
// used to keep compatible with old client where we can only returns after updateStorage.
|
|
||||||
protected ProcedurePrepareLatch latch;
|
|
||||||
|
|
||||||
protected ModifyPeerProcedure() {
|
protected ModifyPeerProcedure() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ModifyPeerProcedure(String peerId) {
|
protected ModifyPeerProcedure(String peerId) {
|
||||||
this.peerId = peerId;
|
super(peerId);
|
||||||
this.latch = ProcedurePrepareLatch.createLatch(2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProcedurePrepareLatch getLatch() {
|
|
||||||
return latch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPeerId() {
|
|
||||||
return peerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,31 +127,6 @@ public abstract class ModifyPeerProcedure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected LockState acquireLock(MasterProcedureEnv env) {
|
|
||||||
if (env.getProcedureScheduler().waitPeerExclusiveLock(this, peerId)) {
|
|
||||||
return LockState.LOCK_EVENT_WAIT;
|
|
||||||
}
|
|
||||||
locked = true;
|
|
||||||
return LockState.LOCK_ACQUIRED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void releaseLock(MasterProcedureEnv env) {
|
|
||||||
locked = false;
|
|
||||||
env.getProcedureScheduler().wakePeerExclusiveLock(this, peerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean holdLock(MasterProcedureEnv env) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean hasLock(MasterProcedureEnv env) {
|
|
||||||
return locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void rollbackState(MasterProcedureEnv env, PeerModificationState state)
|
protected void rollbackState(MasterProcedureEnv env, PeerModificationState state)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
|
@ -199,16 +152,4 @@ public abstract class ModifyPeerProcedure
|
||||||
protected PeerModificationState getInitialState() {
|
protected PeerModificationState getInitialState() {
|
||||||
return PeerModificationState.PRE_PEER_MODIFICATION;
|
return PeerModificationState.PRE_PEER_MODIFICATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
|
|
||||||
super.serializeStateData(serializer);
|
|
||||||
serializer.serialize(ModifyPeerStateData.newBuilder().setPeerId(peerId).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException {
|
|
||||||
super.deserializeStateData(serializer);
|
|
||||||
peerId = serializer.deserialize(ModifyPeerStateData.class).getPeerId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue