Skip to content

Commit d919220

Browse files
committed
HBASE-27125 The batch size of cleaning expired mob files should have an upper bound
1 parent b365748 commit d919220

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public final class MobConstants {
4646
public static final String MOB_CACHE_EVICT_REMAIN_RATIO = "hbase.mob.cache.evict.remain.ratio";
4747
public static final Tag MOB_REF_TAG =
4848
new ArrayBackedTag(TagType.MOB_REFERENCE_TAG_TYPE, HConstants.EMPTY_BYTE_ARRAY);
49+
public static final String MOB_CLEANER_BATCH_SIZE_UPPER_BOUND =
50+
"hbase.master.mob.cleaner.batch.size.upper.bound";
51+
public static final int DEFAULT_MOB_CLEANER_BATCH_SIZE_UPPER_BOUND = 10000;
4952

5053
public static final float DEFAULT_EVICT_REMAIN_RATIO = 0.5f;
5154
public static final long DEFAULT_MOB_CACHE_EVICT_PERIOD = 3600L;

hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobUtils.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
package org.apache.hadoop.hbase.mob;
1919

20+
import static org.apache.hadoop.hbase.mob.MobConstants.DEFAULT_MOB_CLEANER_BATCH_SIZE_UPPER_BOUND;
21+
import static org.apache.hadoop.hbase.mob.MobConstants.MOB_CLEANER_BATCH_SIZE_UPPER_BOUND;
22+
2023
import java.io.FileNotFoundException;
2124
import java.io.IOException;
2225
import java.nio.ByteBuffer;
@@ -314,20 +317,24 @@ public static void cleanExpiredMobFiles(FileSystem fs, Configuration conf, Table
314317
}
315318
filesToClean
316319
.add(new HStoreFile(fs, file.getPath(), conf, cacheConfig, BloomType.NONE, true));
320+
if (
321+
filesToClean.size() > conf.getInt(MOB_CLEANER_BATCH_SIZE_UPPER_BOUND,
322+
DEFAULT_MOB_CLEANER_BATCH_SIZE_UPPER_BOUND)
323+
) {
324+
try {
325+
removeMobFiles(conf, fs, tableName, mobTableDir, columnDescriptor.getName(),
326+
filesToClean);
327+
LOG.info("Table {} {} expired mob files are deleted", tableName, filesToClean.size());
328+
} catch (IOException e) {
329+
LOG.error("Failed to delete the mob files, table {}", tableName, e);
330+
}
331+
filesToClean.clear();
332+
}
317333
}
318334
} catch (Exception e) {
319335
LOG.error("Cannot parse the fileName " + fileName, e);
320336
}
321337
}
322-
if (!filesToClean.isEmpty()) {
323-
try {
324-
removeMobFiles(conf, fs, tableName, mobTableDir, columnDescriptor.getName(), filesToClean);
325-
deletedFileCount = filesToClean.size();
326-
} catch (IOException e) {
327-
LOG.error("Failed to delete the mob files " + filesToClean, e);
328-
}
329-
}
330-
LOG.info("{} expired mob files are deleted", deletedFileCount);
331338
}
332339

333340
/**

hbase-server/src/test/java/org/apache/hadoop/hbase/mob/TestExpiredMobFileCleaner.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.mob;
1919

20+
import static org.apache.hadoop.hbase.mob.MobConstants.MOB_CLEANER_BATCH_SIZE_UPPER_BOUND;
2021
import static org.junit.Assert.assertEquals;
2122

2223
import org.apache.hadoop.fs.FileStatus;
@@ -55,6 +56,7 @@ public class TestExpiredMobFileCleaner {
5556
private final static String family = "family";
5657
private final static byte[] row1 = Bytes.toBytes("row1");
5758
private final static byte[] row2 = Bytes.toBytes("row2");
59+
private final static byte[] row3 = Bytes.toBytes("row3");
5860
private final static byte[] qf = Bytes.toBytes("qf");
5961

6062
private static BufferedMutator table;
@@ -63,6 +65,7 @@ public class TestExpiredMobFileCleaner {
6365
@BeforeClass
6466
public static void setUpBeforeClass() throws Exception {
6567
TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
68+
TEST_UTIL.getConfiguration().setInt(MOB_CLEANER_BATCH_SIZE_UPPER_BOUND, 1);
6669
}
6770

6871
@AfterClass
@@ -146,6 +149,12 @@ public void testCleaner() throws Exception {
146149
String f2 = secondFiles[1].getPath().getName();
147150
String secondFile = f1.equals(firstFile) ? f2 : f1;
148151

152+
ts = EnvironmentEdgeManager.currentTime() - 4 * secondsOfDay() * 1000; // 4 days before
153+
putKVAndFlush(table, row3, dummyData, ts);
154+
FileStatus[] thirdFiles = TEST_UTIL.getTestFileSystem().listStatus(mobDirPath);
155+
// now there are 3 mob files
156+
assertEquals("Before cleanup without delay 3", 3, thirdFiles.length);
157+
149158
modifyColumnExpiryDays(2); // ttl = 2, make the first row expired
150159

151160
// run the cleaner

0 commit comments

Comments
 (0)