/Users/deen/code/yugabyte-db/src/yb/util/init.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 "yb/util/init.h" |
34 | | |
35 | | #include <string> |
36 | | |
37 | | #include "yb/gutil/cpu.h" |
38 | | #include "yb/gutil/strings/split.h" |
39 | | #include "yb/gutil/strings/substitute.h" |
40 | | #include "yb/util/env.h" |
41 | | #include "yb/util/env_util.h" |
42 | | #include "yb/util/flag_tags.h" |
43 | | #include "yb/util/logging.h" |
44 | | #include "yb/util/path_util.h" |
45 | | #include "yb/util/status.h" |
46 | | #include "yb/util/version_info.h" |
47 | | |
48 | | #if defined(__linux__) |
49 | | #include <sys/prctl.h> |
50 | | #endif |
51 | | |
52 | | using std::string; |
53 | | |
54 | | DEFINE_string(fs_data_dirs, "", |
55 | | "Comma-separated list of data directories. This argument must be specified."); |
56 | | TAG_FLAG(fs_data_dirs, stable); |
57 | | DEFINE_bool(stop_on_parent_termination, false, |
58 | | "When specified, this process will terminate when parent process terminates." |
59 | | "Linux-only."); |
60 | | |
61 | | namespace yb { |
62 | | |
63 | | const char* kTopLevelDataDirName = "yb-data"; |
64 | | |
65 | 0 | Status BadCPUStatus(const base::CPU& cpu, const char* instruction_set) { |
66 | 0 | return STATUS(NotSupported, strings::Substitute( |
67 | 0 | "The CPU on this system ($0) does not support the $1 instruction " |
68 | 0 | "set which is required for running YB.", |
69 | 0 | cpu.cpu_brand(), instruction_set)); |
70 | 0 | } |
71 | | |
72 | 71.6k | Status CheckCPUFlags() { |
73 | 71.6k | base::CPU cpu; |
74 | | #ifndef __aarch64__ |
75 | | if (!cpu.has_sse42()) { |
76 | | return BadCPUStatus(cpu, "SSE4.2"); |
77 | | } |
78 | | |
79 | | if (!cpu.has_ssse3()) { |
80 | | return BadCPUStatus(cpu, "SSSE3"); |
81 | | } |
82 | | #endif |
83 | 71.6k | return Status::OK(); |
84 | 71.6k | } |
85 | | |
86 | 14.6k | Status SetupLogDir(const std::string& server_type) { |
87 | | // If no log_dir specified, create the yugabyte specific directory structure and set the flag. |
88 | 14.6k | if (FLAGS_log_dir.empty()) { |
89 | 2.02k | std::vector<std::string> data_paths = strings::Split( |
90 | 2.02k | FLAGS_fs_data_dirs, ",", strings::SkipEmpty()); |
91 | | // Need at least one entry as we're picking the first one to drop the logs into. |
92 | 2.02k | if (data_paths.size() < 1) { |
93 | 0 | return STATUS( |
94 | 0 | InvalidArgument, |
95 | 0 | "Cannot initialize logging. Flag fs_data_dirs (a comma-separated list of data " |
96 | 0 | "directories) must contain at least one data directory."); |
97 | 0 | } |
98 | | |
99 | 2.02k | bool created = false; |
100 | 2.02k | std::string out_dir; |
101 | 2.02k | Status s = SetupRootDir(Env::Default(), data_paths[0], server_type, &out_dir, &created); |
102 | 2.02k | if (!s.ok()) { |
103 | 0 | return STATUS( |
104 | 0 | InvalidArgument, strings::Substitute( |
105 | 0 | "Cannot create directory for logging, please check the --fs_data_dirs parameter " |
106 | 0 | "(Passed: $0). Path does not exist: $1\nDetails: $2", |
107 | 0 | FLAGS_fs_data_dirs, data_paths[0], s.ToString())); |
108 | 0 | } |
109 | | // Create the actual log dir. |
110 | 2.02k | out_dir = JoinPathSegments(out_dir, "logs"); |
111 | 2.02k | RETURN_NOT_OK_PREPEND(env_util::CreateDirIfMissing(Env::Default(), out_dir, &created), |
112 | 2.02k | "Unable to create FSManager path component " + out_dir); |
113 | | // Set the log dir. |
114 | 2.02k | FLAGS_log_dir = out_dir; |
115 | 2.02k | } |
116 | | // If we have a custom specified log_dir, use that. |
117 | 14.6k | return Status::OK(); |
118 | 14.6k | } |
119 | | |
120 | 14.6k | Status InitYB(const std::string &server_type, const char* argv0) { |
121 | | #if defined(__linux__) |
122 | | if (FLAGS_stop_on_parent_termination) { |
123 | | prctl(PR_SET_PDEATHSIG, SIGTERM); |
124 | | } |
125 | | #endif |
126 | 14.6k | RETURN_NOT_OK(CheckCPUFlags()); |
127 | 14.6k | RETURN_NOT_OK(SetupLogDir(server_type)); |
128 | 14.6k | RETURN_NOT_OK(VersionInfo::Init()); |
129 | 14.6k | google::SetApplicationFingerprint(VersionInfo::GetShortVersionString()); |
130 | 14.6k | InitGoogleLoggingSafe(argv0); |
131 | 14.6k | return Status::OK(); |
132 | 14.6k | } |
133 | | |
134 | | } // namespace yb |