Skip to content

Commit aec8f79

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 d28a229 commit aec8f79

11 files changed

Lines changed: 109 additions & 111 deletions

File tree

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
@@ -613,9 +613,8 @@ private List<Path> mergeStoreFiles(MasterProcedureEnv env, HRegionFileSystem reg
613613
List<Path> mergedFiles = new ArrayList<>();
614614
for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
615615
String family = hcd.getNameAsString();
616-
Configuration trackerConfig =
617-
StoreFileTrackerFactory.mergeConfigurations(env.getMasterConfiguration(), htd, hcd);
618-
StoreFileTracker tracker = StoreFileTrackerFactory.create(trackerConfig, family, regionFs);
616+
StoreFileTracker tracker =
617+
StoreFileTrackerFactory.create(env.getMasterConfiguration(), htd, hcd, regionFs);
619618
final Collection<StoreFileInfo> storeFiles = tracker.load();
620619
if (storeFiles != null && storeFiles.size() > 0) {
621620
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
@@ -30,6 +30,7 @@
3030
import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner;
3131
import org.apache.hadoop.hbase.mob.MobConstants;
3232
import org.apache.hadoop.hbase.regionserver.FlushLifeCycleTracker;
33+
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
3334
import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils;
3435
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
3536
import org.apache.hadoop.hbase.testclassification.ClientTests;
@@ -92,7 +93,8 @@ public static void setUpBeforeClass() throws Exception {
9293
@Override
9394
protected void createTable() throws IOException, InterruptedException {
9495
MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName,
95-
SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), DelayFlushCoprocessor.class.getName(),
96+
SnapshotTestingUtils.getSplitKeys(), getNumReplicas(),
97+
StoreFileTrackerFactory.Trackers.DEFAULT.name(), DelayFlushCoprocessor.class.getName(),
9698
FAMILY);
9799
}
98100

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: 25 additions & 9 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;
@@ -33,9 +34,11 @@
3334
import org.apache.hadoop.hbase.HConstants;
3435
import org.apache.hadoop.hbase.HTableDescriptor;
3536
import org.apache.hadoop.hbase.TableName;
37+
import org.apache.hadoop.hbase.TableNameTestRule;
3638
import org.apache.hadoop.hbase.TableNotFoundException;
3739
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
3840
import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;
41+
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
3942
import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
4043
import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException;
4144
import org.apache.hadoop.hbase.snapshot.SnapshotManifestV1;
@@ -52,7 +55,10 @@
5255
import org.junit.Rule;
5356
import org.junit.Test;
5457
import org.junit.experimental.categories.Category;
55-
import org.junit.rules.TestName;
58+
import org.junit.runner.RunWith;
59+
import org.junit.runners.Parameterized;
60+
import org.junit.runners.Parameterized.Parameter;
61+
import org.junit.runners.Parameterized.Parameters;
5662
import org.slf4j.Logger;
5763
import org.slf4j.LoggerFactory;
5864

@@ -65,7 +71,8 @@
6571
* <p>
6672
* This is an end-to-end test for the snapshot utility
6773
*/
68-
@Category({LargeTests.class, ClientTests.class})
74+
@RunWith(Parameterized.class)
75+
@Category({ LargeTests.class, ClientTests.class })
6976
public class TestSnapshotFromClient {
7077

7178
@ClassRule
@@ -83,7 +90,16 @@ public class TestSnapshotFromClient {
8390
private static final Pattern MATCH_ALL = Pattern.compile(".*");
8491

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

88104
/**
89105
* Setup the config for the cluster
@@ -110,7 +126,6 @@ protected static void setupConf(Configuration conf) {
110126
conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
111127
conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
112128
ConstantSizeRegionSplitPolicy.class.getName());
113-
114129
}
115130

116131
@Before
@@ -119,9 +134,10 @@ public void setup() throws Exception {
119134
}
120135

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

127143
protected int getNumReplicas() {
@@ -326,7 +342,7 @@ public void testOfflineTableSnapshotWithEmptyRegions() throws Exception {
326342
@Test
327343
public void testListTableSnapshots() throws Exception {
328344
Admin admin = null;
329-
final TableName tableName = TableName.valueOf(name.getMethodName());
345+
final TableName tableName = name.getTableName();
330346
try {
331347
admin = UTIL.getAdmin();
332348

@@ -411,7 +427,7 @@ public void testListTableSnapshotsWithRegex() throws Exception {
411427
@Test
412428
public void testDeleteTableSnapshots() throws Exception {
413429
Admin admin = null;
414-
final TableName tableName = TableName.valueOf(name.getMethodName());
430+
final TableName tableName = name.getTableName();
415431
try {
416432
admin = UTIL.getAdmin();
417433

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
@@ -53,6 +53,7 @@
5353
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
5454
import org.apache.hadoop.hbase.client.Scan;
5555
import org.apache.hadoop.hbase.client.TableDescriptor;
56+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
5657
import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
5758
import org.apache.hadoop.hbase.io.HFileLink;
5859
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
@@ -1103,10 +1104,9 @@ private Path splitStoreFile(final HRegionFileSystem regionFs, final HRegionInfo
11031104
when(mockEnv.getMasterConfiguration()).thenReturn(new Configuration());
11041105
TableDescriptors mockTblDescs = mock(TableDescriptors.class);
11051106
when(mockServices.getTableDescriptors()).thenReturn(mockTblDescs);
1106-
TableDescriptor mockTblDesc = mock(TableDescriptor.class);
1107+
TableDescriptor mockTblDesc = TableDescriptorBuilder.newBuilder(hri.getTable())
1108+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
11071109
when(mockTblDescs.get(any())).thenReturn(mockTblDesc);
1108-
ColumnFamilyDescriptor mockCfDesc = mock(ColumnFamilyDescriptor.class);
1109-
when(mockTblDesc.getColumnFamily(any())).thenReturn(mockCfDesc);
11101110
Path regionDir = regionFs.commitDaughterRegion(hri, splitFiles, mockEnv);
11111111
return new Path(new Path(regionDir, family), path.getName());
11121112
}

0 commit comments

Comments
 (0)