Skip to content

Commit 9d1b2a5

Browse files
authored
Reduce Searchable Snapshots IndexInput resource descriptions (#68968)
We noticed that the resource descriptions of the IndexInput used for Searchable Snapshots can grow pretty large. This is due to the fact that resource descriptions tend to aggregate all kind of information, maybe more than really useful, and also that description of slices are based on the toString() computation rather than just picking up the parent's index input description. This pull request reduces the length of the description at various places.
1 parent 96b8a24 commit 9d1b2a5

File tree

7 files changed

+41
-48
lines changed

7 files changed

+41
-48
lines changed

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/BaseSearchableSnapshotIndexInput.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ public BaseSearchableSnapshotIndexInput clone() {
205205
return clone;
206206
}
207207

208+
@Override
209+
public String toString() {
210+
return super.toString() + "[length=" + length() + ", file pointer=" + getFilePointer() + ", offset=" + offset + ']';
211+
}
212+
213+
@Override
214+
protected String getFullSliceDescription(String sliceDescription) {
215+
final String resourceDesc = super.toString();
216+
if (sliceDescription != null) {
217+
return "slice(" + sliceDescription + ") of " + resourceDesc;
218+
}
219+
return resourceDesc;
220+
}
221+
208222
protected void ensureOpen() throws IOException {
209223
if (closed.get()) {
210224
throw new IOException(toString() + " is closed");

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/InMemoryNoOpCommitDirectory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,8 @@ private boolean notOverwritingRealSegmentsFile(String name) throws IOException {
131131
return name.startsWith("segments_") == false || Arrays.stream(realDirectory.listAll()).noneMatch(s -> s.equals(name));
132132
}
133133

134+
@Override
135+
public String toString() {
136+
return "InMemoryNoOpCommitDirectory(" + "real=" + realDirectory + ", delegate=" + in + '}';
137+
}
134138
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public boolean isRecoveryFinalized() {
457457

458458
@Override
459459
public String toString() {
460-
return this.getClass().getSimpleName() + "@snapshotId=" + snapshotId + " lockFactory=" + lockFactory + " shard=" + shardId;
460+
return this.getClass().getSimpleName() + "(snapshotId=" + snapshotId + ", indexId=" + indexId + " shardId=" + shardId + ')';
461461
}
462462

463463
private void cleanExistingRegularShardFiles() {

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/CachedBlobContainerIndexInput.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,20 @@ public IndexInput slice(String sliceDescription, long offset, long length) {
608608

609609
@Override
610610
public String toString() {
611-
return "CachedBlobContainerIndexInput{"
612-
+ "cacheFileReference="
613-
+ cacheFileReference
614-
+ ", offset="
615-
+ offset
616-
+ ", length="
617-
+ length()
618-
+ ", position="
619-
+ getFilePointer()
620-
+ ", rangeSize="
621-
+ getDefaultRangeSize()
622-
+ ", directory="
623-
+ directory
624-
+ '}';
611+
final CacheFile cacheFile = cacheFileReference.cacheFile.get();
612+
return super.toString()
613+
+ "[cache file="
614+
+ (cacheFile != null
615+
? String.join(
616+
"/",
617+
directory.getShardId().getIndex().getUUID(),
618+
String.valueOf(directory.getShardId().getId()),
619+
"snapshot_cache",
620+
directory.getSnapshotId().getUUID(),
621+
cacheFile.getFile().getFileName().toString()
622+
)
623+
: null)
624+
+ ']';
625625
}
626626

627627
private static class CacheFileReference implements CacheFile.EvictionListener {

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/FrozenIndexInput.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -648,24 +648,6 @@ public IndexInput slice(String sliceDescription, long offset, long length) {
648648
return slice;
649649
}
650650

651-
@Override
652-
public String toString() {
653-
return "CachedBlobContainerIndexInput{"
654-
+ "sharedCacheFile="
655-
+ frozenCacheFile
656-
+ ", offset="
657-
+ offset
658-
+ ", length="
659-
+ length()
660-
+ ", position="
661-
+ getFilePointer()
662-
+ ", rangeSize="
663-
+ getDefaultRangeSize()
664-
+ ", directory="
665-
+ directory
666-
+ '}';
667-
}
668-
669651
private static boolean assertCurrentThreadMayWriteCacheFile() {
670652
final String threadName = Thread.currentThread().getName();
671653
assert isCacheFetchAsyncThread(threadName) : "expected the current thread ["

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/direct/DirectBlobContainerIndexInput.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public DirectBlobContainerIndexInput clone() {
291291
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
292292
if ((offset >= 0L) && (length >= 0L) && (offset + length <= length())) {
293293
final DirectBlobContainerIndexInput slice = new DirectBlobContainerIndexInput(
294-
sliceDescription,
294+
getFullSliceDescription(sliceDescription),
295295
blobContainer,
296296
fileInfo,
297297
context,
@@ -330,18 +330,7 @@ public void doClose() throws IOException {
330330

331331
@Override
332332
public String toString() {
333-
return "DirectBlobContainerIndexInput{"
334-
+ "resourceDesc="
335-
+ super.toString()
336-
+ ", fileInfo="
337-
+ fileInfo
338-
+ ", offset="
339-
+ offset
340-
+ ", length="
341-
+ length()
342-
+ ", position="
343-
+ position
344-
+ '}';
333+
return super.toString() + "[read seq=" + (streamForSequentialReads != null ? "yes" : "no") + ']';
345334
}
346335

347336
private InputStream openBlobStream(int part, long pos, long length) throws IOException {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,15 @@ public class FrozenCacheFile {
698698
private final CacheKey cacheKey;
699699
private final long length;
700700

701-
public FrozenCacheFile(CacheKey cacheKey, long length) {
701+
private FrozenCacheFile(CacheKey cacheKey, long length) {
702702
this.cacheKey = cacheKey;
703703
this.length = length;
704704
}
705705

706+
public long getLength() {
707+
return length;
708+
}
709+
706710
public StepListener<Integer> populateAndRead(
707711
final ByteRange rangeToWrite,
708712
final ByteRange rangeToRead,
@@ -781,7 +785,7 @@ public StepListener<Integer> readIfAvailableOrPending(final ByteRange rangeToRea
781785

782786
@Override
783787
public String toString() {
784-
return "SharedCacheFile{" + "cacheKey=" + cacheKey + ", length=" + length + '}';
788+
return "FrozenCacheFile{" + "cacheKey=" + cacheKey + ", length=" + length + '}';
785789
}
786790
}
787791

0 commit comments

Comments
 (0)