-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-10373. Implement framework for capturing Merkle Tree Metrics. #6864
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
errose28
merged 15 commits into
apache:HDDS-10239-container-reconciliation
from
aswinshakil:HDDS-10373
Jul 24, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bf0dd6e
Initial outline of checksum manager and merkle tree with proto
errose28 408cff9
Merge branch 'HDDS-10239-container-reconciliation' into mt-manager-wip
errose28 3adbe5a
Add config key for lock stripes
errose28 e02a609
Keep deleted block list sorted
errose28 3680a2e
Change chunk checksum proto, add the first passing test
errose28 0d5800c
Use config defaults for test setup
errose28 eb01da4
Finish tests for ContainerMerkleTree
errose28 f35effd
Add tests for checksum maanger and standardize proto names
errose28 21dd870
Updates after reviewing diff
errose28 47cd213
Rename checksum manager and file. Fix findbugs and Rat
errose28 4ab7a9f
HDDS-10373. Implement framework for capturing Merkle Tree Metrics.
aswinshakil 575c6a5
HDDS-10373. Add create merkle tree latency metric.
aswinshakil accad66
Resolve merge conflict
aswinshakil 8e874ee
removed update metrics and refactored as per review comments.
aswinshakil c900309
Add read metrics test.
aswinshakil 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| */ | ||
| package org.apache.hadoop.ozone.container.checksum; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
| import org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration; | ||
| import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData; | ||
|
|
@@ -34,6 +35,8 @@ | |
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static org.apache.hadoop.util.MetricUtil.captureLatencyNs; | ||
|
|
||
| /** | ||
| * This class coordinates reading and writing Container checksum information for all containers. | ||
| */ | ||
|
|
@@ -44,12 +47,15 @@ public class ContainerChecksumTreeManager { | |
| // Used to coordinate reads and writes to each container's checksum file. | ||
| // Each container ID is mapped to a stripe. | ||
| private final Striped<ReadWriteLock> fileLock; | ||
| private final ContainerMerkleTreeMetrics metrics; | ||
|
|
||
| /** | ||
| * Creates one instance that should be used to coordinate all container checksum info within a datanode. | ||
| */ | ||
| public ContainerChecksumTreeManager(DatanodeConfiguration dnConf) { | ||
| fileLock = SimpleStriped.readWriteLock(dnConf.getContainerChecksumLockStripes(), true); | ||
| // TODO: TO unregister metrics on stop. | ||
| metrics = ContainerMerkleTreeMetrics.create(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -63,7 +69,7 @@ public void writeContainerDataTree(KeyValueContainerData data, ContainerMerkleTr | |
| writeLock.lock(); | ||
| try { | ||
| ContainerProtos.ContainerChecksumInfo newChecksumInfo = read(data).toBuilder() | ||
| .setContainerMerkleTree(tree.toProto()) | ||
| .setContainerMerkleTree(captureLatencyNs(metrics.getCreateMerkleTreeLatencyNS(), tree::toProto)) | ||
| .build(); | ||
| write(data, newChecksumInfo); | ||
| LOG.debug("Data merkle tree for container {} updated", data.getContainerID()); | ||
|
|
@@ -99,21 +105,14 @@ public void markBlocksAsDeleted(KeyValueContainerData data, SortedSet<Long> dele | |
| } | ||
| } | ||
|
|
||
| public ContainerDiff diff(KeyValueContainerData thisContainer, File otherContainerTree) | ||
| public ContainerDiff diff(KeyValueContainerData thisContainer, ContainerProtos.ContainerChecksumInfo otherInfo) | ||
|
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. Let's leave this interface unchanged for now. The current plan is that diff will be passed whatever file or bytestream is obtained from the wire and deserialization into a proto will happen within this class. |
||
| throws IOException { | ||
| // TODO HDDS-10928 compare the checksum info of the two containers and return a summary. | ||
| // Callers can act on this summary to repair their container replica using the peer's replica. | ||
| // This method will use the read lock, which is unused in the current implementation. | ||
| return new ContainerDiff(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the container checksum tree file for the specified container without deserializing it. | ||
| */ | ||
| public File getContainerChecksumFile(KeyValueContainerData data) { | ||
| return new File(data.getMetadataPath(), data.getContainerID() + ".tree"); | ||
| } | ||
|
|
||
| private Lock getReadLock(long containerID) { | ||
| return fileLock.get(containerID).readLock(); | ||
| } | ||
|
|
@@ -139,8 +138,13 @@ private ContainerProtos.ContainerChecksumInfo read(KeyValueContainerData data) t | |
| .build(); | ||
| } | ||
| try (FileInputStream inStream = new FileInputStream(checksumFile)) { | ||
| return ContainerProtos.ContainerChecksumInfo.parseFrom(inStream); | ||
| return captureLatencyNs(metrics.getReadContainerMerkleTreeLatencyNS(), | ||
| () -> ContainerProtos.ContainerChecksumInfo.parseFrom(inStream)); | ||
| } | ||
| } catch (IOException ex) { | ||
| metrics.incrementMerkleTreeReadFailures(); | ||
| throw new IOException("Error occurred when reading container merkle tree for containerID " | ||
| + data.getContainerID(), ex); | ||
| } finally { | ||
| readLock.unlock(); | ||
| } | ||
|
|
@@ -151,12 +155,26 @@ private void write(KeyValueContainerData data, ContainerProtos.ContainerChecksum | |
| Lock writeLock = getWriteLock(data.getContainerID()); | ||
| writeLock.lock(); | ||
| try (FileOutputStream outStream = new FileOutputStream(getContainerChecksumFile(data))) { | ||
| checksumInfo.writeTo(outStream); | ||
| captureLatencyNs(metrics.getWriteContainerMerkleTreeLatencyNS(), | ||
| () -> checksumInfo.writeTo(outStream)); | ||
| } catch (IOException ex) { | ||
| metrics.incrementMerkleTreeWriteFailures(); | ||
| throw new IOException("Error occurred when writing container merkle tree for containerID " | ||
| + data.getContainerID(), ex); | ||
| } finally { | ||
| writeLock.unlock(); | ||
| } | ||
| } | ||
|
|
||
| public File getContainerChecksumFile(KeyValueContainerData data) { | ||
| return new File(data.getMetadataPath(), data.getContainerID() + ".tree"); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public ContainerMerkleTreeMetrics getMetrics() { | ||
errose28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this.metrics; | ||
| } | ||
|
|
||
| /** | ||
| * This class represents the difference between our replica of a container and a peer's replica of a container. | ||
| * It summarizes the operations we need to do to reconcile our replica with the peer replica it was compared to. | ||
|
|
||
77 changes: 77 additions & 0 deletions
77
.../src/main/java/org/apache/hadoop/ozone/container/checksum/ContainerMerkleTreeMetrics.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,77 @@ | ||
| /** | ||
| * 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.container.checksum; | ||
|
|
||
| import org.apache.hadoop.metrics2.MetricsSystem; | ||
| import org.apache.hadoop.metrics2.annotation.Metric; | ||
| import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; | ||
| import org.apache.hadoop.metrics2.lib.MutableCounterLong; | ||
| import org.apache.hadoop.metrics2.lib.MutableRate; | ||
|
|
||
| /** | ||
| * Class to collect metrics related to container merkle tree. | ||
| */ | ||
| public class ContainerMerkleTreeMetrics { | ||
| private static final String METRICS_SOURCE_NAME = ContainerMerkleTreeMetrics.class.getSimpleName(); | ||
|
|
||
| public static ContainerMerkleTreeMetrics create() { | ||
| MetricsSystem ms = DefaultMetricsSystem.instance(); | ||
| return ms.register(METRICS_SOURCE_NAME, "Container Merkle Tree Metrics", | ||
| new ContainerMerkleTreeMetrics()); | ||
| } | ||
|
|
||
| public void unregister() { | ||
| MetricsSystem ms = DefaultMetricsSystem.instance(); | ||
| ms.unregisterSource(METRICS_SOURCE_NAME); | ||
| } | ||
|
|
||
| @Metric(about = "Number of Merkle tree write failure") | ||
| private MutableCounterLong numMerkleTreeWriteFailure; | ||
|
|
||
| @Metric(about = "Number of Merkle tree read failure") | ||
| private MutableCounterLong numMerkleTreeReadFailure; | ||
|
|
||
| @Metric(about = "Merkle tree write latency") | ||
| private MutableRate merkleTreeWriteLatencyNS; | ||
|
|
||
| @Metric(about = "Merkle tree read latency") | ||
| private MutableRate merkleTreeReadLatencyNS; | ||
|
|
||
| @Metric(about = "Merkle tree creation latency") | ||
| private MutableRate merkleTreeCreateLatencyNS; | ||
|
|
||
| public void incrementMerkleTreeWriteFailures() { | ||
| this.numMerkleTreeWriteFailure.incr(); | ||
| } | ||
|
|
||
| public void incrementMerkleTreeReadFailures() { | ||
errose28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.numMerkleTreeReadFailure.incr(); | ||
| } | ||
|
|
||
| public MutableRate getWriteContainerMerkleTreeLatencyNS() { | ||
| return this.merkleTreeWriteLatencyNS; | ||
| } | ||
|
|
||
| public MutableRate getReadContainerMerkleTreeLatencyNS() { | ||
| return this.merkleTreeReadLatencyNS; | ||
| } | ||
|
|
||
| public MutableRate getCreateMerkleTreeLatencyNS() { | ||
| return this.merkleTreeCreateLatencyNS; | ||
| } | ||
| } | ||
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.