Skip to content

Commit de65ea6

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

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
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 & 10 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;
@@ -294,7 +297,6 @@ public static void cleanExpiredMobFiles(FileSystem fs, Configuration conf, Table
294297
return;
295298
}
296299
List<HStoreFile> filesToClean = new ArrayList<>();
297-
int deletedFileCount = 0;
298300
for (FileStatus file : stats) {
299301
String fileName = file.getPath().getName();
300302
try {
@@ -314,20 +316,24 @@ public static void cleanExpiredMobFiles(FileSystem fs, Configuration conf, Table
314316
}
315317
filesToClean
316318
.add(new HStoreFile(fs, file.getPath(), conf, cacheConfig, BloomType.NONE, true));
319+
if (
320+
filesToClean.size() > conf.getInt(MOB_CLEANER_BATCH_SIZE_UPPER_BOUND,
321+
DEFAULT_MOB_CLEANER_BATCH_SIZE_UPPER_BOUND)
322+
) {
323+
try {
324+
removeMobFiles(conf, fs, tableName, mobTableDir, columnDescriptor.getName(),
325+
filesToClean);
326+
LOG.info("Table {} {} expired mob files are deleted", tableName, filesToClean.size());
327+
} catch (IOException e) {
328+
LOG.error("Failed to delete the mob files, table {}", tableName, e);
329+
}
330+
filesToClean.clear();
331+
}
317332
}
318333
} catch (Exception e) {
319334
LOG.error("Cannot parse the fileName " + fileName, e);
320335
}
321336
}
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);
331337
}
332338

333339
/**

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)