From 94d778420d6e8650056abd812c7793a9edadc40d Mon Sep 17 00:00:00 2001 From: comnetwork Date: Mon, 15 Aug 2022 22:14:35 +0800 Subject: [PATCH] HBASE-27303 Unnecessary replication to secondary region replicas should avoid when WAL.sync throws Exception --- .../org/apache/hadoop/hbase/regionserver/HRegion.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 951758d6b424..4fce06587415 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -8040,11 +8040,17 @@ private WriteEntry doWALAppend(WALEdit walEdit, BatchOperation batchOp, try { long txid = this.wal.appendData(this.getRegionInfo(), walKey, walEdit); WriteEntry writeEntry = walKey.getWriteEntry(); - this.attachRegionReplicationInWALAppend(batchOp, miniBatchOp, walKey, walEdit, writeEntry); // Call sync on our edit. if (txid != 0) { sync(txid, batchOp.durability); } + /** + * If above {@link HRegion#sync} throws Exception, the RegionServer should be aborted and + * following {@link BatchOperation#writeMiniBatchOperationsToMemStore} will not be executed, + * so there is no need to replicate to secondary replica, for this reason here we attach the + * region replication action after the {@link HRegion#sync} is successful. + */ + this.attachRegionReplicationInWALAppend(batchOp, miniBatchOp, walKey, walEdit, writeEntry); return writeEntry; } catch (IOException ioe) { if (walKey.getWriteEntry() != null) {