Skip to content

Commit 174954f

Browse files
committed
assert + doc
1 parent 66b1e07 commit 174954f

File tree

2 files changed

+5
-3
lines changed
  • x-pack/plugin/searchable-snapshots/src
    • main/java/org/elasticsearch/xpack/searchablesnapshots/cache/common
    • test/java/org/elasticsearch/xpack/searchablesnapshots/cache/common

2 files changed

+5
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ protected void closeInternal() {
127127
private volatile FileChannelReference channelRef;
128128

129129
/**
130-
* Indicates if the file has already been created.
131-
* This is useful to pass the right options when opening the file.
130+
* Indicates if the file should be created when it is open for the first time.
131+
* This is required to pass the right options for sparse file support.
132132
*/
133133
private volatile boolean created;
134134

@@ -145,6 +145,7 @@ private CacheFile(CacheKey cacheKey, SparseFileTracker tracker, Path file, Modif
145145
this.tracker = Objects.requireNonNull(tracker);
146146
this.file = Objects.requireNonNull(file);
147147
this.listener = Objects.requireNonNull(listener);
148+
assert fileExists == Files.exists(file) : file + " exists? " + fileExists;
148149
this.created = fileExists;
149150
assert invariant();
150151
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ public void onCacheFileDelete(CacheFile cacheFile) {}
5858
private static final CacheKey CACHE_KEY = new CacheKey("_snap_uuid", "_snap_index", new ShardId("_name", "_uuid", 0), "_filename");
5959

6060
public void testGetCacheKey() throws Exception {
61+
final Path file = createTempDir().resolve("file.new");
6162
final CacheKey cacheKey = new CacheKey(
6263
UUIDs.randomBase64UUID(random()),
6364
randomAlphaOfLength(5).toLowerCase(Locale.ROOT),
6465
new ShardId(randomAlphaOfLength(5).toLowerCase(Locale.ROOT), UUIDs.randomBase64UUID(random()), randomInt(5)),
6566
randomAlphaOfLength(105).toLowerCase(Locale.ROOT)
6667
);
6768

68-
final CacheFile cacheFile = new CacheFile(cacheKey, randomLongBetween(1, 100), createTempFile(), NOOP);
69+
final CacheFile cacheFile = new CacheFile(cacheKey, randomLongBetween(1, 100), file, NOOP);
6970
assertThat(cacheFile.getCacheKey(), sameInstance(cacheKey));
7071
}
7172

0 commit comments

Comments
 (0)