forked from apache/ozone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I3a05cc4f41ed667d52b4ecbeca2dd9ffcdad8416 Fix compaction bugs Change-Id: Id5beedb0f4d5519a9dcb02c94a839adbc5defd40 (cherry picked from commit 142a039dcb4838d0970aecbde10f49898df96475)
- Loading branch information
1 parent
c7f0cce
commit f7b4ac4
Showing
9 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/CompactTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 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; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class CompactTask { | ||
private static final Logger LOG = LoggerFactory.getLogger( | ||
CompactTask.class); | ||
private final OzoneManager om; | ||
|
||
public CompactTask(OzoneManager ozoneManager) { | ||
this.om = ozoneManager; | ||
} | ||
|
||
public CompletableFuture<Void> compact(String columnFamily) throws | ||
IOException { | ||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
return compactAsync(columnFamily); | ||
} catch (IOException 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/om/Compact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.admin.om; | ||
|
||
import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse; | ||
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus; | ||
import org.apache.hadoop.util.Time; | ||
import picocli.CommandLine; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.Callable; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.apache.hadoop.ozone.OmUtils.getOmHostsFromConfig; | ||
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED; | ||
|
||
/** | ||
* Handler of ozone admin om comact command. | ||
*/ | ||
@CommandLine.Command( | ||
name = "compact", | ||
description = "Compact OM RocksDB", | ||
mixinStandardHelpOptions = true, | ||
versionProvider = HddsVersionProvider.class | ||
) | ||
public class Compact implements Callable<Void> { | ||
|
||
@CommandLine.ParentCommand | ||
private OMAdmin parent; | ||
|
||
@CommandLine.Option( | ||
names = {"-id", "--service-id"}, | ||
description = "Ozone Manager Service ID", | ||
required = true | ||
) | ||
private String omServiceId; | ||
|
||
@CommandLine.Option( | ||
names = {"-host", "--service-host"}, | ||
description = "Ozone Manager Host" | ||
) | ||
private String omHost; | ||
|
||
@CommandLine.Option( | ||
names = {"-cf", "--column-family"}, | ||
description = "Column family to be compacted.", | ||
defaultValue = "") | ||
private String columnFamily; | ||
|
||
@Override | ||
public Void call() throws Exception { | ||
OzoneManagerProtocol client = parent.createOmClient(omServiceId, omHost, false); | ||
System.out.println("Compacting column family [" + columnFamily + "]..."); | ||
|
||
client.compact(columnFamily); | ||
System.out.println("Compaction request issued."); | ||
|
||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters