-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-4524. Create freon test to measure closed container replication #1635
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f1f62f
HDDS-4524. Create freon test to measure closed container replication
elek 99c4b38
fixes before pr
elek 7a7d378
fix typo
elek 0911e10
Use String.isEmpty()
elek bcf882b
Merge remote-tracking branch 'origin/master' into HDDS-4524
elek 5aa2fcc
implement check on the destination dir
elek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
180 changes: 180 additions & 0 deletions
180
...op-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ClosedContainerReplicator.java
This file contains hidden or 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,180 @@ | ||
| /* | ||
| * 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.freon; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType; | ||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState; | ||
| import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; | ||
| import org.apache.hadoop.hdds.scm.container.ContainerInfo; | ||
| import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline; | ||
| import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics; | ||
| import org.apache.hadoop.ozone.container.common.impl.ContainerSet; | ||
| import org.apache.hadoop.ozone.container.common.interfaces.Handler; | ||
| import org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet; | ||
| import org.apache.hadoop.ozone.container.keyvalue.TarContainerPacker; | ||
| import org.apache.hadoop.ozone.container.ozoneimpl.ContainerController; | ||
| import org.apache.hadoop.ozone.container.replication.ContainerReplicator; | ||
| import org.apache.hadoop.ozone.container.replication.DownloadAndImportReplicator; | ||
| import org.apache.hadoop.ozone.container.replication.ReplicationSupervisor; | ||
| import org.apache.hadoop.ozone.container.replication.ReplicationTask; | ||
| import org.apache.hadoop.ozone.container.replication.SimpleContainerDownloader; | ||
|
|
||
| import com.codahale.metrics.Timer; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import picocli.CommandLine.Command; | ||
| import picocli.CommandLine.Option; | ||
|
|
||
| /** | ||
| * Utility to replicated closed container with datanode code. | ||
| */ | ||
| @Command(name = "cr", | ||
| aliases = "container-replicator", | ||
| description = "Replicate / download closed containers.", | ||
| versionProvider = HddsVersionProvider.class, | ||
| mixinStandardHelpOptions = true, | ||
| showDefaultValues = true) | ||
| public class ClosedContainerReplicator extends BaseFreonGenerator implements | ||
| Callable<Void> { | ||
|
|
||
| @Option(names = {"--datanode"}, | ||
| description = "Replicate only containers on this specific datanode.", | ||
| defaultValue = "") | ||
| private String datanode; | ||
|
|
||
| private ReplicationSupervisor supervisor; | ||
|
|
||
| private Timer timer; | ||
|
|
||
| private List<ReplicationTask> replicationTasks; | ||
|
|
||
| @Override | ||
| public Void call() throws Exception { | ||
|
|
||
| //logic same as the download+import on the destination datanode | ||
| OzoneConfiguration conf = initializeReplicationSupervisor(); | ||
|
|
||
| final ContainerOperationClient containerOperationClient = | ||
| new ContainerOperationClient(conf); | ||
|
|
||
| final List<ContainerInfo> containerInfos = | ||
| containerOperationClient.listContainer(0L, 1_000_000); | ||
|
|
||
| replicationTasks = new ArrayList<>(); | ||
|
|
||
| for (ContainerInfo container : containerInfos) { | ||
|
|
||
| final ContainerWithPipeline containerWithPipeline = | ||
| containerOperationClient | ||
| .getContainerWithPipeline(container.getContainerID()); | ||
|
|
||
| if (container.getState() == LifeCycleState.CLOSED) { | ||
|
|
||
| final List<DatanodeDetails> datanodesWithContainer = | ||
| containerWithPipeline.getPipeline().getNodes(); | ||
|
|
||
| final List<String> datanodeUUIDs = | ||
| datanodesWithContainer | ||
| .stream().map(DatanodeDetails::getUuidString) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| //if datanode is specific replicate only container if has a replica. | ||
| if (datanode.equals("") || datanodeUUIDs.contains(datanode)) { | ||
elek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| replicationTasks.add(new ReplicationTask(container.getContainerID(), | ||
| datanodesWithContainer)); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| //important: override the max number of tasks. | ||
| setTestNo(replicationTasks.size()); | ||
|
|
||
| init(); | ||
|
|
||
| timer = getMetrics().timer("replicate-container"); | ||
| runTests(this::replicateContainer); | ||
| return null; | ||
| } | ||
|
|
||
| @NotNull | ||
| private OzoneConfiguration initializeReplicationSupervisor() | ||
| throws IOException { | ||
| String fakeDatanodeUuid = datanode; | ||
|
|
||
| if (fakeDatanodeUuid.equals("")) { | ||
elek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fakeDatanodeUuid = UUID.randomUUID().toString(); | ||
| } | ||
|
|
||
| OzoneConfiguration conf = createOzoneConfiguration(); | ||
|
|
||
| ContainerSet containerSet = new ContainerSet(); | ||
|
|
||
| ContainerMetrics metrics = ContainerMetrics.create(conf); | ||
|
|
||
| MutableVolumeSet volumeSet = new MutableVolumeSet(fakeDatanodeUuid, conf); | ||
|
|
||
| Map<ContainerType, Handler> handlers = new HashMap<>(); | ||
|
|
||
| for (ContainerType containerType : ContainerType.values()) { | ||
| final Handler handler = | ||
| Handler.getHandlerForContainerType( | ||
| containerType, | ||
| conf, | ||
| fakeDatanodeUuid, | ||
| containerSet, | ||
| volumeSet, | ||
| metrics, | ||
| containerReplicaProto -> { | ||
| }); | ||
| handler.setScmID(UUID.randomUUID().toString()); | ||
| handlers.put(containerType, handler); | ||
| } | ||
|
|
||
| ContainerController controller = | ||
| new ContainerController(containerSet, handlers); | ||
|
|
||
| ContainerReplicator replicator = | ||
| new DownloadAndImportReplicator(containerSet, | ||
| controller, | ||
| new SimpleContainerDownloader(conf, null), | ||
| new TarContainerPacker()); | ||
|
|
||
| supervisor = new ReplicationSupervisor(containerSet, replicator, 10); | ||
| return conf; | ||
| } | ||
|
|
||
| private void replicateContainer(long counter) throws Exception { | ||
| timer.time(() -> { | ||
| final ReplicationTask replicationTask = | ||
| replicationTasks.get((int) counter); | ||
| supervisor.new TaskRunner(replicationTask).run(); | ||
| return null; | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.