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

GH-38011: [C++][Dataset] Change force close to tend to close on write #38030

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
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
11 changes: 7 additions & 4 deletions cpp/src/arrow/dataset/dataset_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class DatasetWriterFileQueue {
: options_(options), schema_(schema), writer_state_(writer_state) {}

void Start(util::AsyncTaskScheduler* file_tasks, const std::string& filename) {
file_tasks_ = std::move(file_tasks);
file_tasks_ = file_tasks;
// Because the scheduler runs one task at a time we know the writer will
// be opened before any attempt to write
file_tasks_->AddSimpleTask(
Expand Down Expand Up @@ -575,7 +575,7 @@ class DatasetWriter::DatasetWriterImpl {
}

protected:
Status CloseLargestFile() {
Status TryCloseLargestFile() {
std::shared_ptr<DatasetWriterDirectoryQueue> largest = nullptr;
uint64_t largest_num_rows = 0;
for (auto& dir_queue : directory_queues_) {
Expand All @@ -584,7 +584,10 @@ class DatasetWriter::DatasetWriterImpl {
largest = dir_queue.second;
}
}
DCHECK_NE(largest, nullptr);
if (largest == nullptr) {
// GH-38011: If all written files has written 0 rows, we should not close any file
return Status::OK();
}
return largest->FinishCurrentFile();
}

Expand Down Expand Up @@ -618,7 +621,7 @@ class DatasetWriter::DatasetWriterImpl {
backpressure = writer_state_.open_files_throttle.Acquire(1);
if (!backpressure.is_finished()) {
EVENT_ON_CURRENT_SPAN("DatasetWriter::Backpressure::TooManyOpenFiles");
RETURN_NOT_OK(CloseLargestFile());
RETURN_NOT_OK(TryCloseLargestFile());
break;
}
}
Expand Down
Loading