Skip to content

Commit

Permalink
Delegate VRS split file creation handling to WriteFileHandler
Browse files Browse the repository at this point in the history
Summary: Let the WriteFileHandler handle the creation of split file's file body, and avoid re-parsing the upload path as FileSpec.

Reviewed By: kiminoue7

Differential Revision: D50109311

fbshipit-source-id: 9afcba792fc60404b1a38866016f67af452aae1a
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Oct 10, 2023
1 parent 54aa2ea commit 583f258
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 1 addition & 6 deletions vrs/RecordFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,7 @@ int RecordFileWriter::createFile(const string& filePath, bool splitHead) {

if (splitHead) {
IF_ERROR_LOG_CLOSE_AND_RETURN(indexRecordWriter_.createSplitIndexRecord(lastRecordSize_))
// create the (first) user record chunk
if (spec.chunks.size() == 1) {
IF_ERROR_LOG_CLOSE_AND_RETURN(file_->create(spec.chunks.front() + "_1"))
} else {
IF_ERROR_LOG_CLOSE_AND_RETURN(file_->create(filePath))
}
IF_ERROR_LOG_CLOSE_AND_RETURN(file_->createSplitFile(spec, filePath));
} else if (preliminaryIndex_ && !preliminaryIndex_->empty()) {
// only use this preliminary index once
unique_ptr<deque<IndexRecord::DiskRecordInfo>> index = std::move(preliminaryIndex_);
Expand Down
13 changes: 13 additions & 0 deletions vrs/WriteFileHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ class WriteFileHandler : public FileHandler {
/// @return A status code, 0 meaning success.
virtual int create(const string& newFilePath) = 0;

/// Create a new file for writing, in split-head file mode, the body part.
/// @param spec: spec as converted already from initialFilePath, if that helps.
/// @param initialFilePath: path as given when the file creation was started.
/// @return A status code, 0 meaning success.
virtual int createSplitFile(const FileSpec& spec, const string& initialFilePath) {
// create the (first) user record chunk
if (spec.chunks.size() == 1) {
return create(spec.chunks.front() + "_1");
} else {
return create(initialFilePath);
}
}

/// Tell if modifying files is supported by this FileHandler implementation.
/// @return True if file modification and creation is supported.
virtual bool reopenForUpdatesSupported() const = 0;
Expand Down

0 comments on commit 583f258

Please sign in to comment.