Skip to content

Commit 3ef44a4

Browse files
committed
HBASE-24437 Flaky test, TestLocalRegionOnTwoFileSystems#testFlushAndCompact
Force another WAL roll just in case and make the check more loose (its about whether the files are present, not their count)
1 parent 90bd19e commit 3ef44a4

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

hbase-server/src/test/java/org/apache/hadoop/hbase/master/store/TestLocalRegionOnTwoFileSystems.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -22,12 +22,13 @@
2222
import static org.junit.Assert.assertTrue;
2323
import static org.mockito.Mockito.mock;
2424
import static org.mockito.Mockito.when;
25-
2625
import java.io.FileNotFoundException;
2726
import java.io.IOException;
2827
import java.util.ArrayList;
28+
import java.util.Arrays;
2929
import java.util.List;
3030
import java.util.concurrent.TimeUnit;
31+
import java.util.stream.Collectors;
3132
import org.apache.hadoop.conf.Configuration;
3233
import org.apache.hadoop.fs.FileStatus;
3334
import org.apache.hadoop.fs.FileSystem;
@@ -53,18 +54,21 @@
5354
import org.apache.hadoop.hbase.util.Bytes;
5455
import org.apache.hadoop.hbase.util.CommonFSUtils;
5556
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
57+
import org.apache.hadoop.hbase.util.Threads;
5658
import org.junit.After;
5759
import org.junit.AfterClass;
5860
import org.junit.Before;
5961
import org.junit.BeforeClass;
6062
import org.junit.ClassRule;
6163
import org.junit.Test;
6264
import org.junit.experimental.categories.Category;
63-
65+
import org.slf4j.Logger;
66+
import org.slf4j.LoggerFactory;
6467
import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
6568

6669
@Category({ MasterTests.class, MediumTests.class })
6770
public 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

Comments
 (0)