Skip to content

Commit c705d80

Browse files
committed
HBASE-26280 Use store file tracker when snapshoting (#3685)
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org> Reviewed-by: Josh Elser <elserj@apache.org>
1 parent 70906cf commit c705d80

File tree

11 files changed

+107
-109
lines changed

11 files changed

+107
-109
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeTableRegionsProcedure.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,8 @@ private List<Path> mergeStoreFiles(MasterProcedureEnv env, HRegionFileSystem reg
612612
List<Path> mergedFiles = new ArrayList<>();
613613
for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
614614
String family = hcd.getNameAsString();
615-
Configuration trackerConfig =
616-
StoreFileTrackerFactory.mergeConfigurations(env.getMasterConfiguration(), htd, hcd);
617-
StoreFileTracker tracker = StoreFileTrackerFactory.create(trackerConfig, family, regionFs);
615+
StoreFileTracker tracker =
616+
StoreFileTrackerFactory.create(env.getMasterConfiguration(), htd, hcd, regionFs);
618617
final Collection<StoreFileInfo> storeFiles = tracker.load();
619618
if (storeFiles != null && storeFiles.size() > 0) {
620619
final Configuration storeConfiguration =

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/SplitTableRegionProcedure.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,8 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
668668
new HashMap<String, Collection<StoreFileInfo>>(htd.getColumnFamilyCount());
669669
for (ColumnFamilyDescriptor cfd : htd.getColumnFamilies()) {
670670
String family = cfd.getNameAsString();
671-
Configuration trackerConfig = StoreFileTrackerFactory.
672-
mergeConfigurations(env.getMasterConfiguration(), htd, htd.getColumnFamily(cfd.getName()));
673-
StoreFileTracker tracker = StoreFileTrackerFactory.create(trackerConfig, family, regionFs);
671+
StoreFileTracker tracker =
672+
StoreFileTrackerFactory.create(env.getMasterConfiguration(), htd, cfd, regionFs);
674673
Collection<StoreFileInfo> sfis = tracker.load();
675674
if (sfis == null) {
676675
continue;

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ void cleanupDaughterRegion(final RegionInfo regionInfo) throws IOException {
598598
* to the proper location in the filesystem.
599599
*
600600
* @param regionInfo daughter {@link org.apache.hadoop.hbase.client.RegionInfo}
601-
* @throws IOException
602601
*/
603602
public Path commitDaughterRegion(final RegionInfo regionInfo, List<Path> allRegionFiles,
604603
MasterProcedureEnv env) throws IOException {
@@ -625,12 +624,8 @@ private void insertRegionFilesIntoStoreTracker(List<Path> allFiles, MasterProced
625624
Map<String, List<StoreFileInfo>> fileInfoMap = new HashMap<>();
626625
for(Path file : allFiles) {
627626
String familyName = file.getParent().getName();
628-
trackerMap.computeIfAbsent(familyName, t -> {
629-
Configuration config = StoreFileTrackerFactory.mergeConfigurations(conf, tblDesc,
630-
tblDesc.getColumnFamily(Bytes.toBytes(familyName)));
631-
return StoreFileTrackerFactory.
632-
create(config, familyName, regionFs);
633-
});
627+
trackerMap.computeIfAbsent(familyName, t -> StoreFileTrackerFactory.create(conf, tblDesc,
628+
tblDesc.getColumnFamily(Bytes.toBytes(familyName)), regionFs));
634629
fileInfoMap.computeIfAbsent(familyName, l -> new ArrayList<>());
635630
List<StoreFileInfo> infos = fileInfoMap.get(familyName);
636631
infos.add(new StoreFileInfo(conf, fs, file, true));
@@ -676,7 +671,6 @@ public void createSplitsDir(RegionInfo daughterA, RegionInfo daughterB) throws I
676671
* this method is invoked on the Master side, then the RegionSplitPolicy will
677672
* NOT have a reference to a Region.
678673
* @return Path to created reference.
679-
* @throws IOException
680674
*/
681675
public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte[] splitRow,
682676
boolean top, RegionSplitPolicy splitPolicy) throws IOException {

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/storefiletracker/StoreFileTrackerFactory.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.hbase.DoNotRetryIOException;
2424
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
25-
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
2625
import org.apache.hadoop.hbase.client.TableDescriptor;
2726
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
2827
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
2928
import org.apache.hadoop.hbase.regionserver.StoreContext;
3029
import org.apache.hadoop.hbase.regionserver.StoreUtils;
31-
import org.apache.hadoop.hbase.util.Bytes;
3230
import org.apache.hadoop.hbase.util.ReflectionUtils;
3331
import org.apache.yetus.audience.InterfaceAudience;
3432
import org.slf4j.Logger;
@@ -113,16 +111,15 @@ public static StoreFileTracker create(Configuration conf, boolean isPrimaryRepli
113111
* Used at master side when splitting/merging regions, as we do not have a Store, thus no
114112
* StoreContext at master side.
115113
*/
116-
public static StoreFileTracker create(Configuration conf, String family,
117-
HRegionFileSystem regionFs) {
118-
ColumnFamilyDescriptorBuilder fDescBuilder =
119-
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family));
120-
StoreContext ctx = StoreContext.getBuilder().withColumnFamilyDescriptor(fDescBuilder.build())
121-
.withRegionFileSystem(regionFs).build();
122-
return StoreFileTrackerFactory.create(conf, true, ctx);
114+
public static StoreFileTracker create(Configuration conf, TableDescriptor td,
115+
ColumnFamilyDescriptor cfd, HRegionFileSystem regionFs) {
116+
StoreContext ctx =
117+
StoreContext.getBuilder().withColumnFamilyDescriptor(cfd).withRegionFileSystem(regionFs)
118+
.withFamilyStoreDirectoryPath(regionFs.getStoreDir(cfd.getNameAsString())).build();
119+
return StoreFileTrackerFactory.create(mergeConfigurations(conf, td, cfd), true, ctx);
123120
}
124121

125-
public static Configuration mergeConfigurations(Configuration global, TableDescriptor table,
122+
private static Configuration mergeConfigurations(Configuration global, TableDescriptor table,
126123
ColumnFamilyDescriptor family) {
127124
return StoreUtils.createStoreConfiguration(global, table, family);
128125
}

hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifest.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
import org.apache.hadoop.hbase.regionserver.HStore;
4848
import org.apache.hadoop.hbase.regionserver.HStoreFile;
4949
import org.apache.hadoop.hbase.regionserver.StoreFileInfo;
50-
import org.apache.hadoop.hbase.util.Bytes;
50+
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTracker;
51+
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
5152
import org.apache.hadoop.hbase.util.CommonFSUtils;
5253
import org.apache.hadoop.hbase.util.FSTableDescriptors;
5354
import org.apache.hadoop.hbase.util.Threads;
@@ -291,17 +292,17 @@ public void addRegion(final Path tableDir, final RegionInfo regionInfo) throws I
291292
addRegion(tableDir, regionInfo, visitor);
292293
}
293294

294-
protected void addRegion(final Path tableDir, final RegionInfo regionInfo, RegionVisitor visitor)
295-
throws IOException {
295+
protected void addRegion(Path tableDir, RegionInfo regionInfo, RegionVisitor visitor)
296+
throws IOException {
296297
boolean isMobRegion = MobUtils.isMobRegionInfo(regionInfo);
297298
try {
298299
Path baseDir = tableDir;
299300
// Open the RegionFS
300301
if (isMobRegion) {
301302
baseDir = CommonFSUtils.getTableDir(MobUtils.getMobHome(conf), regionInfo.getTable());
302303
}
303-
HRegionFileSystem regionFs = HRegionFileSystem.openRegionFromFileSystem(conf, rootFs,
304-
baseDir, regionInfo, true);
304+
HRegionFileSystem regionFs =
305+
HRegionFileSystem.openRegionFromFileSystem(conf, rootFs, baseDir, regionInfo, true);
305306
monitor.rethrowException();
306307

307308
// 1. dump region meta info into the snapshot directory
@@ -317,26 +318,19 @@ protected void addRegion(final Path tableDir, final RegionInfo regionInfo, Regio
317318
// in batches and may miss files being added/deleted. This could be more robust (iteratively
318319
// checking to see if we have all the files until we are sure), but the limit is currently
319320
// 1000 files/batch, far more than the number of store files under a single column family.
320-
Collection<String> familyNames = regionFs.getFamilies();
321-
if (familyNames != null) {
322-
for (String familyName: familyNames) {
323-
Object familyData = visitor.familyOpen(regionData, Bytes.toBytes(familyName));
324-
monitor.rethrowException();
325-
326-
Collection<StoreFileInfo> storeFiles = regionFs.getStoreFiles(familyName);
327-
if (storeFiles == null) {
328-
if (LOG.isDebugEnabled()) {
329-
LOG.debug("No files under family: " + familyName);
330-
}
331-
continue;
332-
}
333-
334-
// 2.1. build the snapshot reference for the store
335-
// iterate through all the store's files and create "references".
336-
addReferenceFiles(visitor, regionData, familyData, storeFiles, false);
337-
338-
visitor.familyClose(regionData, familyData);
321+
for (ColumnFamilyDescriptor cfd : htd.getColumnFamilies()) {
322+
Object familyData = visitor.familyOpen(regionData, cfd.getName());
323+
monitor.rethrowException();
324+
StoreFileTracker tracker = StoreFileTrackerFactory.create(conf, htd, cfd, regionFs);
325+
List<StoreFileInfo> storeFiles = tracker.load();
326+
if (storeFiles.isEmpty()) {
327+
LOG.debug("No files under family: {}", cfd.getNameAsString());
328+
continue;
339329
}
330+
// 2.1. build the snapshot reference for the store
331+
// iterate through all the store's files and create "references".
332+
addReferenceFiles(visitor, regionData, familyData, storeFiles, false);
333+
visitor.familyClose(regionData, familyData);
340334
}
341335
visitor.regionClose(regionData);
342336
} catch (IOException e) {

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner;
3232
import org.apache.hadoop.hbase.mob.MobConstants;
3333
import org.apache.hadoop.hbase.regionserver.FlushLifeCycleTracker;
34+
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
3435
import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils;
3536
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
3637
import org.apache.hadoop.hbase.testclassification.ClientTests;
@@ -93,7 +94,8 @@ public static void setUpBeforeClass() throws Exception {
9394
@Override
9495
protected void createTable() throws IOException, InterruptedException {
9596
MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName,
96-
SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), DelayFlushCoprocessor.class.getName(),
97+
SnapshotTestingUtils.getSplitKeys(), getNumReplicas(),
98+
StoreFileTrackerFactory.Trackers.DEFAULT.name(), DelayFlushCoprocessor.class.getName(),
9799
FAMILY);
98100
}
99101

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobSnapshotFromClient.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.junit.BeforeClass;
2727
import org.junit.ClassRule;
2828
import org.junit.experimental.categories.Category;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3129

3230
/**
3331
* Test create/using/deleting snapshots from the client
@@ -41,8 +39,6 @@ public class TestMobSnapshotFromClient extends TestSnapshotFromClient {
4139
public static final HBaseClassTestRule CLASS_RULE =
4240
HBaseClassTestRule.forClass(TestMobSnapshotFromClient.class);
4341

44-
private static final Logger LOG = LoggerFactory.getLogger(TestMobSnapshotFromClient.class);
45-
4642
/**
4743
* Setup the config for the cluster
4844
* @throws Exception on failure
@@ -60,6 +56,7 @@ protected static void setupConf(Configuration conf) {
6056

6157
@Override
6258
protected void createTable() throws Exception {
63-
MobSnapshotTestingUtils.createMobTable(UTIL, TABLE_NAME, getNumReplicas(), TEST_FAM);
59+
MobSnapshotTestingUtils.createMobTable(UTIL, TABLE_NAME, getNumReplicas(), trackerImpl.name(),
60+
TEST_FAM);
6461
}
6562
}

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.Assert.fail;
2424

2525
import java.util.ArrayList;
26+
import java.util.Arrays;
2627
import java.util.List;
2728
import java.util.regex.Pattern;
2829
import org.apache.hadoop.conf.Configuration;
@@ -32,9 +33,11 @@
3233
import org.apache.hadoop.hbase.HBaseTestingUtil;
3334
import org.apache.hadoop.hbase.HConstants;
3435
import org.apache.hadoop.hbase.TableName;
36+
import org.apache.hadoop.hbase.TableNameTestRule;
3537
import org.apache.hadoop.hbase.TableNotFoundException;
3638
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
3739
import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;
40+
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
3841
import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
3942
import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException;
4043
import org.apache.hadoop.hbase.snapshot.SnapshotManifestV1;
@@ -51,7 +54,10 @@
5154
import org.junit.Rule;
5255
import org.junit.Test;
5356
import org.junit.experimental.categories.Category;
54-
import org.junit.rules.TestName;
57+
import org.junit.runner.RunWith;
58+
import org.junit.runners.Parameterized;
59+
import org.junit.runners.Parameterized.Parameter;
60+
import org.junit.runners.Parameterized.Parameters;
5561
import org.slf4j.Logger;
5662
import org.slf4j.LoggerFactory;
5763

@@ -64,7 +70,8 @@
6470
* <p>
6571
* This is an end-to-end test for the snapshot utility
6672
*/
67-
@Category({LargeTests.class, ClientTests.class})
73+
@RunWith(Parameterized.class)
74+
@Category({ LargeTests.class, ClientTests.class })
6875
public class TestSnapshotFromClient {
6976

7077
@ClassRule
@@ -82,7 +89,16 @@ public class TestSnapshotFromClient {
8289
private static final Pattern MATCH_ALL = Pattern.compile(".*");
8390

8491
@Rule
85-
public TestName name = new TestName();
92+
public TableNameTestRule name = new TableNameTestRule();
93+
94+
@Parameter
95+
public StoreFileTrackerFactory.Trackers trackerImpl;
96+
97+
@Parameters(name = "{index}: tracker={0}")
98+
public static List<Object[]> params() {
99+
return Arrays.asList(new Object[] { StoreFileTrackerFactory.Trackers.DEFAULT },
100+
new Object[] { StoreFileTrackerFactory.Trackers.FILE });
101+
}
86102

87103
/**
88104
* Setup the config for the cluster
@@ -109,7 +125,6 @@ protected static void setupConf(Configuration conf) {
109125
conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
110126
conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
111127
ConstantSizeRegionSplitPolicy.class.getName());
112-
113128
}
114129

115130
@Before
@@ -119,7 +134,8 @@ public void setup() throws Exception {
119134

120135
protected void createTable() throws Exception {
121136
TableDescriptor htd =
122-
TableDescriptorBuilder.newBuilder(TABLE_NAME).setRegionReplication(getNumReplicas()).build();
137+
TableDescriptorBuilder.newBuilder(TABLE_NAME).setRegionReplication(getNumReplicas())
138+
.setValue(StoreFileTrackerFactory.TRACKER_IMPL, trackerImpl.name()).build();
123139
UTIL.createTable(htd, new byte[][] { TEST_FAM }, null);
124140
}
125141

@@ -316,7 +332,7 @@ public void testOfflineTableSnapshotWithEmptyRegions() throws Exception {
316332
@Test
317333
public void testListTableSnapshots() throws Exception {
318334
Admin admin = null;
319-
final TableName tableName = TableName.valueOf(name.getMethodName());
335+
final TableName tableName = name.getTableName();
320336
try {
321337
admin = UTIL.getAdmin();
322338

@@ -401,7 +417,7 @@ public void testListTableSnapshotsWithRegex() throws Exception {
401417
@Test
402418
public void testDeleteTableSnapshots() throws Exception {
403419
Admin admin = null;
404-
final TableName tableName = TableName.valueOf(name.getMethodName());
420+
final TableName tableName = name.getTableName();
405421
try {
406422
admin = UTIL.getAdmin();
407423

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStoreFile.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
5959
import org.apache.hadoop.hbase.client.Scan;
6060
import org.apache.hadoop.hbase.client.TableDescriptor;
61+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
6162
import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
6263
import org.apache.hadoop.hbase.io.HFileLink;
6364
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
@@ -1073,10 +1074,9 @@ private Path splitStoreFile(final HRegionFileSystem regionFs, final RegionInfo h
10731074
when(mockEnv.getMasterConfiguration()).thenReturn(new Configuration());
10741075
TableDescriptors mockTblDescs = mock(TableDescriptors.class);
10751076
when(mockServices.getTableDescriptors()).thenReturn(mockTblDescs);
1076-
TableDescriptor mockTblDesc = mock(TableDescriptor.class);
1077+
TableDescriptor mockTblDesc = TableDescriptorBuilder.newBuilder(hri.getTable())
1078+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
10771079
when(mockTblDescs.get(any())).thenReturn(mockTblDesc);
1078-
ColumnFamilyDescriptor mockCfDesc = mock(ColumnFamilyDescriptor.class);
1079-
when(mockTblDesc.getColumnFamily(any())).thenReturn(mockCfDesc);
10801080
Path regionDir = regionFs.commitDaughterRegion(hri, splitFiles, mockEnv);
10811081
return new Path(new Path(regionDir, family), path.getName());
10821082
}

0 commit comments

Comments
 (0)