1- /**
1+ /*
22 * Licensed to the Apache Software Foundation (ASF) under one
33 * or more contributor license agreements. See the NOTICE file
44 * distributed with this work for additional information
2222import static org .junit .Assert .assertTrue ;
2323import static org .mockito .Mockito .mock ;
2424import static org .mockito .Mockito .when ;
25-
2625import java .io .FileNotFoundException ;
2726import java .io .IOException ;
2827import java .util .ArrayList ;
28+ import java .util .Arrays ;
2929import java .util .List ;
3030import java .util .concurrent .TimeUnit ;
31+ import java .util .stream .Collectors ;
3132import org .apache .hadoop .conf .Configuration ;
3233import org .apache .hadoop .fs .FileStatus ;
3334import org .apache .hadoop .fs .FileSystem ;
5354import org .apache .hadoop .hbase .util .Bytes ;
5455import org .apache .hadoop .hbase .util .CommonFSUtils ;
5556import org .apache .hadoop .hbase .util .HFileArchiveUtil ;
57+ import org .apache .hadoop .hbase .util .Threads ;
5658import org .junit .After ;
5759import org .junit .AfterClass ;
5860import org .junit .Before ;
5961import org .junit .BeforeClass ;
6062import org .junit .ClassRule ;
6163import org .junit .Test ;
6264import org .junit .experimental .categories .Category ;
63-
65+ import org .slf4j .Logger ;
66+ import org .slf4j .LoggerFactory ;
6467import org .apache .hbase .thirdparty .com .google .common .collect .Iterables ;
6568
6669@ Category ({ MasterTests .class , MediumTests .class })
6770public class TestLocalRegionOnTwoFileSystems {
71+ private static final Logger LOG = LoggerFactory .getLogger (TestLocalRegionOnTwoFileSystems .class );
6872
6973 @ ClassRule
7074 public static final HBaseClassTestRule CLASS_RULE =
@@ -78,8 +82,6 @@ public class TestLocalRegionOnTwoFileSystems {
7882
7983 private static byte [] CQ = Bytes .toBytes ("q" );
8084
81- private static String REGION_DIR_NAME = "local" ;
82-
8385 private static TableDescriptor TD =
8486 TableDescriptorBuilder .newBuilder (TableName .valueOf ("test:local" ))
8587 .setColumnFamily (ColumnFamilyDescriptorBuilder .of (CF )).build ();
@@ -114,7 +116,7 @@ private LocalRegion createLocalRegion(ServerName serverName) throws IOException
114116 when (server .getConfiguration ()).thenReturn (HFILE_UTIL .getConfiguration ());
115117 when (server .getServerName ()).thenReturn (serverName );
116118 LocalRegionParams params = new LocalRegionParams ();
117- params .server (server ).regionDirName (REGION_DIR_NAME ).tableDescriptor (TD )
119+ params .server (server ).regionDirName ("local" ).tableDescriptor (TD )
118120 .flushSize (TableDescriptorBuilder .DEFAULT_MEMSTORE_FLUSH_SIZE ).flushPerChanges (1_000_000 )
119121 .flushIntervalMs (TimeUnit .MINUTES .toMillis (15 )).compactMin (COMPACT_MIN ).maxWals (32 )
120122 .useHsync (false ).ringBufferSlotCount (16 ).rollPeriodMs (TimeUnit .MINUTES .toMillis (15 ))
@@ -145,16 +147,17 @@ private int getStorefilesCount() {
145147
146148 @ Test
147149 public void testFlushAndCompact () throws Exception {
148- for (int i = 0 ; i < COMPACT_MIN - 1 ; i ++) {
150+ int compactMinMinusOne = COMPACT_MIN - 1 ;
151+ for (int i = 0 ; i < compactMinMinusOne ; i ++) {
149152 final int index = i ;
150153 region
151154 .update (r -> r .put (new Put (Bytes .toBytes (index )).addColumn (CF , CQ , Bytes .toBytes (index ))));
152155 region .flush (true );
153156 }
154157 region .requestRollAll ();
155158 region .waitUntilWalRollFinished ();
156- region . update ( r -> r . put (
157- new Put (Bytes . toBytes ( COMPACT_MIN - 1 )) .addColumn (CF , CQ , Bytes . toBytes ( COMPACT_MIN - 1 ) )));
159+ byte [] bytes = Bytes . toBytes ( compactMinMinusOne );
160+ region . update ( r -> r . put ( new Put (bytes ) .addColumn (CF , CQ , bytes )));
158161 region .flusherAndCompactor .requestFlush ();
159162
160163 HFILE_UTIL .waitFor (15000 , () -> getStorefilesCount () == 1 );
@@ -171,14 +174,28 @@ public void testFlushAndCompact() throws Exception {
171174 return false ;
172175 }
173176 });
177+ LOG .info ("hfile archive content {}" ,
178+ Arrays .stream (rootFs .listStatus (storeArchiveDir )).map (f -> f .getPath ().toString ()).
179+ collect (Collectors .joining ("," )));
174180
175181 // make sure the archived wal files are on the wal fs
176182 Path walArchiveDir = new Path (CommonFSUtils .getWALRootDir (HFILE_UTIL .getConfiguration ()),
177183 HConstants .HREGION_OLDLOGDIR_NAME );
184+ LOG .info ("wal archive dir {}" , walArchiveDir );
185+ region .requestRollAll ();
186+ region .waitUntilWalRollFinished ();
178187 HFILE_UTIL .waitFor (15000 , () -> {
179188 try {
180189 FileStatus [] fses = WAL_UTIL .getTestFileSystem ().listStatus (walArchiveDir );
181- return fses != null && fses .length == 1 ;
190+ if (fses != null ) {
191+ LOG .info ("wal archive dir content {}" ,
192+ Arrays .stream (fses ).map (f -> f .getPath ().toString ()).
193+ collect (Collectors .joining ("," )));
194+ } else {
195+ LOG .info ("none found" );
196+ Threads .sleep (100 );
197+ }
198+ return fses != null && fses .length >= 1 ;
182199 } catch (FileNotFoundException e ) {
183200 return false ;
184201 }
0 commit comments