-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-12310. Online repair command to perform compaction on om.db #7957
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 all commits
5fc0448
98d1062
2e1d042
26a1043
54218af
88e087e
89695f4
d8204bd
767ae5b
6abb34f
e64a7fb
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.util.concurrent.CompletableFuture; | ||
| 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.OzoneManager; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * This service issues a compaction request for a column family of om.db. | ||
| */ | ||
| public class CompactDBService { | ||
| private static final Logger LOG = LoggerFactory.getLogger( | ||
| CompactDBService.class); | ||
| private final OzoneManager om; | ||
|
|
||
| public CompactDBService(OzoneManager ozoneManager) { | ||
| this.om = ozoneManager; | ||
| } | ||
|
|
||
| public CompletableFuture<Void> compact(String columnFamily) throws | ||
| IOException { | ||
| return CompletableFuture.supplyAsync(() -> { | ||
| try { | ||
| return compactAsync(columnFamily); | ||
| } catch (Exception e) { | ||
| LOG.warn("Failed to compact column family: {}", columnFamily, e); | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| private Void compactAsync(String columnFamilyName) throws IOException { | ||
| LOG.info("Compacting column family: {}", columnFamilyName); | ||
| long startTime = Time.monotonicNow(); | ||
| ManagedCompactRangeOptions options = | ||
| new ManagedCompactRangeOptions(); | ||
| options.setBottommostLevelCompaction( | ||
| ManagedCompactRangeOptions.BottommostLevelCompaction.kForce); | ||
| // Find CF Handler | ||
| RocksDatabase.ColumnFamily columnFamily = | ||
| ((RDBStore)om.getMetadataManager().getStore()).getDb().getColumnFamily(columnFamilyName); | ||
| ((RDBStore)om.getMetadataManager().getStore()).getDb().compactRange( | ||
| columnFamily, null, null, options); | ||
| LOG.info("Compaction of column family: {} completed in {} ms", | ||
| columnFamilyName, Time.monotonicNow() - startTime); | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,8 @@ | |||||||||||
| import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolPB; | ||||||||||||
| import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer; | ||||||||||||
| import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils; | ||||||||||||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerAdminProtocolProtos.CompactRequest; | ||||||||||||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerAdminProtocolProtos.CompactResponse; | ||||||||||||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerAdminProtocolProtos.DecommissionOMRequest; | ||||||||||||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerAdminProtocolProtos.DecommissionOMResponse; | ||||||||||||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerAdminProtocolProtos.OMConfigurationRequest; | ||||||||||||
|
|
@@ -101,4 +103,22 @@ public DecommissionOMResponse decommission(RpcController controller, | |||||||||||
| .setSuccess(true) | ||||||||||||
| .build(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public CompactResponse compactDB(RpcController controller, CompactRequest compactRequest) | ||||||||||||
| throws ServiceException { | ||||||||||||
| try { | ||||||||||||
| // check if table exists. IOException is thrown if table is not found. | ||||||||||||
|
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 only allow admin to compact it.
Suggested change
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. Currently we are doing the check in |
||||||||||||
| ozoneManager.getMetadataManager().getStore().getTable(compactRequest.getColumnFamily()); | ||||||||||||
| ozoneManager.compactOMDB(compactRequest.getColumnFamily()); | ||||||||||||
sadanand48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
| } catch (Exception ex) { | ||||||||||||
| return CompactResponse.newBuilder() | ||||||||||||
| .setSuccess(false) | ||||||||||||
| .setErrorMsg(ex.getMessage()) | ||||||||||||
| .build(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return CompactResponse.newBuilder() | ||||||||||||
| .setSuccess(true).build(); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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.repair.om; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.om.helpers.OMNodeDetails; | ||
| import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolClientSideImpl; | ||
| import org.apache.hadoop.ozone.repair.RepairTool; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import picocli.CommandLine; | ||
|
|
||
| /** | ||
| * Tool to perform compaction on a column family of an om.db. | ||
| */ | ||
| @CommandLine.Command( | ||
| name = "compact", | ||
| description = "CLI to compact a column family in the om.db. " + | ||
| "The compaction happens asynchronously. Requires admin privileges.", | ||
| mixinStandardHelpOptions = true, | ||
| versionProvider = HddsVersionProvider.class | ||
| ) | ||
| public class CompactOMDB extends RepairTool { | ||
|
|
||
| @CommandLine.Option(names = {"--column-family", "--column_family", "--cf"}, | ||
| required = true, | ||
| description = "Column family name") | ||
| private String columnFamilyName; | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"--service-id", "--om-service-id"}, | ||
| description = "Ozone Manager Service ID", | ||
| required = false | ||
| ) | ||
| private String omServiceId; | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"--node-id"}, | ||
| description = "NodeID of the OM for which db needs to be compacted.", | ||
| required = false | ||
| ) | ||
| private String nodeId; | ||
|
|
||
| @Override | ||
| public void execute() throws Exception { | ||
|
|
||
| OzoneConfiguration conf = getOzoneConf(); | ||
| OMNodeDetails omNodeDetails = OMNodeDetails.getOMNodeDetailsFromConf( | ||
| conf, omServiceId, nodeId); | ||
| if (!isDryRun()) { | ||
| try (OMAdminProtocolClientSideImpl omAdminProtocolClient = | ||
| OMAdminProtocolClientSideImpl.createProxyForSingleOM(conf, | ||
| UserGroupInformation.getCurrentUser(), omNodeDetails)) { | ||
| omAdminProtocolClient.compactOMDB(columnFamilyName); | ||
| info("Compaction request issued for om.db of om node: %s, column-family: %s.", nodeId, columnFamilyName); | ||
| info("Please check role logs of %s for completion status.", nodeId); | ||
| } catch (IOException ex) { | ||
| error("Couldn't compact column %s. \nException: %s", columnFamilyName, ex); | ||
| } | ||
| } | ||
sadanand48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So setting this ensures that L0 files are compacted even if the compaction criteria (num of ssts in a level >= threshold etc) are not met and it forces compaction? Also does this only compact L0 files or other upper levels too?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
I believe it compacts everything in the whole range of the column family.