YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/master/master_main.cc
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#include <iostream>
34
35
#include <glog/logging.h>
36
37
#include "yb/common/wire_protocol.h"
38
39
#include "yb/consensus/log_util.h"
40
#include "yb/consensus/consensus_queue.h"
41
42
#include "yb/gutil/sysinfo.h"
43
44
#include "yb/master/call_home.h"
45
#include "yb/master/master.h"
46
#include "yb/master/sys_catalog_initialization.h"
47
48
#include "yb/server/total_mem_watcher.h"
49
50
#include "yb/util/flags.h"
51
#include "yb/util/init.h"
52
#include "yb/util/logging.h"
53
#include "yb/util/main_util.h"
54
#include "yb/util/mem_tracker.h"
55
#include "yb/util/result.h"
56
#include "yb/util/ulimit_util.h"
57
#include "yb/util/debug/trace_event.h"
58
59
#include "yb/tserver/server_main_util.h"
60
61
DECLARE_bool(callhome_enabled);
62
DECLARE_bool(evict_failed_followers);
63
DECLARE_double(default_memory_limit_to_ram_ratio);
64
DECLARE_int32(logbuflevel);
65
DECLARE_int32(webserver_port);
66
DECLARE_string(rpc_bind_addresses);
67
DECLARE_bool(durable_wal_write);
68
DECLARE_int32(stderrthreshold);
69
70
DECLARE_string(metric_node_name);
71
DECLARE_int64(remote_bootstrap_rate_limit_bytes_per_sec);
72
// Deprecated because it's misspelled.  But if set, this flag takes precedence over
73
// remote_bootstrap_rate_limit_bytes_per_sec for compatibility.
74
DECLARE_int64(remote_boostrap_rate_limit_bytes_per_sec);
75
DECLARE_bool(use_docdb_aware_bloom_filter);
76
77
using namespace std::literals;
78
79
namespace yb {
80
namespace master {
81
82
6.93k
static int MasterMain(int argc, char** argv) {
83
  // Reset some default values before parsing gflags.
84
6.93k
  FLAGS_rpc_bind_addresses = strings::Substitute("0.0.0.0:$0", kMasterDefaultPort);
85
6.93k
  FLAGS_webserver_port = kMasterDefaultWebPort;
86
  // Hotfix for https://github.com/yugabyte/yugabyte-db/issues/8731.
87
  // Before enabling bloom filters for the master tablet we need to check whether master code use
88
  // bloom filters properly at all, including if filter key is set correctly during scans.
89
6.93k
  FLAGS_use_docdb_aware_bloom_filter = false;
90
91
6.93k
  string host_name;
92
6.93k
  if (GetHostname(&host_name).ok()) {
93
6.93k
    FLAGS_metric_node_name = strings::Substitute("$0:$1", host_name, kMasterDefaultWebPort);
94
6.93k
  } else {
95
0
    LOG(INFO) << "Failed to get master's host name, keeping default metric_node_name";
96
0
  }
97
98
6.93k
  FLAGS_default_memory_limit_to_ram_ratio = 0.10;
99
  // For masters we always want to fsync the WAL files (except in testing).
100
6.93k
  FLAGS_durable_wal_write = true;
101
102
  // A multi-node Master leader should not evict failed Master followers
103
  // because there is no-one to assign replacement servers in order to maintain
104
  // the desired replication factor. (It's not turtles all the way down!)
105
6.93k
  FLAGS_evict_failed_followers = false;
106
107
6.93k
  LOG_AND_RETURN_FROM_MAIN_NOT_OK(MasterTServerParseFlagsAndInit(
108
6.93k
      MasterOptions::kServerType, &argc, &argv));
109
110
6.93k
  auto opts_result = MasterOptions::CreateMasterOptions();
111
6.93k
  LOG_AND_RETURN_FROM_MAIN_NOT_OK(opts_result);
112
6.93k
  enterprise::Master server(*opts_result);
113
114
6.93k
  SetDefaultInitialSysCatalogSnapshotFlags();
115
116
  // ==============================================================================================
117
  // End of setting master flags
118
  // ==============================================================================================
119
120
6.93k
  LOG(INFO) << "Initializing master server...";
121
6.93k
  LOG_AND_RETURN_FROM_MAIN_NOT_OK(server.Init());
122
123
6.93k
  LOG(INFO) << "Starting Master server...";
124
6.93k
  UlimitUtil::InitUlimits();
125
6.93k
  LOG(INFO) << "ulimit cur(max)..." << UlimitUtil::GetUlimitInfo();
126
6.93k
  LOG_AND_RETURN_FROM_MAIN_NOT_OK(server.Start());
127
128
6.93k
  LOG(INFO) << "Master server successfully started.";
129
130
6.93k
  std::unique_ptr<CallHome> call_home;
131
6.93k
  call_home = std::make_unique<CallHome>(&server, ServerType::MASTER);
132
6.93k
  call_home->ScheduleCallHome();
133
134
6.93k
  auto total_mem_watcher = server::TotalMemWatcher::Create();
135
6.93k
  total_mem_watcher->MemoryMonitoringLoop(
136
6.93k
      [&server]() 
{ server.Shutdown(); }0
,
137
6.93k
      [&server]() 
{ return server.IsShutdown(); }0
138
6.93k
  );
139
6.93k
  return EXIT_FAILURE;
140
6.93k
}
141
142
} // namespace master
143
} // namespace yb
144
145
18.6k
int main(int argc, char** argv) {
146
18.6k
  return yb::master::MasterMain(argc, argv);
147
18.6k
}