@@ -644,20 +644,46 @@ public void createDaughterRegions(final MasterProcedureEnv env) throws IOExcepti
644644 HRegionFileSystem regionFs = HRegionFileSystem .openRegionFromFileSystem (
645645 env .getMasterConfiguration (), fs , tabledir , getParentRegion (), false );
646646 regionFs .createSplitsDir (daughterOneRI , daughterTwoRI );
647+ Pair <List <StoreFileInfo >, List <StoreFileInfo >> expectedReferences =
648+ splitStoreFiles (env , regionFs );
649+ final ExecutorService threadPool = Executors .newFixedThreadPool (2 ,
650+ new ThreadFactoryBuilder ().setNameFormat ("RegionCommitter-pool-%d" ).setDaemon (true )
651+ .setUncaughtExceptionHandler (Threads .LOGGING_EXCEPTION_HANDLER ).build ());
652+ threadPool .submit (new Callable <Path >() {
653+ @ Override
654+ public Path call () throws IOException {
655+ return regionFs .commitDaughterRegion (daughterOneRI , expectedReferences .getFirst (), env );
656+ }
657+ });
658+ threadPool .submit (new Callable <Path >() {
659+ @ Override
660+ public Path call () throws IOException {
661+ return regionFs .commitDaughterRegion (daughterTwoRI , expectedReferences .getSecond (), env );
662+ }
663+ });
664+ // Shutdown the pool
665+ threadPool .shutdown ();
647666
648- Pair <List <Path >, List <Path >> expectedReferences = splitStoreFiles (env , regionFs );
649-
650- assertSplitResultFilesCount (fs , expectedReferences .getFirst ().size (),
651- regionFs .getSplitsDir (daughterOneRI ));
652- regionFs .commitDaughterRegion (daughterOneRI , expectedReferences .getFirst (), env );
653- assertSplitResultFilesCount (fs , expectedReferences .getFirst ().size (),
654- new Path (tabledir , daughterOneRI .getEncodedName ()));
655-
656- assertSplitResultFilesCount (fs , expectedReferences .getSecond ().size (),
657- regionFs .getSplitsDir (daughterTwoRI ));
658- regionFs .commitDaughterRegion (daughterTwoRI , expectedReferences .getSecond (), env );
659- assertSplitResultFilesCount (fs , expectedReferences .getSecond ().size (),
660- new Path (tabledir , daughterTwoRI .getEncodedName ()));
667+ Configuration conf = env .getMasterConfiguration ();
668+ // Wait for all the tasks to finish.
669+ // When splits ran on the RegionServer, how-long-to-wait-configuration was named
670+ // hbase.regionserver.fileSplitTimeout. If set, use its value.
671+ long fileSplitTimeout = conf .getLong ("hbase.master.fileSplitTimeout" ,
672+ conf .getLong ("hbase.regionserver.fileSplitTimeout" , 600000 ));
673+ try {
674+ boolean stillRunning = !threadPool .awaitTermination (fileSplitTimeout , TimeUnit .MILLISECONDS );
675+ if (stillRunning ) {
676+ threadPool .shutdownNow ();
677+ // wait for the thread to shutdown completely.
678+ while (!threadPool .isTerminated ()) {
679+ Thread .sleep (50 );
680+ }
681+ throw new IOException (
682+ "Took too long to split the" + " files and create the references, aborting split" );
683+ }
684+ } catch (InterruptedException e ) {
685+ throw (InterruptedIOException ) new InterruptedIOException ().initCause (e );
686+ }
661687 }
662688
663689 private void deleteDaughterRegions (final MasterProcedureEnv env ) throws IOException {
@@ -673,8 +699,8 @@ private void deleteDaughterRegions(final MasterProcedureEnv env) throws IOExcept
673699 * Create Split directory
674700 * @param env MasterProcedureEnv
675701 */
676- private Pair <List <Path >, List <Path >> splitStoreFiles (final MasterProcedureEnv env ,
677- final HRegionFileSystem regionFs ) throws IOException {
702+ private Pair <List <StoreFileInfo >, List <StoreFileInfo >> splitStoreFiles (
703+ final MasterProcedureEnv env , final HRegionFileSystem regionFs ) throws IOException {
678704 final Configuration conf = env .getMasterConfiguration ();
679705 TableDescriptor htd = env .getMasterServices ().getTableDescriptors ().get (getTableName ());
680706 // The following code sets up a thread pool executor with as many slots as
@@ -729,7 +755,8 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
729755 final ExecutorService threadPool = Executors .newFixedThreadPool (maxThreads ,
730756 new ThreadFactoryBuilder ().setNameFormat ("StoreFileSplitter-pool-%d" ).setDaemon (true )
731757 .setUncaughtExceptionHandler (Threads .LOGGING_EXCEPTION_HANDLER ).build ());
732- final List <Future <Pair <Path , Path >>> futures = new ArrayList <Future <Pair <Path , Path >>>(nbFiles );
758+ final List <Future <Pair <StoreFileInfo , StoreFileInfo >>> futures =
759+ new ArrayList <Future <Pair <StoreFileInfo , StoreFileInfo >>>(nbFiles );
733760
734761 // Split each store file.
735762 for (Map .Entry <String , Collection <StoreFileInfo >> e : files .entrySet ()) {
@@ -776,12 +803,12 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
776803 throw (InterruptedIOException ) new InterruptedIOException ().initCause (e );
777804 }
778805
779- List <Path > daughterA = new ArrayList <>();
780- List <Path > daughterB = new ArrayList <>();
806+ List <StoreFileInfo > daughterA = new ArrayList <>();
807+ List <StoreFileInfo > daughterB = new ArrayList <>();
781808 // Look for any exception
782- for (Future <Pair <Path , Path >> future : futures ) {
809+ for (Future <Pair <StoreFileInfo , StoreFileInfo >> future : futures ) {
783810 try {
784- Pair <Path , Path > p = future .get ();
811+ Pair <StoreFileInfo , StoreFileInfo > p = future .get ();
785812 if (p .getFirst () != null ) {
786813 daughterA .add (p .getFirst ());
787814 }
@@ -803,6 +830,7 @@ private Pair<List<Path>, List<Path>> splitStoreFiles(final MasterProcedureEnv en
803830 return new Pair <>(daughterA , daughterB );
804831 }
805832
833+ // TODO: update assert to do SFT.load instead of FileSystem listing
806834 private void assertSplitResultFilesCount (final FileSystem fs ,
807835 final int expectedSplitResultFileCount , Path dir ) throws IOException {
808836 if (expectedSplitResultFileCount != 0 ) {
@@ -814,8 +842,8 @@ private void assertSplitResultFilesCount(final FileSystem fs,
814842 }
815843 }
816844
817- private Pair <Path , Path > splitStoreFile (HRegionFileSystem regionFs , TableDescriptor htd ,
818- ColumnFamilyDescriptor hcd , HStoreFile sf ) throws IOException {
845+ private Pair <StoreFileInfo , StoreFileInfo > splitStoreFile (HRegionFileSystem regionFs ,
846+ TableDescriptor htd , ColumnFamilyDescriptor hcd , HStoreFile sf ) throws IOException {
819847 if (LOG .isDebugEnabled ()) {
820848 LOG .debug ("pid=" + getProcId () + " splitting started for store file: " + sf .getPath ()
821849 + " for region: " + getParentRegion ().getShortNameToLog ());
@@ -831,22 +859,22 @@ private Pair<Path, Path> splitStoreFile(HRegionFileSystem regionFs, TableDescrip
831859 StoreFileTrackerFactory .create (regionFs .getFileSystem ().getConf (), htd , hcd ,
832860 HRegionFileSystem .create (regionFs .getFileSystem ().getConf (), regionFs .getFileSystem (),
833861 regionFs .getTableDir (), daughterTwoRI ));
834- final Path path_first = regionFs .splitStoreFile (this .daughterOneRI , familyName , sf , splitRow ,
835- false , splitPolicy , daughterOneSft );
836- final Path path_second = regionFs .splitStoreFile (this .daughterTwoRI , familyName , sf , splitRow ,
837- true , splitPolicy , daughterTwoSft );
862+ final StoreFileInfo sfiFirst = regionFs .splitStoreFile (this .daughterOneRI , familyName , sf ,
863+ splitRow , false , splitPolicy , daughterOneSft );
864+ final StoreFileInfo sfiSecond = regionFs .splitStoreFile (this .daughterTwoRI , familyName , sf ,
865+ splitRow , true , splitPolicy , daughterTwoSft );
838866 if (LOG .isDebugEnabled ()) {
839867 LOG .debug ("pid=" + getProcId () + " splitting complete for store file: " + sf .getPath ()
840868 + " for region: " + getParentRegion ().getShortNameToLog ());
841869 }
842- return new Pair <Path , Path >( path_first , path_second );
870+ return new Pair <StoreFileInfo , StoreFileInfo >( sfiFirst , sfiSecond );
843871 }
844872
845873 /**
846874 * Utility class used to do the file splitting / reference writing in parallel instead of
847875 * sequentially.
848876 */
849- private class StoreFileSplitter implements Callable <Pair <Path , Path >> {
877+ private class StoreFileSplitter implements Callable <Pair <StoreFileInfo , StoreFileInfo >> {
850878 private final HRegionFileSystem regionFs ;
851879 private final ColumnFamilyDescriptor hcd ;
852880 private final HStoreFile sf ;
@@ -867,7 +895,7 @@ public StoreFileSplitter(HRegionFileSystem regionFs, TableDescriptor htd,
867895 }
868896
869897 @ Override
870- public Pair <Path , Path > call () throws IOException {
898+ public Pair <StoreFileInfo , StoreFileInfo > call () throws IOException {
871899 return splitStoreFile (regionFs , htd , hcd , sf );
872900 }
873901 }
0 commit comments