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.
fetching term information from master using light-weight call before …
…fetch of cluster-state
- Loading branch information
Showing
10 changed files
with
548 additions
and
42 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
31 changes: 31 additions & 0 deletions
31
...er/src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionAction.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,31 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.action.admin.cluster.state.term; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
/** | ||
* Transport action for fetching cluster term | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetTermVersionAction extends ActionType<GetTermVersionResponse> { | ||
|
||
public static final GetTermVersionAction INSTANCE = new GetTermVersionAction(); | ||
public static final String NAME = "cluster:monitor/term"; | ||
|
||
private GetTermVersionAction() { | ||
super(NAME, GetTermVersionResponse::new); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...r/src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionRequest.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,58 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.action.admin.cluster.state.term; | ||
|
||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.action.support.clustermanager.ClusterManagerNodeReadRequest; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Request object to get cluster term | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetTermVersionRequest extends ClusterManagerNodeReadRequest<GetTermVersionRequest> { | ||
|
||
public GetTermVersionRequest() {} | ||
|
||
public GetTermVersionRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionResponse.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,77 @@ | ||
/* | ||
* 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.action.admin.cluster.state.term; | ||
|
||
import org.opensearch.cluster.ClusterName; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Response object of cluster term | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetTermVersionResponse extends ActionResponse { | ||
|
||
private final ClusterName clusterName; | ||
private final String stateUUID; | ||
private final long term; | ||
private final long version; | ||
|
||
public GetTermVersionResponse(ClusterName clusterName, String stateUUID, long term, long version) { | ||
this.clusterName = clusterName; | ||
this.stateUUID = stateUUID; | ||
this.term = term; | ||
this.version = version; | ||
} | ||
|
||
public GetTermVersionResponse(StreamInput in) throws IOException { | ||
super(in); | ||
this.clusterName = new ClusterName(in); | ||
this.stateUUID = in.readString(); | ||
this.term = in.readLong(); | ||
this.version = in.readLong(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
clusterName.writeTo(out); | ||
out.writeString(stateUUID); | ||
out.writeLong(term); | ||
out.writeLong(version); | ||
} | ||
|
||
public long getTerm() { | ||
return term; | ||
} | ||
|
||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
public ClusterName getClusterName() { | ||
return clusterName; | ||
} | ||
|
||
public String getStateUUID() { | ||
return stateUUID; | ||
} | ||
|
||
public boolean matches(ClusterState clusterState) { | ||
return clusterName.equals(clusterState.getClusterName()) | ||
&& stateUUID.equals(clusterState.stateUUID()) | ||
&& term == clusterState.term() | ||
&& version == clusterState.version(); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...in/java/org/opensearch/action/admin/cluster/state/term/TransportGetTermVersionAction.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,90 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.action.admin.cluster.state.term; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.block.ClusterBlockException; | ||
import org.opensearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Transport action for obtaining cluster term and version from cluster-manager | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class TransportGetTermVersionAction extends TransportClusterManagerNodeReadAction<GetTermVersionRequest, GetTermVersionResponse> { | ||
|
||
private final Logger logger = LogManager.getLogger(getClass()); | ||
|
||
@Inject | ||
public TransportGetTermVersionAction( | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver | ||
) { | ||
super( | ||
GetTermVersionAction.NAME, | ||
false, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
GetTermVersionRequest::new, | ||
indexNameExpressionResolver | ||
); | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return ThreadPool.Names.SAME; | ||
} | ||
|
||
@Override | ||
public GetTermVersionResponse read(StreamInput in) throws IOException { | ||
return new GetTermVersionResponse(in); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(GetTermVersionRequest request, ClusterState state) { | ||
// cluster state term and version needs to be retrieved even on a fully blocked cluster | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void clusterManagerOperation( | ||
GetTermVersionRequest request, | ||
ClusterState state, | ||
ActionListener<GetTermVersionResponse> listener | ||
) throws Exception { | ||
ActionListener.completeWith(listener, () -> buildResponse(request, state)); | ||
} | ||
|
||
private GetTermVersionResponse buildResponse(GetTermVersionRequest request, ClusterState state) { | ||
logger.trace("Serving cluster term version request using term {} and version {}", state.term(), state.version()); | ||
return new GetTermVersionResponse(state.getClusterName(), state.stateUUID(), state.term(), state.getVersion()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/org/opensearch/action/admin/cluster/state/term/package-info.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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** Cluster Term transport handler. */ | ||
package org.opensearch.action.admin.cluster.state.term; |
Oops, something went wrong.