Skip to content

Commit 9254b43

Browse files
rock-gitchuandew
authored andcommitted
[feat][mds] Support tikv as storage.
1 parent da848d9 commit 9254b43

File tree

21 files changed

+727
-66
lines changed

21 files changed

+727
-66
lines changed

.github/workflows/ci-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
4343
- name: Pull dingodatabase/dingo-eureka:rocky9-fs
4444
run: |
45-
docker pull dingodatabase/dingo-eureka:rocky9-fs-78d3a4f
45+
docker pull dingodatabase/dingo-eureka:rocky9-fs-ac7e2b9
4646
4747
- name: Init build script
4848
run: |
@@ -141,7 +141,7 @@ jobs:
141141
- name: Build DingoFS
142142
run: |
143143
echo "Build DingoFS"
144-
docker run --name release-dingofs --rm -v /mnt/dingofs:/opt/dingofs/ dingodatabase/dingo-eureka:rocky9-fs-78d3a4f /opt/dingofs/build.sh
144+
docker run --name release-dingofs --rm -v /mnt/dingofs:/opt/dingofs/ dingodatabase/dingo-eureka:rocky9-fs-ac7e2b9 /opt/dingofs/build.sh
145145
146146
- name: Copy artifactory to another workflow
147147
uses: actions/upload-artifact@v4

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ message("Using rados: ${RADOS_LIBRARIES}")
237237
find_package(dingosdk REQUIRED)
238238
message(STATUS "Found dingosdk: ${dingosdk_VERSION}")
239239

240+
find_package(tikvcpp REQUIRED)
241+
message(STATUS "Found tikvcpp: ${tikvcpp_VERSION}")
242+
240243
# ------------------------ related to source code ------------------------
241244

242245
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

conf/mds.template.conf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11

2-
# storage [dingo-store|dummy]
2+
# storage [dingo-store|tikv|dummy]
3+
# storage_url depends on storage engine
4+
# dingo-store: coordinator address
5+
# tikv: pd address
6+
# dummy: no need address
7+
# format: file://./conf/coor_list | list://ip1:port1,ip2:port2,... | ip1:port1,ip2:port2,...
38
--mds_storage_engine=dingo-store
4-
# dingo-store coordinator address
5-
--coor_url=file://./conf/coor_list
9+
--storage_url=file://./conf/coor_list
610

711
# server
812
--mds_server_id=$INSTANCE_ID$

src/mds/client/br.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ bool Backup::Init(const std::string& coor_addr) {
284284
auto kv_storage = DingodbStorage::New();
285285
CHECK(kv_storage != nullptr) << "new DingodbStorage fail.";
286286

287-
std::string store_addrs = Helper::ParseCoorAddr(coor_addr);
287+
std::string store_addrs = Helper::ParseStorageAddr(coor_addr);
288288
if (store_addrs.empty()) {
289289
return false;
290290
}
@@ -458,7 +458,7 @@ bool Restore::Init(const std::string& coor_addr) {
458458
auto kv_storage = DingodbStorage::New();
459459
CHECK(kv_storage != nullptr) << "new DingodbStorage fail.";
460460

461-
std::string store_addrs = Helper::ParseCoorAddr(coor_addr);
461+
std::string store_addrs = Helper::ParseStorageAddr(coor_addr);
462462
if (store_addrs.empty()) {
463463
return false;
464464
}

src/mds/client/store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool StoreClient::Init(const std::string& coor_addr) {
4040
kv_storage_ = DingodbStorage::New();
4141
CHECK(kv_storage_ != nullptr) << "new DingodbStorage fail.";
4242

43-
std::string store_addrs = Helper::ParseCoorAddr(coor_addr);
43+
std::string store_addrs = Helper::ParseStorageAddr(coor_addr);
4444
if (store_addrs.empty()) {
4545
return false;
4646
}

src/mds/common/helper.cc

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <filesystem>
2424
#include <fstream>
2525
#include <random>
26+
#include <regex>
2627
#include <string>
2728
#include <thread>
2829

@@ -431,8 +432,13 @@ std::string Helper::EndPointToString(const butil::EndPoint& endpoint) {
431432
return std::string(butil::endpoint2str(endpoint).c_str());
432433
}
433434

434-
static bool IsValidFileAddr(const std::string& coor_url) { return coor_url.substr(0, 7) == "file://"; }
435-
static bool IsValidListAddr(const std::string& coor_url) { return coor_url.substr(0, 7) == "list://"; }
435+
static bool IsValidFileAddr(const std::string& url) { return url.substr(0, 7) == "file://"; }
436+
static bool IsValidListAddr(const std::string& url) { return url.substr(0, 7) == "list://"; }
437+
static bool IsValidBareAddr(const std::string& url) {
438+
// check 127.0.0.1:80 or 127.0.0.1:80,127.0.0.1:81 use regex
439+
std::regex ip_port_list_regex(R"(^((\d{1,3}\.){3}\d{1,3}:\d{1,5})(,(\d{1,3}\.){3}\d{1,3}:\d{1,5})*$)");
440+
return std::regex_match(url, ip_port_list_regex);
441+
}
436442

437443
static std::string ParseFileUrl(const std::string& coor_url) {
438444
CHECK(coor_url.substr(0, 7) == "file://") << "Invalid coor_url: " << coor_url;
@@ -461,25 +467,25 @@ static std::string ParseFileUrl(const std::string& coor_url) {
461467
return addrs.empty() ? "" : addrs.substr(0, addrs.size() - 1);
462468
}
463469

464-
static std::string ParseListUrl(const std::string& coor_url) {
465-
CHECK(coor_url.substr(0, 7) == "list://") << "Invalid coor_url: " << coor_url;
470+
static std::string ParseListUrl(const std::string& url) {
471+
CHECK(url.substr(0, 7) == "list://") << "invalid url: " << url;
466472

467-
return coor_url.substr(7);
473+
return url.substr(7);
468474
}
469475

470-
std::string Helper::ParseCoorAddr(const std::string& coor_url) {
471-
std::string coor_addrs;
472-
if (IsValidFileAddr(coor_url)) {
473-
coor_addrs = ParseFileUrl(coor_url);
476+
std::string Helper::ParseStorageAddr(const std::string& url) {
477+
std::string storage_addrs;
478+
if (IsValidFileAddr(url)) {
479+
storage_addrs = ParseFileUrl(url);
474480

475-
} else if (IsValidListAddr(coor_url)) {
476-
coor_addrs = ParseListUrl(coor_url);
481+
} else if (IsValidListAddr(url)) {
482+
storage_addrs = ParseListUrl(url);
477483

478-
} else {
479-
DINGO_LOG(ERROR) << "Invalid coor_url: " << coor_url;
484+
} else if (IsValidBareAddr(url)) {
485+
storage_addrs = url;
480486
}
481487

482-
return coor_addrs;
488+
return storage_addrs;
483489
}
484490

485491
bool Helper::SaveFile(const std::string& filepath, const std::string& data) {

src/mds/common/helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Helper {
100100

101101
static std::string EndPointToString(const butil::EndPoint& endpoint);
102102

103-
static std::string ParseCoorAddr(const std::string& coor_url);
103+
static std::string ParseStorageAddr(const std::string& url);
104104

105105
static bool SaveFile(const std::string& filepath, const std::string& data);
106106

src/mds/filesystem/filesystem.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ DEFINE_validator(mds_transfer_max_slice_num, brpc::PassValidate);
8787
DEFINE_uint32(mds_cache_expire_interval_s, 7200, "Cache expire interval in seconds.");
8888
DEFINE_validator(mds_cache_expire_interval_s, brpc::PassValidate);
8989

90-
DEFINE_string(mds_storage_engine, "dummy", "mds storage engine, e.g dingo-store|dummy");
90+
DEFINE_string(mds_storage_engine, "dummy", "mds storage engine, e.g dingo-store|tikv|dummy");
91+
DEFINE_validator(mds_storage_engine, [](const char*, const std::string& value) -> bool {
92+
return value == "dingo-store" || value == "tikv" || value == "dummy";
93+
});
94+
9195
DEFINE_string(mds_id_generator_type, "coor", "id generator type, e.g coor|store");
96+
DEFINE_validator(mds_id_generator_type,
97+
[](const char*, const std::string& value) -> bool { return value == "coor" || value == "store"; });
9298

9399
static bool IsInvalidName(const std::string& name) {
94100
return name.empty() || name.size() > FLAGS_mds_filesystem_name_max_size;
@@ -2835,7 +2841,7 @@ IdGeneratorUPtr FileSystemSet::NewInoGenerator(uint32_t fs_id) {
28352841
ino_id_generator = (FLAGS_mds_id_generator_type == "coor") ? NewInodeIdGenerator(fs_id, coordinator_client_)
28362842
: NewInodeIdGenerator(fs_id, kv_storage_);
28372843

2838-
} else if (FLAGS_mds_storage_engine == "dummy") {
2844+
} else {
28392845
ino_id_generator = NewInodeIdGenerator(fs_id, kv_storage_);
28402846
}
28412847

@@ -2850,7 +2856,7 @@ void FileSystemSet::DestroyInoGenerator(uint32_t fs_id) {
28502856
DestroyInodeIdGenerator(fs_id, kv_storage_);
28512857
}
28522858

2853-
} else if (FLAGS_mds_storage_engine == "dummy") {
2859+
} else {
28542860
DestroyInodeIdGenerator(fs_id, kv_storage_);
28552861
}
28562862
}

src/mds/filesystem/store_operation.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "mds/filesystem/store_operation.h"
1515

16+
#include <bthread/types.h>
1617
#include <fcntl.h>
1718

1819
#include <algorithm>
@@ -2690,7 +2691,7 @@ void OperationProcessor::LaunchExecuteBatchOperation(const BatchOperation& batch
26902691
Params* params = new Params({.self = this, .batch_operation = batch_operation});
26912692

26922693
bthread_t tid;
2693-
bthread_attr_t attr = BTHREAD_ATTR_SMALL;
2694+
bthread_attr_t attr = BTHREAD_ATTR_NORMAL;
26942695
if (bthread_start_background(
26952696
&tid, &attr,
26962697
[](void* arg) -> void* {

src/mds/main.cc

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "mds/server.h"
3131

3232
DEFINE_string(conf, "./conf/mds.conf", "mds config path");
33-
DEFINE_string(coor_url, "file://./conf/coor_list", "coor service url, e.g. file://<path> or list://<addr1>");
33+
DEFINE_string(storage_url, "file://./conf/coor_list", "storage url, e.g. file://<path> or list://<addr1>");
3434

3535
const int kMaxStacktraceSize = 128;
3636

@@ -218,7 +218,7 @@ static std::vector<gflags::CommandLineFlagInfo> GetFlags(const std::string& pref
218218
gflags::CommandLineFlagInfo conf_flag;
219219
if (gflags::GetCommandLineFlagInfo("conf", &conf_flag)) dist_flags.push_back(conf_flag);
220220
gflags::CommandLineFlagInfo coor_url_flag;
221-
if (gflags::GetCommandLineFlagInfo("coor_url", &coor_url_flag)) dist_flags.push_back(coor_url_flag);
221+
if (gflags::GetCommandLineFlagInfo("storage_url", &coor_url_flag)) dist_flags.push_back(coor_url_flag);
222222

223223
std::vector<gflags::CommandLineFlagInfo> flags;
224224
gflags::GetAllFlags(&flags);
@@ -238,8 +238,8 @@ static std::string GetUsage(char* program_name) {
238238
oss << fmt::format("\t{} --help\n", program_name);
239239
oss << fmt::format("\t{} --mds_server_port=7801", program_name);
240240
oss << fmt::format("\t{} --conf=./conf/mds.conf", program_name);
241-
oss << fmt::format("\t{} --conf=./conf/mds.conf --coor_url=file://./conf/coor_list\n", program_name);
242-
oss << fmt::format("\t{} --conf=./conf/mds.conf --coor_url=list://127.0.0.1:22001\n", program_name);
241+
oss << fmt::format("\t{} --conf=./conf/mds.conf --storage_url=file://./conf/coor_list\n", program_name);
242+
oss << fmt::format("\t{} --conf=./conf/mds.conf --storage_url=list://127.0.0.1:22001\n", program_name);
243243
oss << fmt::format("\t{} [OPTIONS]\n", program_name);
244244

245245
auto flags = GetFlags("mds_");
@@ -287,20 +287,15 @@ static bool ParseOption(int argc, char** argv) {
287287
return false;
288288
}
289289

290-
static bool CheckCoorUrl(const std::string& coor_url) {
291-
if (coor_url.empty()) {
292-
std::cerr << "coor url is empty.\n";
290+
static bool CheckStorageUrl(const std::string& storage_url) {
291+
if (storage_url.empty()) {
292+
std::cerr << "storage url is empty.\n";
293293
return false;
294294
}
295295

296-
if (coor_url.substr(0, 7) != "file://" && coor_url.substr(0, 7) != "list://") {
297-
std::cerr << "coor url must start with file:// or list://\n";
298-
return false;
299-
}
300-
301-
auto coor_addr = dingofs::mds::Helper::ParseCoorAddr(coor_url);
302-
if (coor_addr.empty()) {
303-
std::cerr << "coor addr is invalid, please check your coor url: " << coor_url << '\n';
296+
auto storage_addr = dingofs::mds::Helper::ParseStorageAddr(storage_url);
297+
if (storage_addr.empty()) {
298+
std::cerr << "storage addr is invalid, please check your storage url: " << storage_url << '\n';
304299
return false;
305300
}
306301

@@ -324,7 +319,7 @@ int main(int argc, char* argv[]) {
324319

325320
gflags::ParseCommandLineNonHelpFlags(&argc, &argv, false);
326321

327-
if (!CheckCoorUrl(FLAGS_coor_url)) return -1;
322+
if (dingofs::mds::FLAGS_mds_storage_engine != "dummy" && !CheckStorageUrl(FLAGS_storage_url)) return -1;
328323

329324
SetupSignalHandler();
330325

@@ -334,8 +329,7 @@ int main(int argc, char* argv[]) {
334329
CHECK(server.InitConfig(FLAGS_conf)) << fmt::format("init config({}) error.", FLAGS_conf);
335330
CHECK(GeneratePidFile(server.GetPidFilePath())) << "generate pid file error.";
336331
CHECK(server.InitMDSMeta()) << "init mds meta error.";
337-
CHECK(server.InitCoordinatorClient(FLAGS_coor_url)) << "init coordinator client error.";
338-
CHECK(server.InitStorage(FLAGS_coor_url)) << "init storage error.";
332+
CHECK(server.InitStorage(FLAGS_storage_url)) << "init storage error.";
339333
CHECK(server.InitOperationProcessor()) << "init operation processor error.";
340334
CHECK(server.InitCacheGroupMemberManager()) << "init cache group member manager error.";
341335
CHECK(server.InitNotifyBuddy()) << "init notify buddy error.";

0 commit comments

Comments
 (0)