Repository navigation
[c++] fail on incomplete binary file writes - #7348
Conversation
jameslamb
left a comment
There was a problem hiding this comment.
This looks like a great fix, thanks very much!!
It seems very likely that you used AI to write this... if you come back in the future to contribute here, please write PR titles and descriptions yourself. We're happy to talk to you, but not to talk to an LLM through you.
|
|
||
| data = rng.standard_normal(size=(1000, 20)) | ||
| ds = lgb.Dataset(data).construct() | ||
| original_limit = resource.getrlimit(resource.RLIMIT_FSIZE) |
There was a problem hiding this comment.
I could see this behavior being useful in other tests too, might be worth putting into a function-scoped fixture in the future, named like very_limited_disk or something. If that interests you and you agree, you're welcome to add that here.
Not required though, it could be a followup.
|
Thanks James, really appreciate the review. Yeah, the fixture idea makes sense. Since this one is already approved, I will leave it as a follow-up for now instead of adding more churn here. And fair point on the title / description. I will keep future PRs more direct and in my own voice. |
Fixes #7334.
What changed
Dataset.save_binary()now fails immediately if the local file writer writes fewer bytes than requested. Previously,LocalFile::Write()collapsed any shortfwrite()to0, but callers did not check the returned byte count, sosave_binary()could return successfully after producing a truncated binary file.This changes the local writer to report partial writes via
Log::Fatal, which also covers aligned writes used by dataset headers, metadata, and feature groups.Tests
cmake -B build -S . -DUSE_OPENMP=OFFcmake --build build --target _lightgbm -j4sh build-python.sh install --precompilepython -m pytest tests/python_package_test/test_basic.py::test_save_binary_raises_on_truncated_write tests/python_package_test/test_basic.py::test_save_dataset_subset_and_load_from_file -qpython -m py_compile tests/python_package_test/test_basic.pypython -m ruff check tests/python_package_test/test_basic.pypre-commit run --files src/io/file_io.cpp tests/python_package_test/test_basic.pygit diff --check