forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_sql_trans_util.cpp
More file actions
118 lines (108 loc) · 3.58 KB
/
ob_sql_trans_util.cpp
File metadata and controls
118 lines (108 loc) · 3.58 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
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL
#include "sql/ob_sql_trans_util.h"
#include "sql/session/ob_sql_session_info.h"
namespace oceanbase {
using namespace common;
namespace sql {
OB_SERIALIZE_MEMBER(TransResult, part_epoch_list_, response_partitions_, total_partitions_, max_sql_no_);
void TransResult::reset()
{
ObLockGuard<ObSpinLock> lock_guard(lock_);
total_partitions_.reset();
response_partitions_.reset();
part_epoch_list_.reset();
is_incomplete_ = false;
max_sql_no_ = 0;
}
int TransResult::assign(const TransResult& other)
{
int ret = OB_SUCCESS;
ObLockGuard<ObSpinLock> lock_guard(lock_);
OZ(total_partitions_.assign(other.total_partitions_));
OZ(part_epoch_list_.assign(other.part_epoch_list_));
OZ(response_partitions_.assign(other.response_partitions_));
OX(is_incomplete_ = other.is_incomplete_);
OX(max_sql_no_ = other.max_sql_no_);
return ret;
}
int TransResult::merge_result(const TransResult& other)
{
int ret = OB_SUCCESS;
ObLockGuard<ObSpinLock> lock_guard(lock_);
OZ(append_array_no_dup(total_partitions_, other.total_partitions_), other.total_partitions_);
OZ(append_array_no_dup(part_epoch_list_, other.part_epoch_list_), other.part_epoch_list_);
OZ(append_array_no_dup(response_partitions_, other.response_partitions_), other.response_partitions_);
if (other.is_incomplete()) {
OX(set_incomplete());
}
int64_t other_max_sql_no = other.max_sql_no_;
if (OB_NOT_NULL(other.trans_desc_) && other_max_sql_no < other.trans_desc_->get_max_sql_no()) {
other_max_sql_no = other.trans_desc_->get_max_sql_no();
}
OZ(set_max_sql_no(other_max_sql_no));
if (OB_NOT_NULL(trans_desc_)) {
OX(trans_desc_->set_max_sql_no(get_max_sql_no()));
}
return ret;
}
int TransResult::merge_total_partitions(const ObPartitionArray& partitions)
{
int ret = OB_SUCCESS;
ObLockGuard<ObSpinLock> lock_guard(lock_);
OZ(append_array_no_dup(total_partitions_, partitions), partitions);
return ret;
}
int TransResult::merge_response_partitions(const common::ObPartitionArray& partitions)
{
int ret = OB_SUCCESS;
ObLockGuard<ObSpinLock> lock_guard(lock_);
OZ(append_array_no_dup(response_partitions_, partitions), partitions);
return ret;
}
int TransResult::merge_part_epoch_list(const transaction::ObPartitionEpochArray& part_epoch_list)
{
int ret = OB_SUCCESS;
ObLockGuard<ObSpinLock> lock_guard(lock_);
OZ(append_array_no_dup(part_epoch_list_, part_epoch_list), part_epoch_list);
return ret;
}
void TransResult::clear_stmt_result()
{
ObLockGuard<ObSpinLock> lock_guard(lock_);
total_partitions_.reset();
response_partitions_.reset();
part_epoch_list_.reset();
is_incomplete_ = false;
/*
LOG_INFO("reset_sql_no", K(max_sql_no_), K(lbt()));
*/
max_sql_no_ = 0;
}
int TransResult::set_max_sql_no(int64_t sql_no)
{
int ret = OB_SUCCESS;
if (max_sql_no_ < sql_no) {
/*
LOG_INFO("renew_sql_no", K(max_sql_no_), K(sql_no), K(lbt()));
*/
max_sql_no_ = sql_no;
} else {
/*
LOG_INFO("skip_sql_no", K(max_sql_no_), K(sql_no), K(lbt()));
*/
}
return ret;
}
} // namespace sql
} // namespace oceanbase