-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Stats to record how often the ClusterState diff mechanism is used successfully #26973
Changes from 2 commits
95f0969
5ed348a
db71be7
092be64
8675140
88bfda5
d825792
f004119
ec982bd
c7a0192
660f20a
5543e88
67c1a22
e0f3da3
a9a2828
1852f8f
34c3b5a
6af7728
b935508
68d589d
efcd20d
eaa0fd9
a5124e0
d61551f
3dd4219
b589f36
ed570df
322c1de
840a5bd
54b840a
1fa86b7
ff54a0d
168d94a
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 |
---|---|---|
|
@@ -19,13 +19,15 @@ | |
|
||
package org.elasticsearch.discovery; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.ToXContentFragment; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.discovery.zen.PendingClusterStateStats; | ||
import org.elasticsearch.discovery.zen.PublishClusterStateStats; | ||
|
||
import java.io.IOException; | ||
|
||
|
@@ -34,25 +36,42 @@ public class DiscoveryStats implements Writeable, ToXContentFragment { | |
@Nullable | ||
private final PendingClusterStateStats queueStats; | ||
|
||
public DiscoveryStats(PendingClusterStateStats queueStats) { | ||
@Nullable | ||
private final PublishClusterStateStats publishStats; | ||
|
||
public DiscoveryStats(PendingClusterStateStats queueStats, PublishClusterStateStats publishStats) { | ||
this.queueStats = queueStats; | ||
this.publishStats = publishStats; | ||
} | ||
|
||
public DiscoveryStats(StreamInput in) throws IOException { | ||
queueStats = in.readOptionalWriteable(PendingClusterStateStats::new); | ||
|
||
if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { | ||
publishStats = in.readOptionalWriteable(PublishClusterStateStats::new); | ||
} else { | ||
publishStats = null; | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalWriteable(queueStats); | ||
|
||
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { | ||
out.writeOptionalWriteable(publishStats); | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(Fields.DISCOVERY); | ||
if (queueStats != null ){ | ||
if (queueStats != null) { | ||
queueStats.toXContent(builder, params); | ||
} | ||
if (publishStats != null) { | ||
publishStats.toXContent(builder, params); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
@@ -64,4 +83,5 @@ static final class Fields { | |
public PendingClusterStateStats getQueueStats() { | ||
return queueStats; | ||
} | ||
public PublishClusterStateStats getPublishStats() { return publishStats; } | ||
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. Would you add a newline before this method, and wrap the method definition over multiple lines please? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,10 @@ public class PublishClusterStateAction extends AbstractComponent { | |
public static final String SEND_ACTION_NAME = "internal:discovery/zen/publish/send"; | ||
public static final String COMMIT_ACTION_NAME = "internal:discovery/zen/publish/commit"; | ||
|
||
public PublishClusterStateStats stats() { | ||
return new PublishClusterStateStats(fullClusterStateSentCount, clusterStateDiffSentCount, incompatibleClusterStateDiffVersionCount); | ||
} | ||
|
||
public interface IncomingClusterStateListener { | ||
|
||
/** | ||
|
@@ -90,6 +94,10 @@ public interface IncomingClusterStateListener { | |
private final IncomingClusterStateListener incomingClusterStateListener; | ||
private final DiscoverySettings discoverySettings; | ||
|
||
private long fullClusterStateSentCount = 0; | ||
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. these should probably be atomic... 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. It's sneaky. 😇 |
||
private long clusterStateDiffSentCount = 0; | ||
private long incompatibleClusterStateDiffVersionCount = 0; | ||
|
||
public PublishClusterStateAction( | ||
Settings settings, | ||
TransportService transportService, | ||
|
@@ -249,6 +257,7 @@ private void sendFullClusterState(ClusterState clusterState, Map<Version, BytesR | |
return; | ||
} | ||
} | ||
fullClusterStateSentCount++; | ||
sendClusterStateToNode(clusterState, bytes, node, publishTimeout, sendingController, false, serializedStates); | ||
} | ||
|
||
|
@@ -257,6 +266,7 @@ private void sendClusterStateDiff(ClusterState clusterState, | |
DiscoveryNode node, TimeValue publishTimeout, SendingController sendingController) { | ||
BytesReference bytes = serializedDiffs.get(node.getVersion()); | ||
assert bytes != null : "failed to find serialized diff for node " + node + " of version [" + node.getVersion() + "]"; | ||
clusterStateDiffSentCount++; | ||
sendClusterStateToNode(clusterState, bytes, node, publishTimeout, sendingController, true, serializedStates); | ||
} | ||
|
||
|
@@ -290,6 +300,7 @@ public void handleResponse(TransportResponse.Empty response) { | |
public void handleException(TransportException exp) { | ||
if (sendDiffs && exp.unwrapCause() instanceof IncompatibleClusterStateVersionException) { | ||
logger.debug("resending full cluster state to node {} reason {}", node, exp.getDetailedMessage()); | ||
incompatibleClusterStateDiffVersionCount++; | ||
sendFullClusterState(clusterState, serializedStates, node, publishTimeout, sendingController); | ||
} else { | ||
logger.debug((org.apache.logging.log4j.util.Supplier<?>) () -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.elasticsearch.discovery.zen; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.ToXContentFragment; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Class encapsulating stats about the PublishClusterStateAction | ||
*/ | ||
public class PublishClusterStateStats implements Writeable, ToXContentFragment { | ||
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. I think you want ToXContentObject here. |
||
|
||
private final long fullClusterStateSentCount; | ||
private final long clusterStateDiffSentCount; | ||
private final long incompatibleClusterStateDiffVersionCount; | ||
|
||
public PublishClusterStateStats(long fullClusterStateSentCount, | ||
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. can you java doc the parameters? 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. Params or getters? Or both? |
||
long clusterStateDiffSentCount, | ||
long incompatibleClusterStateDiffVersionCount) { | ||
this.fullClusterStateSentCount = fullClusterStateSentCount; | ||
this.clusterStateDiffSentCount = clusterStateDiffSentCount; | ||
this.incompatibleClusterStateDiffVersionCount = incompatibleClusterStateDiffVersionCount; | ||
} | ||
|
||
public PublishClusterStateStats(StreamInput streamInput) throws IOException { | ||
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 normally name these |
||
fullClusterStateSentCount = streamInput.readVLong(); | ||
clusterStateDiffSentCount = streamInput.readVLong(); | ||
incompatibleClusterStateDiffVersionCount = streamInput.readVLong(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVLong(fullClusterStateSentCount); | ||
out.writeVLong(clusterStateDiffSentCount); | ||
out.writeVLong(incompatibleClusterStateDiffVersionCount); | ||
} | ||
|
||
static final class Fields { | ||
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've been moving away from these inner fields classes, we don't need them to encapsulate some strings. |
||
static final String PUBLISH_CLUSTER_STATE = "publish_cluster_state"; | ||
static final String FULL_SENT = "full_cluster_states_sent"; | ||
static final String DIFFS_SENT = "cluster_state_diffs_sent"; | ||
static final String INCOMPATIBLE_DIFFS = "incompatible_cluster_state_diffs_sent"; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(Fields.PUBLISH_CLUSTER_STATE); | ||
builder.field(Fields.FULL_SENT, fullClusterStateSentCount); | ||
builder.field(Fields.DIFFS_SENT, clusterStateDiffSentCount); | ||
builder.field(Fields.INCOMPATIBLE_DIFFS, incompatibleClusterStateDiffVersionCount); | ||
builder.endObject(); | ||
return builder; | ||
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. Here you can do something like this: diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/PublishClusterStateStats.java b/core/src/main/java/org/elasticsearch/discovery/zen/PublishClusterStateStats.java
index 356b9a29dc..36794e880f 100644
--- a/core/src/main/java/org/elasticsearch/discovery/zen/PublishClusterStateStats.java
+++ b/core/src/main/java/org/elasticsearch/discovery/zen/PublishClusterStateStats.java
@@ -65,9 +65,11 @@ public class PublishClusterStateStats implements Writeable, ToXContentObject {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("published_cluster_states");
- builder.field("full_states", fullClusterStateReceivedCount);
- builder.field("incompatible_diffs", incompatibleClusterStateDiffReceivedCount);
- builder.field("compatible_diffs", compatibleClusterStateDiffReceivedCount);
+ {
+ builder.field("full_states", fullClusterStateReceivedCount);
+ builder.field("incompatible_diffs", incompatibleClusterStateDiffReceivedCount);
+ builder.field("compatible_diffs", compatibleClusterStateDiffReceivedCount);
+ }
builder.endObject();
return builder;
} which makes the JSON-structure clearer in the code. |
||
} | ||
|
||
public long getFullClusterStateSentCount() { | ||
return fullClusterStateSentCount; | ||
} | ||
|
||
public long getClusterStateDiffSentCount() { | ||
return clusterStateDiffSentCount; | ||
} | ||
|
||
public long getIncompatibleClusterStateDiffVersionCount() { | ||
return incompatibleClusterStateDiffVersionCount; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PublishClusterStateStats(full=" + fullClusterStateSentCount | ||
+ ", diffs=" + clusterStateDiffSentCount | ||
+ ", incompatible=" + incompatibleClusterStateDiffVersionCount | ||
+ ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -413,7 +413,8 @@ Set<DiscoveryNode> getFaultDetectionNodes() { | |
@Override | ||
public DiscoveryStats stats() { | ||
PendingClusterStateStats queueStats = pendingStatesQueue.stats(); | ||
return new DiscoveryStats(queueStats); | ||
PublishClusterStateStats publishStats = publishClusterState.stats(); | ||
return new DiscoveryStats(queueStats, publishStats); | ||
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. I think: diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
index 5f62ee6b97..d688a5d5cd 100644
--- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
+++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
@@ -412,9 +412,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
@Override
public DiscoveryStats stats() {
- PendingClusterStateStats queueStats = pendingStatesQueue.stats();
- PublishClusterStateStats publishStats = publishClusterState.stats();
- return new DiscoveryStats(queueStats, publishStats);
+ return new DiscoveryStats(pendingStatesQueue.stats(), publishClusterState.stats());
}
public DiscoverySettings getDiscoverySettings() { is fine? |
||
} | ||
|
||
public DiscoverySettings getDiscoverySettings() { | ||
|
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.
I do not think we need the
@Nullable
annotation on a private field (I question its usefulness in general).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.
Should I remove the one above too?