Skip to content

Commit

Permalink
fix wrong handling on commit_response_kind::available
Browse files Browse the repository at this point in the history
  • Loading branch information
kuron99 committed Oct 23, 2024
1 parent 835dda8 commit 20779bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
3 changes: 1 addition & 2 deletions include/jogasaki/commit_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ using commit_response_kind_set = takatori::util::enum_set<
commit_response_kind::undefined,
commit_response_kind::propagated>;

}

} // namespace jogasaki
25 changes: 18 additions & 7 deletions src/jogasaki/api/impl/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,22 +536,33 @@ void service::command_commit(
if(! tx) {
return;
}
auto nt = from(cm.notification_type());
auto cr = nt != commit_response_kind::undefined ? nt : db_->config()->default_commit_response();
commit_response_kind_set responses{};
if(cr == commit_response_kind::accepted || cr == commit_response_kind::available) {
// currently accepted and available are treated the same
responses.insert(commit_response_kind::accepted);
cr = commit_response_kind::accepted;
}
if(cr == commit_response_kind::stored || cr == commit_response_kind::propagated) {
responses.insert(commit_response_kind::stored);
cr = commit_response_kind::stored;
}

commit_option opt{};
opt.auto_dispose_on_success(cm.auto_dispose())
.commit_response(from(cm.notification_type()));
opt.auto_dispose_on_success(cm.auto_dispose()).commit_response(cr);

auto tctx = get_transaction_context(tx);
executor::commit_async(
get_impl(*db_),
tctx,
[res, req_info](commit_response_kind kind) {
(void) kind; // for now, callback does same regardless of kind
[res, req_info](commit_response_kind) {
// for now, callback does same regardless of kind
details::success<sql::response::ResultOnly>(*res, req_info);
},
commit_response_kind_set{opt.commit_response()},
[res, req_info](commit_response_kind kind, status st, std::shared_ptr<error::error_info> info) { //NOLINT(performance-unnecessary-value-param)
(void) kind; // for now, callback does same regardless of kind
(void) st;
[res, req_info](commit_response_kind, status, std::shared_ptr<error::error_info> info) { //NOLINT(performance-unnecessary-value-param)
// for now, callback does same regardless of kind
VLOG(log_error) << log_location_prefix << info->message();
details::error<sql::response::ResultOnly>(*res, info.get(), req_info);
},
Expand Down
12 changes: 12 additions & 0 deletions src/jogasaki/executor/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#include <jogasaki/scheduler/task_scheduler.h>
#include <jogasaki/transaction_context.h>
#include <jogasaki/utils/abort_error.h>
#include <jogasaki/utils/assert.h>
#include <jogasaki/utils/external_log_utils.h>
#include <jogasaki/utils/hex.h>

Expand Down Expand Up @@ -761,6 +762,13 @@ scheduler::job_context::job_id_type commit_async(
api::commit_option option,
request_info const& req_info
) {
// currently response_kinds contains at most one element
assert_with_exception(response_kinds.size() <= 1, response_kinds);
assert_with_exception(
response_kinds.empty() || response_kinds.contains(commit_response_kind::accepted) ||
response_kinds.contains(commit_response_kind::stored), response_kinds
);

auto req = std::make_shared<scheduler::request_detail>(scheduler::request_detail_kind::commit);
req->status(scheduler::request_detail_status::accepted);
req->transaction_id(tx->transaction_id());
Expand All @@ -782,6 +790,7 @@ scheduler::job_context::job_id_type commit_async(
auto cr = option.commit_response() != commit_response_kind::undefined ?
option.commit_response() :
database.config()->default_commit_response();
assert_with_exception((cr == commit_response_kind::accepted || cr == commit_response_kind::stored), cr);
tx->commit_response(cr);

auto t = scheduler::create_custom_task(rctx.get(),
Expand Down Expand Up @@ -855,10 +864,13 @@ scheduler::job_context::job_id_type commit_async(
if(cr == commit_response_kind::accepted || cr == commit_response_kind::available) {
// currently accepted and available are treated the same
responses.insert(commit_response_kind::accepted);
cr = commit_response_kind::accepted;
}
if(cr == commit_response_kind::stored || cr == commit_response_kind::propagated) {
responses.insert(commit_response_kind::stored);
cr = commit_response_kind::stored;
}
option.commit_response(cr);
return commit_async(
database,
std::move(tx),
Expand Down
1 change: 1 addition & 0 deletions src/jogasaki/executor/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ status commit(
* @param req_info exchange the original request/response info (mainly for logging purpose)
* @return id of the job to execute commit
* @note normal error such as SQL runtime processing failure will be reported by callback
* @deprecated Use `commit_async` with commit_response_callback arg. This function is left for testing.
*/
scheduler::job_context::job_id_type commit_async(
api::impl::database& database,
Expand Down

0 comments on commit 20779bf

Please sign in to comment.