ob_election_group_priority.cpp 2.3 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 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
/**
 * 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.
 */

#include "ob_election_group_priority.h"
#include "ob_election_async_log.h"
#include "lib/json/ob_yson.h"

namespace oceanbase {
using namespace oceanbase::common;

namespace election {
OB_SERIALIZE_MEMBER(ObElectionGroupPriority, is_candidate_, system_score_);

ObElectionGroupPriority::ObElectionGroupPriority(const bool is_candidate, const int64_t system_score)
{
  is_candidate_ = is_candidate;
  system_score_ = system_score;
}

void ObElectionGroupPriority::reset()
{
  is_candidate_ = false;
  system_score_ = 0;
}

ObElectionGroupPriority& ObElectionGroupPriority::operator=(const ObElectionGroupPriority& priority)
{
  if (this != &priority) {
    is_candidate_ = priority.is_candidate();
    system_score_ = priority.get_system_score();
  }

  return *this;
}

bool ObElectionGroupPriority::is_valid() const
{
  return true;
}

DEFINE_TO_STRING_AND_YSON(ObElectionGroupPriority, Y_(is_candidate), Y_(system_score));

int ObElectionGroupPriority::compare(const ObElectionGroupPriority& priority) const
{
  int ret = 0;

  if (system_score_ == priority.get_system_score()) {
    ret = 0;
  } else if (system_score_ < priority.get_system_score()) {
    ret = 1;
  } else {
    ret = -1;
  }

  return ret;
}

67
void ObElectionGroupPriority::set_system_clog_disk_hang()
O
oceanbase-admin 已提交
68
{
69
  system_score_ += SYSTEM_SCORE_CLOG_DISK_HANG * 100;
O
oceanbase-admin 已提交
70 71 72 73 74 75 76
}

void ObElectionGroupPriority::set_system_data_disk_error()
{
  system_score_ += SYSTEM_SCORE_DATA_DISK_ERROR * 100;
}

77 78 79 80 81 82
void ObElectionGroupPriority::set_system_slog_disk_warning()
{
  // slog use the same disk with sstable(data disk)
  system_score_ += SYSTEM_SCORE_DATA_DISK_ERROR * 100;
}

O
oceanbase-admin 已提交
83 84 85 86 87 88
void ObElectionGroupPriority::set_system_service_not_started()
{
  system_score_ += SYSTEM_SCORE_SERVICE_NOT_STARTED * 100;
}
}  // namespace election
}  // namespace oceanbase