Skip to content

Commit bd59ee6

Browse files
committed
Fix clock used in update requests (#45262)
We accidentally switched to using the relative time provider here. This commit fixes this by switching to the appropriate absolute clock.
1 parent 9318192 commit bd59ee6

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

modules/lang-painless/src/test/resources/rest-api-spec/test/painless/25_script_upsert.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,22 @@
7474
id: 3
7575

7676
- match: { _source.has_now: true }
77+
78+
- do:
79+
update:
80+
index: test_1
81+
id: 4
82+
body:
83+
script:
84+
# assume _now is an absolute clock if it's in the range [now - 1m, now]; this tolerance might need adjustment after CI cycles
85+
source: "long now = System.currentTimeMillis();ctx._source.within_one_minute = ctx._now <= now && ctx._now >= now - 1000 * 60 * 1"
86+
lang: "painless"
87+
upsert: { within_one_minute: false }
88+
scripted_upsert: true
89+
90+
- do:
91+
get:
92+
index: test_1
93+
id: 4
94+
95+
- match: { _source.within_one_minute: true }

server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected boolean resolveIndex() {
115115
protected void shardOperationOnPrimary(BulkShardRequest request, IndexShard primary,
116116
ActionListener<PrimaryResult<BulkShardRequest, BulkShardResponse>> listener) {
117117
ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
118-
performOnPrimary(request, primary, updateHelper, threadPool::relativeTimeInMillis,
118+
performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis,
119119
(update, shardId, type, mappingListener) -> {
120120
assert update != null;
121121
assert shardId != null;

server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void testExecuteBulkIndexRequestWithErrorWhileUpdatingMapping() throws Ex
348348
BulkPrimaryExecutionContext context = new BulkPrimaryExecutionContext(bulkShardRequest, shard);
349349
final CountDownLatch latch = new CountDownLatch(1);
350350
TransportShardBulkAction.executeBulkItemRequest(
351-
context, null, threadPool::relativeTimeInMillis,
351+
context, null, threadPool::absoluteTimeInMillis,
352352
errorOnWait == false ? new ThrowingMappingUpdatePerformer(err) : new NoopMappingUpdatePerformer(),
353353
errorOnWait ? listener -> listener.onFailure(err) : listener -> listener.onResponse(null),
354354
new LatchedActionListener<>(new ActionListener<Void>() {

0 commit comments

Comments
 (0)