Skip to content

Commit 78f24b7

Browse files
authored
facade/server: Use inline instead of extern to reduce loc (#5768)
facade: Use inline modifier to reduce loc Signed-off-by: Abhijat Malviya <[email protected]>
1 parent c8f0abd commit 78f24b7

File tree

9 files changed

+42
-89
lines changed

9 files changed

+42
-89
lines changed

src/facade/error.h

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include <atomic>
87
#include <string>
98
#include <string_view>
109

@@ -15,35 +14,37 @@ std::string ConfigSetFailed(std::string_view config_name);
1514
std::string InvalidExpireTime(std::string_view cmd);
1615
std::string UnknownSubCmd(std::string_view subcmd, std::string_view cmd);
1716

18-
extern const char kSyntaxErr[];
19-
extern const char kWrongTypeErr[];
20-
extern const char kWrongJsonTypeErr[];
21-
extern const char kKeyNotFoundErr[];
22-
extern const char kInvalidIntErr[];
23-
extern const char kInvalidFloatErr[];
24-
extern const char kUintErr[];
25-
extern const char kIncrOverflow[];
26-
extern const char kDbIndOutOfRangeErr[];
27-
extern const char kInvalidDbIndErr[];
28-
extern const char kScriptNotFound[];
29-
extern const char kAuthRejected[];
30-
extern const char kExpiryOutOfRange[];
31-
extern const char kIndexOutOfRange[];
32-
extern const char kOutOfMemory[];
33-
extern const char kInvalidNumericResult[];
34-
extern const char kClusterNotConfigured[];
35-
extern const char kLoadingErr[];
36-
extern const char kUndeclaredKeyErr[];
37-
extern const char kInvalidDumpValueErr[];
38-
extern const char kInvalidJsonPathErr[];
39-
extern const char kJsonParseError[];
40-
extern const char kCrossSlotError[];
17+
inline constexpr char kSyntaxErr[] = "syntax error";
18+
inline constexpr char kWrongTypeErr[] =
19+
"-WRONGTYPE Operation against a key holding the wrong kind of value";
20+
inline constexpr char kWrongJsonTypeErr[] = "-WRONGTYPE wrong JSON type of path value";
21+
inline constexpr char kKeyNotFoundErr[] = "no such key";
22+
inline constexpr char kInvalidIntErr[] = "value is not an integer or out of range";
23+
inline constexpr char kInvalidFloatErr[] = "value is not a valid float";
24+
inline constexpr char kUintErr[] = "value is out of range, must be positive";
25+
inline constexpr char kIncrOverflow[] = "increment or decrement would overflow";
26+
inline constexpr char kDbIndOutOfRangeErr[] = "DB index is out of range";
27+
inline constexpr char kInvalidDbIndErr[] = "invalid DB index";
28+
inline constexpr char kScriptNotFound[] = "-NOSCRIPT No matching script. Please use EVAL.";
29+
inline constexpr char kAuthRejected[] =
30+
"-WRONGPASS invalid username-password pair or user is disabled.";
31+
inline constexpr char kExpiryOutOfRange[] = "expiry is out of range";
32+
inline constexpr char kIndexOutOfRange[] = "index out of range";
33+
inline constexpr char kOutOfMemory[] = "Out of memory";
34+
inline constexpr char kInvalidNumericResult[] = "result is not a number";
35+
inline constexpr char kClusterNotConfigured[] = "Cluster is not yet configured";
36+
inline constexpr char kLoadingErr[] = "-LOADING Dragonfly is loading the dataset in memory";
37+
inline constexpr char kUndeclaredKeyErr[] = "script tried accessing undeclared key";
38+
inline constexpr char kInvalidDumpValueErr[] = "DUMP payload version or checksum are wrong";
39+
inline constexpr char kInvalidJsonPathErr[] = "invalid JSON path";
40+
inline constexpr char kJsonParseError[] = "failed to parse JSON";
41+
inline constexpr char kCrossSlotError[] = "-CROSSSLOT Keys in request don't hash to the same slot";
4142

42-
extern const char kSyntaxErrType[];
43-
extern const char kScriptErrType[];
44-
extern const char kConfigErrType[];
45-
extern const char kSearchErrType[];
46-
extern const char kWrongTypeErrType[];
47-
extern const char kRestrictDenied[];
43+
inline constexpr char kSyntaxErrType[] = "syntax_error";
44+
inline constexpr char kScriptErrType[] = "script_error";
45+
inline constexpr char kConfigErrType[] = "config_error";
46+
inline constexpr char kSearchErrType[] = "search_error";
47+
inline constexpr char kWrongTypeErrType[] = "wrong_type";
48+
inline constexpr char kRestrictDenied[] = "restrict_denied";
4849

4950
} // namespace facade

src/facade/facade.cc

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,37 +110,6 @@ string ConfigSetFailed(string_view config_name) {
110110
return absl::StrCat("CONFIG SET failed (possibly related to argument '", config_name, "').");
111111
}
112112

113-
const char kSyntaxErr[] = "syntax error";
114-
const char kWrongTypeErr[] = "-WRONGTYPE Operation against a key holding the wrong kind of value";
115-
const char kWrongJsonTypeErr[] = "-WRONGTYPE wrong JSON type of path value";
116-
const char kKeyNotFoundErr[] = "no such key";
117-
const char kInvalidIntErr[] = "value is not an integer or out of range";
118-
const char kInvalidFloatErr[] = "value is not a valid float";
119-
const char kUintErr[] = "value is out of range, must be positive";
120-
const char kIncrOverflow[] = "increment or decrement would overflow";
121-
const char kDbIndOutOfRangeErr[] = "DB index is out of range";
122-
const char kInvalidDbIndErr[] = "invalid DB index";
123-
const char kScriptNotFound[] = "-NOSCRIPT No matching script. Please use EVAL.";
124-
const char kAuthRejected[] = "-WRONGPASS invalid username-password pair or user is disabled.";
125-
const char kExpiryOutOfRange[] = "expiry is out of range";
126-
const char kIndexOutOfRange[] = "index out of range";
127-
const char kOutOfMemory[] = "Out of memory";
128-
const char kInvalidNumericResult[] = "result is not a number";
129-
const char kClusterNotConfigured[] = "Cluster is not yet configured";
130-
const char kLoadingErr[] = "-LOADING Dragonfly is loading the dataset in memory";
131-
const char kUndeclaredKeyErr[] = "script tried accessing undeclared key";
132-
const char kInvalidDumpValueErr[] = "DUMP payload version or checksum are wrong";
133-
const char kInvalidJsonPathErr[] = "invalid JSON path";
134-
const char kJsonParseError[] = "failed to parse JSON";
135-
const char kCrossSlotError[] = "-CROSSSLOT Keys in request don't hash to the same slot";
136-
137-
const char kSyntaxErrType[] = "syntax_error";
138-
const char kScriptErrType[] = "script_error";
139-
const char kConfigErrType[] = "config_error";
140-
const char kSearchErrType[] = "search_error";
141-
const char kWrongTypeErrType[] = "wrong_type";
142-
const char kRestrictDenied[] = "restrict_denied";
143-
144113
const char* RespExpr::TypeName(Type t) {
145114
switch (t) {
146115
case STRING:
@@ -182,8 +151,6 @@ uint32_t CommandId::OptCount(uint32_t mask) {
182151
return absl::popcount(mask);
183152
}
184153

185-
__thread FacadeStats* tl_facade_stats = nullptr;
186-
187154
static bool ParseHumanReadableBytes(std::string_view str, int64_t* num_bytes) {
188155
if (str.empty())
189156
return false;

src/facade/facade_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ struct ErrorReply {
201201
std::optional<OpStatus> status{std::nullopt};
202202
};
203203

204-
constexpr inline unsigned long long operator""_MB(unsigned long long x) {
204+
constexpr unsigned long long operator""_MB(unsigned long long x) {
205205
return 1024L * 1024L * x;
206206
}
207207

208-
constexpr inline unsigned long long operator""_KB(unsigned long long x) {
208+
constexpr unsigned long long operator""_KB(unsigned long long x) {
209209
return 1024L * x;
210210
}
211211

212-
extern __thread FacadeStats* tl_facade_stats;
212+
inline thread_local FacadeStats* tl_facade_stats = nullptr;
213213

214214
void ResetStats();
215215

src/server/cluster_support.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ optional<SlotId> UniqueSlotChecker::GetUniqueSlotId() const {
4747
return slot_id_ > kMaxSlotNum ? optional<SlotId>() : slot_id_;
4848
}
4949

50-
namespace detail {
51-
ClusterMode cluster_mode = ClusterMode::kUninitialized;
52-
bool cluster_shard_by_slot = false;
53-
54-
} // namespace detail
55-
5650
using namespace detail;
5751

5852
void InitializeCluster() {

src/server/cluster_support.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ enum class ClusterMode {
1919
kRealCluster,
2020
};
2121

22-
extern ClusterMode cluster_mode;
23-
extern bool cluster_shard_by_slot;
22+
inline ClusterMode cluster_mode = ClusterMode::kUninitialized;
23+
inline bool cluster_shard_by_slot = false;
2424

2525
}; // namespace detail
2626

src/server/common.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ std::string_view LockTagOptions::Tag(std::string_view key) const {
110110
return key.substr(start + 1, end - start - 1);
111111
}
112112

113-
atomic_uint64_t used_mem_current(0);
114-
atomic_uint64_t rss_mem_current(0);
115-
atomic_uint64_t max_memory_limit(0);
116-
117-
unsigned kernel_version = 0;
118-
Namespaces* namespaces = nullptr;
119-
120113
const char* GlobalStateName(GlobalState s) {
121114
switch (s) {
122115
case GlobalState::ACTIVE:

src/server/common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ bool ParseDouble(std::string_view src, double* value);
129129
const char* RdbTypeName(unsigned type);
130130

131131
// Globally used atomics for memory readings
132-
extern std::atomic_uint64_t used_mem_current;
133-
extern std::atomic_uint64_t rss_mem_current;
132+
inline std::atomic_uint64_t used_mem_current{0};
133+
inline std::atomic_uint64_t rss_mem_current{0};
134134
// Current value of --maxmemory flag
135-
extern std::atomic_uint64_t max_memory_limit;
135+
inline std::atomic_uint64_t max_memory_limit{0};
136136

137-
extern Namespaces* namespaces;
137+
inline Namespaces* namespaces = nullptr;
138138

139139
// version 5.11 maps to 511 etc.
140140
// set upon server start.
141-
extern unsigned kernel_version;
141+
inline unsigned kernel_version = 0;
142142

143143
const char* GlobalStateName(GlobalState gs);
144144

src/server/config_registry.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,4 @@ void ConfigRegistry::ValidateCustomSetter(std::string_view name, WriteCb setter)
9696
}
9797
}
9898

99-
ConfigRegistry config_registry;
100-
10199
} // namespace dfly

src/server/config_registry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ class ConfigRegistry {
7272
absl::flat_hash_map<std::string, Entry> registry_ ABSL_GUARDED_BY(mu_);
7373
};
7474

75-
extern ConfigRegistry config_registry;
75+
inline ConfigRegistry config_registry;
7676

7777
} // namespace dfly

0 commit comments

Comments
 (0)