Skip to content

Commit e8eca6d

Browse files
HBASE-30016 Cached table regions locations are not using in TableSnapshotInputFormatImpl#getSplits
1 parent 206a6d5 commit e8eca6d

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableSnapshotInputFormat.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hadoop.hbase.HDFSBlocksDistribution;
4040
import org.apache.hadoop.hbase.TableName;
4141
import org.apache.hadoop.hbase.client.Admin;
42+
import org.apache.hadoop.hbase.client.RegionInfo;
4243
import org.apache.hadoop.hbase.client.Result;
4344
import org.apache.hadoop.hbase.client.Scan;
4445
import org.apache.hadoop.hbase.client.Scan.ReadType;
@@ -47,6 +48,7 @@
4748
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
4849
import org.apache.hadoop.hbase.mapreduce.TableSnapshotInputFormat.TableSnapshotRegionSplit;
4950
import org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper;
51+
import org.apache.hadoop.hbase.snapshot.SnapshotManifest;
5052
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
5153
import org.apache.hadoop.hbase.testclassification.LargeTests;
5254
import org.apache.hadoop.hbase.testclassification.VerySlowMapReduceTests;
@@ -683,4 +685,49 @@ public void testReadFromRestoredSnapshotViaMR() throws Exception {
683685
}
684686
}
685687
}
688+
689+
/**
690+
* Tests that TableSnapshotInputFormatImpl correctly caches and uses region locations when
691+
* locality is enabled
692+
*/
693+
@Test
694+
public void testRegionLocatorUsesCache() throws Exception {
695+
final TableName tableName = TableName.valueOf("testRegionLocatorCache");
696+
Configuration conf = UTIL.getConfiguration();
697+
try {
698+
// Create table with multiple regions
699+
createTableAndSnapshot(UTIL, tableName, "snapshot", getStartRow(), getEndRow(), 3);
700+
701+
conf.setBoolean(SNAPSHOT_INPUTFORMAT_LOCALITY_BY_REGION_LOCATION, true);
702+
703+
Path tmpTableDir = UTIL.getDataTestDirOnTestFS("snapshot");
704+
705+
// Get snapshot manifest and region info
706+
SnapshotManifest manifest = TableSnapshotInputFormatImpl.getSnapshotManifest(conf, "snapshot",
707+
CommonFSUtils.getRootDir(conf), UTIL.getTestFileSystem());
708+
List<RegionInfo> regionInfos =
709+
TableSnapshotInputFormatImpl.getRegionInfosFromManifest(manifest);
710+
711+
Scan scan = new Scan();
712+
713+
List<TableSnapshotInputFormatImpl.InputSplit> splits = TableSnapshotInputFormatImpl.getSplits(
714+
scan, manifest, regionInfos, tmpTableDir, conf, new RegionSplitter.UniformSplit(), 1);
715+
716+
// Verify that splits contain proper locality information
717+
Assert.assertNotNull(splits);
718+
Assert.assertTrue(splits.size() > 0);
719+
720+
// Verify locations are populated from cache
721+
for (TableSnapshotInputFormatImpl.InputSplit split : splits) {
722+
String[] locations = split.getLocations();
723+
// Locations should be populated from cache
724+
Assert.assertNotNull(locations);
725+
}
726+
727+
} finally {
728+
UTIL.getAdmin().deleteSnapshot("snapshot");
729+
UTIL.deleteTable(tableName);
730+
conf.unset(SNAPSHOT_INPUTFORMAT_LOCALITY_BY_REGION_LOCATION);
731+
}
732+
}
686733
}

0 commit comments

Comments
 (0)