ob_backup_struct.h 76.1 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 20 21 22 23 24 25 26 27 28 29 30 31 32
/**
 * 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.
 */

#ifndef OCEANBASE_SHARE_BACKUP_OB_BACKUP_STRUCT_H_
#define OCEANBASE_SHARE_BACKUP_OB_BACKUP_STRUCT_H_

#include "lib/container/ob_array.h"
#include "lib/restore/ob_storage.h"
#include "lib/compress/ob_compressor_pool.h"
#include "lib/utility/utility.h"
#include "lib/string/ob_fixed_length_string.h"
#include "lib/worker.h"
#include "common/ob_role.h"
#include "common/ob_timeout_ctx.h"
#include "common/ob_region.h"
#include "share/ob_define.h"
#include "share/ob_force_print_log.h"
#include "share/ob_encryption_util.h"
#include "share/schema/ob_schema_getter_guard.h"

namespace oceanbase {
namespace share {

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
enum ObBackupBackupCopyIdLevel {
  OB_BB_COPY_ID_LEVEL_CLUSTER_GCONF_DEST = 1,
  OB_BB_COPY_ID_LEVEL_CLUSTER_USER_DEST = 2,
  OB_BB_COPY_ID_LEVEL_TENANT_GCONF_DEST = 3,
  OB_BB_COPY_ID_LEVEL_TENANT_USER_DEST = 4,
  OB_BB_COPY_ID_LEVEL_MAX,
};

int get_backup_backup_start_copy_id(const ObBackupBackupCopyIdLevel& copy_id_level, int64_t& copy_id);
int get_backup_copy_id_range_by_copy_level(
    const ObBackupBackupCopyIdLevel& copy_id_level, int64_t& left_copy_id, int64_t& right_copy_id);

enum ObBackupCompatibleVersion          // used for data backup
{ OB_BACKUP_COMPATIBLE_VERSION_V1 = 1,  // since 2.2.60
  OB_BACKUP_COMPATIBLE_VERSION_V2 = 2,  // since 2.2.77
  OB_BACKUP_COMPATIBLE_VERSION_V3 = 3,  // since 3.1 TODO(muwei): use v3 in 3.1
O
oceanbase-admin 已提交
49 50 51
  OB_BACKUP_COMPATIBLE_VERSION_MAX,
};

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
bool has_independ_inc_backup_set(const int64_t version);
// for log archive and data backup, exclude backup lease service inner table
enum ObBackupInnerTableVersion {
  OB_BACKUP_INNER_TABLE_V1 = 1,  // since 2.2.60
  OB_BACKUP_INNER_TABLE_V2 = 2,  // upgrade to 2.2.77 with upgrade exist tenants backup inner table
  OB_BACKUP_INNER_TABLE_V3 =
      3,  // new bootstrap cluster for 2.2.77; or upgrade to 2.2.77 with upgrade all tenants backup inner table
  OB_BACKUP_INNER_TABLE_VMAX,
};
bool is_valid_backup_inner_table_version(const ObBackupInnerTableVersion& version);

const int64_t OB_START_COPY_ID = 1;
const int64_t OB_CLUSTER_USER_DEST_START_COPY_ID = 10001;  // different from gconf.backup_backup_dest
const int64_t OB_TENANT_GCONF_DEST_START_COPY_ID = 20001;
const int64_t OB_TENANT_USER_DEST_START_COPY_ID = 30001;
const int64_t OB_MAX_COPY_ID = 50000;
const int64_t OB_START_ROUND_ID = 1;
O
oceanbase-admin 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
const int64_t OB_ALL_BACKUP_SET_ID = 0;
const int64_t OB_BACKUP_DEFAULT_PG_NUM = 10000;
const int64_t OB_MAX_BACKUP_DEST_LENGTH = common::OB_MAX_URI_LENGTH;
const int64_t OB_MAX_BACKUP_PATH_LENGTH = common::MAX_PATH_SIZE;
const int64_t OB_MAX_BACKUP_ID_LENGTH = 128;
const int64_t OB_MAX_BACKUP_KEY_LENGTH = 128;
const int64_t OB_MAX_BACKUP_HOSTNAME_LENGTH = 128;
const int64_t OB_MAX_BACKUP_STORAGE_INFO_LENGTH = 256;
const int64_t OB_MAX_KEPT_LOG_ARCHIVE_BACKUP_ROUND = 10 * 10000;  // 10w
const int64_t OB_MAX_VALIDATE_LOG_INFO_LENGTH = 256;
const int64_t OB_START_BACKUP_SET_ID = 0;
const int64_t OB_DEFAULT_BACKUP_LOG_INTERVAL = 60 * 1000 * 1000;  // 60s
const int64_t OB_MAX_LOG_ARCHIVE_THREAD_NUM = 20;
const int64_t OB_GROUP_BACKUP_CONCURRENCY = 1;
const int64_t OB_GROUP_VALIDATE_CONCURRENCY = 1;
const int64_t OB_MAX_INCREMENTAL_BACKUP_NUM = 64;
const int64_t OB_MAX_LOG_ARCHIVE_CONCURRENCY = 128;
86 87 88 89 90 91
const int64_t OB_BACKUP_PIECE_DIR_NAME_LENGTH = 128;
const int64_t OB_BACKUP_NO_SWITCH_PIECE_ID = 0;
const int64_t OB_BACKUP_INVALID_PIECE_ID = -1;
const int64_t OB_BACKUP_SWITCH_BASE_PIECE_ID = 1;
const int64_t OB_MIN_LOG_ARCHIVE_CHECKPOINT_INTERVAL = 5 * 1000LL * 1000LL;   // 5s
const int64_t OB_MIN_LOG_ARCHIVE_PIECE_SWITH_INTERVAL = 5 * 1000LL * 1000LL;  // 5s
O
oceanbase-admin 已提交
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

// add by physical backup and restore
const char* const OB_STR_INCARNATION = "incarnation";
const char* const OB_STRING_BACKUP_DATA = "data";
const char* const OB_STRING_BACKUP_CLOG = "clog";
const char* const OB_STRING_BACKUP_INDEX = "index";
const char* const OB_STRING_BACKUP_CLOG_INFO = "clog_info";
const char* const OB_STRING_BACKUP_ARCHIVE_KEY = "archive_key";
const char* const OB_STRING_BACKUP_FULL_BACKUP_SET = "backup_set";
const char* const OB_STRING_BACKUP_INC_BACKUP_SET = "backup";
const char* const OB_STRING_BACKUP_META_INDEX = "meta_index_file";
const char* const OB_STRING_BACKUP_META_FILE = "meta_file";
const char* const OB_STRING_BACKUP_SSTABLE_MACRO_INDEX = "sstable_macro_index";
const char* const OB_STRING_BACKUP_MACRO_BLOCK_INDEX = "macro_block_index";
const char* const OB_STRING_BACKUP_MACRO_BLOCK_FILE = "macro_block";
const char* const OB_STRING_CLUSTER_DATA_BACKUP_INFO = "cluster_data_backup_info";
const char* const OB_STRING_TENANT_DATA_BACKUP_INFO = "tenant_data_backup_info";
const char* const OB_STRING_BACKUP_SET_INFO = "backup_set_info";
const char* const OB_STRING_SYS_PG_LIST = "sys_pg_list";
const char* const OB_STRING_NORMAL_PG_LIST = "normal_pg_list";
const char* const OB_STRING_TENANT_INFO = "tenant_info";
const char* const OB_STRING_TENANT_NAME_INFO = "tenant_name_info";
const char* const OB_STRING_TENANT_LOCALITY_INFO = "tenant_locality_info";
const char* const OB_STRING_TENANT_DIAGNOSE_INFO = "tenant_diagnose_info";
const char* const OB_STR_TENANT_NAME_BACKUP_SCHEMA_VERSION = "tenant_name_backup_schema_version";
const char* const OB_STR_BACKUP_SCHEDULER_LEADER = "backup_scheduler_leader";
const char* const OB_STR_CLUSTER_CLOG_BACKUP_INFO = "cluster_clog_backup_info";
const char* const OB_STR_TENANT_CLOG_BACKUP_INFO = "tenant_clog_backup_info";
120 121 122 123 124 125 126 127 128 129 130 131 132
const char* const OB_STR_CLUSTER_CLOG_BACKUP_PIECE_INFO = "cluster_backup_piece_info";
const char* const OB_STR_CLUSTER_CLOG_BACKUP_BACKUP_PIECE_INFO = "cluster_backup_backup_piece_info";
const char* const OB_STR_TENANT_CLOG_BACKUP_PIECE_INFO = "backup_piece_info";
const char* const OB_STR_TENANT_CLOG_BACKUP_BACKUP_PIECE_INFO = "backup_backup_piece_info";
const char* const OB_STR_TENANT_CLOG_SINGLE_BACKUP_PIECE_INFO = "single_piece_info";
const char* const OB_STR_CLUSTER_BACKUP_SET_FILE_INFO = "cluster_backup_set_file_info";
const char* const OB_STR_TENANT_BACKUP_SET_FILE_INFO = "tenant_backup_set_file_info";
const char* const OB_STR_CLUSTER_BACKUP_BACKUP_SET_FILE_INFO = "cluster_backup_backup_set_file_info";
const char* const OB_STR_TENANT_BACKUP_BACKUP_SET_FILE_INFO = "tenant_backup_backup_set_file_info";
const char* const OB_STR_SINGLE_BACKUP_SET_INFO = "single_backup_set_info";
const char* const OB_STR_TMP_FILE_MARK = ".tmp.";
const char* const Ob_STR_BACKUP_REGION = "backup_region";
const char* const OB_STR_BACKUP_ZONE = "backup_zone";
O
oceanbase-admin 已提交
133 134 135 136 137 138

const char* const OB_STRING_MJAOR_DATA = "major_data";
const char* const OB_STRING_MINOR_DATA = "minor_data";

const char* const OB_STR_LOG_ARCHIVE_STATUS = "log_archive_status";
const char* const OB_STR_BACKUP_DEST = "backup_dest";
139 140 141
const char* const OB_STR_BACKUP_BACKUP_DEST = "backup_backup_dest";
const char* const OB_STR_BACKUP_DEST_OPT = "backup_dest_option";
const char* const OB_STR_BACKUP_BACKUP_DEST_OPT = "backup_backup_dest_option";
O
oceanbase-admin 已提交
142 143 144
const char* const OB_STR_ENABLE_LOG_ARCHIVE = "enable_log_archive";
const char* const OB_STR_TENANT_ID = "tenant_id";
const char* const OB_STR_LOG_ARCHIVE_ROUND = "log_archive_round";
145
const char* const OB_STR_ROUND_ID = "round_id";  // used in piece
O
oceanbase-admin 已提交
146 147 148
const char* const OB_STR_MIN_FIRST_TIME = "min_first_time";
const char* const OB_STR_MAX_NEXT_TIME = "max_next_time";
const char* const OB_STR_STATUS = "status";
149
const char* const OB_STR_FILE_STATUS = "file_status";
O
oceanbase-admin 已提交
150 151 152 153 154 155
const char* const OB_STR_BACKUP_ENCRYPTION_MODE = "encryption_mode";
const char* const OB_STR_BACKUP_PASSWD = "passwd";
const char* const OB_STR_COPY_ID = "copy_id";
const char* const OB_STR_IS_MARK_DELETED = "is_mark_deleted";
const char* const OB_STR_IS_MOUNT_FILE_CREATED = "is_mount_file_created";
const char* const OB_STR_COMPATIBLE = "compatible";
156 157 158 159 160 161 162 163 164 165 166 167 168
const char* const OB_STR_CREATE_DATE = "create_date";
const char* const OB_STR_START_TS = "start_ts";
const char* const OB_STR_CHECKPOINT_TS = "checkpoint_ts";
const char* const OB_STR_MAX_TS = "max_ts";
const char* const OB_STR_BACKUP_PIECE_ID = "backup_piece_id";
const char* const OB_STR_START_PIECE_ID = "start_piece_id";
const char* const OB_STR_MAX_BACKUP_PIECE_ID = "max_backup_piece_id";
const char* const OB_STR_MAX_BACKUP_PIECE_CREATE_DATE = "max_backup_create_date";
const char* const OB_STR_FULL_BACKUP = "full";
const char* const OB_STR_INC_BACKUP = "inc";
const char* const OB_STR_AUTO_DELETE_EXPIRED_BACKUP = "auto_delete_expired_backup";
const char* const OB_STR_AUTO_UPDATE_RESERVED_BACKUP_TIMESTAMP = "_auto_update_reserved_backup_timestamp";
const char* const OB_STR_BACKUP_INNER_TABLE_VERSION = "inner_table_version";
O
oceanbase-admin 已提交
169 170 171 172 173

const char* const OB_BACKUP_ENCRYPTION_MODE_SESSION_STR = "__ob_backup_encryption_mode__";
const char* const OB_BACKUP_ENCRYPTION_PASSWD_SESSION_STR = "__ob_backup_encryption_passwd__";
const char* const OB_BACKUP_DECRYPTION_PASSWD_ARRAY_SESSION_STR = "__ob_backup_decryption_passwd_array__";

174 175 176 177 178 179 180 181 182
const char* const OB_RESTORE_SOURCE_NAME_SESSION_STR = "__ob_restore_source_name__";
const char* const OB_RESTORE_PREVIEW_TENANT_ID_SESSION_STR = "__ob_restore_preview_tenant_id__";
const char* const OB_RESTORE_PREVIEW_BACKUP_DEST_SESSION_STR = "__ob_restore_preview_backup_dest__";
const char* const OB_RESTORE_PREVIEW_TIMESTAMP_SESSION_STR = "__ob_restore_preview_timestamp__";
const char* const OB_RESTORE_PREVIEW_BACKUP_CLUSTER_NAME_SESSION_STR = "__ob_restore_preview_backup_cluster_name__";
const char* const OB_RESTORE_PREVIEW_BACKUP_CLUSTER_ID_SESSION_STR = "__ob_restore_preview_backup_cluster_id__";
const char* const MULTI_BACKUP_SET_PATH_PREFIX = "BACKUPSET";
const char* const MULTI_BACKUP_PIECE_PATH_PREFIX = "BACKUPPIECE";

O
oceanbase-admin 已提交
183 184 185 186 187
enum ObBackupFileType {
  BACKUP_META = 0,
  BACKUP_MACRO_DATA = 1,
  BACKUP_META_INDEX = 2,
  BACKUP_MACRO_DATA_INDEX = 3,
188 189
  BACKUP_SSTABLE_MACRO_INDEX = 4,  // not used
  BACKUP_LOG_ARCHIVE_BACKUP_INFO = 5,
O
oceanbase-admin 已提交
190 191 192 193 194 195 196 197 198
  BACKUP_INFO = 6,
  BACKUP_SET_INFO = 7,
  BACKUP_PG_LIST = 8,
  BACKUP_TENANT_INFO = 9,
  BACKUP_FILE_END_MARK = 10,
  BACKUP_FILE_SWITCH_MARK = 11,
  BACKUP_TENANT_LOCALITY_INFO = 12,
  BACKUP_TENANT_DIAGNOSE_INFO = 13,
  BACKUP_TENANT_NAME_INFO = 14,
199 200 201
  BACKUP_PIECE_INFO = 15,
  BACKUP_SINGLE_PIECE_INFO = 16,
  BACKUP_SET_FILE_INFO = 17,
O
oceanbase-admin 已提交
202 203 204 205 206
  // type <=255 is write header struct to disk directly
  // type > 255 is use serialization to disk
  BACKUP_MAX_DIRECT_WRITE_TYPE = 255,
  BACKUP_ARCHIVE_BLOCK_META = 0x4142,  // 16706
  BACKUP_ARCHIVE_INDEX_FILE = 0x4149,  // 16713 AI means ARCHIVE INDEX
207
  BACKUP_ARCHIVE_KEY_FILE = 0x414B,    // 16713 AK means ARCHIVE  KEY
O
oceanbase-admin 已提交
208 209 210 211 212 213 214 215 216 217 218 219
  BACKUP_TYPE_MAX
};

enum ObBackupMetaType {
  PARTITION_GROUP_META = 0,
  PARTITION_META = 1,
  SSTABLE_METAS = 2,
  TABLE_KEYS = 3,
  PARTITION_GROUP_META_INFO = 4,
  META_TYPE_MAX
};

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
typedef common::ObFixedLengthString<OB_MAX_BACKUP_DEST_LENGTH> ObBackupPathString;

typedef ObBackupPathString ObBackupSetPath;
typedef ObBackupPathString ObBackupPiecePath;

struct ObBackupBaseDataPathInfo;

struct ObBackupFileStatus final {
  enum STATUS {
    BACKUP_FILE_AVAILABLE = 0,
    BACKUP_FILE_COPYING = 1,
    BACKUP_FILE_INCOMPLETE = 2,
    BACKUP_FILE_DELETING = 3,
    BACKUP_FILE_EXPIRED = 4,
    BACKUP_FILE_BROKEN = 5,
    BACKUP_FILE_DELETED = 6,
    BACKUP_FILE_MAX
  };

  static const char* get_str(const STATUS& status);
  static STATUS get_status(const char* status_str);
  static OB_INLINE bool is_valid(const STATUS& status)
  {
    return status >= 0 && status < BACKUP_FILE_MAX;
  }
  static int check_can_change_status(
      const ObBackupFileStatus::STATUS& src_file_status, const ObBackupFileStatus::STATUS& dest_file_status);
  static bool can_show_in_preview(const ObBackupFileStatus::STATUS& status);
};
struct ObSimpleBackupSetPath {
  OB_UNIS_VERSION(1);

public:
  ObSimpleBackupSetPath();
  ~ObSimpleBackupSetPath();
  void reset();
  int set(const common::ObString& uri);
  int set(const common::ObString& path, const common::ObString& storage_info);
  int set(const share::ObBackupBaseDataPathInfo& path_info);
  bool is_valid() const;
  common::ObString get_simple_path() const;
  common::ObString get_storage_info() const;
  TO_STRING_KV(K_(backup_set_id), K_(copy_id), K_(backup_dest), K_(file_status));
  int64_t backup_set_id_;
  int64_t copy_id_;
  ObBackupSetPath backup_dest_;
  ObBackupFileStatus::STATUS file_status_;
};

struct ObSimpleBackupPiecePath {
  OB_UNIS_VERSION(1);

public:
  ObSimpleBackupPiecePath();
  ~ObSimpleBackupPiecePath();
  void reset();
  int set(const common::ObString& uri);
  int set(const common::ObString& path, const common::ObString& storage_info);
  bool is_valid() const;
  common::ObString get_simple_path() const;
  common::ObString get_storage_info() const;
  TO_STRING_KV(K_(round_id), K_(backup_piece_id), K_(copy_id), K_(backup_dest), K_(file_status));
  int64_t round_id_;
  int64_t backup_piece_id_;
  int64_t copy_id_;
  ObBackupPiecePath backup_dest_;
  ObBackupFileStatus::STATUS file_status_;
};

struct ObCompareSimpleBackupSetPath {
  bool operator()(const share::ObSimpleBackupSetPath& lhs, const share::ObSimpleBackupSetPath& rhs);
};
struct ObCompareSimpleBackupPiecePath {
  bool operator()(const share::ObSimpleBackupPiecePath& lhs, const share::ObSimpleBackupPiecePath& rhs);
};

class ObPhysicalRestoreBackupDestList {
  OB_UNIS_VERSION(1);

public:
  ObPhysicalRestoreBackupDestList();
  virtual ~ObPhysicalRestoreBackupDestList();

  int assign(const ObPhysicalRestoreBackupDestList& list);
  int set(const common::ObArray<share::ObSimpleBackupSetPath>& backup_set_list,
      const common::ObArray<share::ObSimpleBackupPiecePath>& backup_piece_list);
  void reset();

  int get_backup_set_list_format_str(common::ObIAllocator& allocator, common::ObString& str) const;
  int get_backup_piece_list_format_str(common::ObIAllocator& allocator, common::ObString& str) const;

  int backup_set_list_assign_with_hex_str(const common::ObString& str);
  int backup_piece_list_assign_with_hex_str(const common::ObString& str);

  int get_backup_set_list_hex_str(common::ObIAllocator& allocator, common::ObString& str) const;
  int get_backup_piece_list_hex_str(common::ObIAllocator& allocator, common::ObString& str) const;

  common::ObSArray<share::ObSimpleBackupSetPath>& get_backup_set_path_list()
  {
    return backup_set_path_list_;
  }
  common::ObSArray<share::ObSimpleBackupPiecePath>& get_backup_piece_path_list()
  {
    return backup_piece_path_list_;
  }
  const common::ObSArray<share::ObSimpleBackupSetPath>& get_backup_set_path_list() const
  {
    return backup_set_path_list_;
  }
  const common::ObSArray<share::ObSimpleBackupPiecePath>& get_backup_piece_path_list() const
  {
    return backup_piece_path_list_;
  }
  bool is_compat_backup_path() const
  {
    return backup_set_path_list_.empty();
  }

  TO_STRING_KV(K_(backup_set_path_list), K_(backup_piece_path_list));

private:
  int64_t get_backup_set_list_format_str_len() const;
  int64_t get_backup_piece_list_format_str_len() const;

private:
  common::ObArenaAllocator allocator_;
  common::ObSArray<share::ObSimpleBackupSetPath> backup_set_path_list_;
  common::ObSArray<share::ObSimpleBackupPiecePath> backup_piece_path_list_;
};

O
oceanbase-admin 已提交
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
struct ObBackupCommonHeader {
  static const uint8_t COMMON_HEADER_VERSION = 1;
  static const uint8_t MACRO_DATA_HEADER_VERSION = 1;
  ObBackupCommonHeader();
  void reset();
  void set_header_checksum();
  int set_checksum(const char* buf, const int64_t len);
  int check_header_checksum() const;
  int16_t calc_header_checksum() const;
  int check_valid() const;
  bool is_compresssed_data() const;
  int check_data_checksum(const char* buf, const int64_t len) const;
  int assign(const ObBackupCommonHeader& header);
  TO_STRING_KV(K_(header_version), K_(compressor_type), K_(data_type), K_(data_version), K_(header_length),
      K_(header_checksum), K_(data_length), K_(data_zlength), K_(data_checksum), K_(align_length));
  uint16_t data_type_;
  uint16_t header_version_;  // header version
  uint16_t data_version_;
  uint16_t compressor_type_;  // data compression type
  int16_t header_length_;     // = sizeof(ObBackupCommonHeader)
  int16_t header_checksum_;
  int64_t data_length_;    // length of data before compression
  int64_t data_zlength_;   // length of data after compression
  int64_t data_checksum_;  // checksum of data part
  int64_t align_length_;
};

struct ObBackupMetaHeader {
  static const uint8_t META_HEADER_VERSION = 1;
  ObBackupMetaHeader();
  void reset();
  void set_header_checksum();
  int set_checksum(const char* buf, const int64_t len);
  int check_header_checksum() const;
  int check_data_checksum(const char* buf, const int64_t len) const;
  int16_t calc_header_checksum() const;
  int check_valid() const;
  TO_STRING_KV(K_(header_version), K_(meta_type), K_(header_checksum), K_(data_length), K_(data_checksum));
  uint16_t header_version_;
  uint16_t meta_type_;  // ObBackupMetaType;
  int16_t header_checksum_;
  int16_t reserved_[3];
  int32_t data_length_;
  int64_t data_checksum_;
};

struct ObBackupMetaIndex {
  static const uint8_t META_INDEX_VERSION = 1;
  OB_UNIS_VERSION(META_INDEX_VERSION);

G
gm 已提交
400
public:
O
oceanbase-admin 已提交
401 402 403 404
  ObBackupMetaIndex();
  void reset();
  int check_valid() const;
  TO_STRING_KV(K_(meta_type), K_(table_id), K_(partition_id), K_(offset), K_(data_length), K_(task_id));
405
  bool operator==(const ObBackupMetaIndex& other) const;
O
oceanbase-admin 已提交
406 407 408 409 410 411 412 413 414 415 416 417
  uint16_t meta_type_;  // ObBackupMetaType
  uint64_t table_id_;
  int64_t partition_id_;
  int64_t offset_;
  int64_t data_length_;  // =sizeof(ObBackupMetaHeader) + ObBackupMetaHeader.data_length_
  int64_t task_id_;
};

struct ObBackupMacroIndex {
  static const int64_t MACRO_INDEX_VERSION = 1;
  OB_UNIS_VERSION(MACRO_INDEX_VERSION);

G
gm 已提交
418
public:
O
oceanbase-admin 已提交
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
  ObBackupMacroIndex();
  void reset();
  int check_valid() const;
  TO_STRING_KV(K_(table_id), K_(partition_id), K_(index_table_id), K_(sstable_macro_index), K_(data_version),
      K_(data_seq), K_(backup_set_id), K_(sub_task_id), K_(offset), K_(data_length));

  uint64_t table_id_;
  int64_t partition_id_;
  uint64_t index_table_id_;
  int64_t sstable_macro_index_;
  int64_t data_version_;
  int64_t data_seq_;
  int64_t backup_set_id_;
  int64_t sub_task_id_;
  int64_t offset_;
  int64_t data_length_;  //=ObBackupDataHeader(header_length_+macro_meta_length_ + macro_data_length_)
};

struct ObBackupSStableMacroIndex {
  static const uint8_t SSTABLE_MACRO_INDEX_VERSION = 1;
  ObBackupSStableMacroIndex();
  void reset();
  void set_header_checksum();
  int check_header_checksum() const;
  int16_t calc_header_checksum() const;
  int is_valid() const;
  TO_STRING_KV(K_(header_version), K_(data_type), K_(header_length), K_(header_checksum), K_(reserved), K_(table_id),
      K_(partition_id), K_(index_table_id), K_(offset), K_(count));

  uint8_t header_version_;
  uint8_t data_type_;  // ObBackupFileType;
  int16_t header_length_;
  int16_t header_checksum_;
  int16_t reserved_;  // for future extension
  int64_t table_id_;
  int64_t partition_id_;
  int64_t index_table_id_;
  int32_t offset_;
  int32_t count_;
};

struct ObMetaIndexKey {
  ObMetaIndexKey();
  ObMetaIndexKey(const int64_t table_id, const int64_t partition_id, const uint8_t meta_type);
  void reset();
  bool operator==(const ObMetaIndexKey& other) const;
  bool operator!=(const ObMetaIndexKey& other) const;
  uint64_t hash() const;
  bool is_valid() const;

  TO_STRING_KV(K_(table_id), K_(partition_id), K_(meta_type));
  int64_t table_id_;
  int64_t partition_id_;
  uint16_t meta_type_;  // ObBackupMetaType;
};

struct ObLogArchiveStatus final {
476 477 478 479 480 481 482 483 484 485 486
  enum STATUS {
    INVALID = 0,
    STOP = 1,
    BEGINNING = 2,
    DOING = 3,
    STOPPING = 4,
    INTERRUPTED = 5,
    MIXED = 6,
    PAUSED = 7,  // only used for backup backup log archive
    MAX
  };
O
oceanbase-admin 已提交
487 488 489 490 491 492 493 494 495 496 497 498

  static const char* get_str(const STATUS& status);
  static STATUS get_status(const char* status_str);
  static OB_INLINE bool is_valid(const STATUS& status)
  {
    return status >= 0 && status < MAX;
  }
};

struct ObGetTenantLogArchiveStatusArg final {
  OB_UNIS_VERSION(1);

G
gm 已提交
499
public:
O
oceanbase-admin 已提交
500 501
  uint64_t incarnation_;
  uint64_t round_;
502 503 504
  uint64_t backup_piece_id_;
  bool is_valid() const;
  ObGetTenantLogArchiveStatusArg() : incarnation_(0), round_(0), backup_piece_id_(0)
O
oceanbase-admin 已提交
505
  {}
506
  TO_STRING_KV(K_(incarnation), K(round_), K_(backup_piece_id));
O
oceanbase-admin 已提交
507 508
};

509 510
struct ObBackupPieceInfoKey;
struct ObServerTenantLogArchiveStatus;
O
oceanbase-admin 已提交
511
struct ObTenantLogArchiveStatus final {
512
  enum COMPATIBLE : int64_t { NONE = 0, COMPATIBLE_VERSION_1 = 1, COMPATIBLE_VERSION_2 = 2, MAX };
O
oceanbase-admin 已提交
513 514 515

  OB_UNIS_VERSION(1);

G
gm 已提交
516
public:
O
oceanbase-admin 已提交
517 518 519
  ObTenantLogArchiveStatus();
  void reset();
  bool is_valid() const;
520
  static bool is_compatible_valid(COMPATIBLE compatible);
O
oceanbase-admin 已提交
521
  int update(const ObTenantLogArchiveStatus& new_status);
522 523
  int get_piece_key(ObBackupPieceInfoKey& key) const;
  bool need_switch_piece() const;
O
oceanbase-admin 已提交
524 525

  uint64_t tenant_id_;
526
  int64_t copy_id_;
O
oceanbase-admin 已提交
527 528 529 530 531 532 533 534
  int64_t start_ts_;
  int64_t checkpoint_ts_;
  int64_t incarnation_;
  int64_t round_;
  ObLogArchiveStatus::STATUS status_;
  bool is_mark_deleted_;
  bool is_mount_file_created_;  // used to check if backup dest is mount properly
  COMPATIBLE compatible_;
535 536 537 538 539
  int64_t backup_piece_id_;
  int64_t start_piece_id_;
  TO_STRING_KV(K_(tenant_id), K_(copy_id), K_(start_ts), K_(checkpoint_ts), K_(status), K_(incarnation), K_(round),
      "status_str", ObLogArchiveStatus::get_str(status_), K_(is_mark_deleted), K_(is_mount_file_created),
      K_(compatible), K_(backup_piece_id), K_(start_piece_id));
O
oceanbase-admin 已提交
540

G
gm 已提交
541
private:
O
oceanbase-admin 已提交
542 543 544 545 546
  int update_stop_(const ObTenantLogArchiveStatus& new_status);
  int update_beginning_(const ObTenantLogArchiveStatus& new_status);
  int update_doing_(const ObTenantLogArchiveStatus& new_status);
  int update_stopping_(const ObTenantLogArchiveStatus& new_status);
  int update_interrupted_(const ObTenantLogArchiveStatus& new_status);
547
  int update_paused_(const ObTenantLogArchiveStatus& new_status);
O
oceanbase-admin 已提交
548 549 550 551 552
};

struct ObTenantLogArchiveStatusWrapper final {
  OB_UNIS_VERSION(1);

G
gm 已提交
553
public:
O
oceanbase-admin 已提交
554 555 556 557 558 559
  ObTenantLogArchiveStatusWrapper();
  int32_t result_code_;
  common::ObSArray<ObTenantLogArchiveStatus> status_array_;
  TO_STRING_KV(K_(result_code), K_(status_array));
};

560 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
struct ObServerTenantLogArchiveStatus final {
  OB_UNIS_VERSION(1);

public:
  uint64_t tenant_id_;
  int64_t incarnation_;
  ObLogArchiveStatus::STATUS status_;
  int64_t round_;
  int64_t min_backup_piece_id_;  // the min piece of all partitions on server
  int64_t start_ts_;
  int64_t checkpoint_ts_;
  int64_t max_log_ts_;  // the max log ts of all partitions on server
  TO_STRING_KV(K_(tenant_id), K_(incarnation), K_(status), K_(round), K_(min_backup_piece_id), K_(start_ts),
      K_(checkpoint_ts), K_(max_log_ts), "status_str", ObLogArchiveStatus::get_str(status_));

  ObServerTenantLogArchiveStatus();
  bool is_valid() const;
  void reset();
  int get_compat_status(ObTenantLogArchiveStatus& status) const;
  int set_status(const ObTenantLogArchiveStatus& status);
};

struct ObServerTenantLogArchiveStatusWrapper final {
  OB_UNIS_VERSION(1);

public:
  ObServerTenantLogArchiveStatusWrapper();
  int32_t result_code_;
  common::ObSArray<ObServerTenantLogArchiveStatus> status_array_;
  TO_STRING_KV(K_(result_code), K_(status_array));
};

struct ObBackupDest;

O
oceanbase-admin 已提交
594 595 596 597 598 599 600 601 602
struct ObLogArchiveBackupInfo final {
  ObLogArchiveBackupInfo();

  ObTenantLogArchiveStatus status_;
  char backup_dest_[OB_MAX_BACKUP_DEST_LENGTH];

  void reset();
  bool is_valid() const;
  bool is_same(const ObLogArchiveBackupInfo& other) const;
603 604 605
  int get_piece_key(ObBackupPieceInfoKey& key) const;
  bool is_oss() const;
  int get_backup_dest(ObBackupDest& backup_dest) const;
O
oceanbase-admin 已提交
606 607 608
  TO_STRING_KV(K_(status), K_(backup_dest));
};

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
struct ObBackupDestOpt final {
  ObBackupDestOpt();
  int init(const bool is_backup_backup);
  int init(const bool is_backup_backup, const char* opt_str, const bool global_auto_delete_obsolete_backup,
      const int64_t global_backup_recovery_window, const int64_t global_log_archive_checkount_interval,
      const bool auto_touch);
  bool is_valid() const
  {
    return is_valid_;
  }
  void reset();
  bool is_switch_piece() const
  {
    return 0 != piece_switch_interval_;
  }

  TO_STRING_KV(K_(log_archive_checkpoint_interval), K_(recovery_window), K_(piece_switch_interval), K_(backup_copies),
      K_(auto_delete_obsolete_backup), K_(auto_touch_reserved_backup));
  int64_t log_archive_checkpoint_interval_;
  int64_t recovery_window_;
  int64_t piece_switch_interval_;
  int64_t backup_copies_;
  bool auto_delete_obsolete_backup_;
  bool auto_touch_reserved_backup_;  // for option auto_update_reserved_backup_timestamp
  bool is_valid_;

private:
  int 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);
  int parse_time_interval_(const char* str, int64_t& val);
  int parse_int_(const char* str, int64_t& val);
  int parse_bool_(const char* str, bool& val);
  int 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);
  int check_valid_();
};

struct ObBackupPieceInfoKey {
  int64_t incarnation_;
  uint64_t tenant_id_;
  int64_t round_id_;
  int64_t backup_piece_id_;  // 0 means piece not swtich in one round
  int64_t copy_id_;

  ObBackupPieceInfoKey();
  // ObBackupPieceInfoKey is serialized in ObBackupPieceInfo
  bool is_valid() const;
  void reset();
  bool operator==(const ObBackupPieceInfoKey& o) const;
  bool operator<(const ObBackupPieceInfoKey& o) const;
  TO_STRING_KV(K_(incarnation), K_(tenant_id), K_(round_id), K_(backup_piece_id), K_(copy_id));
};

// the first piece of a log archive round, init state is ACTIVE
// freeze piece step:
// 1. Change cur as previous and its state as FREEZING; Create new piece with ACTIVE state
// 2. RS check if all observers are using new piece. If true, change the previous piece state as FROZEN.
struct ObBackupPieceStatus final {
  enum STATUS {
    BACKUP_PIECE_ACTIVE = 0,
    BACKUP_PIECE_FREEZING = 1,
    BACKUP_PIECE_FROZEN = 2,
    BACKUP_PIECE_INACTIVE = 3,
    BACKUP_PIECE_MAX
  };

  static const char* get_str(const STATUS& status);
  static STATUS get_status(const char* status_str);
  static OB_INLINE bool is_valid(const STATUS& status)
  {
    return status >= 0 && status < BACKUP_PIECE_MAX;
  }
};

struct ObBackupDest;

struct ObBackupPieceInfo {
  OB_UNIS_VERSION(1);

public:
  ObBackupPieceInfoKey key_;
  int64_t create_date_;
  int64_t start_ts_;       // filled by backup round start or previous piece frozen.
  int64_t checkpoint_ts_;  // filled by trigger freeze piece
  int64_t max_ts_;         // filled by frozen
  ObBackupPieceStatus::STATUS status_;
  ObBackupFileStatus::STATUS file_status_;
  ObFixedLengthString<OB_MAX_BACKUP_DEST_LENGTH> backup_dest_;
  ObTenantLogArchiveStatus::COMPATIBLE compatible_;
  int64_t start_piece_id_;

  ObBackupPieceInfo();
  bool is_valid() const;
  void reset();
  int get_backup_piece_path(char* buf, const int64_t buf_len) const;
  int init_piece_info(const ObBackupPieceInfo& sys_piece, const uint64_t tenant_id);
  const char* get_status_str() const
  {
    return ObBackupPieceStatus::get_str(status_);
  }
  const char* get_file_status_str() const
  {
    return ObBackupFileStatus::get_str(file_status_);
  }
  int get_backup_dest(ObBackupDest& backup_dest) const;
  bool operator==(const ObBackupPieceInfo& o) const;
  bool operator!=(const ObBackupPieceInfo& o) const
  {
    return !(operator==(o));
  }
  TO_STRING_KV(K_(key), K_(create_date), K_(status), K_(file_status), K_(start_ts), K_(checkpoint_ts), K_(max_ts),
      K_(backup_dest), "status_str", get_status_str(), "file_status_str", get_file_status_str(), K_(compatible),
      K_(start_piece_id));
};

struct ObNonFrozenBackupPieceInfo final {
  bool has_prev_piece_info_;
  ObBackupPieceInfo prev_piece_info_;  // is valid only when is_freezing_ is true
  ObBackupPieceInfo cur_piece_info_;

  ObNonFrozenBackupPieceInfo();
  void reset();
  bool is_valid() const;
  int get_backup_piece_id(int64_t& active_piece_id) const;
  int get_backup_piece_info(int64_t& active_piece_id, int64_t& active_piece_create_date) const;
  DECLARE_TO_STRING;
};

struct ObBackupPieceResponse {
  ObBackupPieceInfoKey key_;
  ObBackupPieceStatus status_;
  int64_t checkpoint_ts_;
  int64_t max_ts_;
  int64_t pg_count_;
};

O
oceanbase-admin 已提交
745 746
struct ObBackupDest final {
  ObBackupDest();
747
  int set(const common::ObString& backup_dest);
O
oceanbase-admin 已提交
748 749 750 751 752
  int set(const char* backup_dest);
  int set(const char* root_path, const char* storage_info);
  const char* get_type_str() const;
  void reset();
  bool is_valid() const;
753 754 755 756
  bool is_nfs_storage() const;
  bool is_oss_storage() const;
  bool is_cos_storage() const;
  bool is_root_path_equal(const ObBackupDest& backup_dest) const;
O
oceanbase-admin 已提交
757 758
  int get_backup_dest_str(char* buf, const int64_t buf_size) const;
  bool operator==(const ObBackupDest& backup_dest) const;
759
  bool operator!=(const ObBackupDest& backup_dest) const;
O
oceanbase-admin 已提交
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 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
  uint64_t hash() const;
  // TODO(): delete storage_info from to_string fun later
  TO_STRING_KV(K_(device_type), K_(root_path), K_(storage_info), "type", get_type_str());

  common::ObStorageType device_type_;
  char root_path_[OB_MAX_BACKUP_PATH_LENGTH];
  char storage_info_[OB_MAX_BACKUP_STORAGE_INFO_LENGTH];
};

struct ObBackupInfoStatus final {
  enum BackupStatus {
    STOP = 0,
    PREPARE = 1,
    SCHEDULE = 2,
    DOING = 3,
    CANCEL = 4,
    CLEANUP = 5,
    MAX,
  };
  ObBackupInfoStatus() : status_(MAX)
  {}
  virtual ~ObBackupInfoStatus() = default;
  void reset()
  {
    status_ = MAX;
  }
  bool is_valid() const
  {
    return status_ >= 0 && status_ < MAX;
  }
  static const char* get_status_str(const BackupStatus& status);
  const char* get_info_backup_status_str() const;
  int set_info_backup_status(const char* buf);
  bool is_stop_status() const
  {
    return STOP == status_;
  }
  bool is_prepare_status() const
  {
    return PREPARE == status_;
  }
  bool is_scheduler_status() const
  {
    return SCHEDULE == status_;
  }
  bool is_doing_status() const
  {
    return DOING == status_;
  }
  bool is_cleanup_status() const
  {
    return CLEANUP == status_;
  }
  bool is_cancel_status() const
  {
    return CANCEL == status_;
  }
  void set_backup_status_scheduler()
  {
    status_ = SCHEDULE;
  }
  void set_backup_status_doing()
  {
    status_ = DOING;
  }
  void set_backup_status_cleanup()
  {
    status_ = CLEANUP;
  }
  void set_backup_status_stop()
  {
    status_ = STOP;
  }
  void set_backup_status_cancel()
  {
    status_ = CANCEL;
  }
  TO_STRING_KV(K_(status), "status_str", get_status_str(status_));
  BackupStatus status_;
};

struct ObBackupType final {
  enum BackupType {
    EMPTY = 0,
    FULL_BACKUP = 1,
    INCREMENTAL_BACKUP = 2,
    MAX,
  };

  ObBackupType() : type_(EMPTY)
  {}
  virtual ~ObBackupType() = default;
  void reset()
  {
    type_ = EMPTY;
  }
  bool is_valid() const
  {
    return type_ >= FULL_BACKUP && type_ < MAX;
  }
  const char* get_backup_type_str() const;
  int set_backup_type(const char* buf);
  static OB_INLINE bool is_full_backup(const BackupType& type)
  {
    return FULL_BACKUP == type;
  }
  bool is_full_backup() const
  {
    return ObBackupType::is_full_backup(type_);
  }

  TO_STRING_KV(K_(type));
  BackupType type_;
};

// TODO() backup use lib backupdevicetype, fix it later
struct ObBackupDeviceType final {
  enum BackupDeviceType {
    NFS = 0,
    OSS = 1,
    OFS = 2,
    COS = 3,
    MAX,
  };
  ObBackupDeviceType() : type_(MAX)
  {}
  virtual ~ObBackupDeviceType() = default;
  void reset()
  {
    type_ = MAX;
  }
  const char* get_backup_device_str() const;
  int set_backup_device_type(const char* buf);
  TO_STRING_KV(K_(type));

  BackupDeviceType type_;
};

struct ObBaseBackupInfoStruct {
G
gm 已提交
899
public:
O
oceanbase-admin 已提交
900 901 902 903 904 905 906 907 908 909
  typedef common::ObFixedLengthString<common::OB_MAX_URI_LENGTH> BackupDest;
  ObBaseBackupInfoStruct();
  virtual ~ObBaseBackupInfoStruct() = default;
  void reset();
  bool is_valid() const;
  int assign(const ObBaseBackupInfoStruct& backup_info_struct);
  bool has_cleaned() const;
  ObBaseBackupInfoStruct& operator=(const ObBaseBackupInfoStruct& info);
  int check_backup_info_match(const ObBaseBackupInfoStruct& info) const;

910 911 912
  TO_STRING_KV(K_(tenant_id), K_(backup_set_id), K_(incarnation), K_(backup_dest), K_(backup_backup_dest),
      K_(backup_snapshot_version), K_(backup_schema_version), K_(backup_data_version), K_(detected_backup_region),
      K_(backup_type), K_(backup_status), K_(backup_task_id), K_(copy_id), K_(encryption_mode));
O
oceanbase-admin 已提交
913 914 915 916 917

  uint64_t tenant_id_;
  int64_t backup_set_id_;
  int64_t incarnation_;
  BackupDest backup_dest_;
918
  BackupDest backup_backup_dest_;
O
oceanbase-admin 已提交
919 920 921
  int64_t backup_snapshot_version_;
  int64_t backup_schema_version_;
  int64_t backup_data_version_;
922
  common::ObFixedLengthString<OB_INNER_TABLE_DEFAULT_VALUE_LENTH> detected_backup_region_;
O
oceanbase-admin 已提交
923 924 925
  ObBackupType backup_type_;
  ObBackupInfoStatus backup_status_;
  int64_t backup_task_id_;
926
  int64_t copy_id_;
O
oceanbase-admin 已提交
927 928 929 930 931 932 933
  share::ObBackupEncryptionMode::EncryptionMode encryption_mode_;
  common::ObFixedLengthString<common::OB_MAX_PASSWORD_LENGTH> passwd_;
};

// TODO() add compatible and cluster_version
// to TenantBackupTaskItem
struct ObTenantBackupTaskItem {
G
gm 已提交
934
public:
O
oceanbase-admin 已提交
935 936 937 938 939 940 941 942
  enum BackupStatus {
    GENERATE = 0,
    DOING = 1,
    FINISH = 2,
    CANCEL = 3,
    MAX,
  };

G
gm 已提交
943
public:
O
oceanbase-admin 已提交
944 945 946 947 948 949 950 951
  ObTenantBackupTaskItem();
  virtual ~ObTenantBackupTaskItem() = default;
  void reset();
  bool is_key_valid() const;
  bool is_valid() const;
  bool is_same_task(const ObTenantBackupTaskItem& other) const;
  bool is_result_succeed() const;
  const char* get_backup_task_status_str() const;
M
mw0 已提交
952 953 954
  int set_backup_task_status(const char *buf);
  uint64_t hash() const;
  bool operator==(const ObTenantBackupTaskItem &other) const;
O
oceanbase-admin 已提交
955 956 957 958 959 960

  TO_STRING_KV(K_(tenant_id), K_(backup_set_id), K_(incarnation), K_(snapshot_version), K_(prev_full_backup_set_id),
      K_(prev_inc_backup_set_id), K_(prev_backup_data_version), K_(pg_count), K_(macro_block_count),
      K_(finish_pg_count), K_(finish_macro_block_count), K_(input_bytes), K_(output_bytes), K_(start_time),
      K_(end_time), K_(compatible), K_(cluster_version), K_(backup_type), K_(status), K_(device_type), K_(result),
      K_(cluster_id), K_(backup_dest), K_(backup_data_version), K_(backup_schema_version), K_(partition_count),
961 962
      K_(finish_partition_count), K_(encryption_mode), K_(passwd), K_(is_mark_deleted), K_(start_replay_log_ts),
      K_(date), K_(copy_id));
O
oceanbase-admin 已提交
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993

  uint64_t tenant_id_;
  int64_t backup_set_id_;
  int64_t incarnation_;
  int64_t snapshot_version_;
  int64_t prev_full_backup_set_id_;
  int64_t prev_inc_backup_set_id_;
  int64_t prev_backup_data_version_;
  int64_t pg_count_;
  int64_t macro_block_count_;
  int64_t finish_pg_count_;
  int64_t finish_macro_block_count_;
  int64_t input_bytes_;
  int64_t output_bytes_;
  int64_t start_time_;
  int64_t end_time_;
  int64_t compatible_;
  uint64_t cluster_version_;
  ObBackupType backup_type_;
  BackupStatus status_;
  common::ObStorageType device_type_;
  int32_t result_;
  int64_t cluster_id_;
  ObBackupDest backup_dest_;
  int64_t backup_data_version_;
  int64_t backup_schema_version_;
  int64_t partition_count_;
  int64_t finish_partition_count_;
  share::ObBackupEncryptionMode::EncryptionMode encryption_mode_;
  common::ObFixedLengthString<common::OB_MAX_PASSWORD_LENGTH> passwd_;
  bool is_mark_deleted_;
994 995 996 997 998 999
  // default is 0, compatible is v1 start_log_ts is useless
  int64_t start_replay_log_ts_;
  // default is 0, compatible is v1 date is useless, format like 20210201
  int64_t date_;
  // default is 0, duration in inner table
  int64_t copy_id_;
O
oceanbase-admin 已提交
1000 1001 1002 1003 1004 1005
};

typedef ObTenantBackupTaskItem ObTenantBackupTaskInfo;

// pg backup task item
struct ObPGBackupTaskItem {
G
gm 已提交
1006
public:
O
oceanbase-admin 已提交
1007 1008 1009 1010 1011 1012 1013 1014
  enum BackupStatus {
    PENDING = 0,
    DOING = 1,
    FINISH = 2,
    CANCEL = 3,
    MAX,
  };

G
gm 已提交
1015
public:
O
oceanbase-admin 已提交
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 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
  ObPGBackupTaskItem();
  virtual ~ObPGBackupTaskItem() = default;
  void reset();
  bool is_key_valid() const;
  bool is_valid() const;
  bool is_same_task(const ObPGBackupTaskItem& other) const;
  static const char* get_status_str(const BackupStatus& status);
  const char* get_backup_task_status_str() const;
  int set_backup_task_status(const char* buf);
  int set_trace_id(const char* buf, const int64_t buf_size);
  int get_trace_id(char* buf, const int64_t buf_size) const;
  static int get_trace_id(const ObTaskId& trace_id, const int64_t buf_size, char* buf);

  TO_STRING_KV(K_(tenant_id), K_(table_id), K_(partition_id), K_(incarnation), K_(backup_set_id), K_(backup_type),
      K_(snapshot_version), K_(partition_count), K_(macro_block_count), K_(finish_partition_count),
      K_(finish_macro_block_count), K_(input_bytes), K_(output_bytes), K_(start_time), K_(end_time), K_(retry_count),
      K_(role), K_(replica_type), K_(server), K_(status), K_(result), K_(task_id), K_(trace_id));
  uint64_t tenant_id_;
  uint64_t table_id_;
  int64_t partition_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  ObBackupType backup_type_;
  int64_t snapshot_version_;
  int64_t partition_count_;
  int64_t macro_block_count_;
  int64_t finish_partition_count_;
  int64_t finish_macro_block_count_;
  int64_t input_bytes_;
  int64_t output_bytes_;
  int64_t start_time_;
  int64_t end_time_;
  int64_t retry_count_;
  common::ObRole role_;
  common::ObReplicaType replica_type_;
  common::ObAddr server_;
  BackupStatus status_;
  int32_t result_;
  int64_t task_id_;
  share::ObTaskId trace_id_;
};

typedef ObPGBackupTaskItem ObPGBackupTaskInfo;

struct ObBackupValidateTenant {
  ObBackupValidateTenant();
  virtual ~ObBackupValidateTenant();
  void reset();
  bool is_valid() const;

  TO_STRING_KV(K_(tenant_id), K_(is_dropped));

  uint64_t tenant_id_;
  bool is_dropped_;
};

struct ObBackupValidateTaskItem {
G
gm 已提交
1073
public:
O
oceanbase-admin 已提交
1074 1075 1076 1077 1078 1079 1080 1081
  enum ValidateStatus {
    SCHEDULE = 0,
    DOING = 1,
    FINISHED = 2,
    CANCEL = 3,
    MAX,
  };

G
gm 已提交
1082
public:
O
oceanbase-admin 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
  ObBackupValidateTaskItem();
  virtual ~ObBackupValidateTaskItem();
  void reset();
  bool is_valid() const;
  bool is_same_task(const ObBackupValidateTaskItem& other);
  static const char* get_status_str(const ValidateStatus& status);
  int set_status(const char* status_str);

  typedef common::ObFixedLengthString<common::OB_MAX_TENANT_NAME_LENGTH> TenantName;
  TO_STRING_KV(
      K_(job_id), K_(tenant_id), K_(tenant_name), K_(incarnation), K_(backup_set_id), K_(progress_percent), K_(status));

  int64_t job_id_;
  uint64_t tenant_id_;
  TenantName tenant_name_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t progress_percent_;
  ValidateStatus status_;
};

typedef ObBackupValidateTaskItem ObBackupValidateTaskInfo;

struct ObTenantValidateTaskItem {
G
gm 已提交
1107
public:
O
oceanbase-admin 已提交
1108 1109 1110 1111 1112 1113 1114 1115
  enum ValidateStatus {
    SCHEDULE = 0,
    DOING = 1,
    FINISHED = 2,
    CANCEL = 3,
    MAX,
  };

G
gm 已提交
1116
public:
O
oceanbase-admin 已提交
1117 1118 1119 1120 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 1150 1151 1152 1153
  ObTenantValidateTaskItem();
  virtual ~ObTenantValidateTaskItem();
  void reset();
  bool is_valid() const;
  bool is_same_task(const ObTenantValidateTaskItem& other);
  static const char* get_status_str(const ValidateStatus& status);
  int set_status(const char* status_str);

  TO_STRING_KV(K_(job_id), K_(tenant_id), K_(incarnation), K_(backup_set_id), K_(status), K_(start_time), K_(end_time),
      K_(total_pg_count), K_(finish_pg_count), K_(total_partition_count), K_(finish_partition_count),
      K_(total_macro_block_count), K_(finish_macro_block_count), K_(result));

  typedef common::ObFixedLengthString<common::MAX_TABLE_COMMENT_LENGTH> Comment;

  int64_t job_id_;
  int64_t task_id_;
  uint64_t tenant_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  ValidateStatus status_;
  char backup_dest_[OB_MAX_BACKUP_DEST_LENGTH];
  int64_t start_time_;
  int64_t end_time_;
  int64_t total_pg_count_;
  int64_t finish_pg_count_;
  int64_t total_partition_count_;
  int64_t finish_partition_count_;
  int64_t total_macro_block_count_;
  int64_t finish_macro_block_count_;
  int64_t log_size_;
  int32_t result_;
  Comment comment_;
};

typedef ObTenantValidateTaskItem ObTenantValidateTaskInfo;

struct ObPGValidateTaskItem {
G
gm 已提交
1154
public:
O
oceanbase-admin 已提交
1155 1156 1157 1158 1159 1160 1161
  enum ValidateStatus {
    PENDING = 0,
    DOING = 1,
    FINISHED = 2,
    MAX,
  };

G
gm 已提交
1162
public:
O
oceanbase-admin 已提交
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 1199 1200 1201
  ObPGValidateTaskItem();
  virtual ~ObPGValidateTaskItem();
  void reset();
  bool is_valid() const;
  bool is_same_task(const ObPGValidateTaskItem& other);
  static const char* get_status_str(const ValidateStatus& status);
  int set_status(const char* status_str);

  TO_STRING_KV(K_(job_id), K_(task_id), K_(tenant_id), K_(table_id), K_(partition_id), K_(partition_id),
      K_(incarnation), K_(backup_set_id), K_(archive_round), K_(total_partition_count), K_(finish_partition_count),
      K_(total_macro_block_count), K_(finish_macro_block_count), K_(server), K_(log_size), K_(result), K_(trace_id),
      K_(status), K_(comment));

  typedef common::ObFixedLengthString<common::MAX_TABLE_COMMENT_LENGTH> Comment;

  int64_t job_id_;
  int64_t task_id_;
  uint64_t tenant_id_;
  uint64_t table_id_;
  int64_t partition_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t archive_round_;
  int64_t total_partition_count_;
  int64_t finish_partition_count_;
  int64_t total_macro_block_count_;
  int64_t finish_macro_block_count_;
  common::ObAddr server_;
  char log_info_[OB_MAX_VALIDATE_LOG_INFO_LENGTH];
  int64_t log_size_;
  int32_t result_;
  share::ObTaskId trace_id_;
  ValidateStatus status_;
  Comment comment_;
};

typedef ObPGValidateTaskItem ObPGValidateTaskInfo;

struct ObPGValidateTaskRowKey {
G
gm 已提交
1202
public:
O
oceanbase-admin 已提交
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
  ObPGValidateTaskRowKey();
  virtual ~ObPGValidateTaskRowKey();
  int set(const ObPGValidateTaskInfo* pg_task);

  TO_STRING_KV(
      K_(tenant_id), K_(job_id), K_(task_id), K_(incarnation), K_(backup_set_id), K_(table_id), K_(partition_id));

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t task_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t table_id_;
  int64_t partition_id_;
};

struct ObBackupBackupsetType final {
  enum BackupBackupsetType {
    ALL_BACKUP_SET = 0,
    SINGLE_BACKUP_SET = 1,
    MAX,
  };

  ObBackupBackupsetType() : type_(MAX)
  {}
  ~ObBackupBackupsetType() = default;
  void reset()
  {
    type_ = MAX;
  }
  bool is_valid() const
  {
    return type_ >= ALL_BACKUP_SET && type_ < MAX;
  }
  const char* get_type_str() const;
  int set_type(const char* buf);

  TO_STRING_KV(K_(type));
  BackupBackupsetType type_;
};

struct ObBackupBackupsetJobItem {
G
gm 已提交
1245
public:
O
oceanbase-admin 已提交
1246 1247 1248
  enum JobStatus {
    SCHEDULE,
    BACKUP,
1249
    CLEAN,
O
oceanbase-admin 已提交
1250 1251 1252 1253 1254
    FINISH,
    CANCEL,
    MAX,
  };

G
gm 已提交
1255
public:
O
oceanbase-admin 已提交
1256 1257 1258 1259 1260 1261 1262
  ObBackupBackupsetJobItem();
  virtual ~ObBackupBackupsetJobItem();

  void reset();
  bool is_valid() const;
  int set_status(const char* buf);
  static const char* get_status_str(const JobStatus& status);
1263 1264 1265 1266
  bool is_tenant_level() const
  {
    return OB_SYS_TENANT_ID != tenant_id_;
  }
O
oceanbase-admin 已提交
1267

1268 1269
  TO_STRING_KV(K_(tenant_id), K_(job_id), K_(incarnation), K_(backup_set_id), K_(type), K_(tenant_name), K_(job_status),
      K_(backup_dest), K_(max_backup_times), K_(result));
O
oceanbase-admin 已提交
1270
  typedef common::ObFixedLengthString<common::OB_MAX_TENANT_NAME_LENGTH> TenantName;
1271
  typedef common::ObFixedLengthString<common::MAX_TABLE_COMMENT_LENGTH> Comment;
O
oceanbase-admin 已提交
1272 1273 1274 1275 1276 1277 1278 1279

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  ObBackupBackupsetType type_;
  TenantName tenant_name_;
  JobStatus job_status_;
1280 1281 1282 1283
  share::ObBackupDest backup_dest_;
  int64_t max_backup_times_;
  int64_t result_;
  Comment comment_;
O
oceanbase-admin 已提交
1284 1285 1286 1287 1288
};

typedef ObBackupBackupsetJobItem ObBackupBackupsetJobInfo;

struct ObTenantBackupBackupsetTaskItem {
G
gm 已提交
1289
public:
O
oceanbase-admin 已提交
1290 1291 1292 1293 1294 1295 1296 1297
  enum TaskStatus {
    GENERATE,
    BACKUP,
    FINISH,
    CANCEL,
    MAX,
  };

G
gm 已提交
1298
public:
O
oceanbase-admin 已提交
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
  ObTenantBackupBackupsetTaskItem();
  virtual ~ObTenantBackupBackupsetTaskItem();

  void reset();
  bool is_valid() const;
  int set_status(const char* buf);
  static const char* get_status_str(const TaskStatus& status);
  int convert_to_backup_task_info(ObTenantBackupTaskInfo& info) const;

  TO_STRING_KV(K_(job_id), K_(tenant_id), K_(backup_set_id), K_(task_status), K_(src_backup_dest), K_(dst_backup_dest),
      K_(start_ts), K_(end_ts), K_(total_pg_count), K_(finish_pg_count), K_(total_partition_count),
      K_(finish_partition_count), K_(total_macro_block_count), K_(finish_macro_block_count), K_(result),
1311
      K_(is_mark_deleted), K_(date));
O
oceanbase-admin 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t copy_id_;
  ObBackupType backup_type_;
  int64_t snapshot_version_;
  int64_t prev_full_backup_set_id_;
  int64_t prev_inc_backup_set_id_;
  int64_t prev_backup_data_version_;
  int64_t input_bytes_;
  int64_t output_bytes_;
  int64_t start_ts_;
  int64_t end_ts_;
  int64_t compatible_;
  int64_t cluster_id_;
  int64_t cluster_version_;
  TaskStatus task_status_;
  ObBackupDest src_backup_dest_;
  ObBackupDest dst_backup_dest_;
  int64_t backup_data_version_;
  int64_t backup_schema_version_;
  int64_t total_pg_count_;
  int64_t finish_pg_count_;
  int64_t total_partition_count_;
  int64_t finish_partition_count_;
  int64_t total_macro_block_count_;
  int64_t finish_macro_block_count_;
  int result_;
  share::ObBackupEncryptionMode::EncryptionMode encryption_mode_;
  common::ObFixedLengthString<common::OB_MAX_PASSWORD_LENGTH> passwd_;
  bool is_mark_deleted_;
1345 1346
  int64_t start_replay_log_ts_;
  int64_t date_;
O
oceanbase-admin 已提交
1347 1348 1349 1350 1351
};

typedef ObTenantBackupBackupsetTaskItem ObTenantBackupBackupsetTaskInfo;

struct ObPGBackupBackupsetTaskRowKey {
G
gm 已提交
1352
public:
O
oceanbase-admin 已提交
1353 1354 1355 1356 1357 1358
  ObPGBackupBackupsetTaskRowKey();
  ~ObPGBackupBackupsetTaskRowKey();

  int 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);
  void reset();
1359
  void reuse();
O
oceanbase-admin 已提交
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
  bool is_valid() const;

  TO_STRING_KV(
      K_(tenant_id), K_(job_id), K_(incarnation), K_(backup_set_id), K_(copy_id), K_(table_id), K_(partition_id));

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t copy_id_;
  int64_t table_id_;
  int64_t partition_id_;
};

struct ObPGBackupBackupsetTaskStat {
G
gm 已提交
1375
public:
O
oceanbase-admin 已提交
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
  ObPGBackupBackupsetTaskStat();
  ~ObPGBackupBackupsetTaskStat();

  int 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);
  void reset();
  bool is_valid() const;

  TO_STRING_KV(
      K_(total_partition_count), K_(total_macro_block_count), K_(finish_partition_count), K_(finish_macro_block_count));

  int64_t total_partition_count_;
  int64_t total_macro_block_count_;
  int64_t finish_partition_count_;
  int64_t finish_macro_block_count_;
};

struct ObPGBackupBackupsetTaskItem {
G
gm 已提交
1394
public:
O
oceanbase-admin 已提交
1395 1396 1397 1398 1399 1400 1401
  enum TaskStatus {
    PENDING,
    DOING,
    FINISH,
    MAX,
  };

G
gm 已提交
1402
public:
O
oceanbase-admin 已提交
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
  ObPGBackupBackupsetTaskItem();
  virtual ~ObPGBackupBackupsetTaskItem();

  void reset();
  bool is_valid() const;
  int set_status(const char* buf);
  static const char* get_status_str(const TaskStatus& status);
  int set_trace_id(const char* buf, const int64_t buf_size);
  int get_trace_id(char* buf, const int64_t buf_size) const;
  static int get_trace_id(const ObTaskId& trace_id, const int64_t buf_size, char* buf);

  TO_STRING_KV(K_(job_id), K_(tenant_id), K_(backup_set_id), K_(backup_set_id), K_(copy_id), K_(table_id),
      K_(partition_id), K_(status), K_(total_partition_count), K_(finish_partition_count), K_(total_macro_block_count),
      K_(finish_macro_block_count));

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t copy_id_;
  int64_t table_id_;
  int64_t partition_id_;
  TaskStatus status_;
  share::ObTaskId trace_id_;
  common::ObAddr server_;
  int64_t total_partition_count_;
  int64_t finish_partition_count_;
  int64_t total_macro_block_count_;
  int64_t finish_macro_block_count_;
  int result_;
};

typedef ObPGBackupBackupsetTaskItem ObPGBackupBackupsetTaskInfo;

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
struct ObBackupBackupPieceJobInfo {
public:
  enum JobType {
    ONLY_FROZEN = 0,
    WITH_ACTIVE_PIECE = 1,
    JOB_TYPE_MAX = 2,
  };
  enum JobStatus {
    SCHEDULE = 0,
    DOING = 1,
    CANCEL = 2,
    FINISH = 3,
    MAX,
  };

public:
  ObBackupBackupPieceJobInfo();
  void reset();
  bool is_valid() const;
  int set_status(const char* buf);
  const char* get_status_str() const;
  bool is_tenant_level() const
  {
    return OB_SYS_TENANT_ID != tenant_id_;
  }
  bool with_active_piece() const;

  TO_STRING_KV(K_(tenant_id), K_(job_id), K_(incarnation), K_(piece_id), K_(status), K_(backup_dest), K_(result));
  typedef common::ObFixedLengthString<common::MAX_TABLE_COMMENT_LENGTH> Comment;

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t incarnation_;
  int64_t piece_id_;
  JobStatus status_;
  share::ObBackupDest backup_dest_;
  int64_t max_backup_times_;  // -1 表示没有限制
  int result_;
  Comment comment_;
  int64_t type_;
};

struct ObBackupBackupPieceTaskInfo {
  enum TaskStatus {
    DOING = 0,
    FINISH = 1,
    MAX,
  };

public:
  ObBackupBackupPieceTaskInfo();

  void reset();
  bool is_valid() const;
  int set_status(const char* buf);
  const char* get_status_str() const;
  int get_backup_piece_key(share::ObBackupPieceInfoKey& key) const;

  TO_STRING_KV(K_(tenant_id), K_(job_id), K_(incarnation), K_(round_id), K_(piece_id), K_(copy_id), K_(task_status),
      K_(backup_dest), K_(start_ts), K_(end_ts), K_(result));

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t incarnation_;
  int64_t round_id_;
  int64_t piece_id_;
  int64_t copy_id_;
  TaskStatus task_status_;
  share::ObBackupDest backup_dest_;
  int64_t start_ts_;
  int64_t end_ts_;
  int result_;
};

O
oceanbase-admin 已提交
1511 1512 1513
class ObBackupPath;
class ObIBackupLeaseService;
class ObBackupUtils {
G
gm 已提交
1514
public:
O
oceanbase-admin 已提交
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
  ObBackupUtils()
  {}
  virtual ~ObBackupUtils()
  {}
  static int get_backup_info_default_timeout_ctx(common::ObTimeoutCtx& ctx);
  static bool is_need_retry_error(const int err);
  static bool is_extern_device_error(const int err);
  static int retry_get_tenant_schema_guard(const uint64_t tenant_id,
      schema::ObMultiVersionSchemaService& schema_service, const int64_t tenant_schema_version,
      schema::ObSchemaGetterGuard& schema_guard);
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
  // format input string split with ',' or ';'
  template <class T>
  static int parse_backup_format_input(
      const ObString& format_input, const int64_t max_length, common::ObIArray<T>& array);
  static int get_snapshot_to_time_date(const int64_t snapshot_version, int64_t& date);
  static int check_user_tenant_gts(
      schema::ObMultiVersionSchemaService& schema_service, const ObIArray<uint64_t>& tenant_ids, bool& is_gts);
  static int check_gts(schema::ObMultiVersionSchemaService& schema_service, const uint64_t tenant_id, bool& is_gts);
  static bool can_backup_pieces_be_deleted(const ObBackupPieceStatus::STATUS& status);
  static int check_passwd(const char* passwd_array, const char* passwd);
  static int check_is_tmp_file(const common::ObString& file_name, bool& is_tmp_file);
O
oceanbase-admin 已提交
1536

G
gm 已提交
1537
private:
O
oceanbase-admin 已提交
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
  static const int64_t RETRY_INTERVAL = 10 * 1000 * 1000;
  static const int64_t MAX_RETRY_TIMES = 3;
};

struct ObClusterBackupDest final {
  ObClusterBackupDest();
  void reset();
  int set(const char* backup_dest, const int64_t incarnation);  // use GCONF cluster_name, cluster_id
  int set(const char* backup_dest, const char* cluster_name, const int64_t cluster_id, const int64_t incarnation);
  int set(const ObBackupDest& backup_dest, const int64_t incarnation);
  const char* get_storage_info() const
  {
    return dest_.storage_info_;
  }
  bool is_valid() const;
  bool is_same(const ObClusterBackupDest& other) const;
  uint64_t hash() const;
  bool operator==(const ObClusterBackupDest& other) const;

  TO_STRING_KV(K_(dest), K_(cluster_name), K_(cluster_id), K_(incarnation));

  ObBackupDest dest_;
  char cluster_name_[common::OB_MAX_CLUSTER_NAME_LENGTH];
  int64_t cluster_id_;
  int64_t incarnation_;
};

struct ObBackupBaseDataPathInfo final {
  ObBackupBaseDataPathInfo();
1567 1568
  int 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);
O
oceanbase-admin 已提交
1569 1570
  void reset();
  bool is_valid() const;
1571
  TO_STRING_KV(K_(dest), K_(tenant_id), K_(full_backup_set_id), K_(inc_backup_set_id), K_(backup_date), K_(compatible));
O
oceanbase-admin 已提交
1572 1573 1574 1575
  ObClusterBackupDest dest_;
  int64_t tenant_id_;
  int64_t full_backup_set_id_;
  int64_t inc_backup_set_id_;
1576 1577
  int64_t backup_date_;
  int64_t compatible_;
O
oceanbase-admin 已提交
1578 1579 1580 1581 1582
};

struct ObPhysicalRestoreInfo final {
  OB_UNIS_VERSION(1);

G
gm 已提交
1583
public:
O
oceanbase-admin 已提交
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
  char backup_dest_[OB_MAX_BACKUP_DEST_LENGTH];
  char cluster_name_[common::OB_MAX_CLUSTER_NAME_LENGTH];
  int64_t cluster_id_;
  int64_t incarnation_;
  int64_t tenant_id_;
  int64_t full_backup_set_id_;
  int64_t inc_backup_set_id_;
  int64_t log_archive_round_;
  int64_t restore_snapshot_version_;
  int64_t restore_start_ts_;
  int64_t compatible_;
  int64_t cluster_version_;  // restore tenant cluster version
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
  ObPhysicalRestoreBackupDestList multi_restore_path_list_;
  int64_t backup_date_;  //备份的位点,RS只允许从这个位点之后的位点恢复
  int64_t restore_schema_version_;

  common::ObSArray<share::ObSimpleBackupSetPath>& get_backup_set_path_list()
  {
    return multi_restore_path_list_.get_backup_set_path_list();
  }
  common::ObSArray<share::ObSimpleBackupPiecePath>& get_backup_piece_path_list()
  {
    return multi_restore_path_list_.get_backup_piece_path_list();
  }
  const common::ObSArray<share::ObSimpleBackupSetPath>& get_backup_set_path_list() const
  {
    return multi_restore_path_list_.get_backup_set_path_list();
  }
  const common::ObSArray<share::ObSimpleBackupPiecePath>& get_backup_piece_path_list() const
  {
    return multi_restore_path_list_.get_backup_piece_path_list();
  }
  bool is_compat_backup_path() const
  {
    return multi_restore_path_list_.is_compat_backup_path();
  }
O
oceanbase-admin 已提交
1620 1621

  ObPhysicalRestoreInfo();
1622 1623 1624 1625 1626
  ~ObPhysicalRestoreInfo()
  {
    reset();
  }
  void reset();
O
oceanbase-admin 已提交
1627
  bool is_valid() const;
1628 1629
  bool is_switch_piece_mode() const;
  void set_array_label(const char* lable);
O
oceanbase-admin 已提交
1630 1631 1632
  int assign(const ObPhysicalRestoreInfo& other);
  TO_STRING_KV(K_(backup_dest), K_(cluster_name), K_(cluster_id), K_(incarnation), K_(tenant_id),
      K_(full_backup_set_id), K_(inc_backup_set_id), K_(log_archive_round), K_(restore_snapshot_version),
1633 1634
      K_(restore_start_ts), K_(compatible), K_(cluster_version), K_(restore_schema_version), K_(backup_date),
      K_(multi_restore_path_list));
O
oceanbase-admin 已提交
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
  DISALLOW_COPY_AND_ASSIGN(ObPhysicalRestoreInfo);
};

struct ObRestoreBackupInfo final {
  lib::Worker::CompatMode compat_mode_;  // mysql or oracle mode
  char locality_[common::MAX_LOCALITY_LENGTH];
  char primary_zone_[common::MAX_ZONE_LIST_LENGTH];
  int64_t snapshot_version_;
  int64_t schema_version_;
  int64_t frozen_data_version_;
  int64_t frozen_snapshot_version_;
  int64_t frozen_schema_version_;
  ObPhysicalRestoreInfo physical_restore_info_;
  common::ObArray<common::ObPGKey> sys_pg_key_list_;

  ObRestoreBackupInfo();
  bool is_valid() const;
  TO_STRING_KV(K_(compat_mode), K_(locality), K_(primary_zone), K_(snapshot_version), K_(schema_version),
      K_(frozen_data_version), K_(frozen_snapshot_version), K_(frozen_schema_version), K_(physical_restore_info),
      K_(sys_pg_key_list));
};

struct ObPhysicalRestoreArg final {
  OB_UNIS_VERSION(1);

G
gm 已提交
1660
public:
O
oceanbase-admin 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
  ObPhysicalRestoreArg();
  ObPhysicalRestoreArg(const ObPhysicalRestoreArg& other);
  virtual ~ObPhysicalRestoreArg()
  {}
  ObPhysicalRestoreArg& operator=(const ObPhysicalRestoreArg& other);
  bool is_valid() const;
  int assign(const ObPhysicalRestoreArg& other);
  int trans_schema_id(const uint64_t schema_id, const uint64_t trans_tenant_id_, uint64_t& trans_schema_id) const;
  int get_backup_pgkey(common::ObPartitionKey& pg_key) const;
  int change_dst_pkey_to_src_pkey(const common::ObPartitionKey& dst_pkey, common::ObPartitionKey& src_pkey) const;
  int change_src_pkey_to_dst_pkey(const common::ObPartitionKey& src_pkey, common::ObPartitionKey& dst_pkey) const;
  int trans_to_backup_schema_id(const uint64_t schema_id, uint64_t& backup_schema_id) const;
  int trans_from_backup_schema_id(const uint64_t backup_schema_id, uint64_t& schema_id) const;
  int get_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const;
1675
  int get_largest_backup_set_path(share::ObSimpleBackupSetPath& simple_path) const;
O
oceanbase-admin 已提交
1676 1677 1678 1679
  uint64_t get_tenant_id() const
  {
    return pg_key_.get_tenant_id();
  }
1680
  int get_restore_set_list(common::ObIArray<share::ObSimpleBackupSetPath>& path_list) const;
O
oceanbase-admin 已提交
1681 1682
  TO_STRING_KV(K_(restore_info), K_(pg_key), K_(restore_data_version));

G
gm 已提交
1683
public:
O
oceanbase-admin 已提交
1684 1685 1686 1687 1688 1689 1690 1691
  ObPhysicalRestoreInfo restore_info_;
  common::ObPartitionKey pg_key_;
  int64_t restore_data_version_;
};

struct ObPhysicalValidateArg final {
  OB_UNIS_VERSION(1);

G
gm 已提交
1692
public:
O
oceanbase-admin 已提交
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
  ObPhysicalValidateArg();
  virtual ~ObPhysicalValidateArg()
  {}
  ObPhysicalValidateArg& operator=(const ObPhysicalValidateArg& other);
  int assign(const ObPhysicalValidateArg& other);
  bool is_valid() const;
  int get_validate_pgkey(common::ObPartitionKey& pg_key) const;
  uint64_t get_tenant_id() const
  {
    return pg_key_.get_tenant_id();
  }
  int get_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const;
  TO_STRING_KV(K_(backup_dest), K_(cluster_name), K_(uri_header), K_(storage_info), K_(job_id), K_(task_id),
      K_(trace_id), K_(server), K_(cluster_id), K_(pg_key), K_(table_id), K_(partition_id), K_(tenant_id),
      K_(incarnation), K_(archive_round), K_(backup_set_id), K_(total_partition_count), K_(total_macro_block_count),
      K_(clog_end_timestamp), K_(start_log_id), K_(end_log_id), K_(log_size), K_(is_dropped_tenant),
1709 1710
      K_(need_validate_clog), K_(full_backup_set_id), K_(inc_backup_set_id), K_(cluster_version), K_(backup_date),
      K_(compatible));
O
oceanbase-admin 已提交
1711

G
gm 已提交
1712
public:
O
oceanbase-admin 已提交
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
  char backup_dest_[OB_MAX_BACKUP_DEST_LENGTH];
  char cluster_name_[common::OB_MAX_CLUSTER_NAME_LENGTH];
  char uri_header_[common::OB_MAX_URI_HEADER_LENGTH];
  char storage_info_[OB_MAX_BACKUP_STORAGE_INFO_LENGTH];
  int64_t job_id_;
  int64_t task_id_;
  share::ObTaskId trace_id_;
  common::ObAddr server_;
  int64_t cluster_id_;
  common::ObPartitionKey pg_key_;
  int64_t table_id_;
  int64_t partition_id_;
  uint64_t tenant_id_;
  int64_t incarnation_;
  int64_t archive_round_;
  int64_t backup_set_id_;
  int64_t total_partition_count_;
  int64_t total_macro_block_count_;
  int64_t clog_end_timestamp_;
  int64_t start_log_id_;
  int64_t end_log_id_;
  int64_t log_size_;
  bool is_dropped_tenant_;
  bool need_validate_clog_;
  int64_t full_backup_set_id_;
  int64_t inc_backup_set_id_;
  int64_t cluster_version_;
1740 1741
  int64_t backup_date_;
  int64_t compatible_;
O
oceanbase-admin 已提交
1742 1743 1744 1745 1746
};

struct ObPhysicalBackupArg final {
  OB_UNIS_VERSION(1);

G
gm 已提交
1747
public:
O
oceanbase-admin 已提交
1748 1749 1750 1751 1752 1753 1754 1755
  ObPhysicalBackupArg();
  void reset();
  bool is_valid() const;
  bool is_incremental_backup() const;
  int get_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const;
  int get_prev_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const;
  TO_STRING_KV(K_(uri_header), K_(storage_info), K_(incarnation), K_(tenant_id), K_(backup_set_id),
      K_(backup_data_version), K_(backup_schema_version), K_(prev_full_backup_set_id), K_(prev_inc_backup_set_id),
1756
      K_(prev_data_version), K_(task_id), K_(backup_type), K_(backup_date), K_(prev_backup_date), K_(compatible));
O
oceanbase-admin 已提交
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
  char uri_header_[common::OB_MAX_URI_HEADER_LENGTH];
  char storage_info_[common::OB_MAX_URI_LENGTH];
  int64_t incarnation_;
  int64_t tenant_id_;
  int64_t backup_set_id_;
  int64_t backup_data_version_;
  int64_t backup_schema_version_;
  int64_t prev_full_backup_set_id_;
  int64_t prev_inc_backup_set_id_;
  int64_t prev_data_version_;
  int64_t task_id_;
  ObBackupType::BackupType backup_type_;
  int64_t backup_snapshot_version_;
1770 1771 1772
  int64_t backup_date_;
  int64_t prev_backup_date_;
  int64_t compatible_;
O
oceanbase-admin 已提交
1773 1774 1775 1776 1777
};

struct ObBackupBackupsetArg final {
  OB_UNIS_VERSION(1);

G
gm 已提交
1778
public:
O
oceanbase-admin 已提交
1779 1780 1781 1782 1783 1784 1785 1786 1787
  ObBackupBackupsetArg();
  void reset();
  bool is_valid() const;
  int get_src_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const;
  int get_dst_backup_base_data_info(share::ObBackupBaseDataPathInfo& path_info) const;

  TO_STRING_KV(K_(src_uri_header), K_(src_storage_info), K_(dst_uri_header), K_(dst_storage_info), K_(cluster_name),
      K_(server), K_(copy_id), K_(job_id), K_(tenant_id), K_(cluster_id), K_(incarnation), K_(pg_key),
      K_(backup_set_id), K_(prev_full_backup_set_id), K_(prev_inc_backup_set_id), K_(delete_input), K_(backup_type),
1788
      K_(cluster_version), K_(backup_date), K_(compatible));
O
oceanbase-admin 已提交
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810

  char src_uri_header_[common::OB_MAX_URI_HEADER_LENGTH];
  char src_storage_info_[common::OB_MAX_URI_LENGTH];
  char dst_uri_header_[common::OB_MAX_URI_HEADER_LENGTH];
  char dst_storage_info_[common::OB_MAX_URI_LENGTH];
  char cluster_name_[common::OB_MAX_CLUSTER_NAME_LENGTH];
  int64_t cluster_id_;
  int64_t job_id_;
  uint64_t tenant_id_;
  int64_t incarnation_;
  int64_t backup_set_id_;
  int64_t copy_id_;
  int64_t backup_data_version_;
  int64_t backup_schema_version_;
  int64_t prev_full_backup_set_id_;
  int64_t prev_inc_backup_set_id_;
  int64_t prev_data_version_;
  common::ObPartitionKey pg_key_;
  common::ObAddr server_;
  ObBackupType::BackupType backup_type_;
  bool delete_input_;
  int64_t cluster_version_;
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
  bool tenant_dropped_;
  int64_t backup_date_;
  int64_t compatible_;
};

struct ObBackupArchiveLogArg final {
  OB_UNIS_VERSION(1);

public:
  ObBackupArchiveLogArg();
  void reset();
  bool is_valid() const;
  TO_STRING_KV(K_(pg_key), K_(log_archive_round), K_(piece_id), K_(create_date), K_(job_id), K_(src_backup_dest),
      K_(dst_backup_dest));
  common::ObPGKey pg_key_;
  uint64_t tenant_id_;
  int64_t log_archive_round_;
  int64_t piece_id_;
  int64_t create_date_;
  int64_t job_id_;
  int64_t rs_checkpoint_ts_;
  char src_backup_dest_[share::OB_MAX_BACKUP_PATH_LENGTH];
  char src_storage_info_[share::OB_MAX_BACKUP_STORAGE_INFO_LENGTH];
  char dst_backup_dest_[share::OB_MAX_BACKUP_PATH_LENGTH];
  char dst_storage_info_[share::OB_MAX_BACKUP_STORAGE_INFO_LENGTH];
O
oceanbase-admin 已提交
1836 1837 1838 1839 1840
};

struct ObExternBackupInfo {
  OB_UNIS_VERSION(1);

G
gm 已提交
1841
public:
O
oceanbase-admin 已提交
1842 1843 1844 1845 1846 1847
  enum ExternBackupInfoStatus {
    SUCCESS = 0,
    DOING = 1,
    FAILED = 2,
  };

G
gm 已提交
1848
public:
O
oceanbase-admin 已提交
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
  ObExternBackupInfo();
  virtual ~ObExternBackupInfo()
  {}
  void reset();
  bool is_valid() const;
  bool is_equal(const ObExternBackupInfo& extern_backup_info) const;
  bool is_equal_without_status(const ObExternBackupInfo& extern_backup_info) const;

  TO_STRING_KV(K_(full_backup_set_id), K_(inc_backup_set_id), K_(backup_data_version), K_(backup_snapshot_version),
      K_(backup_schema_version), K_(frozen_snapshot_version), K_(frozen_schema_version), K_(prev_full_backup_set_id),
      K_(prev_inc_backup_set_id), K_(prev_backup_data_version), K_(compatible), K_(cluster_version), K_(backup_type),
1860
      K_(status), K_(encryption_mode), K_(passwd), K_(is_mark_deleted), K_(date));
O
oceanbase-admin 已提交
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
  int64_t full_backup_set_id_;
  int64_t inc_backup_set_id_;
  int64_t backup_data_version_;
  int64_t backup_snapshot_version_;
  int64_t backup_schema_version_;
  int64_t frozen_snapshot_version_;
  int64_t frozen_schema_version_;
  int64_t prev_full_backup_set_id_;
  int64_t prev_inc_backup_set_id_;
  int64_t prev_backup_data_version_;
  int64_t compatible_;
  int64_t cluster_version_;
  ObBackupType::BackupType backup_type_;
  ExternBackupInfoStatus status_;
  share::ObBackupEncryptionMode::EncryptionMode encryption_mode_;
  common::ObFixedLengthString<common::OB_MAX_PASSWORD_LENGTH> passwd_;
  bool is_mark_deleted_;
1878
  int64_t date_;
O
oceanbase-admin 已提交
1879 1880 1881 1882 1883
};

struct ObExternBackupSetInfo {
  OB_UNIS_VERSION(1);

G
gm 已提交
1884
public:
O
oceanbase-admin 已提交
1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
  ObExternBackupSetInfo();
  virtual ~ObExternBackupSetInfo() = default;
  void reset();
  bool is_valid() const;
  TO_STRING_KV(K_(backup_set_id), K_(backup_snapshot_version), K_(compatible), K_(pg_count), K_(macro_block_count),
      K_(input_bytes), K_(output_bytes), K_(cluster_version), K_(compress_type));

  int64_t backup_set_id_;
  int64_t backup_snapshot_version_;
  int64_t compatible_;
  int64_t pg_count_;
  int64_t macro_block_count_;
  int64_t input_bytes_;
  int64_t output_bytes_;
  uint64_t cluster_version_;
  common::ObCompressorType compress_type_;
  // tag_info
};

// TODO () condsider change tenant name
struct ObExternTenantInfo {
  OB_UNIS_VERSION(1);

G
gm 已提交
1908
public:
O
oceanbase-admin 已提交
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
  ObExternTenantInfo();
  virtual ~ObExternTenantInfo() = default;
  void reset();
  bool is_valid() const;
  typedef common::ObFixedLengthString<common::OB_MAX_TENANT_NAME_LENGTH> TenantName;
  TO_STRING_KV(K_(tenant_id), K_(create_timestamp), K_(delete_timestamp), K_(compat_mode), K_(tenant_name),
      K_(backup_snapshot_version));

  uint64_t tenant_id_;
  int64_t create_timestamp_;
  int64_t delete_timestamp_;
  lib::Worker::CompatMode compat_mode_;  // mysql or oracle mode
  TenantName tenant_name_;
  int64_t backup_snapshot_version_;
};

struct ObExternTenantLocalityInfo {
  OB_UNIS_VERSION(1);

G
gm 已提交
1928
public:
O
oceanbase-admin 已提交
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
  ObExternTenantLocalityInfo();
  virtual ~ObExternTenantLocalityInfo() = default;
  void reset();
  bool is_valid() const;
  bool is_equal(const ObExternTenantLocalityInfo& extern_tenant_locality_info) const;
  typedef common::ObFixedLengthString<common::OB_MAX_TENANT_NAME_LENGTH> TenantName;
  typedef common::ObFixedLengthString<common::MAX_LOCALITY_LENGTH> Locality;
  typedef common::ObFixedLengthString<common::MAX_ZONE_LIST_LENGTH> PrimaryZone;
  TO_STRING_KV(K_(tenant_id), K_(backup_set_id), K_(backup_snapshot_version), K_(compat_mode), K_(tenant_name),
      K_(locality), K_(primary_zone));

  uint64_t tenant_id_;
  int64_t backup_set_id_;
  int64_t backup_snapshot_version_;
  lib::Worker::CompatMode compat_mode_;
  TenantName tenant_name_;
  Locality locality_;
  PrimaryZone primary_zone_;
};

struct ObExternBackupDiagnoseInfo {
G
gm 已提交
1950
public:
O
oceanbase-admin 已提交
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
  ObExternBackupDiagnoseInfo();
  virtual ~ObExternBackupDiagnoseInfo() = default;
  void reset();
  uint64_t tenant_id_;
  ObExternTenantLocalityInfo tenant_locality_info_;
  ObExternBackupSetInfo backup_set_info_;
  ObExternBackupInfo extern_backup_info_;
  TO_STRING_KV(K_(tenant_id), K_(tenant_locality_info), K_(backup_set_info), K_(extern_backup_info));
};

struct ObBackupCleanInfoStatus final {
  enum STATUS {
    STOP = 0,
    PREPARE = 1,
    DOING = 2,
    CANCEL = 3,
    MAX,
  };

  static const char* get_str(const STATUS& status);
  static STATUS get_status(const char* status_str);
  static OB_INLINE bool is_valid(const STATUS& status)
  {
    return status >= 0 && status < MAX;
  }
};

struct ObBackupCleanType final {
  enum TYPE {
    EMPTY_TYPE = 0,
    DELETE_OBSOLETE_BACKUP = 1,
    DELETE_BACKUP_SET = 2,
1983 1984 1985 1986
    DELETE_BACKUP_PIECE = 3,
    DELETE_BACKUP_ALL = 4,
    DELETE_OBSOLETE_BACKUP_BACKUP = 5,
    DELETE_BACKUP_ROUND = 6,
O
oceanbase-admin 已提交
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
    MAX,
  };

  static const char* get_str(const TYPE& type);
  static TYPE get_type(const char* type_str);
  static OB_INLINE bool is_valid(const TYPE& type)
  {
    return type >= 0 && type < MAX;
  }
};

struct ObBackupCleanInfo {
G
gm 已提交
1999
public:
O
oceanbase-admin 已提交
2000 2001 2002 2003 2004
  ObBackupCleanInfo();
  virtual ~ObBackupCleanInfo() = default;
  void reset();
  bool is_valid() const;
  bool is_same_info(const ObBackupCleanInfo& clean_info);
2005 2006 2007 2008
  bool is_clean_copy() const
  {
    return copy_id_ > 0;
  }
O
oceanbase-admin 已提交
2009 2010 2011 2012
  bool is_empty_clean_type() const
  {
    return ObBackupCleanType::EMPTY_TYPE == type_;
  }
2013
  bool is_delete_obsolete_backup() const
O
oceanbase-admin 已提交
2014 2015 2016
  {
    return ObBackupCleanType::DELETE_OBSOLETE_BACKUP == type_;
  }
2017 2018 2019 2020
  bool is_delete_obsolete_backup_backup() const
  {
    return ObBackupCleanType::DELETE_OBSOLETE_BACKUP_BACKUP == type_;
  }
O
oceanbase-admin 已提交
2021 2022 2023 2024
  bool is_backup_set_clean() const
  {
    return ObBackupCleanType::DELETE_BACKUP_SET == type_;
  }
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041
  bool is_delete_obsolete() const
  {
    return is_delete_obsolete_backup() || is_delete_obsolete_backup_backup();
  }
  bool is_delete_backup_set() const
  {
    return ObBackupCleanType::DELETE_BACKUP_SET == type_;
  }
  bool is_delete_backup_piece() const
  {
    return ObBackupCleanType::DELETE_BACKUP_PIECE == type_;
  }
  bool is_delete_backup_round() const
  {
    return ObBackupCleanType::DELETE_BACKUP_ROUND == type_;
  }

O
oceanbase-admin 已提交
2042 2043 2044
  int get_clean_parameter(int64_t& parameter) const;
  int set_clean_parameter(const int64_t parameter);
  int check_backup_clean_info_match(const ObBackupCleanInfo& clean_info) const;
2045
  int set_copy_id(const int64_t copy_id);
O
oceanbase-admin 已提交
2046 2047 2048

  typedef common::ObFixedLengthString<common::OB_MAX_ERROR_MSG_LEN> ErrorMsg;
  typedef common::ObFixedLengthString<common::MAX_TABLE_COMMENT_LENGTH> Comment;
2049 2050 2051
  TO_STRING_KV(K_(tenant_id), K_(job_id), K_(start_time), K_(end_time), K_(incarnation), K_(copy_id), K_(type),
      K_(status), K_(expired_time), K_(backup_set_id), K_(error_msg), K_(comment), K_(clog_gc_snapshot), K_(result),
      K_(backup_piece_id), K_(backup_round_id));
O
oceanbase-admin 已提交
2052 2053 2054 2055 2056 2057

  uint64_t tenant_id_;
  int64_t job_id_;
  int64_t start_time_;
  int64_t end_time_;
  int64_t incarnation_;
2058
  int64_t copy_id_;
O
oceanbase-admin 已提交
2059 2060 2061 2062 2063 2064 2065 2066
  ObBackupCleanType::TYPE type_;
  ObBackupCleanInfoStatus::STATUS status_;
  int64_t expired_time_;
  int64_t backup_set_id_;
  ErrorMsg error_msg_;
  Comment comment_;
  int64_t clog_gc_snapshot_;
  int32_t result_;
2067 2068
  int64_t backup_piece_id_;
  int64_t backup_round_id_;
O
oceanbase-admin 已提交
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
};

struct ObBackupDataType final {
  enum BackupDataType {
    BACKUP_MAJOR = 0,
    BACKUP_MINOR = 1,
    MAX,
  };

  ObBackupDataType() : type_(MAX)
  {}
  virtual ~ObBackupDataType() = default;
  void reset()
  {
    type_ = MAX;
  }
  bool is_valid() const
  {
    return type_ >= BACKUP_MAJOR && type_ < MAX;
  }
  static OB_INLINE bool is_major_backup(const BackupDataType& type)
  {
    return BACKUP_MAJOR == type;
  }
  static OB_INLINE bool is_minor_backup(const BackupDataType& type)
  {
    return BACKUP_MINOR == type;
  }
  bool is_major_backup() const
  {
    return ObBackupDataType::is_major_backup(type_);
  }
  bool is_minor_backup() const
  {
    return ObBackupDataType::is_minor_backup(type_);
  }
  void set_major_data_backup()
  {
    type_ = BACKUP_MAJOR;
  }
  void set_minor_data_backup()
  {
    type_ = BACKUP_MINOR;
  }

  TO_STRING_KV(K_(type));
  BackupDataType type_;
};

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 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 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
struct SimpleBackupBackupsetTenant {
  SimpleBackupBackupsetTenant() : is_dropped_(false), tenant_id_(OB_INVALID_ID)
  {}
  ~SimpleBackupBackupsetTenant()
  {}
  void reset()
  {
    tenant_id_ = OB_INVALID_ID;
    is_dropped_ = false;
  }
  bool is_valid() const
  {
    return OB_INVALID_ID != tenant_id_;
  }
  TO_STRING_KV(K_(is_dropped), K_(tenant_id));
  bool is_dropped_;
  uint64_t tenant_id_;
};

struct ObBackupSetFileInfo {
  OB_UNIS_VERSION(1);

public:
  enum BackupSetStatus {
    DOING = 0,
    SUCCESS = 1,
    FAILED,
    MAX,
  };

public:
  ObBackupSetFileInfo();
  virtual ~ObBackupSetFileInfo() = default;
  void reset();
  bool is_key_valid() const;
  bool is_valid() const;
  bool is_same_task(const ObBackupSetFileInfo& other) const;
  bool is_equal(const ObBackupSetFileInfo& other) const;
  const char* get_backup_set_status_str() const;
  int set_backup_set_status(const char* buf);
  int extract_from_backup_task_info(const ObTenantBackupTaskInfo& task_info);
  int extract_from_backup_info(const ObBaseBackupInfoStruct& info, const ObExternBackupInfo& extern_backup_info);
  bool is_backup_finish() const
  {
    return SUCCESS == status_ || FAILED == status_;
  }
  int check_passwd(const char* passwd_array, const char* passwd);
  int 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 get_backup_dest(share::ObBackupDest& backup_dest) const;

  TO_STRING_KV(K_(tenant_id), K_(backup_set_id), K_(incarnation), K_(copy_id), K_(snapshot_version),
      K_(prev_full_backup_set_id), K_(prev_inc_backup_set_id), K_(prev_backup_data_version), K_(pg_count),
      K_(macro_block_count), K_(finish_pg_count), K_(finish_macro_block_count), K_(input_bytes), K_(output_bytes),
      K_(start_time), K_(end_time), K_(compatible), K_(cluster_version), K_(backup_type), K_(status), K_(result),
      K_(cluster_id), K_(backup_dest), K_(backup_data_version), K_(backup_schema_version), K_(partition_count),
      K_(finish_partition_count), K_(encryption_mode), K_(passwd), K_(file_status), K_(start_replay_log_ts), K_(date));

  uint64_t tenant_id_;
  int64_t backup_set_id_;
  int64_t incarnation_;
  int64_t copy_id_;
  int64_t snapshot_version_;
  int64_t prev_full_backup_set_id_;
  int64_t prev_inc_backup_set_id_;
  int64_t prev_backup_data_version_;
  int64_t pg_count_;
  int64_t macro_block_count_;
  int64_t finish_pg_count_;
  int64_t finish_macro_block_count_;
  int64_t input_bytes_;
  int64_t output_bytes_;
  int64_t start_time_;
  int64_t end_time_;
  int64_t compatible_;
  uint64_t cluster_version_;
  ObBackupType backup_type_;
  BackupSetStatus status_;
  int32_t result_;
  int64_t cluster_id_;
  common::ObFixedLengthString<OB_MAX_BACKUP_DEST_LENGTH> backup_dest_;
  int64_t backup_data_version_;
  int64_t backup_schema_version_;
  int64_t partition_count_;
  int64_t finish_partition_count_;
  share::ObBackupEncryptionMode::EncryptionMode encryption_mode_;
  common::ObFixedLengthString<OB_MAX_PASSWORD_LENGTH> passwd_;
  ObBackupFileStatus::STATUS file_status_;
  int64_t start_replay_log_ts_;
  int64_t date_;
};

struct ObBackupStatistics {
  ObBackupStatistics();
  virtual ~ObBackupStatistics() = default;
  void reset();
  bool is_valid() const;
  TO_STRING_KV(K_(pg_count), K_(partition_count), K_(finish_pg_count), K_(finish_partition_count),
      K_(macro_block_count), K_(finish_macro_block_count), K_(input_bytes), K_(output_bytes));
  int64_t pg_count_;
  int64_t finish_pg_count_;
  int64_t partition_count_;
  int64_t finish_partition_count_;
  int64_t macro_block_count_;
  int64_t finish_macro_block_count_;
  int64_t input_bytes_;
  int64_t output_bytes_;
};

struct ObBackupRegion {
  ObBackupRegion();
  virtual ~ObBackupRegion();
  void reset();
  int set(const ObString& region, const int64_t priority);

  bool is_valid() const
  {
    return !region_.is_empty() && priority_ >= 0;
  }
  TO_STRING_KV(K_(region), K_(priority));
  ObRegion region_;
  int64_t priority_;
};

struct ObBackupZone {
  ObBackupZone();
  virtual ~ObBackupZone();
  void reset();
  int set(const ObString& zone, const int64_t priority);

  bool is_valid() const
  {
    return !zone_.is_empty() && priority_ >= 0;
  }
  TO_STRING_KV(K_(zone), K_(priority));
  ObZone zone_;
  int64_t priority_;
};

struct ObBackupSetIdPair {
  ObBackupSetIdPair();
  virtual ~ObBackupSetIdPair() = default;
  void reset();
  bool is_valid() const;
  TO_STRING_KV(K_(backup_set_id), K_(copy_id));
  int64_t backup_set_id_;
  int64_t copy_id_;
};

struct ObBackupPieceIdPair {
  ObBackupPieceIdPair();
  virtual ~ObBackupPieceIdPair() = default;
  void reset();
  bool is_valid() const;
  TO_STRING_KV(K_(backup_piece_id), K_(copy_id));
  int64_t backup_piece_id_;
  int64_t copy_id_;
};

//-----------------------------ObBackupUtils---------------------------
template <class T>
int ObBackupUtils::parse_backup_format_input(const ObString& format_input, const int64_t max_length, ObIArray<T>& array)
{
  int ret = OB_SUCCESS;
  array.reset();
  int64_t pos = 0;
  int64_t length = 0;
  const char split_commma = ',';
  const char split_semicolon = ';';
  T object;
  int64_t priority = 0;

  if (max_length <= 0) {
    ret = OB_INVALID_ARGUMENT;
    OB_LOG(WARN, "parse backup format input get invalid argument", K(ret), K(max_length));
  } else if (0 == format_input.length()) {
    // do nothing
  } else {
    for (int64_t i = 0; OB_SUCC(ret) && i < format_input.length(); ++i) {

      if (format_input.ptr()[i] == split_commma || format_input.ptr()[i] == split_semicolon) {
        length = i - pos;
        if (length <= 0 || length > max_length) {
          ret = OB_ERR_UNEXPECTED;
          OB_LOG(WARN, "format input value is unexpcted", K(ret), K(format_input), K(length), K(max_length));
        } else {
          ObString tmp_string;
          object.reset();
          tmp_string.assign_ptr(format_input.ptr() + pos, length);
          if (OB_FAIL(object.set(tmp_string, priority))) {
            OB_LOG(WARN, "failed to set object", K(ret), K(tmp_string), K(priority));
          } else if (OB_FAIL(array.push_back(object))) {
            OB_LOG(WARN, "failed to push object into array", K(ret), K(object));
          } else {
            pos = i + 1;
            length = 0;
          }
        }

        if (OB_SUCC(ret) && format_input.ptr()[i] == split_semicolon) {
          ++priority;
        }
      }
    }

    if (OB_SUCC(ret)) {
      if (pos < format_input.length()) {
        length = format_input.length() - pos;
        ObString tmp_string;
        object.reset();
        tmp_string.assign_ptr(format_input.ptr() + pos, length);
        if (OB_FAIL(object.set(tmp_string, priority))) {
          OB_LOG(WARN, "failed to set object", K(ret), K(tmp_string), K(priority));
        } else if (OB_FAIL(array.push_back(object))) {
          OB_LOG(WARN, "failed to push object into array", K(ret), K(object));
        }
      }

      if (OB_SUCC(ret)) {
        OB_LOG(INFO, "succeed get objects", K(array));
      }
    }
  }
  return ret;
}

O
oceanbase-admin 已提交
2344 2345 2346 2347
}  // namespace share
}  // namespace oceanbase

#endif /* OCEANBASE_SHARE_BACKUP_OB_BACKUP_STRUCT_H_ */