Skip to content

Commit

Permalink
Fix wrong Tell() result from BufferedOutputStream in an edge case (ap…
Browse files Browse the repository at this point in the history
…ache#73) (apache#74)

Co-authored-by: Hongze Zhang <[email protected]>
  • Loading branch information
zhouyuan and zhztheplayer authored Jan 9, 2022
1 parent b0044c5 commit 21698d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/src/arrow/io/buffered.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class BufferedOutputStream::Impl : public BufferedBase {
RETURN_NOT_OK(FlushUnlocked());
DCHECK_EQ(buffer_pos_, 0);
if (nbytes >= buffer_size_) {
// Invalidate cached raw pos
raw_pos_ = -1;
// Direct write
if (buffer) {
return raw_->Write(buffer);
Expand Down
13 changes: 13 additions & 0 deletions cpp/src/arrow/io/buffered_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ TEST_F(TestBufferedOutputStream, Tell) {
AssertTell(0);
}

TEST_F(TestBufferedOutputStream, Tell2) {
OpenBuffered();
AssertTell(0);

const std::string datastr = GenerateRandomData(10000);
const char* d = datastr.data();

ASSERT_OK(buffered_->Write(d, 5000));
AssertTell(5000);

ASSERT_OK(buffered_->Close());
}

TEST_F(TestBufferedOutputStream, TruncatesFile) {
OpenBuffered();

Expand Down

0 comments on commit 21698d7

Please sign in to comment.