-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDDS-1728. Add metrics for leader's latency in ContainerStateMachine. Contributed by Mukul Kumar Singh. #1022
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -19,11 +19,14 @@ | |
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
| import org.apache.hadoop.metrics2.MetricsSystem; | ||
| import org.apache.hadoop.metrics2.annotation.Metric; | ||
| import org.apache.hadoop.metrics2.annotation.Metrics; | ||
| import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; | ||
| import org.apache.hadoop.metrics2.lib.MutableCounterLong; | ||
| import org.apache.hadoop.metrics2.lib.MutableRate; | ||
| import org.apache.hadoop.metrics2.lib.MetricsRegistry; | ||
| import org.apache.ratis.protocol.RaftGroupId; | ||
|
|
||
| /** | ||
|
|
@@ -43,14 +46,28 @@ public class CSMMetrics { | |
| private @Metric MutableCounterLong numBytesWrittenCount; | ||
| private @Metric MutableCounterLong numBytesCommittedCount; | ||
|
|
||
| private @Metric MutableRate transactionLatency; | ||
| private MutableRate[] opsLatency; | ||
| private MetricsRegistry registry = null; | ||
|
|
||
| // Failure Metrics | ||
| private @Metric MutableCounterLong numWriteStateMachineFails; | ||
| private @Metric MutableCounterLong numQueryStateMachineFails; | ||
| private @Metric MutableCounterLong numApplyTransactionFails; | ||
| private @Metric MutableCounterLong numReadStateMachineFails; | ||
| private @Metric MutableCounterLong numReadStateMachineMissCount; | ||
| private @Metric MutableCounterLong numStartTransactionVerifyFailures; | ||
| private @Metric MutableCounterLong numContainerNotOpenVerifyFailures; | ||
|
|
||
| public CSMMetrics() { | ||
| int numEnumEntries = ContainerProtos.Type.values().length; | ||
| this.opsLatency = new MutableRate[numEnumEntries]; | ||
| this.registry = new MetricsRegistry("CSMMetrics"); | ||
|
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 can use CSMMetrics.class.getName() here. |
||
| for (int i = 0; i < numEnumEntries; i++) { | ||
| opsLatency[i] = registry.newRate( | ||
| ContainerProtos.Type.forNumber(i + 1).toString(), | ||
| ContainerProtos.Type.forNumber(i + 1) + " op"); | ||
| } | ||
| } | ||
|
|
||
| public static CSMMetrics create(RaftGroupId gid) { | ||
|
|
@@ -154,6 +171,19 @@ public long getNumBytesCommittedCount() { | |
| return numBytesCommittedCount.value(); | ||
| } | ||
|
|
||
| public void incPipelineLatency(ContainerProtos.Type type, long latencyNanos) { | ||
| opsLatency[type.ordinal()].add(latencyNanos); | ||
| transactionLatency.add(latencyNanos); | ||
| } | ||
|
|
||
| public void intNumStartTransactionVerifyFailures() { | ||
| numStartTransactionVerifyFailures.incr(); | ||
| } | ||
|
|
||
| public void intNumContainerNotOpenVerifyFailures() { | ||
| numContainerNotOpenVerifyFailures.incr(); | ||
| } | ||
|
|
||
|
|
||
| public void unRegister() { | ||
| MetricsSystem ms = DefaultMetricsSystem.instance(); | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -25,8 +25,10 @@ | |
| import org.apache.hadoop.hdds.HddsUtils; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
|
|
||
| import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerNotOpenException; | ||
| import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; | ||
| import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.apache.ratis.proto.RaftProtos.RaftPeerRole; | ||
| import org.apache.ratis.protocol.RaftGroup; | ||
| import org.apache.ratis.protocol.RaftGroupId; | ||
|
|
@@ -262,12 +264,19 @@ public long takeSnapshot() throws IOException { | |
| @Override | ||
| public TransactionContext startTransaction(RaftClientRequest request) | ||
| throws IOException { | ||
| long startTime = Time.monotonicNowNanos(); | ||
| final ContainerCommandRequestProto proto = | ||
| getContainerCommandRequestProto(request.getMessage().getContent()); | ||
| Preconditions.checkArgument(request.getRaftGroupId().equals(gid)); | ||
| try { | ||
| dispatcher.validateContainerCommand(proto); | ||
| } catch (IOException ioe) { | ||
| if (ioe instanceof ContainerNotOpenException) { | ||
| metrics.intNumContainerNotOpenVerifyFailures(); | ||
|
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. intNumContainerNotOpenVerifyFailures should be in'c'NumContainerNotOpenVerifyFailures. |
||
| } else { | ||
| metrics.intNumStartTransactionVerifyFailures(); | ||
| LOG.error("startTransaction validation failed on leader", ioe); | ||
| } | ||
| TransactionContext ctxt = TransactionContext.newBuilder() | ||
| .setClientRequest(request) | ||
| .setStateMachine(this) | ||
|
|
@@ -297,6 +306,7 @@ public TransactionContext startTransaction(RaftClientRequest request) | |
| .setClientRequest(request) | ||
| .setStateMachine(this) | ||
| .setServerRole(RaftPeerRole.LEADER) | ||
| .setStateMachineContext(startTime) | ||
| .setStateMachineData(write.getData()) | ||
| .setLogData(commitContainerCommandProto.toByteString()) | ||
| .build(); | ||
|
|
@@ -305,6 +315,7 @@ public TransactionContext startTransaction(RaftClientRequest request) | |
| .setClientRequest(request) | ||
| .setStateMachine(this) | ||
| .setServerRole(RaftPeerRole.LEADER) | ||
| .setStateMachineContext(startTime) | ||
| .setLogData(request.getMessage().getContent()) | ||
| .build(); | ||
| } | ||
|
|
@@ -451,8 +462,10 @@ public CompletableFuture<Message> query(Message request) { | |
| } | ||
|
|
||
| private ByteString readStateMachineData( | ||
| ContainerCommandRequestProto requestProto, long term, long index) | ||
| throws IOException { | ||
| ContainerCommandRequestProto requestProto, long term, long index) { | ||
| // the stateMachine data is not present in the stateMachine cache, | ||
| // increment the stateMachine cache miss count | ||
| metrics.incNumReadStateMachineMissCount(); | ||
| WriteChunkRequestProto writeChunkRequestProto = | ||
| requestProto.getWriteChunk(); | ||
| ContainerProtos.ChunkInfo chunkInfo = writeChunkRequestProto.getChunkData(); | ||
|
|
@@ -527,9 +540,6 @@ public CompletableFuture<ByteString> readStateMachineData( | |
| return CompletableFuture.completedFuture(ByteString.EMPTY); | ||
| } | ||
| try { | ||
| // the stateMachine data is not present in the stateMachine cache, | ||
| // increment the stateMachine cache miss count | ||
| metrics.incNumReadStateMachineMissCount(); | ||
| final ContainerCommandRequestProto requestProto = | ||
| getContainerCommandRequestProto( | ||
| entry.getStateMachineLogEntry().getLogData()); | ||
|
|
@@ -622,6 +632,12 @@ public CompletableFuture<Message> applyTransaction(TransactionContext trx) { | |
| getCommandExecutor(requestProto)); | ||
|
|
||
| future.thenAccept(m -> { | ||
| if (trx.getServerRole() == RaftPeerRole.LEADER) { | ||
| long startTime = (long) trx.getStateMachineContext(); | ||
| metrics.incPipelineLatency(cmdType, | ||
| Time.monotonicNowNanos() - startTime); | ||
| } | ||
|
|
||
| final Long previous = | ||
| applyTransactionCompletionMap | ||
| .put(index, trx.getLogEntry().getTerm()); | ||
|
|
||
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.
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.
Can we rename numEnumEntries to numCmdTypes or sth like that?