forked from facebook/wdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WdtOptions.cpp
91 lines (81 loc) · 2.96 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
/**
* 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. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <wdt/WdtOptions.h>
#include <glog/logging.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)
CHANGE_IF_NOT_SPECIFIED(skip_fadvise, 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;
}
/* static */
const WdtOptions& WdtOptions::get() {
return getMutable();
}
WdtOptions& WdtOptions::getMutable() {
static WdtOptions opt;
return opt;
}
void WdtOptions::copyInto(const WdtOptions& src) {
*this = src;
}
}
}