forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_end_trans_callback.cpp
More file actions
120 lines (106 loc) · 3.48 KB
/
Copy pathob_end_trans_callback.cpp
File metadata and controls
120 lines (106 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright (c) 2025 OceanBase.
*
* 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.
*/
#define USING_LOG_PREFIX SQL
#include "ob_end_trans_callback.h"
#include "sql/session/ob_sql_session_info.h"
#include "lib/stat/ob_diagnostic_info_guard.h"
using namespace oceanbase::transaction;
using namespace oceanbase::common;
namespace oceanbase
{
namespace sql
{
ObSharedEndTransCallback::ObSharedEndTransCallback()
{
}
ObSharedEndTransCallback::~ObSharedEndTransCallback()
{
}
ObExclusiveEndTransCallback::ObExclusiveEndTransCallback()
{
reset();
}
ObExclusiveEndTransCallback::~ObExclusiveEndTransCallback()
{
}
///////////////// Async Callback Impl /////////////
ObEndTransAsyncCallback::ObEndTransAsyncCallback() :
ObExclusiveEndTransCallback(),
mysql_end_trans_cb_(),
diagnostic_info_(nullptr)
{
}
ObEndTransAsyncCallback::~ObEndTransAsyncCallback()
{
reset_diagnostic_info();
}
void ObEndTransAsyncCallback::callback(int cb_param, const transaction::ObTransID &trans_id)
{
UNUSED(trans_id);
callback(cb_param);
}
void ObEndTransAsyncCallback::callback(int cb_param)
{
// Add ASH flags to async commit of transactions
// In the start of async commit in func named ` ObSqlTransControl::do_end_trans_() `,
// set the ash flag named `in_committing_` to true.
ObDiagnosticInfoSwitchGuard g(diagnostic_info_);
if (OB_NOT_NULL(diagnostic_info_)) {
common::ObDiagnosticInfo *di = diagnostic_info_;
reset_diagnostic_info();
di->get_ash_stat().in_committing_ = false;
di->get_ash_stat().in_sql_execution_ = true;
di->end_wait_event(ObWaitEventIds::ASYNC_COMMITTING_WAIT, false);
}
bool need_disconnect = false;
if (OB_UNLIKELY(!has_set_need_rollback_)) {
LOG_ERROR_RET(OB_ERR_UNEXPECTED, "is_need_rollback_ has not been set",
K(has_set_need_rollback_),
K(is_need_rollback_));
} else if (OB_UNLIKELY(ObExclusiveEndTransCallback::END_TRANS_TYPE_INVALID == end_trans_type_)) {
LOG_ERROR_RET(OB_INVALID_ARGUMENT, "end trans type is invalid", K(cb_param), K(end_trans_type_));
} else {
ObSQLUtils::check_if_need_disconnect_after_end_trans(
cb_param, is_need_rollback_,
ObExclusiveEndTransCallback::END_TRANS_TYPE_EXPLICIT == end_trans_type_,
need_disconnect);
}
mysql_end_trans_cb_.set_need_disconnect(need_disconnect);
this->handin();
CHECK_BALANCE("[async callback]");
if (OB_SUCCESS == this->last_err_) {
mysql_end_trans_cb_.callback(cb_param);
} else {
cb_param = this->last_err_;
mysql_end_trans_cb_.callback(cb_param);
}
}
void ObEndTransAsyncCallback::set_diagnostic_info(common::ObDiagnosticInfo *diagnostic_info)
{
if (nullptr == diagnostic_info_) {
diagnostic_info_ = diagnostic_info;
common::ObLocalDiagnosticInfo::inc_ref(diagnostic_info_);
}
};
void ObEndTransAsyncCallback::reset_diagnostic_info()
{
if (nullptr != diagnostic_info_) {
common::ObLocalDiagnosticInfo::dec_ref(diagnostic_info_);
diagnostic_info_ = nullptr;
}
}
}/* ns sql*/
}/* ns oceanbase */