|
39 | 39 | import org.apache.hadoop.hbase.HDFSBlocksDistribution; |
40 | 40 | import org.apache.hadoop.hbase.TableName; |
41 | 41 | import org.apache.hadoop.hbase.client.Admin; |
| 42 | +import org.apache.hadoop.hbase.client.RegionInfo; |
42 | 43 | import org.apache.hadoop.hbase.client.Result; |
43 | 44 | import org.apache.hadoop.hbase.client.Scan; |
44 | 45 | import org.apache.hadoop.hbase.client.Scan.ReadType; |
|
47 | 48 | import org.apache.hadoop.hbase.io.ImmutableBytesWritable; |
48 | 49 | import org.apache.hadoop.hbase.mapreduce.TableSnapshotInputFormat.TableSnapshotRegionSplit; |
49 | 50 | import org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper; |
| 51 | +import org.apache.hadoop.hbase.snapshot.SnapshotManifest; |
50 | 52 | import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; |
51 | 53 | import org.apache.hadoop.hbase.testclassification.LargeTests; |
52 | 54 | import org.apache.hadoop.hbase.testclassification.VerySlowMapReduceTests; |
@@ -683,4 +685,49 @@ public void testReadFromRestoredSnapshotViaMR() throws Exception { |
683 | 685 | } |
684 | 686 | } |
685 | 687 | } |
| 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 | + } |
686 | 733 | } |
0 commit comments