http://git-wip-us.apache.org/repos/asf/hbase-site/blob/ac54a6a8/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.html
index 9edb4b1..11458f7 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.html
@@ -660,558 +660,560 @@
 <span class="sourceLineNo">652</span>   * @param f File to split.<a 
name="line.652"></a>
 <span class="sourceLineNo">653</span>   * @param splitRow Split Row<a 
name="line.653"></a>
 <span class="sourceLineNo">654</span>   * @param top True if we are referring 
to the top half of the hfile.<a name="line.654"></a>
-<span class="sourceLineNo">655</span>   * @param splitPolicy<a 
name="line.655"></a>
-<span class="sourceLineNo">656</span>   * @return Path to created reference.<a 
name="line.656"></a>
-<span class="sourceLineNo">657</span>   * @throws IOException<a 
name="line.657"></a>
-<span class="sourceLineNo">658</span>   */<a name="line.658"></a>
-<span class="sourceLineNo">659</span>  public Path splitStoreFile(RegionInfo 
hri, String familyName, HStoreFile f, byte[] splitRow,<a name="line.659"></a>
-<span class="sourceLineNo">660</span>      boolean top, RegionSplitPolicy 
splitPolicy) throws IOException {<a name="line.660"></a>
-<span class="sourceLineNo">661</span>    if (splitPolicy == null || 
!splitPolicy.skipStoreFileRangeCheck(familyName)) {<a name="line.661"></a>
-<span class="sourceLineNo">662</span>      // Check whether the split row lies 
in the range of the store file<a name="line.662"></a>
-<span class="sourceLineNo">663</span>      // If it is outside the range, 
return directly.<a name="line.663"></a>
-<span class="sourceLineNo">664</span>      f.initReader();<a 
name="line.664"></a>
-<span class="sourceLineNo">665</span>      try {<a name="line.665"></a>
-<span class="sourceLineNo">666</span>        if (top) {<a name="line.666"></a>
-<span class="sourceLineNo">667</span>          //check if larger than last 
key.<a name="line.667"></a>
-<span class="sourceLineNo">668</span>          Cell splitKey = 
PrivateCellUtil.createFirstOnRow(splitRow);<a name="line.668"></a>
-<span class="sourceLineNo">669</span>          Optional&lt;Cell&gt; lastKey = 
f.getLastKey();<a name="line.669"></a>
-<span class="sourceLineNo">670</span>          // If lastKey is null means 
storefile is empty.<a name="line.670"></a>
-<span class="sourceLineNo">671</span>          if (!lastKey.isPresent()) {<a 
name="line.671"></a>
-<span class="sourceLineNo">672</span>            return null;<a 
name="line.672"></a>
-<span class="sourceLineNo">673</span>          }<a name="line.673"></a>
-<span class="sourceLineNo">674</span>          if 
(f.getComparator().compare(splitKey, lastKey.get()) &gt; 0) {<a 
name="line.674"></a>
-<span class="sourceLineNo">675</span>            return null;<a 
name="line.675"></a>
-<span class="sourceLineNo">676</span>          }<a name="line.676"></a>
-<span class="sourceLineNo">677</span>        } else {<a name="line.677"></a>
-<span class="sourceLineNo">678</span>          //check if smaller than first 
key<a name="line.678"></a>
-<span class="sourceLineNo">679</span>          Cell splitKey = 
PrivateCellUtil.createLastOnRow(splitRow);<a name="line.679"></a>
-<span class="sourceLineNo">680</span>          Optional&lt;Cell&gt; firstKey = 
f.getFirstKey();<a name="line.680"></a>
-<span class="sourceLineNo">681</span>          // If firstKey is null means 
storefile is empty.<a name="line.681"></a>
-<span class="sourceLineNo">682</span>          if (!firstKey.isPresent()) {<a 
name="line.682"></a>
-<span class="sourceLineNo">683</span>            return null;<a 
name="line.683"></a>
-<span class="sourceLineNo">684</span>          }<a name="line.684"></a>
-<span class="sourceLineNo">685</span>          if 
(f.getComparator().compare(splitKey, firstKey.get()) &lt; 0) {<a 
name="line.685"></a>
-<span class="sourceLineNo">686</span>            return null;<a 
name="line.686"></a>
-<span class="sourceLineNo">687</span>          }<a name="line.687"></a>
-<span class="sourceLineNo">688</span>        }<a name="line.688"></a>
-<span class="sourceLineNo">689</span>      } finally {<a name="line.689"></a>
-<span class="sourceLineNo">690</span>        f.closeStoreFile(f.getCacheConf() 
!= null ? f.getCacheConf().shouldEvictOnClose() : true);<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><a name="line.693"></a>
-<span class="sourceLineNo">694</span>    Path splitDir = new 
Path(getSplitsDir(hri), familyName);<a name="line.694"></a>
-<span class="sourceLineNo">695</span>    // A reference to the bottom half of 
the hsf store file.<a name="line.695"></a>
-<span class="sourceLineNo">696</span>    Reference r =<a name="line.696"></a>
-<span class="sourceLineNo">697</span>      top ? 
Reference.createTopReference(splitRow): 
Reference.createBottomReference(splitRow);<a name="line.697"></a>
-<span class="sourceLineNo">698</span>    // Add the referred-to regions name 
as a dot separated suffix.<a name="line.698"></a>
-<span class="sourceLineNo">699</span>    // See REF_NAME_REGEX regex above.  
The referred-to regions name is<a name="line.699"></a>
-<span class="sourceLineNo">700</span>    // up in the path of the passed in 
&lt;code&gt;f&lt;/code&gt; -- parentdir is family,<a name="line.700"></a>
-<span class="sourceLineNo">701</span>    // then the directory above is the 
region name.<a name="line.701"></a>
-<span class="sourceLineNo">702</span>    String parentRegionName = 
regionInfoForFs.getEncodedName();<a name="line.702"></a>
-<span class="sourceLineNo">703</span>    // Write reference with same file id 
only with the other region name as<a name="line.703"></a>
-<span class="sourceLineNo">704</span>    // suffix and into the new region 
location (under same family).<a name="line.704"></a>
-<span class="sourceLineNo">705</span>    Path p = new Path(splitDir, 
f.getPath().getName() + "." + parentRegionName);<a name="line.705"></a>
-<span class="sourceLineNo">706</span>    return r.write(fs, p);<a 
name="line.706"></a>
-<span class="sourceLineNo">707</span>  }<a name="line.707"></a>
-<span class="sourceLineNo">708</span><a name="line.708"></a>
-<span class="sourceLineNo">709</span>  // 
===========================================================================<a 
name="line.709"></a>
-<span class="sourceLineNo">710</span>  //  Merge Helpers<a name="line.710"></a>
+<span class="sourceLineNo">655</span>   * @param splitPolicy A split policy 
instance; be careful! May not be full populated; e.g. if<a name="line.655"></a>
+<span class="sourceLineNo">656</span>   *                    this method is 
invoked on the Master side, then the RegionSplitPolicy will<a 
name="line.656"></a>
+<span class="sourceLineNo">657</span>   *                    NOT have a 
reference to a Region.<a name="line.657"></a>
+<span class="sourceLineNo">658</span>   * @return Path to created reference.<a 
name="line.658"></a>
+<span class="sourceLineNo">659</span>   * @throws IOException<a 
name="line.659"></a>
+<span class="sourceLineNo">660</span>   */<a name="line.660"></a>
+<span class="sourceLineNo">661</span>  public Path splitStoreFile(RegionInfo 
hri, String familyName, HStoreFile f, byte[] splitRow,<a name="line.661"></a>
+<span class="sourceLineNo">662</span>      boolean top, RegionSplitPolicy 
splitPolicy) throws IOException {<a name="line.662"></a>
+<span class="sourceLineNo">663</span>    if (splitPolicy == null || 
!splitPolicy.skipStoreFileRangeCheck(familyName)) {<a name="line.663"></a>
+<span class="sourceLineNo">664</span>      // Check whether the split row lies 
in the range of the store file<a name="line.664"></a>
+<span class="sourceLineNo">665</span>      // If it is outside the range, 
return directly.<a name="line.665"></a>
+<span class="sourceLineNo">666</span>      f.initReader();<a 
name="line.666"></a>
+<span class="sourceLineNo">667</span>      try {<a name="line.667"></a>
+<span class="sourceLineNo">668</span>        if (top) {<a name="line.668"></a>
+<span class="sourceLineNo">669</span>          //check if larger than last 
key.<a name="line.669"></a>
+<span class="sourceLineNo">670</span>          Cell splitKey = 
PrivateCellUtil.createFirstOnRow(splitRow);<a name="line.670"></a>
+<span class="sourceLineNo">671</span>          Optional&lt;Cell&gt; lastKey = 
f.getLastKey();<a name="line.671"></a>
+<span class="sourceLineNo">672</span>          // If lastKey is null means 
storefile is empty.<a name="line.672"></a>
+<span class="sourceLineNo">673</span>          if (!lastKey.isPresent()) {<a 
name="line.673"></a>
+<span class="sourceLineNo">674</span>            return null;<a 
name="line.674"></a>
+<span class="sourceLineNo">675</span>          }<a name="line.675"></a>
+<span class="sourceLineNo">676</span>          if 
(f.getComparator().compare(splitKey, lastKey.get()) &gt; 0) {<a 
name="line.676"></a>
+<span class="sourceLineNo">677</span>            return null;<a 
name="line.677"></a>
+<span class="sourceLineNo">678</span>          }<a name="line.678"></a>
+<span class="sourceLineNo">679</span>        } else {<a name="line.679"></a>
+<span class="sourceLineNo">680</span>          //check if smaller than first 
key<a name="line.680"></a>
+<span class="sourceLineNo">681</span>          Cell splitKey = 
PrivateCellUtil.createLastOnRow(splitRow);<a name="line.681"></a>
+<span class="sourceLineNo">682</span>          Optional&lt;Cell&gt; firstKey = 
f.getFirstKey();<a name="line.682"></a>
+<span class="sourceLineNo">683</span>          // If firstKey is null means 
storefile is empty.<a name="line.683"></a>
+<span class="sourceLineNo">684</span>          if (!firstKey.isPresent()) {<a 
name="line.684"></a>
+<span class="sourceLineNo">685</span>            return null;<a 
name="line.685"></a>
+<span class="sourceLineNo">686</span>          }<a name="line.686"></a>
+<span class="sourceLineNo">687</span>          if 
(f.getComparator().compare(splitKey, firstKey.get()) &lt; 0) {<a 
name="line.687"></a>
+<span class="sourceLineNo">688</span>            return null;<a 
name="line.688"></a>
+<span class="sourceLineNo">689</span>          }<a name="line.689"></a>
+<span class="sourceLineNo">690</span>        }<a name="line.690"></a>
+<span class="sourceLineNo">691</span>      } finally {<a name="line.691"></a>
+<span class="sourceLineNo">692</span>        f.closeStoreFile(f.getCacheConf() 
!= null ? f.getCacheConf().shouldEvictOnClose() : true);<a name="line.692"></a>
+<span class="sourceLineNo">693</span>      }<a name="line.693"></a>
+<span class="sourceLineNo">694</span>    }<a name="line.694"></a>
+<span class="sourceLineNo">695</span><a name="line.695"></a>
+<span class="sourceLineNo">696</span>    Path splitDir = new 
Path(getSplitsDir(hri), familyName);<a name="line.696"></a>
+<span class="sourceLineNo">697</span>    // A reference to the bottom half of 
the hsf store file.<a name="line.697"></a>
+<span class="sourceLineNo">698</span>    Reference r =<a name="line.698"></a>
+<span class="sourceLineNo">699</span>      top ? 
Reference.createTopReference(splitRow): 
Reference.createBottomReference(splitRow);<a name="line.699"></a>
+<span class="sourceLineNo">700</span>    // Add the referred-to regions name 
as a dot separated suffix.<a name="line.700"></a>
+<span class="sourceLineNo">701</span>    // See REF_NAME_REGEX regex above.  
The referred-to regions name is<a name="line.701"></a>
+<span class="sourceLineNo">702</span>    // up in the path of the passed in 
&lt;code&gt;f&lt;/code&gt; -- parentdir is family,<a name="line.702"></a>
+<span class="sourceLineNo">703</span>    // then the directory above is the 
region name.<a name="line.703"></a>
+<span class="sourceLineNo">704</span>    String parentRegionName = 
regionInfoForFs.getEncodedName();<a name="line.704"></a>
+<span class="sourceLineNo">705</span>    // Write reference with same file id 
only with the other region name as<a name="line.705"></a>
+<span class="sourceLineNo">706</span>    // suffix and into the new region 
location (under same family).<a name="line.706"></a>
+<span class="sourceLineNo">707</span>    Path p = new Path(splitDir, 
f.getPath().getName() + "." + parentRegionName);<a name="line.707"></a>
+<span class="sourceLineNo">708</span>    return r.write(fs, p);<a 
name="line.708"></a>
+<span class="sourceLineNo">709</span>  }<a name="line.709"></a>
+<span class="sourceLineNo">710</span><a name="line.710"></a>
 <span class="sourceLineNo">711</span>  // 
===========================================================================<a 
name="line.711"></a>
-<span class="sourceLineNo">712</span>  /** @return {@link Path} to the temp 
directory used during merge operations */<a name="line.712"></a>
-<span class="sourceLineNo">713</span>  public Path getMergesDir() {<a 
name="line.713"></a>
-<span class="sourceLineNo">714</span>    return new Path(getRegionDir(), 
REGION_MERGES_DIR);<a name="line.714"></a>
-<span class="sourceLineNo">715</span>  }<a name="line.715"></a>
-<span class="sourceLineNo">716</span><a name="line.716"></a>
-<span class="sourceLineNo">717</span>  Path getMergesDir(final RegionInfo hri) 
{<a name="line.717"></a>
-<span class="sourceLineNo">718</span>    return new Path(getMergesDir(), 
hri.getEncodedName());<a name="line.718"></a>
-<span class="sourceLineNo">719</span>  }<a name="line.719"></a>
-<span class="sourceLineNo">720</span><a name="line.720"></a>
-<span class="sourceLineNo">721</span>  /**<a name="line.721"></a>
-<span class="sourceLineNo">722</span>   * Clean up any merge detritus that may 
have been left around from previous merge attempts.<a name="line.722"></a>
-<span class="sourceLineNo">723</span>   */<a name="line.723"></a>
-<span class="sourceLineNo">724</span>  void cleanupMergesDir() throws 
IOException {<a name="line.724"></a>
-<span class="sourceLineNo">725</span>    deleteDir(getMergesDir());<a 
name="line.725"></a>
-<span class="sourceLineNo">726</span>  }<a name="line.726"></a>
-<span class="sourceLineNo">727</span><a name="line.727"></a>
-<span class="sourceLineNo">728</span>  /**<a name="line.728"></a>
-<span class="sourceLineNo">729</span>   * Remove merged region<a 
name="line.729"></a>
-<span class="sourceLineNo">730</span>   * @param mergedRegion {@link 
RegionInfo}<a name="line.730"></a>
-<span class="sourceLineNo">731</span>   * @throws IOException<a 
name="line.731"></a>
-<span class="sourceLineNo">732</span>   */<a name="line.732"></a>
-<span class="sourceLineNo">733</span>  public void cleanupMergedRegion(final 
RegionInfo mergedRegion) throws IOException {<a name="line.733"></a>
-<span class="sourceLineNo">734</span>    Path regionDir = new 
Path(this.tableDir, mergedRegion.getEncodedName());<a name="line.734"></a>
-<span class="sourceLineNo">735</span>    if (this.fs.exists(regionDir) 
&amp;&amp; !this.fs.delete(regionDir, true)) {<a name="line.735"></a>
-<span class="sourceLineNo">736</span>      throw new IOException("Failed 
delete of " + regionDir);<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><a name="line.739"></a>
-<span class="sourceLineNo">740</span>  static boolean mkdirs(FileSystem fs, 
Configuration conf, Path dir) throws IOException {<a name="line.740"></a>
-<span class="sourceLineNo">741</span>    if 
(FSUtils.isDistributedFileSystem(fs) ||<a name="line.741"></a>
-<span class="sourceLineNo">742</span>        
!conf.getBoolean(HConstants.ENABLE_DATA_FILE_UMASK, false)) {<a 
name="line.742"></a>
-<span class="sourceLineNo">743</span>      return fs.mkdirs(dir);<a 
name="line.743"></a>
-<span class="sourceLineNo">744</span>    }<a name="line.744"></a>
-<span class="sourceLineNo">745</span>    FsPermission perms = 
FSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY);<a 
name="line.745"></a>
-<span class="sourceLineNo">746</span>    return fs.mkdirs(dir, perms);<a 
name="line.746"></a>
-<span class="sourceLineNo">747</span>  }<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>   * Create the region merges 
directory.<a name="line.750"></a>
-<span class="sourceLineNo">751</span>   * @throws IOException If merges dir 
already exists or we fail to create it.<a name="line.751"></a>
-<span class="sourceLineNo">752</span>   * @see 
HRegionFileSystem#cleanupMergesDir()<a name="line.752"></a>
-<span class="sourceLineNo">753</span>   */<a name="line.753"></a>
-<span class="sourceLineNo">754</span>  public void createMergesDir() throws 
IOException {<a name="line.754"></a>
-<span class="sourceLineNo">755</span>    Path mergesdir = getMergesDir();<a 
name="line.755"></a>
-<span class="sourceLineNo">756</span>    if (fs.exists(mergesdir)) {<a 
name="line.756"></a>
-<span class="sourceLineNo">757</span>      LOG.info("The " + mergesdir<a 
name="line.757"></a>
-<span class="sourceLineNo">758</span>          + " directory exists.  Hence 
deleting it to recreate it");<a name="line.758"></a>
-<span class="sourceLineNo">759</span>      if (!fs.delete(mergesdir, true)) 
{<a name="line.759"></a>
-<span class="sourceLineNo">760</span>        throw new IOException("Failed 
deletion of " + mergesdir<a name="line.760"></a>
-<span class="sourceLineNo">761</span>            + " before creating them 
again.");<a name="line.761"></a>
-<span class="sourceLineNo">762</span>      }<a name="line.762"></a>
-<span class="sourceLineNo">763</span>    }<a name="line.763"></a>
-<span class="sourceLineNo">764</span>    if (!mkdirs(fs, conf, mergesdir))<a 
name="line.764"></a>
-<span class="sourceLineNo">765</span>      throw new IOException("Failed 
create of " + mergesdir);<a name="line.765"></a>
-<span class="sourceLineNo">766</span>  }<a name="line.766"></a>
-<span class="sourceLineNo">767</span><a name="line.767"></a>
-<span class="sourceLineNo">768</span>  /**<a name="line.768"></a>
-<span class="sourceLineNo">769</span>   * Write out a merge reference under 
the given merges directory. Package local<a name="line.769"></a>
-<span class="sourceLineNo">770</span>   * so it doesnt leak out of 
regionserver.<a name="line.770"></a>
-<span class="sourceLineNo">771</span>   * @param mergedRegion {@link 
RegionInfo} of the merged region<a name="line.771"></a>
-<span class="sourceLineNo">772</span>   * @param familyName Column Family 
Name<a name="line.772"></a>
-<span class="sourceLineNo">773</span>   * @param f File to create reference.<a 
name="line.773"></a>
-<span class="sourceLineNo">774</span>   * @param mergedDir<a 
name="line.774"></a>
-<span class="sourceLineNo">775</span>   * @return Path to created reference.<a 
name="line.775"></a>
-<span class="sourceLineNo">776</span>   * @throws IOException<a 
name="line.776"></a>
-<span class="sourceLineNo">777</span>   */<a name="line.777"></a>
-<span class="sourceLineNo">778</span>  public Path mergeStoreFile(RegionInfo 
mergedRegion, String familyName, HStoreFile f,<a name="line.778"></a>
-<span class="sourceLineNo">779</span>      Path mergedDir) throws IOException 
{<a name="line.779"></a>
-<span class="sourceLineNo">780</span>    Path referenceDir = new Path(new 
Path(mergedDir,<a name="line.780"></a>
-<span class="sourceLineNo">781</span>        mergedRegion.getEncodedName()), 
familyName);<a name="line.781"></a>
-<span class="sourceLineNo">782</span>    // A whole reference to the store 
file.<a name="line.782"></a>
-<span class="sourceLineNo">783</span>    Reference r = 
Reference.createTopReference(regionInfoForFs.getStartKey());<a 
name="line.783"></a>
-<span class="sourceLineNo">784</span>    // Add the referred-to regions name 
as a dot separated suffix.<a name="line.784"></a>
-<span class="sourceLineNo">785</span>    // See REF_NAME_REGEX regex above. 
The referred-to regions name is<a name="line.785"></a>
-<span class="sourceLineNo">786</span>    // up in the path of the passed in 
&lt;code&gt;f&lt;/code&gt; -- parentdir is family,<a name="line.786"></a>
-<span class="sourceLineNo">787</span>    // then the directory above is the 
region name.<a name="line.787"></a>
-<span class="sourceLineNo">788</span>    String mergingRegionName = 
regionInfoForFs.getEncodedName();<a name="line.788"></a>
-<span class="sourceLineNo">789</span>    // Write reference with same file id 
only with the other region name as<a name="line.789"></a>
-<span class="sourceLineNo">790</span>    // suffix and into the new region 
location (under same family).<a name="line.790"></a>
-<span class="sourceLineNo">791</span>    Path p = new Path(referenceDir, 
f.getPath().getName() + "."<a name="line.791"></a>
-<span class="sourceLineNo">792</span>        + mergingRegionName);<a 
name="line.792"></a>
-<span class="sourceLineNo">793</span>    return r.write(fs, p);<a 
name="line.793"></a>
-<span class="sourceLineNo">794</span>  }<a name="line.794"></a>
-<span class="sourceLineNo">795</span><a name="line.795"></a>
-<span class="sourceLineNo">796</span>  /**<a name="line.796"></a>
-<span class="sourceLineNo">797</span>   * Commit a merged region, moving it 
from the merges temporary directory to<a name="line.797"></a>
-<span class="sourceLineNo">798</span>   * the proper location in the 
filesystem.<a name="line.798"></a>
-<span class="sourceLineNo">799</span>   * @param mergedRegionInfo merged 
region {@link RegionInfo}<a name="line.799"></a>
-<span class="sourceLineNo">800</span>   * @throws IOException<a 
name="line.800"></a>
-<span class="sourceLineNo">801</span>   */<a name="line.801"></a>
-<span class="sourceLineNo">802</span>  public void commitMergedRegion(final 
RegionInfo mergedRegionInfo) throws IOException {<a name="line.802"></a>
-<span class="sourceLineNo">803</span>    Path regionDir = new 
Path(this.tableDir, mergedRegionInfo.getEncodedName());<a name="line.803"></a>
-<span class="sourceLineNo">804</span>    Path mergedRegionTmpDir = 
this.getMergesDir(mergedRegionInfo);<a name="line.804"></a>
-<span class="sourceLineNo">805</span>    // Move the tmp dir in the expected 
location<a name="line.805"></a>
-<span class="sourceLineNo">806</span>    if (mergedRegionTmpDir != null 
&amp;&amp; fs.exists(mergedRegionTmpDir)) {<a name="line.806"></a>
-<span class="sourceLineNo">807</span>      if (!fs.rename(mergedRegionTmpDir, 
regionDir)) {<a name="line.807"></a>
-<span class="sourceLineNo">808</span>        throw new IOException("Unable to 
rename " + mergedRegionTmpDir + " to "<a name="line.808"></a>
-<span class="sourceLineNo">809</span>            + regionDir);<a 
name="line.809"></a>
-<span class="sourceLineNo">810</span>      }<a name="line.810"></a>
-<span class="sourceLineNo">811</span>    }<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>  // 
===========================================================================<a 
name="line.814"></a>
-<span class="sourceLineNo">815</span>  //  Create/Open/Delete Helpers<a 
name="line.815"></a>
+<span class="sourceLineNo">712</span>  //  Merge Helpers<a name="line.712"></a>
+<span class="sourceLineNo">713</span>  // 
===========================================================================<a 
name="line.713"></a>
+<span class="sourceLineNo">714</span>  /** @return {@link Path} to the temp 
directory used during merge operations */<a name="line.714"></a>
+<span class="sourceLineNo">715</span>  public Path getMergesDir() {<a 
name="line.715"></a>
+<span class="sourceLineNo">716</span>    return new Path(getRegionDir(), 
REGION_MERGES_DIR);<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>  Path getMergesDir(final RegionInfo hri) 
{<a name="line.719"></a>
+<span class="sourceLineNo">720</span>    return new Path(getMergesDir(), 
hri.getEncodedName());<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>  /**<a name="line.723"></a>
+<span class="sourceLineNo">724</span>   * Clean up any merge detritus that may 
have been left around from previous merge attempts.<a name="line.724"></a>
+<span class="sourceLineNo">725</span>   */<a name="line.725"></a>
+<span class="sourceLineNo">726</span>  void cleanupMergesDir() throws 
IOException {<a name="line.726"></a>
+<span class="sourceLineNo">727</span>    deleteDir(getMergesDir());<a 
name="line.727"></a>
+<span class="sourceLineNo">728</span>  }<a name="line.728"></a>
+<span class="sourceLineNo">729</span><a name="line.729"></a>
+<span class="sourceLineNo">730</span>  /**<a name="line.730"></a>
+<span class="sourceLineNo">731</span>   * Remove merged region<a 
name="line.731"></a>
+<span class="sourceLineNo">732</span>   * @param mergedRegion {@link 
RegionInfo}<a name="line.732"></a>
+<span class="sourceLineNo">733</span>   * @throws IOException<a 
name="line.733"></a>
+<span class="sourceLineNo">734</span>   */<a name="line.734"></a>
+<span class="sourceLineNo">735</span>  public void cleanupMergedRegion(final 
RegionInfo mergedRegion) throws IOException {<a name="line.735"></a>
+<span class="sourceLineNo">736</span>    Path regionDir = new 
Path(this.tableDir, mergedRegion.getEncodedName());<a name="line.736"></a>
+<span class="sourceLineNo">737</span>    if (this.fs.exists(regionDir) 
&amp;&amp; !this.fs.delete(regionDir, true)) {<a name="line.737"></a>
+<span class="sourceLineNo">738</span>      throw new IOException("Failed 
delete of " + regionDir);<a name="line.738"></a>
+<span class="sourceLineNo">739</span>    }<a name="line.739"></a>
+<span class="sourceLineNo">740</span>  }<a name="line.740"></a>
+<span class="sourceLineNo">741</span><a name="line.741"></a>
+<span class="sourceLineNo">742</span>  static boolean mkdirs(FileSystem fs, 
Configuration conf, Path dir) throws IOException {<a name="line.742"></a>
+<span class="sourceLineNo">743</span>    if 
(FSUtils.isDistributedFileSystem(fs) ||<a name="line.743"></a>
+<span class="sourceLineNo">744</span>        
!conf.getBoolean(HConstants.ENABLE_DATA_FILE_UMASK, false)) {<a 
name="line.744"></a>
+<span class="sourceLineNo">745</span>      return fs.mkdirs(dir);<a 
name="line.745"></a>
+<span class="sourceLineNo">746</span>    }<a name="line.746"></a>
+<span class="sourceLineNo">747</span>    FsPermission perms = 
FSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY);<a 
name="line.747"></a>
+<span class="sourceLineNo">748</span>    return fs.mkdirs(dir, perms);<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>   * Create the region merges 
directory.<a name="line.752"></a>
+<span class="sourceLineNo">753</span>   * @throws IOException If merges dir 
already exists or we fail to create it.<a name="line.753"></a>
+<span class="sourceLineNo">754</span>   * @see 
HRegionFileSystem#cleanupMergesDir()<a name="line.754"></a>
+<span class="sourceLineNo">755</span>   */<a name="line.755"></a>
+<span class="sourceLineNo">756</span>  public void createMergesDir() throws 
IOException {<a name="line.756"></a>
+<span class="sourceLineNo">757</span>    Path mergesdir = getMergesDir();<a 
name="line.757"></a>
+<span class="sourceLineNo">758</span>    if (fs.exists(mergesdir)) {<a 
name="line.758"></a>
+<span class="sourceLineNo">759</span>      LOG.info("The " + mergesdir<a 
name="line.759"></a>
+<span class="sourceLineNo">760</span>          + " directory exists.  Hence 
deleting it to recreate it");<a name="line.760"></a>
+<span class="sourceLineNo">761</span>      if (!fs.delete(mergesdir, true)) 
{<a name="line.761"></a>
+<span class="sourceLineNo">762</span>        throw new IOException("Failed 
deletion of " + mergesdir<a name="line.762"></a>
+<span class="sourceLineNo">763</span>            + " before creating them 
again.");<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>    if (!mkdirs(fs, conf, mergesdir))<a 
name="line.766"></a>
+<span class="sourceLineNo">767</span>      throw new IOException("Failed 
create of " + mergesdir);<a name="line.767"></a>
+<span class="sourceLineNo">768</span>  }<a name="line.768"></a>
+<span class="sourceLineNo">769</span><a name="line.769"></a>
+<span class="sourceLineNo">770</span>  /**<a name="line.770"></a>
+<span class="sourceLineNo">771</span>   * Write out a merge reference under 
the given merges directory. Package local<a name="line.771"></a>
+<span class="sourceLineNo">772</span>   * so it doesnt leak out of 
regionserver.<a name="line.772"></a>
+<span class="sourceLineNo">773</span>   * @param mergedRegion {@link 
RegionInfo} of the merged region<a name="line.773"></a>
+<span class="sourceLineNo">774</span>   * @param familyName Column Family 
Name<a name="line.774"></a>
+<span class="sourceLineNo">775</span>   * @param f File to create reference.<a 
name="line.775"></a>
+<span class="sourceLineNo">776</span>   * @param mergedDir<a 
name="line.776"></a>
+<span class="sourceLineNo">777</span>   * @return Path to created reference.<a 
name="line.777"></a>
+<span class="sourceLineNo">778</span>   * @throws IOException<a 
name="line.778"></a>
+<span class="sourceLineNo">779</span>   */<a name="line.779"></a>
+<span class="sourceLineNo">780</span>  public Path mergeStoreFile(RegionInfo 
mergedRegion, String familyName, HStoreFile f,<a name="line.780"></a>
+<span class="sourceLineNo">781</span>      Path mergedDir) throws IOException 
{<a name="line.781"></a>
+<span class="sourceLineNo">782</span>    Path referenceDir = new Path(new 
Path(mergedDir,<a name="line.782"></a>
+<span class="sourceLineNo">783</span>        mergedRegion.getEncodedName()), 
familyName);<a name="line.783"></a>
+<span class="sourceLineNo">784</span>    // A whole reference to the store 
file.<a name="line.784"></a>
+<span class="sourceLineNo">785</span>    Reference r = 
Reference.createTopReference(regionInfoForFs.getStartKey());<a 
name="line.785"></a>
+<span class="sourceLineNo">786</span>    // Add the referred-to regions name 
as a dot separated suffix.<a name="line.786"></a>
+<span class="sourceLineNo">787</span>    // See REF_NAME_REGEX regex above. 
The referred-to regions name is<a name="line.787"></a>
+<span class="sourceLineNo">788</span>    // up in the path of the passed in 
&lt;code&gt;f&lt;/code&gt; -- parentdir is family,<a name="line.788"></a>
+<span class="sourceLineNo">789</span>    // then the directory above is the 
region name.<a name="line.789"></a>
+<span class="sourceLineNo">790</span>    String mergingRegionName = 
regionInfoForFs.getEncodedName();<a name="line.790"></a>
+<span class="sourceLineNo">791</span>    // Write reference with same file id 
only with the other region name as<a name="line.791"></a>
+<span class="sourceLineNo">792</span>    // suffix and into the new region 
location (under same family).<a name="line.792"></a>
+<span class="sourceLineNo">793</span>    Path p = new Path(referenceDir, 
f.getPath().getName() + "."<a name="line.793"></a>
+<span class="sourceLineNo">794</span>        + mergingRegionName);<a 
name="line.794"></a>
+<span class="sourceLineNo">795</span>    return r.write(fs, p);<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>  /**<a name="line.798"></a>
+<span class="sourceLineNo">799</span>   * Commit a merged region, moving it 
from the merges temporary directory to<a name="line.799"></a>
+<span class="sourceLineNo">800</span>   * the proper location in the 
filesystem.<a name="line.800"></a>
+<span class="sourceLineNo">801</span>   * @param mergedRegionInfo merged 
region {@link RegionInfo}<a name="line.801"></a>
+<span class="sourceLineNo">802</span>   * @throws IOException<a 
name="line.802"></a>
+<span class="sourceLineNo">803</span>   */<a name="line.803"></a>
+<span class="sourceLineNo">804</span>  public void commitMergedRegion(final 
RegionInfo mergedRegionInfo) throws IOException {<a name="line.804"></a>
+<span class="sourceLineNo">805</span>    Path regionDir = new 
Path(this.tableDir, mergedRegionInfo.getEncodedName());<a name="line.805"></a>
+<span class="sourceLineNo">806</span>    Path mergedRegionTmpDir = 
this.getMergesDir(mergedRegionInfo);<a name="line.806"></a>
+<span class="sourceLineNo">807</span>    // Move the tmp dir in the expected 
location<a name="line.807"></a>
+<span class="sourceLineNo">808</span>    if (mergedRegionTmpDir != null 
&amp;&amp; fs.exists(mergedRegionTmpDir)) {<a name="line.808"></a>
+<span class="sourceLineNo">809</span>      if (!fs.rename(mergedRegionTmpDir, 
regionDir)) {<a name="line.809"></a>
+<span class="sourceLineNo">810</span>        throw new IOException("Unable to 
rename " + mergedRegionTmpDir + " to "<a name="line.810"></a>
+<span class="sourceLineNo">811</span>            + regionDir);<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>  }<a name="line.814"></a>
+<span class="sourceLineNo">815</span><a name="line.815"></a>
 <span class="sourceLineNo">816</span>  // 
===========================================================================<a 
name="line.816"></a>
-<span class="sourceLineNo">817</span>  /**<a name="line.817"></a>
-<span class="sourceLineNo">818</span>   * Log the current state of the 
region<a name="line.818"></a>
-<span class="sourceLineNo">819</span>   * @param LOG log to output 
information<a name="line.819"></a>
-<span class="sourceLineNo">820</span>   * @throws IOException if an unexpected 
exception occurs<a name="line.820"></a>
-<span class="sourceLineNo">821</span>   */<a name="line.821"></a>
-<span class="sourceLineNo">822</span>  void logFileSystemState(final Logger 
LOG) throws IOException {<a name="line.822"></a>
-<span class="sourceLineNo">823</span>    FSUtils.logFileSystemState(fs, 
this.getRegionDir(), LOG);<a name="line.823"></a>
-<span class="sourceLineNo">824</span>  }<a name="line.824"></a>
-<span class="sourceLineNo">825</span><a name="line.825"></a>
-<span class="sourceLineNo">826</span>  /**<a name="line.826"></a>
-<span class="sourceLineNo">827</span>   * @param hri<a name="line.827"></a>
-<span class="sourceLineNo">828</span>   * @return Content of the file we write 
out to the filesystem under a region<a name="line.828"></a>
-<span class="sourceLineNo">829</span>   * @throws IOException<a 
name="line.829"></a>
-<span class="sourceLineNo">830</span>   */<a name="line.830"></a>
-<span class="sourceLineNo">831</span>  private static byte[] 
getRegionInfoFileContent(final RegionInfo hri) throws IOException {<a 
name="line.831"></a>
-<span class="sourceLineNo">832</span>    return 
RegionInfo.toDelimitedByteArray(hri);<a name="line.832"></a>
-<span class="sourceLineNo">833</span>  }<a name="line.833"></a>
-<span class="sourceLineNo">834</span><a name="line.834"></a>
-<span class="sourceLineNo">835</span>  /**<a name="line.835"></a>
-<span class="sourceLineNo">836</span>   * Create a {@link RegionInfo} from the 
serialized version on-disk.<a name="line.836"></a>
-<span class="sourceLineNo">837</span>   * @param fs {@link FileSystem} that 
contains the Region Info file<a name="line.837"></a>
-<span class="sourceLineNo">838</span>   * @param regionDir {@link Path} to the 
Region Directory that contains the Info file<a name="line.838"></a>
-<span class="sourceLineNo">839</span>   * @return An {@link RegionInfo} 
instance gotten from the Region Info file.<a name="line.839"></a>
-<span class="sourceLineNo">840</span>   * @throws IOException if an error 
occurred during file open/read operation.<a name="line.840"></a>
-<span class="sourceLineNo">841</span>   */<a name="line.841"></a>
-<span class="sourceLineNo">842</span>  public static RegionInfo 
loadRegionInfoFileContent(final FileSystem fs, final Path regionDir)<a 
name="line.842"></a>
-<span class="sourceLineNo">843</span>      throws IOException {<a 
name="line.843"></a>
-<span class="sourceLineNo">844</span>    FSDataInputStream in = fs.open(new 
Path(regionDir, REGION_INFO_FILE));<a name="line.844"></a>
-<span class="sourceLineNo">845</span>    try {<a name="line.845"></a>
-<span class="sourceLineNo">846</span>      return RegionInfo.parseFrom(in);<a 
name="line.846"></a>
-<span class="sourceLineNo">847</span>    } finally {<a name="line.847"></a>
-<span class="sourceLineNo">848</span>      in.close();<a name="line.848"></a>
-<span class="sourceLineNo">849</span>    }<a name="line.849"></a>
-<span class="sourceLineNo">850</span>  }<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>   * Write the .regioninfo file 
on-disk.<a name="line.853"></a>
-<span class="sourceLineNo">854</span>   */<a name="line.854"></a>
-<span class="sourceLineNo">855</span>  private static void 
writeRegionInfoFileContent(final Configuration conf, final FileSystem fs,<a 
name="line.855"></a>
-<span class="sourceLineNo">856</span>      final Path regionInfoFile, final 
byte[] content) throws IOException {<a name="line.856"></a>
-<span class="sourceLineNo">857</span>    // First check to get the 
permissions<a name="line.857"></a>
-<span class="sourceLineNo">858</span>    FsPermission perms = 
FSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY);<a 
name="line.858"></a>
-<span class="sourceLineNo">859</span>    // Write the RegionInfo file 
content<a name="line.859"></a>
-<span class="sourceLineNo">860</span>    FSDataOutputStream out = 
FSUtils.create(conf, fs, regionInfoFile, perms, null);<a name="line.860"></a>
-<span class="sourceLineNo">861</span>    try {<a name="line.861"></a>
-<span class="sourceLineNo">862</span>      out.write(content);<a 
name="line.862"></a>
-<span class="sourceLineNo">863</span>    } finally {<a name="line.863"></a>
-<span class="sourceLineNo">864</span>      out.close();<a name="line.864"></a>
-<span class="sourceLineNo">865</span>    }<a name="line.865"></a>
-<span class="sourceLineNo">866</span>  }<a name="line.866"></a>
-<span class="sourceLineNo">867</span><a name="line.867"></a>
-<span class="sourceLineNo">868</span>  /**<a name="line.868"></a>
-<span class="sourceLineNo">869</span>   * Write out an info file under the 
stored region directory. Useful recovering mangled regions.<a 
name="line.869"></a>
-<span class="sourceLineNo">870</span>   * If the regionInfo already exists 
on-disk, then we fast exit.<a name="line.870"></a>
-<span class="sourceLineNo">871</span>   */<a name="line.871"></a>
-<span class="sourceLineNo">872</span>  void checkRegionInfoOnFilesystem() 
throws IOException {<a name="line.872"></a>
-<span class="sourceLineNo">873</span>    // Compose the content of the file so 
we can compare to length in filesystem. If not same,<a name="line.873"></a>
-<span class="sourceLineNo">874</span>    // rewrite it (it may have been 
written in the old format using Writables instead of pb). The<a 
name="line.874"></a>
-<span class="sourceLineNo">875</span>    // pb version is much shorter -- we 
write now w/o the toString version -- so checking length<a name="line.875"></a>
-<span class="sourceLineNo">876</span>    // only should be sufficient. I don't 
want to read the file every time to check if it pb<a name="line.876"></a>
-<span class="sourceLineNo">877</span>    // serialized.<a name="line.877"></a>
-<span class="sourceLineNo">878</span>    byte[] content = 
getRegionInfoFileContent(regionInfoForFs);<a name="line.878"></a>
-<span class="sourceLineNo">879</span><a name="line.879"></a>
-<span class="sourceLineNo">880</span>    // Verify if the region directory 
exists before opening a region. We need to do this since if<a 
name="line.880"></a>
-<span class="sourceLineNo">881</span>    // the region directory doesn't exist 
we will re-create the region directory and a new HRI<a name="line.881"></a>
-<span class="sourceLineNo">882</span>    // when HRegion.openHRegion() is 
called.<a name="line.882"></a>
-<span class="sourceLineNo">883</span>    try {<a name="line.883"></a>
-<span class="sourceLineNo">884</span>      FileStatus status = 
fs.getFileStatus(getRegionDir());<a name="line.884"></a>
-<span class="sourceLineNo">885</span>    } catch (FileNotFoundException e) {<a 
name="line.885"></a>
-<span class="sourceLineNo">886</span>      LOG.warn(getRegionDir() + " doesn't 
exist for region: " + regionInfoForFs.getEncodedName() +<a name="line.886"></a>
-<span class="sourceLineNo">887</span>          " on table " + 
regionInfo.getTable());<a name="line.887"></a>
-<span class="sourceLineNo">888</span>    }<a name="line.888"></a>
-<span class="sourceLineNo">889</span><a name="line.889"></a>
-<span class="sourceLineNo">890</span>    try {<a name="line.890"></a>
-<span class="sourceLineNo">891</span>      Path regionInfoFile = new 
Path(getRegionDir(), REGION_INFO_FILE);<a name="line.891"></a>
-<span class="sourceLineNo">892</span>      FileStatus status = 
fs.getFileStatus(regionInfoFile);<a name="line.892"></a>
-<span class="sourceLineNo">893</span>      if (status != null &amp;&amp; 
status.getLen() == content.length) {<a name="line.893"></a>
-<span class="sourceLineNo">894</span>        // Then assume the content good 
and move on.<a name="line.894"></a>
-<span class="sourceLineNo">895</span>        // NOTE: that the length is not 
sufficient to define the the content matches.<a name="line.895"></a>
-<span class="sourceLineNo">896</span>        return;<a name="line.896"></a>
-<span class="sourceLineNo">897</span>      }<a name="line.897"></a>
-<span class="sourceLineNo">898</span><a name="line.898"></a>
-<span class="sourceLineNo">899</span>      LOG.info("Rewriting .regioninfo 
file at: " + regionInfoFile);<a name="line.899"></a>
-<span class="sourceLineNo">900</span>      if (!fs.delete(regionInfoFile, 
false)) {<a name="line.900"></a>
-<span class="sourceLineNo">901</span>        throw new IOException("Unable to 
remove existing " + regionInfoFile);<a name="line.901"></a>
-<span class="sourceLineNo">902</span>      }<a name="line.902"></a>
-<span class="sourceLineNo">903</span>    } catch (FileNotFoundException e) {<a 
name="line.903"></a>
-<span class="sourceLineNo">904</span>      LOG.warn(REGION_INFO_FILE + " file 
not found for region: " + regionInfoForFs.getEncodedName() +<a 
name="line.904"></a>
-<span class="sourceLineNo">905</span>          " on table " + 
regionInfo.getTable());<a name="line.905"></a>
-<span class="sourceLineNo">906</span>    }<a name="line.906"></a>
-<span class="sourceLineNo">907</span><a name="line.907"></a>
-<span class="sourceLineNo">908</span>    // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.908"></a>
-<span class="sourceLineNo">909</span>    writeRegionInfoOnFilesystem(content, 
true);<a name="line.909"></a>
-<span class="sourceLineNo">910</span>  }<a name="line.910"></a>
-<span class="sourceLineNo">911</span><a name="line.911"></a>
-<span class="sourceLineNo">912</span>  /**<a name="line.912"></a>
-<span class="sourceLineNo">913</span>   * Write out an info file under the 
region directory. Useful recovering mangled regions.<a name="line.913"></a>
-<span class="sourceLineNo">914</span>   * @param useTempDir indicate whether 
or not using the region .tmp dir for a safer file creation.<a 
name="line.914"></a>
-<span class="sourceLineNo">915</span>   */<a name="line.915"></a>
-<span class="sourceLineNo">916</span>  private void 
writeRegionInfoOnFilesystem(boolean useTempDir) throws IOException {<a 
name="line.916"></a>
-<span class="sourceLineNo">917</span>    byte[] content = 
getRegionInfoFileContent(regionInfoForFs);<a name="line.917"></a>
-<span class="sourceLineNo">918</span>    writeRegionInfoOnFilesystem(content, 
useTempDir);<a name="line.918"></a>
-<span class="sourceLineNo">919</span>  }<a name="line.919"></a>
-<span class="sourceLineNo">920</span><a name="line.920"></a>
-<span class="sourceLineNo">921</span>  /**<a name="line.921"></a>
-<span class="sourceLineNo">922</span>   * Write out an info file under the 
region directory. Useful recovering mangled regions.<a name="line.922"></a>
-<span class="sourceLineNo">923</span>   * @param regionInfoContent serialized 
version of the {@link RegionInfo}<a name="line.923"></a>
-<span class="sourceLineNo">924</span>   * @param useTempDir indicate whether 
or not using the region .tmp dir for a safer file creation.<a 
name="line.924"></a>
-<span class="sourceLineNo">925</span>   */<a name="line.925"></a>
-<span class="sourceLineNo">926</span>  private void 
writeRegionInfoOnFilesystem(final byte[] regionInfoContent,<a 
name="line.926"></a>
-<span class="sourceLineNo">927</span>      final boolean useTempDir) throws 
IOException {<a name="line.927"></a>
-<span class="sourceLineNo">928</span>    Path regionInfoFile = new 
Path(getRegionDir(), REGION_INFO_FILE);<a name="line.928"></a>
-<span class="sourceLineNo">929</span>    if (useTempDir) {<a 
name="line.929"></a>
-<span class="sourceLineNo">930</span>      // Create in tmpDir and then move 
into place in case we crash after<a name="line.930"></a>
-<span class="sourceLineNo">931</span>      // create but before close. If we 
don't successfully close the file,<a name="line.931"></a>
-<span class="sourceLineNo">932</span>      // subsequent region reopens will 
fail the below because create is<a name="line.932"></a>
-<span class="sourceLineNo">933</span>      // registered in NN.<a 
name="line.933"></a>
-<span class="sourceLineNo">934</span><a name="line.934"></a>
-<span class="sourceLineNo">935</span>      // And then create the file<a 
name="line.935"></a>
-<span class="sourceLineNo">936</span>      Path tmpPath = new 
Path(getTempDir(), REGION_INFO_FILE);<a name="line.936"></a>
-<span class="sourceLineNo">937</span><a name="line.937"></a>
-<span class="sourceLineNo">938</span>      // If datanode crashes or if the RS 
goes down just before the close is called while trying to<a name="line.938"></a>
-<span class="sourceLineNo">939</span>      // close the created regioninfo 
file in the .tmp directory then on next<a name="line.939"></a>
-<span class="sourceLineNo">940</span>      // creation we will be getting 
AlreadyCreatedException.<a name="line.940"></a>
-<span class="sourceLineNo">941</span>      // Hence delete and create the file 
if exists.<a name="line.941"></a>
-<span class="sourceLineNo">942</span>      if (FSUtils.isExists(fs, tmpPath)) 
{<a name="line.942"></a>
-<span class="sourceLineNo">943</span>        FSUtils.delete(fs, tmpPath, 
true);<a name="line.943"></a>
-<span class="sourceLineNo">944</span>      }<a name="line.944"></a>
-<span class="sourceLineNo">945</span><a name="line.945"></a>
-<span class="sourceLineNo">946</span>      // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.946"></a>
-<span class="sourceLineNo">947</span>      writeRegionInfoFileContent(conf, 
fs, tmpPath, regionInfoContent);<a name="line.947"></a>
-<span class="sourceLineNo">948</span><a name="line.948"></a>
-<span class="sourceLineNo">949</span>      // Move the created file to the 
original path<a name="line.949"></a>
-<span class="sourceLineNo">950</span>      if (fs.exists(tmpPath) &amp;&amp;  
!rename(tmpPath, regionInfoFile)) {<a name="line.950"></a>
-<span class="sourceLineNo">951</span>        throw new IOException("Unable to 
rename " + tmpPath + " to " + regionInfoFile);<a name="line.951"></a>
-<span class="sourceLineNo">952</span>      }<a name="line.952"></a>
-<span class="sourceLineNo">953</span>    } else {<a name="line.953"></a>
-<span class="sourceLineNo">954</span>      // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.954"></a>
-<span class="sourceLineNo">955</span>      writeRegionInfoFileContent(conf, 
fs, regionInfoFile, regionInfoContent);<a name="line.955"></a>
-<span class="sourceLineNo">956</span>    }<a name="line.956"></a>
-<span class="sourceLineNo">957</span>  }<a name="line.957"></a>
-<span class="sourceLineNo">958</span><a name="line.958"></a>
-<span class="sourceLineNo">959</span>  /**<a name="line.959"></a>
-<span class="sourceLineNo">960</span>   * Create a new Region on 
file-system.<a name="line.960"></a>
-<span class="sourceLineNo">961</span>   * @param conf the {@link 
Configuration} to use<a name="line.961"></a>
-<span class="sourceLineNo">962</span>   * @param fs {@link FileSystem} from 
which to add the region<a name="line.962"></a>
-<span class="sourceLineNo">963</span>   * @param tableDir {@link Path} to 
where the table is being stored<a name="line.963"></a>
-<span class="sourceLineNo">964</span>   * @param regionInfo {@link RegionInfo} 
for region to be added<a name="line.964"></a>
-<span class="sourceLineNo">965</span>   * @throws IOException if the region 
creation fails due to a FileSystem exception.<a name="line.965"></a>
-<span class="sourceLineNo">966</span>   */<a name="line.966"></a>
-<span class="sourceLineNo">967</span>  public static HRegionFileSystem 
createRegionOnFileSystem(final Configuration conf,<a name="line.967"></a>
-<span class="sourceLineNo">968</span>      final FileSystem fs, final Path 
tableDir, final RegionInfo regionInfo) throws IOException {<a 
name="line.968"></a>
-<span class="sourceLineNo">969</span>    HRegionFileSystem regionFs = new 
HRegionFileSystem(conf, fs, tableDir, regionInfo);<a name="line.969"></a>
-<span class="sourceLineNo">970</span>    Path regionDir = 
regionFs.getRegionDir();<a name="line.970"></a>
-<span class="sourceLineNo">971</span><a name="line.971"></a>
-<span class="sourceLineNo">972</span>    if (fs.exists(regionDir)) {<a 
name="line.972"></a>
-<span class="sourceLineNo">973</span>      LOG.warn("Trying to create a region 
that already exists on disk: " + regionDir);<a name="line.973"></a>
-<span class="sourceLineNo">974</span>      throw new IOException("The 
specified region already exists on disk: " + regionDir);<a name="line.974"></a>
-<span class="sourceLineNo">975</span>    }<a name="line.975"></a>
-<span class="sourceLineNo">976</span><a name="line.976"></a>
-<span class="sourceLineNo">977</span>    // Create the region directory<a 
name="line.977"></a>
-<span class="sourceLineNo">978</span>    if (!createDirOnFileSystem(fs, conf, 
regionDir)) {<a name="line.978"></a>
-<span class="sourceLineNo">979</span>      LOG.warn("Unable to create the 
region directory: " + regionDir);<a name="line.979"></a>
-<span class="sourceLineNo">980</span>      throw new IOException("Unable to 
create region directory: " + regionDir);<a name="line.980"></a>
-<span class="sourceLineNo">981</span>    }<a name="line.981"></a>
-<span class="sourceLineNo">982</span><a name="line.982"></a>
-<span class="sourceLineNo">983</span>    // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.983"></a>
-<span class="sourceLineNo">984</span>    // Only primary replicas should write 
region info<a name="line.984"></a>
-<span class="sourceLineNo">985</span>    if (regionInfo.getReplicaId() == 
RegionInfo.DEFAULT_REPLICA_ID) {<a name="line.985"></a>
-<span class="sourceLineNo">986</span>      
regionFs.writeRegionInfoOnFilesystem(false);<a name="line.986"></a>
-<span class="sourceLineNo">987</span>    } else {<a name="line.987"></a>
-<span class="sourceLineNo">988</span>      if (LOG.isDebugEnabled())<a 
name="line.988"></a>
-<span class="sourceLineNo">989</span>        LOG.debug("Skipping creation of 
.regioninfo file for " + regionInfo);<a name="line.989"></a>
-<span class="sourceLineNo">990</span>    }<a name="line.990"></a>
-<span class="sourceLineNo">991</span>    return regionFs;<a 
name="line.991"></a>
-<span class="sourceLineNo">992</span>  }<a name="line.992"></a>
-<span class="sourceLineNo">993</span><a name="line.993"></a>
-<span class="sourceLineNo">994</span>  /**<a name="line.994"></a>
-<span class="sourceLineNo">995</span>   * Open Region from file-system.<a 
name="line.995"></a>
-<span class="sourceLineNo">996</span>   * @param conf the {@link 
Configuration} to use<a name="line.996"></a>
-<span class="sourceLineNo">997</span>   * @param fs {@link FileSystem} from 
which to add the region<a name="line.997"></a>
-<span class="sourceLineNo">998</span>   * @param tableDir {@link Path} to 
where the table is being stored<a name="line.998"></a>
-<span class="sourceLineNo">999</span>   * @param regionInfo {@link RegionInfo} 
for region to be added<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>   * @param readOnly True if you don't 
want to edit the region data<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>   * @throws IOException if the region 
creation fails due to a FileSystem exception.<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>   */<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>  public static HRegionFileSystem 
openRegionFromFileSystem(final Configuration conf,<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>      final FileSystem fs, final Path 
tableDir, final RegionInfo regionInfo, boolean readOnly)<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>      throws IOException {<a 
name="line.1005"></a>
-<span class="sourceLineNo">1006</span>    HRegionFileSystem regionFs = new 
HRegionFileSystem(conf, fs, tableDir, regionInfo);<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>    Path regionDir = 
regionFs.getRegionDir();<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span><a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>    if (!fs.exists(regionDir)) {<a 
name="line.1009"></a>
-<span class="sourceLineNo">1010</span>      LOG.warn("Trying to open a region 
that do not exists on disk: " + regionDir);<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>      throw new IOException("The 
specified region do not exists on disk: " + regionDir);<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>    }<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span><a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>    if (!readOnly) {<a 
name="line.1014"></a>
-<span class="sourceLineNo">1015</span>      // Cleanup temporary directories<a 
name="line.1015"></a>
-<span class="sourceLineNo">1016</span>      regionFs.cleanupTempDir();<a 
name="line.1016"></a>
-<span class="sourceLineNo">1017</span>      regionFs.cleanupSplitsDir();<a 
name="line.1017"></a>
-<span class="sourceLineNo">1018</span>      regionFs.cleanupMergesDir();<a 
name="line.1018"></a>
-<span class="sourceLineNo">1019</span><a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>      // If it doesn't exists, Write HRI 
to a file, in case we need to recover hbase:meta<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>      // Only create HRI if we are the 
default replica<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>      if (regionInfo.getReplicaId() == 
RegionInfo.DEFAULT_REPLICA_ID) {<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>        
regionFs.checkRegionInfoOnFilesystem();<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>      } else {<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>        if (LOG.isDebugEnabled()) {<a 
name="line.1025"></a>
-<span class="sourceLineNo">1026</span>          LOG.debug("Skipping creation 
of .regioninfo file for " + regionInfo);<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>        }<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>      }<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>    }<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span><a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>    return regionFs;<a 
name="line.1031"></a>
-<span class="sourceLineNo">1032</span>  }<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span><a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>  /**<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>   * Remove the region from the table 
directory, archiving the region's hfiles.<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>   * @param conf the {@link 
Configuration} to use<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>   * @param fs {@link FileSystem} from 
which to remove the region<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>   * @param tableDir {@link Path} to 
where the table is being stored<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>   * @param regionInfo {@link 
RegionInfo} for region to be deleted<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>   * @throws IOException if the request 
cannot be completed<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>   */<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>  public static void 
deleteRegionFromFileSystem(final Configuration conf,<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>      final FileSystem fs, final Path 
tableDir, final RegionInfo regionInfo) throws IOException {<a 
name="line.1043"></a>
-<span class="sourceLineNo">1044</span>    HRegionFileSystem regionFs = new 
HRegionFileSystem(conf, fs, tableDir, regionInfo);<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>    Path regionDir = 
regionFs.getRegionDir();<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span><a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>    if (!fs.exists(regionDir)) {<a 
name="line.1047"></a>
-<span class="sourceLineNo">1048</span>      LOG.warn("Trying to delete a 
region that do not exists on disk: " + regionDir);<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>      return;<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>    }<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span><a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>    if (LOG.isDebugEnabled()) {<a 
name="line.1052"></a>
-<span class="sourceLineNo">1053</span>      LOG.debug("DELETING region " + 
regionDir);<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>    }<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span><a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>    // Archive region<a 
name="line.1056"></a>
-<span class="sourceLineNo">1057</span>    Path rootDir = 
FSUtils.getRootDir(conf);<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>    HFileArchiver.archiveRegion(fs, 
rootDir, tableDir, regionDir);<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span><a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>    // Delete empty region dir<a 
name="line.1060"></a>
-<span class="sourceLineNo">1061</span>    if (!fs.delete(regionDir, true)) {<a 
name="line.1061"></a>
-<span class="sourceLineNo">1062</span>      LOG.warn("Failed delete of " + 
regionDir);<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>    }<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>  }<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span><a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>  /**<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>   * Creates a directory. Assumes the 
user has already checked for this directory existence.<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>   * @param dir<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>   * @return the result of fs.mkdirs(). 
In case underlying fs throws an IOException, it checks<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>   *         whether the directory 
exists or not, and returns true if it exists.<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>   * @throws IOException<a 
name="line.1071"></a>
-<span class="sourceLineNo">1072</span>   */<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>  boolean createDir(Path dir) throws 
IOException {<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>    int i = 0;<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>    IOException lastIOE = null;<a 
name="line.1075"></a>
-<span class="sourceLineNo">1076</span>    do {<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>      try {<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>        return mkdirs(fs, conf, dir);<a 
name="line.1078"></a>
-<span class="sourceLineNo">1079</span>      } catch (IOException ioe) {<a 
name="line.1079"></a>
-<span class="sourceLineNo">1080</span>        lastIOE = ioe;<a 
name="line.1080"></a>
-<span class="sourceLineNo">1081</span>        if (fs.exists(dir)) return true; 
// directory is present<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>        try {<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>          sleepBeforeRetry("Create 
Directory", i+1);<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>        } catch (InterruptedException e) 
{<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>          throw 
(InterruptedIOException)new InterruptedIOException().initCause(e);<a 
name="line.1085"></a>
-<span class="sourceLineNo">1086</span>        }<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span>      }<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>    } while (++i &lt;= 
hdfsClientRetriesNumber);<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>    throw new IOException("Exception in 
createDir", lastIOE);<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>  }<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span><a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>  /**<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>   * Renames a directory. Assumes the 
user has already checked for this directory existence.<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>   * @param srcpath<a 
name="line.1094"></a>
-<span class="sourceLineNo">1095</span>   * @param dstPath<a 
name="line.1095"></a>
-<span class="sourceLineNo">1096</span>   * @return true if rename is 
successful.<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span>   * @throws IOException<a 
name="line.1097"></a>
-<span class="sourceLineNo">1098</span>   */<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>  boolean rename(Path srcpath, Path 
dstPath) throws IOException {<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>    IOException lastIOE = null;<a 
name="line.1100"></a>
-<span class="sourceLineNo">1101</span>    int i = 0;<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>    do {<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>      try {<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>        return fs.rename(srcpath, 
dstPath);<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>      } catch (IOException ioe) {<a 
name="line.1105"></a>
-<span class="sourceLineNo">1106</span>        lastIOE = ioe;<a 
name="line.1106"></a>
-<span class="sourceLineNo">1107</span>        if (!fs.exists(srcpath) 
&amp;&amp; fs.exists(dstPath)) return true; // successful move<a 
name="line.1107"></a>
-<span class="sourceLineNo">1108</span>        // dir is not there, retry after 
some time.<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>        try {<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>          sleepBeforeRetry("Rename 
Directory", i+1);<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>        } catch (InterruptedException e) 
{<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>          throw 
(InterruptedIOException)new InterruptedIOException().initCause(e);<a 
name="line.1112"></a>
-<span class="sourceLineNo">1113</span>        }<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>      }<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>    } while (++i &lt;= 
hdfsClientRetriesNumber);<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span><a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>    throw new IOException("Exception in 
rename", lastIOE);<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>  }<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span><a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>  /**<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>   * Deletes a directory. Assumes the 
user has already checked for this directory existence.<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>   * @param dir<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>   * @return true if the directory is 
deleted.<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>   * @throws IOException<a 
name="line.1124"></a>
-<span class="sourceLineNo">1125</span>   */<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>  boolean deleteDir(Path dir) throws 
IOException {<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>    IOException lastIOE = null;<a 
name="line.1127"></a>
-<span class="sourceLineNo">1128</span>    int i = 0;<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>    do {<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>      try {<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>        return fs.delete(dir, true);<a 
name="line.1131"></a>
-<span class="sourceLineNo">1132</span>      } catch (IOException ioe) {<a 
name="line.1132"></a>
-<span class="sourceLineNo">1133</span>        lastIOE = ioe;<a 
name="line.1133"></a>
-<span class="sourceLineNo">1134</span>        if (!fs.exists(dir)) return 
true;<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>        // dir is there, retry deleting 
after some time.<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>        try {<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>          sleepBeforeRetry("Delete 
Directory", i+1);<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>        } catch (InterruptedException e) 
{<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>          throw 
(InterruptedIOException)new InterruptedIOException().initCause(e);<a 
name="line.1139"></a>
-<span class="sourceLineNo">1140</span>        }<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>      }<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>    } while (++i &lt;= 
hdfsClientRetriesNumber);<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span><a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>    throw new IOException("Exception in 
DeleteDir", lastIOE);<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>  }<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span><a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>  /**<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>   * sleeping logic; handles the 
interrupt exception.<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span>   */<a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>  private void sleepBeforeRetry(String 
msg, int sleepMultiplier) throws InterruptedException {<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>    sleepBeforeRetry(msg, 
sleepMultiplier, baseSleepBeforeRetries, hdfsClientRetriesNumber);<a 
name="line.1151"></a>
-<span class="sourceLineNo">1152</span>  }<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span><a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>  /**<a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>   * Creates a directory for a 
filesystem and configuration object. Assumes the user has already<a 
name="line.1155"></a>
-<span class="sourceLineNo">1156</span>   * checked for this directory 
existence.<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>   * @param fs<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>   * @param conf<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>   * @param dir<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>   * @return the result of fs.mkdirs(). 
In case underlying fs throws an IOException, it checks<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>   *         whether the directory 
exists or not, and returns true if it exists.<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>   * @throws IOException<a 
name="line.1162"></a>
-<span class="sourceLineNo">1163</span>   */<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>  private static boolean 
createDirOnFileSystem(FileSystem fs, Configuration conf, Path dir)<a 
name="line.1164"></a>
-<span class="sourceLineNo">1165</span>      throws IOException {<a 
name="line.1165"></a>
-<span class="sourceLineNo">1166</span>    int i = 0;<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>    IOException lastIOE = null;<a 
name="line.1167"></a>
-<span class="sourceLineNo">1168</span>    int hdfsClientRetriesNumber = 
conf.getInt("hdfs.client.retries.number",<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>      
DEFAULT_HDFS_CLIENT_RETRIES_NUMBER);<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>    int baseSleepBeforeRetries = 
conf.getInt("hdfs.client.sleep.before.retries",<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>      
DEFAULT_BASE_SLEEP_BEFORE_RETRIES);<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>    do {<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>      try {<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>        return fs.mkdirs(dir);<a 
name="line.1174"></a>
-<span class="sourceLineNo">1175</span>      } catch (IOException ioe) {<a 
name="line.1175"></a>
-<span class="sourceLineNo">1176</span>        lastIOE = ioe;<a 
name="line.1176"></a>
-<span class="sourceLineNo">1177</span>        if (fs.exists(dir)) return true; 
// directory is present<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>        try {<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>          sleepBeforeRetry("Create 
Directory", i+1, baseSleepBeforeRetries, hdfsClientRetriesNumber);<a 
name="line.1179"></a>
-<span class="sourceLineNo">1180</span>        } catch (InterruptedException e) 
{<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>          throw 
(InterruptedIOException)new InterruptedIOException().initCause(e);<a 
name="line.1181"></a>
-<span class="sourceLineNo">1182</span>        }<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>      }<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span>    } while (++i &lt;= 
hdfsClientRetriesNumber);<a name="line.1184"></a>
-<span class="sourceLineNo">1185</span><a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>    throw new IOException("Exception in 
createDir", lastIOE);<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>  }<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span><a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>  /**<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>   * sleeping logic for static methods; 
handles the interrupt exception. Keeping a static version<a 
name="line.1190"></a>
-<span class="sourceLineNo">1191</span>   * for this to avoid re-looking for 
the integer values.<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span>   */<a name="line.1192"></a>
-<span class="sourceLineNo">1193</span>  private static void 
sleepBeforeRetry(String msg, int sleepMultiplier, int baseSleepBeforeRetries,<a 
name="line.1193"></a>
-<span class="sourceLineNo">1194</span>      int hdfsClientRetriesNumber) 
throws InterruptedException {<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>    if (sleepMultiplier &gt; 
hdfsClientRetriesNumber) {<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>      if (LOG.isDebugEnabled()) {<a 
name="line.1196"></a>
-<span class="sourceLineNo">1197</span>        LOG.debug(msg + ", retries 
exhausted");<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>      }<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>      return;<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>    }<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>    if (LOG.isDebugEnabled()) {<a 
name="line.1201"></a>
-<span class="sourceLineNo">1202</span>      LOG.debug(msg + ", sleeping " + 
baseSleepBeforeRetries + " times " + sleepMultiplier);<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>    }<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>    
Thread.sleep((long)baseSleepBeforeRetries * sleepMultiplier);<a 
name="line.1204"></a>
-<span class="sourceLineNo">1205</span>  }<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>}<a name="line.1206"></a>
+<span class="sourceLineNo">817</span>  //  Create/Open/Delete Helpers<a 
name="line.817"></a>
+<span class="sourceLineNo">818</span>  // 
===========================================================================<a 
name="line.818"></a>
+<span class="sourceLineNo">819</span>  /**<a name="line.819"></a>
+<span class="sourceLineNo">820</span>   * Log the current state of the 
region<a name="line.820"></a>
+<span class="sourceLineNo">821</span>   * @param LOG log to output 
information<a name="line.821"></a>
+<span class="sourceLineNo">822</span>   * @throws IOException if an unexpected 
exception occurs<a name="line.822"></a>
+<span class="sourceLineNo">823</span>   */<a name="line.823"></a>
+<span class="sourceLineNo">824</span>  void logFileSystemState(final Logger 
LOG) throws IOException {<a name="line.824"></a>
+<span class="sourceLineNo">825</span>    FSUtils.logFileSystemState(fs, 
this.getRegionDir(), LOG);<a name="line.825"></a>
+<span class="sourceLineNo">826</span>  }<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>   * @param hri<a name="line.829"></a>
+<span class="sourceLineNo">830</span>   * @return Content of the file we write 
out to the filesystem under a region<a name="line.830"></a>
+<span class="sourceLineNo">831</span>   * @throws IOException<a 
name="line.831"></a>
+<span class="sourceLineNo">832</span>   */<a name="line.832"></a>
+<span class="sourceLineNo">833</span>  private static byte[] 
getRegionInfoFileContent(final RegionInfo hri) throws IOException {<a 
name="line.833"></a>
+<span class="sourceLineNo">834</span>    return 
RegionInfo.toDelimitedByteArray(hri);<a name="line.834"></a>
+<span class="sourceLineNo">835</span>  }<a name="line.835"></a>
+<span class="sourceLineNo">836</span><a name="line.836"></a>
+<span class="sourceLineNo">837</span>  /**<a name="line.837"></a>
+<span class="sourceLineNo">838</span>   * Create a {@link RegionInfo} from the 
serialized version on-disk.<a name="line.838"></a>
+<span class="sourceLineNo">839</span>   * @param fs {@link FileSystem} that 
contains the Region Info file<a name="line.839"></a>
+<span class="sourceLineNo">840</span>   * @param regionDir {@link Path} to the 
Region Directory that contains the Info file<a name="line.840"></a>
+<span class="sourceLineNo">841</span>   * @return An {@link RegionInfo} 
instance gotten from the Region Info file.<a name="line.841"></a>
+<span class="sourceLineNo">842</span>   * @throws IOException if an error 
occurred during file open/read operation.<a name="line.842"></a>
+<span class="sourceLineNo">843</span>   */<a name="line.843"></a>
+<span class="sourceLineNo">844</span>  public static RegionInfo 
loadRegionInfoFileContent(final FileSystem fs, final Path regionDir)<a 
name="line.844"></a>
+<span class="sourceLineNo">845</span>      throws IOException {<a 
name="line.845"></a>
+<span class="sourceLineNo">846</span>    FSDataInputStream in = fs.open(new 
Path(regionDir, REGION_INFO_FILE));<a name="line.846"></a>
+<span class="sourceLineNo">847</span>    try {<a name="line.847"></a>
+<span class="sourceLineNo">848</span>      return RegionInfo.parseFrom(in);<a 
name="line.848"></a>
+<span class="sourceLineNo">849</span>    } finally {<a name="line.849"></a>
+<span class="sourceLineNo">850</span>      in.close();<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><a name="line.853"></a>
+<span class="sourceLineNo">854</span>  /**<a name="line.854"></a>
+<span class="sourceLineNo">855</span>   * Write the .regioninfo file 
on-disk.<a name="line.855"></a>
+<span class="sourceLineNo">856</span>   */<a name="line.856"></a>
+<span class="sourceLineNo">857</span>  private static void 
writeRegionInfoFileContent(final Configuration conf, final FileSystem fs,<a 
name="line.857"></a>
+<span class="sourceLineNo">858</span>      final Path regionInfoFile, final 
byte[] content) throws IOException {<a name="line.858"></a>
+<span class="sourceLineNo">859</span>    // First check to get the 
permissions<a name="line.859"></a>
+<span class="sourceLineNo">860</span>    FsPermission perms = 
FSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY);<a 
name="line.860"></a>
+<span class="sourceLineNo">861</span>    // Write the RegionInfo file 
content<a name="line.861"></a>
+<span class="sourceLineNo">862</span>    FSDataOutputStream out = 
FSUtils.create(conf, fs, regionInfoFile, perms, null);<a name="line.862"></a>
+<span class="sourceLineNo">863</span>    try {<a name="line.863"></a>
+<span class="sourceLineNo">864</span>      out.write(content);<a 
name="line.864"></a>
+<span class="sourceLineNo">865</span>    } finally {<a name="line.865"></a>
+<span class="sourceLineNo">866</span>      out.close();<a name="line.866"></a>
+<span class="sourceLineNo">867</span>    }<a name="line.867"></a>
+<span class="sourceLineNo">868</span>  }<a name="line.868"></a>
+<span class="sourceLineNo">869</span><a name="line.869"></a>
+<span class="sourceLineNo">870</span>  /**<a name="line.870"></a>
+<span class="sourceLineNo">871</span>   * Write out an info file under the 
stored region directory. Useful recovering mangled regions.<a 
name="line.871"></a>
+<span class="sourceLineNo">872</span>   * If the regionInfo already exists 
on-disk, then we fast exit.<a name="line.872"></a>
+<span class="sourceLineNo">873</span>   */<a name="line.873"></a>
+<span class="sourceLineNo">874</span>  void checkRegionInfoOnFilesystem() 
throws IOException {<a name="line.874"></a>
+<span class="sourceLineNo">875</span>    // Compose the content of the file so 
we can compare to length in filesystem. If not same,<a name="line.875"></a>
+<span class="sourceLineNo">876</span>    // rewrite it (it may have been 
written in the old format using Writables instead of pb). The<a 
name="line.876"></a>
+<span class="sourceLineNo">877</span>    // pb version is much shorter -- we 
write now w/o the toString version -- so checking length<a name="line.877"></a>
+<span class="sourceLineNo">878</span>    // only should be sufficient. I don't 
want to read the file every time to check if it pb<a name="line.878"></a>
+<span class="sourceLineNo">879</span>    // serialized.<a name="line.879"></a>
+<span class="sourceLineNo">880</span>    byte[] content = 
getRegionInfoFileContent(regionInfoForFs);<a name="line.880"></a>
+<span class="sourceLineNo">881</span><a name="line.881"></a>
+<span class="sourceLineNo">882</span>    // Verify if the region directory 
exists before opening a region. We need to do this since if<a 
name="line.882"></a>
+<span class="sourceLineNo">883</span>    // the region directory doesn't exist 
we will re-create the region directory and a new HRI<a name="line.883"></a>
+<span class="sourceLineNo">884</span>    // when HRegion.openHRegion() is 
called.<a name="line.884"></a>
+<span class="sourceLineNo">885</span>    try {<a name="line.885"></a>
+<span class="sourceLineNo">886</span>      FileStatus status = 
fs.getFileStatus(getRegionDir());<a name="line.886"></a>
+<span class="sourceLineNo">887</span>    } catch (FileNotFoundException e) {<a 
name="line.887"></a>
+<span class="sourceLineNo">888</span>      LOG.warn(getRegionDir() + " doesn't 
exist for region: " + regionInfoForFs.getEncodedName() +<a name="line.888"></a>
+<span class="sourceLineNo">889</span>          " on table " + 
regionInfo.getTable());<a name="line.889"></a>
+<span class="sourceLineNo">890</span>    }<a name="line.890"></a>
+<span class="sourceLineNo">891</span><a name="line.891"></a>
+<span class="sourceLineNo">892</span>    try {<a name="line.892"></a>
+<span class="sourceLineNo">893</span>      Path regionInfoFile = new 
Path(getRegionDir(), REGION_INFO_FILE);<a name="line.893"></a>
+<span class="sourceLineNo">894</span>      FileStatus status = 
fs.getFileStatus(regionInfoFile);<a name="line.894"></a>
+<span class="sourceLineNo">895</span>      if (status != null &amp;&amp; 
status.getLen() == content.length) {<a name="line.895"></a>
+<span class="sourceLineNo">896</span>        // Then assume the content good 
and move on.<a name="line.896"></a>
+<span class="sourceLineNo">897</span>        // NOTE: that the length is not 
sufficient to define the the content matches.<a name="line.897"></a>
+<span class="sourceLineNo">898</span>        return;<a name="line.898"></a>
+<span class="sourceLineNo">899</span>      }<a name="line.899"></a>
+<span class="sourceLineNo">900</span><a name="line.900"></a>
+<span class="sourceLineNo">901</span>      LOG.info("Rewriting .regioninfo 
file at: " + regionInfoFile);<a name="line.901"></a>
+<span class="sourceLineNo">902</span>      if (!fs.delete(regionInfoFile, 
false)) {<a name="line.902"></a>
+<span class="sourceLineNo">903</span>        throw new IOException("Unable to 
remove existing " + regionInfoFile);<a name="line.903"></a>
+<span class="sourceLineNo">904</span>      }<a name="line.904"></a>
+<span class="sourceLineNo">905</span>    } catch (FileNotFoundException e) {<a 
name="line.905"></a>
+<span class="sourceLineNo">906</span>      LOG.warn(REGION_INFO_FILE + " file 
not found for region: " + regionInfoForFs.getEncodedName() +<a 
name="line.906"></a>
+<span class="sourceLineNo">907</span>          " on table " + 
regionInfo.getTable());<a name="line.907"></a>
+<span class="sourceLineNo">908</span>    }<a name="line.908"></a>
+<span class="sourceLineNo">909</span><a name="line.909"></a>
+<span class="sourceLineNo">910</span>    // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.910"></a>
+<span class="sourceLineNo">911</span>    writeRegionInfoOnFilesystem(content, 
true);<a name="line.911"></a>
+<span class="sourceLineNo">912</span>  }<a name="line.912"></a>
+<span class="sourceLineNo">913</span><a name="line.913"></a>
+<span class="sourceLineNo">914</span>  /**<a name="line.914"></a>
+<span class="sourceLineNo">915</span>   * Write out an info file under the 
region directory. Useful recovering mangled regions.<a name="line.915"></a>
+<span class="sourceLineNo">916</span>   * @param useTempDir indicate whether 
or not using the region .tmp dir for a safer file creation.<a 
name="line.916"></a>
+<span class="sourceLineNo">917</span>   */<a name="line.917"></a>
+<span class="sourceLineNo">918</span>  private void 
writeRegionInfoOnFilesystem(boolean useTempDir) throws IOException {<a 
name="line.918"></a>
+<span class="sourceLineNo">919</span>    byte[] content = 
getRegionInfoFileContent(regionInfoForFs);<a name="line.919"></a>
+<span class="sourceLineNo">920</span>    writeRegionInfoOnFilesystem(content, 
useTempDir);<a name="line.920"></a>
+<span class="sourceLineNo">921</span>  }<a name="line.921"></a>
+<span class="sourceLineNo">922</span><a name="line.922"></a>
+<span class="sourceLineNo">923</span>  /**<a name="line.923"></a>
+<span class="sourceLineNo">924</span>   * Write out an info file under the 
region directory. Useful recovering mangled regions.<a name="line.924"></a>
+<span class="sourceLineNo">925</span>   * @param regionInfoContent serialized 
version of the {@link RegionInfo}<a name="line.925"></a>
+<span class="sourceLineNo">926</span>   * @param useTempDir indicate whether 
or not using the region .tmp dir for a safer file creation.<a 
name="line.926"></a>
+<span class="sourceLineNo">927</span>   */<a name="line.927"></a>
+<span class="sourceLineNo">928</span>  private void 
writeRegionInfoOnFilesystem(final byte[] regionInfoContent,<a 
name="line.928"></a>
+<span class="sourceLineNo">929</span>      final boolean useTempDir) throws 
IOException {<a name="line.929"></a>
+<span class="sourceLineNo">930</span>    Path regionInfoFile = new 
Path(getRegionDir(), REGION_INFO_FILE);<a name="line.930"></a>
+<span class="sourceLineNo">931</span>    if (useTempDir) {<a 
name="line.931"></a>
+<span class="sourceLineNo">932</span>      // Create in tmpDir and then move 
into place in case we crash after<a name="line.932"></a>
+<span class="sourceLineNo">933</span>      // create but before close. If we 
don't successfully close the file,<a name="line.933"></a>
+<span class="sourceLineNo">934</span>      // subsequent region reopens will 
fail the below because create is<a name="line.934"></a>
+<span class="sourceLineNo">935</span>      // registered in NN.<a 
name="line.935"></a>
+<span class="sourceLineNo">936</span><a name="line.936"></a>
+<span class="sourceLineNo">937</span>      // And then create the file<a 
name="line.937"></a>
+<span class="sourceLineNo">938</span>      Path tmpPath = new 
Path(getTempDir(), REGION_INFO_FILE);<a name="line.938"></a>
+<span class="sourceLineNo">939</span><a name="line.939"></a>
+<span class="sourceLineNo">940</span>      // If datanode crashes or if the RS 
goes down just before the close is called while trying to<a name="line.940"></a>
+<span class="sourceLineNo">941</span>      // close the created regioninfo 
file in the .tmp directory then on next<a name="line.941"></a>
+<span class="sourceLineNo">942</span>      // creation we will be getting 
AlreadyCreatedException.<a name="line.942"></a>
+<span class="sourceLineNo">943</span>      // Hence delete and create the file 
if exists.<a name="line.943"></a>
+<span class="sourceLineNo">944</span>      if (FSUtils.isExists(fs, tmpPath)) 
{<a name="line.944"></a>
+<span class="sourceLineNo">945</span>        FSUtils.delete(fs, tmpPath, 
true);<a name="line.945"></a>
+<span class="sourceLineNo">946</span>      }<a name="line.946"></a>
+<span class="sourceLineNo">947</span><a name="line.947"></a>
+<span class="sourceLineNo">948</span>      // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.948"></a>
+<span class="sourceLineNo">949</span>      writeRegionInfoFileContent(conf, 
fs, tmpPath, regionInfoContent);<a name="line.949"></a>
+<span class="sourceLineNo">950</span><a name="line.950"></a>
+<span class="sourceLineNo">951</span>      // Move the created file to the 
original path<a name="line.951"></a>
+<span class="sourceLineNo">952</span>      if (fs.exists(tmpPath) &amp;&amp;  
!rename(tmpPath, regionInfoFile)) {<a name="line.952"></a>
+<span class="sourceLineNo">953</span>        throw new IOException("Unable to 
rename " + tmpPath + " to " + regionInfoFile);<a name="line.953"></a>
+<span class="sourceLineNo">954</span>      }<a name="line.954"></a>
+<span class="sourceLineNo">955</span>    } else {<a name="line.955"></a>
+<span class="sourceLineNo">956</span>      // Write HRI to a file in case we 
need to recover hbase:meta<a name="line.956"></a>
+<span class="sourceLineNo">957</span>      writeRegionInfoFileContent(conf, 
fs, regionInfoFile, regionInfoContent);<a name="line.957"></a>
+<span class="sourceLineNo">958</span>    }<a name="line.958"></a>
+<span class="sourceLineNo">959</span>  }<a name="line.959"></a>
+<span class="sourceLineNo">960</span><a name="line.960"></a>
+<span class="sourceLineNo">961</span>  /**<a name="line.961"></a>
+<span class="sourceLineNo">962</span>   * Create a new Region on 
file-system.<a name="line.962"></a>
+<span class="sourceLineNo">963</span>   * @param conf the {@link 
Configuration} to use<a name="line.963"></a>
+<span class="sourceLineNo">964</span>   * @param fs {@link FileSystem} from 
which to add the region<a name="line.964"></a>
+<span class="sourceLineNo">965</span>   * @param tableDir {@link Path} to 
where the table is being stored<a name="line.965"></a>
+<span class="sourceLineNo">966</span>   * @param regionInfo {@link RegionInfo} 
for region to be added<a name="line.966"></a>
+<span class="sourceLineNo">967</span>   * @th

<TRUNCATED>

Reply via email to