-
Notifications
You must be signed in to change notification settings - Fork 389
/
WdtOptions.cpp
101 lines (90 loc) · 3.36 KB
/
WdtOptions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <glog/logging.h>
#include <wdt/Throttler.h>
#include <wdt/WdtOptions.h>
namespace facebook {
namespace wdt {
/**
* Macro to change the default of some flags based on some other flag
* Example of usage:
* if (enable_download_resumption) {
* CHANGE_IF_NOT_SPECIFIED(overwrite, userSpecifiedOptions, true,
* "(download resumption)")
* }
*/
#define CHANGE_IF_NOT_SPECIFIED(option, specifiedOptions, value, msg) \
if (specifiedOptions.find(#option) == specifiedOptions.end()) { \
WLOG(INFO) << "Setting " << #option << " to " << value << " " << msg; \
option = value; \
} else { \
WLOG(INFO) << "Not overwriting user specified " << #option << " " << msg; \
}
const char* WdtOptions::FLASH_OPTION_TYPE = "flash";
const char* WdtOptions::DISK_OPTION_TYPE = "disk";
void WdtOptions::modifyOptions(
const std::string& optionType,
const std::set<std::string>& userSpecifiedOptions) {
if (optionType == DISK_OPTION_TYPE) {
std::string msg("(disk option type)");
CHANGE_IF_NOT_SPECIFIED(num_ports, userSpecifiedOptions, 3, msg)
CHANGE_IF_NOT_SPECIFIED(block_size_mbytes, userSpecifiedOptions, -1, msg)
CHANGE_IF_NOT_SPECIFIED(disable_preallocation, userSpecifiedOptions, true,
msg)
CHANGE_IF_NOT_SPECIFIED(resume_using_dir_tree, userSpecifiedOptions, true,
msg)
return;
}
if (optionType != FLASH_OPTION_TYPE) {
WLOG(WARNING) << "Invalid option type " << optionType
<< ". Valid types are " << FLASH_OPTION_TYPE << ", "
<< DISK_OPTION_TYPE;
}
// options are initialized for flash. So, no need to change anything
if (userSpecifiedOptions.find("start_port") != userSpecifiedOptions.end() &&
!static_ports) {
WLOG(INFO) << "start_port is specified, setting static_ports true";
static_ports = true;
}
}
bool WdtOptions::shouldPreallocateFiles() const {
#ifdef HAS_POSIX_FALLOCATE
return !disable_preallocation;
#else
return false;
#endif
}
bool WdtOptions::isLogBasedResumption() const {
return enable_download_resumption && !resume_using_dir_tree;
}
bool WdtOptions::isDirectoryTreeBasedResumption() const {
return enable_download_resumption && resume_using_dir_tree;
}
ThrottlerOptions WdtOptions::getThrottlerOptions() const {
ThrottlerOptions throttlerOptions;
throttlerOptions.avg_rate_per_sec = avg_mbytes_per_sec * kMbToB;
throttlerOptions.max_rate_per_sec = max_mbytes_per_sec * kMbToB;
throttlerOptions.throttler_bucket_limit = throttler_bucket_limit * kMbToB;
throttlerOptions.throttler_log_time_millis = throttler_log_time_millis;
// Expected request size equal to buffer size
throttlerOptions.single_request_limit = buffer_size;
return throttlerOptions;
}
/* static */
const WdtOptions& WdtOptions::get() {
return getMutable();
}
WdtOptions& WdtOptions::getMutable() {
static WdtOptions opt;
return opt;
}
void WdtOptions::copyInto(const WdtOptions& src) {
*this = src;
}
} // namespace wdt
} // namespace facebook