Browse Source

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.
Jason Tedor 6 years ago
parent
commit
5508aba42b

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

@@ -74,3 +74,22 @@
           id:     3
 
   - match:  { _source.has_now: true }
+
+  - do:
+      update:
+        index: test_1
+        id: 4
+        body:
+          script:
+            # assume _now is an absolute clock if it's in the range [now - 1m, now]; this tolerance might need adjustment after CI cycles
+            source: "long now = System.currentTimeMillis();ctx._source.within_one_minute = ctx._now <= now && ctx._now >= now - 1000 * 60 * 1"
+            lang: "painless"
+          upsert: { within_one_minute: false }
+          scripted_upsert: true
+
+  - do:
+      get:
+        index: test_1
+        id: 4
+
+  - match: { _source.within_one_minute: true }

+ 1 - 1
server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java

@@ -117,7 +117,7 @@ public class TransportShardBulkAction extends TransportWriteAction<BulkShardRequ
     protected void shardOperationOnPrimary(BulkShardRequest request, IndexShard primary,
             ActionListener<PrimaryResult<BulkShardRequest, BulkShardResponse>> listener) {
         ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
-        performOnPrimary(request, primary, updateHelper, threadPool::relativeTimeInMillis,
+        performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis,
             (update, shardId, type, mappingListener) -> {
                 assert update != null;
                 assert shardId != null;

+ 1 - 1
server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java

@@ -305,7 +305,7 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
         BulkPrimaryExecutionContext context = new BulkPrimaryExecutionContext(bulkShardRequest, shard);
         final CountDownLatch latch = new CountDownLatch(1);
         TransportShardBulkAction.executeBulkItemRequest(
-            context, null, threadPool::relativeTimeInMillis,
+            context, null, threadPool::absoluteTimeInMillis,
             errorOnWait == false ? new ThrowingMappingUpdatePerformer(err) : new NoopMappingUpdatePerformer(),
             errorOnWait ? listener -> listener.onFailure(err) : listener -> listener.onResponse(null),
             new LatchedActionListener<>(new ActionListener<Void>() {