Skip to content

Commit

Permalink
Fix reused/recovered bytes for files that are recovered from cache (#…
Browse files Browse the repository at this point in the history
…97278) (#97347)

Fix in #95987 wasn't complete, I did not restore all the previous behavior.

Closes #95994
  • Loading branch information
tlrx committed Jul 4, 2023
1 parent 0c0571a commit 5663098
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/97278.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 97278
summary: Fix reused/recovered bytes for files that are recovered from cache
area: Snapshot/Restore
type: bug
issues:
- 95994
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.LongSupplier;
import java.util.function.Supplier;

Expand Down Expand Up @@ -504,13 +503,9 @@ private void prewarmCache(ActionListener<Void> listener, Supplier<Boolean> cance
final IndexInput input = openInput(file.physicalName(), CachedBlobContainerIndexInput.CACHE_WARMING_CONTEXT);
assert input instanceof CachedBlobContainerIndexInput : "expected cached index input but got " + input.getClass();

final AtomicLong prefetchedBytes = new AtomicLong(0L);
final AtomicBoolean alreadyCached = new AtomicBoolean();
try (var fileListener = new RefCountingListener(ActionListener.runBefore(completionListener.acquire().map(v -> {
// we don't support files to be reported as partially recovered from disk and partially from the blob store, but
// this is something that can happen for fully mounted searchable snapshots. It is possible that prewarming
// prefetched nothing if a concurrent search was executing (and cached the data) or if the data were fetched from
// the blob cache system index.
if (prefetchedBytes.get() == 0L) {
if (alreadyCached.get()) {
recoveryState.markIndexFileAsReused(file.physicalName());
} else {
recoveryState.getIndex().addRecoveredFromSnapshotBytesToFile(file.physicalName(), file.length());
Expand All @@ -520,6 +515,7 @@ private void prewarmCache(ActionListener<Void> listener, Supplier<Boolean> cance

if (input instanceof CachedBlobContainerIndexInput cachedIndexInput) {
if (cachedIndexInput.getPersistentCacheInitialLength() == file.length()) {
alreadyCached.set(true);
logger.trace(
() -> format(
"%s file [%s] is already available in cache (%d bytes)",
Expand All @@ -540,7 +536,6 @@ private void prewarmCache(ActionListener<Void> listener, Supplier<Boolean> cance
final long startTimeInNanos = statsCurrentTimeNanosSupplier.getAsLong();
var prefetchedPartBytes = ((CachedBlobContainerIndexInput) input).prefetchPart(part, cancelPreWarming);
if (prefetchedPartBytes > -1L) {
prefetchedBytes.addAndGet(prefetchedPartBytes);
logger.trace(
() -> format(
"%s part [%s/%s] of [%s] warmed in [%s] ms (%d bytes)",
Expand All @@ -549,7 +544,7 @@ private void prewarmCache(ActionListener<Void> listener, Supplier<Boolean> cance
file.numberOfParts(),
fileName,
timeValueNanos(statsCurrentTimeNanosSupplier.getAsLong() - startTimeInNanos).millis(),
prefetchedBytes
prefetchedPartBytes
)
);
}
Expand Down

0 comments on commit 5663098

Please sign in to comment.