HBASE-26475 The flush and compact methods in HTU should skip processing secondary replicas (#3868)

Signed-off-by: Xiaolin Ha <haxiaolin@apache.org>
This commit is contained in:
Duo Zhang 2021-11-23 18:31:18 +08:00
parent f8d03d1227
commit 0a51d2b5be
2 changed files with 15 additions and 14 deletions

View File

@ -1467,7 +1467,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
/** /**
* Flushes all caches in the mini hbase cluster * Flushes all caches in the mini hbase cluster
* @throws IOException
*/ */
public void flush() throws IOException { public void flush() throws IOException {
getMiniHBaseCluster().flushcache(); getMiniHBaseCluster().flushcache();
@ -1475,7 +1474,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
/** /**
* Flushes all caches in the mini hbase cluster * Flushes all caches in the mini hbase cluster
* @throws IOException
*/ */
public void flush(TableName tableName) throws IOException { public void flush(TableName tableName) throws IOException {
getMiniHBaseCluster().flushcache(tableName); getMiniHBaseCluster().flushcache(tableName);
@ -1483,7 +1481,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
/** /**
* Compact all regions in the mini hbase cluster * Compact all regions in the mini hbase cluster
* @throws IOException
*/ */
public void compact(boolean major) throws IOException { public void compact(boolean major) throws IOException {
getMiniHBaseCluster().compact(major); getMiniHBaseCluster().compact(major);
@ -1491,7 +1488,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
/** /**
* Compact all of a table's reagion in the mini hbase cluster * Compact all of a table's reagion in the mini hbase cluster
* @throws IOException
*/ */
public void compact(TableName tableName, boolean major) throws IOException { public void compact(TableName tableName, boolean major) throws IOException {
getMiniHBaseCluster().compact(tableName, major); getMiniHBaseCluster().compact(tableName, major);

View File

@ -24,9 +24,9 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.HRegion.FlushResult; import org.apache.hadoop.hbase.regionserver.HRegion.FlushResult;
@ -728,6 +728,9 @@ public class MiniHBaseCluster extends HBaseCluster {
} }
private void executeFlush(HRegion region) throws IOException { private void executeFlush(HRegion region) throws IOException {
if (!RegionReplicaUtil.isDefaultReplica(region.getRegionInfo())) {
return;
}
// retry 5 times if we can not flush // retry 5 times if we can not flush
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
FlushResult result = region.flush(true); FlushResult result = region.flush(true);
@ -767,10 +770,11 @@ public class MiniHBaseCluster extends HBaseCluster {
* @throws IOException * @throws IOException
*/ */
public void compact(boolean major) throws IOException { public void compact(boolean major) throws IOException {
for (JVMClusterUtil.RegionServerThread t: for (JVMClusterUtil.RegionServerThread t : this.hbaseCluster.getRegionServers()) {
this.hbaseCluster.getRegionServers()) { for (HRegion r : t.getRegionServer().getOnlineRegionsLocalContext()) {
for(HRegion r: t.getRegionServer().getOnlineRegionsLocalContext()) { if (RegionReplicaUtil.isDefaultReplica(r.getRegionInfo())) {
r.compact(major); r.compact(major);
}
} }
} }
} }
@ -780,11 +784,12 @@ public class MiniHBaseCluster extends HBaseCluster {
* @throws IOException * @throws IOException
*/ */
public void compact(TableName tableName, boolean major) throws IOException { public void compact(TableName tableName, boolean major) throws IOException {
for (JVMClusterUtil.RegionServerThread t: for (JVMClusterUtil.RegionServerThread t : this.hbaseCluster.getRegionServers()) {
this.hbaseCluster.getRegionServers()) { for (HRegion r : t.getRegionServer().getOnlineRegionsLocalContext()) {
for(HRegion r: t.getRegionServer().getOnlineRegionsLocalContext()) { if (r.getTableDescriptor().getTableName().equals(tableName)) {
if(r.getTableDescriptor().getTableName().equals(tableName)) { if (RegionReplicaUtil.isDefaultReplica(r.getRegionInfo())) {
r.compact(major); r.compact(major);
}
} }
} }
} }