001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master.replication; 019 020import java.io.IOException; 021import org.apache.hadoop.hbase.client.replication.ReplicationPeerConfigUtil; 022import org.apache.hadoop.hbase.master.MasterCoprocessorHost; 023import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 024import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; 025import org.apache.hadoop.hbase.replication.ReplicationException; 026import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 027import org.apache.yetus.audience.InterfaceAudience; 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030 031import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RemovePeerStateData; 032 033/** 034 * The procedure for removing a replication peer. 035 */ 036@InterfaceAudience.Private 037public class RemovePeerProcedure extends ModifyPeerProcedure { 038 039 private static final Logger LOG = LoggerFactory.getLogger(RemovePeerProcedure.class); 040 041 private ReplicationPeerConfig peerConfig; 042 043 public RemovePeerProcedure() { 044 } 045 046 public RemovePeerProcedure(String peerId) { 047 super(peerId); 048 } 049 050 @Override 051 public PeerOperationType getPeerOperationType() { 052 return PeerOperationType.REMOVE; 053 } 054 055 @Override 056 protected void prePeerModification(MasterProcedureEnv env) throws IOException { 057 MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); 058 if (cpHost != null) { 059 cpHost.preRemoveReplicationPeer(peerId); 060 } 061 peerConfig = env.getReplicationPeerManager().preRemovePeer(peerId); 062 } 063 064 @Override 065 protected void updatePeerStorage(MasterProcedureEnv env) throws ReplicationException { 066 env.getReplicationPeerManager().removePeer(peerId); 067 } 068 069 @Override 070 protected void postPeerModification(MasterProcedureEnv env) 071 throws IOException, ReplicationException { 072 env.getReplicationPeerManager().removeAllQueuesAndHFileRefs(peerId); 073 if (peerConfig.isSerial()) { 074 env.getReplicationPeerManager().removeAllLastPushedSeqIds(peerId); 075 } 076 LOG.info("Successfully removed peer {}", peerId); 077 MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); 078 if (cpHost != null) { 079 cpHost.postRemoveReplicationPeer(peerId); 080 } 081 } 082 083 @Override 084 protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { 085 super.serializeStateData(serializer); 086 RemovePeerStateData.Builder builder = RemovePeerStateData.newBuilder(); 087 if (peerConfig != null) { 088 builder.setPeerConfig(ReplicationPeerConfigUtil.convert(peerConfig)); 089 } 090 serializer.serialize(builder.build()); 091 } 092 093 @Override 094 protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { 095 super.deserializeStateData(serializer); 096 RemovePeerStateData data = serializer.deserialize(RemovePeerStateData.class); 097 if (data.hasPeerConfig()) { 098 this.peerConfig = ReplicationPeerConfigUtil.convert(data.getPeerConfig()); 099 } 100 } 101}