ob_backup_struct.cpp 178.8 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/**
 * 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 SHARE
#include "ob_backup_struct.h"
#include "common/ob_record_header.h"
#include "share/config/ob_server_config.h"
#include "share/schema/ob_multi_version_schema_service.h"
#include "share/backup/ob_backup_path.h"
#include "share/backup/ob_backup_lease_info_mgr.h"
20
#include "storage/transaction/ob_i_ts_source.h"
O
oceanbase-admin 已提交
21 22 23 24 25 26

using namespace oceanbase;
using namespace lib;
using namespace common;
using namespace share;

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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
int share::get_backup_backup_start_copy_id(const ObBackupBackupCopyIdLevel& copy_id_level, int64_t& copy_id)
{
  int ret = OB_SUCCESS;
  if (OB_BB_COPY_ID_LEVEL_CLUSTER_GCONF_DEST == copy_id_level) {
    copy_id = OB_START_COPY_ID;
  } else if (OB_BB_COPY_ID_LEVEL_CLUSTER_USER_DEST == copy_id_level) {
    copy_id = OB_CLUSTER_USER_DEST_START_COPY_ID;
  } else if (OB_BB_COPY_ID_LEVEL_TENANT_GCONF_DEST == copy_id_level) {
    copy_id = OB_TENANT_GCONF_DEST_START_COPY_ID;
  } else if (OB_BB_COPY_ID_LEVEL_TENANT_USER_DEST == copy_id_level) {
    copy_id = OB_TENANT_USER_DEST_START_COPY_ID;
  } else {
    ret = OB_ERR_UNEXPECTED;
  }
  return ret;
}

int share::get_backup_copy_id_range_by_copy_level(
    const ObBackupBackupCopyIdLevel& copy_id_level, int64_t& left_copy_id, int64_t& right_copy_id)
{
  int ret = OB_SUCCESS;
  if (OB_BB_COPY_ID_LEVEL_CLUSTER_GCONF_DEST == copy_id_level) {
    left_copy_id = OB_START_COPY_ID;
    right_copy_id = OB_CLUSTER_USER_DEST_START_COPY_ID;
  } else if (OB_BB_COPY_ID_LEVEL_CLUSTER_USER_DEST == copy_id_level) {
    left_copy_id = OB_CLUSTER_USER_DEST_START_COPY_ID;
    right_copy_id = OB_TENANT_GCONF_DEST_START_COPY_ID;
  } else if (OB_BB_COPY_ID_LEVEL_TENANT_GCONF_DEST == copy_id_level) {
    left_copy_id = OB_TENANT_GCONF_DEST_START_COPY_ID;
    right_copy_id = OB_TENANT_USER_DEST_START_COPY_ID;
  } else if (OB_BB_COPY_ID_LEVEL_TENANT_USER_DEST == copy_id_level) {
    left_copy_id = OB_TENANT_USER_DEST_START_COPY_ID;
    right_copy_id = OB_MAX_COPY_ID;
  } else {
    ret = OB_ERR_UNEXPECTED;
  }
  return ret;
}

bool share::has_independ_inc_backup_set(const int64_t version)
{
  return version >= OB_BACKUP_COMPATIBLE_VERSION_V2 && version < OB_BACKUP_COMPATIBLE_VERSION_MAX;
}
bool share::is_valid_backup_inner_table_version(const ObBackupInnerTableVersion& version)
{
  return version > 0 && version < OB_BACKUP_INNER_TABLE_VMAX;
}

OB_SERIALIZE_MEMBER(ObSimpleBackupSetPath, backup_set_id_, copy_id_, backup_dest_, file_status_);
OB_SERIALIZE_MEMBER(ObSimpleBackupPiecePath, backup_piece_id_, copy_id_, backup_dest_, file_status_, round_id_);

ObSimpleBackupSetPath::ObSimpleBackupSetPath() : backup_set_id_(-1), copy_id_(0), backup_dest_(), file_status_()
{}

ObSimpleBackupSetPath::~ObSimpleBackupSetPath()
{}

void ObSimpleBackupSetPath::reset()
{
  backup_set_id_ = -1;
  copy_id_ = 0;
  backup_dest_.reset();
}

int ObSimpleBackupSetPath::set(const share::ObBackupBaseDataPathInfo& path_info)
{
  int ret = OB_SUCCESS;
  ObBackupPath backup_path;
  ObBackupDest backup_dest;
  char tmp_buf[OB_MAX_BACKUP_DEST_LENGTH] = "";

  if (!path_info.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    COMMON_LOG(WARN, "invalid argument", K(ret), K(path_info));
  } else if (OB_FAIL(ObBackupPathUtil::get_tenant_data_full_backup_set_path(path_info, backup_path))) {
    COMMON_LOG(WARN, "failed to get tenant data full backup set path", K(ret), K(path_info));
  } else if (OB_FAIL(backup_dest.set(backup_path.get_ptr(), path_info.dest_.get_storage_info()))) {
    COMMON_LOG(WARN, "failed to set backup dest", K(ret), K(backup_path));
  } else if (OB_FAIL(backup_dest.get_backup_dest_str(tmp_buf, OB_MAX_BACKUP_DEST_LENGTH))) {
    COMMON_LOG(WARN, "failed to get backup dest str", K(ret), K(backup_dest));
  } else if (OB_FAIL(backup_dest_.assign(tmp_buf))) {
    COMMON_LOG(WARN, "failed to assign str", K(ret), K(tmp_buf));
  } else {
    backup_set_id_ = path_info.inc_backup_set_id_;
  }
  return ret;
}

int ObSimpleBackupSetPath::set(const common::ObString& uri)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(backup_dest_.assign(uri))) {
    COMMON_LOG(WARN, "failed to assign str", K(ret), K(uri));
  } else {
    backup_set_id_ = 1;  // fake
  }
  return ret;
}

int ObSimpleBackupSetPath::set(const common::ObString& path, const common::ObString& storage_info)
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  char backup_path_str[OB_MAX_BACKUP_DEST_LENGTH] = "";
  if (OB_FAIL(backup_dest.set(path.ptr(), storage_info.ptr()))) {
    LOG_WARN("failed to set backup dest", KR(ret), K(path), K(storage_info));
  } else if (OB_FAIL(backup_dest.get_backup_dest_str(backup_path_str, OB_MAX_BACKUP_DEST_LENGTH))) {
    LOG_WARN("failed to get backup dest str", KR(ret), K(backup_dest));
  } else if (OB_FAIL(backup_dest_.assign(backup_path_str))) {
    LOG_WARN("failed to assign str", KR(ret));
  } else {
    backup_set_id_ = 1;  // fake
  }
  return ret;
}

bool ObSimpleBackupSetPath::is_valid() const
{
  return backup_set_id_ > 0 && copy_id_ >= 0 && !backup_dest_.is_empty();
}

common::ObString ObSimpleBackupSetPath::get_simple_path() const
{
  int64_t pos = 0;
  const char* str = backup_dest_.ptr();
  char* ptr = const_cast<char*>(str);
  while (ptr[pos] != '\0') {
    if (ptr[pos] == '?') {
      break;
    }
    ++pos;
  }
  return ObString(pos, str);
}

common::ObString ObSimpleBackupSetPath::get_storage_info() const
{
  ObString res;
  int64_t pos = 0;
  const char* str = backup_dest_.ptr();
  char* ptr = const_cast<char*>(str);
  while (ptr[pos] != '\0') {
    if (ptr[pos] == '?') {
      break;
    }
    ++pos;
  }
  if (ptr[pos] == '\0') {
    res = "";
  } else {
    ++ptr;
    res = ObString(strlen(ptr) - pos, ptr + pos);
  }
  return res;
}

ObSimpleBackupPiecePath::ObSimpleBackupPiecePath()
    : round_id_(-1), backup_piece_id_(-1), copy_id_(0), backup_dest_(), file_status_()
{}

ObSimpleBackupPiecePath::~ObSimpleBackupPiecePath()
{}

void ObSimpleBackupPiecePath::reset()
{
  round_id_ = -1;
  backup_piece_id_ = -1;
  copy_id_ = 0;
  backup_dest_.reset();
}

int ObSimpleBackupPiecePath::set(const common::ObString& uri)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(backup_dest_.assign(uri))) {
    COMMON_LOG(WARN, "failed to assign str", K(ret), K(uri));
  } else {
    backup_piece_id_ = 1;  // fake
  }
  return ret;
}

int ObSimpleBackupPiecePath::set(const common::ObString& path, const common::ObString& storage_info)
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  char backup_path_str[OB_MAX_BACKUP_DEST_LENGTH] = "";
  if (OB_FAIL(backup_dest.set(path.ptr(), storage_info.ptr()))) {
    LOG_WARN("failed to set backup dest", KR(ret), K(path), K(storage_info));
  } else if (OB_FAIL(backup_dest.get_backup_dest_str(backup_path_str, OB_MAX_BACKUP_DEST_LENGTH))) {
    LOG_WARN("failed to get backup dest str", KR(ret), K(backup_dest));
  } else if (OB_FAIL(backup_dest_.assign(backup_path_str))) {
    LOG_WARN("failed to assign str", KR(ret));
  } else {
    backup_piece_id_ = 1;  // fake
  }
  return ret;
}

bool ObSimpleBackupPiecePath::is_valid() const
{
  return backup_piece_id_ >= 0 && copy_id_ >= 0 && !backup_dest_.is_empty();
}

common::ObString ObSimpleBackupPiecePath::get_simple_path() const
{
  int64_t pos = 0;
  const char* str = backup_dest_.ptr();
  char* ptr = const_cast<char*>(str);
  while (ptr[pos] != '\0') {
    if (ptr[pos] == '?') {
      break;
    }
    ++pos;
  }
  return ObString(pos, str);
}

common::ObString ObSimpleBackupPiecePath::get_storage_info() const
{
  ObString res;
  int64_t pos = 0;
  const char* str = backup_dest_.ptr();
  char* ptr = const_cast<char*>(str);
  while (ptr[pos] != '\0') {
    if (ptr[pos] == '?') {
      break;
    }
    ++pos;
  }
  if (ptr[pos] == '\0') {
    res = "";
  } else {
    ++ptr;
    res = ObString(strlen(ptr) - pos, ptr + pos);
  }
  return res;
}

bool ObCompareSimpleBackupSetPath::operator()(
    const share::ObSimpleBackupSetPath& lhs, const share::ObSimpleBackupSetPath& rhs)
{
  bool bret = false;
  if (lhs.backup_set_id_ != rhs.backup_set_id_) {
    bret = lhs.backup_set_id_ < rhs.backup_set_id_;
  } else {
    bret = lhs.copy_id_ < rhs.copy_id_;
  }
  return bret;
}

bool ObCompareSimpleBackupPiecePath::operator()(
    const share::ObSimpleBackupPiecePath& lhs, const share::ObSimpleBackupPiecePath& rhs)
{
  bool bret = false;
  if (lhs.backup_piece_id_ != rhs.backup_piece_id_) {
    bret = lhs.backup_piece_id_ < rhs.backup_piece_id_;
  } else {
    bret = lhs.copy_id_ < rhs.copy_id_;
  }
  return bret;
}

OB_SERIALIZE_MEMBER(ObPhysicalRestoreBackupDestList, backup_set_path_list_, backup_piece_path_list_);

ObPhysicalRestoreBackupDestList::ObPhysicalRestoreBackupDestList()
    : allocator_(), backup_set_path_list_(), backup_piece_path_list_()
{}

ObPhysicalRestoreBackupDestList::~ObPhysicalRestoreBackupDestList()
{
  reset();
}

void ObPhysicalRestoreBackupDestList::reset()
{
  backup_set_path_list_.reset();
  backup_piece_path_list_.reset();
  allocator_.reset();
}

int ObPhysicalRestoreBackupDestList::assign(const ObPhysicalRestoreBackupDestList& list)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(backup_set_path_list_.assign(list.backup_set_path_list_))) {
    LOG_WARN("failed to assign backup set path list", KR(ret));
  } else if (OB_FAIL(backup_piece_path_list_.assign(list.backup_piece_path_list_))) {
    LOG_WARN("failed to assign backup piece path list", KR(ret));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::set(const common::ObArray<share::ObSimpleBackupSetPath>& backup_set_list,
    const common::ObArray<share::ObSimpleBackupPiecePath>& backup_piece_list)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(backup_set_path_list_.assign(backup_set_list))) {
    LOG_WARN("failed to assign", KR(ret));
  } else if (OB_FAIL(backup_piece_path_list_.assign(backup_piece_list))) {
    LOG_WARN("failed to assign", KR(ret));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::get_backup_set_list_format_str(
    common::ObIAllocator& allocator, common::ObString& str) const
{
  int ret = OB_SUCCESS;
  char* str_buf = NULL;
  int64_t str_buf_len = get_backup_set_list_format_str_len() + 1;
  if (str_buf_len > OB_MAX_LONGTEXT_LENGTH + 1) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("format str is too long", KR(ret), K(str_buf_len));
  } else if (OB_ISNULL(str_buf = static_cast<char*>(allocator.alloc(str_buf_len)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc buf", KR(ret), K(str_buf_len));
  } else if (backup_set_path_list_.count() <= 0) {
    MEMSET(str_buf, '\0', str_buf_len);
  } else {
    int64_t pos = 0;
    for (int64_t i = 0; OB_SUCC(ret) && i < backup_set_path_list_.count(); i++) {
      const share::ObSimpleBackupSetPath& item = backup_set_path_list_.at(i);
      if (OB_FAIL(databuff_printf(str_buf,
              str_buf_len,
              pos,
              "%s%.*s",
              0 == i ? "" : ",",
              static_cast<int>(item.backup_dest_.size()),
              item.backup_dest_.ptr()))) {
        LOG_WARN("fail to append str", KR(ret), K(item), K(pos), K(str_buf));
      }
    }
  }
  if (OB_FAIL(ret)) {
  } else if (OB_ISNULL(str_buf) || str_buf_len <= 0) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("unexpected format str", KR(ret), K(str_buf), K(str_buf_len));
  } else {
    str.assign_ptr(str_buf, str_buf_len - 1);
    LOG_DEBUG("get format backup set path list str", KR(ret), K(str));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::get_backup_piece_list_format_str(
    common::ObIAllocator& allocator, common::ObString& str) const
{
  int ret = OB_SUCCESS;
  char* str_buf = NULL;
  int64_t str_buf_len = get_backup_piece_list_format_str_len() + 1;
  if (str_buf_len > OB_MAX_LONGTEXT_LENGTH + 1) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("format str is too long", KR(ret), K(str_buf_len));
  } else if (OB_ISNULL(str_buf = static_cast<char*>(allocator.alloc(str_buf_len)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc buf", KR(ret), K(str_buf_len));
  } else if (backup_piece_path_list_.count() <= 0) {
    MEMSET(str_buf, '\0', str_buf_len);
  } else {
    int64_t pos = 0;
    for (int64_t i = 0; OB_SUCC(ret) && i < backup_piece_path_list_.count(); i++) {
      const share::ObSimpleBackupPiecePath& item = backup_piece_path_list_.at(i);
      if (OB_FAIL(databuff_printf(str_buf,
              str_buf_len,
              pos,
              "%s%.*s",
              0 == i ? "" : ",",
              static_cast<int>(item.backup_dest_.size()),
              item.backup_dest_.ptr()))) {
        LOG_WARN("fail to append str", KR(ret), K(item), K(pos), K(str_buf));
      }
    }
  }
  if (OB_FAIL(ret)) {
  } else if (OB_ISNULL(str_buf) || str_buf_len <= 0) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("unexpected format str", KR(ret), K(str_buf), K(str_buf_len));
  } else {
    str.assign_ptr(str_buf, str_buf_len - 1);
    LOG_DEBUG("get format backup piece path list str", KR(ret), K(str));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::backup_set_list_assign_with_hex_str(const common::ObString& str)
{
  int ret = OB_SUCCESS;
  int64_t str_size = str.length();
  char* deserialize_buf = NULL;
  int64_t deserialize_size = str.length() / 2 + 1;
  int64_t deserialize_pos = 0;
  if (str_size <= 0) {
    // skip
  } else if (OB_ISNULL(deserialize_buf = static_cast<char*>(allocator_.alloc(deserialize_size)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc memory", KR(ret), K(deserialize_size));
  } else if (OB_FAIL(hex_to_cstr(str.ptr(), str_size, deserialize_buf, deserialize_size))) {
    LOG_WARN("fail to get cstr from hex", KR(ret), K(str_size), K(deserialize_size), K(str));
  } else if (OB_FAIL(backup_set_path_list_.deserialize(deserialize_buf, deserialize_size, deserialize_pos))) {
    LOG_WARN("fail to deserialize backup set path list",
        KR(ret),
        K(str),
        "deserialize_buf",
        ObString(deserialize_size, deserialize_buf));
  } else if (deserialize_pos > deserialize_size) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("deserialize error", KR(ret), K(deserialize_pos), K(deserialize_size));
  } else {
    LOG_DEBUG("assign with hex str", KR(ret), K(str));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::backup_piece_list_assign_with_hex_str(const common::ObString& str)
{
  int ret = OB_SUCCESS;
  int64_t str_size = str.length();
  char* deserialize_buf = NULL;
  int64_t deserialize_size = str.length() / 2 + 1;
  int64_t deserialize_pos = 0;
  if (str_size <= 0) {
    // skip
  } else if (OB_ISNULL(deserialize_buf = static_cast<char*>(allocator_.alloc(deserialize_size)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc memory", KR(ret), K(deserialize_size));
  } else if (OB_FAIL(hex_to_cstr(str.ptr(), str_size, deserialize_buf, deserialize_size))) {
    LOG_WARN("fail to get cstr from hex", KR(ret), K(str_size), K(deserialize_size), K(str));
  } else if (OB_FAIL(backup_piece_path_list_.deserialize(deserialize_buf, deserialize_size, deserialize_pos))) {
    LOG_WARN("fail to deserialize backup piece path list",
        KR(ret),
        K(str),
        "deserialize_buf",
        ObString(deserialize_size, deserialize_buf));
  } else if (deserialize_pos > deserialize_size) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("deserialize error", KR(ret), K(deserialize_pos), K(deserialize_size));
  } else {
    LOG_DEBUG("assign with hex str", KR(ret), K(str));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::get_backup_set_list_hex_str(
    common::ObIAllocator& allocator, common::ObString& str) const
{
  int ret = OB_SUCCESS;
  char* serialize_buf = NULL;
  int64_t serialize_size = backup_set_path_list_.get_serialize_size();
  int64_t serialize_pos = 0;
  char* hex_buf = NULL;
  int64_t hex_size = 2 * serialize_size;
  int64_t hex_pos = 0;
  if (serialize_size > OB_MAX_LONGTEXT_LENGTH / 2) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("serialize_size is too long", KR(ret), K(serialize_size));
  } else if (OB_ISNULL(serialize_buf = static_cast<char*>(allocator.alloc(serialize_size)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc memory", KR(ret));
  } else if (OB_FAIL(backup_set_path_list_.serialize(serialize_buf, serialize_size, serialize_pos))) {
    LOG_WARN("fail to serialize table_items", KR(ret), K_(backup_set_path_list));
  } else if (serialize_pos > serialize_size) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("serialize error", KR(ret), K(serialize_pos), K(serialize_size));
  } else if (OB_ISNULL(hex_buf = static_cast<char*>(allocator.alloc(hex_size)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc memory", KR(ret), K(hex_size));
  } else if (OB_FAIL(hex_print(serialize_buf, serialize_pos, hex_buf, hex_size, hex_pos))) {
    LOG_WARN("fail to print hex", KR(ret), K(serialize_pos), K(hex_size));
  } else if (hex_pos > hex_size) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("encode error", KR(ret), K(hex_pos), K(hex_size));
  } else {
    str.assign_ptr(hex_buf, hex_size);
    LOG_DEBUG("get hex backup set list str", KR(ret), K(str));
  }
  return ret;
}

int ObPhysicalRestoreBackupDestList::get_backup_piece_list_hex_str(
    common::ObIAllocator& allocator, common::ObString& str) const
{
  int ret = OB_SUCCESS;
  char* serialize_buf = NULL;
  int64_t serialize_size = backup_piece_path_list_.get_serialize_size();
  int64_t serialize_pos = 0;
  char* hex_buf = NULL;
  int64_t hex_size = 2 * serialize_size;
  int64_t hex_pos = 0;
  if (serialize_size > OB_MAX_LONGTEXT_LENGTH / 2) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("serialize_size is too long", KR(ret), K(serialize_size));
  } else if (OB_ISNULL(serialize_buf = static_cast<char*>(allocator.alloc(serialize_size)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc memory", KR(ret));
  } else if (OB_FAIL(backup_piece_path_list_.serialize(serialize_buf, serialize_size, serialize_pos))) {
    LOG_WARN("fail to serialize table_items", KR(ret), K_(backup_piece_path_list));
  } else if (serialize_pos > serialize_size) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("serialize error", KR(ret), K(serialize_pos), K(serialize_size));
  } else if (OB_ISNULL(hex_buf = static_cast<char*>(allocator.alloc(hex_size)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("fail to alloc memory", KR(ret), K(hex_size));
  } else if (OB_FAIL(hex_print(serialize_buf, serialize_pos, hex_buf, hex_size, hex_pos))) {
    LOG_WARN("fail to print hex", KR(ret), K(serialize_pos), K(hex_size));
  } else if (hex_pos > hex_size) {
    ret = OB_SIZE_OVERFLOW;
    LOG_WARN("encode error", KR(ret), K(hex_pos), K(hex_size));
  } else {
    str.assign_ptr(hex_buf, hex_size);
    LOG_DEBUG("get hex backup piece list str", KR(ret), K(str));
  }
  return ret;
}

int64_t ObPhysicalRestoreBackupDestList::get_backup_set_list_format_str_len() const
{
  int64_t length = 0;
  for (int64_t i = 0; i < backup_set_path_list_.count(); ++i) {
    const ObSimpleBackupSetPath& path = backup_set_path_list_.at(i);
    length += path.backup_dest_.size() + (0 == i ? 0 : 1);
  }
  return length;
}

int64_t ObPhysicalRestoreBackupDestList::get_backup_piece_list_format_str_len() const
{
  int64_t length = 0;
  for (int64_t i = 0; i < backup_piece_path_list_.count(); ++i) {
    const ObSimpleBackupPiecePath& path = backup_piece_path_list_.at(i);
    length += path.backup_dest_.size() + (0 == i ? 0 : 1);
  }
  return length;
}

O
oceanbase-admin 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
/******************ObBackupCommonHeader*******************/
ObBackupCommonHeader::ObBackupCommonHeader()
{
  reset();
}

void ObBackupCommonHeader::reset()
{
  memset(this, 0, sizeof(ObBackupCommonHeader));
  header_version_ = COMMON_HEADER_VERSION;
  compressor_type_ = static_cast<uint8_t>(common::ObCompressorType::INVALID_COMPRESSOR);
  data_type_ = static_cast<uint16_t>(ObBackupFileType::BACKUP_TYPE_MAX);
  header_length_ = static_cast<uint16_t>(sizeof(ObBackupCommonHeader));
}

void ObBackupCommonHeader::set_header_checksum()
{
  header_checksum_ = calc_header_checksum();
}

int ObBackupCommonHeader::set_checksum(const char* buf, const int64_t len)
{
  int ret = OB_SUCCESS;

  if (OB_ISNULL(buf) || len < 0 || data_zlength_ != len) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), KP(buf), K(len), K_(data_zlength));
  } else {
    data_checksum_ = ob_crc64(buf, len);
    header_checksum_ = calc_header_checksum();
  }
  return ret;
}

int ObBackupCommonHeader::check_header_checksum() const
{
  int ret = OB_SUCCESS;
  int16_t checksum = calc_header_checksum();
  if (OB_UNLIKELY(header_checksum_ != checksum)) {
    ret = OB_CHECKSUM_ERROR;
    COMMON_LOG(WARN, "check header checksum failed.", K(*this), K(checksum), K(ret));
  }
  return ret;
}

int16_t ObBackupCommonHeader::calc_header_checksum() const
{
  int16_t checksum = 0;

  checksum = static_cast<int16_t>(checksum ^ static_cast<int16_t>(header_version_));
  checksum = static_cast<int16_t>(checksum ^ static_cast<int16_t>(compressor_type_));
  checksum = checksum ^ data_type_;
  checksum = checksum ^ header_length_;
  format_i64(data_length_, checksum);
  format_i64(data_zlength_, checksum);
  format_i64(data_checksum_, checksum);
  format_i64(align_length_, checksum);
  return checksum;
}

int ObBackupCommonHeader::check_valid() const
{
  int ret = OB_SUCCESS;

  if (COMMON_HEADER_VERSION != header_version_ || ObCompressorType::INVALID_COMPRESSOR == compressor_type_ ||
      ((ObCompressorType::NONE_COMPRESSOR == compressor_type_) && (data_length_ != data_zlength_)) ||
      data_type_ >= ObBackupFileType::BACKUP_TYPE_MAX || header_length_ != sizeof(ObBackupCommonHeader) ||
      align_length_ < 0) {
    ret = OB_INVALID_ERROR;
    COMMON_LOG(WARN, "invalid header", K(ret), K(*this), "ObBackupCommonHeader size", sizeof(ObBackupCommonHeader));
  } else if (OB_FAIL(check_header_checksum())) {
    COMMON_LOG(WARN, "header checksum error", K(ret));
  }

  return ret;
}

bool ObBackupCommonHeader::is_compresssed_data() const
{
  return (data_length_ != data_zlength_) || (compressor_type_ > ObCompressorType::NONE_COMPRESSOR);
}

int ObBackupCommonHeader::check_data_checksum(const char* buf, const int64_t len) const
{
  int ret = OB_SUCCESS;
  if (NULL == buf || len < 0) {
    ret = OB_INVALID_ARGUMENT;
    COMMON_LOG(WARN, "invalid argument.", K(ret), KP(buf), K(len));
  } else if ((0 == len) && (0 != data_length_ || 0 != data_zlength_ || 0 != data_checksum_)) {
    ret = OB_INVALID_ARGUMENT;
    COMMON_LOG(WARN, "invalid argument.", K(ret), K(len), K_(data_length), K_(data_zlength), K_(data_checksum));
  } else if (data_zlength_ != len) {
    ret = OB_INVALID_ARGUMENT;
    COMMON_LOG(WARN, "invalid argument.", K(ret), K(len), K_(data_zlength));
  } else {
    int64_t crc_check_sum = ob_crc64(buf, len);
    if (crc_check_sum != data_checksum_) {
      ret = OB_CHECKSUM_ERROR;
      COMMON_LOG(WARN, "checksum error", K(crc_check_sum), K_(data_checksum), K(ret));
    }
  }
  return ret;
}

/******************ObBackupMetaHeader*******************/
ObBackupMetaHeader::ObBackupMetaHeader()
{
  reset();
}

void ObBackupMetaHeader::reset()
{
  memset(this, 0, sizeof(ObBackupMetaHeader));
  header_version_ = META_HEADER_VERSION;
  meta_type_ = static_cast<uint8_t>(ObBackupMetaType::META_TYPE_MAX);
}

void ObBackupMetaHeader::set_header_checksum()
{
  header_checksum_ = calc_header_checksum();
}

int ObBackupMetaHeader::set_checksum(const char* buf, const int64_t len)
{
  int ret = OB_SUCCESS;

  if (OB_ISNULL(buf) || len < 0 || data_length_ != len) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), KP(buf), K(len), K_(data_length));
  } else {
    data_checksum_ = ob_crc64(buf, len);
    header_checksum_ = calc_header_checksum();
  }
  return ret;
}

int ObBackupMetaHeader::check_header_checksum() const
{
  int ret = OB_SUCCESS;
  int16_t checksum = calc_header_checksum();
  if (OB_UNLIKELY(header_checksum_ != checksum)) {
    ret = OB_CHECKSUM_ERROR;
    COMMON_LOG(WARN, "check header checksum failed.", K(*this), K(checksum), K(ret));
  }
  return ret;
}

int16_t ObBackupMetaHeader::calc_header_checksum() const
{
  int16_t checksum = 0;

  checksum = static_cast<int16_t>(checksum ^ static_cast<int16_t>(header_version_));
  checksum = static_cast<int16_t>(checksum ^ static_cast<int16_t>(meta_type_));
  format_i32(data_length_, checksum);
  format_i64(data_checksum_, checksum);

  return checksum;
}

int ObBackupMetaHeader::check_data_checksum(const char* buf, const int64_t len) const
{
  int ret = OB_SUCCESS;

  if (OB_ISNULL(buf) || len < 0 || data_length_ != len) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), KP(buf), K(len), K_(data_length));
  } else {
    int64_t checksum = ob_crc64(buf, len);
    if (OB_UNLIKELY(data_checksum_ != checksum)) {
      ret = OB_CHECKSUM_ERROR;
      COMMON_LOG(WARN, "check data checksum failed.", K(*this), K(checksum), K(ret));
    }
  }
  return ret;
}

int ObBackupMetaHeader::check_valid() const
{
  int ret = OB_SUCCESS;

  if (META_HEADER_VERSION != header_version_ || meta_type_ >= ObBackupFileType::BACKUP_TYPE_MAX) {
    ret = OB_INVALID_ERROR;
    COMMON_LOG(WARN, "invalid header", K(*this), K(ret));
  } else if (OB_FAIL(check_header_checksum())) {
    COMMON_LOG(WARN, "header checksum error", K(ret));
  }

  return ret;
}

/******************ObBackupMetaIndex*******************/
OB_SERIALIZE_MEMBER(ObBackupMetaIndex, meta_type_, table_id_, partition_id_, offset_, data_length_, task_id_);
ObBackupMetaIndex::ObBackupMetaIndex()
{
  reset();
}

void ObBackupMetaIndex::reset()
{
  memset(this, 0, sizeof(ObBackupMetaIndex));
  meta_type_ = static_cast<uint8_t>(ObBackupMetaType::META_TYPE_MAX);
}

int ObBackupMetaIndex::check_valid() const
{
  int ret = OB_SUCCESS;

  if (meta_type_ >= ObBackupFileType::BACKUP_TYPE_MAX) {
    ret = OB_INVALID_ERROR;
    COMMON_LOG(WARN, "invalid header", K(*this), K(ret));
  } else if (partition_id_ < 0 || offset_ < 0 || data_length_ < 0 || task_id_ < 0) {
    ret = OB_INVALID_ERROR;
    COMMON_LOG(WARN, "invalid  index", K(ret), K(*this));
  }

  return ret;
}

779 780 781 782 783 784
bool ObBackupMetaIndex::operator==(const ObBackupMetaIndex& other) const
{
  return table_id_ == other.table_id_ && partition_id_ == other.partition_id_ && meta_type_ == other.meta_type_ &&
         offset_ == other.offset_ && data_length_ == other.data_length_ && task_id_ == other.task_id_;
}

O
oceanbase-admin 已提交
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
/******************ObBackupMacroIndex*******************/
ObBackupMacroIndex::ObBackupMacroIndex()
{
  reset();
}

void ObBackupMacroIndex::reset()
{
  memset(this, 0, sizeof(ObBackupMacroIndex));
}

OB_SERIALIZE_MEMBER(ObBackupMacroIndex, table_id_, partition_id_, index_table_id_, sstable_macro_index_, data_version_,
    data_seq_, backup_set_id_, sub_task_id_, offset_, data_length_);

int ObBackupMacroIndex::check_valid() const
{
  int ret = OB_SUCCESS;

  if (!(table_id_ != OB_INVALID_ID && partition_id_ >= 0 && index_table_id_ != OB_INVALID_ID &&
          sstable_macro_index_ >= 0 && data_version_ >= 0 && data_seq_ >= 0 && backup_set_id_ >= 0 &&
          sub_task_id_ >= 0 && offset_ >= 0 && data_length_ >= 0)) {
    ret = OB_INVALID_ERROR;
    COMMON_LOG(WARN, "invalid index", K(*this), K(ret));
  }

  return ret;
}

/******************ObBackupSStableMacroIndex*******************/
ObBackupSStableMacroIndex::ObBackupSStableMacroIndex()
{
  reset();
}

void ObBackupSStableMacroIndex::reset()
{
  memset(this, 0, sizeof(ObBackupSStableMacroIndex));
  header_version_ = SSTABLE_MACRO_INDEX_VERSION;
  data_type_ = static_cast<uint8_t>(ObBackupFileType::BACKUP_SSTABLE_MACRO_INDEX);
  header_length_ = static_cast<uint16_t>(sizeof(ObBackupSStableMacroIndex));
}

void ObBackupSStableMacroIndex::set_header_checksum()
{
  header_checksum_ = calc_header_checksum();
}

int ObBackupSStableMacroIndex::check_header_checksum() const
{
  int ret = OB_SUCCESS;
  int16_t checksum = calc_header_checksum();
  if (OB_UNLIKELY(header_checksum_ != checksum)) {
    ret = OB_CHECKSUM_ERROR;
    COMMON_LOG(WARN, "check header checksum failed.", K(*this), K(checksum), K(ret));
  }
  return ret;
}

int16_t ObBackupSStableMacroIndex::calc_header_checksum() const
{
  int16_t checksum = 0;

  checksum = static_cast<int16_t>(checksum ^ static_cast<int16_t>(header_version_));
  checksum = static_cast<int16_t>(checksum ^ static_cast<int16_t>(data_type_));
  checksum = checksum ^ header_length_;
  checksum = checksum ^ reserved_;
  format_i64(table_id_, checksum);
  format_i64(partition_id_, checksum);
  format_i64(index_table_id_, checksum);
  format_i64(offset_, checksum);
  format_i64(count_, checksum);

  return checksum;
}

int ObBackupSStableMacroIndex::is_valid() const
{
  int ret = OB_SUCCESS;

  if (SSTABLE_MACRO_INDEX_VERSION != header_version_ || ObBackupFileType::BACKUP_SSTABLE_MACRO_INDEX != data_type_ ||
      header_length_ != sizeof(ObBackupSStableMacroIndex)) {
    ret = OB_INVALID_ERROR;
    COMMON_LOG(WARN, "invalid header", K(*this), K(ret));
  } else if (OB_FAIL(check_header_checksum())) {
    COMMON_LOG(WARN, "header checksum error", K(ret));
  }

  return ret;
}

ObMetaIndexKey::ObMetaIndexKey()
{
  reset();
}

ObMetaIndexKey::ObMetaIndexKey(const int64_t table_id, const int64_t partition_id, const uint8_t meta_type)
{
  table_id_ = table_id;
  partition_id_ = partition_id;
  meta_type_ = meta_type;
}

void ObMetaIndexKey::reset()
{
  table_id_ = OB_INVALID_ID;
  partition_id_ = -1;
  meta_type_ = ObBackupMetaType::META_TYPE_MAX;
}

bool ObMetaIndexKey::operator==(const ObMetaIndexKey& other) const
{
  return table_id_ == other.table_id_ && partition_id_ == other.partition_id_ && meta_type_ == other.meta_type_;
}

bool ObMetaIndexKey::operator!=(const ObMetaIndexKey& other) const
{
  return !(*this == other);
}

uint64_t ObMetaIndexKey::hash() const
{
  uint64_t hash_val = 0;
  hash_val = murmurhash(&table_id_, sizeof(table_id_), hash_val);
  hash_val = murmurhash(&partition_id_, sizeof(partition_id_), hash_val);
  hash_val = murmurhash(&meta_type_, sizeof(meta_type_), hash_val);
  return hash_val;
}

bool ObMetaIndexKey::is_valid() const
{
  return OB_INVALID_ID != table_id_ && partition_id_ >= 0 && meta_type_ < ObBackupMetaType::META_TYPE_MAX;
}

static const char* status_strs[] = {
    "INVALID",
    "STOP",
    "BEGINNING",
    "DOING",
    "STOPPING",
    "INTERRUPTED",
    "MIXED",
926
    "PAUSED",
O
oceanbase-admin 已提交
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
};

const char* ObLogArchiveStatus::get_str(const STATUS& status)
{
  const char* str = nullptr;

  if (status < 0 || status >= MAX) {
    str = "UNKNOWN";
  } else {
    str = status_strs[status];
  }
  return str;
}

ObLogArchiveStatus::STATUS ObLogArchiveStatus::get_status(const char* status_str)
{
  ObLogArchiveStatus::STATUS status = ObLogArchiveStatus::MAX;

  const int64_t count = ARRAYSIZEOF(status_strs);
  STATIC_ASSERT(static_cast<int64_t>(ObLogArchiveStatus::MAX) == count, "status count mismatch");
  for (int64_t i = 0; i < count; ++i) {
    if (0 == strcmp(status_str, status_strs[i])) {
      status = static_cast<ObLogArchiveStatus::STATUS>(i);
      break;
    }
  }
  return status;
}

956 957 958 959 960 961
OB_SERIALIZE_MEMBER(ObGetTenantLogArchiveStatusArg, incarnation_, round_, backup_piece_id_);

bool ObGetTenantLogArchiveStatusArg::is_valid() const
{
  return incarnation_ >= 1 && round_ >= 1;
}
O
oceanbase-admin 已提交
962 963 964

ObTenantLogArchiveStatus::ObTenantLogArchiveStatus()
    : tenant_id_(OB_INVALID_ID),
965
      copy_id_(0),
O
oceanbase-admin 已提交
966 967 968 969 970 971 972
      start_ts_(0),
      checkpoint_ts_(0),
      incarnation_(0),
      round_(0),
      status_(ObLogArchiveStatus::MAX),
      is_mark_deleted_(false),
      is_mount_file_created_(false),
973 974 975
      compatible_(COMPATIBLE::NONE),
      backup_piece_id_(0),
      start_piece_id_(0)
O
oceanbase-admin 已提交
976 977 978 979 980
{}

void ObTenantLogArchiveStatus::reset()
{
  tenant_id_ = OB_INVALID_ID;
981
  copy_id_ = 0;
O
oceanbase-admin 已提交
982 983 984 985 986 987 988 989
  start_ts_ = 0;
  checkpoint_ts_ = 0;
  incarnation_ = 0;
  round_ = 0;
  status_ = ObLogArchiveStatus::MAX;
  is_mark_deleted_ = false;
  is_mount_file_created_ = false;
  compatible_ = COMPATIBLE::NONE;
990 991
  backup_piece_id_ = 0;
  start_piece_id_ = 0;
O
oceanbase-admin 已提交
992 993 994 995
}

bool ObTenantLogArchiveStatus::is_valid() const
{
996 997 998
  return tenant_id_ != OB_INVALID_ID && copy_id_ >= 0 && ObLogArchiveStatus::is_valid(status_) && incarnation_ >= 0 &&
         round_ >= 0 && start_ts_ >= -1 && checkpoint_ts_ >= -1 && compatible_ >= COMPATIBLE::NONE &&
         backup_piece_id_ >= 0 && start_piece_id_ >= 0;
O
oceanbase-admin 已提交
999 1000 1001 1002 1003 1004 1005
}

bool ObTenantLogArchiveStatus::is_compatible_valid(COMPATIBLE compatible)
{
  return compatible >= COMPATIBLE::NONE && compatible < COMPATIBLE::MAX;
}

1006
// 备份状态机
O
oceanbase-admin 已提交
1007 1008 1009 1010 1011
// STOP->STOP
// BEGINNING -> BEGINNING\DOING\STOPPING\INERRUPTED
// DOING -> DOING\STOPPING\INERRUPTED
// STOPPING -> STOPPIONG\STOP
// INTERRUPTED -> INERRUPTED\STOPPING
1012 1013 1014
// 备份备份状态机
// DOING->PAUSED\STOP
// PAUSED->DOING
O
oceanbase-admin 已提交
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
int ObTenantLogArchiveStatus::update(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (!is_valid()) {
    ret = OB_NOT_INIT;
    LOG_WARN("not valid status", K(ret), K(*this));
  } else if (!new_status.is_valid() || new_status.incarnation_ != incarnation_ || new_status.round_ != round_ ||
             new_status.tenant_id_ != tenant_id_ || new_status.compatible_ != compatible_) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), "is_new_status_valid", new_status.is_valid(), K(new_status), K(*this));
  } else if (is_mount_file_created_ && !new_status.is_mount_file_created_) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("is_mount_file_created_ cannot change", K(ret), K(*this), K(new_status));
  } else {
    is_mount_file_created_ = new_status.is_mount_file_created_;
    switch (status_) {
      case ObLogArchiveStatus::STOP: {
        if (OB_FAIL(update_stop_(new_status))) {
          LOG_WARN("failed to update stop", K(ret));
        }
        break;
      }
      case ObLogArchiveStatus::BEGINNING: {
        if (OB_FAIL(update_beginning_(new_status))) {
          LOG_WARN("failed to update beginning", K(ret));
        }
        break;
      }
      case ObLogArchiveStatus::DOING: {
        if (OB_FAIL(update_doing_(new_status))) {
          LOG_WARN("failed to update doing", K(ret));
        }
        break;
      }
      case ObLogArchiveStatus::STOPPING: {
        if (OB_FAIL(update_stopping_(new_status))) {
          LOG_WARN("failed to update stopping", K(ret));
        }
        break;
      }
      case ObLogArchiveStatus::INTERRUPTED: {
        if (OB_FAIL(update_interrupted_(new_status))) {
          LOG_WARN("failed to update interrupted", K(ret));
        }
        break;
      }
1062 1063 1064 1065 1066 1067
      case ObLogArchiveStatus::PAUSED: {
        if (OB_FAIL(update_paused_(new_status))) {
          LOG_WARN("failed to update paused", K(ret));
        }
        break;
      }
O
oceanbase-admin 已提交
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
      default: {
        ret = OB_ERR_SYS;
        LOG_ERROR("invalid status", K(ret), K(*this), K(new_status));
      }
    }  // end switch
  }

  return ret;
}

1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
int ObTenantLogArchiveStatus::get_piece_key(ObBackupPieceInfoKey& key) const
{
  int ret = OB_SUCCESS;
  key.reset();

  key.incarnation_ = incarnation_;
  key.tenant_id_ = tenant_id_;
  key.round_id_ = round_;
  if (start_piece_id_ > 0) {
    key.backup_piece_id_ = backup_piece_id_;
  } else {
    key.backup_piece_id_ = 0;  // 0 means not switch piece
  }
  key.copy_id_ = copy_id_;
  return ret;
}

bool ObTenantLogArchiveStatus::need_switch_piece() const
{
  return start_piece_id_ > 0;
}

O
oceanbase-admin 已提交
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
int ObTenantLogArchiveStatus::update_stop_(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (ObLogArchiveStatus::STOP != new_status.status_) {
    ret = OB_LOG_ARCHIVE_STAT_NOT_MATCH;
    LOG_ERROR("stop status can only update with stop", K(ret), K(*this), K(new_status));
  } else {
    LOG_INFO("no need update stop status", K(*this), K(new_status));
  }
  return ret;
}

int ObTenantLogArchiveStatus::update_beginning_(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (ObLogArchiveStatus::DOING == new_status.status_) {
    if (0 >= new_status.start_ts_ || 0 >= new_status.checkpoint_ts_) {
      ret = OB_INVALID_LOG_ARCHIVE_STATUS;
1120
      LOG_WARN("[LOG_ARCHIVE] checkpoint_ts or start_ts must not less than 0", K(ret), K(*this), K(new_status));
O
oceanbase-admin 已提交
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
    } else {
      LOG_INFO("[LOG_ARCHIVE] update beginning to doing", K(*this), K(new_status));
      status_ = new_status.status_;
      start_ts_ = new_status.start_ts_;
      checkpoint_ts_ = new_status.checkpoint_ts_;
    }
  } else if (ObLogArchiveStatus::BEGINNING == new_status.status_) {
    // do nothing
  } else if (ObLogArchiveStatus::STOPPING == new_status.status_ || ObLogArchiveStatus::STOP == new_status.status_ ||
             ObLogArchiveStatus::INTERRUPTED == new_status.status_) {
    LOG_INFO("[LOG_ARCHIVE] update beginning to new stat", K(*this), K(new_status));
    status_ = new_status.status_;
  } else {
    ret = OB_LOG_ARCHIVE_STAT_NOT_MATCH;
    LOG_ERROR("stat not match", K(ret), K(*this), K(new_status));
  }
  return ret;
}

int ObTenantLogArchiveStatus::update_doing_(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (ObLogArchiveStatus::DOING == new_status.status_) {
    if (start_ts_ < new_status.start_ts_) {
      ret = OB_INVALID_LOG_ARCHIVE_STATUS;
      LOG_ERROR("new start_ts must not larger than the prev one", K(ret), K(*this), K(new_status));
    } else if (checkpoint_ts_ > new_status.checkpoint_ts_) {
      ret = OB_INVALID_LOG_ARCHIVE_STATUS;
1150
      LOG_WARN("new checkpoint_ts must not less than the prev one", K(ret), K(*this), K(new_status));
O
oceanbase-admin 已提交
1151 1152 1153 1154 1155
    } else {
      LOG_INFO("update doing stat", K(*this), K(new_status));
      checkpoint_ts_ = new_status.checkpoint_ts_;
    }
  } else if (ObLogArchiveStatus::STOPPING == new_status.status_ || ObLogArchiveStatus::STOP == new_status.status_ ||
1156 1157
             ObLogArchiveStatus::INTERRUPTED == new_status.status_ ||
             ObLogArchiveStatus::PAUSED == new_status.status_) {
O
oceanbase-admin 已提交
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
    FLOG_INFO("[LOG_ARCHIVE] update doing to new stat", K(*this), K(new_status));
    status_ = new_status.status_;
  } else {
    ret = OB_LOG_ARCHIVE_STAT_NOT_MATCH;
    LOG_ERROR("stat not match", K(ret), K(*this), K(new_status));
  }
  return ret;
}

int ObTenantLogArchiveStatus::update_stopping_(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (ObLogArchiveStatus::STOPPING == new_status.status_) {
    // do nothing
  } else if (ObLogArchiveStatus::STOP == new_status.status_) {
    FLOG_INFO("[LOG_ARCHIVE] update stopping to new stat", K(*this), K(new_status));
    status_ = new_status.status_;
  } else {
    ret = OB_LOG_ARCHIVE_STAT_NOT_MATCH;
    LOG_ERROR("stat not match", K(ret), K(*this), K(new_status));
  }
  return ret;
}

int ObTenantLogArchiveStatus::update_interrupted_(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (ObLogArchiveStatus::INTERRUPTED == new_status.status_) {
    // do nothing
  } else if (ObLogArchiveStatus::STOPPING == new_status.status_ || ObLogArchiveStatus::STOP == new_status.status_) {
    FLOG_INFO("[LOG_ARCHIVE] update interrupted to new stat", K(*this), K(new_status));
    status_ = new_status.status_;
  } else {
    ret = OB_LOG_ARCHIVE_STAT_NOT_MATCH;
    LOG_ERROR("stat not match", K(ret), K(*this), K(new_status));
  }
  return ret;
}

1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
int ObTenantLogArchiveStatus::update_paused_(const ObTenantLogArchiveStatus& new_status)
{
  int ret = OB_SUCCESS;

  if (ObLogArchiveStatus::INTERRUPTED == new_status.status_) {
    // do nothing
  } else if (ObLogArchiveStatus::DOING == new_status.status_ || ObLogArchiveStatus::STOP == new_status.status_) {
    FLOG_INFO("[LOG_ARCHIVE] update paused to new stat", K(*this), K(new_status));
    status_ = new_status.status_;
  } else {
    ret = OB_LOG_ARCHIVE_STAT_NOT_MATCH;
    LOG_ERROR("stat not match", K(ret), K(*this), K(new_status));
  }
  return ret;
}

O
oceanbase-admin 已提交
1215
OB_SERIALIZE_MEMBER(ObTenantLogArchiveStatus, tenant_id_, start_ts_, checkpoint_ts_, incarnation_, round_, status_,
1216
    is_mark_deleted_, is_mount_file_created_, compatible_, backup_piece_id_, start_piece_id_);
O
oceanbase-admin 已提交
1217

1218 1219
OB_SERIALIZE_MEMBER(ObServerTenantLogArchiveStatus, tenant_id_, incarnation_, status_, round_, min_backup_piece_id_,
    start_ts_, checkpoint_ts_, max_log_ts_);
O
oceanbase-admin 已提交
1220

1221
ObServerTenantLogArchiveStatus::ObServerTenantLogArchiveStatus()
O
oceanbase-admin 已提交
1222
{
1223
  reset();
O
oceanbase-admin 已提交
1224 1225
}

1226
bool ObServerTenantLogArchiveStatus::is_valid() const
O
oceanbase-admin 已提交
1227
{
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
  return tenant_id_ != OB_INVALID_ID && incarnation_ >= 0 && ObLogArchiveStatus::is_valid(status_) && round_ >= 0 &&
         min_backup_piece_id_ >= 0 && start_ts_ >= -1 && checkpoint_ts_ >= -1 && max_log_ts_ >= 0;
}

void ObServerTenantLogArchiveStatus::reset()
{
  tenant_id_ = 0;
  incarnation_ = 0;
  status_ = ObLogArchiveStatus::MAX;
  round_ = 0;
  min_backup_piece_id_ = 0;
  start_ts_ = 0;
  checkpoint_ts_ = 0;
  max_log_ts_ = 0;
}

int ObServerTenantLogArchiveStatus::get_compat_status(ObTenantLogArchiveStatus& status) const
{
  int ret = OB_SUCCESS;
  status.reset();

  if (!is_valid()) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("this status is not valid", K(ret), K(*this));
  } else if (min_backup_piece_id_ != 0) {
    ret = OB_ERR_SYS;
    LOG_ERROR("only compat mode need trans server tenant status to tenant status", K(ret), K(*this));
  } else {
    status.tenant_id_ = tenant_id_;
    status.incarnation_ = incarnation_;
    status.status_ = status_;
    status.round_ = round_;
    status.backup_piece_id_ = min_backup_piece_id_;  // must be 0
    status.start_ts_ = start_ts_;
    status.checkpoint_ts_ = checkpoint_ts_;
    // ObTenantLogArchiveStatus has not max_log_ts
  }
  return ret;
}

int ObServerTenantLogArchiveStatus::set_status(const ObTenantLogArchiveStatus& status)
{
  int ret = OB_SUCCESS;

  if (!status.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), K(status));
  } else {
    tenant_id_ = status.tenant_id_;
    incarnation_ = status.incarnation_;
    status_ = status.status_;
    round_ = status.round_;
    min_backup_piece_id_ = status.backup_piece_id_;
    start_ts_ = status.start_ts_;
    checkpoint_ts_ = status.checkpoint_ts_;
    max_log_ts_ = 0;  // // ObTenantLogArchiveStatus has not max_log_ts
  }
  return ret;
}

ObServerTenantLogArchiveStatusWrapper::ObServerTenantLogArchiveStatusWrapper()
    : result_code_(OB_SUCCESS), status_array_()
{}

OB_SERIALIZE_MEMBER(ObServerTenantLogArchiveStatusWrapper, result_code_, status_array_);

ObTenantLogArchiveStatusWrapper::ObTenantLogArchiveStatusWrapper() : result_code_(OB_SUCCESS), status_array_()
{}

OB_SERIALIZE_MEMBER(ObTenantLogArchiveStatusWrapper, result_code_, status_array_);

ObLogArchiveBackupInfo::ObLogArchiveBackupInfo() : status_()
{
  backup_dest_[0] = '\0';
}

void ObLogArchiveBackupInfo::reset()
{
  status_.reset();
  backup_dest_[0] = '\0';
O
oceanbase-admin 已提交
1308 1309 1310 1311 1312 1313 1314
}

bool ObLogArchiveBackupInfo::is_valid() const
{
  return status_.is_valid();
}

1315 1316 1317 1318 1319 1320 1321
// TODO(yaoying.yyy): S3 is alse oss?
bool ObLogArchiveBackupInfo::is_oss() const
{
  ObString dest(backup_dest_);
  return dest.prefix_match(OB_OSS_PREFIX);
}

O
oceanbase-admin 已提交
1322 1323 1324 1325 1326 1327 1328 1329 1330
bool ObLogArchiveBackupInfo::is_same(const ObLogArchiveBackupInfo& other) const
{
  return 0 == strncmp(backup_dest_, other.backup_dest_, sizeof(backup_dest_)) &&
         status_.tenant_id_ == other.status_.tenant_id_ && status_.start_ts_ == other.status_.start_ts_ &&
         status_.checkpoint_ts_ == other.status_.checkpoint_ts_ && status_.incarnation_ == other.status_.incarnation_ &&
         status_.round_ == other.status_.round_ && status_.status_ == other.status_.status_ &&
         status_.is_mark_deleted_ == other.status_.is_mark_deleted_;
}

1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
int ObLogArchiveBackupInfo::get_piece_key(ObBackupPieceInfoKey& key) const
{
  return status_.get_piece_key(key);
}

int ObLogArchiveBackupInfo::get_backup_dest(ObBackupDest& backup_dest) const
{
  int ret = OB_SUCCESS;
  backup_dest.reset();
  if (0 == strlen(backup_dest_)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("get invalid args", KR(ret));
  } else if (OB_FAIL(backup_dest.set(backup_dest_))) {
    LOG_WARN("failed to set backup dest", KR(ret), K(backup_dest_));
  }
  return ret;
}

O
oceanbase-admin 已提交
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
ObBackupDest::ObBackupDest() : device_type_(OB_STORAGE_MAX_TYPE)
{
  root_path_[0] = '\0';
  storage_info_[0] = '\0';
}

bool ObBackupDest::is_valid() const
{
  return device_type_ >= 0 && device_type_ < OB_STORAGE_MAX_TYPE && strlen(root_path_) > 0;
}

void ObBackupDest::reset()
{
  device_type_ = OB_STORAGE_MAX_TYPE;
  root_path_[0] = '\0';
  storage_info_[0] = '\0';
}

1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
int ObBackupDest::set(const common::ObString& backup_dest)
{
  int ret = OB_SUCCESS;
  ObArenaAllocator allocator;
  char* buf = NULL;
  if (OB_ISNULL(buf = reinterpret_cast<char*>(allocator.alloc(backup_dest.length() + 1)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("allocate memory failed", KR(ret));
  } else {
    MEMCPY(buf, backup_dest.ptr(), backup_dest.length());
    buf[backup_dest.length()] = '\0';
    if (OB_FAIL(set(buf))) {
      LOG_WARN("failed to set backup dest", KR(ret), K(backup_dest));
    }
  }
  return ret;
}

O
oceanbase-admin 已提交
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
int ObBackupDest::set(const char* backup_dest)
{
  int ret = OB_SUCCESS;
  int64_t pos = 0;
  common::ObStorageType type;
  ObString bakup_dest_str(backup_dest);

  if (device_type_ != OB_STORAGE_MAX_TYPE) {
    ret = OB_INIT_TWICE;
    LOG_WARN("cannot init twice", K(ret), K(*this));
  } else if (OB_ISNULL(backup_dest)) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_WARN("invalid args", K(ret), KP(backup_dest));
  } else if (OB_FAIL(get_storage_type_from_path(bakup_dest_str, type))) {
    LOG_WARN("failed to get storage type", K(ret));
  } else {
    // oss://backup_dir/?host=http://oss-cn-hangzhou-zmf.aliyuncs.com&access_id=111&access_key=222
    // file:///root_backup_dir"
    while (backup_dest[pos] != '\0') {
      if (backup_dest[pos] == '?') {
        break;
      }
      ++pos;
    }
    int64_t left_count = strlen(backup_dest) - pos;

    if (pos >= sizeof(root_path_) || left_count >= sizeof(storage_info_)) {
      ret = OB_INVALID_BACKUP_DEST;
      LOG_ERROR("backup dest is too long, cannot work", K(ret), K(pos), K(backup_dest), K(left_count));
    } else {
      MEMCPY(root_path_, backup_dest, pos);
      root_path_[pos] = '\0';
      ++pos;
      if (left_count > 0) {
        STRNCPY(storage_info_, backup_dest + pos, left_count);
        storage_info_[left_count] = '\0';
      }
1422 1423 1424 1425 1426 1427 1428 1429

      if (ObStorageType::OB_STORAGE_FILE != type && 0 == strlen(storage_info_)) {
        ret = OB_ERR_UNEXPECTED;
        LOG_WARN("backup device is not nfs, do not allow storage info be empty", K(ret), K(backup_dest));
      } else {
        device_type_ = type;
        LOG_TRACE("succeed to set backup dest", K(ret), K(backup_dest), K(*this));
      }
O
oceanbase-admin 已提交
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
    }
  }

  return ret;
}

int ObBackupDest::set(const char* root_path, const char* storage_info)
{
  int ret = OB_SUCCESS;
  common::ObStorageType type;
  ObString root_path_str(root_path);

  if (device_type_ != OB_STORAGE_MAX_TYPE) {
    ret = OB_INIT_TWICE;
    LOG_WARN("cannot init twice", K(ret), K(*this));
  } else if (OB_ISNULL(root_path) || OB_ISNULL(storage_info)) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_WARN("invalid args", K(ret), KP(root_path), KP(storage_info));
  } else if (OB_FAIL(get_storage_type_from_path(root_path_str, type))) {
    LOG_WARN("failed to get storage type", K(ret));
  } else if (OB_FAIL(databuff_printf(root_path_, OB_MAX_BACKUP_PATH_LENGTH, "%s", root_path))) {
    LOG_WARN("failed to set root path", K(ret), K(root_path), K(strlen(root_path)));
  } else if (OB_FAIL(databuff_printf(storage_info_, OB_MAX_BACKUP_STORAGE_INFO_LENGTH, "%s", storage_info))) {
    LOG_WARN("failed to set storage info", K(ret), K(storage_info), K(strlen(storage_info)));
1454 1455 1456
  } else if (ObStorageType::OB_STORAGE_FILE != type && 0 == strlen(storage_info_)) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("backup device is not nfs, do not allow storage info empty", K(ret), K(root_path), K(storage_info));
O
oceanbase-admin 已提交
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
  } else {
    device_type_ = type;
  }
  return ret;
}

const char* ObBackupDest::get_type_str() const
{
  return get_storage_type_str(device_type_);
}

1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
bool ObBackupDest::is_nfs_storage() const
{
  return OB_STORAGE_FILE == device_type_;
}

bool ObBackupDest::is_oss_storage() const
{
  return OB_STORAGE_OSS == device_type_;
}

bool ObBackupDest::is_cos_storage() const
{
  return OB_STORAGE_COS == device_type_;
}

bool ObBackupDest::is_root_path_equal(const ObBackupDest& backup_dest) const
{
  return device_type_ == backup_dest.device_type_ &&
         (0 == STRNCMP(root_path_, backup_dest.root_path_, OB_MAX_BACKUP_PATH_LENGTH));
}

O
oceanbase-admin 已提交
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
int ObBackupDest::get_backup_dest_str(char* buf, const int64_t buf_size) const
{
  int ret = OB_SUCCESS;
  if (!is_valid()) {
    ret = OB_NOT_INIT;
    LOG_WARN("backup dest is not init", K(ret), K(*this));
  } else if (OB_ISNULL(buf) || buf_size < share::OB_MAX_BACKUP_DEST_LENGTH) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("get backup dest str get invalid argument", K(ret), KP(buf), K(buf_size));
  } else if (OB_FAIL(databuff_printf(buf, buf_size, "%s", root_path_))) {
    LOG_WARN("failed to copy backup dest", K(ret), K(root_path_), K(sizeof(root_path_)));
  } else if (ObStorageType::OB_STORAGE_OSS == device_type_) {
    const int64_t str_len = strlen(buf);
    if (OB_FAIL(databuff_printf(buf + str_len, buf_size - str_len, "?%s", storage_info_))) {
      LOG_WARN("failed to copy backup dest", K(ret), K(storage_info_), K(str_len), K(sizeof(storage_info_)));
    }
  } else if (ObStorageType::OB_STORAGE_COS == device_type_) {
    const int64_t str_len = strlen(buf);
    if (OB_FAIL(databuff_printf(buf + str_len, buf_size - str_len, "?%s", storage_info_))) {
      LOG_WARN("failed to copy backup dest", K(ret), K(storage_info_), K(str_len), K(sizeof(storage_info_)));
    }
  }
  return ret;
}

bool ObBackupDest::operator==(const ObBackupDest& backup_dest) const
{
  return device_type_ == backup_dest.device_type_ && (0 == STRCMP(root_path_, backup_dest.root_path_)) &&
         (0 == STRCMP(storage_info_, backup_dest.storage_info_));
}

1520 1521 1522 1523 1524 1525
bool ObBackupDest::operator!=(const ObBackupDest& backup_dest) const
{
  return device_type_ != backup_dest.device_type_ || (0 != STRCMP(root_path_, backup_dest.root_path_)) ||
         (0 != STRCMP(storage_info_, backup_dest.storage_info_));
}

O
oceanbase-admin 已提交
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
uint64_t ObBackupDest::hash() const
{
  uint64_t hash_val = 0;
  hash_val = murmurhash(&device_type_, sizeof(device_type_), hash_val);
  hash_val = murmurhash(root_path_, static_cast<int32_t>(strlen(root_path_)), hash_val);
  hash_val = murmurhash(storage_info_, static_cast<int32_t>(strlen(storage_info_)), hash_val);
  return hash_val;
}

ObBackupBaseDataPathInfo::ObBackupBaseDataPathInfo()
1536
    : dest_(), tenant_id_(OB_INVALID_ID), full_backup_set_id_(0), inc_backup_set_id_(0), backup_date_(0), compatible_(0)
O
oceanbase-admin 已提交
1537 1538
{}

1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
int ObBackupBaseDataPathInfo::set(const ObClusterBackupDest& dest, const uint64_t tenant_id,
    const int64_t full_backup_set_id, const int64_t inc_backup_set_id, const int64_t backup_date,
    const int64_t compatible)
{
  int ret = OB_SUCCESS;
  if (!dest.is_valid() || OB_INVALID_ID == tenant_id || full_backup_set_id <= 0 || inc_backup_set_id <= 0 ||
      backup_date < 0 || compatible < OB_BACKUP_COMPATIBLE_VERSION_V1 ||
      compatible > OB_BACKUP_COMPATIBLE_VERSION_MAX) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_WARN("invalid argument",
        K(ret),
        K(dest),
        K(tenant_id),
        K(full_backup_set_id),
        K(inc_backup_set_id),
        K(backup_date),
        K(compatible));
  } else {
    dest_ = dest;
    tenant_id_ = tenant_id;
    full_backup_set_id_ = full_backup_set_id;
    inc_backup_set_id_ = inc_backup_set_id;
    backup_date_ = backup_date;
    compatible_ = compatible;
  }
  return ret;
}

O
oceanbase-admin 已提交
1567 1568 1569 1570 1571 1572
void ObBackupBaseDataPathInfo::reset()
{
  dest_.reset();
  tenant_id_ = OB_INVALID_ID;
  full_backup_set_id_ = 0;
  inc_backup_set_id_ = 0;
1573 1574
  backup_date_ = 0;
  compatible_ = 0;
O
oceanbase-admin 已提交
1575 1576 1577 1578 1579
}

bool ObBackupBaseDataPathInfo::is_valid() const
{
  return dest_.is_valid() && OB_INVALID_ID != tenant_id_ && inc_backup_set_id_ >= full_backup_set_id_ &&
1580 1581
         full_backup_set_id_ > 0 && backup_date_ >= 0 && compatible_ < OB_BACKUP_COMPATIBLE_VERSION_MAX &&
         compatible_ >= OB_BACKUP_COMPATIBLE_VERSION_V1;
O
oceanbase-admin 已提交
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
}

const char* ObBackupInfoStatus::get_status_str(const BackupStatus& status)
{
  const char* str = "UNKNOWN";
  const char* info_backup_status_strs[] = {
      "STOP",
      "PREPARE",
      "SCHEDULE",
      "DOING",
      "CANCEL",
      "CLEANUP",
  };
  STATIC_ASSERT(MAX == ARRAYSIZEOF(info_backup_status_strs), "status count mismatch");
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup info status", K(status));
  } else {
    str = info_backup_status_strs[status];
  }
  return str;
}

const char* ObBackupInfoStatus::get_info_backup_status_str() const
{
  return get_status_str(status_);
}

int ObBackupInfoStatus::set_info_backup_status(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set info backup status get invalid argument", K(ret), KP(buf));
  } else {
    const char* info_backup_status_strs[] = {
        "STOP",
        "PREPARE",
        "SCHEDULE",
        "DOING",
        "CANCEL",
        "CLEANUP",
    };
    BackupStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(info_backup_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(info_backup_status_strs); i++) {
      if (0 == STRCMP(info_backup_status_strs[i], buf)) {
        tmp_status = static_cast<BackupStatus>(i);
      }
    }
    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup info status str not found", K(ret), K(buf));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

const char* ObBackupType::get_backup_type_str() const
{
  const char* str = "UNKNOWN";
  const char* backup_func_type_strs[] = {
      "",
      "D",
      "I",
  };
  STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_func_type_strs), "types count mismatch");
  if (type_ < 0 || type_ >= MAX) {
    LOG_ERROR("invalid backup type", K(type_));
  } else {
    str = backup_func_type_strs[type_];
  }
  return str;
}

int ObBackupType::set_backup_type(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set backup type get invalid argument", K(ret), KP(buf));
  } else {
    const char* backup_func_type_strs[] = {
        "",
        "D",
        "I",
    };
    BackupType tmp_type = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_func_type_strs), "types count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_func_type_strs); i++) {
      if (0 == STRCMP(backup_func_type_strs[i], buf)) {
        tmp_type = static_cast<BackupType>(i);
      }
    }

    if (MAX == tmp_type) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup type str not found", K(ret), K(buf));
    } else {
      type_ = tmp_type;
    }
  }
  return ret;
}

const char* ObBackupDeviceType::get_backup_device_str() const
{
  const char* str = "UNKNOWN";
  const char* backup_device_type_strs[] = {
      "file://",
      "oss://",
      "ofs://",
      "cos://",
  };
  STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_device_type_strs), "types count mismatch");
  if (type_ < 0 || type_ >= MAX) {
    LOG_ERROR("invalid backup device type", K(type_));
  } else {
    str = backup_device_type_strs[type_];
  }
  return str;
}

int ObBackupDeviceType::set_backup_device_type(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set backup device get invalid argument", K(ret), KP(buf));
  } else {
    const char* backup_device_type_strs[] = {
        "file://",
        "oss://",
        "ofs://",
        "cos://",
    };
    BackupDeviceType tmp_type = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_device_type_strs), "types count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_device_type_strs); i++) {
      if (0 == STRCMP(backup_device_type_strs[i], buf)) {
        tmp_type = static_cast<BackupDeviceType>(i);
      }
    }

    if (MAX == tmp_type) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup device type str not found", K(ret), K(buf));
    } else {
      type_ = tmp_type;
    }
  }
  return ret;
}

ObBaseBackupInfoStruct::ObBaseBackupInfoStruct()
    : tenant_id_(OB_INVALID_ID),
      backup_set_id_(0),
      incarnation_(0),
      backup_dest_(),
1742
      backup_backup_dest_(),
O
oceanbase-admin 已提交
1743 1744 1745 1746 1747 1748 1749
      backup_snapshot_version_(0),
      backup_schema_version_(0),
      backup_data_version_(0),
      detected_backup_region_(),
      backup_type_(),
      backup_status_(),
      backup_task_id_(0),
1750
      copy_id_(0),
O
oceanbase-admin 已提交
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
      encryption_mode_(share::ObBackupEncryptionMode::MAX_MODE),
      passwd_()
{}

void ObBaseBackupInfoStruct::reset()
{
  tenant_id_ = OB_INVALID_ID;
  backup_set_id_ = 0;
  incarnation_ = 0;
  backup_dest_.reset();
1761
  backup_backup_dest_.reset();
O
oceanbase-admin 已提交
1762 1763 1764 1765 1766 1767 1768
  backup_snapshot_version_ = 0;
  backup_schema_version_ = 0;
  backup_data_version_ = 0;
  detected_backup_region_.reset();
  backup_type_.reset();
  backup_status_.reset();
  backup_task_id_ = 0;
1769
  copy_id_ = 0;
O
oceanbase-admin 已提交
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
  encryption_mode_ = share::ObBackupEncryptionMode::MAX_MODE;
  passwd_.reset();
}

bool ObBaseBackupInfoStruct::is_valid() const
{
  return OB_INVALID_ID != tenant_id_ && tenant_id_ > 0 && backup_status_.is_valid() &&
         share::ObBackupEncryptionMode::is_valid(encryption_mode_);
}

bool ObBaseBackupInfoStruct::has_cleaned() const
{
  return is_valid() && backup_status_.is_stop_status() && 0 == backup_snapshot_version_ &&
         0 == backup_schema_version_ && 0 == backup_data_version_ && ObBackupType::EMPTY == backup_type_.type_;
}

ObBaseBackupInfoStruct& ObBaseBackupInfoStruct::operator=(const ObBaseBackupInfoStruct& info)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(assign(info))) {
    LOG_ERROR("failed to assign backup info", K(ret), K(info));
  }
  return *this;
}

int ObBaseBackupInfoStruct::assign(const ObBaseBackupInfoStruct& backup_info_struct)
{
  int ret = OB_SUCCESS;
  if (!backup_info_struct.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    LOG_ERROR("backup info struct is invalid", K(ret), K(backup_info_struct));
  } else {
    backup_dest_ = backup_info_struct.backup_dest_;
1803
    backup_backup_dest_ = backup_info_struct.backup_backup_dest_;
O
oceanbase-admin 已提交
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
    detected_backup_region_ = backup_info_struct.detected_backup_region_;
    tenant_id_ = backup_info_struct.tenant_id_;
    backup_set_id_ = backup_info_struct.backup_set_id_;
    incarnation_ = backup_info_struct.incarnation_;
    backup_snapshot_version_ = backup_info_struct.backup_snapshot_version_;
    backup_schema_version_ = backup_info_struct.backup_schema_version_;
    backup_data_version_ = backup_info_struct.backup_data_version_;
    backup_type_ = backup_info_struct.backup_type_;
    backup_status_ = backup_info_struct.backup_status_;
    backup_task_id_ = backup_info_struct.backup_task_id_;
1814
    copy_id_ = backup_info_struct.copy_id_;
O
oceanbase-admin 已提交
1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
    encryption_mode_ = backup_info_struct.encryption_mode_;
    passwd_ = backup_info_struct.passwd_;
  }
  return ret;
}

int ObBaseBackupInfoStruct::check_backup_info_match(const ObBaseBackupInfoStruct& backup_info_struct) const
{
  int ret = OB_SUCCESS;
  if (!backup_info_struct.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    LOG_ERROR("backup info struct is invalid", K(ret), K(backup_info_struct));
  } else if (backup_dest_ != backup_info_struct.backup_dest_ || tenant_id_ != backup_info_struct.tenant_id_ ||
             backup_set_id_ != backup_info_struct.backup_set_id_ || incarnation_ != backup_info_struct.incarnation_ ||
             backup_snapshot_version_ != backup_info_struct.backup_snapshot_version_ ||
             backup_schema_version_ != backup_info_struct.backup_schema_version_ ||
             backup_data_version_ != backup_info_struct.backup_data_version_ ||
             backup_type_.type_ != backup_info_struct.backup_type_.type_ ||
             backup_status_.status_ != backup_info_struct.backup_status_.status_ ||
             encryption_mode_ != backup_info_struct.encryption_mode_ || passwd_ != backup_info_struct.passwd_) {
    ret = OB_BACKUP_INFO_NOT_MATCH;
    LOG_WARN("backup info is not match", K(ret), K(*this), K(backup_info_struct));
  }
  return ret;
}

ObClusterBackupDest::ObClusterBackupDest() : dest_(), cluster_id_(0), incarnation_(0)
{
  cluster_name_[0] = '\0';
}

bool ObClusterBackupDest::is_valid() const
{
  return dest_.is_valid() && strlen(cluster_name_) > 0 && cluster_id_ > 0 && incarnation_ == OB_START_INCARNATION;
}

bool ObClusterBackupDest::is_same(const ObClusterBackupDest& other) const
{
  return dest_ == other.dest_ && 0 == STRCMP(cluster_name_, other.cluster_name_) && cluster_id_ == other.cluster_id_ &&
         incarnation_ == other.incarnation_;
}

void ObClusterBackupDest::reset()
{
  dest_.reset();
  cluster_id_ = 0;
  incarnation_ = 0;
  cluster_name_[0] = '\0';
}

int ObClusterBackupDest::set(const char* backup_dest, const int64_t incarnation)
{
  int ret = OB_SUCCESS;
  const char* cluster_name = GCONF.cluster;
  const int64_t cluster_id = GCONF.cluster_id;
  if (OB_FAIL(set(backup_dest, cluster_name, cluster_id, incarnation))) {
    LOG_WARN("failed to set", K(ret), K(backup_dest), K(cluster_name), K(cluster_id), K(incarnation));
  }
  return ret;
}

int ObClusterBackupDest::set(
    const char* backup_dest, const char* cluster_name, const int64_t cluster_id, const int64_t incarnation)
{
  int ret = OB_SUCCESS;

  if (OB_ISNULL(backup_dest) || OB_ISNULL(cluster_name) || cluster_id <= 0 || incarnation != OB_START_INCARNATION) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_WARN("invalid args", K(ret), KP(backup_dest), KP(cluster_name), K(cluster_id), K(incarnation));
  } else if (strlen(cluster_name) >= sizeof(cluster_name_)) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_ERROR("cluster is too long, cannot work", K(ret), K(cluster_name));
  } else if (OB_FAIL(dest_.set(backup_dest))) {
    LOG_WARN("failed to set backup dest", K(ret), K(backup_dest));
  } else {
    const int64_t len = strlen(cluster_name);
    STRNCPY(cluster_name_, cluster_name, len);
    cluster_name_[len] = '\0';
    cluster_id_ = cluster_id;
    incarnation_ = incarnation;
    LOG_TRACE("succeed to set cluster backup dest", K(ret), K(*this), K(backup_dest));
  }

  return ret;
}

int ObClusterBackupDest::set(const ObBackupDest& backup_dest, const int64_t incarnation)
{
  int ret = OB_SUCCESS;
  const char* cluster_name = GCONF.cluster;
  if (incarnation <= 0 || !backup_dest.is_valid()) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_WARN("invalid args", K(ret), K(backup_dest), K(incarnation));
  } else if (strlen(cluster_name) >= sizeof(cluster_name_)) {
    ret = OB_INVALID_BACKUP_DEST;
    LOG_ERROR("cluster is too long, cannot work", K(ret), K(cluster_name));
  } else {
    const int64_t len = strlen(cluster_name);
    STRNCPY(cluster_name_, cluster_name, len);
    cluster_name_[len] = '\0';
    cluster_id_ = GCONF.cluster_id;
    incarnation_ = incarnation;
    dest_ = backup_dest;
    LOG_INFO("succeed to set cluster backup dest", K(ret), K(*this), K(dest_));
  }
  return ret;
}

uint64_t ObClusterBackupDest::hash() const
{
  uint64_t hash_val = 0;
  hash_val = murmurhash(cluster_name_, static_cast<int32_t>(strlen(cluster_name_)), hash_val);
  hash_val = murmurhash(&cluster_id_, sizeof(cluster_id_), hash_val);
  hash_val = murmurhash(&incarnation_, sizeof(incarnation_), hash_val);
  hash_val += dest_.hash();
  return hash_val;
}

bool ObClusterBackupDest::operator==(const ObClusterBackupDest& other) const
{
  return is_same(other);
}

ObTenantBackupTaskItem::ObTenantBackupTaskItem()
    : tenant_id_(OB_INVALID_ID),
      backup_set_id_(0),
      incarnation_(0),
      snapshot_version_(0),
      prev_full_backup_set_id_(0),
      prev_inc_backup_set_id_(0),
      prev_backup_data_version_(0),
      pg_count_(0),
      macro_block_count_(0),
      finish_pg_count_(0),
      finish_macro_block_count_(0),
      input_bytes_(0),
      output_bytes_(0),
      start_time_(0),
      end_time_(0),
      compatible_(0),
      cluster_version_(0),
      backup_type_(),
      status_(BackupStatus::MAX),
      device_type_(ObStorageType::OB_STORAGE_MAX_TYPE),
      result_(0),
      cluster_id_(OB_INVALID_CLUSTER_ID),
      backup_dest_(),
      backup_data_version_(0),
      backup_schema_version_(0),
      partition_count_(0),
      finish_partition_count_(0),
      encryption_mode_(ObBackupEncryptionMode::MAX_MODE),
      passwd_(),
1968 1969 1970 1971
      is_mark_deleted_(false),
      start_replay_log_ts_(0),
      date_(0),
      copy_id_(0)
O
oceanbase-admin 已提交
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
{}

void ObTenantBackupTaskItem::reset()
{
  tenant_id_ = OB_INVALID_ID;
  backup_set_id_ = 0;
  incarnation_ = 0;
  snapshot_version_ = 0;
  prev_full_backup_set_id_ = 0;
  prev_inc_backup_set_id_ = 0;
  prev_backup_data_version_ = 0;
  pg_count_ = 0;
  macro_block_count_ = 0;
  finish_pg_count_ = 0;
  finish_macro_block_count_ = 0;
  input_bytes_ = 0;
  output_bytes_ = 0;
  start_time_ = 0;
  end_time_ = 0;
  compatible_ = 0;
  cluster_version_ = 0;
  backup_type_.reset();
  status_ = BackupStatus::MAX;
  device_type_ = ObStorageType::OB_STORAGE_MAX_TYPE;
  result_ = 0;
  cluster_id_ = OB_INVALID_CLUSTER_ID;
  backup_dest_.reset();
  backup_data_version_ = 0;
  backup_schema_version_ = 0;
  partition_count_ = 0;
  finish_partition_count_ = 0;
  encryption_mode_ = share::ObBackupEncryptionMode::MAX_MODE;
  passwd_.reset();
  is_mark_deleted_ = false;
2006 2007 2008
  start_replay_log_ts_ = 0;
  date_ = 0;
  copy_id_ = 0;
O
oceanbase-admin 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191
}

bool ObTenantBackupTaskItem::is_key_valid() const
{
  return tenant_id_ != OB_INVALID_ID && backup_set_id_ > 0 && incarnation_ > 0;
}

bool ObTenantBackupTaskItem::is_valid() const
{
  return is_key_valid() && BackupStatus::MAX != status_ && share::ObBackupEncryptionMode::is_valid(encryption_mode_);
}

bool ObTenantBackupTaskItem::is_same_task(const ObTenantBackupTaskItem& other) const
{
  return tenant_id_ == other.tenant_id_ && backup_set_id_ == other.backup_set_id_ && incarnation_ == other.incarnation_;
}

bool ObTenantBackupTaskItem::is_result_succeed() const
{
  return OB_SUCCESS == result_;
}

const char* ObTenantBackupTaskItem::get_backup_task_status_str() const
{
  const char* str = "UNKNOWN";
  const char* tenant_task_backup_status_strs[] = {"GENERATE", "DOING", "FINISH", "CANCEL"};
  STATIC_ASSERT(MAX == ARRAYSIZEOF(tenant_task_backup_status_strs), "status count mismatch");
  if (status_ < 0 || status_ >= MAX) {
    LOG_WARN("invalid backup task status", K(status_));
  } else {
    str = tenant_task_backup_status_strs[status_];
  }
  return str;
}

int ObTenantBackupTaskItem::set_backup_task_status(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set backup task status get invalid argument", K(ret), KP(buf));
  } else {
    const char* tenant_task_backup_status_strs[] = {"GENERATE", "DOING", "FINISH", "CANCEL"};
    BackupStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(tenant_task_backup_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(tenant_task_backup_status_strs); i++) {
      if (0 == STRCMP(tenant_task_backup_status_strs[i], buf)) {
        tmp_status = static_cast<BackupStatus>(i);
      }
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup status str not found", K(ret), K(buf));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

ObPGBackupTaskItem::ObPGBackupTaskItem()
    : tenant_id_(OB_INVALID_ID),
      table_id_(OB_INVALID_ID),
      partition_id_(-1),
      incarnation_(0),
      backup_set_id_(0),
      backup_type_(),
      snapshot_version_(0),
      partition_count_(0),
      macro_block_count_(0),
      finish_partition_count_(0),
      finish_macro_block_count_(0),
      input_bytes_(0),
      output_bytes_(0),
      start_time_(0),
      end_time_(0),
      retry_count_(0),
      role_(INVALID_ROLE),
      replica_type_(REPLICA_TYPE_MAX),
      server_(),
      status_(BackupStatus::MAX),
      result_(0),
      task_id_(0),
      trace_id_()
{}

void ObPGBackupTaskItem::reset()
{
  tenant_id_ = OB_INVALID_ID;
  table_id_ = OB_INVALID_ID;
  partition_id_ = -1;
  incarnation_ = 0;
  backup_set_id_ = 0;
  backup_type_.reset();
  snapshot_version_ = 0;
  partition_count_ = 0;
  macro_block_count_ = 0;
  finish_partition_count_ = 0;
  finish_macro_block_count_ = 0;
  input_bytes_ = 0;
  output_bytes_ = 0;
  start_time_ = 0;
  end_time_ = 0;
  retry_count_ = 0;
  role_ = INVALID_ROLE;
  replica_type_ = REPLICA_TYPE_MAX;
  server_.reset();
  status_ = BackupStatus::MAX;
  result_ = 0;
  task_id_ = 0;
  trace_id_.reset();
}

bool ObPGBackupTaskItem::is_key_valid() const
{
  return OB_INVALID_ID != tenant_id_ && OB_INVALID_ID != table_id_ && partition_id_ >= 0 && incarnation_ > 0 &&
         backup_set_id_ > 0;
}

bool ObPGBackupTaskItem::is_same_task(const ObPGBackupTaskItem& item) const
{
  return tenant_id_ == item.tenant_id_ && table_id_ == item.table_id_ && partition_id_ == item.partition_id_ &&
         incarnation_ == item.incarnation_ && backup_set_id_ == item.backup_set_id_;
}

bool ObPGBackupTaskItem::is_valid() const
{
  return is_key_valid() && BackupStatus::MAX != status_;
}

const char* ObPGBackupTaskItem::get_status_str(const BackupStatus& status)
{
  const char* str = "UNKNOWN";
  const char* pg_task_backup_status_strs[] = {"PENDING", "DOING", "FINISH", "CANCEL"};
  STATIC_ASSERT(MAX == ARRAYSIZEOF(pg_task_backup_status_strs), "status count mismatch");
  if (status < 0 || status >= MAX) {
    LOG_WARN("invalid backup task status", K(status));
  } else {
    str = pg_task_backup_status_strs[status];
  }
  return str;
}

const char* ObPGBackupTaskItem::get_backup_task_status_str() const
{
  return get_status_str(status_);
}

int ObPGBackupTaskItem::set_backup_task_status(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set backup task status get invalid argument", K(ret), KP(buf));
  } else {
    const char* pg_task_backup_status_strs[] = {"PENDING", "DOING", "FINISH", "CANCEL"};
    BackupStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(pg_task_backup_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(pg_task_backup_status_strs); i++) {
      if (0 == STRCMP(pg_task_backup_status_strs[i], buf)) {
        tmp_status = static_cast<BackupStatus>(i);
      }
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup status str not found", K(ret), K(buf));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

int ObPGBackupTaskItem::set_trace_id(const char* buf, const int64_t buf_size)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf) || buf_size < common::OB_MAX_TRACE_ID_BUFFER_SIZE) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set trace id get invalid argument", K(ret), KP(buf), K(buf_size));
  } else if (0 == strlen(buf)) {
    // do nothing
2192 2193
  } else if (OB_FAIL(trace_id_.set(buf))) {
    LOG_WARN("failed to set trace id", K(ret), K(buf), K(buf_size));
O
oceanbase-admin 已提交
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213
  }
  return ret;
}

int ObPGBackupTaskItem::get_trace_id(char* buf, const int64_t buf_size) const
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(get_trace_id(trace_id_, buf_size, buf))) {
    LOG_WARN("failed to get trace id", K(ret), K(trace_id_), KP(buf), K(buf_size));
  }
  return ret;
}

int ObPGBackupTaskItem::get_trace_id(const ObTaskId& trace_id, const int64_t buf_size, char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf) || buf_size < common::OB_MAX_TRACE_ID_BUFFER_SIZE) {
    LOG_WARN("get trace id get invalid argument", K(ret), K(trace_id), K(buf_size));
  } else if (trace_id.is_invalid()) {
    // do noting
2214 2215 2216 2217 2218 2219
  } else {
    const int64_t pos = trace_id.to_string(buf, buf_size);
    if (pos > buf_size) {
      ret = OB_SIZE_OVERFLOW;
      LOG_WARN("failed to change trace id to string", K(ret), K(buf), K(buf_size));
    }
O
oceanbase-admin 已提交
2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543
  }
  return ret;
}

static const char* backup_validate_status_strs[] = {
    "SCHEDULE",
    "DOING",
    "FINISHED",
    "CANCEL",
};

ObBackupValidateTenant::ObBackupValidateTenant() : tenant_id_(OB_INVALID_ID), is_dropped_(false)
{}

ObBackupValidateTenant::~ObBackupValidateTenant()
{
  reset();
}

void ObBackupValidateTenant::reset()
{
  tenant_id_ = OB_INVALID_ID;
  is_dropped_ = false;
}

bool ObBackupValidateTenant::is_valid() const
{
  return OB_INVALID_ID != tenant_id_;
}

ObBackupValidateTaskItem::ObBackupValidateTaskItem()
    : job_id_(-1),
      tenant_id_(OB_INVALID_ID),
      tenant_name_(""),
      incarnation_(-1),
      backup_set_id_(-1),
      progress_percent_(0),
      status_(ObBackupValidateTaskItem::MAX)
{}

ObBackupValidateTaskItem::~ObBackupValidateTaskItem()
{
  reset();
}

void ObBackupValidateTaskItem::reset()
{
  job_id_ = -1;
  tenant_id_ = OB_INVALID_ID;
  tenant_name_ = "";
  incarnation_ = -1;
  backup_set_id_ = -1;
  progress_percent_ = 0;
  status_ = ObBackupValidateTaskItem::MAX;
}

bool ObBackupValidateTaskItem::is_valid() const
{
  return job_id_ >= 0 && OB_INVALID_ID != tenant_id_ && incarnation_ > 0 && backup_set_id_ >= 0 &&
         status_ < ValidateStatus::MAX;
}

bool ObBackupValidateTaskItem::is_same_task(const ObBackupValidateTaskItem& other)
{
  return job_id_ == other.job_id_ && tenant_id_ == other.tenant_id_ && incarnation_ == other.incarnation_ &&
         backup_set_id_ == other.backup_set_id_;
}

const char* ObBackupValidateTaskItem::get_status_str(const ValidateStatus& status)
{
  const char* str = "UNKNOWN";
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup info status", K(status));
  } else {
    str = backup_validate_status_strs[status];
  }
  return str;
}

int ObBackupValidateTaskItem::set_status(const char* status_str)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(status_str)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("get status get invalid argument", K(ret), K(status_str));
  } else {
    ValidateStatus tmp_status = MAX;
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_validate_status_strs); ++i) {
      if (0 == STRCMP(backup_validate_status_strs[i], status_str)) {
        tmp_status = static_cast<ValidateStatus>(i);
      }
    }
    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("validate status str do not found", K(ret), K(status_str));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

static const char* tenant_validate_status_strs[] = {
    "SCHEDULE",
    "DOING",
    "FINISHED",
    "CANCEL",
};

ObTenantValidateTaskItem::ObTenantValidateTaskItem()
    : job_id_(-1),
      task_id_(-1),
      tenant_id_(OB_INVALID_ID),
      incarnation_(-1),
      backup_set_id_(-1),
      status_(ObTenantValidateTaskItem::MAX),
      backup_dest_(""),
      start_time_(-1),
      end_time_(-1),
      total_pg_count_(-1),
      finish_pg_count_(0),
      total_partition_count_(-1),
      finish_partition_count_(0),
      total_macro_block_count_(-1),
      finish_macro_block_count_(0),
      log_size_(-1),
      result_(-1),
      comment_()
{}

ObTenantValidateTaskItem::~ObTenantValidateTaskItem()
{
  reset();
}

void ObTenantValidateTaskItem::reset()
{
  job_id_ = -1;
  task_id_ = -1;
  tenant_id_ = OB_INVALID_ID;
  incarnation_ = -1;
  backup_set_id_ = -1;
  status_ = ObTenantValidateTaskItem::MAX;
  backup_dest_[0] = '\0';
  start_time_ = -1;
  end_time_ = -1;
  total_pg_count_ = -1;
  finish_pg_count_ = -1;
  total_partition_count_ = -1;
  finish_partition_count_ = -1;
  total_macro_block_count_ = -1;
  finish_macro_block_count_ = -1;
  log_size_ = -1;
}

bool ObTenantValidateTaskItem::is_valid() const
{
  return job_id_ >= 0 && task_id_ >= 0 && OB_INVALID_ID != tenant_id_ && incarnation_ > 0 && backup_set_id_ >= 0 &&
         status_ < ObTenantValidateTaskItem::MAX;
}

bool ObTenantValidateTaskItem::is_same_task(const ObTenantValidateTaskItem& other)
{
  return job_id_ == other.job_id_ && task_id_ == other.task_id_ && tenant_id_ == other.tenant_id_ &&
         incarnation_ == other.incarnation_ && backup_set_id_ == other.backup_set_id_;
}

const char* ObTenantValidateTaskItem::get_status_str(const ValidateStatus& status)
{
  const char* str = "UNKNOWN";
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup info status", K(status));
  } else {
    str = tenant_validate_status_strs[status];
  }
  return str;
}

int ObTenantValidateTaskItem::set_status(const char* status_str)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(status_str)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("get status get invalid argument", K(ret), K(status_str));
  } else {
    ValidateStatus tmp_status = MAX;
    for (int64_t i = 0; i < ARRAYSIZEOF(tenant_validate_status_strs); ++i) {
      if (0 == STRCMP(tenant_validate_status_strs[i], status_str)) {
        tmp_status = static_cast<ValidateStatus>(i);
      }
    }
    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("validate status str do not found", K(ret), K(status_str));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

static const char* pg_validate_status_strs[] = {
    "PENDING",
    "DOING",
    "FINISHED",
};

ObPGValidateTaskItem::ObPGValidateTaskItem()
    : job_id_(-1),
      task_id_(-1),
      tenant_id_(OB_INVALID_ID),
      table_id_(-1),
      partition_id_(-1),
      incarnation_(-1),
      backup_set_id_(-1),
      archive_round_(-1),
      total_partition_count_(-1),
      finish_partition_count_(-1),
      total_macro_block_count_(-1),
      finish_macro_block_count_(-1),
      log_info_(""),
      log_size_(-1),
      result_(-1),
      trace_id_(),
      status_(ObPGValidateTaskItem::MAX)
{}

ObPGValidateTaskItem::~ObPGValidateTaskItem()
{
  reset();
}

void ObPGValidateTaskItem::reset()
{
  job_id_ = -1;
  task_id_ = -1;
  tenant_id_ = OB_INVALID_ID;
  table_id_ = -1;
  partition_id_ = -1;
  incarnation_ = -1;
  backup_set_id_ = -1;
  archive_round_ = -1;
  total_partition_count_ = -1;
  finish_partition_count_ = -1;
  total_macro_block_count_ = -1;
  finish_macro_block_count_ = -1;
  log_info_[0] = '\0';
  log_size_ = -1;
  result_ = -1;
  trace_id_.reset();
  status_ = ObPGValidateTaskItem::MAX;
}

bool ObPGValidateTaskItem::is_valid() const
{
  return job_id_ >= 0 && task_id_ >= 0 && OB_INVALID_ID != tenant_id_ && backup_set_id_ >= 0 &&
         archive_round_ >= 0 /*&& status_ < ObPGValidateTaskItem::MAX*/;
}

bool ObPGValidateTaskItem::is_same_task(const ObPGValidateTaskItem& other)
{
  return job_id_ == other.job_id_ && task_id_ == other.task_id_ && tenant_id_ == other.tenant_id_ &&
         table_id_ == other.table_id_ && partition_id_ == other.partition_id_ && incarnation_ == other.incarnation_ &&
         backup_set_id_ == other.backup_set_id_ && archive_round_ == other.archive_round_;
}

const char* ObPGValidateTaskItem::get_status_str(const ValidateStatus& status)
{
  const char* str = "UNKNOWN";
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup info status", K(status));
  } else {
    str = pg_validate_status_strs[status];
  }
  return str;
}

int ObPGValidateTaskItem::set_status(const char* status_str)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(status_str)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("get status get invalid argument", K(ret), K(status_str));
  } else {
    ValidateStatus tmp_status = MAX;
    for (int64_t i = 0; i < ARRAYSIZEOF(pg_validate_status_strs); ++i) {
      if (0 == STRCMP(pg_validate_status_strs[i], status_str)) {
        tmp_status = static_cast<ValidateStatus>(i);
      }
    }
    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("validate status str do not found", K(ret), K(status_str));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

ObPGValidateTaskRowKey::ObPGValidateTaskRowKey()
    : tenant_id_(0), job_id_(0), task_id_(0), incarnation_(0), backup_set_id_(0), table_id_(0), partition_id_(0)
{}

ObPGValidateTaskRowKey::~ObPGValidateTaskRowKey()
{}

int ObPGValidateTaskRowKey::set(const ObPGValidateTaskInfo* pg_task)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(pg_task)) {
    // use the default value
  } else {
    tenant_id_ = pg_task->tenant_id_;
    job_id_ = pg_task->job_id_;
    task_id_ = pg_task->task_id_;
    incarnation_ = pg_task->incarnation_;
    backup_set_id_ = pg_task->backup_set_id_;
    table_id_ = pg_task->table_id_;
    partition_id_ = pg_task->partition_id_;
  }
  return ret;
}

2544 2545
/* ObBackupBackupsetType */
const char* ObBackupBackupsetType::get_type_str() const
O
oceanbase-admin 已提交
2546
{
2547 2548 2549 2550 2551 2552 2553 2554 2555 2556
  const char* str = "UNKNOWN";
  const char* backup_backupset_type_str[] = {
      "A",
      "S",
  };
  STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_backupset_type_str), "type count mismatch");
  if (type_ < 0 || type_ >= MAX) {
    LOG_ERROR("invalid backup type", K(type_));
  } else {
    str = backup_backupset_type_str[type_];
O
oceanbase-admin 已提交
2557
  }
2558 2559
  return str;
}
O
oceanbase-admin 已提交
2560

2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584
int ObBackupBackupsetType::set_type(const char* buf)
{
  int ret = OB_SUCCESS;
  BackupBackupsetType tmp_type = MAX;
  const char* backup_backupset_type_str[] = {
      "A",
      "S",
  };
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set type get invalid argument", KR(ret), KP(buf));
  } else {
    STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_backupset_type_str), "type count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_backupset_type_str); ++i) {
      if (0 == STRCMP(backup_backupset_type_str[i], buf)) {
        tmp_type = static_cast<BackupBackupsetType>(i);
      }
    }
    if (MAX == tmp_type) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup backupset type str not found", KR(ret), K(buf));
    } else {
      type_ = tmp_type;
    }
O
oceanbase-admin 已提交
2585 2586 2587 2588
  }
  return ret;
}

2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609
/* ObBackupBackupsetJobItem */
static const char* backup_backupset_job_status_strs[] = {"SCHEDULE", "BACKUP", "CLEAN", "FINISH", "CANCEL"};

ObBackupBackupsetJobItem::ObBackupBackupsetJobItem()
    : tenant_id_(OB_INVALID_ID),
      job_id_(-1),
      incarnation_(-1),
      backup_set_id_(-1),
      type_(),
      tenant_name_(),
      job_status_(JobStatus::MAX),
      backup_dest_(),
      max_backup_times_(-1),
      result_(OB_SUCCESS),
      comment_()
{}

ObBackupBackupsetJobItem::~ObBackupBackupsetJobItem()
{}

void ObBackupBackupsetJobItem::reset()
O
oceanbase-admin 已提交
2610
{
2611 2612 2613 2614 2615 2616 2617 2618 2619
  tenant_id_ = OB_INVALID_ID;
  job_id_ = -1;
  incarnation_ = -1;
  backup_set_id_ = -1;
  job_status_ = JobStatus::MAX;
  backup_dest_.reset();
  max_backup_times_ = -1;
  result_ = OB_SUCCESS;
  comment_.reset();
O
oceanbase-admin 已提交
2620 2621
}

2622
bool ObBackupBackupsetJobItem::is_valid() const
O
oceanbase-admin 已提交
2623
{
2624 2625
  return OB_INVALID_ID != tenant_id_ && job_id_ > 0 && incarnation_ > 0 && backup_set_id_ >= 0 && type_.is_valid() &&
         job_status_ >= ObBackupBackupsetJobItem::SCHEDULE && job_status_ < ObBackupBackupsetJobItem::MAX;
O
oceanbase-admin 已提交
2626 2627
}

2628
int ObBackupBackupsetJobItem::set_status(const char* buf)
O
oceanbase-admin 已提交
2629 2630
{
  int ret = OB_SUCCESS;
2631
  if (OB_ISNULL(buf)) {
O
oceanbase-admin 已提交
2632
    ret = OB_INVALID_ARGUMENT;
2633
    LOG_WARN("set backup backupset job status get invalid argument", KR(ret), KP(buf));
O
oceanbase-admin 已提交
2634
  } else {
2635 2636 2637 2638 2639
    JobStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_backupset_job_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_backupset_job_status_strs); i++) {
      if (0 == STRCMP(backup_backupset_job_status_strs[i], buf)) {
        tmp_status = static_cast<JobStatus>(i);
O
oceanbase-admin 已提交
2640
      }
2641 2642 2643 2644 2645 2646 2647
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup status str not found", KR(ret), K(buf));
    } else {
      job_status_ = tmp_status;
O
oceanbase-admin 已提交
2648 2649 2650 2651 2652
    }
  }
  return ret;
}

2653
const char* ObBackupBackupsetJobItem::get_status_str(const JobStatus& status)
O
oceanbase-admin 已提交
2654
{
2655 2656 2657 2658 2659 2660 2661 2662
  const char* str = "UNKNOWN";
  STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_backupset_job_status_strs), "status count mismatch");
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup backupset job info status", K(status));
  } else {
    str = backup_backupset_job_status_strs[status];
  }
  return str;
O
oceanbase-admin 已提交
2663 2664
}

2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701
/* ObTenantBackupBackupsetTaskItem */
ObTenantBackupBackupsetTaskItem::ObTenantBackupBackupsetTaskItem()
    : tenant_id_(OB_INVALID_ID),
      job_id_(-1),
      incarnation_(-1),
      backup_set_id_(-1),
      copy_id_(-1),
      backup_type_(),
      snapshot_version_(-1),
      prev_full_backup_set_id_(-1),
      prev_inc_backup_set_id_(-1),
      prev_backup_data_version_(-1),
      input_bytes_(0),
      output_bytes_(0),
      start_ts_(-1),
      end_ts_(-1),
      compatible_(false),
      cluster_id_(-1),
      cluster_version_(-1),
      task_status_(TaskStatus::MAX),
      src_backup_dest_(),
      dst_backup_dest_(),
      backup_data_version_(-1),
      backup_schema_version_(-1),
      total_pg_count_(-1),
      finish_pg_count_(-1),
      total_partition_count_(-1),
      finish_partition_count_(-1),
      total_macro_block_count_(-1),
      finish_macro_block_count_(-1),
      result_(-1),
      encryption_mode_(),
      passwd_(),
      is_mark_deleted_(false),
      start_replay_log_ts_(0),
      date_(0)
{}
O
oceanbase-admin 已提交
2702

2703 2704
ObTenantBackupBackupsetTaskItem::~ObTenantBackupBackupsetTaskItem()
{}
O
oceanbase-admin 已提交
2705

2706 2707 2708 2709
void ObTenantBackupBackupsetTaskItem::reset()
{}

bool ObTenantBackupBackupsetTaskItem::is_valid() const
O
oceanbase-admin 已提交
2710
{
2711 2712 2713
  return OB_INVALID_ID != tenant_id_ && job_id_ > 0 && incarnation_ > 0 && backup_set_id_ >= 0 && copy_id_ >= 0 &&
         backup_type_.is_valid() && task_status_ >= ObTenantBackupBackupsetTaskItem::GENERATE &&
         task_status_ < ObTenantBackupBackupsetTaskItem::MAX;
O
oceanbase-admin 已提交
2714 2715
}

2716
int ObTenantBackupBackupsetTaskItem::set_status(const char* buf)
O
oceanbase-admin 已提交
2717
{
2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set tenant backup backupset task status get invalid argument", KR(ret), KP(buf));
  } else {
    const char* tenant_backup_backupset_task_status_strs[] = {"GENERATE", "BACKUP", "FINISH", "CANCEL"};
    TaskStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(tenant_backup_backupset_task_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(tenant_backup_backupset_task_status_strs); i++) {
      if (0 == STRCMP(tenant_backup_backupset_task_status_strs[i], buf)) {
        tmp_status = static_cast<TaskStatus>(i);
      }
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup status str not found", KR(ret), K(buf));
    } else {
      task_status_ = tmp_status;
    }
  }
  return ret;
O
oceanbase-admin 已提交
2740 2741
}

2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753
const char* ObTenantBackupBackupsetTaskItem::get_status_str(const TaskStatus& status)
{
  const char* str = "UNKNOWN";
  const char* backup_backupset_task_status_strs[] = {"GENERATE", "BACKUP", "FINISH", "CANCEL"};
  STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_backupset_task_status_strs), "status count mismatch");
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup backupset task info status", K(status));
  } else {
    str = backup_backupset_task_status_strs[status];
  }
  return str;
}
O
oceanbase-admin 已提交
2754

2755
int ObTenantBackupBackupsetTaskItem::convert_to_backup_task_info(ObTenantBackupTaskInfo& info) const
O
oceanbase-admin 已提交
2756 2757
{
  int ret = OB_SUCCESS;
2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803
  if (!is_valid()) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("self should be valid", KR(ret), K(this));
  } else {
    info.tenant_id_ = tenant_id_;
    info.backup_set_id_ = backup_set_id_;
    info.incarnation_ = incarnation_;
    info.snapshot_version_ = snapshot_version_;
    info.prev_full_backup_set_id_ = prev_full_backup_set_id_;
    info.prev_inc_backup_set_id_ = prev_inc_backup_set_id_;
    info.prev_backup_data_version_ = prev_backup_data_version_;
    info.pg_count_ = total_pg_count_;
    info.macro_block_count_ = total_macro_block_count_;
    info.finish_pg_count_ = finish_pg_count_;
    info.finish_macro_block_count_ = finish_macro_block_count_;
    info.input_bytes_ = input_bytes_;
    info.output_bytes_ = output_bytes_;
    info.start_time_ = start_ts_;
    info.end_time_ = end_ts_;
    info.compatible_ = compatible_;
    info.cluster_version_ = cluster_version_;
    info.backup_type_ = backup_type_;
    if (TaskStatus::GENERATE == task_status_) {
      info.status_ = ObTenantBackupTaskInfo::GENERATE;
    } else if (TaskStatus::BACKUP == task_status_) {
      info.status_ = ObTenantBackupTaskInfo::DOING;
    } else if (TaskStatus::FINISH == task_status_) {
      info.status_ = ObTenantBackupTaskInfo::FINISH;
    } else if (TaskStatus::CANCEL == task_status_) {
      info.status_ = ObTenantBackupTaskInfo::CANCEL;
    }

    info.device_type_ = dst_backup_dest_.device_type_;
    info.result_ = result_;
    info.cluster_id_ = cluster_id_;
    info.backup_dest_ = dst_backup_dest_;
    info.backup_data_version_ = backup_data_version_;
    info.backup_schema_version_ = backup_schema_version_;
    info.partition_count_ = total_partition_count_;
    info.finish_partition_count_ = total_partition_count_;
    info.encryption_mode_ = encryption_mode_;
    info.passwd_ = passwd_;
    info.is_mark_deleted_ = is_mark_deleted_;
    info.start_replay_log_ts_ = start_replay_log_ts_;
    info.date_ = date_;
    info.copy_id_ = copy_id_;
O
oceanbase-admin 已提交
2804
  }
2805
  return ret;
O
oceanbase-admin 已提交
2806 2807
}

2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823
/* ObPGBackupBackupsetTaskRowKey */
ObPGBackupBackupsetTaskRowKey::ObPGBackupBackupsetTaskRowKey()
    : tenant_id_(OB_INVALID_ID),
      job_id_(-1),
      incarnation_(-1),
      backup_set_id_(-1),
      copy_id_(-1),
      table_id_(-1),
      partition_id_(-1)
{}

ObPGBackupBackupsetTaskRowKey::~ObPGBackupBackupsetTaskRowKey()
{}

int ObPGBackupBackupsetTaskRowKey::set(const uint64_t tenant_id, const int64_t job_id, const int64_t incarnation,
    const int64_t backup_set_id, const int64_t copy_id, const int64_t table_id, const int64_t partition_id)
O
oceanbase-admin 已提交
2824 2825
{
  int ret = OB_SUCCESS;
2826 2827 2828 2829 2830 2831 2832 2833
  tenant_id_ = tenant_id;
  job_id_ = job_id;
  incarnation_ = incarnation;
  backup_set_id_ = backup_set_id;
  copy_id_ = copy_id;
  table_id_ = table_id;
  partition_id_ = partition_id;
  return ret;
O
oceanbase-admin 已提交
2834 2835
}

2836
void ObPGBackupBackupsetTaskRowKey::reset()
O
oceanbase-admin 已提交
2837
{
2838 2839 2840 2841 2842 2843 2844
  tenant_id_ = OB_INVALID_ID;
  job_id_ = -1;
  incarnation_ = -1;
  backup_set_id_ = -1;
  copy_id_ = -1;
  table_id_ = -1;
  partition_id_ = -1;
O
oceanbase-admin 已提交
2845 2846
}

2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871
void ObPGBackupBackupsetTaskRowKey::reuse()
{
  tenant_id_ = 0;
  job_id_ = 0;
  incarnation_ = 0;
  backup_set_id_ = 0;
  copy_id_ = 0;
  table_id_ = 0;
  partition_id_ = 0;
}

bool ObPGBackupBackupsetTaskRowKey::is_valid() const
{
  return OB_INVALID_ID != tenant_id_ && job_id_ > 0 && incarnation_ > 0 && backup_set_id_ > 0 && copy_id_ > 0;
}

ObPGBackupBackupsetTaskStat::ObPGBackupBackupsetTaskStat()
    : total_partition_count_(0), total_macro_block_count_(0), finish_partition_count_(0), finish_macro_block_count_(0)
{}

ObPGBackupBackupsetTaskStat::~ObPGBackupBackupsetTaskStat()
{}

int ObPGBackupBackupsetTaskStat::set(const int64_t total_partition_cnt, const int64_t total_macro_block_cnt,
    const int64_t finish_partition_cnt, const int64_t finish_macro_block_cnt)
O
oceanbase-admin 已提交
2872 2873
{
  int ret = OB_SUCCESS;
2874 2875 2876 2877
  total_partition_count_ = total_partition_cnt;
  total_macro_block_count_ = total_macro_block_cnt;
  finish_partition_count_ = finish_partition_cnt;
  finish_macro_block_count_ = finish_macro_block_cnt;
O
oceanbase-admin 已提交
2878 2879 2880
  return ret;
}

2881 2882 2883 2884 2885 2886 2887
void ObPGBackupBackupsetTaskStat::reset()
{
  total_partition_count_ = 0;
  total_macro_block_count_ = 0;
  finish_partition_count_ = 0;
  finish_macro_block_count_ = 0;
}
O
oceanbase-admin 已提交
2888

2889 2890 2891 2892 2893 2894 2895 2896
bool ObPGBackupBackupsetTaskStat::is_valid() const
{
  return finish_partition_count_ >= 0 && finish_macro_block_count_ >= 0;
}

/* ObPGBackupBackupsetTaskItem */
ObPGBackupBackupsetTaskItem::ObPGBackupBackupsetTaskItem()
    : tenant_id_(OB_INVALID_ID),
O
oceanbase-admin 已提交
2897 2898 2899
      job_id_(-1),
      incarnation_(-1),
      backup_set_id_(-1),
2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910
      copy_id_(-1),
      table_id_(-1),
      partition_id_(-1),
      status_(ObPGBackupBackupsetTaskItem::MAX),
      trace_id_(),
      server_(),
      total_partition_count_(0),
      finish_partition_count_(0),
      total_macro_block_count_(0),
      finish_macro_block_count_(0),
      result_(0)
O
oceanbase-admin 已提交
2911 2912
{}

2913 2914 2915 2916 2917 2918 2919
ObPGBackupBackupsetTaskItem::~ObPGBackupBackupsetTaskItem()
{}

void ObPGBackupBackupsetTaskItem::reset()
{}

bool ObPGBackupBackupsetTaskItem::is_valid() const
O
oceanbase-admin 已提交
2920
{
2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604
  return OB_INVALID_ID != tenant_id_ && job_id_ > 0 && incarnation_ > 0 && backup_set_id_ > 0 && copy_id_ > 0 &&
         status_ >= ObPGBackupBackupsetTaskItem::PENDING && status_ < ObPGBackupBackupsetTaskItem::MAX;
}

int ObPGBackupBackupsetTaskItem::set_status(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set pg backup backupset task status get invalid argument", KR(ret), KP(buf));
  } else {
    const char* pg_backup_backupset_task_status_strs[] = {"PENDING", "DOING", "FINISH"};
    TaskStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(pg_backup_backupset_task_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(pg_backup_backupset_task_status_strs); i++) {
      if (0 == STRCMP(pg_backup_backupset_task_status_strs[i], buf)) {
        tmp_status = static_cast<TaskStatus>(i);
      }
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup status str not found", KR(ret), K(buf));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

const char* ObPGBackupBackupsetTaskItem::get_status_str(const TaskStatus& status)
{
  const char* str = "UNKNOWN";
  const char* pg_backup_backupset_task_status_strs[] = {"PENDING", "DOING", "FINISH"};
  STATIC_ASSERT(MAX == ARRAYSIZEOF(pg_backup_backupset_task_status_strs), "status count mismatch");
  if (status < 0 || status >= MAX) {
    LOG_ERROR("invalid backup backupset task info status", K(status));
  } else {
    str = pg_backup_backupset_task_status_strs[status];
  }
  return str;
}

int ObPGBackupBackupsetTaskItem::set_trace_id(const char* buf, const int64_t buf_size)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf) || buf_size < common::OB_MAX_TRACE_ID_BUFFER_SIZE) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set trace id get invalid argument", KR(ret), KP(buf), K(buf_size));
  } else if (0 == strlen(buf)) {
    // do nothing
  } else if (OB_FAIL(trace_id_.set(buf))) {
    LOG_WARN("failed to set trace id", K(ret), K(buf), K(buf_size));
  }
  return ret;
}

int ObPGBackupBackupsetTaskItem::get_trace_id(char* buf, const int64_t buf_size) const
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(get_trace_id(trace_id_, buf_size, buf))) {
    LOG_WARN("failed to get trace id", KR(ret), K(trace_id_), KP(buf), K(buf_size));
  }
  return ret;
}

int ObPGBackupBackupsetTaskItem::get_trace_id(const ObTaskId& trace_id, const int64_t buf_size, char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf) || buf_size < common::OB_MAX_TRACE_ID_BUFFER_SIZE) {
    LOG_WARN("get trace id get invalid argument", KR(ret), K(trace_id), K(buf_size));
  } else if (trace_id.is_invalid()) {
    // do noting
  } else {
    const int64_t pos = trace_id.to_string(buf, buf_size);
    if (pos > buf_size) {
      ret = OB_SIZE_OVERFLOW;
      LOG_WARN("failed to change trace id to string", K(ret), K(buf), K(buf_size));
    }
  }
  return ret;
}

/* ObBackupBackupPieceJobInfo */
ObBackupBackupPieceJobInfo::ObBackupBackupPieceJobInfo()
    : tenant_id_(OB_INVALID_ID),
      job_id_(-1),
      incarnation_(-1),
      piece_id_(-1),
      status_(ObBackupBackupPieceJobInfo::MAX),
      max_backup_times_(-1),
      result_(OB_SUCCESS),
      comment_(),
      type_()
{}

void ObBackupBackupPieceJobInfo::reset()
{
  tenant_id_ = OB_SYS_TENANT_ID;
  job_id_ = -1;
  incarnation_ = -1;
  piece_id_ = -1;
  status_ = ObBackupBackupPieceJobInfo::MAX;
  max_backup_times_ = -1;
  result_ = OB_SUCCESS;
  comment_.reset();
  type_ = JOB_TYPE_MAX;
}

bool ObBackupBackupPieceJobInfo::is_valid() const
{
  return OB_INVALID_ID != tenant_id_ && job_id_ > 0 && incarnation_ > 0 &&
         piece_id_ >= 0;  // equals 0 mean backup backuppiece all
}

const char* backup_backuppiece_job_status_strs[] = {
    "SCHEDULE",
    "DOING",
    "CANCEL",
    "FINISH",
};

int ObBackupBackupPieceJobInfo::set_status(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set job status get invalid argument", K(ret), KP(buf));
  } else {
    JobStatus tmp_status = MAX;
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_backuppiece_job_status_strs); i++) {
      if (0 == STRCMP(backup_backuppiece_job_status_strs[i], buf)) {
        tmp_status = static_cast<JobStatus>(i);
      }
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("job status str not found", K(ret), K(buf));
    } else {
      status_ = tmp_status;
    }
  }
  return ret;
}

const char* ObBackupBackupPieceJobInfo::get_status_str() const
{
  const char* str = "UNKNOWN";
  if (status_ < 0 || status_ >= MAX) {
    LOG_ERROR("invalid backup info status", K(status_));
  } else {
    str = backup_backuppiece_job_status_strs[status_];
  }
  return str;
}

bool ObBackupBackupPieceJobInfo::with_active_piece() const
{
  return type_ == WITH_ACTIVE_PIECE;
}

/* ObBackupBackupPieceTaskInfo */
ObBackupBackupPieceTaskInfo::ObBackupBackupPieceTaskInfo()
    : tenant_id_(OB_INVALID_ID),
      job_id_(-1),
      incarnation_(-1),
      round_id_(-1),
      piece_id_(-1),
      copy_id_(-1),
      task_status_(ObBackupBackupPieceTaskInfo::MAX),
      start_ts_(-1),
      end_ts_(-1),
      result_(0)
{}

void ObBackupBackupPieceTaskInfo::reset()
{
  tenant_id_ = OB_SYS_TENANT_ID;
  job_id_ = -1;
  incarnation_ = -1;
  round_id_ = -1;
  piece_id_ = -1;
  copy_id_ = -1;
  task_status_ = ObBackupBackupPieceTaskInfo::MAX;
  start_ts_ = -1;
  end_ts_ = -1;
  result_ = 0;
}

bool ObBackupBackupPieceTaskInfo::is_valid() const
{
  return OB_INVALID_ID != tenant_id_ && job_id_ > 0 && incarnation_ > 0 && round_id_ > 0 && piece_id_ > 0 &&
         copy_id_ > 0;
}
static const char* backup_backuppiece_task_status_strs[] = {
    "DOING",
    "FINISH",
};

int ObBackupBackupPieceTaskInfo::set_status(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set job status get invalid argument", K(ret), KP(buf));
  } else {

    TaskStatus tmp_status = MAX;
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_backuppiece_task_status_strs); i++) {
      if (0 == STRCMP(backup_backuppiece_task_status_strs[i], buf)) {
        tmp_status = static_cast<TaskStatus>(i);
      }
    }

    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("task status str not found", K(ret), K(buf));
    } else {
      task_status_ = tmp_status;
    }
  }
  return ret;
}

const char* ObBackupBackupPieceTaskInfo::get_status_str() const
{
  const char* str = "UNKNOWN";
  if (task_status_ < 0 || task_status_ >= MAX) {
    LOG_ERROR("invalid backup info status", K(task_status_));
  } else {
    str = backup_backuppiece_task_status_strs[task_status_];
  }
  return str;
}

int ObBackupBackupPieceTaskInfo::get_backup_piece_key(share::ObBackupPieceInfoKey& key) const
{
  int ret = OB_SUCCESS;
  key.incarnation_ = incarnation_;
  key.tenant_id_ = tenant_id_;
  key.round_id_ = round_id_;
  key.backup_piece_id_ = piece_id_;
  key.copy_id_ = copy_id_;
  return ret;
}

int ObBackupUtils::get_backup_info_default_timeout_ctx(ObTimeoutCtx& ctx)
{
  int ret = OB_SUCCESS;
  const int64_t DEFAULT_TIMEOUT_US = 2 * 1000 * 1000;  // 2s
  int64_t abs_timeout_us = ctx.get_abs_timeout();
  int64_t worker_timeout_us = THIS_WORKER.get_timeout_ts();

  if (abs_timeout_us < 0) {
    abs_timeout_us = ObTimeUtility::current_time() + DEFAULT_TIMEOUT_US;
  }

  if (INT64_MAX == worker_timeout_us) {
    abs_timeout_us = ObTimeUtility::current_time() + DEFAULT_TIMEOUT_US;
  } else if (worker_timeout_us > 0 && worker_timeout_us < abs_timeout_us) {
    abs_timeout_us = worker_timeout_us;
  }

  if (OB_FAIL(ctx.set_abs_timeout(abs_timeout_us))) {
    LOG_WARN("set timeout failed", K(ret), K(abs_timeout_us));
  } else if (ctx.is_timeouted()) {
    ret = OB_TIMEOUT;
    LOG_WARN("is timeout",
        K(ret),
        "abs_timeout",
        ctx.get_abs_timeout(),
        "this worker timeout ts",
        THIS_WORKER.get_timeout_ts());
  }
  return ret;
}

bool ObBackupUtils::is_need_retry_error(const int err)
{
  bool bret = true;
  switch (err) {
    case OB_NOT_INIT:
    case OB_INVALID_ARGUMENT:
    case OB_ERR_UNEXPECTED:
    case OB_ERR_SYS:
    case OB_INIT_TWICE:
    case OB_SRC_DO_NOT_ALLOWED_MIGRATE:
    case OB_CANCELED:
    case OB_BACKUP_DATA_VERSION_GAP_OVER_LIMIT:
    case OB_LOG_ARCHIVE_STAT_NOT_MATCH:
    case OB_NOT_SUPPORTED:
    case OB_TENANT_HAS_BEEN_DROPPED:
    case OB_CS_OUTOF_DISK_SPACE:
    case OB_HASH_NOT_EXIST:
    case OB_ARCHIVE_LOG_NOT_CONTINUES_WITH_DATA:
      bret = false;
      break;
    default:
      break;
  }
  return bret;
}

bool ObBackupUtils::is_extern_device_error(const int err)
{
  bool bret = false;
  switch (err) {
    case OB_IO_ERROR:
    case OB_OSS_ERROR:
    case OB_BACKUP_IO_PROHIBITED:
      bret = true;
      break;
    default:
      break;
  }
  return bret;
}

int ObBackupUtils::retry_get_tenant_schema_guard(const uint64_t tenant_id,
    schema::ObMultiVersionSchemaService& schema_service, const int64_t tenant_schema_version,
    schema::ObSchemaGetterGuard& schema_guard)
{
  int ret = OB_SUCCESS;
  const schema::ObMultiVersionSchemaService::RefreshSchemaMode refresh_mode =
      schema::ObMultiVersionSchemaService::RefreshSchemaMode::FORCE_FALLBACK;

  if (OB_UNLIKELY(OB_INVALID_ID == tenant_id || tenant_schema_version < OB_INVALID_VERSION)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid argument", K(tenant_id), K(tenant_schema_version));
  } else {
    int retry_times = 0;
    const int64_t sys_schema_version = OB_INVALID_VERSION;  // sys_schema_version use latest
    while (retry_times < MAX_RETRY_TIMES) {
      if (OB_FAIL(schema_service.get_tenant_schema_guard(
              tenant_id, schema_guard, tenant_schema_version, sys_schema_version, refresh_mode))) {
        STORAGE_LOG(WARN,
            "fail to get schema, sleep 1s and retry",
            K(ret),
            K(tenant_id),
            K(tenant_schema_version),
            K(sys_schema_version));
        usleep(RETRY_INTERVAL);
      } else {
        break;
      }
      ++retry_times;
    }
  }
  return ret;
}

int ObBackupUtils::get_snapshot_to_time_date(const int64_t snapshot_version, int64_t& date)
{
  int ret = OB_SUCCESS;
  date = 0;
  static const int64_t MAX_BUF_LENGTH = 64;
  char buf[MAX_BUF_LENGTH] = {0};
  int64_t tmp_date = 0;

  if (snapshot_version <= 0) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "get snapshot to time str get invalid argument", K(ret), K(snapshot_version));
  } else {
    const time_t rawtime = snapshot_version / (1000 * 1000);  // second
    struct tm time_info;
    struct tm* time_info_ptr = NULL;

    if (NULL == (time_info_ptr = (localtime_r(&rawtime, &time_info)))) {
      ret = OB_ERR_SYS;
      LOG_WARN("get localtime failed", K(ret));
    } else if (0 == strftime(buf, MAX_BUF_LENGTH, "%Y%m%d", time_info_ptr)) {
      ret = OB_ERR_UNEXPECTED;
      STORAGE_LOG(WARN, "failed to strftime", K(ret), K(buf), K(snapshot_version));
    } else if (OB_FAIL(ob_atoll(buf, tmp_date))) {
      STORAGE_LOG(WARN, "failed to atoll", K(ret), K(buf));
    } else {
      date = tmp_date;
    }
  }
  return ret;
}

int ObBackupUtils::check_user_tenant_gts(
    schema::ObMultiVersionSchemaService& schema_service, const ObIArray<uint64_t>& tenant_ids, bool& is_gts)
{
  int ret = OB_SUCCESS;
  is_gts = true;

  for (int64_t i = 0; i < tenant_ids.count() && OB_SUCC(ret) && is_gts; ++i) {
    const uint64_t tenant_id = tenant_ids.at(i);
    if (!is_valid_no_sys_tenant_id(tenant_id)) {
      // sys tenants has gts
    } else if (OB_FAIL(check_gts(schema_service, tenant_id, is_gts))) {
      LOG_WARN("failed to check gts", K(ret), K(tenant_id));
    }
  }

  return ret;
}

int ObBackupUtils::check_gts(
    schema::ObMultiVersionSchemaService& schema_service, const uint64_t tenant_id, bool& is_gts)
{
  int ret = OB_SUCCESS;
  int64_t gts_type = oceanbase::transaction::TS_SOURCE_LTS;
  schema::ObSchemaGetterGuard schema_guard;

  if (OB_FAIL(schema_service.get_tenant_schema_guard(tenant_id, schema_guard))) {
    LOG_WARN("fail to get tenant schema guard to determine tenant gts type", KR(ret), K(tenant_id));
  } else if (OB_FAIL(schema_guard.get_timestamp_service_type(tenant_id, gts_type))) {
    LOG_WARN("fail to get tenant gts switch", KR(ret), K(tenant_id));
  } else if (!oceanbase::transaction::is_ts_type_external_consistent(gts_type)) {
    is_gts = false;
    LOG_INFO("tenant is not gts", K(tenant_id));
  }
  return ret;
}

bool ObBackupUtils::can_backup_pieces_be_deleted(const ObBackupPieceStatus::STATUS& status)
{
  return ObBackupPieceStatus::BACKUP_PIECE_INACTIVE == status || ObBackupPieceStatus::BACKUP_PIECE_FROZEN == status;
}

int ObBackupUtils::check_passwd(const char* passwd_array, const char* passwd)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(passwd_array) || OB_ISNULL(passwd)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), KP(passwd_array), KP(passwd));
  } else if (STRLEN(passwd) == 0) {
    // empty password no need check
  } else if (OB_ISNULL(STRSTR(passwd_array, passwd))) {
    ret = OB_BACKUP_INVALID_PASSWORD;
    LOG_WARN("no valid passwd found", K(ret), K(passwd_array), K(passwd));
  }
  return ret;
}

int ObBackupUtils::check_is_tmp_file(const common::ObString& file_name, bool& is_tmp_file)
{
  int ret = OB_SUCCESS;
  is_tmp_file = false;
  char* buf = NULL;
  ObArenaAllocator allocator;
  if (file_name.empty()) {
    // no need check
  } else if (OB_ISNULL(buf = static_cast<char*>(allocator.alloc(file_name.length() + 1)))) {
    ret = OB_ALLOCATE_MEMORY_FAILED;
    LOG_WARN("allocate memory failed", K(ret), K(file_name));
  } else {
    STRNCPY(buf, file_name.ptr(), file_name.length());
    buf[file_name.length()] = '\0';
    char* ptr = STRSTR(buf, OB_STR_TMP_FILE_MARK);
    if (OB_ISNULL(ptr)) {
      is_tmp_file = false;
    } else {
      ptr = ptr + STRLEN(OB_STR_TMP_FILE_MARK);
      bool is_valid_tmp_file = false;
      while (OB_NOT_NULL(ptr)) {
        if ('\0' == *ptr) {
          break;  // reach str end
        } else if (!isdigit(*ptr)) {
          is_valid_tmp_file = false;
          break;
        } else {
          is_valid_tmp_file = true;
        }
        ++ptr;
      }
      if (is_valid_tmp_file) {
        is_tmp_file = true;
      } else {
        is_tmp_file = false;
      }
    }
  }
  return ret;
}

ObPhysicalRestoreInfo::ObPhysicalRestoreInfo()
    : cluster_id_(0),
      incarnation_(0),
      tenant_id_(0),
      full_backup_set_id_(0),
      inc_backup_set_id_(0),
      log_archive_round_(0),
      restore_snapshot_version_(OB_INVALID_TIMESTAMP),
      restore_start_ts_(0),
      compatible_(0),
      cluster_version_(0),
      multi_restore_path_list_(),
      backup_date_(0),
      restore_schema_version_(OB_INVALID_VERSION)
{
  backup_dest_[0] = '\0';
  cluster_name_[0] = '\0';
}

void ObPhysicalRestoreInfo::reset()
{
  backup_dest_[0] = '\0';
  cluster_name_[0] = '\0';
  cluster_id_ = 0;
  incarnation_ = 0;
  tenant_id_ = 0;
  full_backup_set_id_ = 0;
  inc_backup_set_id_ = 0;
  log_archive_round_ = 0;
  restore_snapshot_version_ = OB_INVALID_TIMESTAMP;
  restore_start_ts_ = 0;
  compatible_ = 0;
  cluster_version_ = 0;
  multi_restore_path_list_.reset();
  backup_date_ = 0;
  restore_schema_version_ = OB_INVALID_VERSION;
}

bool ObPhysicalRestoreInfo::is_valid() const
{
  return (strlen(backup_dest_) > 0 || multi_restore_path_list_.get_backup_set_path_list().count() > 0) &&
         !(strlen(backup_dest_) > 0 && multi_restore_path_list_.get_backup_set_path_list().count() > 0) &&
         strlen(cluster_name_) > 0 && cluster_id_ > 0 && OB_START_INCARNATION == incarnation_ && tenant_id_ > 0 &&
         full_backup_set_id_ > 0 && inc_backup_set_id_ > 0 && log_archive_round_ > 0 && restore_snapshot_version_ > 0 &&
         restore_start_ts_ > 0 && compatible_ > 0 && cluster_version_ > 0 && backup_date_ >= 0;
}

void ObPhysicalRestoreInfo::set_array_label(const char* lable)
{
  UNUSED(lable);
  // backup_piece_list_.set_label(lable);
  // backup_set_list_.set_label(lable);
}

bool ObPhysicalRestoreInfo::is_switch_piece_mode() const
{
  bool b_ret = false;
  if (multi_restore_path_list_.get_backup_piece_path_list().count() > 0) {
    b_ret =
        (OB_BACKUP_NO_SWITCH_PIECE_ID != multi_restore_path_list_.get_backup_piece_path_list().at(0).backup_piece_id_);
  }
  return b_ret;
}

int ObPhysicalRestoreInfo::assign(const ObPhysicalRestoreInfo& other)
{
  int ret = OB_SUCCESS;
  STRNCPY(backup_dest_, other.backup_dest_, share::OB_MAX_BACKUP_DEST_LENGTH);
  STRNCPY(cluster_name_, other.cluster_name_, common::OB_MAX_CLUSTER_NAME_LENGTH);
  cluster_id_ = other.cluster_id_;
  incarnation_ = other.incarnation_;
  tenant_id_ = other.tenant_id_;
  full_backup_set_id_ = other.full_backup_set_id_;
  inc_backup_set_id_ = other.inc_backup_set_id_;
  log_archive_round_ = other.log_archive_round_;
  restore_snapshot_version_ = other.restore_snapshot_version_;
  restore_start_ts_ = other.restore_start_ts_;
  compatible_ = other.compatible_;
  cluster_version_ = other.cluster_version_;
  backup_date_ = other.backup_date_;
  restore_schema_version_ = other.restore_schema_version_;
  if (OB_FAIL(multi_restore_path_list_.assign(other.multi_restore_path_list_))) {
    LOG_WARN("failed to assign multi restore path list", KR(ret));
  }
  return ret;
}

OB_SERIALIZE_MEMBER(ObPhysicalRestoreInfo, backup_dest_, cluster_name_, cluster_id_, incarnation_, tenant_id_,
    full_backup_set_id_, inc_backup_set_id_, log_archive_round_, restore_snapshot_version_, restore_start_ts_,
    compatible_, cluster_version_, multi_restore_path_list_, backup_date_, restore_schema_version_);

ObRestoreBackupInfo::ObRestoreBackupInfo()
    : compat_mode_(Worker::CompatMode::INVALID),
      snapshot_version_(0),
      schema_version_(0),
      frozen_data_version_(0),
      frozen_snapshot_version_(0),
      frozen_schema_version_(0),
      physical_restore_info_(),
      sys_pg_key_list_()
{
  locality_[0] = '\0';
  primary_zone_[0] = '\0';
}

bool ObRestoreBackupInfo::is_valid() const
{
  return Worker::CompatMode::INVALID != compat_mode_ && snapshot_version_ > 0 && schema_version_ > 0 &&
         frozen_data_version_ > 0 && frozen_snapshot_version_ > 0 && frozen_schema_version_ > 0 &&
         physical_restore_info_.is_valid();
}

ObPhysicalRestoreArg::ObPhysicalRestoreArg() : restore_info_(), pg_key_(), restore_data_version_(0)
{}

ObPhysicalRestoreArg::ObPhysicalRestoreArg(const ObPhysicalRestoreArg& other)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(assign(other))) {
    LOG_ERROR("failed to assign arg", K(ret), K(other));
  }
}

ObPhysicalRestoreArg& ObPhysicalRestoreArg::operator=(const ObPhysicalRestoreArg& other)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(assign(other))) {
    LOG_ERROR("failed to assign arg", K(ret), K(other));
  }
  return *this;
}

bool ObPhysicalRestoreArg::is_valid() const
{
  return restore_info_.is_valid() && pg_key_.is_valid() && restore_data_version_ > 0;
}

int ObPhysicalRestoreArg::assign(const ObPhysicalRestoreArg& other)
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(restore_info_.assign(other.restore_info_))) {
    LOG_WARN("fail to assign restore info", K(ret), K(other));
  } else {
    pg_key_ = other.pg_key_;
    restore_data_version_ = other.restore_data_version_;
  }
  return ret;
}

OB_SERIALIZE_MEMBER(ObPhysicalRestoreArg, restore_info_, pg_key_, restore_data_version_);

ObPhysicalValidateArg::ObPhysicalValidateArg()
    : backup_dest_(""),
      cluster_name_(""),
      uri_header_(""),
      storage_info_(""),
      job_id_(-1),
      task_id_(-1),
      trace_id_(),
      server_(),
      cluster_id_(-1),
      pg_key_(),
      table_id_(-1),
      partition_id_(-1),
      tenant_id_(OB_INVALID_ID),
      incarnation_(-1),
      archive_round_(-1),
      backup_set_id_(-1),
      total_partition_count_(-1),
      total_macro_block_count_(-1),
      clog_end_timestamp_(-1),
      start_log_id_(-1),
      end_log_id_(-1),
      log_size_(-1),
      is_dropped_tenant_(false),
      need_validate_clog_(true),
      full_backup_set_id_(-1),
      inc_backup_set_id_(-1),
      cluster_version_(0),
      backup_date_(0),
      compatible_(0)
{}

ObPhysicalValidateArg& ObPhysicalValidateArg::operator=(const ObPhysicalValidateArg& other)
{
  if (this != &other) {
    STRNCPY(backup_dest_, other.backup_dest_, OB_MAX_BACKUP_DEST_LENGTH);
    STRNCPY(cluster_name_, other.cluster_name_, OB_MAX_CLUSTER_NAME_LENGTH);
    STRNCPY(uri_header_, other.uri_header_, OB_MAX_URI_HEADER_LENGTH);
    STRNCPY(storage_info_, other.storage_info_, OB_MAX_BACKUP_STORAGE_INFO_LENGTH);
    job_id_ = other.job_id_;
    task_id_ = other.task_id_;
    trace_id_.set(other.trace_id_);
    // server_
    cluster_id_ = other.cluster_id_;
    pg_key_ = other.pg_key_;
    table_id_ = other.table_id_;
    partition_id_ = other.partition_id_;
    tenant_id_ = other.tenant_id_;
    incarnation_ = other.incarnation_;
    archive_round_ = other.archive_round_;
    backup_set_id_ = other.backup_set_id_;
    total_partition_count_ = other.total_partition_count_;
    total_macro_block_count_ = other.total_macro_block_count_;
O
oceanbase-admin 已提交
3605 3606 3607 3608 3609 3610 3611 3612 3613
    clog_end_timestamp_ = other.clog_end_timestamp_;
    start_log_id_ = other.start_log_id_;
    end_log_id_ = other.end_log_id_;
    log_size_ = other.log_size_;
    is_dropped_tenant_ = other.is_dropped_tenant_;
    need_validate_clog_ = other.need_validate_clog_;
    full_backup_set_id_ = other.full_backup_set_id_;
    inc_backup_set_id_ = other.inc_backup_set_id_;
    cluster_version_ = other.cluster_version_;
3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994
    backup_date_ = other.backup_date_;
    compatible_ = other.compatible_;
  }
  return *this;
}

int ObPhysicalValidateArg::assign(const ObPhysicalValidateArg& other)
{
  int ret = OB_SUCCESS;
  *this = other;
  return ret;
}

bool ObPhysicalValidateArg::is_valid() const
{
  return job_id_ >= 0 && task_id_ >= 0 && cluster_id_ >= 0 && table_id_ >= 0 && OB_INVALID_ID != tenant_id_ &&
         incarnation_ >= 0 && archive_round_ >= 0 && backup_set_id_ >= 0 && total_partition_count_ >= 0 &&
         total_macro_block_count_ >= 0 && clog_end_timestamp_ >= 0 && start_log_id_ >= 0 && end_log_id_ >= 0 &&
         log_size_ >= 0 && cluster_version_ > 0 && backup_date_ >= 0 &&
         compatible_ >= OB_BACKUP_COMPATIBLE_VERSION_V1 && compatible_ < OB_BACKUP_COMPATIBLE_VERSION_MAX;
}

int ObPhysicalValidateArg::get_validate_pgkey(common::ObPartitionKey& pg_key) const
{
  int ret = OB_SUCCESS;
  if (OB_FAIL(pg_key.init(pg_key_.get_table_id(), pg_key_.get_partition_id(), 0))) {
    STORAGE_LOG(WARN, "init pg key failed", K(ret), K(pg_key_));
  }
  return ret;
}

int ObPhysicalValidateArg::get_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  ObClusterBackupDest cluster_backup_dest;

  if (!is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObPhysicalValidateArg", K(ret), K(*this));
  } else if (OB_FAIL(path_info.dest_.set(backup_dest_, cluster_name_, cluster_id_, incarnation_))) {
    STORAGE_LOG(WARN, "failed to set backup dest", K(ret), K(*this));
  } else {
    path_info.tenant_id_ = tenant_id_;
    path_info.full_backup_set_id_ = full_backup_set_id_;
    path_info.inc_backup_set_id_ = inc_backup_set_id_;
    path_info.compatible_ = compatible_;
    path_info.backup_date_ = backup_date_;
  }
  return ret;
}

OB_SERIALIZE_MEMBER(ObPhysicalValidateArg, backup_dest_, cluster_name_, uri_header_, storage_info_, job_id_, task_id_,
    trace_id_, server_, cluster_id_, pg_key_, table_id_, partition_id_, tenant_id_, incarnation_, archive_round_,
    backup_set_id_, total_partition_count_, total_macro_block_count_, clog_end_timestamp_, start_log_id_, end_log_id_,
    log_size_, is_dropped_tenant_, need_validate_clog_, full_backup_set_id_, inc_backup_set_id_, cluster_version_,
    backup_date_, compatible_);

ObPhysicalBackupArg::ObPhysicalBackupArg()
    : uri_header_(),
      storage_info_(),
      incarnation_(0),
      tenant_id_(OB_INVALID_ID),
      backup_set_id_(0),
      backup_data_version_(0),
      backup_schema_version_(0),
      prev_full_backup_set_id_(0),
      prev_inc_backup_set_id_(0),
      prev_data_version_(0),
      task_id_(0),
      backup_type_(ObBackupType::MAX),
      backup_snapshot_version_(0),
      backup_date_(0),
      prev_backup_date_(0),
      compatible_(0)
{}

void ObPhysicalBackupArg::reset()
{
  MEMSET(uri_header_, 0, sizeof(uri_header_));
  MEMSET(storage_info_, 0, sizeof(storage_info_));
  incarnation_ = 0;
  tenant_id_ = OB_INVALID_ID;
  backup_set_id_ = 0;
  backup_data_version_ = 0;
  backup_schema_version_ = 0;
  prev_full_backup_set_id_ = 0;
  prev_inc_backup_set_id_ = 0;
  prev_data_version_ = 0;
  task_id_ = 0;
  backup_type_ = ObBackupType::MAX;
  backup_snapshot_version_ = 0;
  backup_date_ = 0;
  prev_backup_date_ = 0;
  compatible_ = 0;
}

bool ObPhysicalBackupArg::is_valid() const
{
  bool ret = true;
  if (STRLEN(uri_header_) == 0 || incarnation_ < 0 || tenant_id_ == OB_INVALID_ID || backup_set_id_ <= 0 ||
      backup_data_version_ <= 0 || backup_schema_version_ <= 0 || prev_full_backup_set_id_ < 0 ||
      prev_inc_backup_set_id_ < 0 || task_id_ < 0 ||
      (backup_type_ >= ObBackupType::MAX && backup_type_ < ObBackupType::FULL_BACKUP) ||
      backup_snapshot_version_ <= 0 || backup_date_ <= 0 ||
      (ObBackupType::INCREMENTAL_BACKUP == backup_type_ && prev_backup_date_ <= 0) ||
      compatible_ < OB_BACKUP_COMPATIBLE_VERSION_V1 || compatible_ > OB_BACKUP_COMPATIBLE_VERSION_MAX) {
    ret = false;
  }
  return ret;
}

bool ObPhysicalBackupArg::is_incremental_backup() const
{
  return ObBackupType::INCREMENTAL_BACKUP == backup_type_;
}

int ObPhysicalBackupArg::get_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  ObClusterBackupDest cluster_backup_dest;

  if (OB_UNLIKELY(!is_valid())) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObPhysicalBackupArg", K(ret), K(*this));
  } else if (OB_FAIL(backup_dest.set(uri_header_, storage_info_))) {
    LOG_WARN("failed to set backup dest", K(ret), K(*this));
  } else if (OB_FAIL(cluster_backup_dest.set(backup_dest, incarnation_))) {
    LOG_WARN("failed to set cluster backup dest", K(ret), K(backup_dest));
  } else {
    path_info.tenant_id_ = tenant_id_;
    int64_t full_backup_set_id = 0;
    int64_t inc_backup_set_id = 0;
    if (ObBackupType::FULL_BACKUP == backup_type_) {
      full_backup_set_id = backup_set_id_;
      inc_backup_set_id = backup_set_id_;
    } else if (ObBackupType::INCREMENTAL_BACKUP == backup_type_) {
      full_backup_set_id = prev_full_backup_set_id_;
      inc_backup_set_id = backup_set_id_;
    } else {
      ret = OB_ERR_UNEXPECTED;
      STORAGE_LOG(WARN, "unexpected ObBackupType", K(ret), K(*this));
    }

    if (OB_FAIL(ret)) {
    } else if (OB_FAIL(path_info.set(cluster_backup_dest,
                   tenant_id_,
                   full_backup_set_id,
                   inc_backup_set_id,
                   backup_date_,
                   compatible_))) {
      LOG_WARN("failed to set backup path info", K(ret), K(cluster_backup_dest));
    }
  }
  return ret;
}

int ObPhysicalBackupArg::get_prev_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  ObClusterBackupDest cluster_backup_dest;

  if (OB_UNLIKELY(!is_valid())) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObPhysicalBackupArg", K(ret), K(*this));
  } else if (OB_UNLIKELY(ObBackupType::INCREMENTAL_BACKUP != backup_type_)) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "only incremental backup has prev backup data", K(ret), K(*this));
  } else if (OB_FAIL(backup_dest.set(uri_header_, storage_info_))) {
    LOG_WARN("failed to set backup dest", K(ret), K(*this));
  } else if (OB_FAIL(cluster_backup_dest.set(backup_dest, incarnation_))) {
    LOG_WARN("failed to set cluster backup dest", K(ret), K(backup_dest));
  } else if (OB_FAIL(path_info.set(cluster_backup_dest,
                 tenant_id_,
                 prev_full_backup_set_id_,
                 prev_inc_backup_set_id_,
                 prev_backup_date_,
                 compatible_))) {
    LOG_WARN("failed to set backup path info", K(ret), K(cluster_backup_dest));
  }
  return ret;
}

OB_SERIALIZE_MEMBER(ObPhysicalBackupArg, storage_info_, uri_header_, incarnation_, tenant_id_, backup_set_id_,
    backup_data_version_, backup_schema_version_, prev_full_backup_set_id_, prev_inc_backup_set_id_, prev_data_version_,
    task_id_, backup_type_, backup_date_, prev_backup_date_, compatible_, backup_snapshot_version_);

OB_SERIALIZE_MEMBER(ObBackupBackupsetArg, src_uri_header_, src_storage_info_, dst_uri_header_, dst_storage_info_,
    cluster_name_, cluster_id_, job_id_, tenant_id_, incarnation_, backup_set_id_, copy_id_, backup_data_version_,
    backup_schema_version_, prev_full_backup_set_id_, prev_inc_backup_set_id_, pg_key_, server_, backup_type_,
    delete_input_, cluster_version_, tenant_dropped_, backup_date_, compatible_);

ObBackupBackupsetArg::ObBackupBackupsetArg()
    : src_uri_header_(),
      src_storage_info_(),
      dst_uri_header_(),
      dst_storage_info_(),
      cluster_name_(),
      cluster_id_(-1),
      job_id_(-1),
      tenant_id_(OB_INVALID_ID),
      incarnation_(-1),
      backup_set_id_(-1),
      copy_id_(-1),
      backup_data_version_(-1),
      backup_schema_version_(-1),
      prev_full_backup_set_id_(-1),
      prev_inc_backup_set_id_(-1),
      prev_data_version_(-1),
      pg_key_(),
      server_(),
      backup_type_(ObBackupType::MAX),
      delete_input_(false),
      cluster_version_(0),
      tenant_dropped_(false),
      backup_date_(0),
      compatible_(0)
{}

void ObBackupBackupsetArg::reset()
{
  MEMSET(src_uri_header_, 0, sizeof(src_uri_header_));
  MEMSET(src_storage_info_, 0, sizeof(src_storage_info_));
  MEMSET(dst_uri_header_, 0, sizeof(dst_uri_header_));
  MEMSET(dst_storage_info_, 0, sizeof(dst_storage_info_));
  MEMSET(cluster_name_, 0, sizeof(cluster_name_));
  job_id_ = -1;
  tenant_id_ = OB_INVALID_ID;
  cluster_id_ = -1;
  incarnation_ = -1;
  backup_set_id_ = -1;
  copy_id_ = -1;
  prev_full_backup_set_id_ = -1;
  prev_inc_backup_set_id_ = -1;
  prev_data_version_ = -1;
  pg_key_.reset();
  server_.reset();
  backup_type_ = ObBackupType::MAX;
  delete_input_ = false;
  cluster_version_ = 0;
  tenant_dropped_ = false;
  backup_date_ = 0;
  compatible_ = 0;
}

bool ObBackupBackupsetArg::is_valid() const
{
  return job_id_ > 0 && OB_INVALID_ID != tenant_id_ && cluster_id_ > 0 && incarnation_ > 0 && backup_set_id_ > 0 &&
         copy_id_ > 0 && pg_key_.is_valid() && server_.is_valid() && backup_type_ >= ObBackupType::FULL_BACKUP &&
         backup_type_ < ObBackupType::MAX && cluster_version_ > 0 && backup_date_ >= 0 &&
         compatible_ >= OB_BACKUP_COMPATIBLE_VERSION_V1 && compatible_ < OB_BACKUP_COMPATIBLE_VERSION_MAX;
}

int ObBackupBackupsetArg::get_src_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  ObClusterBackupDest cluster_backup_dest;
  if (!is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObBackupBackupsetArg", K(ret), K(*this));
  } else if (OB_FAIL(backup_dest.set(src_uri_header_, src_storage_info_))) {
    STORAGE_LOG(WARN, "failed to set src backup dest", KR(ret), K(src_uri_header_), K(src_storage_info_));
  } else if (OB_FAIL(cluster_backup_dest.set(backup_dest, incarnation_))) {
    STORAGE_LOG(WARN, "failed to set cluster backup dest", K(ret), K(backup_dest));
  } else {
    const uint64_t tenant_id = pg_key_.get_tenant_id();
    int64_t full_backup_set_id = 0;
    const int64_t inc_backup_set_id = backup_set_id_;
    if (0 == prev_full_backup_set_id_ && 0 == prev_inc_backup_set_id_) {
      full_backup_set_id = backup_set_id_;
    } else {
      full_backup_set_id = prev_full_backup_set_id_;
    }

    if (OB_FAIL(path_info.set(
            cluster_backup_dest, tenant_id, full_backup_set_id, inc_backup_set_id, backup_date_, compatible_))) {
      STORAGE_LOG(WARN, "failed to set backup path info", K(ret), K(cluster_backup_dest));
    }
  }
  return ret;
}

int ObBackupBackupsetArg::get_dst_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const
{
  int ret = OB_SUCCESS;
  ObBackupDest backup_dest;
  ObClusterBackupDest cluster_backup_dest;
  if (!is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObBackupBackupsetArg", K(ret), K(*this));
  } else if (OB_FAIL(backup_dest.set(dst_uri_header_, dst_storage_info_))) {
    STORAGE_LOG(WARN, "failed to set src backup dest", KR(ret), K(dst_uri_header_), K(dst_storage_info_));
  } else if (OB_FAIL(cluster_backup_dest.set(backup_dest, incarnation_))) {
    STORAGE_LOG(WARN, "failed to set cluster backup dest", K(ret), K(backup_dest));
  } else {
    const uint64_t tenant_id = pg_key_.get_tenant_id();
    int64_t full_backup_set_id = 0;
    int64_t inc_backup_set_id = 0;
    if (0 == prev_full_backup_set_id_ && 0 == prev_inc_backup_set_id_) {
      full_backup_set_id = backup_set_id_;
      inc_backup_set_id = backup_set_id_;
    } else {
      full_backup_set_id = prev_full_backup_set_id_;
      inc_backup_set_id = backup_set_id_;
    }
    if (OB_FAIL(path_info.set(
            cluster_backup_dest, tenant_id, full_backup_set_id, inc_backup_set_id, backup_date_, compatible_))) {
      STORAGE_LOG(WARN, "failed to set backup path info", K(ret), K(cluster_backup_dest));
    }
  }
  return ret;
}

ObBackupArchiveLogArg::ObBackupArchiveLogArg()
    : pg_key_(),
      tenant_id_(OB_INVALID_ID),
      log_archive_round_(-1),
      piece_id_(-1),
      create_date_(-1),
      job_id_(-1),
      rs_checkpoint_ts_(-1),
      src_backup_dest_(),
      src_storage_info_(),
      dst_backup_dest_(),
      dst_storage_info_()
{}

void ObBackupArchiveLogArg::reset()
{
  memset(this, 0, sizeof(ObBackupArchiveLogArg));
  log_archive_round_ = -1;
  rs_checkpoint_ts_ = -1;
}

bool ObBackupArchiveLogArg::is_valid() const
{
  return pg_key_.is_valid() && log_archive_round_ > 0 && rs_checkpoint_ts_ > 0;
}

int ObPhysicalRestoreArg::trans_schema_id(
    const uint64_t schema_id, const uint64_t trans_tenant_id_, uint64_t& trans_schema_id) const
{
  int ret = OB_SUCCESS;

  if (OB_UNLIKELY(!is_valid_id(schema_id) || !is_valid_tenant_id(trans_tenant_id_))) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid id", K(ret), K(schema_id), K(trans_tenant_id_));
  } else {
    trans_schema_id = combine_id(trans_tenant_id_, schema_id);
  }
  return ret;
}

int ObPhysicalRestoreArg::get_backup_pgkey(common::ObPartitionKey& pg_key) const
{
  int ret = OB_SUCCESS;
  uint64_t table_id = 0;
  if (OB_FAIL(trans_schema_id(pg_key_.get_tablegroup_id(), restore_info_.tenant_id_, table_id))) {
    pg_key.reset();
    STORAGE_LOG(WARN, "get backup pgkey fail", K(ret), K(pg_key_), K(restore_info_));
  } else if (OB_FAIL(pg_key.init(table_id, pg_key_.get_partition_id(), pg_key_.get_partition_cnt()))) {
    STORAGE_LOG(WARN, "init pgkey fail", K(ret), K(pg_key_));
  }
  return ret;
}

int ObPhysicalRestoreArg::change_dst_pkey_to_src_pkey(
    const common::ObPartitionKey& dst_pkey, common::ObPartitionKey& src_pkey) const
{
  int ret = OB_SUCCESS;
  uint64_t src_table_id = 0;
  if (!dst_pkey.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "dst pkey is invalid", K(ret), K(dst_pkey));
  } else if (OB_FAIL(trans_schema_id(dst_pkey.get_table_id(), restore_info_.tenant_id_, src_table_id))) {
    STORAGE_LOG(WARN, "failed to change dst table id to src table id", K(dst_pkey), K(restore_info_));
  } else if (OB_FAIL(src_pkey.init(src_table_id, dst_pkey.get_partition_id(), dst_pkey.get_partition_cnt()))) {
    STORAGE_LOG(WARN, "init pgkey fail", K(ret), K(dst_pkey));
O
oceanbase-admin 已提交
3995
  }
3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280
  return ret;
}

int ObPhysicalRestoreArg::change_src_pkey_to_dst_pkey(
    const common::ObPartitionKey& src_pkey, common::ObPartitionKey& dst_pkey) const
{
  int ret = OB_SUCCESS;
  uint64_t dst_table_id = 0;
  dst_pkey.reset();
  if (!src_pkey.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "src pkey is invalid", K(ret), K(src_pkey));
  } else if (OB_FAIL(trans_schema_id(src_pkey.get_table_id(), pg_key_.get_tenant_id(), dst_table_id))) {
    STORAGE_LOG(WARN, "failed to change src table id to dst table id", K(src_pkey), K(restore_info_));
  } else if (OB_FAIL(dst_pkey.init(dst_table_id, src_pkey.get_partition_id(), src_pkey.get_partition_cnt()))) {
    STORAGE_LOG(WARN, "init pgkey fail", K(ret), K(src_pkey));
  }
  return ret;
}

int ObPhysicalRestoreArg::trans_to_backup_schema_id(const uint64_t schema_id, uint64_t& backup_schema_id) const
{
  int ret = OB_SUCCESS;

  if (!is_valid()) {
    ret = OB_NOT_INIT;
    STORAGE_LOG(WARN, "not init", K(ret));
  } else if (OB_FAIL(trans_schema_id(schema_id, restore_info_.tenant_id_, backup_schema_id))) {
    STORAGE_LOG(WARN, "tran schema is fail", K(ret), K(*this), K(schema_id), K(backup_schema_id));
  }
  return ret;
}

int ObPhysicalRestoreArg::trans_from_backup_schema_id(const uint64_t backup_schema_id, uint64_t& schema_id) const
{
  int ret = OB_SUCCESS;

  if (!is_valid()) {
    ret = OB_NOT_INIT;
    STORAGE_LOG(WARN, "not init", K(ret));
  } else if (OB_FAIL(trans_schema_id(backup_schema_id, pg_key_.get_tenant_id(), schema_id))) {
    STORAGE_LOG(WARN, "tran schema is fail", K(ret), K(*this), K(backup_schema_id), K(schema_id));
  }
  return ret;
}

int ObPhysicalRestoreArg::get_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const
{
  int ret = OB_SUCCESS;
  ObClusterBackupDest cluster_backup_dest;

  if (OB_UNLIKELY(!is_valid())) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObPhysicalBackupArg", K(ret), K(*this));
  } else if (OB_FAIL(cluster_backup_dest.set(restore_info_.backup_dest_,
                 restore_info_.cluster_name_,
                 restore_info_.cluster_id_,
                 restore_info_.incarnation_))) {
    STORAGE_LOG(WARN, "failed to set cluster backup dest", K(ret), K(restore_info_));
  } else if (OB_FAIL(path_info.set(cluster_backup_dest,
                 restore_info_.tenant_id_,
                 restore_info_.full_backup_set_id_,
                 restore_info_.inc_backup_set_id_,
                 restore_info_.backup_date_,
                 restore_info_.compatible_))) {
    STORAGE_LOG(WARN, "failed to set backup path info", K(ret), K(restore_info_));
  }
  return ret;
}

int ObPhysicalRestoreArg::get_largest_backup_set_path(share::ObSimpleBackupSetPath& simple_path) const
{
  int ret = OB_SUCCESS;
  simple_path.reset();
  int64_t idx = -1;
  int64_t largest_backup_set_id = -1;
  for (int64_t i = 0; OB_SUCC(ret) && i < restore_info_.get_backup_set_path_list().count(); ++i) {
    const share::ObSimpleBackupSetPath& path = restore_info_.get_backup_set_path_list().at(i);
    if (path.backup_set_id_ > largest_backup_set_id) {
      largest_backup_set_id = path.backup_set_id_;
      idx = i;
    }
  }
  if (OB_SUCC(ret)) {
    if (idx >= 0) {
      simple_path = restore_info_.get_backup_set_path_list().at(idx);
      STORAGE_LOG(INFO, "largest backup set path", K(simple_path));
    } else {
      ret = OB_ENTRY_NOT_EXIST;
      STORAGE_LOG(WARN, "backup set path not found", K(ret));
    }
  }
  return ret;
}

int ObPhysicalRestoreArg::get_restore_set_list(common::ObIArray<share::ObSimpleBackupSetPath>& path_list) const
{
  int ret = OB_SUCCESS;
  path_list.reset();
  if (OB_UNLIKELY(!is_valid())) {
    ret = OB_INVALID_ARGUMENT;
    STORAGE_LOG(WARN, "invalid ObPhysicalRestoreArg", K(ret), K(*this));
  } else if (OB_FAIL(path_list.assign(restore_info_.get_backup_set_path_list()))) {
    STORAGE_LOG(WARN, "failed to assign backup set list", K(ret), K(*this));
  }
  return ret;
}

ObExternBackupInfo::ObExternBackupInfo()
    : full_backup_set_id_(0),
      inc_backup_set_id_(0),
      backup_data_version_(0),
      backup_snapshot_version_(0),
      backup_schema_version_(0),
      frozen_snapshot_version_(0),
      frozen_schema_version_(0),
      prev_full_backup_set_id_(0),
      prev_inc_backup_set_id_(0),
      prev_backup_data_version_(0),
      compatible_(0),
      cluster_version_(0),
      backup_type_(ObBackupType::MAX),
      status_(ObExternBackupInfo::DOING),
      encryption_mode_(share::ObBackupEncryptionMode::MAX_MODE),
      passwd_(),
      is_mark_deleted_(false),
      date_(0)
{}

void ObExternBackupInfo::reset()
{
  full_backup_set_id_ = 0;
  inc_backup_set_id_ = 0;
  backup_data_version_ = 0;
  backup_snapshot_version_ = 0;
  backup_schema_version_ = 0;
  frozen_snapshot_version_ = 0;
  frozen_schema_version_ = 0;
  prev_full_backup_set_id_ = 0;
  prev_inc_backup_set_id_ = 0;
  prev_backup_data_version_ = 0;
  compatible_ = 0;
  cluster_version_ = 0;
  backup_type_ = ObBackupType::MAX;
  status_ = ObExternBackupInfo::DOING;
  encryption_mode_ = share::ObBackupEncryptionMode::MAX_MODE;
  passwd_.reset();
  is_mark_deleted_ = false;
  date_ = 0;
}

bool ObExternBackupInfo::is_valid() const
{
  return full_backup_set_id_ > 0 && inc_backup_set_id_ > 0 && backup_data_version_ > 0 &&
         backup_snapshot_version_ > 0 && backup_schema_version_ > 0 && frozen_snapshot_version_ > 0 &&
         frozen_schema_version_ >= 0 && backup_type_ >= ObBackupType::FULL_BACKUP && backup_type_ < ObBackupType::MAX &&
         status_ >= SUCCESS && status_ <= FAILED && share::ObBackupEncryptionMode::is_valid(encryption_mode_) &&
         date_ >= 0;
}

bool ObExternBackupInfo::is_equal_without_status(const ObExternBackupInfo& extern_backup_info) const
{
  return full_backup_set_id_ == extern_backup_info.full_backup_set_id_ &&
         inc_backup_set_id_ == extern_backup_info.inc_backup_set_id_ &&
         backup_data_version_ == extern_backup_info.backup_data_version_ &&
         backup_snapshot_version_ == extern_backup_info.backup_snapshot_version_ &&
         backup_schema_version_ == extern_backup_info.backup_schema_version_ &&
         frozen_snapshot_version_ == extern_backup_info.frozen_snapshot_version_ &&
         frozen_schema_version_ == extern_backup_info.frozen_schema_version_ &&
         prev_full_backup_set_id_ == extern_backup_info.prev_full_backup_set_id_ &&
         prev_inc_backup_set_id_ == extern_backup_info.prev_inc_backup_set_id_ &&
         prev_backup_data_version_ == extern_backup_info.prev_backup_data_version_ &&
         compatible_ == extern_backup_info.compatible_ && cluster_version_ == extern_backup_info.cluster_version_ &&
         backup_type_ == extern_backup_info.backup_type_ && encryption_mode_ == extern_backup_info.encryption_mode_ &&
         passwd_ == extern_backup_info.passwd_ && date_ == extern_backup_info.date_;
}

bool ObExternBackupInfo::is_equal(const ObExternBackupInfo& extern_backup_info) const
{
  return is_equal_without_status(extern_backup_info) && status_ == extern_backup_info.status_ &&
         is_mark_deleted_ == extern_backup_info.is_mark_deleted_;
}

OB_SERIALIZE_MEMBER(ObExternBackupInfo, full_backup_set_id_, inc_backup_set_id_, backup_data_version_,
    backup_snapshot_version_, backup_schema_version_, frozen_snapshot_version_, frozen_schema_version_,
    prev_full_backup_set_id_, prev_inc_backup_set_id_, prev_backup_data_version_, compatible_, cluster_version_,
    backup_type_, status_, encryption_mode_, passwd_, is_mark_deleted_, date_);

ObExternBackupSetInfo::ObExternBackupSetInfo()
    : backup_set_id_(0),
      backup_snapshot_version_(0),
      compatible_(0),
      pg_count_(0),
      macro_block_count_(0),
      input_bytes_(0),
      output_bytes_(0),
      cluster_version_(0),
      compress_type_(ObCompressorType::INVALID_COMPRESSOR)
{}

void ObExternBackupSetInfo::reset()
{
  backup_set_id_ = 0;
  backup_snapshot_version_ = 0;
  compatible_ = 0;
  pg_count_ = 0;
  macro_block_count_ = 0;
  input_bytes_ = 0;
  output_bytes_ = 0;
  cluster_version_ = 0;
  compress_type_ = ObCompressorType::INVALID_COMPRESSOR;
}

bool ObExternBackupSetInfo::is_valid() const
{
  return backup_set_id_ >= 0 && backup_snapshot_version_ >= 0 && pg_count_ >= 0 && macro_block_count_ >= 0 &&
         input_bytes_ >= 0 && output_bytes_ >= 0 && cluster_version_ > 0 &&
         compress_type_ > ObCompressorType::INVALID_COMPRESSOR;
}

OB_SERIALIZE_MEMBER(ObExternBackupSetInfo, backup_set_id_, backup_snapshot_version_, compatible_, pg_count_,
    macro_block_count_, input_bytes_, output_bytes_, cluster_version_, compress_type_);

ObExternTenantInfo::ObExternTenantInfo()
    : tenant_id_(OB_INVALID_ID),
      create_timestamp_(0),
      delete_timestamp_(0),
      compat_mode_(lib::Worker::CompatMode::INVALID),
      tenant_name_(),
      backup_snapshot_version_(0)
{}

void ObExternTenantInfo::reset()
{
  tenant_id_ = OB_INVALID_ID;
  create_timestamp_ = 0;
  delete_timestamp_ = 0;
  tenant_name_.reset();
  compat_mode_ = lib::Worker::CompatMode::INVALID;
  backup_snapshot_version_ = 0;
}

bool ObExternTenantInfo::is_valid() const
{
  return tenant_id_ != OB_INVALID_ID && create_timestamp_ >= 0 && !tenant_name_.is_empty() &&
         compat_mode_ != lib::Worker::CompatMode::INVALID && backup_snapshot_version_ > 0;
}

OB_SERIALIZE_MEMBER(ObExternTenantInfo, tenant_id_, create_timestamp_, delete_timestamp_, compat_mode_, tenant_name_,
    backup_snapshot_version_);

ObExternTenantLocalityInfo::ObExternTenantLocalityInfo()
    : tenant_id_(OB_INVALID_ID),
      backup_set_id_(0),
      backup_snapshot_version_(),
      compat_mode_(lib::Worker::CompatMode::INVALID),
      tenant_name_(),
      locality_(),
      primary_zone_()
{}

void ObExternTenantLocalityInfo::reset()
{
  tenant_id_ = OB_INVALID_ID;
  backup_set_id_ = 0;
  backup_snapshot_version_ = 0;
  compat_mode_ = lib::Worker::CompatMode::INVALID;
  tenant_name_.reset();
  locality_.reset();
  primary_zone_.reset();
}

bool ObExternTenantLocalityInfo::is_valid() const
{
  return tenant_id_ != OB_INVALID_ID && backup_set_id_ > 0 && backup_snapshot_version_ > 0 &&
         compat_mode_ != lib::Worker::CompatMode::INVALID && !tenant_name_.is_empty() && !locality_.is_empty() &&
         !primary_zone_.is_empty();
}

bool ObExternTenantLocalityInfo::is_equal(const ObExternTenantLocalityInfo& tenant_locality_info) const
{
  return tenant_id_ == tenant_locality_info.tenant_id_ && backup_set_id_ == tenant_locality_info.backup_set_id_ &&
         backup_snapshot_version_ == tenant_locality_info.backup_snapshot_version_ &&
         compat_mode_ == tenant_locality_info.compat_mode_ && tenant_name_ == tenant_locality_info.tenant_name_ &&
         locality_ == tenant_locality_info.locality_ && primary_zone_ == tenant_locality_info.primary_zone_;
O
oceanbase-admin 已提交
4281 4282
}

4283 4284 4285 4286 4287 4288 4289 4290
OB_SERIALIZE_MEMBER(ObExternTenantLocalityInfo, tenant_id_, backup_set_id_, backup_snapshot_version_, compat_mode_,
    tenant_name_, locality_, primary_zone_);

ObExternBackupDiagnoseInfo::ObExternBackupDiagnoseInfo()
    : tenant_id_(OB_INVALID_ID), tenant_locality_info_(), backup_set_info_(), extern_backup_info_()
{}

void ObExternBackupDiagnoseInfo::reset()
O
oceanbase-admin 已提交
4291
{
4292 4293 4294 4295
  tenant_id_ = OB_INVALID_ID;
  tenant_locality_info_.reset();
  backup_set_info_.reset();
  extern_backup_info_.reset();
O
oceanbase-admin 已提交
4296 4297
}

4298 4299 4300 4301 4302 4303 4304 4305
static const char* backup_clean_status_strs[] = {
    "STOP",
    "PREPARE",
    "DOING",
    "CANCEL",
};

const char* ObBackupCleanInfoStatus::get_str(const STATUS& status)
O
oceanbase-admin 已提交
4306
{
4307 4308 4309 4310 4311 4312 4313 4314
  const char* str = nullptr;

  if (status < 0 || status >= MAX) {
    str = "UNKOWN";
  } else {
    str = backup_clean_status_strs[status];
  }
  return str;
O
oceanbase-admin 已提交
4315 4316
}

4317
ObBackupCleanInfoStatus::STATUS ObBackupCleanInfoStatus::get_status(const char* status_str)
O
oceanbase-admin 已提交
4318
{
4319 4320 4321 4322 4323 4324 4325 4326 4327
  ObBackupCleanInfoStatus::STATUS status = ObBackupCleanInfoStatus::MAX;

  const int64_t count = ARRAYSIZEOF(backup_clean_status_strs);
  STATIC_ASSERT(static_cast<int64_t>(ObBackupCleanInfoStatus::MAX) == count, "status count mismatch");
  for (int64_t i = 0; i < count; ++i) {
    if (0 == strcmp(status_str, backup_clean_status_strs[i])) {
      status = static_cast<ObBackupCleanInfoStatus::STATUS>(i);
      break;
    }
O
oceanbase-admin 已提交
4328
  }
4329
  return status;
O
oceanbase-admin 已提交
4330 4331
}

4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342
static const char* backup_clean_type_str[] = {
    "",
    "DELETE OBSOLETE BACKUP",
    "DELETE BACKUP SET",
    "DELETE BACKUP PIECE",
    "DELETE BACKUP ALL",
    "DELETE OBSOLETE BACKUP BACKUP",
    "DELETE BACKUP ROUND",
};

const char* ObBackupCleanType::get_str(const TYPE& type)
O
oceanbase-admin 已提交
4343
{
4344 4345 4346 4347
  const char* str = nullptr;

  if (type < 0 || type >= MAX) {
    str = "UNKOWN";
O
oceanbase-admin 已提交
4348
  } else {
4349
    str = backup_clean_type_str[type];
O
oceanbase-admin 已提交
4350
  }
4351
  return str;
O
oceanbase-admin 已提交
4352 4353
}

4354 4355 4356
ObBackupCleanType::TYPE ObBackupCleanType::get_type(const char* type_str)
{
  ObBackupCleanType::TYPE type = ObBackupCleanType::MAX;
O
oceanbase-admin 已提交
4357

4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373
  const int64_t count = ARRAYSIZEOF(backup_clean_type_str);
  STATIC_ASSERT(static_cast<int64_t>(ObBackupCleanType::MAX) == count, "status count mismatch");
  for (int64_t i = 0; i < count; ++i) {
    if (0 == strcmp(type_str, backup_clean_type_str[i])) {
      type = static_cast<ObBackupCleanType::TYPE>(i);
      break;
    }
  }
  return type;
}

ObBackupCleanInfo::ObBackupCleanInfo()
    : tenant_id_(OB_INVALID_ID),
      job_id_(0),
      start_time_(0),
      end_time_(0),
O
oceanbase-admin 已提交
4374
      incarnation_(0),
4375 4376 4377 4378
      copy_id_(0),
      type_(ObBackupCleanType::MAX),
      status_(ObBackupCleanInfoStatus::MAX),
      expired_time_(0),
O
oceanbase-admin 已提交
4379
      backup_set_id_(0),
4380 4381 4382 4383 4384 4385
      error_msg_(),
      comment_(),
      clog_gc_snapshot_(0),
      result_(OB_SUCCESS),
      backup_piece_id_(0),
      backup_round_id_(0)
O
oceanbase-admin 已提交
4386 4387
{}

4388
void ObBackupCleanInfo::reset()
O
oceanbase-admin 已提交
4389 4390
{
  tenant_id_ = OB_INVALID_ID;
4391 4392 4393 4394 4395 4396 4397 4398
  job_id_ = 0;
  start_time_ = 0;
  end_time_ = 0;
  incarnation_ = 0;
  copy_id_ = 0;
  type_ = ObBackupCleanType::MAX;
  status_ = ObBackupCleanInfoStatus::MAX;
  expired_time_ = 0;
O
oceanbase-admin 已提交
4399
  backup_set_id_ = 0;
4400 4401 4402 4403 4404 4405
  error_msg_.reset();
  comment_.reset();
  clog_gc_snapshot_ = 0;
  result_ = OB_SUCCESS;
  backup_piece_id_ = 0;
  backup_round_id_ = 0;
O
oceanbase-admin 已提交
4406 4407
}

4408
bool ObBackupCleanInfo::is_valid() const
O
oceanbase-admin 已提交
4409
{
4410 4411 4412 4413 4414 4415 4416 4417 4418
  bool is_valid = true;
  is_valid = tenant_id_ != OB_INVALID_ID && ObBackupCleanInfoStatus::is_valid(status_);
  if (is_valid) {
    if (ObBackupCleanInfoStatus::STOP != status_) {
      is_valid = ObBackupCleanType::is_valid(type_) && job_id_ >= 0 && incarnation_ > 0 &&
                 ((is_delete_obsolete() && expired_time_ > 0) || (is_backup_set_clean() && backup_set_id_ > 0) ||
                     (is_delete_backup_piece() && backup_piece_id_ >= 0) ||
                     (is_delete_backup_round() && backup_round_id_ > 0));
    }
O
oceanbase-admin 已提交
4419
  }
4420
  return is_valid;
O
oceanbase-admin 已提交
4421 4422
}

4423
int ObBackupCleanInfo::get_clean_parameter(int64_t& parameter) const
O
oceanbase-admin 已提交
4424 4425
{
  int ret = OB_SUCCESS;
4426 4427
  parameter = 0;
  if (!is_valid()) {
O
oceanbase-admin 已提交
4428
    ret = OB_INVALID_ARGUMENT;
4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439
    LOG_WARN("backup clean info is invalid", K(*this));
  } else if (is_delete_obsolete()) {
    parameter = expired_time_;
  } else if (is_backup_set_clean()) {
    parameter = backup_set_id_;
  } else if (is_delete_backup_piece()) {
    parameter = backup_piece_id_;
  } else if (is_delete_backup_round()) {
    parameter = backup_round_id_;
  } else if (is_empty_clean_type()) {
    // do nothing
O
oceanbase-admin 已提交
4440
  } else {
4441 4442
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("can not get clean paramater", K(ret), K(*this));
O
oceanbase-admin 已提交
4443 4444 4445 4446
  }
  return ret;
}

4447
int ObBackupCleanInfo::set_clean_parameter(const int64_t parameter)
O
oceanbase-admin 已提交
4448 4449
{
  int ret = OB_SUCCESS;
4450
  if (parameter < 0) {
O
oceanbase-admin 已提交
4451
    ret = OB_INVALID_ARGUMENT;
4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462
    LOG_WARN("set clean parameter get invalid argument", K(ret), K(parameter));
  } else if (is_empty_clean_type() && ObBackupCleanInfoStatus::STOP == status_) {
    // do nothing
  } else if (is_delete_obsolete()) {
    expired_time_ = parameter;
  } else if (is_backup_set_clean()) {
    backup_set_id_ = parameter;
  } else if (is_delete_backup_piece()) {
    backup_piece_id_ = parameter;
  } else if (is_delete_backup_round()) {
    backup_round_id_ = parameter;
O
oceanbase-admin 已提交
4463
  } else {
4464 4465 4466 4467
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("backup clean info is invalid, can not set parameter", K(ret), K(*this), K(parameter));
  }
  return ret;
O
oceanbase-admin 已提交
4468 4469
}

4470
int ObBackupCleanInfo::set_copy_id(const int64_t copy_id)
O
oceanbase-admin 已提交
4471
{
4472 4473 4474 4475 4476 4477 4478 4479
  int ret = OB_SUCCESS;
  if (copy_id < 0) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set copy id get invalid argument", KR(ret), K(copy_id));
  } else {
    copy_id_ = copy_id;
  }
  return ret;
O
oceanbase-admin 已提交
4480 4481
}

4482
int ObBackupCleanInfo::check_backup_clean_info_match(const ObBackupCleanInfo& clean_info) const
O
oceanbase-admin 已提交
4483 4484
{
  int ret = OB_SUCCESS;
4485
  if (!clean_info.is_valid()) {
O
oceanbase-admin 已提交
4486
    ret = OB_INVALID_ARGUMENT;
4487 4488 4489 4490 4491
    LOG_ERROR("backup info struct is invalid", K(ret), K(clean_info));
  } else if (tenant_id_ != clean_info.tenant_id_ || job_id_ != clean_info.job_id_ ||
             incarnation_ != clean_info.incarnation_ || type_ != clean_info.type_ || status_ != clean_info.status_) {
    ret = OB_BACKUP_CLEAN_INFO_NOT_MATCH;
    LOG_WARN("backup clean info is not match", K(ret), K(*this), K(clean_info));
O
oceanbase-admin 已提交
4492 4493 4494 4495
  }
  return ret;
}

4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517
ObBackupDestOpt::ObBackupDestOpt()
    : log_archive_checkpoint_interval_(0),
      recovery_window_(0),
      piece_switch_interval_(0),
      backup_copies_(0),
      auto_delete_obsolete_backup_(false),
      auto_touch_reserved_backup_(false),
      is_valid_(false)
{}

void ObBackupDestOpt::reset()
{
  log_archive_checkpoint_interval_ = 0;
  recovery_window_ = 0;
  piece_switch_interval_ = 0;
  backup_copies_ = 0;
  auto_delete_obsolete_backup_ = false;
  auto_touch_reserved_backup_ = false;
  is_valid_ = false;
}

int ObBackupDestOpt::init(const bool is_backup_backup)
O
oceanbase-admin 已提交
4518 4519
{
  int ret = OB_SUCCESS;
4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530
  const int64_t buf_len = OB_MAX_CONFIG_VALUE_LEN;
  char opt_buf[buf_len] = "";
  const bool global_auto_delete_obsolete_backup = GCONF.auto_delete_expired_backup;
  const int64_t global_recovery_window = GCONF.backup_recovery_window;
  int64_t global_checkpoint_interval = is_backup_backup ? 0 : GCONF.log_archive_checkpoint_interval;
  const bool auto_touch = GCONF._auto_update_reserved_backup_timestamp;

  if (is_backup_backup) {
    if (OB_FAIL(GCONF.backup_backup_dest_option.copy(opt_buf, buf_len))) {
      LOG_WARN("failed to copy backup dest opt", K(ret));
    }
O
oceanbase-admin 已提交
4531
  } else {
4532 4533
    if (OB_FAIL(GCONF.backup_dest_option.copy(opt_buf, buf_len))) {
      LOG_WARN("failed to copy backup dest opt", K(ret));
O
oceanbase-admin 已提交
4534 4535
    }
  }
4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550

  if (OB_FAIL(ret)) {
  } else if (OB_FAIL(init(is_backup_backup,
                 opt_buf,
                 global_auto_delete_obsolete_backup,
                 global_recovery_window,
                 global_checkpoint_interval,
                 auto_touch))) {
    LOG_WARN("failed to init",
        K(ret),
        K(global_auto_delete_obsolete_backup),
        K(global_recovery_window),
        K(global_checkpoint_interval));
  }

O
oceanbase-admin 已提交
4551 4552 4553
  return ret;
}

4554 4555 4556
int ObBackupDestOpt::init(const bool is_backup_backup, const char* opt_str,
    const bool global_auto_delete_obsolete_backup, const int64_t global_recovery_window,
    const int64_t global_checkpoint_interval, const bool global_auto_touch_reserved_backup)
O
oceanbase-admin 已提交
4557 4558
{
  int ret = OB_SUCCESS;
4559 4560 4561 4562 4563
  const bool* delete_obsolete_ptr = &global_auto_delete_obsolete_backup;
  const int64_t* recovery_window_ptr = &global_recovery_window;
  const int64_t* checkpoint_interval_ptr = &global_checkpoint_interval;
  const bool* auto_touch_ptr = &global_auto_touch_reserved_backup;
  reset();
O
oceanbase-admin 已提交
4564

4565
  if (OB_ISNULL(opt_str) || global_recovery_window < 0 || global_checkpoint_interval < 0) {
O
oceanbase-admin 已提交
4566
    ret = OB_INVALID_ARGUMENT;
4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596
    LOG_WARN("invalid args", K(ret), KP(opt_str));
  } else if (OB_FAIL(parse_opt_(
                 opt_str, delete_obsolete_ptr, recovery_window_ptr, checkpoint_interval_ptr, auto_touch_ptr))) {
    LOG_WARN("failed to parse opt", K(ret), K(opt_str));
  } else if (OB_FAIL(
                 fill_global_opt_(delete_obsolete_ptr, recovery_window_ptr, checkpoint_interval_ptr, auto_touch_ptr))) {
    LOG_WARN("failed to fill global opt", K(ret), K(opt_str));
  } else if (OB_FAIL(check_valid_())) {
    LOG_WARN("failed to check valid", K(ret), K(*this));
  } else if (is_backup_backup) {
    if (piece_switch_interval_ != 0 || backup_copies_ != 0) {
      ret = OB_INVALID_ARGUMENT;
      LOG_WARN("backup backup dest cannot support these param",
          K(ret),
          K(piece_switch_interval_),
          K(backup_copies_),
          K(*opt_str));
    }
  }

  if (OB_FAIL(ret)) {
    reset();
    is_valid_ = false;
    LOG_WARN("failed to init BackupDestOpt",
        K(opt_str),
        K(global_auto_delete_obsolete_backup),
        K(global_recovery_window),
        K(global_checkpoint_interval),
        K(global_auto_touch_reserved_backup),
        K(is_backup_backup));
O
oceanbase-admin 已提交
4597
  } else {
4598 4599 4600 4601 4602 4603 4604 4605 4606
    is_valid_ = true;
    LOG_INFO("succeed to init BackupDestOpt",
        K(*this),
        K(opt_str),
        K(global_auto_delete_obsolete_backup),
        K(global_recovery_window),
        K(global_checkpoint_interval),
        K(global_auto_touch_reserved_backup),
        K(is_backup_backup));
O
oceanbase-admin 已提交
4607 4608 4609 4610
  }
  return ret;
}

4611
int ObBackupDestOpt::check_valid_()
O
oceanbase-admin 已提交
4612 4613
{
  int ret = OB_SUCCESS;
4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636
  ;

  if (log_archive_checkpoint_interval_ != 0 &&
      log_archive_checkpoint_interval_ < OB_MIN_LOG_ARCHIVE_CHECKPOINT_INTERVAL) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("log_archive_checkpoint_interval_ cannot less than 5s", K(log_archive_checkpoint_interval_));
    LOG_USER_ERROR(OB_NOT_SUPPORTED, "log_archive_checkpoint_interval_ less than 5s is");
  } else if (recovery_window_ < 0) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("recovery_window_ must not less than 0", K(recovery_window_));
    LOG_USER_ERROR(OB_NOT_SUPPORTED, "recovery_window_ less than 0 is");
  } else if (piece_switch_interval_ != 0 && piece_switch_interval_ < OB_MIN_LOG_ARCHIVE_PIECE_SWITH_INTERVAL) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("piece_switch_interval_ less than 10s is not support", K(piece_switch_interval_));
    LOG_USER_ERROR(OB_NOT_SUPPORTED, "piece_switch_interval_ less than 10s is ");
  } else if (backup_copies_ < 0) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("backup copies must not less than 0", K(backup_copies_));
    LOG_USER_ERROR(OB_NOT_SUPPORTED, "backup copies less than 0 is");
  } else if (auto_delete_obsolete_backup_ && auto_touch_reserved_backup_) {
    ret = OB_NOT_SUPPORTED;
    LOG_WARN("cannot do auto tounch and auto delete both");
    LOG_USER_ERROR(OB_NOT_SUPPORTED, "auto delete and touch backup at same time is");
O
oceanbase-admin 已提交
4637
  }
4638

O
oceanbase-admin 已提交
4639 4640 4641
  return ret;
}

4642 4643
int ObBackupDestOpt::parse_opt_(const char* opt_str, const bool*& delete_obsolete_ptr,
    const int64_t*& recovery_window_ptr, const int64_t*& checkount_interval_ptr, const bool*& auto_touch)
O
oceanbase-admin 已提交
4644 4645
{
  int ret = OB_SUCCESS;
4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658
  const char* LOG_ARCHIVE_CHECKPOINT_INTERVAL = "log_archive_checkpoint_interval=";
  const char* RECOVERY_WINDOW = "recovery_window=";
  const char* LOG_ARCHIVE_PIECE_SWITCH_INTERVAL = "log_archive_piece_switch_interval=";
  const char* BACKUP_COPIES = "backup_copies=";
  const char* AUTO_DELETE_OBSOLETE_BACKUP = "auto_delete_obsolete_backup=";
  const char* AUTO_UPDATE_RESERVED_BACKUP_TIMESTAMP = "auto_update_reserved_backup_timestamp=";
  char buf[OB_MAX_CONFIG_VALUE_LEN] = "";
  char* token = nullptr;
  char* saved_ptr = nullptr;

  if (OB_FAIL(databuff_printf(buf, sizeof(buf), "%s", opt_str))) {
    LOG_WARN("failed to copy opt str", K(ret), K(opt_str));
  } else if (NULL != memchr(opt_str, ' ', strlen(opt_str))) {
O
oceanbase-admin 已提交
4659
    ret = OB_INVALID_ARGUMENT;
4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700
    LOG_WARN("backup dest opt should not contain backspace", K(ret), K(opt_str));
  }

  for (char* str = buf; OB_SUCC(ret); str = nullptr) {
    token = ::strtok_r(str, "&", &saved_ptr);
    if (NULL == token) {
      break;
    } else if (0 == strncmp(token, LOG_ARCHIVE_CHECKPOINT_INTERVAL, strlen(LOG_ARCHIVE_CHECKPOINT_INTERVAL))) {
      if (OB_FAIL(parse_time_interval_(
              token + strlen(LOG_ARCHIVE_CHECKPOINT_INTERVAL), log_archive_checkpoint_interval_))) {
        LOG_WARN("failed to parse log_archive_checkpoint_interval", K(ret), K(token));
      }
      checkount_interval_ptr = nullptr;
    } else if (0 == strncmp(token, RECOVERY_WINDOW, strlen(RECOVERY_WINDOW))) {
      if (OB_FAIL(parse_time_interval_(token + strlen(RECOVERY_WINDOW), recovery_window_))) {
        LOG_WARN("failed to parse recover window", K(ret), K(*token));
      }
      recovery_window_ptr = nullptr;
    } else if (0 == strncmp(token, LOG_ARCHIVE_PIECE_SWITCH_INTERVAL, strlen(LOG_ARCHIVE_PIECE_SWITCH_INTERVAL))) {
      if (OB_FAIL(parse_time_interval_(token + strlen(LOG_ARCHIVE_PIECE_SWITCH_INTERVAL), piece_switch_interval_))) {
        LOG_WARN("failed to parse log archive piece switch interval", K(ret), K(token));
      }
    } else if (0 == strncmp(token, BACKUP_COPIES, strlen(BACKUP_COPIES))) {
      if (OB_FAIL(parse_int_(token + strlen(BACKUP_COPIES), backup_copies_))) {
        LOG_WARN("failed to parse backup copies", K(ret), K(*token));
      }
    } else if (0 == strncmp(token, AUTO_DELETE_OBSOLETE_BACKUP, strlen(AUTO_DELETE_OBSOLETE_BACKUP))) {
      if (OB_FAIL(parse_bool_(token + strlen(AUTO_DELETE_OBSOLETE_BACKUP), auto_delete_obsolete_backup_))) {
        LOG_WARN("failed to parse auto delete obsolete backup", K(ret), K(token));
      }
      delete_obsolete_ptr = nullptr;
    } else if (0 ==
               strncmp(token, AUTO_UPDATE_RESERVED_BACKUP_TIMESTAMP, strlen(AUTO_UPDATE_RESERVED_BACKUP_TIMESTAMP))) {
      if (OB_FAIL(parse_bool_(token + strlen(AUTO_UPDATE_RESERVED_BACKUP_TIMESTAMP), auto_touch_reserved_backup_))) {
        LOG_WARN("failed to parse auto touch reserved backup", K(ret), K(token));
      }
      auto_touch = nullptr;
    } else {
      ret = OB_INVALID_ARGUMENT;
      LOG_ERROR("unknown backup dest opt", K(ret), K(token));
    }
O
oceanbase-admin 已提交
4701
  }
4702

O
oceanbase-admin 已提交
4703 4704 4705
  return ret;
}

4706
int ObBackupDestOpt::parse_time_interval_(const char* str, int64_t& val)
O
oceanbase-admin 已提交
4707 4708
{
  int ret = OB_SUCCESS;
4709 4710 4711 4712
  bool is_valid = true;
  val = 0;

  if (OB_ISNULL(str)) {
O
oceanbase-admin 已提交
4713
    ret = OB_INVALID_ARGUMENT;
4714 4715 4716 4717 4718 4719 4720
    LOG_WARN("invalid args", K(ret), KP(str));
  } else {
    val = ObConfigTimeParser::get(str, is_valid);
    if (!is_valid) {
      ret = OB_INVALID_ARGUMENT;
      LOG_WARN("invalid time interval str", K(ret), K(str));
    }
O
oceanbase-admin 已提交
4721 4722 4723 4724
  }
  return ret;
}

4725
int ObBackupDestOpt::parse_int_(const char* str, int64_t& val)
O
oceanbase-admin 已提交
4726 4727
{
  int ret = OB_SUCCESS;
4728 4729
  bool is_valid = true;
  val = 0;
O
oceanbase-admin 已提交
4730

4731 4732 4733 4734 4735 4736 4737 4738 4739
  if (OB_ISNULL(str)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), KP(str));
  } else {
    val = ObConfigIntParser::get(str, is_valid);
    if (!is_valid) {
      ret = OB_INVALID_ARGUMENT;
      LOG_WARN("invalid int str", K(ret), K(str));
    }
O
oceanbase-admin 已提交
4740
  }
4741

O
oceanbase-admin 已提交
4742 4743 4744
  return ret;
}

4745
int ObBackupDestOpt::parse_bool_(const char* str, bool& val)
O
oceanbase-admin 已提交
4746 4747
{
  int ret = OB_SUCCESS;
4748 4749
  bool is_valid = true;
  val = false;
O
oceanbase-admin 已提交
4750

4751 4752 4753 4754 4755 4756 4757 4758 4759
  if (OB_ISNULL(str)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), KP(str));
  } else {
    val = ObConfigBoolParser::get(str, is_valid);
    if (!is_valid) {
      ret = OB_INVALID_ARGUMENT;
      LOG_WARN("invalid bool str", K(ret), K(str));
    }
O
oceanbase-admin 已提交
4760
  }
4761

O
oceanbase-admin 已提交
4762 4763 4764
  return ret;
}

4765 4766
int ObBackupDestOpt::fill_global_opt_(const bool* delete_obsolete_ptr, const int64_t* recovery_window_ptr,
    const int64_t* checkpoint_interval_ptr, const bool* auto_touch_ptr)
O
oceanbase-admin 已提交
4767 4768
{
  int ret = OB_SUCCESS;
4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783

  if (nullptr != delete_obsolete_ptr) {
    auto_delete_obsolete_backup_ = *delete_obsolete_ptr;
  }

  if (nullptr != recovery_window_ptr) {
    recovery_window_ = *recovery_window_ptr;
  }

  if (nullptr != checkpoint_interval_ptr) {
    log_archive_checkpoint_interval_ = *checkpoint_interval_ptr;
  }

  if (nullptr != auto_touch_ptr) {
    auto_touch_reserved_backup_ = *auto_touch_ptr;
O
oceanbase-admin 已提交
4784 4785 4786 4787
  }
  return ret;
}

4788 4789
ObBackupPieceInfoKey::ObBackupPieceInfoKey()
    : incarnation_(0), tenant_id_(0), round_id_(0), backup_piece_id_(0), copy_id_(0)
O
oceanbase-admin 已提交
4790 4791
{}

4792
bool ObBackupPieceInfoKey::is_valid() const
O
oceanbase-admin 已提交
4793
{
4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995
  return OB_START_INCARNATION == incarnation_ && tenant_id_ > 0 && round_id_ > 0 && backup_piece_id_ >= 0 &&
         copy_id_ >= 0;
}

void ObBackupPieceInfoKey::reset()
{
  incarnation_ = 0;
  tenant_id_ = 0;
  round_id_ = 0;
  backup_piece_id_ = 0;
  copy_id_ = 0;
}

bool ObBackupPieceInfoKey::operator==(const ObBackupPieceInfoKey& o) const
{
  return incarnation_ == o.incarnation_ && tenant_id_ == o.tenant_id_ && round_id_ == o.round_id_ &&
         backup_piece_id_ == o.backup_piece_id_ && copy_id_ == o.copy_id_;
}

bool ObBackupPieceInfoKey::operator<(const ObBackupPieceInfoKey& o) const
{
  bool result = false;

  if (incarnation_ < o.incarnation_) {
    result = true;
  } else if (incarnation_ > o.incarnation_) {
    result = false;
  } else if (tenant_id_ < o.tenant_id_) {
    result = true;
  } else if (tenant_id_ > o.tenant_id_) {
    result = false;
  } else if (round_id_ < o.round_id_) {
    result = true;
  } else if (round_id_ > o.round_id_) {
    result = false;
  } else if (backup_piece_id_ < o.backup_piece_id_) {
    result = true;
  } else if (backup_piece_id_ > o.backup_piece_id_) {
    result = false;
  } else if (copy_id_ < o.copy_id_) {
    result = true;
  } else {
    result = false;
  }
  return result;
}

static const char* PIECE_STATUS_STRS[] = {
    "ACTIVE",
    "FREEZING",
    "FROZEN",
    "INACTIVE",
};

const char* ObBackupPieceStatus::get_str(const STATUS& status)
{
  const char* str = nullptr;

  if (status < 0 || status >= BACKUP_PIECE_MAX) {
    str = "UNKNOWN";
  } else {
    str = PIECE_STATUS_STRS[status];
  }
  return str;
}

ObBackupPieceStatus::STATUS ObBackupPieceStatus::get_status(const char* status_str)
{
  ObBackupPieceStatus::STATUS status = ObBackupPieceStatus::BACKUP_PIECE_MAX;

  const int64_t count = ARRAYSIZEOF(PIECE_STATUS_STRS);
  STATIC_ASSERT(static_cast<int64_t>(ObBackupPieceStatus::BACKUP_PIECE_MAX) == count, "status count mismatch");
  for (int64_t i = 0; i < count; ++i) {
    if (0 == strcmp(status_str, PIECE_STATUS_STRS[i])) {
      status = static_cast<ObBackupPieceStatus::STATUS>(i);
      break;
    }
  }
  return status;
}

static const char* PIECE_FILE_STATUS_STRS[] = {
    "AVAILABLE",
    "COPYING",
    "INCOMPLETE",
    "DELETING",
    "EXPIRED",
    "BROKEN",
    "DELETED",
};

const char* ObBackupFileStatus::get_str(const STATUS& status)
{
  const char* str = nullptr;

  if (status < 0 || status >= BACKUP_FILE_MAX) {
    str = "UNKNOWN";
  } else {
    str = PIECE_FILE_STATUS_STRS[status];
  }
  return str;
}

ObBackupFileStatus::STATUS ObBackupFileStatus::get_status(const char* status_str)
{
  ObBackupFileStatus::STATUS status = ObBackupFileStatus::BACKUP_FILE_MAX;

  const int64_t count = ARRAYSIZEOF(PIECE_FILE_STATUS_STRS);
  STATIC_ASSERT(static_cast<int64_t>(ObBackupFileStatus::BACKUP_FILE_MAX) == count, "status count mismatch");
  for (int64_t i = 0; i < count; ++i) {
    if (0 == strcmp(status_str, PIECE_FILE_STATUS_STRS[i])) {
      status = static_cast<ObBackupFileStatus::STATUS>(i);
      break;
    }
  }
  return status;
}

int ObBackupFileStatus::check_can_change_status(
    const ObBackupFileStatus::STATUS& src_file_status, const ObBackupFileStatus::STATUS& dest_file_status)
{
  int ret = OB_SUCCESS;
  if (ObBackupFileStatus::BACKUP_FILE_MAX == src_file_status ||
      ObBackupFileStatus::BACKUP_FILE_MAX == dest_file_status) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("check can change status get invalid argument", K(ret), K(src_file_status), K(dest_file_status));
  } else {
    switch (src_file_status) {
      case ObBackupFileStatus::BACKUP_FILE_AVAILABLE: {
        if (ObBackupFileStatus::BACKUP_FILE_BROKEN != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_EXPIRED != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_DELETING != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_AVAILABLE != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_INCOMPLETE != dest_file_status /*for sys backup backup*/) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not change backup file status", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_INCOMPLETE: {
        if (ObBackupFileStatus::BACKUP_FILE_COPYING != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_INCOMPLETE != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_DELETING != dest_file_status) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not change backup file status", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_COPYING: {
        if (ObBackupFileStatus::BACKUP_FILE_COPYING != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_AVAILABLE != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_INCOMPLETE != dest_file_status) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not change backup file status", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_BROKEN: {
        if (ObBackupFileStatus::BACKUP_FILE_BROKEN != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_DELETING != dest_file_status) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not change backup file status", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_EXPIRED: {
        if (ObBackupFileStatus::BACKUP_FILE_EXPIRED != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_AVAILABLE != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_DELETING != dest_file_status) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not change backup file status", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_DELETING: {
        if (ObBackupFileStatus::BACKUP_FILE_DELETING != dest_file_status &&
            ObBackupFileStatus::BACKUP_FILE_DELETED != dest_file_status) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not change backup file status", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_DELETED: {
        if (ObBackupFileStatus::BACKUP_FILE_DELETED != dest_file_status) {
          ret = OB_ERR_UNEXPECTED;
          LOG_WARN("can not update backup set file info", K(ret), K(src_file_status), K(dest_file_status));
        }
        break;
      }
      case ObBackupFileStatus::BACKUP_FILE_MAX: {
        ret = OB_ERR_UNEXPECTED;
        LOG_WARN("can not update backup task", K(ret), K(src_file_status), K(dest_file_status));
        break;
      }
      default: {
        ret = OB_ERR_UNEXPECTED;
        LOG_WARN("unknown file status", K(ret), K(src_file_status), K(dest_file_status));
        break;
      }
    }
  }
  return ret;
O
oceanbase-admin 已提交
4996 4997
}

4998
bool ObBackupFileStatus::can_show_in_preview(const ObBackupFileStatus::STATUS& status)
O
oceanbase-admin 已提交
4999
{
5000 5001
  return ObBackupFileStatus::BACKUP_FILE_AVAILABLE == status || ObBackupFileStatus::BACKUP_FILE_DELETING == status ||
         ObBackupFileStatus::BACKUP_FILE_DELETED == status;
O
oceanbase-admin 已提交
5002 5003
}

5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021
ObBackupPieceInfo::ObBackupPieceInfo()
    : key_(),
      create_date_(0),
      start_ts_(0),
      checkpoint_ts_(0),
      max_ts_(0),
      status_(ObBackupPieceStatus::BACKUP_PIECE_MAX),
      file_status_(ObBackupFileStatus::BACKUP_FILE_AVAILABLE),
      backup_dest_(),
      compatible_(ObTenantLogArchiveStatus::MAX),
      start_piece_id_(0)
{}

OB_SERIALIZE_MEMBER(ObBackupPieceInfo, key_.incarnation_, key_.tenant_id_, key_.round_id_, key_.backup_piece_id_,
    key_.copy_id_, create_date_, start_ts_, checkpoint_ts_, max_ts_, status_, file_status_, backup_dest_, compatible_,
    start_piece_id_);

bool ObBackupPieceInfo::is_valid() const
O
oceanbase-admin 已提交
5022
{
5023 5024 5025 5026 5027
  return key_.is_valid() && create_date_ >= 0 && status_ >= 0 && status_ < ObBackupPieceStatus::BACKUP_PIECE_MAX &&
         file_status_ >= 0 && file_status_ < ObBackupFileStatus::BACKUP_FILE_MAX && start_ts_ >= 0 &&
         checkpoint_ts_ >= 0 && max_ts_ >= 0 && backup_dest_.size() > 0 &&
         (compatible_ >= ObTenantLogArchiveStatus::NONE && compatible_ < ObTenantLogArchiveStatus::MAX) &&
         start_piece_id_ >= 0;
O
oceanbase-admin 已提交
5028 5029
}

5030
void ObBackupPieceInfo::reset()
O
oceanbase-admin 已提交
5031
{
5032 5033 5034 5035 5036 5037 5038 5039 5040 5041
  key_.reset();
  create_date_ = 0;
  status_ = ObBackupPieceStatus::BACKUP_PIECE_MAX;
  file_status_ = ObBackupFileStatus::BACKUP_FILE_AVAILABLE;
  start_ts_ = 0;
  checkpoint_ts_ = 0;
  max_ts_ = 0;
  backup_dest_.reset();
  compatible_ = ObTenantLogArchiveStatus::MAX;
  start_piece_id_ = 0;
O
oceanbase-admin 已提交
5042 5043
}

5044
bool ObBackupPieceInfo::operator==(const ObBackupPieceInfo& o) const
O
oceanbase-admin 已提交
5045
{
5046 5047 5048 5049
  return key_ == o.key_ && create_date_ == o.create_date_ && start_ts_ == o.start_ts_ &&
         checkpoint_ts_ == o.checkpoint_ts_ && max_ts_ == o.max_ts_ && status_ == o.status_ &&
         file_status_ == o.file_status_ && backup_dest_ == o.backup_dest_ && compatible_ == o.compatible_ &&
         start_piece_id_ == o.start_piece_id_;
O
oceanbase-admin 已提交
5050 5051
}

5052
int ObBackupPieceInfo::init_piece_info(const ObBackupPieceInfo& sys_piece, const uint64_t tenant_id)
O
oceanbase-admin 已提交
5053
{
5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076
  int ret = OB_SUCCESS;
  reset();

  if (!sys_piece.is_valid() || OB_INVALID_ID == tenant_id || OB_SYS_TENANT_ID != sys_piece.key_.tenant_id_) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("invalid args", K(ret), K(sys_piece), K(tenant_id));
  } else if (OB_FAIL(backup_dest_.assign(sys_piece.backup_dest_))) {
    LOG_WARN("failed to copy backup dest", K(ret), K(sys_piece));
  } else {
    // key
    key_ = sys_piece.key_;
    key_.tenant_id_ = tenant_id;
    create_date_ = sys_piece.create_date_;
    // value
    start_ts_ = sys_piece.start_ts_;
    checkpoint_ts_ = sys_piece.checkpoint_ts_;
    max_ts_ = sys_piece.max_ts_;
    status_ = sys_piece.status_;
    file_status_ = sys_piece.file_status_;
    compatible_ = sys_piece.compatible_;
    start_piece_id_ = sys_piece.start_piece_id_;
  }
  return ret;
O
oceanbase-admin 已提交
5077 5078
}

5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090
int ObBackupPieceInfo::get_backup_dest(ObBackupDest& backup_dest) const
{
  int ret = OB_SUCCESS;
  backup_dest.reset();
  if (backup_dest_.is_empty()) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("get invalid args", KR(ret));
  } else if (OB_FAIL(backup_dest.set(backup_dest_.ptr()))) {
    LOG_WARN("failed to set backup dest", KR(ret), K(backup_dest_));
  }
  return ret;
}
O
oceanbase-admin 已提交
5091

5092 5093
ObNonFrozenBackupPieceInfo::ObNonFrozenBackupPieceInfo()
    : has_prev_piece_info_(false), prev_piece_info_(), cur_piece_info_()
O
oceanbase-admin 已提交
5094 5095
{}

5096
void ObNonFrozenBackupPieceInfo::reset()
O
oceanbase-admin 已提交
5097
{
5098 5099 5100
  has_prev_piece_info_ = false;
  prev_piece_info_.reset();
  cur_piece_info_.reset();
O
oceanbase-admin 已提交
5101 5102
}

5103
bool ObNonFrozenBackupPieceInfo::is_valid() const
O
oceanbase-admin 已提交
5104
{
5105
  bool is_valid = true;
O
oceanbase-admin 已提交
5106

5107 5108 5109 5110
  if (!cur_piece_info_.is_valid()) {
    is_valid = false;
    LOG_WARN("cur piece info is invalid", K(*this));
  }
O
oceanbase-admin 已提交
5111

5112 5113 5114 5115 5116 5117 5118 5119 5120
  if (has_prev_piece_info_ && is_valid) {
    if (!prev_piece_info_.is_valid()) {
      is_valid = false;
      LOG_WARN("prev piece info is invalid", K(*this));
    } else if (ObBackupPieceStatus::BACKUP_PIECE_ACTIVE == prev_piece_info_.status_) {
      is_valid = false;
      LOG_WARN("previous piece info is active", K(*this));
    }
  }
O
oceanbase-admin 已提交
5121

5122
  return is_valid;
O
oceanbase-admin 已提交
5123 5124
}

5125
int ObNonFrozenBackupPieceInfo::get_backup_piece_id(int64_t& active_piece_id) const
O
oceanbase-admin 已提交
5126
{
5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137
  int ret = OB_SUCCESS;
  active_piece_id = -1;

  if (!is_valid()) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("invalid piece info", K(ret), K(*this));
  } else {
    active_piece_id = cur_piece_info_.key_.backup_piece_id_;
  }

  return ret;
O
oceanbase-admin 已提交
5138 5139
}

5140
int ObNonFrozenBackupPieceInfo::get_backup_piece_info(int64_t& active_piece_id, int64_t& active_piece_create_date) const
O
oceanbase-admin 已提交
5141
{
5142 5143 5144
  int ret = OB_SUCCESS;
  active_piece_id = -1;
  active_piece_create_date = OB_INVALID_TIMESTAMP;
O
oceanbase-admin 已提交
5145

5146 5147 5148 5149 5150 5151 5152
  if (!is_valid()) {
    ret = OB_ERR_UNEXPECTED;
    LOG_WARN("invalid piece info", K(ret), K(*this));
  } else {
    active_piece_id = cur_piece_info_.key_.backup_piece_id_;
    active_piece_create_date = cur_piece_info_.create_date_;
  }
O
oceanbase-admin 已提交
5153

5154 5155
  return ret;
}
O
oceanbase-admin 已提交
5156

5157
int64_t ObNonFrozenBackupPieceInfo::to_string(char* buf, const int64_t buf_len) const
O
oceanbase-admin 已提交
5158
{
5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173
  int64_t pos = 0;

  if (OB_ISNULL(buf) || buf_len <= 0) {
    // do nothing
  } else {
    J_OBJ_START();
    J_KV(K_(has_prev_piece_info), K_(cur_piece_info));
    if (has_prev_piece_info_) {
      J_COMMA();
      J_KV(K_(prev_piece_info));
    }

    J_OBJ_END();
  }
  return pos;
O
oceanbase-admin 已提交
5174 5175
}

5176
const char* backup_set_file_info_status_strs[] = {
O
oceanbase-admin 已提交
5177
    "DOING",
5178 5179
    "SUCCESS",
    "FAILED",
O
oceanbase-admin 已提交
5180 5181
};

5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215
ObBackupSetFileInfo::ObBackupSetFileInfo()
    : tenant_id_(OB_INVALID_ID),
      backup_set_id_(0),
      incarnation_(0),
      copy_id_(-1),
      snapshot_version_(0),
      prev_full_backup_set_id_(0),
      prev_inc_backup_set_id_(0),
      prev_backup_data_version_(0),
      pg_count_(0),
      macro_block_count_(0),
      finish_pg_count_(0),
      finish_macro_block_count_(0),
      input_bytes_(0),
      output_bytes_(0),
      start_time_(0),
      end_time_(0),
      compatible_(0),
      cluster_version_(0),
      backup_type_(),
      status_(BackupSetStatus::MAX),
      result_(0),
      cluster_id_(OB_INVALID_CLUSTER_ID),
      backup_dest_(),
      backup_data_version_(0),
      backup_schema_version_(0),
      partition_count_(0),
      finish_partition_count_(0),
      encryption_mode_(ObBackupEncryptionMode::MAX_MODE),
      passwd_(),
      file_status_(ObBackupFileStatus::BACKUP_FILE_MAX),
      start_replay_log_ts_(0),
      date_(0)
{}
O
oceanbase-admin 已提交
5216

5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250
void ObBackupSetFileInfo::reset()
{
  tenant_id_ = OB_INVALID_ID;
  backup_set_id_ = 0;
  incarnation_ = 0;
  copy_id_ = -1;
  snapshot_version_ = 0;
  prev_full_backup_set_id_ = 0;
  prev_inc_backup_set_id_ = 0;
  prev_backup_data_version_ = 0;
  pg_count_ = 0;
  macro_block_count_ = 0;
  finish_pg_count_ = 0;
  finish_macro_block_count_ = 0;
  input_bytes_ = 0;
  output_bytes_ = 0;
  start_time_ = 0;
  end_time_ = 0;
  compatible_ = 0;
  cluster_version_ = 0;
  backup_type_.reset();
  status_ = BackupSetStatus::MAX;
  result_ = 0;
  cluster_id_ = OB_INVALID_CLUSTER_ID;
  backup_dest_.reset();
  backup_data_version_ = 0;
  backup_schema_version_ = 0;
  partition_count_ = 0;
  finish_partition_count_ = 0;
  encryption_mode_ = share::ObBackupEncryptionMode::MAX_MODE;
  passwd_.reset();
  file_status_ = ObBackupFileStatus::BACKUP_FILE_MAX;
  start_replay_log_ts_ = 0;
  date_ = 0;
O
oceanbase-admin 已提交
5251 5252
}

5253
bool ObBackupSetFileInfo::is_key_valid() const
O
oceanbase-admin 已提交
5254
{
5255 5256
  return tenant_id_ != OB_INVALID_ID && backup_set_id_ > 0 && incarnation_ > 0 && copy_id_ >= 0;
}
O
oceanbase-admin 已提交
5257

5258 5259 5260 5261
bool ObBackupSetFileInfo::is_valid() const
{
  return is_key_valid() && BackupSetStatus::MAX != status_ &&
         share::ObBackupEncryptionMode::is_valid(encryption_mode_) && ObBackupFileStatus::is_valid(file_status_);
O
oceanbase-admin 已提交
5262 5263
}

5264 5265 5266 5267 5268
bool ObBackupSetFileInfo::is_same_task(const ObBackupSetFileInfo& other) const
{
  return tenant_id_ == other.tenant_id_ && backup_set_id_ == other.backup_set_id_ &&
         incarnation_ == other.incarnation_ && copy_id_ == other.copy_id_;
}
O
oceanbase-admin 已提交
5269

5270
const char* ObBackupSetFileInfo::get_backup_set_status_str() const
O
oceanbase-admin 已提交
5271
{
5272
  const char* str = "UNKNOWN";
O
oceanbase-admin 已提交
5273

5274 5275 5276
  STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_set_file_info_status_strs), "status count mismatch");
  if (status_ < 0 || status_ >= MAX) {
    LOG_WARN("invalid backup set status", K(status_));
O
oceanbase-admin 已提交
5277
  } else {
5278
    str = backup_set_file_info_status_strs[status_];
O
oceanbase-admin 已提交
5279 5280 5281 5282
  }
  return str;
}

5283
int ObBackupSetFileInfo::set_backup_set_status(const char* buf)
O
oceanbase-admin 已提交
5284
{
5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("set backup task status get invalid argument", K(ret), KP(buf));
  } else {
    BackupSetStatus tmp_status = MAX;
    STATIC_ASSERT(MAX == ARRAYSIZEOF(backup_set_file_info_status_strs), "status count mismatch");
    for (int64_t i = 0; i < ARRAYSIZEOF(backup_set_file_info_status_strs); i++) {
      if (0 == STRCMP(backup_set_file_info_status_strs[i], buf)) {
        tmp_status = static_cast<BackupSetStatus>(i);
      }
    }
O
oceanbase-admin 已提交
5297

5298 5299 5300 5301 5302
    if (MAX == tmp_status) {
      ret = OB_ENTRY_NOT_EXIST;
      LOG_WARN("backup status str not found", K(ret), K(buf));
    } else {
      status_ = tmp_status;
O
oceanbase-admin 已提交
5303 5304
    }
  }
5305
  return ret;
O
oceanbase-admin 已提交
5306 5307
}

5308
int ObBackupSetFileInfo::extract_from_backup_task_info(const ObTenantBackupTaskInfo& task_info)
O
oceanbase-admin 已提交
5309
{
5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369
  int ret = OB_SUCCESS;
  if (!task_info.is_valid()) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("extract from backup task info get invalid argument", K(ret), K(task_info));
  } else {
    char backup_dest[OB_MAX_BACKUP_DEST_LENGTH] = "";
    tenant_id_ = task_info.tenant_id_;
    backup_set_id_ = task_info.backup_set_id_;
    incarnation_ = task_info.incarnation_;
    copy_id_ = 0;  // first backup image copy id is 0
    snapshot_version_ = task_info.snapshot_version_;
    prev_full_backup_set_id_ = task_info.prev_full_backup_set_id_;
    prev_inc_backup_set_id_ = task_info.prev_inc_backup_set_id_;
    prev_backup_data_version_ = task_info.prev_backup_data_version_;
    pg_count_ = task_info.pg_count_;
    macro_block_count_ = task_info.macro_block_count_;
    finish_pg_count_ = task_info.finish_pg_count_;
    finish_macro_block_count_ = task_info.finish_macro_block_count_;
    input_bytes_ = task_info.input_bytes_;
    output_bytes_ = task_info.output_bytes_;
    start_time_ = task_info.start_time_;
    end_time_ = task_info.end_time_;
    compatible_ = task_info.compatible_;
    cluster_version_ = task_info.cluster_version_;
    backup_type_.type_ = task_info.backup_type_.type_;
    if (ObTenantBackupTaskItem::FINISH == task_info.status_) {
      status_ = OB_SUCCESS == task_info.result_ ? ObBackupSetFileInfo::SUCCESS : ObBackupSetFileInfo::FAILED;
    } else {
      status_ = ObBackupSetFileInfo::DOING;
    }
    result_ = task_info.result_;
    cluster_id_ = task_info.cluster_id_;
    backup_data_version_ = task_info.backup_data_version_;
    backup_schema_version_ = task_info.backup_schema_version_;
    partition_count_ = task_info.partition_count_;
    finish_partition_count_ = task_info.finish_partition_count_;
    encryption_mode_ = task_info.encryption_mode_;
    passwd_ = task_info.passwd_;
    start_replay_log_ts_ = task_info.start_replay_log_ts_;
    date_ = task_info.date_;
    if (ObBackupSetFileInfo::DOING == status_) {
      file_status_ = ObBackupFileStatus::BACKUP_FILE_COPYING;
    } else if (ObBackupSetFileInfo::SUCCESS == status_) {
      file_status_ = ObBackupFileStatus::BACKUP_FILE_AVAILABLE;
    } else if (ObBackupSetFileInfo::FAILED == status_) {
      file_status_ = ObBackupFileStatus::BACKUP_FILE_INCOMPLETE;
    }
    if (task_info.is_mark_deleted_) {
      file_status_ = ObBackupFileStatus::BACKUP_FILE_DELETING;
    }
    if (OB_FAIL(task_info.backup_dest_.get_backup_dest_str(backup_dest, OB_MAX_URI_LENGTH))) {
      LOG_WARN("failed to get backup dest str", K(ret), K(task_info));
    } else if (OB_FAIL(backup_dest_.assign(backup_dest))) {
      LOG_WARN("failed to assign backup dest str", K(ret), K(backup_dest));
    } else if (!is_valid()) {
      ret = OB_ERR_UNEXPECTED;
      LOG_WARN("failed to extract from backup task info", K(ret), K(*this), K(task_info));
    }
  }
  return ret;
O
oceanbase-admin 已提交
5370 5371
}

5372 5373
int ObBackupSetFileInfo::extract_from_backup_info(
    const ObBaseBackupInfoStruct& info, const ObExternBackupInfo& extern_backup_info)
O
oceanbase-admin 已提交
5374
{
5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414
  int ret = OB_SUCCESS;
  if (!extern_backup_info.is_valid() || !info.is_valid() || info.backup_status_.is_stop_status()) {
    ret = OB_INVALID_ARGUMENT;
    LOG_WARN("extract from extern backup info get invalid argument", K(ret), K(extern_backup_info), K(info));
  } else {
    tenant_id_ = info.tenant_id_;
    backup_set_id_ = info.backup_set_id_;
    incarnation_ = info.incarnation_;
    copy_id_ = 0;  // first backup image copy id is 0
    snapshot_version_ = info.backup_snapshot_version_;
    prev_full_backup_set_id_ = extern_backup_info.prev_full_backup_set_id_;
    prev_inc_backup_set_id_ = extern_backup_info.prev_inc_backup_set_id_;
    prev_backup_data_version_ = extern_backup_info.prev_backup_data_version_;
    pg_count_ = 0;
    macro_block_count_ = 0;
    finish_pg_count_ = 0;
    finish_macro_block_count_ = 0;
    input_bytes_ = 0;
    output_bytes_ = 0;
    start_time_ = 0;
    end_time_ = 0;
    compatible_ = extern_backup_info.compatible_;
    cluster_version_ = extern_backup_info.cluster_version_;
    backup_type_.type_ = extern_backup_info.backup_type_;
    status_ = ObBackupSetFileInfo::DOING;
    result_ = OB_SUCCESS;
    cluster_id_ = GCONF.cluster_id;
    backup_data_version_ = info.backup_data_version_;
    backup_schema_version_ = info.backup_schema_version_;
    partition_count_ = 0;
    finish_partition_count_ = 0;
    encryption_mode_ = info.encryption_mode_;
    passwd_ = info.passwd_;
    backup_dest_ = info.backup_dest_;
    file_status_ = ObBackupFileStatus::BACKUP_FILE_COPYING;
    start_replay_log_ts_ = 0;
    date_ = extern_backup_info.date_;
    if (!is_valid()) {
      ret = OB_ERR_UNEXPECTED;
      LOG_WARN("failed to extract backup set file info from backup info", K(ret), K(info), K(extern_backup_info));
O
oceanbase-admin 已提交
5415 5416
    }
  }
5417
  return ret;
O
oceanbase-admin 已提交
5418 5419
}

5420
int ObBackupSetFileInfo::check_passwd(const char* passwd_array, const char* passwd)
O
oceanbase-admin 已提交
5421 5422
{
  int ret = OB_SUCCESS;
5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433
  if (OB_FAIL(ObBackupUtils::check_passwd(passwd_array, passwd))) {
    LOG_WARN("failed to check passwd", KR(ret), K(passwd_array), K(passwd));
  }
  return ret;
}

int ObBackupSetFileInfo::convert_to_backup_backup_task_info(const int64_t job_id, const int64_t copy_id,
    const int64_t result, const share::ObBackupDest& dst_backup_dest, ObTenantBackupBackupsetTaskInfo& bb_task)
{
  int ret = OB_SUCCESS;
  if (job_id < 0 || copy_id <= 0 || !dst_backup_dest.is_valid()) {
O
oceanbase-admin 已提交
5434
    ret = OB_INVALID_ARGUMENT;
5435 5436 5437
    LOG_WARN("get invalid args", KR(ret), K(job_id), K(copy_id));
  } else if (OB_FAIL(bb_task.src_backup_dest_.set(backup_dest_.ptr()))) {
    LOG_WARN("failed to set backup dest", KR(ret), K(backup_dest_));
O
oceanbase-admin 已提交
5438
  } else {
5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471
    bb_task.tenant_id_ = tenant_id_;
    bb_task.job_id_ = job_id;
    bb_task.incarnation_ = incarnation_;
    bb_task.backup_set_id_ = backup_set_id_;
    bb_task.copy_id_ = copy_id;
    bb_task.backup_type_ = backup_type_;
    bb_task.snapshot_version_ = snapshot_version_;
    bb_task.prev_full_backup_set_id_ = prev_full_backup_set_id_;
    bb_task.prev_inc_backup_set_id_ = prev_inc_backup_set_id_;
    bb_task.prev_backup_data_version_ = prev_backup_data_version_;
    bb_task.input_bytes_ = input_bytes_;
    bb_task.output_bytes_ = output_bytes_;
    bb_task.start_ts_ = start_time_;
    bb_task.end_ts_ = end_time_;
    bb_task.compatible_ = compatible_;
    bb_task.cluster_id_ = cluster_id_;
    bb_task.cluster_version_ = cluster_version_;
    bb_task.task_status_ = ObTenantBackupBackupsetTaskItem::FINISH;
    bb_task.dst_backup_dest_ = dst_backup_dest;
    bb_task.backup_data_version_ = backup_data_version_;
    bb_task.backup_schema_version_ = backup_schema_version_;
    bb_task.total_pg_count_ = pg_count_;
    bb_task.finish_pg_count_ = finish_pg_count_;
    bb_task.total_partition_count_ = partition_count_;
    bb_task.finish_partition_count_ = finish_partition_count_;
    bb_task.total_macro_block_count_ = macro_block_count_;
    bb_task.finish_macro_block_count_ = finish_macro_block_count_;
    bb_task.result_ = result;
    bb_task.encryption_mode_ = encryption_mode_;
    bb_task.passwd_ = passwd_;
    bb_task.is_mark_deleted_ = false;
    bb_task.start_replay_log_ts_ = start_replay_log_ts_;
    bb_task.date_ = date_;
O
oceanbase-admin 已提交
5472 5473 5474 5475
  }
  return ret;
}

5476
int ObBackupSetFileInfo::get_backup_dest(share::ObBackupDest& backup_dest) const
O
oceanbase-admin 已提交
5477 5478
{
  int ret = OB_SUCCESS;
5479 5480
  backup_dest.reset();
  if (backup_dest_.is_empty()) {
O
oceanbase-admin 已提交
5481
    ret = OB_INVALID_ARGUMENT;
5482 5483 5484
    LOG_WARN("get invalid args", KR(ret));
  } else if (OB_FAIL(backup_dest.set(backup_dest_.ptr()))) {
    LOG_WARN("failed to set backup dest", KR(ret), K(backup_dest_));
O
oceanbase-admin 已提交
5485 5486 5487 5488
  }
  return ret;
}

5489 5490 5491 5492 5493 5494
OB_SERIALIZE_MEMBER(ObBackupSetFileInfo, tenant_id_, backup_set_id_, incarnation_, copy_id_, snapshot_version_,
    prev_full_backup_set_id_, prev_inc_backup_set_id_, prev_backup_data_version_, pg_count_, macro_block_count_,
    finish_pg_count_, finish_macro_block_count_, input_bytes_, output_bytes_, start_time_, end_time_, compatible_,
    cluster_version_, backup_type_.type_, status_, result_, cluster_id_, backup_dest_, backup_data_version_,
    backup_schema_version_, partition_count_, finish_partition_count_, encryption_mode_, passwd_, file_status_,
    start_replay_log_ts_, date_);
O
oceanbase-admin 已提交
5495

5496
ObBackupRegion::ObBackupRegion() : region_(), priority_(-1)
O
oceanbase-admin 已提交
5497 5498
{}

5499
ObBackupRegion::~ObBackupRegion()
O
oceanbase-admin 已提交
5500 5501
{}

5502
void ObBackupRegion::reset()
O
oceanbase-admin 已提交
5503
{
5504 5505
  region_.reset();
  priority_ = -1;
O
oceanbase-admin 已提交
5506 5507
}

5508
int ObBackupRegion::set(const ObString& region, const int64_t priority)
O
oceanbase-admin 已提交
5509 5510
{
  int ret = OB_SUCCESS;
5511
  if (0 == region.length() || priority < 0) {
O
oceanbase-admin 已提交
5512
    ret = OB_INVALID_ARGUMENT;
5513 5514 5515
    OB_LOG(WARN, "set backup region get invalid argument", K(ret), K(region), K(priority));
  } else if (OB_FAIL(region_.assign(region))) {
    OB_LOG(WARN, "failed to assign region", K(ret), K(region));
O
oceanbase-admin 已提交
5516
  } else {
5517
    priority_ = priority;
O
oceanbase-admin 已提交
5518 5519 5520 5521
  }
  return ret;
}

5522 5523 5524 5525 5526 5527 5528
ObBackupZone::ObBackupZone() : zone_(), priority_(-1)
{}

ObBackupZone::~ObBackupZone()
{}

void ObBackupZone::reset()
O
oceanbase-admin 已提交
5529
{
5530 5531
  zone_.reset();
  priority_ = -1;
O
oceanbase-admin 已提交
5532 5533
}

5534
int ObBackupZone::set(const ObString& zone, const int64_t priority)
O
oceanbase-admin 已提交
5535 5536
{
  int ret = OB_SUCCESS;
5537 5538 5539 5540 5541
  if (0 == zone.length() || priority < 0) {
    ret = OB_INVALID_ARGUMENT;
    OB_LOG(WARN, "set backup zone get invalid argument", K(ret), K(zone), K(priority));
  } else if (OB_FAIL(zone_.assign(zone))) {
    OB_LOG(WARN, "failed to assign zone", K(ret), K(zone));
O
oceanbase-admin 已提交
5542
  } else {
5543
    priority_ = priority;
O
oceanbase-admin 已提交
5544 5545 5546 5547
  }
  return ret;
}

5548 5549 5550 5551
ObBackupSetIdPair::ObBackupSetIdPair() : backup_set_id_(0), copy_id_(0)
{}

void ObBackupSetIdPair::reset()
O
oceanbase-admin 已提交
5552
{
5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602
  backup_set_id_ = 0;
  copy_id_ = 0;
}

bool ObBackupSetIdPair::is_valid() const
{
  return backup_set_id_ > 0 && copy_id_ >= 0;
}

ObBackupPieceIdPair::ObBackupPieceIdPair() : backup_piece_id_(0), copy_id_(0)
{}

void ObBackupPieceIdPair::reset()
{
  backup_piece_id_ = 0;
  copy_id_ = 0;
}

bool ObBackupPieceIdPair::is_valid() const
{
  return backup_piece_id_ > 0 && copy_id_ >= 0;
}

ObBackupStatistics::ObBackupStatistics()
    : pg_count_(0),
      finish_pg_count_(0),
      partition_count_(0),
      finish_partition_count_(0),
      macro_block_count_(0),
      finish_macro_block_count_(0),
      input_bytes_(0),
      output_bytes_(0)
{}

void ObBackupStatistics::reset()
{
  pg_count_ = 0;
  finish_pg_count_ = 0;
  partition_count_ = 0;
  finish_partition_count_ = 0;
  macro_block_count_ = 0;
  finish_macro_block_count_ = 0;
  input_bytes_ = 0;
  output_bytes_ = 0;
}

bool ObBackupStatistics::is_valid() const
{
  return pg_count_ >= 0 && finish_pg_count_ >= 0 && partition_count_ >= 0 && finish_partition_count_ >= 0 &&
         macro_block_count_ >= 0 && finish_macro_block_count_ >= 0 && input_bytes_ >= 0 && output_bytes_ >= 0;
O
oceanbase-admin 已提交
5603
}