Skip to content

Commit 917cb08

Browse files
[feat][client] Use gflags for client command options
1 parent 9254b43 commit 917cb08

Some content is hidden

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

41 files changed

+729
-1766
lines changed

src/cache/benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ target_link_libraries(cache_benchmark
2727
cache_utils
2828
cache_common
2929
cache_storage
30+
cache_tiercache
3031
)
3132

3233
add_executable(cache-bench main.cc)

src/cache/cachegroup/cache_group_node_server.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "cache/cachegroup/cache_group_node.h"
2626
#include "cache/cachegroup/cache_group_node_service.h"
2727
#include "cache/common/macro.h"
28+
#include "common/options/cache.h"
2829

2930
namespace brpc {
3031
DECLARE_bool(graceful_quit_on_sigterm);

src/cache/common/mds_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
namespace dingofs {
4747
namespace cache {
4848

49-
DEFINE_string(mds_addrs, "",
49+
DEFINE_string(mds_addrs, "127.0.0.1:7400",
5050
"Cache group member manager service rpc addresses");
5151
DEFINE_validator(mds_addrs, Helper::NonEmptyString);
5252

src/client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ target_link_libraries(fuse_client_lib
2929
dingofs_metrics
3030
dingofs_common
3131
client_options
32+
cache_tiercache
3233
jsoncpp
3334
${FUSE3_LIBRARY}
3435
)

src/client/common/client_option.h

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (c) 2025 dingodb.com, Inc. All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef DINGOFS_CLIENT_COMMON_CLIENT_OPTION_H_
18+
#define DINGOFS_CLIENT_COMMON_CLIENT_OPTION_H_
19+
20+
#include <brpc/reloadable_flags.h>
21+
#include <gflags/gflags.h>
22+
23+
#include <string>
24+
25+
#include "common/blockaccess/accesser_common.h"
26+
#include "common/const.h"
27+
#include "common/options/client.h"
28+
29+
namespace dingofs {
30+
namespace client {
31+
32+
// fuse option
33+
struct FuseConnInfo {
34+
bool want_splice_move;
35+
bool want_splice_read;
36+
bool want_splice_write;
37+
bool want_auto_inval_data;
38+
};
39+
40+
struct FuseFileInfo {
41+
bool keep_cache;
42+
};
43+
44+
struct FuseOption {
45+
FuseConnInfo conn_info;
46+
FuseFileInfo file_info;
47+
};
48+
49+
// memory option
50+
struct PageOption {
51+
uint32_t page_size;
52+
uint64_t total_size;
53+
bool use_pool;
54+
};
55+
56+
// vfs option
57+
struct VFSMetaOption {
58+
uint32_t max_name_length; // max length of file name
59+
};
60+
61+
struct VFSDataOption {
62+
bool writeback{false}; // whether to use writeback
63+
std::string writeback_suffix;
64+
};
65+
66+
struct VFSOption {
67+
blockaccess::BlockAccessOptions block_access_opt; // from gflags
68+
PageOption page_option;
69+
FuseOption fuse_option;
70+
71+
VFSMetaOption meta_option;
72+
VFSDataOption data_option;
73+
74+
uint32_t dummy_server_port{10000};
75+
};
76+
77+
static void InitFuseOption(FuseOption* option) {
78+
{ // fuse conn info
79+
auto* fuse_conn_info = &option->conn_info;
80+
fuse_conn_info->want_splice_move = FLAGS_fuse_conn_info_want_splice_move;
81+
fuse_conn_info->want_splice_read = FLAGS_fuse_conn_info_want_splice_read;
82+
fuse_conn_info->want_splice_write = FLAGS_fuse_conn_info_want_splice_write;
83+
fuse_conn_info->want_auto_inval_data =
84+
FLAGS_fuse_conn_info_want_auto_inval_data;
85+
}
86+
87+
{ // fuse file info
88+
auto* fuse_file_info = &option->file_info;
89+
fuse_file_info->keep_cache = FLAGS_client_fuse_file_info_keep_cache;
90+
}
91+
}
92+
93+
static void InitMemoryPageOption(PageOption* option) {
94+
// page option
95+
option->page_size = FLAGS_data_stream_page_size;
96+
option->total_size = FLAGS_data_stream_page_total_size_mb;
97+
option->use_pool = FLAGS_data_stream_page_use_pool;
98+
99+
if (option->page_size == 0) {
100+
CHECK(false) << "page size must greater than 0.";
101+
}
102+
103+
option->total_size = option->total_size * kMiB;
104+
if (option->total_size < 64 * kMiB) {
105+
CHECK(false) << "page total size must greater than 64MB.";
106+
}
107+
}
108+
109+
static void InitVFSMetaOption(VFSMetaOption* option) {
110+
option->max_name_length = FLAGS_vfs_meta_max_name_length;
111+
if (option->max_name_length < 1) {
112+
CHECK(false) << "file name length must greater than 0.";
113+
}
114+
}
115+
116+
static void InitVFSDataOption(VFSDataOption* option) {
117+
option->writeback = FLAGS_vfs_data_writeback;
118+
option->writeback_suffix = FLAGS_vfs_data_writeback_suffix;
119+
}
120+
121+
static void InitVFSOption(VFSOption* option) {
122+
blockaccess::InitAwsSdkConfig(
123+
&option->block_access_opt.s3_options.aws_sdk_config);
124+
blockaccess::InitBlockAccesserThrottleOptions(
125+
&option->block_access_opt.throttle_options);
126+
127+
InitMemoryPageOption(&option->page_option);
128+
129+
InitFuseOption(&option->fuse_option);
130+
131+
InitVFSMetaOption(&option->meta_option);
132+
133+
InitVFSDataOption(&option->data_option);
134+
135+
option->dummy_server_port = FLAGS_vfs_dummy_server_port;
136+
}
137+
138+
} // namespace client
139+
} // namespace dingofs
140+
141+
#endif // DINGOFS_CLIENT_COMMON_CLIENT_OPTION_H_

src/client/common/global_log.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,21 @@
1818
#define DINGOFS_SRC_CLIENT_COMMON_GLOBAL_LOG_H_
1919

2020
#include "common/options/client.h"
21-
#include "fmt/format.h"
2221
#include "glog/logging.h"
23-
#include "utils/configuration.h"
24-
#include "utils/gflags_helper.h"
25-
26-
static int InitLog(const char* argv0, const std::string& conf_path) {
27-
dingofs::utils::Configuration conf;
28-
conf.SetConfigPath(conf_path);
29-
if (!conf.LoadConfig()) {
30-
LOG(ERROR) << "loadConfig fail, confPath=" << conf_path;
31-
return 1;
32-
}
3322

23+
static int InitLog(const char* argv0) {
3424
// set log dir
35-
if (FLAGS_log_dir.empty()) {
36-
if (!conf.GetStringValue("client.common.logDir", &FLAGS_log_dir)) {
37-
LOG(WARNING) << fmt::format(
38-
"no client.common.logDir in {}, will log to /tmp.", conf_path);
39-
}
40-
}
41-
42-
dingofs::utils::GflagsLoadValueFromConfIfCmdNotSet dummy;
43-
dummy.Load(&conf, "v", "client.loglevel", &FLAGS_v);
44-
dingofs::client::FLAGS_vlog_level = FLAGS_v;
25+
FLAGS_log_dir = dingofs::client::FLAGS_client_log_dir;
26+
FLAGS_v = dingofs::client::FLAGS_client_log_level;
4527

4628
FLAGS_logbufsecs = 4;
4729
FLAGS_minloglevel = google::GLOG_INFO;
4830
FLAGS_logbuflevel = google::GLOG_INFO;
4931

5032
// initialize logging module
5133
google::InitGoogleLogging(argv0);
34+
LOG(INFO) << "current verbose logging level is: " << FLAGS_v
35+
<< ", log dir is: " << FLAGS_log_dir;
5236

5337
return 0;
5438
}

src/client/common/utils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ static std::string Char2Addr(const char* p) {
2828
return oss.str();
2929
}
3030

31+
inline bool ParseMetaURL(const std::string& meta_url, std::string& addrs,
32+
std::string& fs_name) {
33+
size_t pos = meta_url.find('/');
34+
if (pos == std::string::npos) {
35+
return false;
36+
}
37+
addrs = meta_url.substr(0, pos);
38+
fs_name = meta_url.substr(pos + 1);
39+
40+
return true;
41+
}
42+
3143
} // namespace client
3244
} // namespace dingofs
3345

src/client/fuse/fuse_common.h

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,24 @@ using dingofs::utils::TrimSpace;
4646

4747
const std::string kFdCommPathKey = "fd_comm_path";
4848

49-
#ifdef __cplusplus
50-
extern "C" {
51-
#endif
52-
5349
struct MountOption {
54-
const char* mount_point;
55-
const char* fs_name;
56-
const char* fs_type;
57-
char* conf;
58-
char* mds_addr;
50+
std::string mount_point;
51+
std::string fs_name;
52+
std::string fs_type;
53+
std::string mds_addrs;
5954
};
6055

61-
static const struct fuse_opt kMountOpts[] = {
62-
{"fsname=%s", offsetof(struct MountOption, fs_name), 0},
63-
64-
{"fstype=%s", offsetof(struct MountOption, fs_type), 0},
65-
66-
{"conf=%s", offsetof(struct MountOption, conf), 0},
67-
68-
FUSE_OPT_END};
69-
70-
#ifdef __cplusplus
71-
} // extern "C"
72-
#endif
73-
7456
inline int FuseAddOpts(struct fuse_args* args, const char* arg_value) {
7557
if (fuse_opt_add_arg(args, "-o") == -1) return 1;
7658
if (fuse_opt_add_arg(args, arg_value) == -1) return 1;
7759
return 0;
7860
}
7961

8062
// Get file inode number
81-
inline int GetFileInode(const char* file_name) {
63+
inline int GetFileInode(const std::string& file_name) {
8264
struct stat file_info;
8365

84-
if (stat(file_name, &file_info) == 0) {
66+
if (stat(file_name.c_str(), &file_info) == 0) {
8567
return file_info.st_ino;
8668
}
8769
return -1;
@@ -161,7 +143,7 @@ inline std::string GetFdCommFileName(const std::string& filename) {
161143
*
162144
* @param mountpoint dingo-fuse mountpoint
163145
*/
164-
inline bool CanShutdownGracefully(const char* mountpoint) {
146+
inline bool CanShutdownGracefully(const std::string& mountpoint) {
165147
if (GetFileInode(mountpoint) != dingofs::ROOTINODEID) {
166148
return false;
167149
}
@@ -175,7 +157,7 @@ inline bool CanShutdownGracefully(const char* mountpoint) {
175157
* @param mountpoint dingo-fuse mountpoint
176158
* @param fd file descriptor for /dev/fuse
177159
*/
178-
inline void DingoSessionUnmount(const char* mountpoint, int fd) {
160+
inline void DingoSessionUnmount(const std::string& mountpoint, int fd) {
179161
int res;
180162

181163
if (fd != -1) {
@@ -198,7 +180,7 @@ inline void DingoSessionUnmount(const char* mountpoint, int fd) {
198180
if (res == 1 && (pfd.revents & POLLERR)) return;
199181
}
200182

201-
res = umount2(mountpoint, 2);
183+
res = umount2(mountpoint.c_str(), 2);
202184
if (res == 0) return;
203185
}
204186

src/client/fuse/fuse_op.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "common/status.h"
3737
#include "fmt/format.h"
3838
#include "glog/logging.h"
39-
#include "utils/configuration.h"
4039

4140
static dingofs::client::vfs::VFSWrapper* g_vfs = nullptr;
4241

@@ -310,9 +309,9 @@ static void ReplyStatfs(fuse_req_t req, const FsStat& stat) {
310309

311310
int InitFuseClient(const char* argv0, const struct MountOption* mount_option) {
312311
dingofs::client::vfs::VFSConfig config = {
312+
.mds_addrs = mount_option->mds_addrs,
313313
.mount_point = mount_option->mount_point,
314314
.fs_name = mount_option->fs_name,
315-
.config_path = mount_option->conf,
316315
.fs_type = mount_option->fs_type,
317316
};
318317

0 commit comments

Comments
 (0)