-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve executor::commit_async for various commit response
- Loading branch information
Showing
10 changed files
with
334 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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,80 @@ | ||
/* | ||
* Copyright 2018-2023 Project Tsurugi. | ||
* | ||
* 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 <atomic> | ||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include <jogasaki/error/error_info.h> | ||
#include <jogasaki/commit_response.h> | ||
|
||
namespace jogasaki { | ||
|
||
/** | ||
* @brief the callback type used for async commit successful response | ||
*/ | ||
using commit_response_callback = std::function<void(commit_response_kind)>; | ||
|
||
/** | ||
* @brief the callback type used for async commit error response | ||
*/ | ||
using commit_error_callback = std::function<void(commit_response_kind, status, std::shared_ptr<error::error_info>)>; | ||
|
||
/** | ||
* @brief context object for tx commit processing | ||
*/ | ||
class commit_context { | ||
public: | ||
/** | ||
* @brief create default context object | ||
*/ | ||
commit_context() = default; | ||
|
||
/** | ||
* @brief create new context object | ||
* @param on_response the callback function to be called when the response is ready | ||
* @param response_kinds the kinds of response to be notified | ||
*/ | ||
commit_context( | ||
commit_response_callback on_response, | ||
commit_response_kind_set response_kinds, | ||
commit_error_callback on_error | ||
) : on_response_(std::move(on_response)), | ||
response_kinds_(response_kinds), | ||
on_error_(std::move(on_error)) | ||
{} | ||
|
||
commit_response_callback& on_response() noexcept { | ||
return on_response_; | ||
} | ||
|
||
commit_response_kind_set& response_kinds() noexcept { | ||
return response_kinds_; | ||
} | ||
|
||
commit_error_callback& on_error() noexcept { | ||
return on_error_; | ||
} | ||
private: | ||
commit_response_callback on_response_{}; | ||
commit_response_kind_set response_kinds_{}; | ||
commit_error_callback on_error_{}; | ||
|
||
}; | ||
|
||
} // namespace jogasaki |
This file contains 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 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,67 @@ | ||
/* | ||
* Copyright 2018-2023 Project Tsurugi. | ||
* | ||
* 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 "durability_common.h" | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <ostream> | ||
#include <string_view> | ||
#include <type_traits> | ||
#include <utility> | ||
#include <glog/logging.h> | ||
|
||
#include <takatori/util/maybe_shared_ptr.h> | ||
|
||
#include <jogasaki/api/impl/database.h> | ||
#include <jogasaki/api/impl/request_context_factory.h> | ||
#include <jogasaki/commit_profile.h> | ||
#include <jogasaki/configuration.h> | ||
#include <jogasaki/durability_manager.h> | ||
#include <jogasaki/logging.h> | ||
#include <jogasaki/model/task.h> | ||
#include <jogasaki/request_context.h> | ||
#include <jogasaki/request_logging.h> | ||
#include <jogasaki/scheduler/flat_task.h> | ||
#include <jogasaki/scheduler/request_detail.h> | ||
#include <jogasaki/scheduler/schedule_option.h> | ||
#include <jogasaki/scheduler/task_factory.h> | ||
#include <jogasaki/scheduler/task_scheduler.h> | ||
#include <jogasaki/transaction_context.h> | ||
#include <jogasaki/utils/set_cancel_status.h> | ||
|
||
namespace jogasaki { | ||
|
||
void submit_commit_response( | ||
std::shared_ptr<request_context> rctx, //NOLINT(performance-unnecessary-value-param) | ||
commit_response_kind kind, | ||
bool is_error, | ||
bool teardown_try_on_suspended_worker | ||
) { | ||
auto& ts = *rctx->scheduler(); | ||
ts.schedule_task( | ||
scheduler::create_custom_task(rctx.get(), [rctx, kind, teardown_try_on_suspended_worker, is_error]() { | ||
if(is_error) { | ||
rctx->commit_ctx()->on_error()(kind, rctx->status_code(), rctx->error_info()); | ||
} else { | ||
rctx->commit_ctx()->on_response()(kind); | ||
} | ||
scheduler::submit_teardown(*rctx, false, teardown_try_on_suspended_worker); | ||
return model::task_result::complete; | ||
}, false) | ||
); | ||
} | ||
|
||
} // namespace jogasaki |
This file contains 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,41 @@ | ||
/* | ||
* Copyright 2018-2023 Project Tsurugi. | ||
* | ||
* 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 <atomic> | ||
#include <memory> | ||
|
||
#include <jogasaki/request_context.h> | ||
#include <jogasaki/commit_response.h> | ||
|
||
namespace jogasaki { | ||
|
||
/** | ||
* @brief submit a task to process commit response | ||
* @details this function submits a task to invoke commit response callback and scheduler following teardown task | ||
* @param rctx the request context | ||
* @param kind the kind of the commit response | ||
* @param is_error whether the commit response is an error | ||
* @param teardown_try_on_suspended_worker whether to submit teardown on the suspended worker | ||
*/ | ||
void submit_commit_response( | ||
std::shared_ptr<request_context> rctx, | ||
commit_response_kind kind, | ||
bool is_error, | ||
bool teardown_try_on_suspended_worker | ||
); | ||
|
||
} // namespace jogasaki |
Oops, something went wrong.