Skip to content

Commit c6e2776

Browse files
veselink1trondn
authored andcommitted
MB-67342: Use byte_literals.h
Change-Id: Ibdb9e4d69cb2c183c97d2a00e8e2f92fb607c796 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/229826 Reviewed-by: Trond Norbye <[email protected]> Tested-by: Vesko Karaganev <[email protected]>
1 parent 04bf2c2 commit c6e2776

File tree

75 files changed

+186
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+186
-199
lines changed

auditd/src/auditconfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma once
1111

1212
#include <nlohmann/json_fwd.hpp>
13+
#include <platform/byte_literals.h>
1314
#include <atomic>
1415
#include <chrono>
1516
#include <cinttypes>
@@ -91,7 +92,7 @@ class AuditConfig {
9192

9293
bool auditd_enabled{false};
9394
uint32_t rotate_interval{900};
94-
size_t rotate_size{20 * 1024 * 1024};
95+
size_t rotate_size{20_MiB};
9596
std::optional<std::chrono::seconds> prune_age;
9697
bool buffered{true};
9798
bool filtering_enabled{false};

auditd/src/auditfile.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ bool AuditFile::open() {
206206

207207
try {
208208
file = cb::crypto::FileWriter::create(
209-
key, open_file_name, 8192, cb::crypto::Compression::None);
209+
key, open_file_name, 8_KiB, cb::crypto::Compression::None);
210210
LOG_INFO_CTX(
211211
"Audit file",
212212
{"encrypted", file->is_encrypted() ? "encrypted" : "plain"});

auditd/src/auditfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class AuditFile {
127127
std::filesystem::path open_file_name;
128128
std::filesystem::path log_directory;
129129
time_t open_time = 0;
130-
size_t max_log_size = 20 * 1024 * 1024;
130+
size_t max_log_size = 20_MiB;
131131
uint32_t rotate_interval = 900;
132132
std::optional<std::chrono::seconds> prune_age;
133133
/// Iterating over all files in the directory and fetch their

auditd/tests/auditconfig_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AuditConfigTest : public ::testing::Test {
3939
nlohmann::json createDefaultConfig() {
4040
nlohmann::json root;
4141
root["version"] = 2;
42-
root["rotate_size"] = 20 * 1024 * 1024;
42+
root["rotate_size"] = 20_MiB;
4343
root["rotate_interval"] = 900;
4444
root["auditd_enabled"] = true;
4545
root["buffered"] = true;

daemon/cmdline.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void usage() {
3232
}
3333

3434
static std::string read_command() {
35-
std::vector<char> buffer(1 * 1024 * 1024);
35+
std::vector<char> buffer(1_MiB);
3636
#ifdef WIN32
3737
// Windows call a blocking call to fgets() in stdin_check so we
3838
// can might as well use the portable fgets() and not have to

daemon/connection_libevent.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/// consume memory on the server (for instance send everything except
3232
/// the last byte of a request and let the server be stuck waiting
3333
/// for the last byte of a 20MB command)
34-
static constexpr size_t MaxUnauthenticatedFrameSize = 16 * 1024;
34+
static constexpr size_t MaxUnauthenticatedFrameSize = 16_KiB;
3535

3636
LibeventConnection::LibeventConnection(SOCKET sfd,
3737
FrontEndThread& thr,
@@ -161,7 +161,7 @@ void LibeventConnection::rw_callback() {
161161
// transferred at least 64k to getting notified *too* often.
162162
const auto length = getSendQueueSize();
163163
if (length) {
164-
const size_t chunk = 64 * 1024;
164+
const size_t chunk = 64_KiB;
165165
if (length > chunk) {
166166
const auto watermark =
167167
std::min(length - chunk, max_send_watermark_size);

daemon/protocol/mcbp/get_file_fragment_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <platform/crc32c.h>
2626
#include <platform/strerror.h>
2727

28-
constexpr std::size_t MaxReadSize = 2 * 1024 * 1024 * 1024ULL;
28+
constexpr std::size_t MaxReadSize = 2_GiB;
2929

3030
GetFileFragmentContext::GetFileFragmentContext(Cookie& cookie)
3131
: SteppableCommandContext(cookie),
@@ -195,7 +195,7 @@ cb::engine_errc GetFileFragmentContext::read_file_chunk() {
195195
"Read file fragment",
196196
[this]() {
197197
try {
198-
constexpr std::size_t ChunkSize = 20 * 1024 * 1024;
198+
constexpr std::size_t ChunkSize = 20_MiB;
199199
const auto to_read = std::min(length, ChunkSize);
200200

201201
auto iob = folly::IOBuf::createCombined(to_read);

daemon/settings.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void Settings::reconfigure(const nlohmann::json& json) {
216216
setMaxPacketSize(value.get<uint32_t>() * uint32_t(1024) *
217217
uint32_t(1024));
218218
} else if (key == "max_send_queue_size"sv) {
219-
setMaxSendQueueSize(value.get<size_t>() * 1024 * 1024);
219+
setMaxSendQueueSize(value.get<size_t>() * 1_MiB);
220220
} else if (key == "max_so_sndbuf_size"sv) {
221221
setMaxSoSndbufSize(value.get<uint32_t>());
222222
} else if (key == "max_connections"sv) {
@@ -705,8 +705,8 @@ void Settings::updateSettings(const Settings& other, bool apply) {
705705
if (other.has.max_send_queue_size) {
706706
if (other.max_send_queue_size != max_send_queue_size) {
707707
LOG_INFO_CTX("Change max packet size",
708-
{"from", max_send_queue_size / (1024 * 1024)},
709-
{"to", other.max_send_queue_size / (1024 * 1024)});
708+
{"from", max_send_queue_size / (1_MiB)},
709+
{"to", other.max_send_queue_size / (1_MiB)});
710710
setMaxSendQueueSize(other.max_send_queue_size);
711711
}
712712
}

daemon/settings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ class Settings {
10191019
/// body of the document. With a 1MB output queue you can fit 50 ~20k
10201020
/// documents (50 is the (default) max number of operations a client
10211021
/// may perform before backing off.
1022-
std::atomic<size_t> max_send_queue_size{1024 * 1024};
1022+
std::atomic<size_t> max_send_queue_size{1_MiB};
10231023

10241024
/// The maximum size we want to try to set SO_SNDBUF to. For windows
10251025
/// the default is 1MB as there is no operating system tunable which
@@ -1028,9 +1028,9 @@ class Settings {
10281028
/// insane large number and use the operating systems max value.
10291029
std::atomic<uint32_t> max_so_sndbuf_size{
10301030
#ifdef WIN32
1031-
1024 * 1024
1031+
1_MiB
10321032
#else
1033-
256 * 1024 * 1024
1033+
256_MiB
10341034
#endif
10351035
};
10361036

@@ -1099,7 +1099,7 @@ class Settings {
10991099
std::atomic<std::size_t> max_concurrent_commands_per_connection{32};
11001100

11011101
// The rate limit for Fusion extent migration, in bytes per second
1102-
std::atomic<size_t> fusion_migration_rate_limit{1024 * 1024 * 75};
1102+
std::atomic<size_t> fusion_migration_rate_limit{75_MiB};
11031103

11041104
/**
11051105
* Note that it is not safe to add new listeners after we've spun up
@@ -1138,7 +1138,7 @@ class Settings {
11381138
/// Max document size is 20MB so by using 30MB we'll get the correct
11391139
/// E2BIG error message for connections going a bit bigger (and not
11401140
/// a quiet disconnect)
1141-
uint32_t max_packet_size{30 * 1024 * 1024};
1141+
uint32_t max_packet_size{30_MiB};
11421142

11431143
std::atomic<int> num_reader_threads{0};
11441144
std::atomic<int> num_writer_threads{0};

daemon/settings_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ TEST_F(SettingsTest, max_packet_size) {
630630
obj["max_packet_size"] = maxPacketSize;
631631
try {
632632
Settings settings(obj);
633-
EXPECT_EQ(30 * 1024 * 1024, settings.getMaxPacketSize());
633+
EXPECT_EQ(30_MiB, settings.getMaxPacketSize());
634634
EXPECT_TRUE(settings.has.max_packet_size);
635635
} catch (std::exception& exception) {
636636
FAIL() << exception.what();
@@ -909,7 +909,7 @@ TEST(SettingsUpdateTest, UpdatingLoggerSettingsShouldFail) {
909909
cb::logger::Config config;
910910
config.filename.assign("logger_test");
911911
config.buffersize = 1024;
912-
config.cyclesize = 1024 * 1024;
912+
config.cyclesize = 1_MiB;
913913

914914
EXPECT_NO_THROW(settings.updateSettings(updated, false));
915915

0 commit comments

Comments
 (0)