hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [03/21] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Sat, 01 Jul 2017 23:43:56 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/640333c3/testdevapidocs/src-html/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.SnapshotMock.SnapshotBuilder.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.SnapshotMock.SnapshotBuilder.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.SnapshotMock.SnapshotBuilder.html
index be69921..f7f103c 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.SnapshotMock.SnapshotBuilder.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.SnapshotMock.SnapshotBuilder.html
@@ -217,7 +217,7 @@
 <span class="sourceLineNo">209</span>    // check snapshot dir<a name="line.209"></a>
 <span class="sourceLineNo">210</span>    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(<a name="line.210"></a>
 <span class="sourceLineNo">211</span>        snapshotDescriptor, rootDir);<a name="line.211"></a>
-<span class="sourceLineNo">212</span>    assertTrue(fs.exists(snapshotDir));<a name="line.212"></a>
+<span class="sourceLineNo">212</span>    assertTrue("target snapshot directory, '"+ snapshotDir +"', doesn't exist.", fs.exists(snapshotDir));<a name="line.212"></a>
 <span class="sourceLineNo">213</span><a name="line.213"></a>
 <span class="sourceLineNo">214</span>    SnapshotProtos.SnapshotDescription desc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);<a name="line.214"></a>
 <span class="sourceLineNo">215</span><a name="line.215"></a>
@@ -240,14 +240,14 @@
 <span class="sourceLineNo">232</span>    // Verify that there are store files in the specified families<a name="line.232"></a>
 <span class="sourceLineNo">233</span>    if (nonEmptyTestFamilies != null) {<a name="line.233"></a>
 <span class="sourceLineNo">234</span>      for (final byte[] familyName: nonEmptyTestFamilies) {<a name="line.234"></a>
-<span class="sourceLineNo">235</span>        assertTrue(snapshotFamilies.contains(familyName));<a name="line.235"></a>
+<span class="sourceLineNo">235</span>        assertTrue("Expected snapshot to contain family '" + Bytes.toString(familyName) + "', but it does not.", snapshotFamilies.contains(familyName));<a name="line.235"></a>
 <span class="sourceLineNo">236</span>      }<a name="line.236"></a>
 <span class="sourceLineNo">237</span>    }<a name="line.237"></a>
 <span class="sourceLineNo">238</span><a name="line.238"></a>
 <span class="sourceLineNo">239</span>    // Verify that there are no store files in the specified families<a name="line.239"></a>
 <span class="sourceLineNo">240</span>    if (emptyTestFamilies != null) {<a name="line.240"></a>
 <span class="sourceLineNo">241</span>      for (final byte[] familyName: emptyTestFamilies) {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>        assertFalse(snapshotFamilies.contains(familyName));<a name="line.242"></a>
+<span class="sourceLineNo">242</span>        assertFalse("Expected snapshot to skip empty family '" + Bytes.toString(familyName) + "', but it is present.", snapshotFamilies.contains(familyName));<a name="line.242"></a>
 <span class="sourceLineNo">243</span>      }<a name="line.243"></a>
 <span class="sourceLineNo">244</span>    }<a name="line.244"></a>
 <span class="sourceLineNo">245</span><a name="line.245"></a>
@@ -258,7 +258,7 @@
 <span class="sourceLineNo">250</span>    boolean hasMob = regionManifests.containsKey(MobUtils.getMobRegionInfo(tableName)<a name="line.250"></a>
 <span class="sourceLineNo">251</span>        .getEncodedName());<a name="line.251"></a>
 <span class="sourceLineNo">252</span>    if (hasMob) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>      assertEquals(regions.size(), regionManifests.size() - 1);<a name="line.253"></a>
+<span class="sourceLineNo">253</span>      assertEquals("Wrong number of regions.", regions.size(), regionManifests.size() - 1);<a name="line.253"></a>
 <span class="sourceLineNo">254</span>    } else {<a name="line.254"></a>
 <span class="sourceLineNo">255</span>      // if create snapshot when table splitting, parent region will be included to the snapshot<a name="line.255"></a>
 <span class="sourceLineNo">256</span>      // region manifest. we should exclude the parent regions.<a name="line.256"></a>
@@ -270,13 +270,13 @@
 <span class="sourceLineNo">262</span>        }<a name="line.262"></a>
 <span class="sourceLineNo">263</span>        regionCountExclusiveSplitParent++;<a name="line.263"></a>
 <span class="sourceLineNo">264</span>      }<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      assertEquals(regions.size(), regionCountExclusiveSplitParent);<a name="line.265"></a>
+<span class="sourceLineNo">265</span>      assertEquals("Wrong number of regions.", regions.size(), regionCountExclusiveSplitParent);<a name="line.265"></a>
 <span class="sourceLineNo">266</span>    }<a name="line.266"></a>
 <span class="sourceLineNo">267</span><a name="line.267"></a>
 <span class="sourceLineNo">268</span>    // Verify Regions (redundant check, see MasterSnapshotVerifier)<a name="line.268"></a>
 <span class="sourceLineNo">269</span>    for (HRegionInfo info : regions) {<a name="line.269"></a>
 <span class="sourceLineNo">270</span>      String regionName = info.getEncodedName();<a name="line.270"></a>
-<span class="sourceLineNo">271</span>      assertTrue(regionManifests.containsKey(regionName));<a name="line.271"></a>
+<span class="sourceLineNo">271</span>      assertTrue("Missing region name: '" + regionName + "'", regionManifests.containsKey(regionName));<a name="line.271"></a>
 <span class="sourceLineNo">272</span>    }<a name="line.272"></a>
 <span class="sourceLineNo">273</span>  }<a name="line.273"></a>
 <span class="sourceLineNo">274</span><a name="line.274"></a>
@@ -411,496 +411,500 @@
 <span class="sourceLineNo">403</span>        throws Exception {<a name="line.403"></a>
 <span class="sourceLineNo">404</span>    if (!onlineSnapshot) {<a name="line.404"></a>
 <span class="sourceLineNo">405</span>      try {<a name="line.405"></a>
-<span class="sourceLineNo">406</span>        admin.disableTable(tableName);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>      } catch (TableNotEnabledException tne) {<a name="line.407"></a>
-<span class="sourceLineNo">408</span>        LOG.info("In attempting to disable " + tableName + " it turns out that the this table is " +<a name="line.408"></a>
-<span class="sourceLineNo">409</span>            "already disabled.");<a name="line.409"></a>
-<span class="sourceLineNo">410</span>      }<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    }<a name="line.411"></a>
-<span class="sourceLineNo">412</span>    admin.snapshot(snapshotNameString, tableName);<a name="line.412"></a>
-<span class="sourceLineNo">413</span><a name="line.413"></a>
-<span class="sourceLineNo">414</span>    List&lt;SnapshotDescription&gt; snapshots =<a name="line.414"></a>
-<span class="sourceLineNo">415</span>        SnapshotTestingUtils.assertExistsMatchingSnapshot(admin, snapshotNameString, tableName);<a name="line.415"></a>
-<span class="sourceLineNo">416</span>    if (snapshots == null || snapshots.size() != 1) {<a name="line.416"></a>
-<span class="sourceLineNo">417</span>      Assert.fail("Incorrect number of snapshots for table " + tableName);<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    }<a name="line.418"></a>
-<span class="sourceLineNo">419</span><a name="line.419"></a>
-<span class="sourceLineNo">420</span>    SnapshotTestingUtils.confirmSnapshotValid(<a name="line.420"></a>
-<span class="sourceLineNo">421</span>      ProtobufUtil.createHBaseProtosSnapshotDesc(snapshots.get(0)), tableName, nonEmptyFamilyNames,<a name="line.421"></a>
-<span class="sourceLineNo">422</span>      emptyFamilyNames, rootDir, admin, fs);<a name="line.422"></a>
-<span class="sourceLineNo">423</span>  }<a name="line.423"></a>
-<span class="sourceLineNo">424</span><a name="line.424"></a>
-<span class="sourceLineNo">425</span>  /**<a name="line.425"></a>
-<span class="sourceLineNo">426</span>   * Corrupt the specified snapshot by deleting some files.<a name="line.426"></a>
-<span class="sourceLineNo">427</span>   *<a name="line.427"></a>
-<span class="sourceLineNo">428</span>   * @param util {@link HBaseTestingUtility}<a name="line.428"></a>
-<span class="sourceLineNo">429</span>   * @param snapshotName name of the snapshot to corrupt<a name="line.429"></a>
-<span class="sourceLineNo">430</span>   * @return array of the corrupted HFiles<a name="line.430"></a>
-<span class="sourceLineNo">431</span>   * @throws IOException on unexecpted error reading the FS<a name="line.431"></a>
-<span class="sourceLineNo">432</span>   */<a name="line.432"></a>
-<span class="sourceLineNo">433</span>  public static ArrayList corruptSnapshot(final HBaseTestingUtility util, final String snapshotName)<a name="line.433"></a>
-<span class="sourceLineNo">434</span>      throws IOException {<a name="line.434"></a>
-<span class="sourceLineNo">435</span>    final MasterFileSystem mfs = util.getHBaseCluster().getMaster().getMasterFileSystem();<a name="line.435"></a>
-<span class="sourceLineNo">436</span>    final FileSystem fs = mfs.getFileSystem();<a name="line.436"></a>
-<span class="sourceLineNo">437</span><a name="line.437"></a>
-<span class="sourceLineNo">438</span>    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName,<a name="line.438"></a>
-<span class="sourceLineNo">439</span>                                                                        mfs.getRootDir());<a name="line.439"></a>
-<span class="sourceLineNo">440</span>    SnapshotProtos.SnapshotDescription snapshotDesc =<a name="line.440"></a>
-<span class="sourceLineNo">441</span>        SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);<a name="line.441"></a>
-<span class="sourceLineNo">442</span>    final TableName table = TableName.valueOf(snapshotDesc.getTable());<a name="line.442"></a>
-<span class="sourceLineNo">443</span><a name="line.443"></a>
-<span class="sourceLineNo">444</span>    final ArrayList corruptedFiles = new ArrayList();<a name="line.444"></a>
-<span class="sourceLineNo">445</span>    final Configuration conf = util.getConfiguration();<a name="line.445"></a>
-<span class="sourceLineNo">446</span>    SnapshotReferenceUtil.visitTableStoreFiles(conf, fs, snapshotDir, snapshotDesc,<a name="line.446"></a>
-<span class="sourceLineNo">447</span>        new SnapshotReferenceUtil.StoreFileVisitor() {<a name="line.447"></a>
-<span class="sourceLineNo">448</span>      @Override<a name="line.448"></a>
-<span class="sourceLineNo">449</span>      public void storeFile(final HRegionInfo regionInfo, final String family,<a name="line.449"></a>
-<span class="sourceLineNo">450</span>            final SnapshotRegionManifest.StoreFile storeFile) throws IOException {<a name="line.450"></a>
-<span class="sourceLineNo">451</span>        String region = regionInfo.getEncodedName();<a name="line.451"></a>
-<span class="sourceLineNo">452</span>        String hfile = storeFile.getName();<a name="line.452"></a>
-<span class="sourceLineNo">453</span>        HFileLink link = HFileLink.build(conf, table, region, family, hfile);<a name="line.453"></a>
-<span class="sourceLineNo">454</span>        if (corruptedFiles.size() % 2 == 0) {<a name="line.454"></a>
-<span class="sourceLineNo">455</span>          fs.delete(link.getAvailablePath(fs), true);<a name="line.455"></a>
-<span class="sourceLineNo">456</span>          corruptedFiles.add(hfile);<a name="line.456"></a>
-<span class="sourceLineNo">457</span>        }<a name="line.457"></a>
-<span class="sourceLineNo">458</span>      }<a name="line.458"></a>
-<span class="sourceLineNo">459</span>    });<a name="line.459"></a>
-<span class="sourceLineNo">460</span><a name="line.460"></a>
-<span class="sourceLineNo">461</span>    assertTrue(corruptedFiles.size() &gt; 0);<a name="line.461"></a>
-<span class="sourceLineNo">462</span>    return corruptedFiles;<a name="line.462"></a>
-<span class="sourceLineNo">463</span>  }<a name="line.463"></a>
+<span class="sourceLineNo">406</span>        LOG.info("prepping for offline snapshot.");<a name="line.406"></a>
+<span class="sourceLineNo">407</span>        admin.disableTable(tableName);<a name="line.407"></a>
+<span class="sourceLineNo">408</span>      } catch (TableNotEnabledException tne) {<a name="line.408"></a>
+<span class="sourceLineNo">409</span>        LOG.info("In attempting to disable " + tableName + " it turns out that the this table is " +<a name="line.409"></a>
+<span class="sourceLineNo">410</span>            "already disabled.");<a name="line.410"></a>
+<span class="sourceLineNo">411</span>      }<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    }<a name="line.412"></a>
+<span class="sourceLineNo">413</span>    LOG.info("taking snapshot.");<a name="line.413"></a>
+<span class="sourceLineNo">414</span>    admin.snapshot(snapshotNameString, tableName);<a name="line.414"></a>
+<span class="sourceLineNo">415</span><a name="line.415"></a>
+<span class="sourceLineNo">416</span>    LOG.info("Confirming snapshot exists.");<a name="line.416"></a>
+<span class="sourceLineNo">417</span>    List&lt;SnapshotDescription&gt; snapshots =<a name="line.417"></a>
+<span class="sourceLineNo">418</span>        SnapshotTestingUtils.assertExistsMatchingSnapshot(admin, snapshotNameString, tableName);<a name="line.418"></a>
+<span class="sourceLineNo">419</span>    if (snapshots == null || snapshots.size() != 1) {<a name="line.419"></a>
+<span class="sourceLineNo">420</span>      Assert.fail("Incorrect number of snapshots for table " + tableName);<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    }<a name="line.421"></a>
+<span class="sourceLineNo">422</span><a name="line.422"></a>
+<span class="sourceLineNo">423</span>    LOG.info("validating snapshot.");<a name="line.423"></a>
+<span class="sourceLineNo">424</span>    SnapshotTestingUtils.confirmSnapshotValid(<a name="line.424"></a>
+<span class="sourceLineNo">425</span>      ProtobufUtil.createHBaseProtosSnapshotDesc(snapshots.get(0)), tableName, nonEmptyFamilyNames,<a name="line.425"></a>
+<span class="sourceLineNo">426</span>      emptyFamilyNames, rootDir, admin, fs);<a name="line.426"></a>
+<span class="sourceLineNo">427</span>  }<a name="line.427"></a>
+<span class="sourceLineNo">428</span><a name="line.428"></a>
+<span class="sourceLineNo">429</span>  /**<a name="line.429"></a>
+<span class="sourceLineNo">430</span>   * Corrupt the specified snapshot by deleting some files.<a name="line.430"></a>
+<span class="sourceLineNo">431</span>   *<a name="line.431"></a>
+<span class="sourceLineNo">432</span>   * @param util {@link HBaseTestingUtility}<a name="line.432"></a>
+<span class="sourceLineNo">433</span>   * @param snapshotName name of the snapshot to corrupt<a name="line.433"></a>
+<span class="sourceLineNo">434</span>   * @return array of the corrupted HFiles<a name="line.434"></a>
+<span class="sourceLineNo">435</span>   * @throws IOException on unexecpted error reading the FS<a name="line.435"></a>
+<span class="sourceLineNo">436</span>   */<a name="line.436"></a>
+<span class="sourceLineNo">437</span>  public static ArrayList corruptSnapshot(final HBaseTestingUtility util, final String snapshotName)<a name="line.437"></a>
+<span class="sourceLineNo">438</span>      throws IOException {<a name="line.438"></a>
+<span class="sourceLineNo">439</span>    final MasterFileSystem mfs = util.getHBaseCluster().getMaster().getMasterFileSystem();<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    final FileSystem fs = mfs.getFileSystem();<a name="line.440"></a>
+<span class="sourceLineNo">441</span><a name="line.441"></a>
+<span class="sourceLineNo">442</span>    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName,<a name="line.442"></a>
+<span class="sourceLineNo">443</span>                                                                        mfs.getRootDir());<a name="line.443"></a>
+<span class="sourceLineNo">444</span>    SnapshotProtos.SnapshotDescription snapshotDesc =<a name="line.444"></a>
+<span class="sourceLineNo">445</span>        SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);<a name="line.445"></a>
+<span class="sourceLineNo">446</span>    final TableName table = TableName.valueOf(snapshotDesc.getTable());<a name="line.446"></a>
+<span class="sourceLineNo">447</span><a name="line.447"></a>
+<span class="sourceLineNo">448</span>    final ArrayList corruptedFiles = new ArrayList();<a name="line.448"></a>
+<span class="sourceLineNo">449</span>    final Configuration conf = util.getConfiguration();<a name="line.449"></a>
+<span class="sourceLineNo">450</span>    SnapshotReferenceUtil.visitTableStoreFiles(conf, fs, snapshotDir, snapshotDesc,<a name="line.450"></a>
+<span class="sourceLineNo">451</span>        new SnapshotReferenceUtil.StoreFileVisitor() {<a name="line.451"></a>
+<span class="sourceLineNo">452</span>      @Override<a name="line.452"></a>
+<span class="sourceLineNo">453</span>      public void storeFile(final HRegionInfo regionInfo, final String family,<a name="line.453"></a>
+<span class="sourceLineNo">454</span>            final SnapshotRegionManifest.StoreFile storeFile) throws IOException {<a name="line.454"></a>
+<span class="sourceLineNo">455</span>        String region = regionInfo.getEncodedName();<a name="line.455"></a>
+<span class="sourceLineNo">456</span>        String hfile = storeFile.getName();<a name="line.456"></a>
+<span class="sourceLineNo">457</span>        HFileLink link = HFileLink.build(conf, table, region, family, hfile);<a name="line.457"></a>
+<span class="sourceLineNo">458</span>        if (corruptedFiles.size() % 2 == 0) {<a name="line.458"></a>
+<span class="sourceLineNo">459</span>          fs.delete(link.getAvailablePath(fs), true);<a name="line.459"></a>
+<span class="sourceLineNo">460</span>          corruptedFiles.add(hfile);<a name="line.460"></a>
+<span class="sourceLineNo">461</span>        }<a name="line.461"></a>
+<span class="sourceLineNo">462</span>      }<a name="line.462"></a>
+<span class="sourceLineNo">463</span>    });<a name="line.463"></a>
 <span class="sourceLineNo">464</span><a name="line.464"></a>
-<span class="sourceLineNo">465</span>  // ==========================================================================<a name="line.465"></a>
-<span class="sourceLineNo">466</span>  //  Snapshot Mock<a name="line.466"></a>
-<span class="sourceLineNo">467</span>  // ==========================================================================<a name="line.467"></a>
-<span class="sourceLineNo">468</span>  public static class SnapshotMock {<a name="line.468"></a>
-<span class="sourceLineNo">469</span>    protected final static String TEST_FAMILY = "cf";<a name="line.469"></a>
-<span class="sourceLineNo">470</span>    public final static int TEST_NUM_REGIONS = 4;<a name="line.470"></a>
-<span class="sourceLineNo">471</span><a name="line.471"></a>
-<span class="sourceLineNo">472</span>    private final Configuration conf;<a name="line.472"></a>
-<span class="sourceLineNo">473</span>    private final FileSystem fs;<a name="line.473"></a>
-<span class="sourceLineNo">474</span>    private final Path rootDir;<a name="line.474"></a>
+<span class="sourceLineNo">465</span>    assertTrue(corruptedFiles.size() &gt; 0);<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    return corruptedFiles;<a name="line.466"></a>
+<span class="sourceLineNo">467</span>  }<a name="line.467"></a>
+<span class="sourceLineNo">468</span><a name="line.468"></a>
+<span class="sourceLineNo">469</span>  // ==========================================================================<a name="line.469"></a>
+<span class="sourceLineNo">470</span>  //  Snapshot Mock<a name="line.470"></a>
+<span class="sourceLineNo">471</span>  // ==========================================================================<a name="line.471"></a>
+<span class="sourceLineNo">472</span>  public static class SnapshotMock {<a name="line.472"></a>
+<span class="sourceLineNo">473</span>    protected final static String TEST_FAMILY = "cf";<a name="line.473"></a>
+<span class="sourceLineNo">474</span>    public final static int TEST_NUM_REGIONS = 4;<a name="line.474"></a>
 <span class="sourceLineNo">475</span><a name="line.475"></a>
-<span class="sourceLineNo">476</span>    static class RegionData {<a name="line.476"></a>
-<span class="sourceLineNo">477</span>      public HRegionInfo hri;<a name="line.477"></a>
-<span class="sourceLineNo">478</span>      public Path tableDir;<a name="line.478"></a>
-<span class="sourceLineNo">479</span>      public Path[] files;<a name="line.479"></a>
-<span class="sourceLineNo">480</span><a name="line.480"></a>
-<span class="sourceLineNo">481</span>      public RegionData(final Path tableDir, final HRegionInfo hri, final int nfiles) {<a name="line.481"></a>
-<span class="sourceLineNo">482</span>        this.tableDir = tableDir;<a name="line.482"></a>
-<span class="sourceLineNo">483</span>        this.hri = hri;<a name="line.483"></a>
-<span class="sourceLineNo">484</span>        this.files = new Path[nfiles];<a name="line.484"></a>
-<span class="sourceLineNo">485</span>      }<a name="line.485"></a>
-<span class="sourceLineNo">486</span>    }<a name="line.486"></a>
-<span class="sourceLineNo">487</span><a name="line.487"></a>
-<span class="sourceLineNo">488</span>    public static class SnapshotBuilder {<a name="line.488"></a>
-<span class="sourceLineNo">489</span>      private final RegionData[] tableRegions;<a name="line.489"></a>
-<span class="sourceLineNo">490</span>      private final SnapshotProtos.SnapshotDescription desc;<a name="line.490"></a>
-<span class="sourceLineNo">491</span>      private final HTableDescriptor htd;<a name="line.491"></a>
-<span class="sourceLineNo">492</span>      private final Configuration conf;<a name="line.492"></a>
-<span class="sourceLineNo">493</span>      private final FileSystem fs;<a name="line.493"></a>
-<span class="sourceLineNo">494</span>      private final Path rootDir;<a name="line.494"></a>
-<span class="sourceLineNo">495</span>      private Path snapshotDir;<a name="line.495"></a>
-<span class="sourceLineNo">496</span>      private int snapshotted = 0;<a name="line.496"></a>
-<span class="sourceLineNo">497</span><a name="line.497"></a>
-<span class="sourceLineNo">498</span>      public SnapshotBuilder(final Configuration conf, final FileSystem fs,<a name="line.498"></a>
-<span class="sourceLineNo">499</span>          final Path rootDir, final HTableDescriptor htd,<a name="line.499"></a>
-<span class="sourceLineNo">500</span>          final SnapshotProtos.SnapshotDescription desc, final RegionData[] tableRegions)<a name="line.500"></a>
-<span class="sourceLineNo">501</span>          throws IOException {<a name="line.501"></a>
-<span class="sourceLineNo">502</span>        this.fs = fs;<a name="line.502"></a>
-<span class="sourceLineNo">503</span>        this.conf = conf;<a name="line.503"></a>
-<span class="sourceLineNo">504</span>        this.rootDir = rootDir;<a name="line.504"></a>
-<span class="sourceLineNo">505</span>        this.htd = htd;<a name="line.505"></a>
-<span class="sourceLineNo">506</span>        this.desc = desc;<a name="line.506"></a>
-<span class="sourceLineNo">507</span>        this.tableRegions = tableRegions;<a name="line.507"></a>
-<span class="sourceLineNo">508</span>        this.snapshotDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(desc, rootDir);<a name="line.508"></a>
-<span class="sourceLineNo">509</span>        new FSTableDescriptors(conf)<a name="line.509"></a>
-<span class="sourceLineNo">510</span>          .createTableDescriptorForTableDirectory(snapshotDir, htd, false);<a name="line.510"></a>
-<span class="sourceLineNo">511</span>      }<a name="line.511"></a>
-<span class="sourceLineNo">512</span><a name="line.512"></a>
-<span class="sourceLineNo">513</span>      public HTableDescriptor getTableDescriptor() {<a name="line.513"></a>
-<span class="sourceLineNo">514</span>        return this.htd;<a name="line.514"></a>
+<span class="sourceLineNo">476</span>    private final Configuration conf;<a name="line.476"></a>
+<span class="sourceLineNo">477</span>    private final FileSystem fs;<a name="line.477"></a>
+<span class="sourceLineNo">478</span>    private final Path rootDir;<a name="line.478"></a>
+<span class="sourceLineNo">479</span><a name="line.479"></a>
+<span class="sourceLineNo">480</span>    static class RegionData {<a name="line.480"></a>
+<span class="sourceLineNo">481</span>      public HRegionInfo hri;<a name="line.481"></a>
+<span class="sourceLineNo">482</span>      public Path tableDir;<a name="line.482"></a>
+<span class="sourceLineNo">483</span>      public Path[] files;<a name="line.483"></a>
+<span class="sourceLineNo">484</span><a name="line.484"></a>
+<span class="sourceLineNo">485</span>      public RegionData(final Path tableDir, final HRegionInfo hri, final int nfiles) {<a name="line.485"></a>
+<span class="sourceLineNo">486</span>        this.tableDir = tableDir;<a name="line.486"></a>
+<span class="sourceLineNo">487</span>        this.hri = hri;<a name="line.487"></a>
+<span class="sourceLineNo">488</span>        this.files = new Path[nfiles];<a name="line.488"></a>
+<span class="sourceLineNo">489</span>      }<a name="line.489"></a>
+<span class="sourceLineNo">490</span>    }<a name="line.490"></a>
+<span class="sourceLineNo">491</span><a name="line.491"></a>
+<span class="sourceLineNo">492</span>    public static class SnapshotBuilder {<a name="line.492"></a>
+<span class="sourceLineNo">493</span>      private final RegionData[] tableRegions;<a name="line.493"></a>
+<span class="sourceLineNo">494</span>      private final SnapshotProtos.SnapshotDescription desc;<a name="line.494"></a>
+<span class="sourceLineNo">495</span>      private final HTableDescriptor htd;<a name="line.495"></a>
+<span class="sourceLineNo">496</span>      private final Configuration conf;<a name="line.496"></a>
+<span class="sourceLineNo">497</span>      private final FileSystem fs;<a name="line.497"></a>
+<span class="sourceLineNo">498</span>      private final Path rootDir;<a name="line.498"></a>
+<span class="sourceLineNo">499</span>      private Path snapshotDir;<a name="line.499"></a>
+<span class="sourceLineNo">500</span>      private int snapshotted = 0;<a name="line.500"></a>
+<span class="sourceLineNo">501</span><a name="line.501"></a>
+<span class="sourceLineNo">502</span>      public SnapshotBuilder(final Configuration conf, final FileSystem fs,<a name="line.502"></a>
+<span class="sourceLineNo">503</span>          final Path rootDir, final HTableDescriptor htd,<a name="line.503"></a>
+<span class="sourceLineNo">504</span>          final SnapshotProtos.SnapshotDescription desc, final RegionData[] tableRegions)<a name="line.504"></a>
+<span class="sourceLineNo">505</span>          throws IOException {<a name="line.505"></a>
+<span class="sourceLineNo">506</span>        this.fs = fs;<a name="line.506"></a>
+<span class="sourceLineNo">507</span>        this.conf = conf;<a name="line.507"></a>
+<span class="sourceLineNo">508</span>        this.rootDir = rootDir;<a name="line.508"></a>
+<span class="sourceLineNo">509</span>        this.htd = htd;<a name="line.509"></a>
+<span class="sourceLineNo">510</span>        this.desc = desc;<a name="line.510"></a>
+<span class="sourceLineNo">511</span>        this.tableRegions = tableRegions;<a name="line.511"></a>
+<span class="sourceLineNo">512</span>        this.snapshotDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(desc, rootDir);<a name="line.512"></a>
+<span class="sourceLineNo">513</span>        new FSTableDescriptors(conf)<a name="line.513"></a>
+<span class="sourceLineNo">514</span>          .createTableDescriptorForTableDirectory(snapshotDir, htd, false);<a name="line.514"></a>
 <span class="sourceLineNo">515</span>      }<a name="line.515"></a>
 <span class="sourceLineNo">516</span><a name="line.516"></a>
-<span class="sourceLineNo">517</span>      public SnapshotProtos.SnapshotDescription getSnapshotDescription() {<a name="line.517"></a>
-<span class="sourceLineNo">518</span>        return this.desc;<a name="line.518"></a>
+<span class="sourceLineNo">517</span>      public HTableDescriptor getTableDescriptor() {<a name="line.517"></a>
+<span class="sourceLineNo">518</span>        return this.htd;<a name="line.518"></a>
 <span class="sourceLineNo">519</span>      }<a name="line.519"></a>
 <span class="sourceLineNo">520</span><a name="line.520"></a>
-<span class="sourceLineNo">521</span>      public Path getSnapshotsDir() {<a name="line.521"></a>
-<span class="sourceLineNo">522</span>        return this.snapshotDir;<a name="line.522"></a>
+<span class="sourceLineNo">521</span>      public SnapshotProtos.SnapshotDescription getSnapshotDescription() {<a name="line.521"></a>
+<span class="sourceLineNo">522</span>        return this.desc;<a name="line.522"></a>
 <span class="sourceLineNo">523</span>      }<a name="line.523"></a>
 <span class="sourceLineNo">524</span><a name="line.524"></a>
-<span class="sourceLineNo">525</span>      public Path[] addRegion() throws IOException {<a name="line.525"></a>
-<span class="sourceLineNo">526</span>        return addRegion(desc);<a name="line.526"></a>
+<span class="sourceLineNo">525</span>      public Path getSnapshotsDir() {<a name="line.525"></a>
+<span class="sourceLineNo">526</span>        return this.snapshotDir;<a name="line.526"></a>
 <span class="sourceLineNo">527</span>      }<a name="line.527"></a>
 <span class="sourceLineNo">528</span><a name="line.528"></a>
-<span class="sourceLineNo">529</span>      public Path[] addRegionV1() throws IOException {<a name="line.529"></a>
-<span class="sourceLineNo">530</span>        return addRegion(desc.toBuilder()<a name="line.530"></a>
-<span class="sourceLineNo">531</span>                          .setVersion(SnapshotManifestV1.DESCRIPTOR_VERSION)<a name="line.531"></a>
-<span class="sourceLineNo">532</span>                          .build());<a name="line.532"></a>
-<span class="sourceLineNo">533</span>      }<a name="line.533"></a>
-<span class="sourceLineNo">534</span><a name="line.534"></a>
-<span class="sourceLineNo">535</span>      public Path[] addRegionV2() throws IOException {<a name="line.535"></a>
-<span class="sourceLineNo">536</span>        return addRegion(desc.toBuilder()<a name="line.536"></a>
-<span class="sourceLineNo">537</span>                          .setVersion(SnapshotManifestV2.DESCRIPTOR_VERSION)<a name="line.537"></a>
-<span class="sourceLineNo">538</span>                          .build());<a name="line.538"></a>
-<span class="sourceLineNo">539</span>      }<a name="line.539"></a>
-<span class="sourceLineNo">540</span><a name="line.540"></a>
-<span class="sourceLineNo">541</span>      private Path[] addRegion(final SnapshotProtos.SnapshotDescription desc) throws IOException {<a name="line.541"></a>
-<span class="sourceLineNo">542</span>        if (this.snapshotted == tableRegions.length) {<a name="line.542"></a>
-<span class="sourceLineNo">543</span>          throw new UnsupportedOperationException("No more regions in the table");<a name="line.543"></a>
-<span class="sourceLineNo">544</span>        }<a name="line.544"></a>
-<span class="sourceLineNo">545</span><a name="line.545"></a>
-<span class="sourceLineNo">546</span>        RegionData regionData = tableRegions[this.snapshotted++];<a name="line.546"></a>
-<span class="sourceLineNo">547</span>        ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getName());<a name="line.547"></a>
-<span class="sourceLineNo">548</span>        SnapshotManifest manifest = SnapshotManifest.create(conf, fs, snapshotDir, desc, monitor);<a name="line.548"></a>
-<span class="sourceLineNo">549</span>        manifest.addRegion(regionData.tableDir, regionData.hri);<a name="line.549"></a>
-<span class="sourceLineNo">550</span>        return regionData.files;<a name="line.550"></a>
-<span class="sourceLineNo">551</span>      }<a name="line.551"></a>
-<span class="sourceLineNo">552</span><a name="line.552"></a>
-<span class="sourceLineNo">553</span>      private void corruptFile(Path p) throws IOException {<a name="line.553"></a>
-<span class="sourceLineNo">554</span>        String manifestName = p.getName();<a name="line.554"></a>
-<span class="sourceLineNo">555</span><a name="line.555"></a>
-<span class="sourceLineNo">556</span>        // Rename the original region-manifest file<a name="line.556"></a>
-<span class="sourceLineNo">557</span>        Path newP = new Path(p.getParent(), manifestName + "1");<a name="line.557"></a>
-<span class="sourceLineNo">558</span>        fs.rename(p, newP);<a name="line.558"></a>
+<span class="sourceLineNo">529</span>      public Path[] addRegion() throws IOException {<a name="line.529"></a>
+<span class="sourceLineNo">530</span>        return addRegion(desc);<a name="line.530"></a>
+<span class="sourceLineNo">531</span>      }<a name="line.531"></a>
+<span class="sourceLineNo">532</span><a name="line.532"></a>
+<span class="sourceLineNo">533</span>      public Path[] addRegionV1() throws IOException {<a name="line.533"></a>
+<span class="sourceLineNo">534</span>        return addRegion(desc.toBuilder()<a name="line.534"></a>
+<span class="sourceLineNo">535</span>                          .setVersion(SnapshotManifestV1.DESCRIPTOR_VERSION)<a name="line.535"></a>
+<span class="sourceLineNo">536</span>                          .build());<a name="line.536"></a>
+<span class="sourceLineNo">537</span>      }<a name="line.537"></a>
+<span class="sourceLineNo">538</span><a name="line.538"></a>
+<span class="sourceLineNo">539</span>      public Path[] addRegionV2() throws IOException {<a name="line.539"></a>
+<span class="sourceLineNo">540</span>        return addRegion(desc.toBuilder()<a name="line.540"></a>
+<span class="sourceLineNo">541</span>                          .setVersion(SnapshotManifestV2.DESCRIPTOR_VERSION)<a name="line.541"></a>
+<span class="sourceLineNo">542</span>                          .build());<a name="line.542"></a>
+<span class="sourceLineNo">543</span>      }<a name="line.543"></a>
+<span class="sourceLineNo">544</span><a name="line.544"></a>
+<span class="sourceLineNo">545</span>      private Path[] addRegion(final SnapshotProtos.SnapshotDescription desc) throws IOException {<a name="line.545"></a>
+<span class="sourceLineNo">546</span>        if (this.snapshotted == tableRegions.length) {<a name="line.546"></a>
+<span class="sourceLineNo">547</span>          throw new UnsupportedOperationException("No more regions in the table");<a name="line.547"></a>
+<span class="sourceLineNo">548</span>        }<a name="line.548"></a>
+<span class="sourceLineNo">549</span><a name="line.549"></a>
+<span class="sourceLineNo">550</span>        RegionData regionData = tableRegions[this.snapshotted++];<a name="line.550"></a>
+<span class="sourceLineNo">551</span>        ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getName());<a name="line.551"></a>
+<span class="sourceLineNo">552</span>        SnapshotManifest manifest = SnapshotManifest.create(conf, fs, snapshotDir, desc, monitor);<a name="line.552"></a>
+<span class="sourceLineNo">553</span>        manifest.addRegion(regionData.tableDir, regionData.hri);<a name="line.553"></a>
+<span class="sourceLineNo">554</span>        return regionData.files;<a name="line.554"></a>
+<span class="sourceLineNo">555</span>      }<a name="line.555"></a>
+<span class="sourceLineNo">556</span><a name="line.556"></a>
+<span class="sourceLineNo">557</span>      private void corruptFile(Path p) throws IOException {<a name="line.557"></a>
+<span class="sourceLineNo">558</span>        String manifestName = p.getName();<a name="line.558"></a>
 <span class="sourceLineNo">559</span><a name="line.559"></a>
-<span class="sourceLineNo">560</span>        // Create a new region-manifest file<a name="line.560"></a>
-<span class="sourceLineNo">561</span>        FSDataOutputStream out = fs.create(p);<a name="line.561"></a>
-<span class="sourceLineNo">562</span><a name="line.562"></a>
-<span class="sourceLineNo">563</span>        //Copy the first 25 bytes of the original region-manifest into the new one,<a name="line.563"></a>
-<span class="sourceLineNo">564</span>        //make it a corrupted region-manifest file.<a name="line.564"></a>
-<span class="sourceLineNo">565</span>        FSDataInputStream input = fs.open(newP);<a name="line.565"></a>
-<span class="sourceLineNo">566</span>        byte[] buffer = new byte[25];<a name="line.566"></a>
-<span class="sourceLineNo">567</span>        int len = input.read(0, buffer, 0, 25);<a name="line.567"></a>
-<span class="sourceLineNo">568</span>        if (len &gt; 1) {<a name="line.568"></a>
-<span class="sourceLineNo">569</span>          out.write(buffer, 0, len - 1);<a name="line.569"></a>
-<span class="sourceLineNo">570</span>        }<a name="line.570"></a>
-<span class="sourceLineNo">571</span>        out.close();<a name="line.571"></a>
-<span class="sourceLineNo">572</span><a name="line.572"></a>
-<span class="sourceLineNo">573</span>        // Delete the original region-manifest<a name="line.573"></a>
-<span class="sourceLineNo">574</span>        fs.delete(newP);<a name="line.574"></a>
-<span class="sourceLineNo">575</span>      }<a name="line.575"></a>
+<span class="sourceLineNo">560</span>        // Rename the original region-manifest file<a name="line.560"></a>
+<span class="sourceLineNo">561</span>        Path newP = new Path(p.getParent(), manifestName + "1");<a name="line.561"></a>
+<span class="sourceLineNo">562</span>        fs.rename(p, newP);<a name="line.562"></a>
+<span class="sourceLineNo">563</span><a name="line.563"></a>
+<span class="sourceLineNo">564</span>        // Create a new region-manifest file<a name="line.564"></a>
+<span class="sourceLineNo">565</span>        FSDataOutputStream out = fs.create(p);<a name="line.565"></a>
+<span class="sourceLineNo">566</span><a name="line.566"></a>
+<span class="sourceLineNo">567</span>        //Copy the first 25 bytes of the original region-manifest into the new one,<a name="line.567"></a>
+<span class="sourceLineNo">568</span>        //make it a corrupted region-manifest file.<a name="line.568"></a>
+<span class="sourceLineNo">569</span>        FSDataInputStream input = fs.open(newP);<a name="line.569"></a>
+<span class="sourceLineNo">570</span>        byte[] buffer = new byte[25];<a name="line.570"></a>
+<span class="sourceLineNo">571</span>        int len = input.read(0, buffer, 0, 25);<a name="line.571"></a>
+<span class="sourceLineNo">572</span>        if (len &gt; 1) {<a name="line.572"></a>
+<span class="sourceLineNo">573</span>          out.write(buffer, 0, len - 1);<a name="line.573"></a>
+<span class="sourceLineNo">574</span>        }<a name="line.574"></a>
+<span class="sourceLineNo">575</span>        out.close();<a name="line.575"></a>
 <span class="sourceLineNo">576</span><a name="line.576"></a>
-<span class="sourceLineNo">577</span>      /**<a name="line.577"></a>
-<span class="sourceLineNo">578</span>       * Corrupt one region-manifest file<a name="line.578"></a>
-<span class="sourceLineNo">579</span>       *<a name="line.579"></a>
-<span class="sourceLineNo">580</span>       * @throws IOException on unexecpted error from the FS<a name="line.580"></a>
-<span class="sourceLineNo">581</span>       */<a name="line.581"></a>
-<span class="sourceLineNo">582</span>      public void corruptOneRegionManifest() throws IOException {<a name="line.582"></a>
-<span class="sourceLineNo">583</span>        FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir, new PathFilter() {<a name="line.583"></a>
-<span class="sourceLineNo">584</span>          @Override public boolean accept(Path path) {<a name="line.584"></a>
-<span class="sourceLineNo">585</span>            return path.getName().startsWith(SnapshotManifestV2.SNAPSHOT_MANIFEST_PREFIX);<a name="line.585"></a>
-<span class="sourceLineNo">586</span>          }<a name="line.586"></a>
-<span class="sourceLineNo">587</span>        });<a name="line.587"></a>
-<span class="sourceLineNo">588</span><a name="line.588"></a>
-<span class="sourceLineNo">589</span>        if (manifestFiles.length == 0) return;<a name="line.589"></a>
-<span class="sourceLineNo">590</span><a name="line.590"></a>
-<span class="sourceLineNo">591</span>        // Just choose the first one<a name="line.591"></a>
-<span class="sourceLineNo">592</span>        Path p = manifestFiles[0].getPath();<a name="line.592"></a>
-<span class="sourceLineNo">593</span>        corruptFile(p);<a name="line.593"></a>
-<span class="sourceLineNo">594</span>      }<a name="line.594"></a>
-<span class="sourceLineNo">595</span><a name="line.595"></a>
-<span class="sourceLineNo">596</span>      public void missOneRegionSnapshotFile() throws IOException {<a name="line.596"></a>
-<span class="sourceLineNo">597</span>        FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir);<a name="line.597"></a>
-<span class="sourceLineNo">598</span>        for (FileStatus fileStatus : manifestFiles) {<a name="line.598"></a>
-<span class="sourceLineNo">599</span>          String fileName = fileStatus.getPath().getName();<a name="line.599"></a>
-<span class="sourceLineNo">600</span>          if (fileName.endsWith(SnapshotDescriptionUtils.SNAPSHOTINFO_FILE)<a name="line.600"></a>
-<span class="sourceLineNo">601</span>            || fileName.endsWith(".tabledesc")<a name="line.601"></a>
-<span class="sourceLineNo">602</span>            || fileName.endsWith(SnapshotDescriptionUtils.SNAPSHOT_TMP_DIR_NAME)) {<a name="line.602"></a>
-<span class="sourceLineNo">603</span>              fs.delete(fileStatus.getPath(), true);<a name="line.603"></a>
-<span class="sourceLineNo">604</span>          }<a name="line.604"></a>
-<span class="sourceLineNo">605</span>        }<a name="line.605"></a>
-<span class="sourceLineNo">606</span>      }<a name="line.606"></a>
-<span class="sourceLineNo">607</span><a name="line.607"></a>
-<span class="sourceLineNo">608</span>      /**<a name="line.608"></a>
-<span class="sourceLineNo">609</span>       * Corrupt data-manifest file<a name="line.609"></a>
-<span class="sourceLineNo">610</span>       *<a name="line.610"></a>
-<span class="sourceLineNo">611</span>       * @throws IOException on unexecpted error from the FS<a name="line.611"></a>
-<span class="sourceLineNo">612</span>       */<a name="line.612"></a>
-<span class="sourceLineNo">613</span>      public void corruptDataManifest() throws IOException {<a name="line.613"></a>
-<span class="sourceLineNo">614</span>        FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir, new PathFilter() {<a name="line.614"></a>
-<span class="sourceLineNo">615</span>          @Override<a name="line.615"></a>
-<span class="sourceLineNo">616</span>          public boolean accept(Path path) {<a name="line.616"></a>
-<span class="sourceLineNo">617</span>            return path.getName().startsWith(SnapshotManifest.DATA_MANIFEST_NAME);<a name="line.617"></a>
-<span class="sourceLineNo">618</span>          }<a name="line.618"></a>
-<span class="sourceLineNo">619</span>        });<a name="line.619"></a>
-<span class="sourceLineNo">620</span><a name="line.620"></a>
-<span class="sourceLineNo">621</span>        if (manifestFiles.length == 0) return;<a name="line.621"></a>
-<span class="sourceLineNo">622</span><a name="line.622"></a>
-<span class="sourceLineNo">623</span>        // Just choose the first one<a name="line.623"></a>
-<span class="sourceLineNo">624</span>        Path p = manifestFiles[0].getPath();<a name="line.624"></a>
-<span class="sourceLineNo">625</span>        corruptFile(p);<a name="line.625"></a>
-<span class="sourceLineNo">626</span>      }<a name="line.626"></a>
-<span class="sourceLineNo">627</span><a name="line.627"></a>
-<span class="sourceLineNo">628</span>      public Path commit() throws IOException {<a name="line.628"></a>
-<span class="sourceLineNo">629</span>        ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getName());<a name="line.629"></a>
-<span class="sourceLineNo">630</span>        SnapshotManifest manifest = SnapshotManifest.create(conf, fs, snapshotDir, desc, monitor);<a name="line.630"></a>
-<span class="sourceLineNo">631</span>        manifest.addTableDescriptor(htd);<a name="line.631"></a>
-<span class="sourceLineNo">632</span>        manifest.consolidate();<a name="line.632"></a>
-<span class="sourceLineNo">633</span>        SnapshotDescriptionUtils.completeSnapshot(desc, rootDir, snapshotDir, fs);<a name="line.633"></a>
-<span class="sourceLineNo">634</span>        snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(desc, rootDir);<a name="line.634"></a>
-<span class="sourceLineNo">635</span>        return snapshotDir;<a name="line.635"></a>
-<span class="sourceLineNo">636</span>      }<a name="line.636"></a>
-<span class="sourceLineNo">637</span><a name="line.637"></a>
-<span class="sourceLineNo">638</span>      public void consolidate() throws IOException {<a name="line.638"></a>
-<span class="sourceLineNo">639</span>        ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getName());<a name="line.639"></a>
-<span class="sourceLineNo">640</span>        SnapshotManifest manifest = SnapshotManifest.create(conf, fs, snapshotDir, desc, monitor);<a name="line.640"></a>
-<span class="sourceLineNo">641</span>        manifest.addTableDescriptor(htd);<a name="line.641"></a>
-<span class="sourceLineNo">642</span>        manifest.consolidate();<a name="line.642"></a>
-<span class="sourceLineNo">643</span>      }<a name="line.643"></a>
-<span class="sourceLineNo">644</span>    }<a name="line.644"></a>
-<span class="sourceLineNo">645</span><a name="line.645"></a>
-<span class="sourceLineNo">646</span>    public SnapshotMock(final Configuration conf, final FileSystem fs, final Path rootDir) {<a name="line.646"></a>
-<span class="sourceLineNo">647</span>      this.fs = fs;<a name="line.647"></a>
-<span class="sourceLineNo">648</span>      this.conf = conf;<a name="line.648"></a>
-<span class="sourceLineNo">649</span>      this.rootDir = rootDir;<a name="line.649"></a>
-<span class="sourceLineNo">650</span>    }<a name="line.650"></a>
-<span class="sourceLineNo">651</span><a name="line.651"></a>
-<span class="sourceLineNo">652</span>    public SnapshotBuilder createSnapshotV1(final String snapshotName, final String tableName)<a name="line.652"></a>
-<span class="sourceLineNo">653</span>        throws IOException {<a name="line.653"></a>
-<span class="sourceLineNo">654</span>      return createSnapshot(snapshotName, tableName, SnapshotManifestV1.DESCRIPTOR_VERSION);<a name="line.654"></a>
-<span class="sourceLineNo">655</span>    }<a name="line.655"></a>
-<span class="sourceLineNo">656</span><a name="line.656"></a>
-<span class="sourceLineNo">657</span>    public SnapshotBuilder createSnapshotV1(final String snapshotName, final String tableName,<a name="line.657"></a>
-<span class="sourceLineNo">658</span>        final int numRegions) throws IOException {<a name="line.658"></a>
-<span class="sourceLineNo">659</span>      return createSnapshot(snapshotName, tableName, numRegions, SnapshotManifestV1.DESCRIPTOR_VERSION);<a name="line.659"></a>
-<span class="sourceLineNo">660</span>    }<a name="line.660"></a>
-<span class="sourceLineNo">661</span><a name="line.661"></a>
-<span class="sourceLineNo">662</span>    public SnapshotBuilder createSnapshotV2(final String snapshotName, final String tableName)<a name="line.662"></a>
-<span class="sourceLineNo">663</span>        throws IOException {<a name="line.663"></a>
-<span class="sourceLineNo">664</span>      return createSnapshot(snapshotName, tableName, SnapshotManifestV2.DESCRIPTOR_VERSION);<a name="line.664"></a>
-<span class="sourceLineNo">665</span>    }<a name="line.665"></a>
-<span class="sourceLineNo">666</span><a name="line.666"></a>
-<span class="sourceLineNo">667</span>    public SnapshotBuilder createSnapshotV2(final String snapshotName, final String tableName,<a name="line.667"></a>
-<span class="sourceLineNo">668</span>        final int numRegions) throws IOException {<a name="line.668"></a>
-<span class="sourceLineNo">669</span>      return createSnapshot(snapshotName, tableName, numRegions, SnapshotManifestV2.DESCRIPTOR_VERSION);<a name="line.669"></a>
-<span class="sourceLineNo">670</span>    }<a name="line.670"></a>
-<span class="sourceLineNo">671</span><a name="line.671"></a>
-<span class="sourceLineNo">672</span>    private SnapshotBuilder createSnapshot(final String snapshotName, final String tableName,<a name="line.672"></a>
-<span class="sourceLineNo">673</span>        final int version) throws IOException {<a name="line.673"></a>
-<span class="sourceLineNo">674</span>      return createSnapshot(snapshotName, tableName, TEST_NUM_REGIONS, version);<a name="line.674"></a>
-<span class="sourceLineNo">675</span>    }<a name="line.675"></a>
-<span class="sourceLineNo">676</span><a name="line.676"></a>
-<span class="sourceLineNo">677</span>    private SnapshotBuilder createSnapshot(final String snapshotName, final String tableName,<a name="line.677"></a>
-<span class="sourceLineNo">678</span>        final int numRegions, final int version) throws IOException {<a name="line.678"></a>
-<span class="sourceLineNo">679</span>      HTableDescriptor htd = createHtd(tableName);<a name="line.679"></a>
-<span class="sourceLineNo">680</span>      RegionData[] regions = createTable(htd, numRegions);<a name="line.680"></a>
-<span class="sourceLineNo">681</span><a name="line.681"></a>
-<span class="sourceLineNo">682</span>      SnapshotProtos.SnapshotDescription desc = SnapshotProtos.SnapshotDescription.newBuilder()<a name="line.682"></a>
-<span class="sourceLineNo">683</span>        .setTable(htd.getNameAsString())<a name="line.683"></a>
-<span class="sourceLineNo">684</span>        .setName(snapshotName)<a name="line.684"></a>
-<span class="sourceLineNo">685</span>        .setVersion(version)<a name="line.685"></a>
-<span class="sourceLineNo">686</span>        .build();<a name="line.686"></a>
-<span class="sourceLineNo">687</span><a name="line.687"></a>
-<span class="sourceLineNo">688</span>      Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(desc, rootDir);<a name="line.688"></a>
-<span class="sourceLineNo">689</span>      SnapshotDescriptionUtils.writeSnapshotInfo(desc, workingDir, fs);<a name="line.689"></a>
-<span class="sourceLineNo">690</span>      return new SnapshotBuilder(conf, fs, rootDir, htd, desc, regions);<a name="line.690"></a>
-<span class="sourceLineNo">691</span>    }<a name="line.691"></a>
-<span class="sourceLineNo">692</span><a name="line.692"></a>
-<span class="sourceLineNo">693</span>    public HTableDescriptor createHtd(final String tableName) {<a name="line.693"></a>
-<span class="sourceLineNo">694</span>      HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));<a name="line.694"></a>
-<span class="sourceLineNo">695</span>      htd.addFamily(new HColumnDescriptor(TEST_FAMILY));<a name="line.695"></a>
-<span class="sourceLineNo">696</span>      return htd;<a name="line.696"></a>
-<span class="sourceLineNo">697</span>    }<a name="line.697"></a>
-<span class="sourceLineNo">698</span><a name="line.698"></a>
-<span class="sourceLineNo">699</span>    private RegionData[] createTable(final HTableDescriptor htd, final int nregions)<a name="line.699"></a>
-<span class="sourceLineNo">700</span>        throws IOException {<a name="line.700"></a>
-<span class="sourceLineNo">701</span>      Path tableDir = FSUtils.getTableDir(rootDir, htd.getTableName());<a name="line.701"></a>
-<span class="sourceLineNo">702</span>      new FSTableDescriptors(conf).createTableDescriptorForTableDirectory(tableDir, htd, false);<a name="line.702"></a>
-<span class="sourceLineNo">703</span><a name="line.703"></a>
-<span class="sourceLineNo">704</span>      assertTrue(nregions % 2 == 0);<a name="line.704"></a>
-<span class="sourceLineNo">705</span>      RegionData[] regions = new RegionData[nregions];<a name="line.705"></a>
-<span class="sourceLineNo">706</span>      for (int i = 0; i &lt; regions.length; i += 2) {<a name="line.706"></a>
-<span class="sourceLineNo">707</span>        byte[] startKey = Bytes.toBytes(0 + i * 2);<a name="line.707"></a>
-<span class="sourceLineNo">708</span>        byte[] endKey = Bytes.toBytes(1 + i * 2);<a name="line.708"></a>
-<span class="sourceLineNo">709</span><a name="line.709"></a>
-<span class="sourceLineNo">710</span>        // First region, simple with one plain hfile.<a name="line.710"></a>
-<span class="sourceLineNo">711</span>        HRegionInfo hri = new HRegionInfo(htd.getTableName(), startKey, endKey);<a name="line.711"></a>
-<span class="sourceLineNo">712</span>        HRegionFileSystem rfs = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, hri);<a name="line.712"></a>
-<span class="sourceLineNo">713</span>        regions[i] = new RegionData(tableDir, hri, 3);<a name="line.713"></a>
-<span class="sourceLineNo">714</span>        for (int j = 0; j &lt; regions[i].files.length; ++j) {<a name="line.714"></a>
-<span class="sourceLineNo">715</span>          Path storeFile = createStoreFile(rfs.createTempName());<a name="line.715"></a>
-<span class="sourceLineNo">716</span>          regions[i].files[j] = rfs.commitStoreFile(TEST_FAMILY, storeFile);<a name="line.716"></a>
-<span class="sourceLineNo">717</span>        }<a name="line.717"></a>
-<span class="sourceLineNo">718</span><a name="line.718"></a>
-<span class="sourceLineNo">719</span>        // Second region, used to test the split case.<a name="line.719"></a>
-<span class="sourceLineNo">720</span>        // This region contains a reference to the hfile in the first region.<a name="line.720"></a>
-<span class="sourceLineNo">721</span>        startKey = Bytes.toBytes(2 + i * 2);<a name="line.721"></a>
-<span class="sourceLineNo">722</span>        endKey = Bytes.toBytes(3 + i * 2);<a name="line.722"></a>
-<span class="sourceLineNo">723</span>        hri = new HRegionInfo(htd.getTableName());<a name="line.723"></a>
-<span class="sourceLineNo">724</span>        rfs = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, hri);<a name="line.724"></a>
-<span class="sourceLineNo">725</span>        regions[i+1] = new RegionData(tableDir, hri, regions[i].files.length);<a name="line.725"></a>
-<span class="sourceLineNo">726</span>        for (int j = 0; j &lt; regions[i].files.length; ++j) {<a name="line.726"></a>
-<span class="sourceLineNo">727</span>          String refName = regions[i].files[j].getName() + '.' + regions[i].hri.getEncodedName();<a name="line.727"></a>
-<span class="sourceLineNo">728</span>          Path refFile = createStoreFile(new Path(rootDir, refName));<a name="line.728"></a>
-<span class="sourceLineNo">729</span>          regions[i+1].files[j] = rfs.commitStoreFile(TEST_FAMILY, refFile);<a name="line.729"></a>
-<span class="sourceLineNo">730</span>        }<a name="line.730"></a>
-<span class="sourceLineNo">731</span>      }<a name="line.731"></a>
-<span class="sourceLineNo">732</span>      return regions;<a name="line.732"></a>
-<span class="sourceLineNo">733</span>    }<a name="line.733"></a>
-<span class="sourceLineNo">734</span><a name="line.734"></a>
-<span class="sourceLineNo">735</span>    private Path createStoreFile(final Path storeFile)<a name="line.735"></a>
-<span class="sourceLineNo">736</span>        throws IOException {<a name="line.736"></a>
-<span class="sourceLineNo">737</span>      FSDataOutputStream out = fs.create(storeFile);<a name="line.737"></a>
-<span class="sourceLineNo">738</span>      try {<a name="line.738"></a>
-<span class="sourceLineNo">739</span>        out.write(Bytes.toBytes(storeFile.toString()));<a name="line.739"></a>
-<span class="sourceLineNo">740</span>      } finally {<a name="line.740"></a>
-<span class="sourceLineNo">741</span>        out.close();<a name="line.741"></a>
-<span class="sourceLineNo">742</span>      }<a name="line.742"></a>
-<span class="sourceLineNo">743</span>      return storeFile;<a name="line.743"></a>
-<span class="sourceLineNo">744</span>    }<a name="line.744"></a>
-<span class="sourceLineNo">745</span>  }<a name="line.745"></a>
-<span class="sourceLineNo">746</span><a name="line.746"></a>
-<span class="sourceLineNo">747</span>  // ==========================================================================<a name="line.747"></a>
-<span class="sourceLineNo">748</span>  //  Table Helpers<a name="line.748"></a>
-<span class="sourceLineNo">749</span>  // ==========================================================================<a name="line.749"></a>
-<span class="sourceLineNo">750</span>  public static void waitForTableToBeOnline(final HBaseTestingUtility util,<a name="line.750"></a>
-<span class="sourceLineNo">751</span>                                            final TableName tableName)<a name="line.751"></a>
-<span class="sourceLineNo">752</span>      throws IOException, InterruptedException {<a name="line.752"></a>
-<span class="sourceLineNo">753</span>    HRegionServer rs = util.getRSForFirstRegionInTable(tableName);<a name="line.753"></a>
-<span class="sourceLineNo">754</span>    List&lt;Region&gt; onlineRegions = rs.getOnlineRegions(tableName);<a name="line.754"></a>
-<span class="sourceLineNo">755</span>    for (Region region : onlineRegions) {<a name="line.755"></a>
-<span class="sourceLineNo">756</span>      region.waitForFlushesAndCompactions();<a name="line.756"></a>
-<span class="sourceLineNo">757</span>    }<a name="line.757"></a>
-<span class="sourceLineNo">758</span>    // Wait up to 60 seconds for a table to be available.<a name="line.758"></a>
-<span class="sourceLineNo">759</span>    util.waitFor(60000, util.predicateTableAvailable(tableName));<a name="line.759"></a>
-<span class="sourceLineNo">760</span>  }<a name="line.760"></a>
-<span class="sourceLineNo">761</span><a name="line.761"></a>
-<span class="sourceLineNo">762</span>  public static void createTable(final HBaseTestingUtility util, final TableName tableName,<a name="line.762"></a>
-<span class="sourceLineNo">763</span>      int regionReplication, int nRegions, final byte[]... families)<a name="line.763"></a>
-<span class="sourceLineNo">764</span>      throws IOException, InterruptedException {<a name="line.764"></a>
-<span class="sourceLineNo">765</span>    HTableDescriptor htd = new HTableDescriptor(tableName);<a name="line.765"></a>
-<span class="sourceLineNo">766</span>    htd.setRegionReplication(regionReplication);<a name="line.766"></a>
-<span class="sourceLineNo">767</span>    for (byte[] family : families) {<a name="line.767"></a>
-<span class="sourceLineNo">768</span>      HColumnDescriptor hcd = new HColumnDescriptor(family);<a name="line.768"></a>
-<span class="sourceLineNo">769</span>      htd.addFamily(hcd);<a name="line.769"></a>
-<span class="sourceLineNo">770</span>    }<a name="line.770"></a>
-<span class="sourceLineNo">771</span>    byte[][] splitKeys = getSplitKeys(nRegions);<a name="line.771"></a>
-<span class="sourceLineNo">772</span>    util.createTable(htd, splitKeys);<a name="line.772"></a>
-<span class="sourceLineNo">773</span>    assertEquals((splitKeys.length + 1) * regionReplication,<a name="line.773"></a>
-<span class="sourceLineNo">774</span>        util.getAdmin().getTableRegions(tableName).size());<a name="line.774"></a>
-<span class="sourceLineNo">775</span>  }<a name="line.775"></a>
-<span class="sourceLineNo">776</span><a name="line.776"></a>
-<span class="sourceLineNo">777</span>  public static byte[][] getSplitKeys() {<a name="line.777"></a>
-<span class="sourceLineNo">778</span>    return getSplitKeys(KEYS.length);<a name="line.778"></a>
+<span class="sourceLineNo">577</span>        // Delete the original region-manifest<a name="line.577"></a>
+<span class="sourceLineNo">578</span>        fs.delete(newP);<a name="line.578"></a>
+<span class="sourceLineNo">579</span>      }<a name="line.579"></a>
+<span class="sourceLineNo">580</span><a name="line.580"></a>
+<span class="sourceLineNo">581</span>      /**<a name="line.581"></a>
+<span class="sourceLineNo">582</span>       * Corrupt one region-manifest file<a name="line.582"></a>
+<span class="sourceLineNo">583</span>       *<a name="line.583"></a>
+<span class="sourceLineNo">584</span>       * @throws IOException on unexecpted error from the FS<a name="line.584"></a>
+<span class="sourceLineNo">585</span>       */<a name="line.585"></a>
+<span class="sourceLineNo">586</span>      public void corruptOneRegionManifest() throws IOException {<a name="line.586"></a>
+<span class="sourceLineNo">587</span>        FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir, new PathFilter() {<a name="line.587"></a>
+<span class="sourceLineNo">588</span>          @Override public boolean accept(Path path) {<a name="line.588"></a>
+<span class="sourceLineNo">589</span>            return path.getName().startsWith(SnapshotManifestV2.SNAPSHOT_MANIFEST_PREFIX);<a name="line.589"></a>
+<span class="sourceLineNo">590</span>          }<a name="line.590"></a>
+<span class="sourceLineNo">591</span>        });<a name="line.591"></a>
+<span class="sourceLineNo">592</span><a name="line.592"></a>
+<span class="sourceLineNo">593</span>        if (manifestFiles.length == 0) return;<a name="line.593"></a>
+<span class="sourceLineNo">594</span><a name="line.594"></a>
+<span class="sourceLineNo">595</span>        // Just choose the first one<a name="line.595"></a>
+<span class="sourceLineNo">596</span>        Path p = manifestFiles[0].getPath();<a name="line.596"></a>
+<span class="sourceLineNo">597</span>        corruptFile(p);<a name="line.597"></a>
+<span class="sourceLineNo">598</span>      }<a name="line.598"></a>
+<span class="sourceLineNo">599</span><a name="line.599"></a>
+<span class="sourceLineNo">600</span>      public void missOneRegionSnapshotFile() throws IOException {<a name="line.600"></a>
+<span class="sourceLineNo">601</span>        FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir);<a name="line.601"></a>
+<span class="sourceLineNo">602</span>        for (FileStatus fileStatus : manifestFiles) {<a name="line.602"></a>
+<span class="sourceLineNo">603</span>          String fileName = fileStatus.getPath().getName();<a name="line.603"></a>
+<span class="sourceLineNo">604</span>          if (fileName.endsWith(SnapshotDescriptionUtils.SNAPSHOTINFO_FILE)<a name="line.604"></a>
+<span class="sourceLineNo">605</span>            || fileName.endsWith(".tabledesc")<a name="line.605"></a>
+<span class="sourceLineNo">606</span>            || fileName.endsWith(SnapshotDescriptionUtils.SNAPSHOT_TMP_DIR_NAME)) {<a name="line.606"></a>
+<span class="sourceLineNo">607</span>              fs.delete(fileStatus.getPath(), true);<a name="line.607"></a>
+<span class="sourceLineNo">608</span>          }<a name="line.608"></a>
+<span class="sourceLineNo">609</span>        }<a name="line.609"></a>
+<span class="sourceLineNo">610</span>      }<a name="line.610"></a>
+<span class="sourceLineNo">611</span><a name="line.611"></a>
+<span class="sourceLineNo">612</span>      /**<a name="line.612"></a>
+<span class="sourceLineNo">613</span>       * Corrupt data-manifest file<a name="line.613"></a>
+<span class="sourceLineNo">614</span>       *<a name="line.614"></a>
+<span class="sourceLineNo">615</span>       * @throws IOException on unexecpted error from the FS<a name="line.615"></a>
+<span class="sourceLineNo">616</span>       */<a name="line.616"></a>
+<span class="sourceLineNo">617</span>      public void corruptDataManifest() throws IOException {<a name="line.617"></a>
+<span class="sourceLineNo">618</span>        FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir, new PathFilter() {<a name="line.618"></a>
+<span class="sourceLineNo">619</span>          @Override<a name="line.619"></a>
+<span class="sourceLineNo">620</span>          public boolean accept(Path path) {<a name="line.620"></a>
+<span class="sourceLineNo">621</span>            return path.getName().startsWith(SnapshotManifest.DATA_MANIFEST_NAME);<a name="line.621"></a>
+<span class="sourceLineNo">622</span>          }<a name="line.622"></a>
+<span class="sourceLineNo">623</span>        });<a name="line.623"></a>
+<span class="sourceLineNo">624</span><a name="line.624"></a>
+<span class="sourceLineNo">625</span>        if (manifestFiles.length == 0) return;<a name="line.625"></a>
+<span class="sourceLineNo">626</span><a name="line.626"></a>
+<span class="sourceLineNo">627</span>        // Just choose the first one<a name="line.627"></a>
+<span class="sourceLineNo">628</span>        Path p = manifestFiles[0].getPath();<a name="line.628"></a>
+<span class="sourceLineNo">629</span>        corruptFile(p);<a name="line.629"></a>
+<span class="sourceLineNo">630</span>      }<a name="line.630"></a>
+<span class="sourceLineNo">631</span><a name="line.631"></a>
+<span class="sourceLineNo">632</span>      public Path commit() throws IOException {<a name="line.632"></a>
+<span class="sourceLineNo">633</span>        ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getName());<a name="line.633"></a>
+<span class="sourceLineNo">634</span>        SnapshotManifest manifest = SnapshotManifest.create(conf, fs, snapshotDir, desc, monitor);<a name="line.634"></a>
+<span class="sourceLineNo">635</span>        manifest.addTableDescriptor(htd);<a name="line.635"></a>
+<span class="sourceLineNo">636</span>        manifest.consolidate();<a name="line.636"></a>
+<span class="sourceLineNo">637</span>        SnapshotDescriptionUtils.completeSnapshot(desc, rootDir, snapshotDir, fs);<a name="line.637"></a>
+<span class="sourceLineNo">638</span>        snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(desc, rootDir);<a name="line.638"></a>
+<span class="sourceLineNo">639</span>        return snapshotDir;<a name="line.639"></a>
+<span class="sourceLineNo">640</span>      }<a name="line.640"></a>
+<span class="sourceLineNo">641</span><a name="line.641"></a>
+<span class="sourceLineNo">642</span>      public void consolidate() throws IOException {<a name="line.642"></a>
+<span class="sourceLineNo">643</span>        ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher(desc.getName());<a name="line.643"></a>
+<span class="sourceLineNo">644</span>        SnapshotManifest manifest = SnapshotManifest.create(conf, fs, snapshotDir, desc, monitor);<a name="line.644"></a>
+<span class="sourceLineNo">645</span>        manifest.addTableDescriptor(htd);<a name="line.645"></a>
+<span class="sourceLineNo">646</span>        manifest.consolidate();<a name="line.646"></a>
+<span class="sourceLineNo">647</span>      }<a name="line.647"></a>
+<span class="sourceLineNo">648</span>    }<a name="line.648"></a>
+<span class="sourceLineNo">649</span><a name="line.649"></a>
+<span class="sourceLineNo">650</span>    public SnapshotMock(final Configuration conf, final FileSystem fs, final Path rootDir) {<a name="line.650"></a>
+<span class="sourceLineNo">651</span>      this.fs = fs;<a name="line.651"></a>
+<span class="sourceLineNo">652</span>      this.conf = conf;<a name="line.652"></a>
+<span class="sourceLineNo">653</span>      this.rootDir = rootDir;<a name="line.653"></a>
+<span class="sourceLineNo">654</span>    }<a name="line.654"></a>
+<span class="sourceLineNo">655</span><a name="line.655"></a>
+<span class="sourceLineNo">656</span>    public SnapshotBuilder createSnapshotV1(final String snapshotName, final String tableName)<a name="line.656"></a>
+<span class="sourceLineNo">657</span>        throws IOException {<a name="line.657"></a>
+<span class="sourceLineNo">658</span>      return createSnapshot(snapshotName, tableName, SnapshotManifestV1.DESCRIPTOR_VERSION);<a name="line.658"></a>
+<span class="sourceLineNo">659</span>    }<a name="line.659"></a>
+<span class="sourceLineNo">660</span><a name="line.660"></a>
+<span class="sourceLineNo">661</span>    public SnapshotBuilder createSnapshotV1(final String snapshotName, final String tableName,<a name="line.661"></a>
+<span class="sourceLineNo">662</span>        final int numRegions) throws IOException {<a name="line.662"></a>
+<span class="sourceLineNo">663</span>      return createSnapshot(snapshotName, tableName, numRegions, SnapshotManifestV1.DESCRIPTOR_VERSION);<a name="line.663"></a>
+<span class="sourceLineNo">664</span>    }<a name="line.664"></a>
+<span class="sourceLineNo">665</span><a name="line.665"></a>
+<span class="sourceLineNo">666</span>    public SnapshotBuilder createSnapshotV2(final String snapshotName, final String tableName)<a name="line.666"></a>
+<span class="sourceLineNo">667</span>        throws IOException {<a name="line.667"></a>
+<span class="sourceLineNo">668</span>      return createSnapshot(snapshotName, tableName, SnapshotManifestV2.DESCRIPTOR_VERSION);<a name="line.668"></a>
+<span class="sourceLineNo">669</span>    }<a name="line.669"></a>
+<span class="sourceLineNo">670</span><a name="line.670"></a>
+<span class="sourceLineNo">671</span>    public SnapshotBuilder createSnapshotV2(final String snapshotName, final String tableName,<a name="line.671"></a>
+<span class="sourceLineNo">672</span>        final int numRegions) throws IOException {<a name="line.672"></a>
+<span class="sourceLineNo">673</span>      return createSnapshot(snapshotName, tableName, numRegions, SnapshotManifestV2.DESCRIPTOR_VERSION);<a name="line.673"></a>
+<span class="sourceLineNo">674</span>    }<a name="line.674"></a>
+<span class="sourceLineNo">675</span><a name="line.675"></a>
+<span class="sourceLineNo">676</span>    private SnapshotBuilder createSnapshot(final String snapshotName, final String tableName,<a name="line.676"></a>
+<span class="sourceLineNo">677</span>        final int version) throws IOException {<a name="line.677"></a>
+<span class="sourceLineNo">678</span>      return createSnapshot(snapshotName, tableName, TEST_NUM_REGIONS, version);<a name="line.678"></a>
+<span class="sourceLineNo">679</span>    }<a name="line.679"></a>
+<span class="sourceLineNo">680</span><a name="line.680"></a>
+<span class="sourceLineNo">681</span>    private SnapshotBuilder createSnapshot(final String snapshotName, final String tableName,<a name="line.681"></a>
+<span class="sourceLineNo">682</span>        final int numRegions, final int version) throws IOException {<a name="line.682"></a>
+<span class="sourceLineNo">683</span>      HTableDescriptor htd = createHtd(tableName);<a name="line.683"></a>
+<span class="sourceLineNo">684</span>      RegionData[] regions = createTable(htd, numRegions);<a name="line.684"></a>
+<span class="sourceLineNo">685</span><a name="line.685"></a>
+<span class="sourceLineNo">686</span>      SnapshotProtos.SnapshotDescription desc = SnapshotProtos.SnapshotDescription.newBuilder()<a name="line.686"></a>
+<span class="sourceLineNo">687</span>        .setTable(htd.getNameAsString())<a name="line.687"></a>
+<span class="sourceLineNo">688</span>        .setName(snapshotName)<a name="line.688"></a>
+<span class="sourceLineNo">689</span>        .setVersion(version)<a name="line.689"></a>
+<span class="sourceLineNo">690</span>        .build();<a name="line.690"></a>
+<span class="sourceLineNo">691</span><a name="line.691"></a>
+<span class="sourceLineNo">692</span>      Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(desc, rootDir);<a name="line.692"></a>
+<span class="sourceLineNo">693</span>      SnapshotDescriptionUtils.writeSnapshotInfo(desc, workingDir, fs);<a name="line.693"></a>
+<span class="sourceLineNo">694</span>      return new SnapshotBuilder(conf, fs, rootDir, htd, desc, regions);<a name="line.694"></a>
+<span class="sourceLineNo">695</span>    }<a name="line.695"></a>
+<span class="sourceLineNo">696</span><a name="line.696"></a>
+<span class="sourceLineNo">697</span>    public HTableDescriptor createHtd(final String tableName) {<a name="line.697"></a>
+<span class="sourceLineNo">698</span>      HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));<a name="line.698"></a>
+<span class="sourceLineNo">699</span>      htd.addFamily(new HColumnDescriptor(TEST_FAMILY));<a name="line.699"></a>
+<span class="sourceLineNo">700</span>      return htd;<a name="line.700"></a>
+<span class="sourceLineNo">701</span>    }<a name="line.701"></a>
+<span class="sourceLineNo">702</span><a name="line.702"></a>
+<span class="sourceLineNo">703</span>    private RegionData[] createTable(final HTableDescriptor htd, final int nregions)<a name="line.703"></a>
+<span class="sourceLineNo">704</span>        throws IOException {<a name="line.704"></a>
+<span class="sourceLineNo">705</span>      Path tableDir = FSUtils.getTableDir(rootDir, htd.getTableName());<a name="line.705"></a>
+<span class="sourceLineNo">706</span>      new FSTableDescriptors(conf).createTableDescriptorForTableDirectory(tableDir, htd, false);<a name="line.706"></a>
+<span class="sourceLineNo">707</span><a name="line.707"></a>
+<span class="sourceLineNo">708</span>      assertTrue(nregions % 2 == 0);<a name="line.708"></a>
+<span class="sourceLineNo">709</span>      RegionData[] regions = new RegionData[nregions];<a name="line.709"></a>
+<span class="sourceLineNo">710</span>      for (int i = 0; i &lt; regions.length; i += 2) {<a name="line.710"></a>
+<span class="sourceLineNo">711</span>        byte[] startKey = Bytes.toBytes(0 + i * 2);<a name="line.711"></a>
+<span class="sourceLineNo">712</span>        byte[] endKey = Bytes.toBytes(1 + i * 2);<a name="line.712"></a>
+<span class="sourceLineNo">713</span><a name="line.713"></a>
+<span class="sourceLineNo">714</span>        // First region, simple with one plain hfile.<a name="line.714"></a>
+<span class="sourceLineNo">715</span>        HRegionInfo hri = new HRegionInfo(htd.getTableName(), startKey, endKey);<a name="line.715"></a>
+<span class="sourceLineNo">716</span>        HRegionFileSystem rfs = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, hri);<a name="line.716"></a>
+<span class="sourceLineNo">717</span>        regions[i] = new RegionData(tableDir, hri, 3);<a name="line.717"></a>
+<span class="sourceLineNo">718</span>        for (int j = 0; j &lt; regions[i].files.length; ++j) {<a name="line.718"></a>
+<span class="sourceLineNo">719</span>          Path storeFile = createStoreFile(rfs.createTempName());<a name="line.719"></a>
+<span class="sourceLineNo">720</span>          regions[i].files[j] = rfs.commitStoreFile(TEST_FAMILY, storeFile);<a name="line.720"></a>
+<span class="sourceLineNo">721</span>        }<a name="line.721"></a>
+<span class="sourceLineNo">722</span><a name="line.722"></a>
+<span class="sourceLineNo">723</span>        // Second region, used to test the split case.<a name="line.723"></a>
+<span class="sourceLineNo">724</span>        // This region contains a reference to the hfile in the first region.<a name="line.724"></a>
+<span class="sourceLineNo">725</span>        startKey = Bytes.toBytes(2 + i * 2);<a name="line.725"></a>
+<span class="sourceLineNo">726</span>        endKey = Bytes.toBytes(3 + i * 2);<a name="line.726"></a>
+<span class="sourceLineNo">727</span>        hri = new HRegionInfo(htd.getTableName());<a name="line.727"></a>
+<span class="sourceLineNo">728</span>        rfs = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, hri);<a name="line.728"></a>
+<span class="sourceLineNo">729</span>        regions[i+1] = new RegionData(tableDir, hri, regions[i].files.length);<a name="line.729"></a>
+<span class="sourceLineNo">730</span>        for (int j = 0; j &lt; regions[i].files.length; ++j) {<a name="line.730"></a>
+<span class="sourceLineNo">731</span>          String refName = regions[i].files[j].getName() + '.' + regions[i].hri.getEncodedName();<a name="line.731"></a>
+<span class="sourceLineNo">732</span>          Path refFile = createStoreFile(new Path(rootDir, refName));<a name="line.732"></a>
+<span class="sourceLineNo">733</span>          regions[i+1].files[j] = rfs.commitStoreFile(TEST_FAMILY, refFile);<a name="line.733"></a>
+<span class="sourceLineNo">734</span>        }<a name="line.734"></a>
+<span class="sourceLineNo">735</span>      }<a name="line.735"></a>
+<span class="sourceLineNo">736</span>      return regions;<a name="line.736"></a>
+<span class="sourceLineNo">737</span>    }<a name="line.737"></a>
+<span class="sourceLineNo">738</span><a name="line.738"></a>
+<span class="sourceLineNo">739</span>    private Path createStoreFile(final Path storeFile)<a name="line.739"></a>
+<span class="sourceLineNo">740</span>        throws IOException {<a name="line.740"></a>
+<span class="sourceLineNo">741</span>      FSDataOutputStream out = fs.create(storeFile);<a name="line.741"></a>
+<span class="sourceLineNo">742</span>      try {<a name="line.742"></a>
+<span class="sourceLineNo">743</span>        out.write(Bytes.toBytes(storeFile.toString()));<a name="line.743"></a>
+<span class="sourceLineNo">744</span>      } finally {<a name="line.744"></a>
+<span class="sourceLineNo">745</span>        out.close();<a name="line.745"></a>
+<span class="sourceLineNo">746</span>      }<a name="line.746"></a>
+<span class="sourceLineNo">747</span>      return storeFile;<a name="line.747"></a>
+<span class="sourceLineNo">748</span>    }<a name="line.748"></a>
+<span class="sourceLineNo">749</span>  }<a name="line.749"></a>
+<span class="sourceLineNo">750</span><a name="line.750"></a>
+<span class="sourceLineNo">751</span>  // ==========================================================================<a name="line.751"></a>
+<span class="sourceLineNo">752</span>  //  Table Helpers<a name="line.752"></a>
+<span class="sourceLineNo">753</span>  // ==========================================================================<a name="line.753"></a>
+<span class="sourceLineNo">754</span>  public static void waitForTableToBeOnline(final HBaseTestingUtility util,<a name="line.754"></a>
+<span class="sourceLineNo">755</span>                                            final TableName tableName)<a name="line.755"></a>
+<span class="sourceLineNo">756</span>      throws IOException, InterruptedException {<a name="line.756"></a>
+<span class="sourceLineNo">757</span>    HRegionServer rs = util.getRSForFirstRegionInTable(tableName);<a name="line.757"></a>
+<span class="sourceLineNo">758</span>    List&lt;Region&gt; onlineRegions = rs.getOnlineRegions(tableName);<a name="line.758"></a>
+<span class="sourceLineNo">759</span>    for (Region region : onlineRegions) {<a name="line.759"></a>
+<span class="sourceLineNo">760</span>      region.waitForFlushesAndCompactions();<a name="line.760"></a>
+<span class="sourceLineNo">761</span>    }<a name="line.761"></a>
+<span class="sourceLineNo">762</span>    // Wait up to 60 seconds for a table to be available.<a name="line.762"></a>
+<span class="sourceLineNo">763</span>    util.waitFor(60000, util.predicateTableAvailable(tableName));<a name="line.763"></a>
+<span class="sourceLineNo">764</span>  }<a name="line.764"></a>
+<span class="sourceLineNo">765</span><a name="line.765"></a>
+<span class="sourceLineNo">766</span>  public static void createTable(final HBaseTestingUtility util, final TableName tableName,<a name="line.766"></a>
+<span class="sourceLineNo">767</span>      int regionReplication, int nRegions, final byte[]... families)<a name="line.767"></a>
+<span class="sourceLineNo">768</span>      throws IOException, InterruptedException {<a name="line.768"></a>
+<span class="sourceLineNo">769</span>    HTableDescriptor htd = new HTableDescriptor(tableName);<a name="line.769"></a>
+<span class="sourceLineNo">770</span>    htd.setRegionReplication(regionReplication);<a name="line.770"></a>
+<span class="sourceLineNo">771</span>    for (byte[] family : families) {<a name="line.771"></a>
+<span class="sourceLineNo">772</span>      HColumnDescriptor hcd = new HColumnDescriptor(family);<a name="line.772"></a>
+<span class="sourceLineNo">773</span>      htd.addFamily(hcd);<a name="line.773"></a>
+<span class="sourceLineNo">774</span>    }<a name="line.774"></a>
+<span class="sourceLineNo">775</span>    byte[][] splitKeys = getSplitKeys(nRegions);<a name="line.775"></a>
+<span class="sourceLineNo">776</span>    util.createTable(htd, splitKeys);<a name="line.776"></a>
+<span class="sourceLineNo">777</span>    assertEquals((splitKeys.length + 1) * regionReplication,<a name="line.777"></a>
+<span class="sourceLineNo">778</span>        util.getAdmin().getTableRegions(tableName).size());<a name="line.778"></a>
 <span class="sourceLineNo">779</span>  }<a name="line.779"></a>
 <span class="sourceLineNo">780</span><a name="line.780"></a>
-<span class="sourceLineNo">781</span>  public static byte[][] getSplitKeys(int nRegions) {<a name="line.781"></a>
-<span class="sourceLineNo">782</span>    nRegions = nRegions &lt; KEYS.length ? nRegions : (KEYS.length - 1);<a name="line.782"></a>
-<span class="sourceLineNo">783</span>    final byte[][] splitKeys = new byte[nRegions-1][];<a name="line.783"></a>
-<span class="sourceLineNo">784</span>    final int step = KEYS.length / nRegions;<a name="line.784"></a>
-<span class="sourceLineNo">785</span>    int keyIndex = 1;<a name="line.785"></a>
-<span class="sourceLineNo">786</span>    for (int i = 0; i &lt; splitKeys.length; ++i) {<a name="line.786"></a>
-<span class="sourceLineNo">787</span>      splitKeys[i] = new byte[] { KEYS[keyIndex] };<a name="line.787"></a>
-<span class="sourceLineNo">788</span>      keyIndex += step;<a name="line.788"></a>
-<span class="sourceLineNo">789</span>    }<a name="line.789"></a>
-<span class="sourceLineNo">790</span>    return splitKeys;<a name="line.790"></a>
-<span class="sourceLineNo">791</span>  }<a name="line.791"></a>
-<span class="sourceLineNo">792</span><a name="line.792"></a>
-<span class="sourceLineNo">793</span>  public static void createTable(final HBaseTestingUtility util, final TableName tableName,<a name="line.793"></a>
-<span class="sourceLineNo">794</span>      final byte[]... families) throws IOException, InterruptedException {<a name="line.794"></a>
-<span class="sourceLineNo">795</span>    createTable(util, tableName, 1, families);<a name="line.795"></a>
-<span class="sourceLineNo">796</span>  }<a name="line.796"></a>
-<span class="sourceLineNo">797</span><a name="line.797"></a>
-<span class="sourceLineNo">798</span>  public static void createTable(final HBaseTestingUtility util, final TableName tableName,<a name="line.798"></a>
-<span class="sourceLineNo">799</span>      final int regionReplication, final byte[]... families) throws IOException, InterruptedException {<a name="line.799"></a>
-<span class="sourceLineNo">800</span>    createTable(util, tableName, regionReplication, KEYS.length, families);<a name="line.800"></a>
-<span class="sourceLineNo">801</span>  }<a name="line.801"></a>
-<span class="sourceLineNo">802</span><a name="line.802"></a>
-<span class="sourceLineNo">803</span>  public static void createPreSplitTable(final HBaseTestingUtility util, final TableName tableName,<a name="line.803"></a>
-<span class="sourceLineNo">804</span>      final int nRegions, final byte[]... families) throws IOException, InterruptedException {<a name="line.804"></a>
-<span class="sourceLineNo">805</span>    createTable(util, tableName, 1, nRegions, families);<a name="line.805"></a>
-<span class="sourceLineNo">806</span>  }<a name="line.806"></a>
-<span class="sourceLineNo">807</span><a name="line.807"></a>
-<span class="sourceLineNo">808</span>  public static void loadData(final HBaseTestingUtility util, final TableName tableName, int rows,<a name="line.808"></a>
-<span class="sourceLineNo">809</span>      byte[]... families) throws IOException, InterruptedException {<a name="line.809"></a>
-<span class="sourceLineNo">810</span>    BufferedMutator mutator = util.getConnection().getBufferedMutator(tableName);<a name="line.810"></a>
-<span class="sourceLineNo">811</span>    loadData(util, mutator, rows, families);<a name="line.811"></a>
-<span class="sourceLineNo">812</span>  }<a name="line.812"></a>
-<span class="sourceLineNo">813</span><a name="line.813"></a>
-<span class="sourceLineNo">814</span>  public static void loadData(final HBaseTestingUtility util, final BufferedMutator mutator, int rows,<a name="line.814"></a>
-<span class="sourceLineNo">815</span>      byte[]... families) throws IOException, InterruptedException {<a name="line.815"></a>
-<span class="sourceLineNo">816</span>    // Ensure one row per region<a name="line.816"></a>
-<span class="sourceLineNo">817</span>    assertTrue(rows &gt;= KEYS.length);<a name="line.817"></a>
-<span class="sourceLineNo">818</span>    for (byte k0: KEYS) {<a name="line.818"></a>
-<span class="sourceLineNo">819</span>      byte[] k = new byte[] { k0 };<a name="line.819"></a>
-<span class="sourceLineNo">820</span>      byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), k);<a name="line.820"></a>
-<span class="sourceLineNo">821</span>      byte[] key = Bytes.add(k, Bytes.toBytes(MD5Hash.getMD5AsHex(value)));<a name="line.821"></a>
-<span class="sourceLineNo">822</span>      final byte[][] families1 = families;<a name="line.822"></a>
-<span class="sourceLineNo">823</span>      final byte[] key1 = key;<a name="line.823"></a>
-<span class="sourceLineNo">824</span>      final byte[] value1 = value;<a name="line.824"></a>
-<span class="sourceLineNo">825</span>      mutator.mutate(createPut(families1, key1, value1));<a name="line.825"></a>
-<span class="sourceLineNo">826</span>      rows--;<a name="line.826"></a>
-<span class="sourceLineNo">827</span>    }<a name="line.827"></a>
-<span class="sourceLineNo">828</span><a name="line.828"></a>
-<span class="sourceLineNo">829</span>    // Add other extra rows. more rows, more files<a name="line.829"></a>
-<span class="sourceLineNo">830</span>    while (rows-- &gt; 0) {<a name="line.830"></a>
-<span class="sourceLineNo">831</span>      byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), Bytes.toBytes(rows));<a name="line.831"></a>
-<span class="sourceLineNo">832</span>      byte[] key = Bytes.toBytes(MD5Hash.getMD5AsHex(value));<a name="line.832"></a>
-<span class="sourceLineNo">833</span>      final byte[][] families1 = families;<a name="line.833"></a>
-<span class="sourceLineNo">834</span>      final byte[] key1 = key;<a name="line.834"></a>
-<span class="sourceLineNo">835</span>      final byte[] value1 = value;<a name="line.835"></a>
-<span class="sourceLineNo">836</span>      mutator.mutate(createPut(families1, key1, value1));<a name="line.836"></a>
-<span class="sourceLineNo">837</span>    }<a name="line.837"></a>
-<span class="sourceLineNo">838</span>    mutator.flush();<a name="line.838"></a>
-<span class="sourceLineNo">839</span><a name="line.839"></a>
-<span class="sourceLineNo">840</span>    waitForTableToBeOnline(util, mutator.getName());<a name="line.840"></a>
-<span class="sourceLineNo">841</span>  }<a name="line.841"></a>
-<span class="sourceLineNo">842</span><a name="line.842"></a>
-<span class="sourceLineNo">843</span>  private static Put createPut(final byte[][] families, final byte[] key, final byte[] value) {<a name="line.843"></a>
-<span class="sourceLineNo">844</span>    byte[] q = Bytes.toBytes("q");<a name="line.844"></a>
-<span class="sourceLineNo">845</span>    Put put = new Put(key);<a name="line.845"></a>
-<span class="sourceLineNo">846</span>    put.setDurability(Durability.SKIP_WAL);<a name="line.846"></a>
-<span class="sourceLineNo">847</span>    for (byte[] family: families) {<a name="line.847"></a>
-<span class="sourceLineNo">848</span>      put.addColumn(family, q, value);<a name="line.848"></a>
-<span class="sourceLineNo">849</span>    }<a name="line.849"></a>
-<span class="sourceLineNo">850</span>    return put;<a name="line.850"></a>
-<span class="sourceLineNo">851</span>  }<a name="line.851"></a>
-<span class="sourceLineNo">852</span><a name="line.852"></a>
-<span class="sourceLineNo">853</span>  public static void deleteAllSnapshots(final Admin admin)<a name="line.853"></a>
-<span class="sourceLineNo">854</span>      throws IOException {<a name="line.854"></a>
-<span class="sourceLineNo">855</span>    // Delete all the snapshots<a name="line.855"></a>
-<span class="sourceLineNo">856</span>    for (SnapshotDescription snapshot: admin.listSnapshots()) {<a name="line.856"></a>
-<span class="sourceLineNo">857</span>      admin.deleteSnapshot(snapshot.getName());<a name="line.857"></a>
-<span class="sourceLineNo">858</span>    }<a name="line.858"></a>
-<span class="sourceLineNo">859</span>    SnapshotTestingUtils.assertNoSnapshots(admin);<a name="line.859"></a>
-<span class="sourceLineNo">860</span>  }<a name="line.860"></a>
-<span class="sourceLineNo">861</span><a name="line.861"></a>
-<span class="sourceLineNo">862</span>  public static void deleteArchiveDirectory(final HBaseTesting

<TRUNCATED>

Mime
View raw message