Skip to content

Commit 310610f

Browse files
Add option to control if the index record should be pre-allocated
Summary: By default, during filter-copy operations, when the output file is created locally, vrs pre-allocates space for the index record early in the file. While this usually makes the file more streaming-friendly if it's later uploaded to the cloud, in some situations, the index can be significantly smaller or bigger than anticipated, causing some file size "surprises". This is usually not a problem (the files are fine and the "surprises" are at most 10 to 20 MB large when dealing with large indexes), but it can create confusion, in particular when trying experimenting with data size. This new option gives control, so we can avoid this condition altogether. Note that these conditions never happen when a file is created in the cloud, because of how the index can be prepended to the file, at the end of the file's head. Differential Revision: D77634889 fbshipit-source-id: bec9ad38d4dcdc02ec26c08398a6895367c9e1b4
1 parent f1cf3d9 commit 310610f

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

vrs/utils/FilterCopy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int filterCopy(
9393
if (copyOptions.tagOverrider) {
9494
copyOptions.tagOverrider->overrideTags(writer);
9595
}
96-
if (throttledFileDelegate->shouldPreallocateIndex()) {
96+
if (copyOptions.preallocateIndex && throttledFileDelegate->shouldPreallocateIndex()) {
9797
writer.preallocateIndex(filteredReader.buildIndex());
9898
}
9999
int copyResult = throttledFileDelegate->createFile(pathToCopy);
@@ -276,7 +276,7 @@ int filterMerge(
276276
}
277277
sort(records.begin(), records.end());
278278

279-
if (throttledFileDelegate->shouldPreallocateIndex()) {
279+
if (copyOptions.preallocateIndex && throttledFileDelegate->shouldPreallocateIndex()) {
280280
// Build preliminary index
281281
auto preliminaryIndex = make_unique<deque<IndexRecord::DiskRecordInfo>>();
282282
deque<IndexRecord::DiskRecordInfo>& index = *preliminaryIndex;

vrs/utils/FilterCopyHelpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ struct CopyOptions {
7272
unique_ptr<TagOverrider> tagOverrider;
7373
// For merge operations only: tell if streams with the same RecordableTypeId should be merged.
7474
bool mergeStreams = false;
75+
// Control if the index record should be pre-allocated early in the file (good for streaming).
76+
bool preallocateIndex = true;
77+
7578
// Count the number of records copied. Set during the copy/merge operation.
7679
mutable uint32_t outRecordCopiedCount = 0;
7780
// Maybe: output URI if the destination's storage system decides where to write the file

vrs/utils/cli/CliParsing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ void printCopyOptionsHelp() {
110110
" [ --chunk-size <nb>[M|G] ]: chunk output file every <nb> number of MiB or GiB.\n"
111111
" Use 'M' for MiB (default), or 'G' for GiB.\n"
112112
" [ --compression={none|default|fast|tight|zfast|zlight|zmedium|ztight|zmax} ]:"
113-
" set compression setting.\n";
113+
" set compression setting.\n"
114+
" [ --late-index ]: write the index at the end of the file.\n";
114115
}
115116

116117
bool parseTagOverrideOptions(

0 commit comments

Comments
 (0)