forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task cancellation monitoring service (opensearch-project#7642)
* Task cancellation monitoring service Signed-off-by: Sagar Upadhyaya <[email protected]> Signed-off-by: Rishab Nahata <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,016 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
75 changes: 75 additions & 0 deletions
75
server/src/main/java/org/opensearch/tasks/SearchShardTaskCancellationStats.java
This file contains 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,75 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.tasks; | ||
|
||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Holds monitoring service stats specific to search shard task. | ||
*/ | ||
public class SearchShardTaskCancellationStats implements ToXContentObject, Writeable { | ||
|
||
private final long currentLongRunningCancelledTaskCount; | ||
private final long totalLongRunningCancelledTaskCount; | ||
|
||
public SearchShardTaskCancellationStats(long currentTaskCount, long totalTaskCount) { | ||
this.currentLongRunningCancelledTaskCount = currentTaskCount; | ||
this.totalLongRunningCancelledTaskCount = totalTaskCount; | ||
} | ||
|
||
public SearchShardTaskCancellationStats(StreamInput in) throws IOException { | ||
this.currentLongRunningCancelledTaskCount = in.readVLong(); | ||
this.totalLongRunningCancelledTaskCount = in.readVLong(); | ||
} | ||
|
||
// package private for testing | ||
protected long getCurrentLongRunningCancelledTaskCount() { | ||
return this.currentLongRunningCancelledTaskCount; | ||
} | ||
|
||
// package private for testing | ||
protected long getTotalLongRunningCancelledTaskCount() { | ||
return this.totalLongRunningCancelledTaskCount; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("current_count_post_cancel", currentLongRunningCancelledTaskCount); | ||
builder.field("total_count_post_cancel", totalLongRunningCancelledTaskCount); | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVLong(currentLongRunningCancelledTaskCount); | ||
out.writeVLong(totalLongRunningCancelledTaskCount); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
SearchShardTaskCancellationStats that = (SearchShardTaskCancellationStats) o; | ||
return currentLongRunningCancelledTaskCount == that.currentLongRunningCancelledTaskCount | ||
&& totalLongRunningCancelledTaskCount == that.totalLongRunningCancelledTaskCount; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(currentLongRunningCancelledTaskCount, totalLongRunningCancelledTaskCount); | ||
} | ||
} |
Oops, something went wrong.