|
@@ -55,6 +55,7 @@ import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.function.LongSupplier;
|
|
|
import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -78,6 +79,7 @@ public class AllocationService {
|
|
|
private final ClusterInfoService clusterInfoService;
|
|
|
private final SnapshotsInfoService snapshotsInfoService;
|
|
|
private final ShardRoutingRoleStrategy shardRoutingRoleStrategy;
|
|
|
+ private final LongSupplier relativeTimeInNanoSupplier;
|
|
|
|
|
|
// only for tests that use the GatewayAllocator as the unique ExistingShardsAllocator
|
|
|
public AllocationService(
|
|
@@ -86,9 +88,17 @@ public class AllocationService {
|
|
|
ShardsAllocator shardsAllocator,
|
|
|
ClusterInfoService clusterInfoService,
|
|
|
SnapshotsInfoService snapshotsInfoService,
|
|
|
- ShardRoutingRoleStrategy shardRoutingRoleStrategy
|
|
|
+ ShardRoutingRoleStrategy shardRoutingRoleStrategy,
|
|
|
+ LongSupplier relativeTimeInNanoSupplier
|
|
|
) {
|
|
|
- this(allocationDeciders, shardsAllocator, clusterInfoService, snapshotsInfoService, shardRoutingRoleStrategy);
|
|
|
+ this(
|
|
|
+ allocationDeciders,
|
|
|
+ shardsAllocator,
|
|
|
+ clusterInfoService,
|
|
|
+ snapshotsInfoService,
|
|
|
+ shardRoutingRoleStrategy,
|
|
|
+ relativeTimeInNanoSupplier
|
|
|
+ );
|
|
|
setExistingShardsAllocators(Collections.singletonMap(GatewayAllocator.ALLOCATOR_NAME, gatewayAllocator));
|
|
|
}
|
|
|
|
|
@@ -97,13 +107,15 @@ public class AllocationService {
|
|
|
ShardsAllocator shardsAllocator,
|
|
|
ClusterInfoService clusterInfoService,
|
|
|
SnapshotsInfoService snapshotsInfoService,
|
|
|
- ShardRoutingRoleStrategy shardRoutingRoleStrategy
|
|
|
+ ShardRoutingRoleStrategy shardRoutingRoleStrategy,
|
|
|
+ LongSupplier relativeTimeInNanoSupplier
|
|
|
) {
|
|
|
this.allocationDeciders = allocationDeciders;
|
|
|
this.shardsAllocator = shardsAllocator;
|
|
|
this.clusterInfoService = clusterInfoService;
|
|
|
this.snapshotsInfoService = snapshotsInfoService;
|
|
|
this.shardRoutingRoleStrategy = shardRoutingRoleStrategy;
|
|
|
+ this.relativeTimeInNanoSupplier = relativeTimeInNanoSupplier;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -630,7 +642,7 @@ public class AllocationService {
|
|
|
|
|
|
/** override this to control time based decisions during allocation */
|
|
|
protected long currentNanoTime() {
|
|
|
- return System.nanoTime();
|
|
|
+ return relativeTimeInNanoSupplier.getAsLong();
|
|
|
}
|
|
|
|
|
|
public void cleanCaches() {
|