YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
1.76k
static int GetYCQLNumShardsPerTServer() {
55
1.76k
  if (GetAtomicFlag(&FLAGS_enable_automatic_tablet_splitting)) {
56
1.70k
    return 1;
57
1.70k
  }
58
53
  int value = 8;
59
53
  if (IsTsan()) {
60
0
    value = 2;
61
53
  } else if (base::NumCPUs() <= 2) {
62
0
    value = 4;
63
0
  }
64
53
  return value;
65
53
}
66
67
1.77k
static int GetYSQLNumShardsPerTServer() {
68
1.77k
  if (GetAtomicFlag(&FLAGS_enable_automatic_tablet_splitting)) {
69
1.71k
    return 1;
70
1.71k
  }
71
53
  int value = 8;
72
53
  if (IsTsan()) {
73
0
    value = 2;
74
53
  } else if (base::NumCPUs() <= 2) {
75
0
    value = 2;
76
53
  } else if (base::NumCPUs() <= 4) {
77
0
    value = 4;
78
0
  }
79
53
  return value;
80
53
}
81
82
37.4k
void InitCommonFlags() {
83
37.4k
  if (GetAtomicFlag(&FLAGS_yb_num_shards_per_tserver) == kAutoDetectNumShardsPerTServer) {
84
1.76k
    int value = GetYCQLNumShardsPerTServer();
85
0
    VLOG(1) << "Auto setting FLAGS_yb_num_shards_per_tserver to " << value;
86
1.76k
    SetAtomicFlag(value, &FLAGS_yb_num_shards_per_tserver);
87
1.76k
  }
88
37.4k
  if (GetAtomicFlag(&FLAGS_ysql_num_shards_per_tserver) == kAutoDetectNumShardsPerTServer) {
89
1.77k
    int value = GetYSQLNumShardsPerTServer();
90
0
    VLOG(1) << "Auto setting FLAGS_ysql_num_shards_per_tserver to " << value;
91
1.77k
    SetAtomicFlag(value, &FLAGS_ysql_num_shards_per_tserver);
92
1.77k
  }
93
37.4k
}
94
95
} // namespace yb