Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows native method to retrieve the number of allocated bytes on disk for file #79698

Merged
merged 24 commits into from
Nov 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.randomPopulateAndReads;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
Expand Down Expand Up @@ -411,7 +412,16 @@ public void testCacheFileCreatedAsSparseFile() throws Exception {
fill(cacheFile.getChannel(), Math.toIntExact(cacheFile.getLength() - 1L), Math.toIntExact(cacheFile.getLength()));

sizeOnDisk = Natives.allocatedSizeInBytes(file);
assertThat("Cache file should be sparse and not fully allocated on disk", sizeOnDisk, not(equalTo(1048576L)));
assertThat("Cache file should be sparse and not fully allocated on disk", sizeOnDisk, lessThan(1048576L));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference for extracting the 1048576L as a constant (it appears in 3 places now and anyway I don't immediately recognise that this is a nice power of two).


fill(cacheFile.getChannel(), 0, Math.toIntExact(cacheFile.getLength()));

sizeOnDisk = Natives.allocatedSizeInBytes(file);
assertThat(
"Cache file should be fully allocated on disk (maybe more given cluster/block size)",
sizeOnDisk,
greaterThanOrEqualTo(1048576L)
);
} finally {
cacheFile.release(listener);
}
Expand Down