Skip to content

Commit e49b593

Browse files
authored
Move TokenService to seqno powered cas (#38311)
Relates #37872 Relates #10708
1 parent ece8c65 commit e49b593

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ public SearchRequestBuilder setVersion(boolean version) {
225225
return this;
226226
}
227227

228+
/**
229+
* Should each {@link org.elasticsearch.search.SearchHit} be returned with the
230+
* sequence number and primary term of the last modification of the document.
231+
*/
232+
public SearchRequestBuilder seqNoAndPrimaryTerm(boolean seqNoAndPrimaryTerm) {
233+
sourceBuilder().seqNoAndPrimaryTerm(seqNoAndPrimaryTerm);
234+
return this;
235+
}
236+
228237
/**
229238
* Sets the boost a specific index will receive when the query is executed against it.
230239
*

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/TokenService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
3131
import org.elasticsearch.action.support.master.AcknowledgedRequest;
3232
import org.elasticsearch.action.update.UpdateRequest;
33+
import org.elasticsearch.action.update.UpdateRequestBuilder;
3334
import org.elasticsearch.action.update.UpdateResponse;
3435
import org.elasticsearch.client.Client;
3536
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
@@ -744,13 +745,17 @@ private void innerRefresh(String tokenDocId, Authentication userAuth, ActionList
744745
try (StreamInput in = StreamInput.wrap(Base64.getDecoder().decode(authString))) {
745746
in.setVersion(authVersion);
746747
Authentication authentication = new Authentication(in);
747-
UpdateRequest updateRequest =
748+
UpdateRequestBuilder updateRequest =
748749
client.prepareUpdate(SecurityIndexManager.SECURITY_INDEX_NAME, TYPE, tokenDocId)
749-
.setVersion(response.getVersion())
750750
.setDoc("refresh_token", Collections.singletonMap("refreshed", true))
751-
.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
752-
.request();
753-
executeAsyncWithOrigin(client.threadPool().getThreadContext(), SECURITY_ORIGIN, updateRequest,
751+
.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
752+
if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_6_7_0)) {
753+
updateRequest.setIfSeqNo(response.getSeqNo());
754+
updateRequest.setIfPrimaryTerm(response.getPrimaryTerm());
755+
} else {
756+
updateRequest.setVersion(response.getVersion());
757+
}
758+
executeAsyncWithOrigin(client.threadPool().getThreadContext(), SECURITY_ORIGIN, updateRequest.request(),
754759
ActionListener.<UpdateResponse>wrap(
755760
updateResponse -> createUserToken(authentication, userAuth, listener, metadata, true),
756761
e -> {

0 commit comments

Comments
 (0)