diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSink.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSink.java index 7d476774ba0..11019f61290 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSink.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSink.java @@ -72,7 +72,7 @@ public class ReplicationSink { private static final Log LOG = LogFactory.getLog(ReplicationSink.class); private final Configuration conf; - private final Connection sharedHtableCon; + private Connection sharedHtableCon; private final MetricsSink metrics; private final AtomicLong totalReplicatedEdits = new AtomicLong(); @@ -88,7 +88,6 @@ public class ReplicationSink { this.conf = HBaseConfiguration.create(conf); decorateConf(); this.metrics = new MetricsSink(); - this.sharedHtableCon = ConnectionFactory.createConnection(this.conf); } /** @@ -213,7 +212,9 @@ public class ReplicationSink { */ public void stopReplicationSinkServices() { try { - this.sharedHtableCon.close(); + if (this.sharedHtableCon != null) { + this.sharedHtableCon.close(); + } } catch (IOException e) { LOG.warn("IOException while closing the connection", e); // ignoring as we are closing. } @@ -232,6 +233,9 @@ public class ReplicationSink { } Table table = null; try { + if (this.sharedHtableCon == null) { + this.sharedHtableCon = ConnectionFactory.createConnection(this.conf); + } table = this.sharedHtableCon.getTable(tableName); for (List rows : allRows) { table.batch(rows);