Skip to content

Commit

Permalink
feat: support wiredtiger on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kabu1204 committed Feb 28, 2023
1 parent c2352d2 commit 775de50
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 68 deletions.
45 changes: 45 additions & 0 deletions BUILD_ON_WINDOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Prerequisite

1. You need to install Visual Studio Community first, for example VS2019.
2. [vcpkg](https://github.com/microsoft/vcpkg)
3. [CMake](https://cmake.org/download/)

# Building

The following steps are done in *Developer Powershell for VS 2019*(StartMenu - Visual Studio 2019 - Developer Powershell for VS 2019)

1. Install RocksDB
```powershell
cd <vcpkg_root>
.\vcpkg.exe install rocksdb[*]:x64-windows-static
```
This will automatically install dependent compression libraries(lz4, snappy, zstd, zlib), and build rocksdb with these libraries enabled.

`<vcpkg_root>` is the path where you've installed the vcpkg, `C:/src/vcpkg` for example.

2. Install WiredTiger

see [wiredtiger/README.md](wiredtiger/README.md)

3. Clone YCSB-cpp
```powershell
cd <somewhere>
git clone https://github.com/kabu1204/YCSB-cpp
cd YCSB-cpp
git submodule update --init
```
4. Build YCSB-cpp
```powershell
mkdir build
cd build
cmake -DBIND_ROCKSDB=1 -DWITH_SNAPPY=1 -DCMAKE_TOOLCHAIN_FILE=<vcpkg_root>/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static ..
msbuild ycsb-cpp.sln /p:Configuration=Release
```
`-DCMAKE_TOOLCHAIN_FILE=<vcpkg_root>/scripts/buildsystems/vcpkg.cmake` enables CMake `find_packege()` to find libraries
installed by vcpkg. You do not need to use backslash '\' in your path here.

`-DBIND_ROCKSDB=1` binds rocksdb.

`-DWITH_SNAPPY=1` tells CMake to link snappy with YCSB, same for `WITH_LZ4`, `WITH_ZLIB` and `WITH_ZSTD`.

The executable `ycsb.exe` can be found in `build/Release`.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ target_include_directories(ycsb PRIVATE ${PROJECT_SOURCE_DIR})

if (BIND_ROCKSDB)
message(STATUS "BIND_ROCKSDB - ON")
# rocksdb need zlib
set(WITH_ZLIB ON)
set(WITH_ZLIB ON) # rocksdb needs zlib
file(GLOB_RECURSE YCSB_ROCKSDB_SRC "rocksdb/*.cc")
target_sources(ycsb PRIVATE ${YCSB_ROCKSDB_SRC})
find_package(RocksDB CONFIG REQUIRED)
Expand All @@ -42,6 +41,18 @@ else()
message(STATUS "BIND_ROCKSDB - OFF")
endif()

if (BIND_WIREDTIGER)
message(STATUS "BIND_WIREDTIGER - ON")
file(GLOB_RECURSE YCSB_WT_SRC "wiredtiger/*.cc")
target_sources(ycsb PRIVATE ${YCSB_WT_SRC})
find_library(WIREDTIGER_LIB wiredtiger REQUIRED)
find_path(WIREDTIGER_INCLUDE_DIR "wiredtiger.h" REQUIRED)
target_link_libraries(ycsb PRIVATE ${WIREDTIGER_LIB})
target_include_directories(ycsb PRIVATE ${WIREDTIGER_INCLUDE_DIR})
else()
message(STATUS "BIND_WIREDTIGER - OFF")
endif ()

if(WITH_ZLIB)
message(STATUS "WITH_ZLIB - ON")
find_package(ZLIB REQUIRED)
Expand Down
63 changes: 4 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,9 @@ This is a fork of [YCSB-C](https://github.com/basicthinker/YCSB-C) with some add

This repo is forked from [ls4154/YCSB-cpp](https://github.com/ls4154/YCSB-cpp) to support WiredTiger.

# Build WiredTiger
# Build YCSB-cpp

Clone the source:
```
git clone git://github.com/wiredtiger/wiredtiger.git
mkdir -p wiredtiger/build
cd wiredtiger/build
```

Enable built-in compressors and build
```
cmake -DHAVE_BUILTIN_EXTENSION_LZ4=1 -DHAVE_BUILTIN_EXTENSION_SNAPPY=1 -DHAVE_BUILTIN_EXTENSION_ZLIB=1 -DHAVE_BUILTIN_EXTENSION_ZSTD=1 -DENABLE_STATIC=1 ../.
make -j$(nproc)
sudo make install
```

## Build YCSB-cpp

## Build with Makefile on GNU
## Build with Makefile on POSIX

Simply use `make` to build.

Expand Down Expand Up @@ -64,47 +48,8 @@ BIND_ROCKSDB ?= 1
```

## Build with CMake+vcpkg on Windows
### Prerequisite

1. You need to install Visual Studio Community first, for example VS2019.
2. [vcpkg](https://github.com/microsoft/vcpkg)
3. [CMake](https://cmake.org/download/)

### Building

The following steps are done in *Developer Powershell for VS 2019*(StartMenu - Visual Studio 2019 - Developer Powershell for VS 2019)

1. Install RocksDB
```powershell
cd <vcpkg_root>
.\vcpkg.exe install rocksdb[*]:x64-windows-static
```
This will automatically install dependent compression libraries(lz4, snappy, zstd, zlib), and build rocksdb with these libraries enabled.

`<vcpkg_root>` is the path where you've installed the vcpkg, `C:/src/vcpkg` for example.

2. Clone YCSB-cpp
```powershell
cd <somewhere>
git clone https://github.com/kabu1204/YCSB-cpp
cd YCSB-cpp
git submodule update --init
```
3. Build YCSB-cpp
```powershell
mkdir build
cd build
cmake -DBIND_ROCKSDB=1 -DWITH_SNAPPY=1 -DCMAKE_TOOLCHAIN_FILE=<vcpkg_root>/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static ..
msbuild ycsb-cpp.sln /p:Configuration=Release
```
`-DCMAKE_TOOLCHAIN_FILE=<vcpkg_root>/scripts/buildsystems/vcpkg.cmake` enables CMake `find_packege()` to find libraries
installed by vcpkg. You do not need to use backslash '\' in your path here.

`-DBIND_ROCKSDB=1` binds rocksdb.

`-DWITH_SNAPPY=1` tells CMake to link snappy with YCSB, same for `WITH_LZ4`, `WITH_ZLIB` and `WITH_ZSTD`.

The executable `ycsb.exe` can be found in `build/Release`.

see [BUILD_ON_WINDOWS](BUILD_ON_WINDOWS.md)

## Running

Expand Down
33 changes: 33 additions & 0 deletions wiredtiger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# WiredTiger

The code in `wiredtiger_db.cc` assumes your libwiredtiger to have built-in `<compressor>` that you specify in the
`wiredtiger.properties`.

For example, if you specify `wiredtiger.blk_mgr.compressor=snappy` in `wiredtiger.properties`, your libwiredtiger
should be built with `DHAVE_BUILTIN_EXTENSION_SNAPPY=1`.

## Install WiredTiger library on POSIX

Download and extract the source:
```
wget https://github.com/wiredtiger/wiredtiger/archive/refs/tags/11.1.0.tar.gz
tar xvzf 11.1.0.tar.gz
mkdir -p wiredtiger-11.1.0/build
cd wiredtiger-11.1.0/build
```

Enable built-in compressors and build
```
cmake -DHAVE_BUILTIN_EXTENSION_LZ4=1 -DHAVE_BUILTIN_EXTENSION_SNAPPY=1 -DHAVE_BUILTIN_EXTENSION_ZLIB=1 -DHAVE_BUILTIN_EXTENSION_ZSTD=1 -DENABLE_STATIC=1 ../.
make -j$(nproc)
sudo make install
```

## Install WiredTiger library on Windows with vcpkg

Build wiredtiger on Windows with built-in compressors is a little more complicated, we need to modify some source code of wiredtiger.

So I made a vcpkg port of wiredtiger, which simplifies the process.

1. install cmake/vcpkg on Windows
2. refer to the step 1-2 of [wiredtiger-vcpkg](https://github.com/kabu1204/wiredtiger-vcpkg) to install wiredtiger.lib.
2 changes: 1 addition & 1 deletion wiredtiger/wiredtiger.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wiredtiger.home=/tmp/ycsb-wiredtiger
wiredtiger.home=ycsb-wiredtiger
wiredtiger.format=single

# for detailed description, please see:
Expand Down
22 changes: 16 additions & 6 deletions wiredtiger/wiredtiger_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
} \
}

#if defined(_MSC_VER)
#if _MSC_VER >= 1911
#define MAYBE_UNUSED [[maybe_unused]]
#else
#define MAYBE_UNUSED
#endif
#elif defined(__GNUC__)
#define MAYBE_UNUSED __attribute__ ((unused))
#endif

namespace {
const std::string PROP_HOME = WT_PREFIX ".home";
const std::string PROP_HOME_DEFAULT = "";
Expand Down Expand Up @@ -206,7 +216,7 @@ void WTDB::Cleanup(){
DB::Status WTDB::ReadSingleEntry(const std::string &table, const std::string &key,
const std::vector<std::string> *fields,
std::vector<Field> &result) {
WT_ITEM k = {.data = key.data(), .size = key.size()};
WT_ITEM k = {key.data(), key.size()};
WT_ITEM v;
int ret;
cursor_->set_key(cursor_, &k);
Expand All @@ -228,7 +238,7 @@ DB::Status WTDB::ReadSingleEntry(const std::string &table, const std::string &ke
DB::Status WTDB::ScanSingleEntry(const std::string &table, const std::string &key, int len,
const std::vector<std::string> *fields,
std::vector<std::vector<Field>> &result) {
WT_ITEM k = {.data = key.data(), .size = key.size()};
WT_ITEM k = {key.data(), key.size()};
WT_ITEM v;
int ret = 0, exact;

Expand All @@ -252,7 +262,7 @@ DB::Status WTDB::ScanSingleEntry(const std::string &table, const std::string &ke
DB::Status WTDB::UpdateSingleEntry(const std::string &table, const std::string &key,
std::vector<Field> &values){
std::vector<Field> current_values;
WT_ITEM k = {.data = key.data(), .size = key.size()};
WT_ITEM k = {key.data(), key.size()};
WT_ITEM v;
int ret;

Expand All @@ -266,7 +276,7 @@ DB::Status WTDB::UpdateSingleEntry(const std::string &table, const std::string &
error_check(cursor_->get_value(cursor_, &v));
DeserializeRow(&current_values, (const char*)v.data, v.size);
for (Field &new_field : values) {
bool found __attribute__((unused)) = false;
bool found MAYBE_UNUSED = false;
for (Field &cur_field : current_values) {
if (cur_field.name == new_field.name) {
found = true;
Expand Down Expand Up @@ -294,7 +304,7 @@ DB::Status WTDB::UpdateSingleEntry(const std::string &table, const std::string &
DB::Status WTDB::InsertSingleEntry(const std::string &table, const std::string &key,
std::vector<Field> &values){
std::string data;
WT_ITEM k = {.data = key.data(), .size = key.size()}, v;
WT_ITEM k = {key.data(), key.size()}, v;

cursor_->set_key(cursor_, &k);
SerializeRow(values, &data);
Expand All @@ -306,7 +316,7 @@ DB::Status WTDB::InsertSingleEntry(const std::string &table, const std::string &
return kOK;
}
DB::Status WTDB::DeleteSingleEntry(const std::string &table, const std::string &key){
WT_ITEM k = {.data = key.data(), .size = key.size()};
WT_ITEM k = {key.data(), key.size()};
cursor_->set_key(cursor_, &k);
error_check(cursor_->remove(cursor_));
return kOK;
Expand Down

0 comments on commit 775de50

Please sign in to comment.