-
Notifications
You must be signed in to change notification settings - Fork 44
feat(spill): add SpillWriter, SpillReader and SpillChannelManager for… #219
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
dalingmeng
wants to merge
1
commit into
alibaba:main
Choose a base branch
from
dalingmeng:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "paimon/core/disk/file_io_channel.h" | ||
|
|
||
| #include <iomanip> | ||
| #include <sstream> | ||
| #include <utility> | ||
|
|
||
| #include "paimon/common/utils/path_util.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| std::string FileIOChannel::GenerateRandomHexString(std::mt19937* random) { | ||
| std::uniform_int_distribution<int32_t> dist(0, 255); | ||
| std::ostringstream hex_stream; | ||
| hex_stream << std::hex << std::setfill('0'); | ||
| for (int32_t i = 0; i < kRandomBytesLength; ++i) { | ||
| hex_stream << std::setw(2) << dist(*random); | ||
| } | ||
| return hex_stream.str(); | ||
| } | ||
|
|
||
| FileIOChannel::ID::ID(const std::string& path) : path_(path) {} | ||
|
|
||
| FileIOChannel::ID::ID(const std::string& base_path, std::mt19937* random) | ||
| : path_(PathUtil::JoinPath(base_path, GenerateRandomHexString(random) + ".channel")) {} | ||
|
|
||
| FileIOChannel::ID::ID(const std::string& base_path, const std::string& prefix, std::mt19937* random) | ||
| : path_(PathUtil::JoinPath(base_path, | ||
| prefix + "-" + GenerateRandomHexString(random) + ".channel")) {} | ||
|
|
||
| const std::string& FileIOChannel::ID::GetPath() const { | ||
| return path_; | ||
| } | ||
|
|
||
| bool FileIOChannel::ID::operator==(const ID& other) const { | ||
| return path_ == other.path_; | ||
| } | ||
|
|
||
| bool FileIOChannel::ID::operator!=(const ID& other) const { | ||
| return !(*this == other); | ||
| } | ||
|
|
||
| size_t FileIOChannel::ID::Hash::operator()(const ID& id) const { | ||
| return std::hash<std::string>{}(id.path_); | ||
| } | ||
|
|
||
| FileIOChannel::Enumerator::Enumerator(const std::string& base_path, std::mt19937* random) | ||
| : path_(base_path), name_prefix_(GenerateRandomHexString(random)) {} | ||
|
|
||
| FileIOChannel::ID FileIOChannel::Enumerator::Next() { | ||
| std::ostringstream filename; | ||
| filename << name_prefix_ << "." << std::setfill('0') << std::setw(6) << (local_counter_++) | ||
| << ".channel"; | ||
|
|
||
| std::string full_path = PathUtil::JoinPath(path_, filename.str()); | ||
| return ID(full_path); | ||
| } | ||
|
|
||
| } // namespace paimon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <random> | ||
| #include <string> | ||
|
|
||
| #include "paimon/visibility.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// A FileIOChannel represents a collection of files that belong logically to the same resource. | ||
| class PAIMON_EXPORT FileIOChannel { | ||
| public: | ||
| class PAIMON_EXPORT ID { | ||
| public: | ||
| ID() = default; | ||
|
|
||
| explicit ID(const std::string& path); | ||
|
|
||
| ID(const std::string& base_path, std::mt19937* random); | ||
|
|
||
| ID(const std::string& base_path, const std::string& prefix, std::mt19937* random); | ||
|
|
||
| const std::string& GetPath() const; | ||
|
|
||
| bool operator==(const ID& other) const; | ||
|
|
||
| bool operator!=(const ID& other) const; | ||
|
|
||
| struct Hash { | ||
| size_t operator()(const ID& id) const; | ||
| }; | ||
|
|
||
| private: | ||
| std::string path_; | ||
| }; | ||
|
|
||
| private: | ||
| static constexpr int32_t kRandomBytesLength = 16; | ||
| static std::string GenerateRandomHexString(std::mt19937* random); | ||
|
|
||
| public: | ||
| class PAIMON_EXPORT Enumerator { | ||
| public: | ||
| Enumerator(const std::string& base_path, std::mt19937* random); | ||
|
|
||
| ID Next(); | ||
|
|
||
dalingmeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private: | ||
| std::string path_; | ||
| std::string name_prefix_; | ||
| uint64_t local_counter_{0}; | ||
| }; | ||
| }; | ||
|
|
||
| } // namespace paimon | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <mutex> | ||
| #include <random> | ||
| #include <string> | ||
|
|
||
| #include "paimon/common/utils/path_util.h" | ||
| #include "paimon/common/utils/uuid.h" | ||
| #include "paimon/core/disk/file_io_channel.h" | ||
| #include "paimon/disk/io_manager.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| class IOManagerImpl : public IOManager { | ||
| public: | ||
| explicit IOManagerImpl(const std::string& tmp_dir) : tmp_dir_(tmp_dir) { | ||
| std::random_device rd; | ||
| random_.seed(rd()); | ||
| } | ||
|
|
||
| const std::string& GetTempDir() const override { | ||
| return tmp_dir_; | ||
| } | ||
|
|
||
| Result<std::string> GenerateTempFilePath(const std::string& prefix) const override { | ||
| std::string uuid; | ||
| if (!UUID::Generate(&uuid)) { | ||
| return Status::Invalid("generate uuid for io manager tmp path failed."); | ||
| } | ||
| return PathUtil::JoinPath(tmp_dir_, prefix + "-" + uuid + std::string(kSuffix)); | ||
| } | ||
|
|
||
| Result<FileIOChannel::ID> CreateChannel() { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| return FileIOChannel::ID(tmp_dir_, &random_); | ||
| } | ||
|
|
||
| Result<FileIOChannel::ID> CreateChannel(const std::string& prefix) { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| return FileIOChannel::ID(tmp_dir_, prefix, &random_); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<FileIOChannel::Enumerator>> CreateChannelEnumerator() { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| return std::make_shared<FileIOChannel::Enumerator>(tmp_dir_, &random_); | ||
| } | ||
|
|
||
| private: | ||
| static constexpr char kSuffix[] = ".channel"; | ||
| std::string tmp_dir_; | ||
| std::mutex mutex_; | ||
| std::mt19937 random_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.