Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cloud data store #517

Merged
merged 34 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fa71c46
rocksdb-cloud: add submodule
de-sh Jun 23, 2020
fdb9942
initiate crate librocksdb_cloud_sys
de-sh Jun 25, 2020
1326e49
rocksdb-cloud: add code to build
de-sh Jul 9, 2020
05af468
rocksdb-cloud: move out CMakeLists.txt
de-sh Jul 10, 2020
b3f8422
CMake: update build process
de-sh Jul 10, 2020
06edfc4
Complete sub-crate addition librocksdb_sys/librocksdb_cloud_sys
de-sh Jul 21, 2020
43e4dc1
rocksdb-cloud: add to compilation
de-sh Jul 22, 2020
5119a1c
rocksdb-cloud: create extern for NewAWSEnv
de-sh Jul 22, 2020
06812f6
rocksdb-cloud: NewAWSEnv rust binding
de-sh Jul 22, 2020
0cd4c89
fmt: correct code formatting
de-sh Jul 22, 2020
abdd3e2
rocskdb-cloud: expose CloudEnvOptions
de-sh Jul 22, 2020
5afcd6f
rust-rocksdb: start writing interface in rust
de-sh Jul 22, 2020
18e75a7
rust-rocksdb: conditionally compile with cloud plugin
de-sh Jul 22, 2020
36dc1ec
TravisCI: add cloud to build in CI
de-sh Jul 23, 2020
1a078ce
rocksdb-cloud: update submod, correction of compile error
de-sh Jul 23, 2020
d8bbd7d
fmt: correct format
de-sh Jul 23, 2020
c3c56ac
expose Env::new_aws_env to call NewAWSEnv binding
de-sh Jul 23, 2020
efff2cf
cargo: include cloud as feature in crate settings
de-sh Jul 23, 2020
ed42f17
submodules update
de-sh Jul 23, 2020
0c4766b
rocksdb-cloud: rename link library to rocksdb_cloud
de-sh Jul 25, 2020
06a5e35
rocksdb-cloud: use fork tikv/rocksdb/6.4.cloud
de-sh Jul 25, 2020
0919d3d
rocksdb-cloud: restructure binding code, add test build with add aws sdk
de-sh Jul 25, 2020
0f33e1c
CI: Conditionally build AWS-CPP-SDK for cloud test only
de-sh Jul 28, 2020
8622093
CI: remove comments and outer os def
de-sh Jul 28, 2020
8de085e
*: add License note
de-sh Aug 1, 2020
a742516
rocksdb-cloud: refactor signature used with NewAwsEnv
de-sh Aug 1, 2020
5e9a51b
rocksdb: refactor test according to example, clang-fmt
de-sh Aug 1, 2020
b3bda19
rocksdb-cloud: update submod to v5.18.3+edits
de-sh Aug 1, 2020
65d8e95
crocksdb: use static_cast and solve test warn
de-sh Aug 2, 2020
7266339
make: add update_rocksdb_cloud sequence to Makefile
de-sh Aug 2, 2020
93f7d77
rocksdb/tikv: update submodule
de-sh Aug 3, 2020
87a4d2e
cmake: downgrade version of rocksdb used
de-sh Aug 3, 2020
5211b88
CI: cache /tmp/aws-sdk-cpp-x.x.x
de-sh Aug 4, 2020
38c489c
Merge branch 'master' into master
Aug 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
path = librocksdb_sys/rocksdb
url = https://github.com/tikv/rocksdb.git
branch = 6.4.tikv

[submodule "titan"]
path = librocksdb_sys/libtitan_sys/titan
url = https://github.com/tikv/titan.git
branch = master

[submodule "rocksdb-cloud"]
path = librocksdb_sys/librocksdb_cloud_sys/rocksdb-cloud
url = https://github.com/tikv/rocksdb
branch = 6.4.cloud
29 changes: 23 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
dist: bionic
language: rust

os:
- linux

rust:
- nightly

cache:
cargo: false
directories:
- "/tmp/aws-sdk-cpp-1.8.14"

addons:
apt:
sources:
Expand All @@ -19,6 +21,9 @@ jobs:
- os: linux
rust: nightly
env: FEATURES="encryption,jemalloc,portable,sse"
- os: linux
rust: nightly
env: FEATURES="cloud"
- os: linux
arch: arm64
rust: nightly
Expand All @@ -31,14 +36,26 @@ env:
global:
- RUST_BACKTRACE=1

cache: false

before_script:
# Installing the AWS-SDK, so increase the maximum number of open file descriptors,
# since some tests use more FDs than the default limit.
- if [ "${FEATURES}" == "cloud" ]; then
echo "limit maxfiles 1024 unlimited" | sudo tee -a /etc/launchd.conf;
pushd /tmp;
wget https://github.com/aws/aws-sdk-cpp/archive/1.8.14.tar.gz -O /tmp/aws-sdk.tar.gz;
tar -xvf /tmp/aws-sdk.tar.gz > /dev/null;
popd;
pushd /tmp/aws-sdk-cpp-1.8.14;
cmake -DBUILD_ONLY='kinesis;core;s3;transfer' -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_TESTING=OFF .;
make -j4 all;
sudo make install;
popd;
fi
- rustup component add rustfmt-preview
- rustup component add clippy

script:
# copile rocksdb may cost more than 10 minutes, see https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received
# compiling rocksdb may cost more than 10 minutes, see https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received
- if [ "${TASK}" == "clang-format" ]; then
bash ./travis-build/travis-format.sh;
else
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ portable = ["librocksdb_sys/portable"]
sse = ["librocksdb_sys/sse"]
static_libcpp = ["librocksdb_sys/static_libcpp"]
valgrind = []
# rocksdb-cloud integration
cloud = ["librocksdb_sys/cloud"]
de-sh marked this conversation as resolved.
Show resolved Hide resolved

[dependencies]
libc = "0.2.11"
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ update_rocksdb:
fi
@git submodule sync
@git submodule update --init --remote librocksdb_sys/rocksdb

update_rocksdb_cloud:
@if [ -n "${ROCKSDB_CLOUD_REPO}" ]; then \
git config --file=.gitmodules submodule.rocksdb-cloud.url https://github.com/${ROCKSDB_CLOUD_REPO}/rocksdb.git; \
fi
@if [ -n "${ROCKSDB_CLOUD_BRANCH}" ]; then \
git config --file=.gitmodules submodule.rocksdb-cloud.branch ${ROCKSDB_CLOUD_BRANCH}; \
fi
@git submodule sync
@git submodule update --init --remote librocksdb_sys/librocksdb_cloud_sys/rocksdb-cloud

2 changes: 2 additions & 0 deletions librocksdb_sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ links = "rocksdb"
[dependencies]
bzip2-sys = "0.1.8+1.0.8"
libc = "0.2.11"
librocksdb_cloud_sys = { path = "librocksdb_cloud_sys" }
de-sh marked this conversation as resolved.
Show resolved Hide resolved
libtitan_sys = { path = "libtitan_sys" }
libz-sys = { version = "1.0.25", features = ["static"] }
openssl-sys = { version = "0.9.54", optional = true, features = ["vendored"] }
Expand All @@ -25,6 +26,7 @@ jemalloc = ["tikv-jemalloc-sys"]
portable = ["libtitan_sys/portable"]
sse = ["libtitan_sys/sse"]
static_libcpp = []
cloud = []

[build-dependencies]
cc = "1.0.3"
Expand Down
14 changes: 14 additions & 0 deletions librocksdb_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ fn link_cpp(build: &mut Build) {
fn build_rocksdb() -> Build {
let target = env::var("TARGET").expect("TARGET was not set");
let mut cfg = Config::new("rocksdb");
// Conditionally compile with support for RocksDB-Cloud, setting USE_AWS
if cfg!(feature = "cloud") {
println!("cargo:rustc-link-lib=static=rocksdb_cloud");
}
if cfg!(feature = "encryption") {
cfg.register_dep("OPENSSL").define("WITH_OPENSSL", "ON");
println!("cargo:rustc-link-lib=static=crypto");
Expand Down Expand Up @@ -195,13 +199,23 @@ fn build_rocksdb() -> Build {
build.include(cur_dir.join("rocksdb"));
build.include(cur_dir.join("libtitan_sys").join("titan").join("include"));
build.include(cur_dir.join("libtitan_sys").join("titan"));
build.include(
cur_dir
.join("librocksdb_cloud_sys")
.join("rocksdb-cloud")
.join("include"),
);
build.include(cur_dir.join("librocksdb_cloud_sys").join("rocksdb-cloud"));

// Adding rocksdb specific compile macros.
// TODO: should make sure crocksdb compile options is the same as rocksdb and titan.
build.define("ROCKSDB_SUPPORT_THREAD_LOCAL", None);
if cfg!(feature = "encryption") {
build.define("OPENSSL", None);
}
if cfg!(feature = "cloud") {
build.define("USE_AWS", None).define("USE_CLOUD", None);
}

println!("cargo:rustc-link-lib=static=rocksdb");
println!("cargo:rustc-link-lib=static=titan");
Expand Down
49 changes: 49 additions & 0 deletions librocksdb_sys/crocksdb/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "db/column_family.h"
#include "rocksdb/cache.h"
#include "rocksdb/cloud/cloud_env_options.h"
#include "rocksdb/compaction_filter.h"
#include "rocksdb/comparator.h"
#include "rocksdb/convenience.h"
Expand Down Expand Up @@ -178,6 +179,9 @@ using rocksdb::titandb::TitanDBOptions;
using rocksdb::titandb::TitanOptions;
using rocksdb::titandb::TitanReadOptions;

using rocksdb::CloudEnv;
using rocksdb::CloudEnvOptions;

using rocksdb::MemoryAllocator;

#ifdef OPENSSL
Expand Down Expand Up @@ -5853,4 +5857,49 @@ void ctitandb_delete_files_in_ranges_cf(
SaveError(errptr, static_cast<TitanDB*>(db->rep)->DeleteFilesInRanges(
cf->rep, &ranges[0], num_ranges, include_end));
}

/* RocksDB Cloud */
#ifdef USE_CLOUD
struct crocksdb_cloud_envoptions_t {
CloudEnvOptions rep;
};

crocksdb_env_t* crocksdb_cloud_aws_env_create(
crocksdb_env_t* base_env, const char* src_cloud_bucket,
const char* src_cloud_object, const char* src_cloud_region,
const char* dest_cloud_bucket, const char* dest_cloud_object,
const char* dest_cloud_region, crocksdb_cloud_envoptions_t* cloud_options,
char** errptr) {
// Store a reference to a cloud env. A new cloud env object should be
// associated with every new cloud-db.
CloudEnv* cloud_env;

CloudEnv* cenv;
if (SaveError(errptr,
CloudEnv::NewAwsEnv(
base_env->rep, src_cloud_bucket, src_cloud_object,
src_cloud_region, dest_cloud_bucket, dest_cloud_object,
dest_cloud_region, cloud_options->rep, nullptr, &cenv))) {
assert(cenv != nullptr);
return nullptr;
}
de-sh marked this conversation as resolved.
Show resolved Hide resolved
cloud_env = cenv;

crocksdb_env_t* result = new crocksdb_env_t;
result->rep = static_cast<Env*>(cloud_env);
result->block_cipher = nullptr;
result->encryption_provider = nullptr;
result->is_default = true;
return result;
}

crocksdb_cloud_envoptions_t* crocksdb_cloud_envoptions_create() {
crocksdb_cloud_envoptions_t* opt = new crocksdb_cloud_envoptions_t;
return opt;
}

void crocksdb_cloud_envoptions_destroy(crocksdb_cloud_envoptions_t* opt) {
delete opt;
}
#endif
} // end extern "C"
16 changes: 16 additions & 0 deletions librocksdb_sys/crocksdb/crocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extern "C" {

/* Exported types */

typedef struct crocksdb_cloud_envoptions_t crocksdb_cloud_envoptions_t;
typedef struct crocksdb_t crocksdb_t;
typedef struct crocksdb_status_ptr_t crocksdb_status_ptr_t;
typedef struct crocksdb_backup_engine_t crocksdb_backup_engine_t;
Expand Down Expand Up @@ -2348,6 +2349,21 @@ extern C_ROCKSDB_LIBRARY_API void ctitandb_delete_files_in_ranges_cf(
const char* const* limit_keys, const size_t* limit_keys_lens,
size_t num_ranges, unsigned char include_end, char** errptr);

/* RocksDB Cloud */

#ifdef USE_CLOUD
extern C_ROCKSDB_LIBRARY_API crocksdb_env_t* crocksdb_cloud_aws_env_create(
crocksdb_env_t* base_env, const char* src_cloud_bucket,
const char* src_cloud_object, const char* src_cloud_region,
const char* dest_cloud_bucket, const char* dest_cloud_object,
const char* dest_cloud_region, crocksdb_cloud_envoptions_t* cloud_options,
char** errptr);
extern C_ROCKSDB_LIBRARY_API crocksdb_cloud_envoptions_t*
crocksdb_cloud_envoptions_create();
extern C_ROCKSDB_LIBRARY_API void crocksdb_cloud_envoptions_destroy(
crocksdb_cloud_envoptions_t* opt);
#endif

#ifdef __cplusplus
} /* end extern "C" */
#endif
Expand Down
60 changes: 60 additions & 0 deletions librocksdb_sys/librocksdb_cloud_sys/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
cmake_minimum_required(VERSION 3.0)
project(rocksdb_cloud)
enable_language(CXX)
enable_language(C)

# Manage absence of rocksdb code dependence

if (NOT ROCKSDB_GIT_REPO)
set(ROCKSDB_GIT_REPO "https://github.com/tikv/rocksdb.git")
endif()

if (NOT ROCKSDB_GIT_BRANCH)
set(ROCKSDB_GIT_BRANCH "6.4.tikv")
endif()

if (NOT DEFINED ROCKSDB_DIR)
if (GIT_FOUND)
if (WIN32)
execute_process(COMMAND $ENV{COMSPEC} /C ${GIT_EXECUTABLE} clone --branch=${ROCKSDB_GIT_BRANCH} ${ROCKSDB_GIT_REPO})
else()
execute_process(COMMAND ${GIT_EXECUTABLE} clone --branch=${ROCKSDB_GIT_BRANCH} ${ROCKSDB_GIT_REPO})
endif()
set(ROCKSDB_DIR "${CMAKE_BINARY_DIR}/rocksdb")
endif()
endif()

if (NOT DEFINED ROCKSDB_DIR)
message(FATAL_ERROR "ROCKSDB_DIR is not defined.")
endif()

# Append rocksdb modules
list(APPEND CMAKE_MODULE_PATH "${ROCKSDB_DIR}/cmake/modules/")
include("cmake_modules/rocksdb_flags.cmake")

include_directories("${ROCKSDB_DIR}")
include_directories("${ROCKSDB_DIR}/include")
include_directories("rocksdb-cloud")
include_directories("rocksdb-cloud/include")

file(GLOB SOURCES rocksdb-cloud/cloud/*.cc)

add_library(rocksdb_cloud STATIC ${SOURCES} $<TARGET_OBJECTS:cloud_env>)

option(WITH_CLOUD_TESTS "Build with tests." ON)

include_directories(SYSTEM ${ROCKSDB_DIR}/third-party/gtest-1.7.0/fused-src)

add_library(cloud_env OBJECT "rocksdb-cloud/cloud/cloud_env.cc")
de-sh marked this conversation as resolved.
Show resolved Hide resolved

include(GNUInstallDirs)
install(DIRECTORY include/rocksdb/cloud
COMPONENT devel
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(TARGETS rocksdb_cloud
COMPONENT devel
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
13 changes: 13 additions & 0 deletions librocksdb_sys/librocksdb_cloud_sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "librocksdb_cloud_sys"
version = "0.1.0"
edition = "2018"
build = "build.rs"
links = "rocksdb-cloud"

[features]
cloud = []

[build-dependencies]
cc = "1.0.3"
cmake = "0.1"
18 changes: 18 additions & 0 deletions librocksdb_sys/librocksdb_cloud_sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
extern crate cc;
extern crate cmake;

use std::env;

fn main() {
let cur_dir = env::current_dir().unwrap();
let mut cfg = cmake::Config::new(".");
let dst = cfg
.define("ROCKSDB_DIR", cur_dir.join("..").join("rocksdb"))
.env("USE_AWS", "1")
.build_target("rocksdb_cloud")
.very_verbose(true)
.build();
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=static=rocksdb_cloud");
}
Loading