Skip to content

Commit 6ac5a6e

Browse files
committed
move creation time up
1 parent 71ff57a commit 6ac5a6e

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ public Collection<Object> createComponents(
347347
final BlobStoreCacheService blobStoreCacheService = new BlobStoreCacheService(
348348
clusterService,
349349
client,
350-
SNAPSHOT_BLOB_CACHE_INDEX,
351-
threadPool::absoluteTimeInMillis
350+
SNAPSHOT_BLOB_CACHE_INDEX
352351
);
353352
this.blobStoreCacheService.set(blobStoreCacheService);
354353
clusterService.addListener(

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import java.util.concurrent.Semaphore;
5050
import java.util.concurrent.TimeUnit;
5151
import java.util.concurrent.atomic.AtomicBoolean;
52-
import java.util.function.Supplier;
5352

5453
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
5554
import static org.elasticsearch.xpack.core.ClientHelper.SEARCHABLE_SNAPSHOTS_ORIGIN;
@@ -72,17 +71,15 @@ public class BlobStoreCacheService extends AbstractLifecycleComponent {
7271

7372
private final ClusterService clusterService;
7473
private final Semaphore inFlightCacheFills;
75-
private final Supplier<Long> timeSupplier;
7674
private final AtomicBoolean closed;
7775
private final Client client;
7876
private final String index;
7977

80-
public BlobStoreCacheService(ClusterService clusterService, Client client, String index, Supplier<Long> timeSupplier) {
78+
public BlobStoreCacheService(ClusterService clusterService, Client client, String index) {
8179
this.client = new OriginSettingClient(client, SEARCHABLE_SNAPSHOTS_ORIGIN);
8280
this.inFlightCacheFills = new Semaphore(MAX_IN_FLIGHT_CACHE_FILLS);
8381
this.closed = new AtomicBoolean(false);
8482
this.clusterService = clusterService;
85-
this.timeSupplier = timeSupplier;
8683
this.index = index;
8784
}
8885

@@ -242,12 +239,13 @@ public final void putAsync(
242239
final String name,
243240
final ByteRange range,
244241
final BytesReference bytes,
242+
final long timeInEpochMillis,
245243
final ActionListener<Void> listener
246244
) {
247245
final String id = generateId(repository, snapshotId, indexId, shardId, name, range);
248246
try {
249247
final CachedBlob cachedBlob = new CachedBlob(
250-
Instant.ofEpochMilli(timeSupplier.get()),
248+
Instant.ofEpochMilli(timeInEpochMillis),
251249
Version.CURRENT,
252250
repository,
253251
name,

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,17 @@ public CachedBlob getCachedBlob(String name, ByteRange range) {
704704
}
705705

706706
public void putCachedBlob(String name, ByteRange range, BytesReference content, ActionListener<Void> listener) {
707-
blobStoreCacheService.putAsync(repository, snapshotId, indexId, shardId, name, range, content, listener);
707+
blobStoreCacheService.putAsync(
708+
repository,
709+
snapshotId,
710+
indexId,
711+
shardId,
712+
name,
713+
range,
714+
content,
715+
threadPool.absoluteTimeInMillis(),
716+
listener
717+
);
708718
}
709719

710720
public FrozenCacheFile getFrozenCacheFile(String fileName, long length) {

x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheServiceTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void testGetWhenServiceNotStarted() {
100100
return null;
101101
}).when(mockClient).execute(eq(GetAction.INSTANCE), any(GetRequest.class), any(ActionListener.class));
102102

103-
BlobStoreCacheService blobCacheService = new BlobStoreCacheService(null, mockClient, SNAPSHOT_BLOB_CACHE_INDEX, () -> 0L);
103+
BlobStoreCacheService blobCacheService = new BlobStoreCacheService(null, mockClient, SNAPSHOT_BLOB_CACHE_INDEX);
104104
blobCacheService.start();
105105

106106
PlainActionFuture<CachedBlob> future = PlainActionFuture.newFuture();
@@ -132,17 +132,17 @@ public void testPutWhenServiceNotStarted() {
132132
return null;
133133
}).when(mockClient).execute(eq(IndexAction.INSTANCE), any(IndexRequest.class), any(ActionListener.class));
134134

135-
BlobStoreCacheService blobCacheService = new BlobStoreCacheService(null, mockClient, SNAPSHOT_BLOB_CACHE_INDEX, () -> 0L);
135+
BlobStoreCacheService blobCacheService = new BlobStoreCacheService(null, mockClient, SNAPSHOT_BLOB_CACHE_INDEX);
136136
blobCacheService.start();
137137

138138
PlainActionFuture<Void> future = PlainActionFuture.newFuture();
139-
blobCacheService.putAsync(repository, snapshotId, indexId, shardId, fileName, range, BytesArray.EMPTY, future);
139+
blobCacheService.putAsync(repository, snapshotId, indexId, shardId, fileName, range, BytesArray.EMPTY, 0L, future);
140140
assertThat(future.actionGet(), nullValue());
141141

142142
blobCacheService.stop();
143143

144144
future = PlainActionFuture.newFuture();
145-
blobCacheService.putAsync(repository, snapshotId, indexId, shardId, fileName, range, BytesArray.EMPTY, future);
145+
blobCacheService.putAsync(repository, snapshotId, indexId, shardId, fileName, range, BytesArray.EMPTY, 0L, future);
146146
IllegalStateException exception = expectThrows(IllegalStateException.class, future::actionGet);
147147
assertThat(exception.getMessage(), containsString("Blob cache service is closed"));
148148
}
@@ -170,7 +170,7 @@ public void testWaitForInFlightCacheFillsToComplete() throws Exception {
170170
return null;
171171
}).when(mockClient).execute(eq(IndexAction.INSTANCE), any(IndexRequest.class), any(ActionListener.class));
172172

173-
final BlobStoreCacheService blobCacheService = new BlobStoreCacheService(null, mockClient, SNAPSHOT_BLOB_CACHE_INDEX, () -> 0L);
173+
final BlobStoreCacheService blobCacheService = new BlobStoreCacheService(null, mockClient, SNAPSHOT_BLOB_CACHE_INDEX);
174174
blobCacheService.start();
175175

176176
assertThat(blobCacheService.getInFlightCacheFills(), equalTo(0));
@@ -180,7 +180,7 @@ public void testWaitForInFlightCacheFillsToComplete() throws Exception {
180180
final PlainActionFuture<Void> future = PlainActionFuture.newFuture();
181181
threadPool.generic()
182182
.execute(
183-
() -> blobCacheService.putAsync(repository, snapshotId, indexId, shardId, fileName, range, BytesArray.EMPTY, future)
183+
() -> blobCacheService.putAsync(repository, snapshotId, indexId, shardId, fileName, range, BytesArray.EMPTY, 0L, future)
184184
);
185185
futures.add(future);
186186
}

x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/TestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private UnsupportedOperationException unsupportedException() {
316316
public static class NoopBlobStoreCacheService extends BlobStoreCacheService {
317317

318318
public NoopBlobStoreCacheService() {
319-
super(null, mock(Client.class), SNAPSHOT_BLOB_CACHE_INDEX, () -> 0L);
319+
super(null, mock(Client.class), SNAPSHOT_BLOB_CACHE_INDEX);
320320
}
321321

322322
@Override
@@ -345,7 +345,7 @@ public static class SimpleBlobStoreCacheService extends BlobStoreCacheService {
345345
private final ConcurrentHashMap<String, BytesArray> blobs = new ConcurrentHashMap<>();
346346

347347
public SimpleBlobStoreCacheService() {
348-
super(null, mock(Client.class), SNAPSHOT_BLOB_CACHE_INDEX, System::currentTimeMillis);
348+
super(null, mock(Client.class), SNAPSHOT_BLOB_CACHE_INDEX);
349349
}
350350

351351
@Override

0 commit comments

Comments
 (0)