From 220359916d7d5ad5cb28428a8fe0996e5b19d372 Mon Sep 17 00:00:00 2001 From: Lingfeng Zhang Date: Mon, 18 Nov 2024 20:01:33 +0800 Subject: [PATCH] update --- cpp/core/shuffle/Utils.cc | 6 +----- cpp/core/shuffle/Utils.h | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cpp/core/shuffle/Utils.cc b/cpp/core/shuffle/Utils.cc index 8965288beeeda..157c100a1f6f8 100644 --- a/cpp/core/shuffle/Utils.cc +++ b/cpp/core/shuffle/Utils.cc @@ -227,11 +227,7 @@ arrow::Result> MmapFileStream::open(const std::s return arrow::Status::IOError("Memory mapping file failed: ", ::arrow::internal::ErrnoMessage(errno)); } - auto fstream = std::shared_ptr(new MmapFileStream()); - fstream->fd_ = std::move(fd); - fstream->data_ = static_cast(result); - fstream->size_ = size; - return fstream; + return std::make_shared(std::move(fd), static_cast(result), size); } void MmapFileStream::advance(int64_t length) { diff --git a/cpp/core/shuffle/Utils.h b/cpp/core/shuffle/Utils.h index 5d6f07707a733..41b0d5160445e 100644 --- a/cpp/core/shuffle/Utils.h +++ b/cpp/core/shuffle/Utils.h @@ -72,8 +72,12 @@ arrow::Result> makeUncompressedRecordBatch( std::shared_ptr zeroLengthNullBuffer(); +// MmapFileStream is used to optimize sequential file reading. It uses madvise +// to prefetch and release memory timely. class MmapFileStream : public arrow::io::InputStream { public: + MmapFileStream(arrow::internal::FileDescriptor fd, uint8_t* data, int64_t size) + : fd_(std::move(fd)), data_(data), size_(size){}; static arrow::Result> open(const std::string& path); arrow::Result Tell() const override; arrow::Status Close() override; @@ -99,7 +103,6 @@ class MmapFileStream : public arrow::io::InputStream { int64_t size_; int64_t pos_ = 0; int64_t posRetain_ = 0; - MmapFileStream() = default; }; } // namespace gluten