-
Notifications
You must be signed in to change notification settings - Fork 619
HDDS-12819. Auto-compact tables which can tend to be large in size at intervals #8260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
fbfdb99
8a953f2
939cee1
fc72f4e
2699e77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -627,4 +627,22 @@ private OMConfigKeys() { | |
| public static final String OZONE_OM_EDEKCACHELOADER_MAX_RETRIES_KEY = | ||
| "ozone.om.edekcacheloader.max-retries"; | ||
| public static final int OZONE_OM_EDEKCACHELOADER_MAX_RETRIES_DEFAULT = 10; | ||
|
|
||
| /** | ||
| * Configuration properties for Compaction Service. | ||
| */ | ||
| public static final String OZONE_OM_COMPACTION_SERVICE_ENABLED = "ozone.compaction.service.enabled"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Tejaskriya - public static final String OZONE_OM_COMPACTION_SERVICE_ENABLED = "ozone.compaction.service.enabled";
+ public static final String OZONE_OM_COMPACTION_SERVICE_ENABLED = "ozone.om.compaction.service.enabled";
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although it is consistent with what the config is named in ozone-default.xml, I will correct it in a followup jira. Thanks for catching this! @jojochuang I am not sure if someone using this version of the patch would face any issues. Do you happen to know if not following the config naming convention would cause any breakage?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HDDS-13525 fixes this |
||
| public static final boolean OZONE_OM_COMPACTION_SERVICE_ENABLED_DEFAULT = true; | ||
| public static final String OZONE_OM_COMPACTION_SERVICE_RUN_INTERVAL = | ||
| "ozone.om.compaction.service.run.interval"; | ||
| public static final long OZONE_OM_COMPACTION_SERVICE_RUN_INTERVAL_DEFAULT | ||
| = TimeUnit.HOURS.toMillis(6); | ||
|
|
||
| public static final String OZONE_OM_COMPACTION_SERVICE_TIMEOUT | ||
| = "ozone.om.compaction.service.timeout"; | ||
| public static final String OZONE_OM_COMPACTION_SERVICE_TIMEOUT_DEFAULT = "10m"; | ||
| public static final String OZONE_OM_COMPACTION_SERVICE_COLUMNFAMILIES | ||
| = "ozone.om.compaction.service.columnfamilies"; | ||
| public static final String OZONE_OM_COMPACTION_SERVICE_COLUMNFAMILIES_DEFAULT = | ||
| "keyTable,fileTable,directoryTable,deletedTable,deletedDirectoryTable,multipartInfoTable"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.ozone.om.service; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import org.apache.hadoop.hdds.utils.BackgroundService; | ||
| import org.apache.hadoop.hdds.utils.BackgroundTask; | ||
| import org.apache.hadoop.hdds.utils.BackgroundTaskQueue; | ||
| import org.apache.hadoop.hdds.utils.BackgroundTaskResult; | ||
| import org.apache.hadoop.hdds.utils.db.RDBStore; | ||
| import org.apache.hadoop.hdds.utils.db.RocksDatabase; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedCompactRangeOptions; | ||
| import org.apache.hadoop.ozone.om.OMMetadataManager; | ||
| import org.apache.hadoop.ozone.om.OzoneManager; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * This is the background service to compact OM rocksdb tables. | ||
| */ | ||
| public class CompactionService extends BackgroundService { | ||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(CompactionService.class); | ||
|
|
||
| // Use only a single thread for Compaction. | ||
| private static final int COMPACTOR_THREAD_POOL_SIZE = 1; | ||
|
|
||
| private final OzoneManager ozoneManager; | ||
| private final OMMetadataManager omMetadataManager; | ||
| private final AtomicLong numCompactions; | ||
| private final AtomicBoolean suspended; | ||
| // list of tables that can be compacted | ||
| private final List<String> compactableTables; | ||
|
|
||
| public CompactionService(OzoneManager ozoneManager, TimeUnit unit, long interval, long timeout, | ||
| List<String> tables) { | ||
| super("CompactionService", interval, unit, | ||
| COMPACTOR_THREAD_POOL_SIZE, timeout, | ||
| ozoneManager.getThreadNamePrefix()); | ||
| this.ozoneManager = ozoneManager; | ||
| this.omMetadataManager = this.ozoneManager.getMetadataManager(); | ||
|
|
||
| this.numCompactions = new AtomicLong(0); | ||
| this.suspended = new AtomicBoolean(false); | ||
| for (String table : tables) { | ||
| if (!omMetadataManager.listTableNames().contains(table)) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| this.compactableTables = tables; | ||
| } | ||
|
Tejaskriya marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Suspend the service (for testing). | ||
| */ | ||
| @VisibleForTesting | ||
| public void suspend() { | ||
| suspended.set(true); | ||
| } | ||
|
|
||
| /** | ||
| * Resume the service if suspended (for testing). | ||
| */ | ||
| @VisibleForTesting | ||
| public void resume() { | ||
| suspended.set(false); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of manual compactions performed. | ||
| * | ||
| * @return long count. | ||
| */ | ||
| @VisibleForTesting | ||
| public long getNumCompactions() { | ||
| return numCompactions.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized BackgroundTaskQueue getTasks() { | ||
| BackgroundTaskQueue queue = new BackgroundTaskQueue(); | ||
| for (String tableName : compactableTables) { | ||
| queue.add(new CompactTask(tableName)); | ||
| } | ||
| return queue; | ||
| } | ||
|
|
||
| private boolean shouldRun() { | ||
| return !suspended.get(); | ||
| } | ||
|
|
||
| protected void compactFully(String tableName) throws IOException { | ||
| long startTime = Time.monotonicNow(); | ||
| LOG.info("Compacting column family: {}", tableName); | ||
| try (ManagedCompactRangeOptions options = new ManagedCompactRangeOptions()) { | ||
| options.setBottommostLevelCompaction(ManagedCompactRangeOptions.BottommostLevelCompaction.kForce); | ||
| RocksDatabase rocksDatabase = ((RDBStore) omMetadataManager.getStore()).getDb(); | ||
|
|
||
| try { | ||
| // Find CF Handler | ||
| RocksDatabase.ColumnFamily columnFamily = rocksDatabase.getColumnFamily(tableName); | ||
| rocksDatabase.compactRange(columnFamily, null, null, options); | ||
|
Comment on lines
+116
to
+148
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have one similar suggestion just like I left in #8029 (comment) This can be moved to And it would be better to let the function be #8178 would also take benefit from it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional, but maybe a
jojochuang marked this conversation as resolved.
|
||
| LOG.info("Compaction of column family: {} completed in {} ms", | ||
| tableName, Time.monotonicNow() - startTime); | ||
| } catch (NullPointerException ex) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check null instead of catching BTW, the commit message somehow used HDDS-12518 instead of HDDS-12819. |
||
| LOG.error("Unable to trigger compaction for \"{}\". Column family not found ", tableName); | ||
| throw new IOException("Column family \"" + tableName + "\" not found."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private class CompactTask implements BackgroundTask { | ||
| private final String tableName; | ||
|
|
||
| CompactTask(String tableName) { | ||
| this.tableName = tableName; | ||
| } | ||
|
|
||
| @Override | ||
| public int getPriority() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public BackgroundTaskResult call() throws Exception { | ||
| // trigger full compaction for the specified table. | ||
| if (!shouldRun()) { | ||
| return BackgroundTaskResult.EmptyTaskResult.newResult(); | ||
| } | ||
| LOG.debug("Running CompactTask"); | ||
|
|
||
| compactFully(tableName); | ||
| numCompactions.incrementAndGet(); | ||
| return () -> 1; | ||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.