Skip to content

Replace std::shared_ptr<File> by std::unique_ptr<File> #1054

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions contrib/pax_storage/src/api/python3/paxfilereader_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int paxfilereader_init(PyObject *self, PyObject *args,
PyObject *schema = NULL, *proj = NULL, *pax_file = NULL;
PaxFileObject *pax_file_obj;
std::shared_ptr<pax::Bitmap8> visible_map_bm = nullptr;
std::shared_ptr<pax::File> toast_file = nullptr;
std::unique_ptr<pax::File> toast_file = nullptr;

PaxFileReaderObject *pax_file_reader;
pax_file_reader = (PaxFileReaderObject *)self;
Expand Down Expand Up @@ -205,7 +205,7 @@ static int paxfilereader_init(PyObject *self, PyObject *args,

auto file_ptr = pax::Singleton<pax::LocalFileSystem>::GetInstance()->Open(
pax_file_obj->filepath, pax::fs::kReadMode);
auto reader = new pax::OrcReader(std::move(file_ptr), toast_file);
auto reader = new pax::OrcReader(std::move(file_ptr), std::move(toast_file));
reader->Open(std::move(read_options));
pax_file_reader->reader = reader;
} catch (cbdb::CException &e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ bool PaxClusteringReader::GetNextTuple(TupleTableSlot *slot) {
file->Close();
}

std::shared_ptr<File> file;
std::shared_ptr<File> toast_file;
std::unique_ptr<File> file;
std::unique_ptr<File> toast_file;
file =
file_system_->Open(meta_info.GetFileName(), pax::fs::kReadMode);

Expand All @@ -75,7 +75,7 @@ bool PaxClusteringReader::GetNextTuple(TupleTableSlot *slot) {
}

reader_ = MicroPartitionFileFactory::CreateMicroPartitionReader(
options, ReaderFlags::FLAGS_EMPTY, file, toast_file);
options, ReaderFlags::FLAGS_EMPTY, std::move(file), std::move(toast_file));
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/pax_storage/src/cpp/storage/micro_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class MicroPartitionReader {
// fetch, compression/encoding. At the same time, pax column can also be
// used as a general interface for internal using, because it's zero copy
// from buffer. more details in `storage/columns`
virtual const std::shared_ptr<PaxColumns> &GetAllColumns() const = 0;
virtual const std::unique_ptr<PaxColumns> &GetAllColumns() const = 0;

virtual void SetVisibilityMap(
std::shared_ptr<Bitmap8> visibility_bitmap) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ namespace pax {
std::unique_ptr<MicroPartitionReader>
MicroPartitionFileFactory::CreateMicroPartitionReader(
const MicroPartitionReader::ReaderOptions &options, int32 flags,
std::shared_ptr<File> file, std::shared_ptr<File> toast_file) {
std::unique_ptr<File> file, std::unique_ptr<File> toast_file) {
std::unique_ptr<MicroPartitionReader> reader =
std::make_unique<OrcReader>(file, toast_file);
std::make_unique<OrcReader>(std::move(file), std::move(toast_file));

#ifdef VEC_BUILD
if (flags & ReaderFlags::FLAGS_VECTOR_PATH) {
Expand All @@ -63,13 +63,13 @@ MicroPartitionFileFactory::CreateMicroPartitionReader(
std::unique_ptr<MicroPartitionWriter>
MicroPartitionFileFactory::CreateMicroPartitionWriter(
const MicroPartitionWriter::WriterOptions &options,
std::shared_ptr<File> file, std::shared_ptr<File> toast_file) {
std::unique_ptr<File> file, std::unique_ptr<File> toast_file) {
std::vector<pax::porc::proto::Type_Kind> type_kinds;
type_kinds = OrcWriter::BuildSchema(
options.rel_tuple_desc,
options.storage_format == PaxStorageFormat::kTypeStoragePorcVec);
return std::make_unique<OrcWriter>(options, std::move(type_kinds), file,
toast_file);
return std::make_unique<OrcWriter>(options, std::move(type_kinds),
std::move(file), std::move(toast_file));
}

} // namespace pax
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class MicroPartitionFileFactory final {
public:
static std::unique_ptr<MicroPartitionWriter> CreateMicroPartitionWriter(
const MicroPartitionWriter::WriterOptions &options,
std::shared_ptr<File> file,
std::shared_ptr<File> toast_file = nullptr);
std::unique_ptr<File> file,
std::unique_ptr<File> toast_file = nullptr);

static std::unique_ptr<MicroPartitionReader> CreateMicroPartitionReader(
const MicroPartitionReader::ReaderOptions &options, int32 flags,
std::shared_ptr<File> file,
std::shared_ptr<File> toast_file = nullptr);
std::unique_ptr<File> file,
std::unique_ptr<File> toast_file = nullptr);
};

} // namespace pax
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ TEST_F(MicroPartitionFileFactoryTest, CreateMicroPartitionWriter) {
auto local_fs = Singleton<LocalFileSystem>::GetInstance();
ASSERT_NE(nullptr, local_fs);

std::shared_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr);
std::unique_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr.get());

std::vector<std::tuple<ColumnEncoding_Kind, int>> types_encoding;
types_encoding.emplace_back(
Expand All @@ -88,7 +88,7 @@ TEST_F(MicroPartitionFileFactoryTest, CreateMicroPartitionWriter) {
writer_options.encoding_opts = types_encoding;

auto writer = MicroPartitionFileFactory::CreateMicroPartitionWriter(
writer_options, file_ptr);
writer_options, std::move(file_ptr));

writer->WriteTuple(tuple_slot);
writer->Close();
Expand All @@ -101,8 +101,8 @@ TEST_F(MicroPartitionFileFactoryTest, CreateMicroPartitionReader) {
auto local_fs = Singleton<LocalFileSystem>::GetInstance();
ASSERT_NE(nullptr, local_fs);

std::shared_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr);
std::unique_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr.get());

std::vector<std::tuple<ColumnEncoding_Kind, int>> types_encoding;
types_encoding.emplace_back(
Expand All @@ -117,7 +117,7 @@ TEST_F(MicroPartitionFileFactoryTest, CreateMicroPartitionReader) {
writer_options.encoding_opts = types_encoding;

auto writer = MicroPartitionFileFactory::CreateMicroPartitionWriter(
writer_options, file_ptr);
writer_options, std::move(file_ptr));
TupleTableSlot *tuple_slot_empty = CreateTestTupleTableSlot(false);

writer->WriteTuple(tuple_slot);
Expand All @@ -130,7 +130,7 @@ TEST_F(MicroPartitionFileFactoryTest, CreateMicroPartitionReader) {
int32 flags = FLAGS_EMPTY;

auto reader = MicroPartitionFileFactory::CreateMicroPartitionReader(
reader_options, flags, file_ptr);
reader_options, flags, std::move(file_ptr));
reader->ReadTuple(tuple_slot_empty);
EXPECT_TRUE(VerifyTestTupleTableSlot(tuple_slot_empty));

Expand All @@ -145,8 +145,8 @@ TEST_F(MicroPartitionFileFactoryTest, OrcReadWithVisibilitymap) {
auto local_fs = Singleton<LocalFileSystem>::GetInstance();
ASSERT_NE(nullptr, local_fs);

std::shared_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr);
std::unique_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr.get());

std::vector<std::tuple<ColumnEncoding_Kind, int>> types_encoding;
types_encoding.emplace_back(
Expand All @@ -161,7 +161,7 @@ TEST_F(MicroPartitionFileFactoryTest, OrcReadWithVisibilitymap) {
writer_options.encoding_opts = types_encoding;

auto writer = MicroPartitionFileFactory::CreateMicroPartitionWriter(
writer_options, file_ptr);
writer_options, std::move(file_ptr));

int tuple_count = 1000;
for (int i = 0; i < tuple_count; i++) {
Expand All @@ -186,7 +186,7 @@ TEST_F(MicroPartitionFileFactoryTest, OrcReadWithVisibilitymap) {

TupleTableSlot *tuple_slot_empty = CreateTestTupleTableSlot();
auto reader = MicroPartitionFileFactory::CreateMicroPartitionReader(
reader_options, flags, file_ptr);
reader_options, flags, std::move(file_ptr));

int read_tuple_count = 0;
while (reader->ReadTuple(tuple_slot_empty)) {
Expand All @@ -210,8 +210,8 @@ TEST_F(MicroPartitionFileFactoryTest, VecReadWithVisibilitymap) {
auto local_fs = Singleton<LocalFileSystem>::GetInstance();
ASSERT_NE(nullptr, local_fs);

std::shared_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr);
std::unique_ptr<File> file_ptr = local_fs->Open(file_name_, fs::kWriteMode);
EXPECT_NE(nullptr, file_ptr.get());

std::vector<std::tuple<ColumnEncoding_Kind, int>> types_encoding;
types_encoding.emplace_back(
Expand All @@ -226,7 +226,7 @@ TEST_F(MicroPartitionFileFactoryTest, VecReadWithVisibilitymap) {
writer_options.encoding_opts = types_encoding;

auto writer = MicroPartitionFileFactory::CreateMicroPartitionWriter(
writer_options, file_ptr);
writer_options, std::move(file_ptr));

int tuple_count = 1000;
for (int i = 0; i < tuple_count; i++) {
Expand Down Expand Up @@ -264,7 +264,7 @@ TEST_F(MicroPartitionFileFactoryTest, VecReadWithVisibilitymap) {
CreateVecEmptyTupleSlot(tuple_slot->tts_tupleDescriptor);

auto reader = MicroPartitionFileFactory::CreateMicroPartitionReader(
reader_options, flags, file_ptr);
reader_options, flags, std::move(file_ptr));

auto ret = reader->ReadTuple(read_tuple_slot);
ASSERT_TRUE(ret);
Expand Down
6 changes: 3 additions & 3 deletions contrib/pax_storage/src/cpp/storage/orc/orc_dump_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ OrcDumpReader::OrcDumpReader(DumpConfig *config)
bool OrcDumpReader::Open() {
FileSystem *fs = nullptr;
std::shared_ptr<FileSystemOptions> fs_opt;
std::shared_ptr<File> open_file;
std::shared_ptr<File> open_toast_file;
std::unique_ptr<File> open_file;
std::unique_ptr<File> open_toast_file;

assert(config_);
assert(config_->file_name);
Expand All @@ -111,7 +111,7 @@ bool OrcDumpReader::Open() {
}
}

format_reader_ = new OrcFormatReader(open_file, open_toast_file);
format_reader_ = new OrcFormatReader(std::move(open_file), std::move(open_toast_file));
format_reader_->Open();

return true;
Expand Down
4 changes: 2 additions & 2 deletions contrib/pax_storage/src/cpp/storage/orc/orc_format_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

namespace pax {

OrcFormatReader::OrcFormatReader(std::shared_ptr<File> file,
std::shared_ptr<File> toast_file)
OrcFormatReader::OrcFormatReader(std::unique_ptr<File> file,
std::unique_ptr<File> toast_file)
: file_(std::move(file)),
toast_file_(std::move(toast_file)),
reused_buffer_(nullptr),
Expand Down
6 changes: 3 additions & 3 deletions contrib/pax_storage/src/cpp/storage/orc/orc_format_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OrcDumpReader;
}
class OrcFormatReader final {
public:
explicit OrcFormatReader(std::shared_ptr<File> file, std::shared_ptr<File> toast_file = nullptr);
explicit OrcFormatReader(std::unique_ptr<File> file, std::unique_ptr<File> toast_file = nullptr);

~OrcFormatReader();

Expand Down Expand Up @@ -78,8 +78,8 @@ class OrcFormatReader final {
friend class OrcGroupStatsProvider;
std::vector<pax::porc::proto::Type_Kind> column_types_;
std::vector<std::map<std::string, std::string>> column_attrs_;
std::shared_ptr<File> file_;
std::shared_ptr<File> toast_file_;
std::unique_ptr<File> file_;
std::unique_ptr<File> toast_file_;
std::shared_ptr<DataBuffer<char>> reused_buffer_;
size_t num_of_stripes_;
bool is_vec_;
Expand Down
4 changes: 2 additions & 2 deletions contrib/pax_storage/src/cpp/storage/orc/orc_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ inline static std::pair<Datum, bool> GetColumnDatum(PaxColumn *column,
return {rc, false};
}

OrcGroup::OrcGroup(std::unique_ptr<PaxColumns> &&pax_column, size_t row_offset,
OrcGroup::OrcGroup(std::unique_ptr<PaxColumns> pax_column, size_t row_offset,
const std::vector<int> *proj_col_index,
std::shared_ptr<Bitmap8> micro_partition_visibility_bitmap)
: pax_columns_(std::move(pax_column)),
Expand All @@ -88,7 +88,7 @@ size_t OrcGroup::GetRows() const { return pax_columns_->GetRows(); }

size_t OrcGroup::GetRowOffset() const { return row_offset_; }

const std::shared_ptr<PaxColumns> &OrcGroup::GetAllColumns() const {
const std::unique_ptr<PaxColumns> &OrcGroup::GetAllColumns() const {
return pax_columns_;
}

Expand Down
6 changes: 3 additions & 3 deletions contrib/pax_storage/src/cpp/storage/orc/orc_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OrcDumpReader;
class OrcGroup : public MicroPartitionReader::Group {
public:
OrcGroup(
std::unique_ptr<PaxColumns> &&pax_column, size_t row_offset,
std::unique_ptr<PaxColumns> pax_column, size_t row_offset,
const std::vector<int> *proj_col_index,
std::shared_ptr<Bitmap8> micro_partition_visibility_bitmap = nullptr);

Expand All @@ -50,7 +50,7 @@ class OrcGroup : public MicroPartitionReader::Group {

size_t GetRowOffset() const override;

const std::shared_ptr<PaxColumns> &GetAllColumns() const override;
const std::unique_ptr<PaxColumns> &GetAllColumns() const override;

virtual std::pair<bool, size_t> ReadTuple(TupleTableSlot *slot) override;

Expand All @@ -74,7 +74,7 @@ class OrcGroup : public MicroPartitionReader::Group {
size_t row_index);

protected:
std::shared_ptr<PaxColumns> pax_columns_;
std::unique_ptr<PaxColumns> pax_columns_;
std::shared_ptr<Bitmap8> micro_partition_visibility_bitmap_;
size_t row_offset_;
size_t current_row_index_;
Expand Down
6 changes: 3 additions & 3 deletions contrib/pax_storage/src/cpp/storage/orc/orc_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class OrcGroupStatsProvider final : public ColumnStatsProvider {
size_t group_index_;
};

OrcReader::OrcReader(std::shared_ptr<File> file,
std::shared_ptr<File> toast_file)
OrcReader::OrcReader(std::unique_ptr<File> file,
std::unique_ptr<File> toast_file)
: working_group_(nullptr),
cached_group_(nullptr),
current_group_index_(0),
format_reader_(file, toast_file),
format_reader_(std::move(file), std::move(toast_file)),
is_closed_(true) {}

std::unique_ptr<ColumnStatsProvider> OrcReader::GetGroupStatsInfo(
Expand Down
Loading
Loading