oceanbase

Форк
0
/
ob_snapshot_info_manager.cpp 
222 строки · 8.3 Кб
1
/**
2
 * Copyright (c) 2021 OceanBase
3
 * OceanBase CE is licensed under Mulan PubL v2.
4
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
5
 * You may obtain a copy of Mulan PubL v2 at:
6
 *          http://license.coscl.org.cn/MulanPubL-2.0
7
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
 * See the Mulan PubL v2 for more details.
11
 */
12

13
#define USING_LOG_PREFIX RS
14
#include "ob_snapshot_info_manager.h"
15
#include "share/ob_snapshot_table_proxy.h"
16
#include "share/schema/ob_schema_utils.h"
17
#include "share/ob_ddl_common.h"
18
#include "common/ob_timeout_ctx.h"
19
#include "lib/mysqlclient/ob_mysql_transaction.h"
20
#include "ob_rs_event_history_table_operator.h"
21

22
using namespace oceanbase::common;
23
using namespace oceanbase::share;
24
using namespace oceanbase::share::schema;
25
using namespace oceanbase::palf;
26
namespace oceanbase
27
{
28
namespace rootserver
29
{
30
int ObSnapshotInfoManager::init(const ObAddr &self_addr)
31
{
32
  int ret = OB_SUCCESS;
33
  if (!self_addr.is_valid()) {
34
    ret = OB_INVALID_ARGUMENT;
35
    LOG_WARN("invalid argument", K(ret), K(self_addr));
36
  } else {
37
    self_addr_ = self_addr;
38
  }
39
  return ret;
40
}
41

42
int ObSnapshotInfoManager::acquire_snapshot(
43
    common::ObMySQLTransaction &trans,
44
    const uint64_t tenant_id,
45
    const ObSnapshotInfo &snapshot)
46
{
47
  int ret = OB_SUCCESS;
48
  ObSnapshotTableProxy snapshot_proxy;
49
  if (!snapshot.is_valid()) {
50
    ret = OB_INVALID_ARGUMENT;
51
    LOG_WARN("invalid argument", K(ret), K(snapshot));
52
  } else if (OB_FAIL(snapshot_proxy.add_snapshot(trans, snapshot))) {
53
    LOG_WARN("fail to add snapshot", K(ret), K(tenant_id), K(snapshot));
54
  }
55
  ROOTSERVICE_EVENT_ADD("snapshot", "acquire_snapshot", K(ret), K(snapshot), "rs_addr", self_addr_);
56
  return ret;
57
}
58

59
int ObSnapshotInfoManager::batch_acquire_snapshot(
60
    common::ObMySQLProxy &proxy,
61
    share::ObSnapShotType snapshot_type,
62
    const uint64_t tenant_id,
63
    const int64_t schema_version,
64
    const SCN &snapshot_scn,
65
    const char *comment,
66
    const common::ObIArray<ObTabletID> &tablet_ids)
67
{
68
  int ret = OB_SUCCESS;
69
  ObMySQLTransaction trans;
70
  ObSnapshotTableProxy snapshot_proxy;
71
  ObSnapshotInfo snapshot;
72
  ObTimeoutCtx timeout_ctx;
73
  snapshot.snapshot_type_ = snapshot_type;
74
  snapshot.tenant_id_ = tenant_id;
75
  snapshot.snapshot_scn_ = snapshot_scn;
76
  snapshot.schema_version_ = schema_version;
77
  snapshot.comment_ = comment;
78
  if (OB_UNLIKELY(!snapshot.is_valid() || tablet_ids.count() <= 0)) {
79
    ret = OB_INVALID_ARGUMENT;
80
    LOG_WARN("invalid argument", K(ret), K(tablet_ids.count()));
81
  } else {
82
    int64_t rpc_timeout = 0;
83
    int64_t trx_timeout = 0;
84
    if (OB_FAIL(ObDDLUtil::get_ddl_rpc_timeout(tablet_ids.count(), rpc_timeout))) {
85
      LOG_WARN("get ddl rpc timeout failed", K(ret), K(tablet_ids.count()));
86
    } else if (OB_FAIL(ObDDLUtil::get_ddl_tx_timeout(tablet_ids.count(), trx_timeout))) {
87
      LOG_WARN("get ddl tx timeout failed", K(ret), K(tablet_ids.count()));
88
    } else if (OB_FAIL(timeout_ctx.set_trx_timeout_us(trx_timeout))) {
89
      LOG_WARN("set trx timeout failed", K(ret), K(trx_timeout));
90
    } else if (OB_FAIL(timeout_ctx.set_timeout(rpc_timeout))) {
91
      LOG_WARN("set timeout failed", K(ret), K(rpc_timeout));
92
    } else if (OB_FAIL(trans.start(&proxy, tenant_id))) {
93
      LOG_WARN("fail to start trans", K(ret), K(tenant_id));
94
    } else if (OB_FAIL(snapshot_proxy.batch_add_snapshot(trans, snapshot_type,
95
        tenant_id, schema_version, snapshot.snapshot_scn_, comment, tablet_ids))) {
96
      LOG_WARN("batch add snapshot failed", K(ret));
97
    } else {
98
      bool need_commit = (ret == OB_SUCCESS);
99
      int tmp_ret = trans.end(need_commit);
100
      if (OB_SUCCESS != tmp_ret) {
101
        LOG_WARN("fail to end trans", K(tmp_ret), K(need_commit));
102
      }
103
      ret = OB_SUCC(ret) ? tmp_ret : ret;
104
    }
105
    ROOTSERVICE_EVENT_ADD("snapshot", "batch_acquire_snapshot", K(ret), K(snapshot), "rs_addr", self_addr_);
106
  }
107
  
108
  return ret;
109
}
110

111
int ObSnapshotInfoManager::release_snapshot(
112
    common::ObMySQLTransaction &trans,
113
    const uint64_t tenant_id,
114
    const ObSnapshotInfo &snapshot)
115
{
116
  int ret = OB_SUCCESS;
117
  ObSnapshotTableProxy snapshot_proxy;
118
  if (!snapshot.is_valid()) {
119
     ret = OB_INVALID_ARGUMENT;
120
     LOG_WARN("invalid argument", K(ret), K(snapshot));
121
  } else if (OB_FAIL(snapshot_proxy.remove_snapshot(trans, tenant_id, snapshot))) {
122
    LOG_WARN("fail to remove snapshot", K(ret), K(tenant_id), K(snapshot));
123
  }
124
  ROOTSERVICE_EVENT_ADD("snapshot", "release_snapshot", K(ret), K(snapshot), "rs_addr", self_addr_);
125
  return ret;
126
}
127

128
int ObSnapshotInfoManager::batch_release_snapshot_in_trans(
129
    common::ObMySQLTransaction &trans,
130
    share::ObSnapShotType snapshot_type,
131
    const uint64_t tenant_id,
132
    const int64_t schema_version,
133
    const SCN &snapshot_scn,
134
    const common::ObIArray<ObTabletID> &tablet_ids)
135
{
136
  int ret = OB_SUCCESS;
137
  ObSnapshotTableProxy snapshot_proxy;
138
  ObSnapshotInfo snapshot;
139
  snapshot.snapshot_type_ = snapshot_type;
140
  snapshot.tenant_id_ = tenant_id;
141
  snapshot.snapshot_scn_ = snapshot_scn;
142
  snapshot.schema_version_ = schema_version;
143
  if (OB_UNLIKELY(tablet_ids.count() <= 0)) {
144
    ret = OB_INVALID_ARGUMENT;
145
    LOG_WARN("invalid argument", K(ret), K(tablet_ids.count()));
146
  } else if (OB_FAIL(snapshot_proxy.batch_remove_snapshots(trans,
147
                                                           snapshot_type,
148
                                                           tenant_id,
149
                                                           schema_version,
150
                                                           snapshot.snapshot_scn_,
151
                                                           tablet_ids))) {
152
    LOG_WARN("fail to batch remove snapshots", K(ret));
153
  }
154
  ROOTSERVICE_EVENT_ADD("snapshot", "batch_release_snapshot", K(ret), K(snapshot), "rs_addr", self_addr_);
155
  return ret;
156
}
157

158
int ObSnapshotInfoManager::get_snapshot(common::ObMySQLProxy &proxy,
159
                                        const uint64_t tenant_id,
160
                                        share::ObSnapShotType snapshot_type,
161
                                        const char *extra_info,
162
                                        ObSnapshotInfo &snapshot_info)
163
{
164
  int ret = OB_SUCCESS;
165
  ObSnapshotTableProxy snapshot_proxy;
166
  if (OB_FAIL(snapshot_proxy.get_snapshot(proxy, tenant_id, snapshot_type, extra_info, snapshot_info))) {
167
    if (OB_ITER_END == ret) {
168
    } else {
169
      LOG_WARN("fail to get snapshot", K(ret));
170
    }
171
  }
172

173
  return ret;
174
}
175

176
int ObSnapshotInfoManager::get_snapshot(common::ObMySQLProxy &proxy,
177
                                        const uint64_t tenant_id,
178
                                        share::ObSnapShotType snapshot_type,
179
                                        const SCN &snapshot_scn,
180
                                        share::ObSnapshotInfo &snapshot_info)
181
{
182
  int ret = OB_SUCCESS;
183
  ObSnapshotTableProxy snapshot_proxy;
184
  if (OB_FAIL(snapshot_proxy.get_snapshot(proxy, tenant_id, snapshot_type, snapshot_scn, snapshot_info))) {
185
    if (OB_ITER_END == ret) {
186
    } else {
187
      LOG_WARN("fail to get snapshot", KR(ret), K(snapshot_type), K(snapshot_scn));
188
    }
189
  }
190
  return ret;
191
}
192

193
int ObSnapshotInfoManager::check_restore_point(common::ObMySQLProxy &proxy,
194
                                               const uint64_t tenant_id,
195
                                               const int64_t table_id,
196
                                               bool &is_exist)
197
{
198
  int ret = OB_SUCCESS;
199
  is_exist = false;
200
  ObSnapshotTableProxy snapshot_proxy;
201
  if (OB_FAIL(snapshot_proxy.check_snapshot_exist(proxy, tenant_id, table_id,
202
      share::SNAPSHOT_FOR_RESTORE_POINT, is_exist))) {
203
    LOG_WARN("fail to check snapshot exist", K(ret), K(tenant_id), K(table_id));
204
  }
205
  return ret;
206
}
207

208
int ObSnapshotInfoManager::get_snapshot_count(common::ObMySQLProxy &proxy,
209
                                              const uint64_t tenant_id,
210
                                              share::ObSnapShotType snapshot_type,
211
                                              int64_t &count)
212
{
213
  int ret = OB_SUCCESS;
214
  ObSnapshotTableProxy snapshot_proxy;
215
  if (OB_FAIL(snapshot_proxy.get_snapshot_count(proxy, tenant_id, snapshot_type, count))) {
216
    LOG_WARN("fail to get snapshot count", K(ret), K(tenant_id), K(snapshot_type));
217
  }
218
  return ret;
219
}
220

221
} //end rootserver
222
} //end oceanbase
223

224

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.