-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add TaskContext and Data as task argument #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b7b4a7e
Add TaskContext as first argument of task
sitaowang1998 aa8115c
Add data storage set locality and basic client data implementation
sitaowang1998 0330fde
Add serializer for data
sitaowang1998 b9d9db3
Fix clang tidy
sitaowang1998 84d5d7f
Fix clang tidy
sitaowang1998 988f2c7
Add data implementation
sitaowang1998 7a424a3
Add create data builder interface in driver and task context
sitaowang1998 c6ee8fe
Remove direct Data serializer becuase data serialization is ambiguous
sitaowang1998 a791b1e
Add data serializer
sitaowang1998 c34e0eb
Reformat cmake files
sitaowang1998 cb662e7
Add task id into args buffer message
sitaowang1998 ef1104b
Add data support in task
sitaowang1998 65bc812
Add function manager test for data
sitaowang1998 6222a65
Add data in task executor unit test
sitaowang1998 82e6e17
Add data test in integration test
sitaowang1998 5e87551
Fix clang tidy
sitaowang1998 1508038
Fix clang tidy
sitaowang1998 9b3098b
Fix clang tidy
sitaowang1998 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
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,28 @@ | ||
| #ifndef SPIDER_CORE_DATAIMPL_HPP | ||
| #define SPIDER_CORE_DATAIMPL_HPP | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| #include "../client/Data.hpp" | ||
| #include "../core/Data.hpp" | ||
|
|
||
| namespace spider::core { | ||
|
|
||
| class DataImpl { | ||
| public: | ||
| template <class T> | ||
| static auto create_data(std::unique_ptr<Data> data, std::shared_ptr<DataStorage> data_store) | ||
| -> spider::Data<T> { | ||
| return spider::Data<T>{std::move(data), data_store}; | ||
| } | ||
|
|
||
| template <class T> | ||
| static auto get_impl(spider::Data<T> const& data) -> std::shared_ptr<DataStorage> { | ||
| return data.get_impl(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace spider::core | ||
|
|
||
| #endif |
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,32 @@ | ||
| #ifndef SPIDER_CORE_TASKCONTEXTIMPL_HPP | ||
| #define SPIDER_CORE_TASKCONTEXTIMPL_HPP | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "../client/TaskContext.hpp" | ||
| #include "../storage/DataStorage.hpp" | ||
| #include "../storage/MetadataStorage.hpp" | ||
|
|
||
| namespace spider::core { | ||
| class TaskContextImpl { | ||
| public: | ||
| static auto create_task_context( | ||
| std::shared_ptr<DataStorage> const& data_storage, | ||
| std::shared_ptr<MetadataStorage> const& metadata_storage | ||
| ) -> TaskContext { | ||
| return TaskContext{data_storage, metadata_storage}; | ||
| } | ||
|
|
||
| static auto get_data_store(TaskContext const& task_context) -> std::shared_ptr<DataStorage> { | ||
| return task_context.m_data_store; | ||
| } | ||
|
|
||
| static auto get_metadata_store(TaskContext const& task_context | ||
| ) -> std::shared_ptr<MetadataStorage> { | ||
| return task_context.m_metadata_store; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace spider::core | ||
|
|
||
| #endif | ||
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 |
|---|---|---|
|
|
@@ -1475,6 +1475,36 @@ auto MySqlDataStorage::get_data(boost::uuids::uuid id, Data* data) -> StorageErr | |
| return StorageErr{}; | ||
| } | ||
|
|
||
| auto MySqlDataStorage::set_data_locality(Data const& data) -> StorageErr { | ||
| try { | ||
| std::unique_ptr<sql::PreparedStatement> const delete_statement( | ||
| m_conn->prepareStatement("DELETE FROM `data_locality` WHERE `id` = ?") | ||
| ); | ||
| sql::bytes id_bytes = uuid_get_bytes(data.get_id()); | ||
| delete_statement->setBytes(1, &id_bytes); | ||
| delete_statement->executeUpdate(); | ||
| std::unique_ptr<sql::PreparedStatement> const insert_statement(m_conn->prepareStatement( | ||
| "INSERT INTO `data_locality` (`id`, `address`) VALUES(?, ?)" | ||
| )); | ||
| for (std::string const& addr : data.get_locality()) { | ||
| insert_statement->setBytes(1, &id_bytes); | ||
| insert_statement->setString(2, addr); | ||
| insert_statement->executeUpdate(); | ||
| } | ||
| std::unique_ptr<sql::PreparedStatement> const hard_locality_statement( | ||
| m_conn->prepareStatement("UPDATE `data` SET `hard_locality` = ? WHERE `id` = ?") | ||
| ); | ||
| hard_locality_statement->setBoolean(1, data.is_hard_locality()); | ||
| hard_locality_statement->setBytes(2, &id_bytes); | ||
| hard_locality_statement->executeUpdate(); | ||
| } catch (sql::SQLException& e) { | ||
| m_conn->rollback(); | ||
| return StorageErr{StorageErrType::OtherErr, e.what()}; | ||
| } | ||
| m_conn->commit(); | ||
| return StorageErr{}; | ||
| } | ||
|
Comment on lines
+1478
to
+1506
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance data locality update robustness Consider these improvements for better error handling and safety:
auto MySqlDataStorage::set_data_locality(Data const& data) -> StorageErr {
try {
+ // Verify data exists
+ std::unique_ptr<sql::PreparedStatement> const check_statement(
+ m_conn->prepareStatement("SELECT 1 FROM `data` WHERE `id` = ?")
+ );
+ sql::bytes id_bytes = uuid_get_bytes(data.get_id());
+ check_statement->setBytes(1, &id_bytes);
+ std::unique_ptr<sql::ResultSet> const check_result(check_statement->executeQuery());
+ if (check_result->rowsCount() == 0) {
+ m_conn->rollback();
+ return StorageErr{
+ StorageErrType::KeyNotFoundErr,
+ fmt::format("no data with id {}", boost::uuids::to_string(data.get_id()))
+ };
+ }
+
std::unique_ptr<sql::PreparedStatement> const delete_statement(
- m_conn->prepareStatement("DELETE FROM `data_locality` WHERE `id` = ?")
+ m_conn->prepareStatement("DELETE FROM `data_locality` WHERE `id` = ?")
);
- sql::bytes id_bytes = uuid_get_bytes(data.get_id());
delete_statement->setBytes(1, &id_bytes);
- delete_statement->executeUpdate();
+ int const deleted_rows = delete_statement->executeUpdate();
+ if (deleted_rows < 0) {
+ m_conn->rollback();
+ return StorageErr{StorageErrType::OtherErr, "Failed to delete existing locality"};
+ }
|
||
|
|
||
| auto MySqlDataStorage::remove_data(boost::uuids::uuid id) -> StorageErr { | ||
| try { | ||
| std::unique_ptr<sql::PreparedStatement> statement( | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Null pointer validation needed in TaskContext construction
Based on the code analysis, there are no explicit null pointer checks when constructing TaskContext objects. Since these shared pointers are crucial for the task execution context, I recommend adding validation to prevent potential null pointer issues.
create_task_contextmethod insrc/spider/core/TaskContextImpl.hppstd::invalid_argument) if eitherdata_storageormetadata_storageis null🔗 Analysis chain
create_task_context
The static method create_task_context cleanly constructs a contextual environment. Confirm that the usage covers potential error handling if data_storage or metadata_storage is null.
Let me check the implementation details and usage context more thoroughly.
Let me check the TaskContext implementation and constructor to see how it handles null pointers.
Let me try one final check to see the constructor implementation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 627
Script:
Length of output: 2623
Script:
Length of output: 152
Script:
Length of output: 1180