From 174954f9973d707e15414f71223acbac2d6283e3 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 19 Oct 2021 09:49:42 +0200 Subject: [PATCH] assert + doc --- .../xpack/searchablesnapshots/cache/common/CacheFile.java | 5 +++-- .../searchablesnapshots/cache/common/CacheFileTests.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFile.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFile.java index 2d2a9ce4b26ba..3e6b719267f54 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFile.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFile.java @@ -127,8 +127,8 @@ protected void closeInternal() { private volatile FileChannelReference channelRef; /** - * Indicates if the file has already been created. - * This is useful to pass the right options when opening the file. + * Indicates if the file should be created when it is open for the first time. + * This is required to pass the right options for sparse file support. */ private volatile boolean created; @@ -145,6 +145,7 @@ private CacheFile(CacheKey cacheKey, SparseFileTracker tracker, Path file, Modif this.tracker = Objects.requireNonNull(tracker); this.file = Objects.requireNonNull(file); this.listener = Objects.requireNonNull(listener); + assert fileExists == Files.exists(file) : file + " exists? " + fileExists; this.created = fileExists; assert invariant(); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFileTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFileTests.java index eacfee06db39e..8ad1d21885f46 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFileTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/common/CacheFileTests.java @@ -58,6 +58,7 @@ public void onCacheFileDelete(CacheFile cacheFile) {} private static final CacheKey CACHE_KEY = new CacheKey("_snap_uuid", "_snap_index", new ShardId("_name", "_uuid", 0), "_filename"); public void testGetCacheKey() throws Exception { + final Path file = createTempDir().resolve("file.new"); final CacheKey cacheKey = new CacheKey( UUIDs.randomBase64UUID(random()), randomAlphaOfLength(5).toLowerCase(Locale.ROOT), @@ -65,7 +66,7 @@ public void testGetCacheKey() throws Exception { randomAlphaOfLength(105).toLowerCase(Locale.ROOT) ); - final CacheFile cacheFile = new CacheFile(cacheKey, randomLongBetween(1, 100), createTempFile(), NOOP); + final CacheFile cacheFile = new CacheFile(cacheKey, randomLongBetween(1, 100), file, NOOP); assertThat(cacheFile.getCacheKey(), sameInstance(cacheKey)); }