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.replication.regionserver; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Class that handles the recovered source of a replication stream, which is transfered from another 024 * dead region server. This will be closed when all logs are pushed to peer cluster. 025 */ 026@InterfaceAudience.Private 027public class RecoveredReplicationSource extends ReplicationSource { 028 029 @Override 030 protected void startShippers() { 031 for (String walGroupId : logQueue.getQueues().keySet()) { 032 workerThreads.put(walGroupId, createNewShipper(walGroupId)); 033 } 034 // start shippers after initializing the workerThreads, as in the below postFinish logic, if 035 // workerThreads is empty, we will mark the RecoveredReplicationSource as finished. So if we 036 // start the worker on the fly, it is possible that a shipper has already finished its work and 037 // called postFinish, and find out the workerThreads is empty and then mark the 038 // RecoveredReplicationSource as finish, while the next shipper has not been added to 039 // workerThreads yet. See HBASE-28155 for more details. 040 for (ReplicationSourceShipper shipper : workerThreads.values()) { 041 startShipper(shipper); 042 } 043 } 044 045 @Override 046 protected RecoveredReplicationSourceShipper createNewShipper(String walGroupId, 047 ReplicationSourceWALReader walReader) { 048 return new RecoveredReplicationSourceShipper(conf, walGroupId, this, walReader, queueStorage, 049 () -> { 050 if (workerThreads.isEmpty()) { 051 this.getSourceMetrics().clear(); 052 if (this.getReplicationEndpoint() != null) { 053 this.getReplicationEndpoint().stop(); 054 } 055 manager.finishRecoveredSource(this); 056 } 057 }); 058 } 059}