diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 4b53ee25e0c..b2d58203954 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -61,7 +61,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; /** @@ -196,15 +195,16 @@ public class TransportBulkAction extends HandledTransportAction listener) { - final long startTimeNanos = System.nanoTime(); - executeBulk(bulkRequest, startTimeNanos, listener, new AtomicArray<>(bulkRequest.requests.size())); + final long startTime = System.currentTimeMillis(); + executeBulk(bulkRequest, startTime, listener, new AtomicArray<>(bulkRequest.requests.size())); } - private long buildTookInMillis(long startTimeNanos) { - return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeNanos); + private long buildTookInMillis(long startTime) { + // protect ourselves against time going backwards + return Math.max(1, System.currentTimeMillis() - startTime); } - private void executeBulk(final BulkRequest bulkRequest, final long startTimeNanos, final ActionListener listener, final AtomicArray responses ) { + private void executeBulk(final BulkRequest bulkRequest, final long startTime, final ActionListener listener, final AtomicArray responses ) { final ClusterState clusterState = clusterService.state(); // TODO use timeout to wait here if its blocked... clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.WRITE); @@ -302,7 +302,7 @@ public class TransportBulkAction extends HandledTransportAction