-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add REST API for cache directory stats #51815
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
tlrx
merged 14 commits into
elastic:feature/searchable-snapshots
from
tlrx:add-instrumentation-step-2
Feb 6, 2020
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
690a9b4
Add REST API for cache directory stats
tlrx 2dfb3fd
Fix typos
tlrx 88d5c2e
TransportBroadcastByNodeAction
tlrx fe84072
Remove unnecessary dependency
tlrx b934e0e
Merge branch 'feature/searchable-snapshots' into add-instrumentation-…
tlrx 1167ff7
Renaming
tlrx b1d7973
handle negative longs in tests + random seeking threshold
tlrx a4f92bd
unknown
tlrx f2ea47f
replicas to 0 and rename index to docs
tlrx dda6ab7
Collections.unmodifiableMap(stats);
tlrx fde0a86
Document // NORELEASE
tlrx c9468d1
RNFE
tlrx d1049a3
RNFE bis
tlrx c81bcde
Merge branch 'feature/searchable-snapshots' into add-instrumentation-…
elasticmachine 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
397 changes: 397 additions & 0 deletions
397
...c/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotStats.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,397 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.searchablesnapshots; | ||
|
||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
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.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.repositories.IndexId; | ||
import org.elasticsearch.snapshots.SnapshotId; | ||
|
||
import java.io.IOException; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
public class SearchableSnapshotStats implements Writeable, ToXContentObject { | ||
|
||
private final List<CacheIndexInputStats> inputStats; | ||
private final ShardRouting shardRouting; | ||
private final SnapshotId snapshotId; | ||
private final IndexId indexId; | ||
|
||
public SearchableSnapshotStats(ShardRouting shardRouting, SnapshotId snapshotId, IndexId indexId, List<CacheIndexInputStats> stats) { | ||
this.shardRouting = Objects.requireNonNull(shardRouting); | ||
this.snapshotId = Objects.requireNonNull(snapshotId); | ||
this.indexId = Objects.requireNonNull(indexId); | ||
this.inputStats = unmodifiableList(Objects.requireNonNull(stats)); | ||
} | ||
|
||
public SearchableSnapshotStats(StreamInput in) throws IOException { | ||
this.shardRouting = new ShardRouting(in); | ||
this.snapshotId = new SnapshotId(in); | ||
this.indexId = new IndexId(in); | ||
this.inputStats = in.readList(CacheIndexInputStats::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
shardRouting.writeTo(out); | ||
snapshotId.writeTo(out); | ||
indexId.writeTo(out); | ||
out.writeList(inputStats); | ||
} | ||
|
||
public ShardRouting getShardRouting() { | ||
return shardRouting; | ||
} | ||
|
||
public SnapshotId getSnapshotId() { | ||
return snapshotId; | ||
} | ||
|
||
public IndexId getIndexId() { | ||
return indexId; | ||
} | ||
|
||
public List<CacheIndexInputStats> getStats() { | ||
return inputStats; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field("snapshot_uuid", getSnapshotId().getUUID()); | ||
builder.field("index_uuid", getIndexId().getId()); | ||
builder.startObject("shard"); | ||
{ | ||
builder.field("state", shardRouting.state()); | ||
builder.field("primary", shardRouting.primary()); | ||
builder.field("node", shardRouting.currentNodeId()); | ||
if (shardRouting.relocatingNodeId() != null) { | ||
builder.field("relocating_node", shardRouting.relocatingNodeId()); | ||
} | ||
} | ||
builder.endObject(); | ||
builder.startArray("files"); | ||
{ | ||
List<CacheIndexInputStats> stats = inputStats.stream() | ||
.sorted(Comparator.comparing(CacheIndexInputStats::getFileName)).collect(toList()); | ||
for (CacheIndexInputStats stat : stats) { | ||
stat.toXContent(builder, params); | ||
} | ||
} | ||
builder.endArray(); | ||
} | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
SearchableSnapshotStats that = (SearchableSnapshotStats) other; | ||
return Objects.equals(shardRouting, that.shardRouting) | ||
&& Objects.equals(snapshotId, that.snapshotId) | ||
&& Objects.equals(indexId, that.indexId) | ||
&& Objects.equals(inputStats, that.inputStats); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(shardRouting, snapshotId, indexId, inputStats); | ||
} | ||
|
||
|
||
public static class CacheIndexInputStats implements Writeable, ToXContentObject { | ||
|
||
private final String fileName; | ||
private final long fileLength; | ||
|
||
private final long openCount; | ||
private final long innerCount; | ||
private final long closeCount; | ||
|
||
private final Counter forwardSmallSeeks; | ||
private final Counter backwardSmallSeeks; | ||
private final Counter forwardLargeSeeks; | ||
private final Counter backwardLargeSeeks; | ||
private final Counter contiguousReads; | ||
private final Counter nonContiguousReads; | ||
private final Counter cachedBytesRead; | ||
private final Counter cachedBytesWritten; | ||
private final Counter directBytesRead; | ||
|
||
public CacheIndexInputStats(String fileName, long fileLength, long openCount, long innerCount, long closeCount, | ||
Counter forwardSmallSeeks, Counter backwardSmallSeeks, | ||
Counter forwardLargeSeeks, Counter backwardLargeSeeks, | ||
Counter contiguousReads, Counter nonContiguousReads, | ||
Counter cachedBytesRead, Counter cachedBytesWritten, | ||
Counter directBytesRead) { | ||
this.fileName = fileName; | ||
this.fileLength = fileLength; | ||
this.openCount = openCount; | ||
this.innerCount = innerCount; | ||
this.closeCount = closeCount; | ||
this.forwardSmallSeeks = forwardSmallSeeks; | ||
this.backwardSmallSeeks = backwardSmallSeeks; | ||
this.forwardLargeSeeks = forwardLargeSeeks; | ||
this.backwardLargeSeeks = backwardLargeSeeks; | ||
this.contiguousReads = contiguousReads; | ||
this.nonContiguousReads = nonContiguousReads; | ||
this.cachedBytesRead = cachedBytesRead; | ||
this.cachedBytesWritten = cachedBytesWritten; | ||
this.directBytesRead = directBytesRead; | ||
} | ||
|
||
CacheIndexInputStats(final StreamInput in) throws IOException { | ||
this.fileName = in.readString(); | ||
this.fileLength = in.readVLong(); | ||
this.openCount = in.readVLong(); | ||
this.innerCount = in.readVLong(); | ||
this.closeCount = in.readVLong(); | ||
this.forwardSmallSeeks = new Counter(in); | ||
this.backwardSmallSeeks = new Counter(in); | ||
this.forwardLargeSeeks = new Counter(in); | ||
this.backwardLargeSeeks = new Counter(in); | ||
this.contiguousReads = new Counter(in); | ||
this.nonContiguousReads = new Counter(in); | ||
this.cachedBytesRead = new Counter(in); | ||
this.cachedBytesWritten = new Counter(in); | ||
this.directBytesRead = new Counter(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(fileName); | ||
out.writeVLong(fileLength); | ||
out.writeVLong(openCount); | ||
out.writeVLong(innerCount); | ||
out.writeVLong(closeCount); | ||
|
||
forwardSmallSeeks.writeTo(out); | ||
backwardSmallSeeks.writeTo(out); | ||
forwardLargeSeeks.writeTo(out); | ||
backwardLargeSeeks.writeTo(out); | ||
contiguousReads.writeTo(out); | ||
nonContiguousReads.writeTo(out); | ||
cachedBytesRead.writeTo(out); | ||
cachedBytesWritten.writeTo(out); | ||
directBytesRead.writeTo(out); | ||
} | ||
|
||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
public long getFileLength() { | ||
return fileLength; | ||
} | ||
|
||
public long getOpenCount() { | ||
return openCount; | ||
} | ||
|
||
public long getInnerCount() { | ||
return innerCount; | ||
} | ||
|
||
public long getCloseCount() { | ||
return closeCount; | ||
} | ||
|
||
public Counter getForwardSmallSeeks() { | ||
return forwardSmallSeeks; | ||
} | ||
|
||
public Counter getBackwardSmallSeeks() { | ||
return backwardSmallSeeks; | ||
} | ||
|
||
public Counter getForwardLargeSeeks() { | ||
return forwardLargeSeeks; | ||
} | ||
|
||
public Counter getBackwardLargeSeeks() { | ||
return backwardLargeSeeks; | ||
} | ||
|
||
public Counter getContiguousReads() { | ||
return contiguousReads; | ||
} | ||
|
||
public Counter getNonContiguousReads() { | ||
return nonContiguousReads; | ||
} | ||
|
||
public Counter getCachedBytesRead() { | ||
return cachedBytesRead; | ||
} | ||
|
||
public Counter getCachedBytesWritten() { | ||
return cachedBytesWritten; | ||
} | ||
|
||
public Counter getDirectBytesRead() { | ||
return directBytesRead; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field("name", getFileName()); | ||
builder.field("length", getFileLength()); | ||
builder.field("open_count", getOpenCount()); | ||
builder.field("inner_count", getInnerCount()); | ||
builder.field("close_count", getCloseCount()); | ||
builder.field("contiguous_bytes_read", getContiguousReads()); | ||
builder.field("non_contiguous_bytes_read", getNonContiguousReads()); | ||
builder.field("cached_bytes_read", getCachedBytesRead()); | ||
builder.field("cached_bytes_written", getCachedBytesWritten()); | ||
builder.field("direct_bytes_read", getDirectBytesRead()); | ||
{ | ||
builder.startObject("forward_seeks"); | ||
builder.field("small", getForwardSmallSeeks()); | ||
builder.field("large", getForwardLargeSeeks()); | ||
builder.endObject(); | ||
} | ||
{ | ||
builder.startObject("backward_seeks"); | ||
builder.field("small", getBackwardSmallSeeks()); | ||
builder.field("large", getBackwardLargeSeeks()); | ||
builder.endObject(); | ||
} | ||
} | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
CacheIndexInputStats stats = (CacheIndexInputStats) other; | ||
return fileLength == stats.fileLength | ||
&& openCount == stats.openCount | ||
&& innerCount == stats.innerCount | ||
&& closeCount == stats.closeCount | ||
&& Objects.equals(fileName, stats.fileName) | ||
&& Objects.equals(forwardSmallSeeks, stats.forwardSmallSeeks) | ||
&& Objects.equals(backwardSmallSeeks, stats.backwardSmallSeeks) | ||
&& Objects.equals(forwardLargeSeeks, stats.forwardLargeSeeks) | ||
&& Objects.equals(backwardLargeSeeks, stats.backwardLargeSeeks) | ||
&& Objects.equals(contiguousReads, stats.contiguousReads) | ||
&& Objects.equals(nonContiguousReads, stats.nonContiguousReads) | ||
&& Objects.equals(cachedBytesRead, stats.cachedBytesRead) | ||
&& Objects.equals(cachedBytesWritten, stats.cachedBytesWritten) | ||
&& Objects.equals(directBytesRead, stats.directBytesRead); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fileName, fileLength, openCount, innerCount, closeCount, | ||
forwardSmallSeeks, backwardSmallSeeks, | ||
forwardLargeSeeks, backwardLargeSeeks, | ||
contiguousReads, nonContiguousReads, | ||
cachedBytesRead, cachedBytesWritten, | ||
directBytesRead); | ||
} | ||
} | ||
|
||
public static class Counter implements Writeable, ToXContentObject { | ||
|
||
private final long count; | ||
private final long total; | ||
private final long min; | ||
private final long max; | ||
|
||
public Counter(final long count, final long total, final long min, final long max) { | ||
this.count = count; | ||
this.total = total; | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
Counter(final StreamInput in) throws IOException { | ||
this.count = in.readZLong(); | ||
this.total = in.readZLong(); | ||
this.min = in.readZLong(); | ||
this.max = in.readZLong(); | ||
} | ||
|
||
@Override | ||
public void writeTo(final StreamOutput out) throws IOException { | ||
out.writeZLong(count); | ||
DaveCTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
out.writeZLong(total); | ||
out.writeZLong(min); | ||
out.writeZLong(max); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field("count", count); | ||
builder.field("sum", total); | ||
builder.field("min", min); | ||
builder.field("max", max); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public long getCount() { | ||
return count; | ||
} | ||
|
||
public long getTotal() { | ||
return total; | ||
} | ||
|
||
public long getMin() { | ||
return min; | ||
} | ||
|
||
public long getMax() { | ||
return max; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
Counter that = (Counter) other; | ||
return count == that.count | ||
&& total == that.total | ||
&& min == that.min | ||
&& max == that.max; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(count, total, min, max); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.