Skip to content

Commit 18c35a7

Browse files
Eyizoha蚂蚁代码服务
authored andcommitted
PullRequest: 1 feat(zdfs): 新增zdfs文件系统支持
Merge branch 'yzh-dfs of git@code.alipay.com:antflink/paimon-cpp.git into main https://code.alipay.com/antflink/paimon-cpp/pull_requests/1 Reviewed-by: 量子 <zhangchaoming.zcm@antgroup.com>
2 parents 9810a14 + cee0137 commit 18c35a7

15 files changed

Lines changed: 876 additions & 0 deletions

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ option(PAIMON_ENABLE_AVRO "Whether to enable avro file format" ON)
5252
option(PAIMON_ENABLE_ORC "Whether to enable orc file format" ON)
5353
option(PAIMON_ENABLE_LANCE "Whether to enable lance file format" OFF)
5454
option(PAIMON_ENABLE_JINDO "Whether to enable jindo file system" OFF)
55+
option(PAIMON_ENABLE_ZDFS "Whether to enable zdfs file system" OFF)
5556
option(PAIMON_ENABLE_LUMINA "Whether to enable lumina vector index" ON)
5657
option(PAIMON_ENABLE_LUCENE "Whether to enable lucene index" ON)
5758

@@ -64,6 +65,12 @@ endif()
6465
if(PAIMON_ENABLE_JINDO)
6566
add_definitions(-DPAIMON_ENABLE_JINDO)
6667
endif()
68+
if(PAIMON_ENABLE_ZDFS)
69+
if(PAIMON_USE_CXX11_ABI)
70+
message(FATAL_ERROR "ZDFS cannot be enabled with C++11 ABI on")
71+
endif()
72+
add_definitions(-DPAIMON_ENABLE_ZDFS)
73+
endif()
6774
if(PAIMON_USE_CXX11_ABI)
6875
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
6976
else()
@@ -395,6 +402,11 @@ if(PAIMON_BUILD_TESTS)
395402
list(APPEND TEST_STATIC_LINK_LIBS paimon_jindo_file_system_shared)
396403
list(APPEND TEST_STATIC_LINK_LIBS "-Wl,--as-needed")
397404
endif()
405+
if(PAIMON_ENABLE_ZDFS)
406+
list(APPEND TEST_STATIC_LINK_LIBS "-Wl,--no-as-needed")
407+
list(APPEND TEST_STATIC_LINK_LIBS paimon_zdfs_file_system_shared)
408+
list(APPEND TEST_STATIC_LINK_LIBS "-Wl,--as-needed")
409+
endif()
398410
if(PAIMON_ENABLE_LUMINA)
399411
list(APPEND TEST_STATIC_LINK_LIBS "-Wl,--no-as-needed")
400412
list(APPEND TEST_STATIC_LINK_LIBS paimon_lumina_index_shared)
@@ -426,6 +438,7 @@ config_summary_message()
426438
add_subdirectory(src/paimon)
427439
add_subdirectory(src/paimon/fs/local)
428440
add_subdirectory(src/paimon/fs/jindo)
441+
add_subdirectory(src/paimon/fs/zdfs)
429442
add_subdirectory(src/paimon/format/blob)
430443
add_subdirectory(src/paimon/format/orc)
431444
add_subdirectory(src/paimon/format/parquet)

PaimonConfig.cmake.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ set_target_properties(paimon_jindo_file_system_static PROPERTIES
120120
INTERFACE_INCLUDE_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/include"
121121
)
122122

123+
# paimon_zdfs_file_system
124+
add_library(paimon_zdfs_file_system_shared SHARED IMPORTED)
125+
set_target_properties(paimon_zdfs_file_system_shared PROPERTIES
126+
IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libpaimon_zdfs_file_system.so"
127+
INTERFACE_INCLUDE_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/include"
128+
)
129+
add_library(paimon_zdfs_file_system_static STATIC IMPORTED)
130+
set_target_properties(paimon_zdfs_file_system_static PROPERTIES
131+
IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libpaimon_zdfs_file_system.a"
132+
INTERFACE_INCLUDE_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/include"
133+
)
134+
123135
# paimon_lance_file_format
124136
add_library(paimon_lance_file_format_shared SHARED IMPORTED)
125137
set_target_properties(paimon_lance_file_format_shared PROPERTIES

cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ else()
160160
endif()
161161
endif()
162162

163+
if(DEFINED ENV{PAIMON_GFLAGS_URL})
164+
set(GFLAGS_SOURCE_URL "$ENV{PAIMON_GFLAGS_URL}")
165+
else()
166+
if(EXISTS "${THIRDPARTY_DIR}/${PAIMON_GFLAGS_PKG_NAME}")
167+
set_urls(GFLAGS_SOURCE_URL "${THIRDPARTY_DIR}/${PAIMON_GFLAGS_PKG_NAME}")
168+
else()
169+
set_urls(GFLAGS_SOURCE_URL
170+
"${THIRDPARTY_MIRROR_URL}https://github.com/gflags/gflags/archive/refs/tags/${PAIMON_GFLAGS_BUILD_VERSION}.tar.gz"
171+
)
172+
endif()
173+
endif()
174+
163175
if(DEFINED ENV{PAIMON_ZLIB_URL})
164176
set(ZLIB_SOURCE_URL "$ENV{PAIMON_ZLIB_URL}")
165177
else()
@@ -280,6 +292,18 @@ else()
280292
endif()
281293
endif()
282294

295+
if(DEFINED ENV{PAIMON_ZDFS_URL})
296+
set(ZDFS_SOURCE_URL "$ENV{PAIMON_ZDFS_URL}")
297+
else()
298+
if(EXISTS "${THIRDPARTY_DIR}/${PAIMON_ZDFS_PKG_NAME}")
299+
set_urls(ZDFS_SOURCE_URL "${THIRDPARTY_DIR}/${PAIMON_ZDFS_PKG_NAME}")
300+
else()
301+
set_urls(ZDFS_SOURCE_URL
302+
"http://beiming.alibaba-inc.com/beiming/services/zdfs/${PAIMON_ZDFS_BUILD_VERSION}/apps/zdfs-dfs-lib"
303+
)
304+
endif()
305+
endif()
306+
283307
set(EP_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
284308
set(EP_C_FLAGS "${CMAKE_C_FLAGS}")
285309
string(REPLACE "-Wglobal-constructors" "" EP_CXX_FLAGS ${EP_CXX_FLAGS})
@@ -800,6 +824,50 @@ macro(build_jindosdk_nextarch)
800824
add_dependencies(jindosdk::nextarch jindosdk-nextarch_ep)
801825
endmacro()
802826

827+
macro(build_zdfs)
828+
message(STATUS "Building zdfs from precompiled package")
829+
830+
set(ZDFS_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/zdfs_ep-install")
831+
set(ZDFS_HOME "${ZDFS_PREFIX}")
832+
set(ZDFS_INCLUDE_DIR "${ZDFS_PREFIX}/include")
833+
set(ZDFS_LIB_DIR "${ZDFS_PREFIX}/lib")
834+
set(ZDFS_STATIC_LIB "${ZDFS_LIB_DIR}/libzdfs.a")
835+
set(ZDFS_DYNAMIC_LIB "${ZDFS_LIB_DIR}/libzdfs.so")
836+
837+
# Extract and install zdfs from precompiled package
838+
externalproject_add(zdfs_ep
839+
URL ${ZDFS_SOURCE_URL}
840+
URL_HASH "SHA256=${PAIMON_ZDFS_BUILD_SHA256_CHECKSUM}"
841+
${THIRDPARTY_LOG_OPTIONS}
842+
CONFIGURE_COMMAND ""
843+
BUILD_COMMAND ""
844+
INSTALL_COMMAND bash -c
845+
"cp -r <SOURCE_DIR>/include/* ${ZDFS_INCLUDE_DIR}"
846+
COMMAND bash -c "cp -r <SOURCE_DIR>/lib/libzdfs.* ${ZDFS_LIB_DIR}"
847+
BUILD_BYPRODUCTS "${ZDFS_STATIC_LIB}" "${ZDFS_DYNAMIC_LIB}")
848+
849+
# The include directory must exist before it is referenced by a target.
850+
file(MAKE_DIRECTORY "${ZDFS_INCLUDE_DIR}")
851+
file(MAKE_DIRECTORY "${ZDFS_LIB_DIR}")
852+
853+
add_library(zdfs::sdk_static STATIC IMPORTED)
854+
set_target_properties(zdfs::sdk_static
855+
PROPERTIES IMPORTED_LOCATION "${ZDFS_STATIC_LIB}"
856+
INTERFACE_INCLUDE_DIRECTORIES "${ZDFS_INCLUDE_DIR}")
857+
add_dependencies(zdfs::sdk_static zdfs_ep)
858+
859+
add_library(zdfs::sdk_shared SHARED IMPORTED)
860+
set_target_properties(zdfs::sdk_shared
861+
PROPERTIES IMPORTED_LOCATION "${ZDFS_DYNAMIC_LIB}"
862+
INTERFACE_INCLUDE_DIRECTORIES "${ZDFS_INCLUDE_DIR}")
863+
add_dependencies(zdfs::sdk_shared zdfs_ep)
864+
865+
install(DIRECTORY "${ZDFS_LIB_DIR}/"
866+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
867+
FILES_MATCHING
868+
PATTERN "libzdfs.*")
869+
endmacro()
870+
803871
macro(build_protobuf)
804872
message(STATUS "Building protobuf from source")
805873
set(PROTOBUF_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/protobuf_ep-install")
@@ -1339,6 +1407,44 @@ macro(build_glog)
13391407
endif()
13401408
endmacro()
13411409

1410+
macro(build_gflags)
1411+
message(STATUS "Building gflags from source")
1412+
set(GFLAGS_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/gflags_ep-install")
1413+
set(GFLAGS_INCLUDE_DIR "${GFLAGS_PREFIX}/include")
1414+
if(${UPPERCASE_BUILD_TYPE} STREQUAL "DEBUG")
1415+
set(GLOG_LIB_SUFFIX "_debug")
1416+
else()
1417+
set(GLOG_LIB_SUFFIX "")
1418+
endif()
1419+
set(GFLAGS_STATIC_LIB "${GFLAGS_PREFIX}/lib/libgflags${GLOG_LIB_SUFFIX}.a")
1420+
set(GFLAGS_CMAKE_CXX_FLAGS " -Wno-error ${EP_CXX_FLAGS}")
1421+
set(GFLAGS_CMAKE_C_FLAGS " -Wno-error ${EP_C_FLAGS}")
1422+
1423+
set(GFLAGS_CMAKE_ARGS
1424+
${EP_COMMON_CMAKE_ARGS}
1425+
-DCMAKE_INSTALL_PREFIX=${GFLAGS_PREFIX}
1426+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
1427+
-DGFLAGS_NAMESPACE=gflags
1428+
-DCMAKE_CXX_FLAGS=${GFLAGS_CMAKE_CXX_FLAGS}
1429+
-DCMAKE_C_FLAGS=${GFLAGS_CMAKE_C_FLAGS})
1430+
1431+
externalproject_add(gflags_ep
1432+
URL ${GFLAGS_SOURCE_URL}
1433+
URL_HASH "SHA256=${PAIMON_GFLAGS_BUILD_SHA256_CHECKSUM}"
1434+
CMAKE_ARGS ${GFLAGS_CMAKE_ARGS}
1435+
BUILD_BYPRODUCTS "${GFLAGS_STATIC_LIB}")
1436+
1437+
file(MAKE_DIRECTORY "${GFLAGS_INCLUDE_DIR}")
1438+
add_library(gflags::gflags STATIC IMPORTED)
1439+
set_target_properties(gflags::gflags
1440+
PROPERTIES IMPORTED_LOCATION "${GFLAGS_STATIC_LIB}"
1441+
INTERFACE_INCLUDE_DIRECTORIES "${GFLAGS_INCLUDE_DIR}"
1442+
INTERFACE_LINK_DIRECTORIES "${GFLAGS_BUILD_DIR}/lib"
1443+
INTERFACE_COMPILE_DEFINITIONS "GFLAGS_USE_GFLAGS_EXPORT")
1444+
1445+
add_dependencies(gflags::gflags gflags_ep)
1446+
endmacro()
1447+
13421448
build_fmt()
13431449
build_rapidjson()
13441450
build_snappy()
@@ -1360,6 +1466,10 @@ if(PAIMON_ENABLE_JINDO)
13601466
build_jindosdk_c()
13611467
build_jindosdk_nextarch()
13621468
endif()
1469+
if(PAIMON_ENABLE_ZDFS)
1470+
build_gflags()
1471+
build_zdfs()
1472+
endif()
13631473
if(PAIMON_ENABLE_LUCENE)
13641474
build_boost()
13651475
build_lucene()

docs/source/build_system.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Paimon provides a set of built-in optional plugins that you can link to as neede
8585

8686
- ``paimon_local_file_system_shared`` / ``paimon_local_file_system_static``
8787
- ``paimon_jindo_file_system_shared`` / ``paimon_jindo_file_system_static``
88+
- ``paimon_zdfs_file_system_shared`` / ``paimon_zdfs_file_system_static``
8889

8990
- Index plugins:
9091

src/paimon/fs/zdfs/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
option(PAIMON_ZDFS_USE_SHARED_SDK "Use shared zdfs sdk" OFF)
2+
3+
if(PAIMON_ENABLE_ZDFS)
4+
if(PAIMON_ZDFS_USE_SHARED_SDK)
5+
set(zdfs_sdk_to_link "zdfs::sdk_shared")
6+
set(zdfs_sdk_static_link "")
7+
set(zdfs_sdk_shared_link "zdfs::sdk_shared")
8+
else()
9+
find_package(OpenSSL REQUIRED)
10+
set(zdfs_sdk_to_link "zdfs::sdk_static" "OpenSSL::SSL" "OpenSSL::Crypto" "gflags::gflags")
11+
set(zdfs_sdk_static_link "zdfs::sdk_static" "gflags::gflags")
12+
set(zdfs_sdk_shared_link "OpenSSL::SSL" "OpenSSL::Crypto")
13+
endif()
14+
15+
set(PAIMON_ZDFS_FILE_SYSTEM zdfs_file_status.cpp zdfs_file_system.cpp
16+
zdfs_file_system_factory.cpp zdfs_stream.cpp)
17+
18+
add_paimon_lib(paimon_zdfs_file_system
19+
SOURCES
20+
${PAIMON_ZDFS_FILE_SYSTEM}
21+
EXTRA_INCLUDES
22+
${ZDFS_INCLUDE_DIR}
23+
DEPENDENCIES
24+
paimon_shared
25+
${zdfs_sdk_to_link}
26+
STATIC_LINK_LIBS
27+
${zdfs_sdk_static_link}
28+
SHARED_LINK_LIBS
29+
paimon_shared
30+
${zdfs_sdk_shared_link}
31+
SHARED_LINK_FLAGS
32+
${PAIMON_VERSION_SCRIPT_FLAGS})
33+
endif()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Created by haohao.yzh on 2026/1/6.
3+
//
4+
5+
#include "zdfs_file_status.h"
6+
7+
namespace paimon {
8+
static std::string concatPath(const std::string &dir, const std::string &path) {
9+
if (dir.empty()) {
10+
return path;
11+
}
12+
if (dir.back() == '/') {
13+
return dir + path;
14+
}
15+
return dir + "/" + path;
16+
}
17+
18+
std::unique_ptr<ZdfsBasicFileStatus> ZdfsBasicFileStatus::Create(std::string path,
19+
const zdfs::EntryStat &entry_stat) {
20+
return std::make_unique<ZdfsBasicFileStatus>(entry_stat.IsDir(), std::move(path));
21+
}
22+
23+
std::unique_ptr<ZdfsBasicFileStatus> ZdfsBasicFileStatus::CreateSubfile(
24+
const std::string &dir, const zdfs::EntryStat &entry_stat) {
25+
return Create(concatPath(dir, entry_stat.path), entry_stat);
26+
}
27+
28+
std::unique_ptr<ZdfsFileStatus> ZdfsFileStatus::Create(std::string path,
29+
const zdfs::EntryStat &entry_stat) {
30+
if (entry_stat.IsDir()) {
31+
const zdfs::DirStat &dirStat = entry_stat.dir;
32+
return std::make_unique<ZdfsFileStatus>(true, std::move(path), dirStat.length,
33+
dirStat.modify_time);
34+
} else {
35+
const zdfs::FileStat &fileStat = entry_stat.file;
36+
return std::make_unique<ZdfsFileStatus>(false, std::move(path), fileStat.length,
37+
fileStat.modify_time);
38+
}
39+
}
40+
41+
std::unique_ptr<ZdfsFileStatus> ZdfsFileStatus::CreateSubfile(const std::string &dir,
42+
const zdfs::EntryStat &entry_stat) {
43+
return Create(concatPath(dir, entry_stat.path), entry_stat);
44+
}
45+
46+
} // namespace paimon
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Created by haohao.yzh on 2026/1/6.
3+
//
4+
5+
#pragma once
6+
7+
#include <paimon/fs/file_system.h>
8+
#include <zdfs/zdfs.h>
9+
10+
#include <utility>
11+
12+
namespace paimon {
13+
class ZdfsBasicFileStatus : public BasicFileStatus {
14+
public:
15+
static std::unique_ptr<ZdfsBasicFileStatus> Create(std::string path,
16+
const zdfs::EntryStat &entry_stat);
17+
static std::unique_ptr<ZdfsBasicFileStatus> CreateSubfile(const std::string &dir,
18+
const zdfs::EntryStat &entry_stat);
19+
20+
ZdfsBasicFileStatus(bool is_dir, std::string path) : is_dir_(is_dir), path_(std::move(path)) {}
21+
22+
bool IsDir() const override {
23+
return is_dir_;
24+
}
25+
26+
std::string GetPath() const override {
27+
return path_;
28+
}
29+
30+
private:
31+
const bool is_dir_;
32+
const std::string path_;
33+
};
34+
35+
class ZdfsFileStatus : public FileStatus {
36+
public:
37+
static std::unique_ptr<ZdfsFileStatus> Create(std::string path,
38+
const zdfs::EntryStat &entry_stat);
39+
static std::unique_ptr<ZdfsFileStatus> CreateSubfile(const std::string &dir,
40+
const zdfs::EntryStat &entry_stat);
41+
42+
ZdfsFileStatus(bool is_dir, std::string path, int64_t modification_time, uint64_t len)
43+
: is_dir_(is_dir), path_(std::move(path)),
44+
modification_time_(modification_time), len_(len) {}
45+
46+
uint64_t GetLen() const override {
47+
return len_;
48+
}
49+
50+
bool IsDir() const override {
51+
return is_dir_;
52+
}
53+
54+
std::string GetPath() const override {
55+
return path_;
56+
}
57+
58+
int64_t GetModificationTime() const override {
59+
return modification_time_;
60+
}
61+
62+
private:
63+
const bool is_dir_;
64+
const std::string path_;
65+
const int64_t modification_time_;
66+
const uint64_t len_;
67+
};
68+
69+
} // namespace paimon

0 commit comments

Comments
 (0)