/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 | 4.93k | static int MasterMain(int argc, char** argv) { |
83 | | // Reset some default values before parsing gflags. |
84 | 4.93k | FLAGS_rpc_bind_addresses = strings::Substitute("0.0.0.0:$0", kMasterDefaultPort); |
85 | 4.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 | 4.93k | FLAGS_use_docdb_aware_bloom_filter = false; |
90 | | |
91 | 4.93k | string host_name; |
92 | 4.93k | if (GetHostname(&host_name).ok()) { |
93 | 4.93k | FLAGS_metric_node_name = strings::Substitute("$0:$1", host_name, kMasterDefaultWebPort); |
94 | 0 | } else { |
95 | 0 | LOG(INFO) << "Failed to get master's host name, keeping default metric_node_name"; |
96 | 0 | } |
97 | | |
98 | 4.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 | 4.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 | 4.93k | FLAGS_evict_failed_followers = false; |
106 | | |
107 | 4.93k | LOG_AND_RETURN_FROM_MAIN_NOT_OK(MasterTServerParseFlagsAndInit( |
108 | 4.93k | MasterOptions::kServerType, &argc, &argv)); |
109 | | |
110 | 4.93k | auto opts_result = MasterOptions::CreateMasterOptions(); |
111 | 4.93k | LOG_AND_RETURN_FROM_MAIN_NOT_OK(opts_result); |
112 | 4.93k | enterprise::Master server(*opts_result); |
113 | | |
114 | 4.93k | SetDefaultInitialSysCatalogSnapshotFlags(); |
115 | | |
116 | | // ============================================================================================== |
117 | | // End of setting master flags |
118 | | // ============================================================================================== |
119 | | |
120 | 4.93k | LOG(INFO) << "Initializing master server..."; |
121 | 4.93k | LOG_AND_RETURN_FROM_MAIN_NOT_OK(server.Init()); |
122 | | |
123 | 4.93k | LOG(INFO) << "Starting Master server..."; |
124 | 4.93k | UlimitUtil::InitUlimits(); |
125 | 4.93k | LOG(INFO) << "ulimit cur(max)..." << UlimitUtil::GetUlimitInfo(); |
126 | 4.93k | LOG_AND_RETURN_FROM_MAIN_NOT_OK(server.Start()); |
127 | | |
128 | 4.93k | LOG(INFO) << "Master server successfully started."; |
129 | | |
130 | 4.93k | std::unique_ptr<CallHome> call_home; |
131 | 4.93k | call_home = std::make_unique<CallHome>(&server, ServerType::MASTER); |
132 | 4.93k | call_home->ScheduleCallHome(); |
133 | | |
134 | 4.93k | auto total_mem_watcher = server::TotalMemWatcher::Create(); |
135 | 4.93k | total_mem_watcher->MemoryMonitoringLoop( |
136 | 0 | [&server]() { server.Shutdown(); }, |
137 | 0 | [&server]() { return server.IsShutdown(); } |
138 | 4.93k | ); |
139 | 4.93k | return EXIT_FAILURE; |
140 | 4.93k | } |
141 | | |
142 | | } // namespace master |
143 | | } // namespace yb |
144 | | |
145 | 13.2k | int main(int argc, char** argv) { |
146 | 13.2k | return yb::master::MasterMain(argc, argv); |
147 | 13.2k | } |