Skip to content

Commit

Permalink
Fix numOpenOutputs and modCount in ByteSizeCachingDirectory (#92440) (#…
Browse files Browse the repository at this point in the history
…92466)

Co-authored-by: loupipalien <loupipalien@gmail.com>
  • Loading branch information
pxsalehi and loupipalien committed Dec 20, 2022
1 parent b9f901d commit bf5e313
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/92440.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 92440
summary: Fix numOpenOutputs and modCount in ByteSizeCachingDirectory
area: Store
type: bug
issues:
- 92434
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private IndexOutput wrapIndexOutput(IndexOutput out) {
numOpenOutputs++;
}
return new FilterIndexOutput(out.toString(), out) {
private boolean closed;

@Override
public void writeBytes(byte[] b, int length) throws IOException {
// Don't write to atomicXXX here since it might be called in
Expand Down Expand Up @@ -168,8 +170,11 @@ public void close() throws IOException {
super.close();
} finally {
synchronized (ByteSizeCachingDirectory.this) {
numOpenOutputs--;
modCount++;
if (closed == false) {
closed = true;
numOpenOutputs--;
modCount++;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ public void testBasics() throws IOException {
assertEquals(18, countingDir.numFileLengthCalls);
assertEquals(15, cachingDir.estimateSizeInBytes());
assertEquals(18, countingDir.numFileLengthCalls);

// Close more than once
IndexOutput out = cachingDir.createOutput("foo", IOContext.DEFAULT);
try {
out.writeBytes(new byte[5], 5);

cachingDir.estimateSizeInBytes();
// +3 because there are 3 files
assertEquals(21, countingDir.numFileLengthCalls);
// An index output is open so no caching
cachingDir.estimateSizeInBytes();
assertEquals(24, countingDir.numFileLengthCalls);
} finally {
out.close();
assertEquals(20, cachingDir.estimateSizeInBytes());
assertEquals(27, countingDir.numFileLengthCalls);
}
out.close();
assertEquals(20, cachingDir.estimateSizeInBytes());
assertEquals(27, countingDir.numFileLengthCalls);
}
}

Expand Down

0 comments on commit bf5e313

Please sign in to comment.