@@ -575,49 +575,9 @@ Pair<Path, Path> bulkLoadStoreFile(final String familyName, Path srcPath, long s
575575 // ===========================================================================
576576 // Splits Helpers
577577 // ===========================================================================
578- /** @return {@link Path} to the temp directory used during split operations */
579- Path getSplitsDir () {
580- return new Path (getRegionDir (), REGION_SPLITS_DIR );
581- }
582578
583579 public Path getSplitsDir (final RegionInfo hri ) {
584- return new Path (getSplitsDir (), hri .getEncodedName ());
585- }
586-
587- /**
588- * Clean up any split detritus that may have been left around from previous split attempts.
589- */
590- void cleanupSplitsDir () throws IOException {
591- deleteDir (getSplitsDir ());
592- }
593-
594- /**
595- * Clean up any split detritus that may have been left around from previous
596- * split attempts.
597- * Call this method on initial region deploy.
598- * @throws IOException
599- */
600- void cleanupAnySplitDetritus () throws IOException {
601- Path splitdir = this .getSplitsDir ();
602- if (!fs .exists (splitdir )) return ;
603- // Look at the splitdir. It could have the encoded names of the daughter
604- // regions we tried to make. See if the daughter regions actually got made
605- // out under the tabledir. If here under splitdir still, then the split did
606- // not complete. Try and do cleanup. This code WILL NOT catch the case
607- // where we successfully created daughter a but regionserver crashed during
608- // the creation of region b. In this case, there'll be an orphan daughter
609- // dir in the filesystem. TOOD: Fix.
610- FileStatus [] daughters = CommonFSUtils .listStatus (fs , splitdir , new FSUtils .DirFilter (fs ));
611- if (daughters != null ) {
612- for (FileStatus daughter : daughters ) {
613- Path daughterDir = new Path (getTableDir (), daughter .getPath ().getName ());
614- if (fs .exists (daughterDir ) && !deleteDir (daughterDir )) {
615- throw new IOException ("Failed delete of " + daughterDir );
616- }
617- }
618- }
619- cleanupSplitsDir ();
620- LOG .info ("Cleaned up old failed split transaction detritus: " + splitdir );
580+ return new Path (getTableDir (), hri .getEncodedName ());
621581 }
622582
623583 /**
@@ -641,47 +601,38 @@ void cleanupDaughterRegion(final RegionInfo regionInfo) throws IOException {
641601 */
642602 public Path commitDaughterRegion (final RegionInfo regionInfo )
643603 throws IOException {
644- Path regionDir = new Path (this .tableDir , regionInfo .getEncodedName ());
645- Path daughterTmpDir = this .getSplitsDir (regionInfo );
646-
647- if (fs .exists (daughterTmpDir )) {
648-
604+ Path regionDir = this .getSplitsDir (regionInfo );
605+ if (fs .exists (regionDir )) {
649606 // Write HRI to a file in case we need to recover hbase:meta
650- Path regionInfoFile = new Path (daughterTmpDir , REGION_INFO_FILE );
607+ Path regionInfoFile = new Path (regionDir , REGION_INFO_FILE );
651608 byte [] regionInfoContent = getRegionInfoFileContent (regionInfo );
652609 writeRegionInfoFileContent (conf , fs , regionInfoFile , regionInfoContent );
653-
654- // Move the daughter temp dir to the table dir
655- if (!rename (daughterTmpDir , regionDir )) {
656- throw new IOException ("Unable to rename " + daughterTmpDir + " to " + regionDir );
657- }
658610 }
659611
660612 return regionDir ;
661613 }
662614
663615 /**
664- * Create the region splits directory.
616+ * Creates region split daughter directories under the table dir. If the daughter regions already
617+ * exist, for example, in the case of a recovery from a previous failed split procedure, this
618+ * method deletes the given region dir recursively, then recreates it again.
665619 */
666620 public void createSplitsDir (RegionInfo daughterA , RegionInfo daughterB ) throws IOException {
667- Path splitdir = getSplitsDir ();
668- if (fs .exists (splitdir )) {
669- LOG .info ("The " + splitdir + " directory exists. Hence deleting it to recreate it" );
670- if (!deleteDir (splitdir )) {
671- throw new IOException ("Failed deletion of " + splitdir + " before creating them again." );
672- }
621+ Path daughterADir = getSplitsDir (daughterA );
622+ if (fs .exists (daughterADir ) && !deleteDir (daughterADir )) {
623+ throw new IOException ("Failed deletion of " + daughterADir + " before creating them again." );
624+
673625 }
674- // splitDir doesn't exists now. No need to do an exists() call for it.
675- if (!createDir (splitdir )) {
676- throw new IOException ("Failed create of " + splitdir );
626+ if (!createDir (daughterADir )) {
627+ throw new IOException ("Failed create of " + daughterADir );
677628 }
678- Path daughterATmpDir = getSplitsDir (daughterA );
679- if (!createDir (daughterATmpDir )) {
680- throw new IOException ("Failed create of " + daughterATmpDir );
629+ Path daughterBDir = getSplitsDir (daughterB );
630+ if (fs .exists (daughterBDir ) && !deleteDir (daughterBDir )) {
631+ throw new IOException ("Failed deletion of " + daughterBDir + " before creating them again." );
632+
681633 }
682- Path daughterBTmpDir = getSplitsDir (daughterB );
683- if (!createDir (daughterBTmpDir )) {
684- throw new IOException ("Failed create of " + daughterBTmpDir );
634+ if (!createDir (daughterBDir )) {
635+ throw new IOException ("Failed create of " + daughterBDir );
685636 }
686637 }
687638
@@ -703,6 +654,18 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte
703654 boolean top , RegionSplitPolicy splitPolicy ) throws IOException {
704655 boolean createLinkFile = false ;
705656 Path splitDir = new Path (getSplitsDir (hri ), familyName );
657+ // Add the referred-to regions name as a dot separated suffix.
658+ // See REF_NAME_REGEX regex above. The referred-to regions name is
659+ // up in the path of the passed in <code>f</code> -- parentdir is family,
660+ // then the directory above is the region name.
661+ String parentRegionName = regionInfoForFs .getEncodedName ();
662+ // Write reference with same file id only with the other region name as
663+ // suffix and into the new region location (under same family).
664+ Path p = new Path (splitDir , f .getPath ().getName () + "." + parentRegionName );
665+ if (fs .exists (p )){
666+ LOG .warn ("Found an already existing split file for {}. Assuming this is a recovery." , p );
667+ return p ;
668+ }
706669 if (splitPolicy == null || !splitPolicy .skipStoreFileRangeCheck (familyName )) {
707670 // Check whether the split row lies in the range of the store file
708671 // If it is outside the range, return directly.
@@ -775,35 +738,17 @@ public Path splitStoreFile(RegionInfo hri, String familyName, HStoreFile f, byte
775738 // A reference to the bottom half of the hsf store file.
776739 Reference r =
777740 top ? Reference .createTopReference (splitRow ): Reference .createBottomReference (splitRow );
778- // Add the referred-to regions name as a dot separated suffix.
779- // See REF_NAME_REGEX regex above. The referred-to regions name is
780- // up in the path of the passed in <code>f</code> -- parentdir is family,
781- // then the directory above is the region name.
782- String parentRegionName = regionInfoForFs .getEncodedName ();
783- // Write reference with same file id only with the other region name as
784- // suffix and into the new region location (under same family).
785- Path p = new Path (splitDir , f .getPath ().getName () + "." + parentRegionName );
786741 return r .write (fs , p );
787742 }
788743
789744 // ===========================================================================
790745 // Merge Helpers
791746 // ===========================================================================
792- /** @return {@link Path} to the temp directory used during merge operations */
793- public Path getMergesDir () {
794- return new Path (getRegionDir (), REGION_MERGES_DIR );
795- }
796747
797748 Path getMergesDir (final RegionInfo hri ) {
798- return new Path (getMergesDir (), hri .getEncodedName ());
749+ return new Path (getTableDir (), hri .getEncodedName ());
799750 }
800751
801- /**
802- * Clean up any merge detritus that may have been left around from previous merge attempts.
803- */
804- void cleanupMergesDir () throws IOException {
805- deleteDir (getMergesDir ());
806- }
807752
808753 /**
809754 * Remove merged region
@@ -827,73 +772,41 @@ static boolean mkdirs(FileSystem fs, Configuration conf, Path dir) throws IOExce
827772 }
828773
829774 /**
830- * Create the region merges directory, a temporary directory to accumulate
831- * merges in.
832- * @throws IOException If merges dir already exists or we fail to create it.
833- * @see HRegionFileSystem#cleanupMergesDir()
834- */
835- public void createMergesDir () throws IOException {
836- Path mergesdir = getMergesDir ();
837- if (fs .exists (mergesdir )) {
838- LOG .info ("{} directory exists. Deleting it to recreate it anew" , mergesdir );
839- if (!fs .delete (mergesdir , true )) {
840- throw new IOException ("Failed deletion of " + mergesdir + " before recreate." );
841- }
842- }
843- if (!mkdirs (fs , conf , mergesdir )) {
844- throw new IOException ("Failed create of " + mergesdir );
845- }
846- }
847-
848- /**
849- * Write out a merge reference under the given merges directory. Package local
850- * so it doesnt leak out of regionserver.
851- * @param mergedRegion {@link RegionInfo} of the merged region
775+ * Write out a merge reference under the given merges directory.
776+ * @param mergingRegion {@link RegionInfo} for one of the regions being merged.
852777 * @param familyName Column Family Name
853778 * @param f File to create reference.
854- * @param mergedDir
855779 * @return Path to created reference.
856- * @throws IOException
780+ * @throws IOException if the merge write fails.
857781 */
858- public Path mergeStoreFile (RegionInfo mergedRegion , String familyName , HStoreFile f ,
859- Path mergedDir ) throws IOException {
860- Path referenceDir = new Path (new Path (mergedDir ,
861- mergedRegion .getEncodedName ()), familyName );
782+ public Path mergeStoreFile (RegionInfo mergingRegion , String familyName , HStoreFile f )
783+ throws IOException {
784+ Path referenceDir = new Path (getMergesDir (regionInfoForFs ), familyName );
862785 // A whole reference to the store file.
863- Reference r = Reference .createTopReference (regionInfoForFs .getStartKey ());
786+ Reference r = Reference .createTopReference (mergingRegion .getStartKey ());
864787 // Add the referred-to regions name as a dot separated suffix.
865788 // See REF_NAME_REGEX regex above. The referred-to regions name is
866789 // up in the path of the passed in <code>f</code> -- parentdir is family,
867790 // then the directory above is the region name.
868- String mergingRegionName = regionInfoForFs .getEncodedName ();
791+ String mergingRegionName = mergingRegion .getEncodedName ();
869792 // Write reference with same file id only with the other region name as
870793 // suffix and into the new region location (under same family).
871794 Path p = new Path (referenceDir , f .getPath ().getName () + "."
872- + mergingRegionName );
795+ + mergingRegionName );
873796 return r .write (fs , p );
874797 }
875798
876799 /**
877- * Commit a merged region, moving it from the merges temporary directory to
878- * the proper location in the filesystem.
879- * @param mergedRegionInfo merged region {@link RegionInfo}
800+ * Commit a merged region, making it ready for use.
880801 * @throws IOException
881802 */
882- public void commitMergedRegion (final RegionInfo mergedRegionInfo ) throws IOException {
883- Path regionDir = new Path (this .tableDir , mergedRegionInfo .getEncodedName ());
884- Path mergedRegionTmpDir = this .getMergesDir (mergedRegionInfo );
885- // Move the tmp dir to the expected location
886- if (mergedRegionTmpDir != null && fs .exists (mergedRegionTmpDir )) {
887-
803+ public void commitMergedRegion () throws IOException {
804+ Path regionDir = getMergesDir (regionInfoForFs );
805+ if (regionDir != null && fs .exists (regionDir )) {
888806 // Write HRI to a file in case we need to recover hbase:meta
889- Path regionInfoFile = new Path (mergedRegionTmpDir , REGION_INFO_FILE );
807+ Path regionInfoFile = new Path (regionDir , REGION_INFO_FILE );
890808 byte [] regionInfoContent = getRegionInfoFileContent (regionInfo );
891809 writeRegionInfoFileContent (conf , fs , regionInfoFile , regionInfoContent );
892-
893- if (!fs .rename (mergedRegionTmpDir , regionDir )) {
894- throw new IOException ("Unable to rename " + mergedRegionTmpDir + " to "
895- + regionDir );
896- }
897810 }
898811 }
899812
@@ -1098,8 +1011,6 @@ public static HRegionFileSystem openRegionFromFileSystem(final Configuration con
10981011 if (!readOnly ) {
10991012 // Cleanup temporary directories
11001013 regionFs .cleanupTempDir ();
1101- regionFs .cleanupSplitsDir ();
1102- regionFs .cleanupMergesDir ();
11031014
11041015 // If it doesn't exists, Write HRI to a file, in case we need to recover hbase:meta
11051016 // Only create HRI if we are the default replica
0 commit comments