-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expose retention leases in shard stats #37991
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 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
09c5efa
Expose retention leases in shard stats
jasontedor c78edb4
Fix formatting
jasontedor 7c78213
Remove debugging code
jasontedor bdfb2bc
Add a getter
jasontedor ad66152
Merge branch 'master' into retention-lease-stats
jasontedor e219371
Add tests
jasontedor 2429d7e
Rename field in output
jasontedor a06b86f
Missing newline
jasontedor 347d38b
Another missing newline
jasontedor 3635ee1
Fix imports
jasontedor 517d111
Tighter assertion
jasontedor 5c1c3d4
Use test infrastructure
jasontedor a948a95
Use single-node test case
jasontedor b064e7e
Fix imports
jasontedor 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
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
102 changes: 102 additions & 0 deletions
102
server/src/main/java/org/elasticsearch/index/seqno/RetentionLeaseStats.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,102 @@ | ||
/* | ||
* 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.index.seqno; | ||
|
||
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; | ||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents retention lease stats. | ||
*/ | ||
public class RetentionLeaseStats implements ToXContentFragment, Writeable { | ||
|
||
private final Collection<RetentionLease> leases; | ||
|
||
/** | ||
* Constructs a new retention lease stats object from the specified leases. | ||
* | ||
* @param leases the leases | ||
*/ | ||
public RetentionLeaseStats(final Collection<RetentionLease> leases) { | ||
this.leases = Objects.requireNonNull(leases); | ||
} | ||
|
||
/** | ||
* Constructs a new retention lease stats object from a stream. The retention lease stats should have been written via | ||
* {@link #writeTo(StreamOutput)}. | ||
* | ||
* @param in the stream to construct the retention lease stats from | ||
* @throws IOException if an I/O exception occurs reading from the stream | ||
*/ | ||
public RetentionLeaseStats(final StreamInput in) throws IOException { | ||
leases = in.readList(RetentionLease::new); | ||
} | ||
|
||
/** | ||
* Writes a retention lease stats object to a stream in a manner suitable for later reconstruction via | ||
* {@link #RetentionLeaseStats(StreamInput)} (StreamInput)}. | ||
* | ||
* @param out the stream to write the retention lease stats to | ||
* @throws IOException if an I/O exception occurs writing to the stream | ||
*/ | ||
@Override | ||
public void writeTo(final StreamOutput out) throws IOException { | ||
out.writeCollection(leases); | ||
} | ||
|
||
/** | ||
* Converts the retention lease stats to {@link org.elasticsearch.common.xcontent.XContent} using the specified builder and pararms. | ||
* | ||
* @param builder the builder | ||
* @param params the params | ||
* @return the builder that these retention leases were converted to {@link org.elasticsearch.common.xcontent.XContent} into | ||
* @throws IOException if an I/O exception occurs writing to the builder | ||
*/ | ||
@Override | ||
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { | ||
builder.startObject("retention_leases"); | ||
{ | ||
builder.startArray("leases"); | ||
{ | ||
for (final RetentionLease retentionLease : leases) { | ||
builder.startObject(); | ||
{ | ||
builder.field("id", retentionLease.id()); | ||
builder.field("retaining_sequence_number", retentionLease.retainingSequenceNumber()); | ||
jasontedor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
builder.field("timestamp", retentionLease.timestamp()); | ||
builder.field("source", retentionLease.source()); | ||
} | ||
builder.endObject(); | ||
} | ||
} | ||
builder.endArray(); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
} |
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
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
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
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.