YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/common_flags.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/common/common_flags.h"
15
16
#include <thread>
17
18
#include "yb/util/atomic.h"
19
#include "yb/util/flag_tags.h"
20
#include "yb/util/tsan_util.h"
21
#include "yb/gutil/sysinfo.h"
22
23
// Note that this is used by the client or master only, not by tserver.
24
DEFINE_int32(yb_num_shards_per_tserver, kAutoDetectNumShardsPerTServer,
25
    "The default number of shards per table per tablet server when a table is created. If the "
26
    "value is -1, the system sets the number of shards per tserver to 1 if "
27
    "enable_automatic_tablet_splitting is true, and otherwise automatically determines an "
28
    "appropriate value based on number of CPU cores.");
29
30
DEFINE_int32(ysql_num_shards_per_tserver, kAutoDetectNumShardsPerTServer,
31
    "The default number of shards per YSQL table per tablet server when a table is created. If the "
32
    "value is -1, the system sets the number of shards per tserver to 1 if "
33
    "enable_automatic_tablet_splitting is true, and otherwise automatically determines an "
34
    "appropriate value based on number of CPU cores.");
35
36
DEFINE_bool(ysql_disable_index_backfill, false,
37
    "A kill switch to disable multi-stage backfill for YSQL indexes.");
38
TAG_FLAG(ysql_disable_index_backfill, hidden);
39
TAG_FLAG(ysql_disable_index_backfill, advanced);
40
41
DEFINE_bool(enable_pg_savepoints, true,
42
            "DEPRECATED -- Set to false to disable savepoints in YugaByte PostgreSQL API.");
43
TAG_FLAG(enable_pg_savepoints, hidden);
44
45
DEFINE_bool(enable_automatic_tablet_splitting, true,
46
            "If false, disables automatic tablet splitting driven from the yb-master side.");
47
48
DEFINE_bool(log_ysql_catalog_versions, false,
49
            "Log YSQL catalog events. For debugging purposes.");
50
TAG_FLAG(log_ysql_catalog_versions, hidden);
51
52
namespace yb {
53
54
3.40k
static int GetYCQLNumShardsPerTServer() {
55
3.40k
  if (GetAtomicFlag(&FLAGS_enable_automatic_tablet_splitting)) {
56
3.34k
    return 1;
57
3.34k
  }
58
59
  int value = 8;
59
59
  if (IsTsan()) {
60
0
    value = 2;
61
59
  } else if (base::NumCPUs() <= 2) {
62
0
    value = 4;
63
0
  }
64
59
  return value;
65
3.40k
}
66
67
3.05k
static int GetYSQLNumShardsPerTServer() {
68
3.05k
  if (GetAtomicFlag(&FLAGS_enable_automatic_tablet_splitting)) {
69
2.99k
    return 1;
70
2.99k
  }
71
59
  int value = 8;
72
59
  if (IsTsan()) {
73
0
    value = 2;
74
59
  } else if (base::NumCPUs() <= 2) {
75
0
    value = 2;
76
59
  } else if (base::NumCPUs() <= 4) {
77
0
    value = 4;
78
0
  }
79
59
  return value;
80
3.05k
}
81
82
54.9k
void InitCommonFlags() {
83
54.9k
  if (GetAtomicFlag(&FLAGS_yb_num_shards_per_tserver) == kAutoDetectNumShardsPerTServer) {
84
3.40k
    int value = GetYCQLNumShardsPerTServer();
85
3.40k
    VLOG
(1) << "Auto setting FLAGS_yb_num_shards_per_tserver to " << value0
;
86
3.40k
    SetAtomicFlag(value, &FLAGS_yb_num_shards_per_tserver);
87
3.40k
  }
88
54.9k
  if (GetAtomicFlag(&FLAGS_ysql_num_shards_per_tserver) == kAutoDetectNumShardsPerTServer) {
89
3.05k
    int value = GetYSQLNumShardsPerTServer();
90
3.05k
    VLOG
(1) << "Auto setting FLAGS_ysql_num_shards_per_tserver to " << value0
;
91
3.05k
    SetAtomicFlag(value, &FLAGS_ysql_num_shards_per_tserver);
92
3.05k
  }
93
54.9k
}
94
95
} // namespace yb