diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1204157..4b643dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,12 +9,31 @@ on: name: CI jobs: - build: - name: build + check: + name: check runs-on: ubuntu-latest + env: + CARGO_TARGET_DIR: "./build" steps: - - uses: actions/checkout@v2 - - name: Rust Cache - uses: Swatinem/rust-cache@v1.4.0 + - uses: actions/checkout@v3 + - name: cpp lint + uses: DoozyX/clang-format-lint-action@v0.16.2 + with: + source: '.' + extensions: 'cpp,h' + exclude: 'build' + style: Google + - name: rust cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + build/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: rust lint + run: cargo fmt -- --check && cargo clippy -- -D warnings && cargo check --all-targets --all-features - name: cmake build - run: cmake -S . -B build && cmake --build build + run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build diff --git a/Cargo.lock b/Cargo.lock index 21a2dfb..27b802f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,7 +51,7 @@ checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" dependencies = [ "async-stream-impl", "futures-core", - "pin-project-lite", + "pin-project-lite 0.2.10", ] [[package]] @@ -84,7 +84,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi 0.1.19", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -102,7 +102,7 @@ dependencies = [ "async-trait", "axum-core", "bitflags 1.3.2", - "bytes", + "bytes 1.4.0", "futures-util", "http", "http-body", @@ -112,7 +112,7 @@ dependencies = [ "memchr", "mime", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.10", "rustversion", "serde", "sync_wrapper", @@ -128,7 +128,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" dependencies = [ "async-trait", - "bytes", + "bytes 1.4.0", "futures-util", "http", "http-body", @@ -146,7 +146,7 @@ checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -183,6 +183,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + [[package]] name = "bytes" version = "1.4.0" @@ -195,6 +201,12 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -212,7 +224,7 @@ dependencies = [ "futures", "log", "tikv-client", - "tokio", + "tokio 1.29.1", ] [[package]] @@ -308,7 +320,19 @@ version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "enum-as-inner" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "570d109b813e904becc80d8d5da38376818a143348413f7149f1340fe04754d4" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -392,6 +416,22 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags 1.3.2", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + [[package]] name = "futures" version = "0.3.28" @@ -476,7 +516,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.10", "pin-utils", "slab", ] @@ -487,7 +527,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -498,7 +538,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.11.0+wasi-snapshot-preview1", ] @@ -515,7 +555,7 @@ version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" dependencies = [ - "bytes", + "bytes 1.4.0", "fnv", "futures-core", "futures-sink", @@ -523,7 +563,7 @@ dependencies = [ "http", "indexmap", "slab", - "tokio", + "tokio 1.29.1", "tokio-util", "tracing", ] @@ -534,6 +574,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -555,13 +601,24 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi 0.3.9", +] + [[package]] name = "http" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ - "bytes", + "bytes 1.4.0", "fnv", "itoa", ] @@ -572,9 +629,9 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes", + "bytes 1.4.0", "http", - "pin-project-lite", + "pin-project-lite 0.2.10", ] [[package]] @@ -601,7 +658,7 @@ version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ - "bytes", + "bytes 1.4.0", "futures-channel", "futures-core", "futures-util", @@ -611,9 +668,9 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project-lite", - "socket2", - "tokio", + "pin-project-lite 0.2.10", + "socket2 0.4.9", + "tokio 1.29.1", "tower-service", "tracing", "want", @@ -626,8 +683,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ "hyper", - "pin-project-lite", - "tokio", + "pin-project-lite 0.2.10", + "tokio 1.29.1", "tokio-io-timeout", ] @@ -637,13 +694,24 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes", + "bytes 1.4.0", "hyper", "native-tls", - "tokio", + "tokio 1.29.1", "tokio-native-tls", ] +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.4.0" @@ -675,6 +743,27 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "ipconfig" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" +dependencies = [ + "socket2 0.3.19", + "widestring", + "winapi 0.3.9", + "winreg 0.6.2", +] + [[package]] name = "ipnet" version = "2.8.0" @@ -705,6 +794,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -726,6 +825,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.1.4" @@ -754,6 +859,27 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + [[package]] name = "matchit" version = "0.7.0" @@ -781,6 +907,25 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", +] + [[package]] name = "mio" version = "0.8.8" @@ -792,6 +937,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + [[package]] name = "native-tls" version = "0.2.11" @@ -810,6 +967,17 @@ dependencies = [ "tempfile", ] +[[package]] +name = "net2" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b13b648036a2339d06de780866fbdfda0dde886de7b3af2ddeba8b14f4ee34ac" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -842,7 +1010,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" dependencies = [ "bitflags 1.3.2", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -895,7 +1063,7 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", @@ -928,6 +1096,12 @@ dependencies = [ "syn 2.0.27", ] +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + [[package]] name = "pin-project-lite" version = "0.2.10" @@ -980,7 +1154,7 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fnv", "lazy_static", "libc", @@ -998,7 +1172,7 @@ version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" dependencies = [ - "bytes", + "bytes 1.4.0", "prost-derive", ] @@ -1021,6 +1195,12 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.32" @@ -1146,7 +1326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" dependencies = [ "base64", - "bytes", + "bytes 1.4.0", "encoding_rs", "futures-core", "futures-util", @@ -1162,18 +1342,28 @@ dependencies = [ "native-tls", "once_cell", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.10", "serde", "serde_json", "serde_urlencoded", - "tokio", + "tokio 1.29.1", "tokio-native-tls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "winreg 0.10.1", +] + +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", ] [[package]] @@ -1188,7 +1378,7 @@ dependencies = [ "spin", "untrusted", "web-sys", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1391,6 +1581,17 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi 0.3.9", +] + [[package]] name = "socket2" version = "0.4.9" @@ -1398,7 +1599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1441,7 +1642,7 @@ version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "redox_syscall", "rustix 0.38.4", @@ -1480,7 +1681,7 @@ dependencies = [ [[package]] name = "tikv-client" version = "0.2.0" -source = "git+https://github.com/tikv/client-rust.git?rev=8b3ada28#8b3ada28ee3bf9fe02d5a5468ab236a7ad9bb1c0" +source = "git+https://github.com/smityz/client-rust.git?rev=1fe409b#1fe409b35e90448760225d933365ff47dd9eda54" dependencies = [ "async-recursion", "async-trait", @@ -1499,8 +1700,10 @@ dependencies = [ "serde", "serde_derive", "thiserror", - "tokio", + "tokio 1.29.1", "tonic", + "trust-dns-resolver", + "url", ] [[package]] @@ -1518,6 +1721,20 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +dependencies = [ + "bytes 0.5.6", + "iovec", + "lazy_static", + "mio 0.6.23", + "pin-project-lite 0.1.12", + "slab", +] + [[package]] name = "tokio" version = "1.29.1" @@ -1526,14 +1743,14 @@ checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", "backtrace", - "bytes", + "bytes 1.4.0", "libc", - "mio", + "mio 0.8.8", "num_cpus", "parking_lot", - "pin-project-lite", + "pin-project-lite 0.2.10", "signal-hook-registry", - "socket2", + "socket2 0.4.9", "tokio-macros", "windows-sys 0.48.0", ] @@ -1544,8 +1761,8 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" dependencies = [ - "pin-project-lite", - "tokio", + "pin-project-lite 0.2.10", + "tokio 1.29.1", ] [[package]] @@ -1566,7 +1783,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ "native-tls", - "tokio", + "tokio 1.29.1", ] [[package]] @@ -1576,7 +1793,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ "rustls", - "tokio", + "tokio 1.29.1", ] [[package]] @@ -1586,8 +1803,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", - "pin-project-lite", - "tokio", + "pin-project-lite 0.2.10", + "tokio 1.29.1", ] [[package]] @@ -1596,11 +1813,11 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ - "bytes", + "bytes 1.4.0", "futures-core", "futures-sink", - "pin-project-lite", - "tokio", + "pin-project-lite 0.2.10", + "tokio 1.29.1", "tracing", ] @@ -1614,7 +1831,7 @@ dependencies = [ "async-trait", "axum", "base64", - "bytes", + "bytes 1.4.0", "futures-core", "futures-util", "h2", @@ -1626,7 +1843,7 @@ dependencies = [ "pin-project", "prost", "rustls-pemfile", - "tokio", + "tokio 1.29.1", "tokio-rustls", "tokio-stream", "tower", @@ -1645,10 +1862,10 @@ dependencies = [ "futures-util", "indexmap", "pin-project", - "pin-project-lite", + "pin-project-lite 0.2.10", "rand 0.8.5", "slab", - "tokio", + "tokio 1.29.1", "tokio-util", "tower-layer", "tower-service", @@ -1673,8 +1890,8 @@ version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ - "cfg-if", - "pin-project-lite", + "cfg-if 1.0.0", + "pin-project-lite 0.2.10", "tracing-attributes", "tracing-core", ] @@ -1699,6 +1916,46 @@ dependencies = [ "once_cell", ] +[[package]] +name = "trust-dns-proto" +version = "0.19.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9" +dependencies = [ + "async-trait", + "backtrace", + "cfg-if 1.0.0", + "enum-as-inner", + "futures", + "idna 0.2.3", + "lazy_static", + "log", + "rand 0.7.3", + "smallvec", + "thiserror", + "tokio 0.2.25", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.19.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb" +dependencies = [ + "cfg-if 0.1.10", + "futures", + "ipconfig", + "lazy_static", + "log", + "lru-cache", + "resolv-conf", + "smallvec", + "thiserror", + "tokio 0.2.25", + "trust-dns-proto", +] + [[package]] name = "try-lock" version = "0.2.4" @@ -1745,7 +2002,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" dependencies = [ "form_urlencoded", - "idna", + "idna 0.4.0", "percent-encoding", ] @@ -1782,7 +2039,7 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -1807,7 +2064,7 @@ version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1852,6 +2109,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "widestring" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -1862,6 +2131,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1874,7 +2149,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2015,11 +2290,30 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winreg" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "winreg" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", ] diff --git a/Cargo.toml b/Cargo.toml index cc41da2..9dc85dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ futures = "0.3" log = "0.4" env_logger = "0.8" tokio = { version = "1.28.2", features = ["full"] } -tikv-client = { git = "https://github.com/tikv/client-rust.git", rev = "8b3ada28" } +tikv-client = { git = "https://github.com/smityz/client-rust.git", rev = "1fe409b" } [build-dependencies] cxx-build = "1.0.18" diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ba153da..15e93d0 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,11 +1,22 @@ -project(Example) cmake_minimum_required(VERSION 3.5) +project(Example) set (CMAKE_CXX_STANDARD 17) # using local repository -find_package(tikvcpp 0.1.0) +include(ExternalProject) +set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external) +ExternalProject_Add(tikv + SOURCE_DIR ${CMAKE_SOURCE_DIR}/../ + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} +) + +include_directories(${EXTERNAL_INSTALL_LOCATION}/include) +link_directories(${EXTERNAL_INSTALL_LOCATION}/lib) add_executable(raw raw.cpp) -target_link_libraries(raw tikvcpp tikvrust pthread dl ssl crypto) add_executable(txn txn.cpp) + +add_dependencies(raw tikv) +add_dependencies(txn tikv) +target_link_libraries(raw tikvcpp tikvrust pthread dl ssl crypto) target_link_libraries(txn tikvcpp tikvrust pthread dl ssl crypto) diff --git a/example/raw.cpp b/example/raw.cpp index db51b1a..7fa96d6 100644 --- a/example/raw.cpp +++ b/example/raw.cpp @@ -1,40 +1,42 @@ // Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. -#include #include +#include + int main() { - auto client = tikv_client::RawKVClient({"127.0.0.1:2379"}); - - const std::uint32_t kTimeoutMs = 10; - client.put("k1", "v1", kTimeoutMs); - - auto val = client.get("k1",kTimeoutMs); - if (val) { - std::cout << "get key: \n(k1:" << *val << ")" << std::endl; - } else { - std::cout << "key not found" << std::endl; - } - - client.batch_put({{"k2","v2"},{"k3","v3"},{"k4","v4"},{"k5","v5"}}, kTimeoutMs); - - const std::uint32_t kLimit = 20; - // scan [k1,k6), limit 20, timeout 10ms - auto kv_pairs = client.scan("k1","k6", kLimit ,kTimeoutMs); - std::cout<<"scan[\"k1\",\"k6\"):"<key << ": " << iter->value << ") "; - } - std::cout << std::endl; - - // delete [k3,k5), so [k1,k6) should be [k1,k3) + [k5,k6) - std::cout<<"scan[\"k1\",\"k6\") after delete:"<key << ": " << iter->value << ") "; - } - std::cout << std::endl; - - return 0; + auto client = tikv_client::RawKVClient({"127.0.0.1:2379"}); + + const std::uint32_t kTimeoutMs = 10; + client.put("k1", "v1", kTimeoutMs); + + auto val = client.get("k1", kTimeoutMs); + if (val) { + std::cout << "get key: \n(k1:" << *val << ")" << std::endl; + } else { + std::cout << "key not found" << std::endl; + } + + client.batch_put({{"k2", "v2"}, {"k3", "v3"}, {"k4", "v4"}, {"k5", "v5"}}, + kTimeoutMs); + + const std::uint32_t kLimit = 20; + // scan [k1,k6), limit 20, timeout 10ms + auto kv_pairs = client.scan("k1", "k6", kLimit, kTimeoutMs); + std::cout << "scan[\"k1\",\"k6\"):" << std::endl; + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + std::cout << "(" << iter->key << ": " << iter->value << ") "; + } + std::cout << std::endl; + + // delete [k3,k5), so [k1,k6) should be [k1,k3) + [k5,k6) + std::cout << "scan[\"k1\",\"k6\") after delete:" << std::endl; + client.remove_range("k3", "k5", kTimeoutMs); + kv_pairs = client.scan("k1", "k6", kLimit, kTimeoutMs); + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + std::cout << "(" << iter->key << ": " << iter->value << ") "; + } + std::cout << std::endl; + + return 0; } diff --git a/example/txn.cpp b/example/txn.cpp index eca8420..aed323a 100644 --- a/example/txn.cpp +++ b/example/txn.cpp @@ -1,27 +1,28 @@ // Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. -#include #include +#include + int main() { - auto client = tikv_client::TransactionClient({"127.0.0.1:2379"}); - auto txn = client.begin(); + auto client = tikv_client::TransactionClient({"127.0.0.1:2379"}); + auto txn = client.begin(); - txn.put("k1", "v2"); + txn.put("k1", "v2"); - auto val = txn.get("k1"); - if (val) { - std::cout << "get key k1:" << *val << std::endl; - } else { - std::cout << "key not found" << std::endl; - } + auto val = txn.get("k1"); + if (val) { + std::cout << "get key k1:" << *val << std::endl; + } else { + std::cout << "key not found" << std::endl; + } - auto kv_pairs = txn.scan("k1", Bound::Included, "", Bound::Unbounded, 10); - for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { - std::cout << "scan:" << iter->key << ": " << iter->value << std::endl; - } + auto kv_pairs = txn.scan("k1", Bound::Included, "", Bound::Unbounded, 10); + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + std::cout << "scan:" << iter->key << ": " << iter->value << std::endl; + } - txn.commit(); + txn.commit(); - return 0; + return 0; } diff --git a/include/tikv_client.h b/include/tikv_client.h index 7f52684..f9925d9 100644 --- a/include/tikv_client.h +++ b/include/tikv_client.h @@ -1,62 +1,78 @@ // Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. #ifndef _TIKV_CLIENT_H_ -#define _TIKV_CLIENT_H_ +#define _TIKV_CLIENT_H_ -#include "lib.rs.h" #include #include +#include "lib.rs.h" + namespace tikv_client { struct KvPair final { - std::string key; - std::string value; + std::string key; + std::string value; - KvPair(std::string &&key, std::string &&value); - ffi::KvPair to_ffi(); + KvPair(std::string &&key, std::string &&value); + ffi::KvPair to_ffi(); }; +config get_default_config(); + class Transaction { -public: - Transaction(::rust::cxxbridge1::Box txn); - std::optional get(const std::string &key); - std::optional get_for_update(const std::string &key); - std::vector batch_get(const std::vector &keys); - std::vector batch_get_for_update(const std::vector &keys); - std::vector scan(const std::string &start, Bound start_bound, const std::string &end, Bound end_bound, std::uint32_t limit); - std::vector scan_keys(const std::string &start, Bound start_bound, const std::string &end, Bound end_bound, std::uint32_t limit); - void put(const std::string &key, const std::string &value); - void batch_put(const std::vector &kvs); - void remove(const std::string &key); - void commit(); -private: - ::rust::cxxbridge1::Box _txn; + public: + Transaction(::rust::cxxbridge1::Box txn); + std::optional get(const std::string &key); + std::optional get_for_update(const std::string &key); + std::vector batch_get(const std::vector &keys); + std::vector batch_get_for_update( + const std::vector &keys); + std::vector scan(const std::string &start, Bound start_bound, + const std::string &end, Bound end_bound, + std::uint32_t limit); + std::vector scan_keys(const std::string &start, + Bound start_bound, const std::string &end, + Bound end_bound, std::uint32_t limit); + void put(const std::string &key, const std::string &value); + void batch_put(const std::vector &kvs); + void remove(const std::string &key); + void commit(); + + private: + ::rust::cxxbridge1::Box _txn; }; class TransactionClient { -public: - TransactionClient(const std::vector &pd_endpoints); - Transaction begin(); - Transaction begin_pessimistic(); -private: - ::rust::cxxbridge1::Box _client; + public: + TransactionClient(const std::vector &pd_endpoints); + Transaction begin(); + Transaction begin_pessimistic(); + + private: + ::rust::cxxbridge1::Box _client; }; class RawKVClient { -public: - RawKVClient(const std::vector &pd_endpoints); - std::optional get(const std::string &key,const std::uint64_t timeout); - void put(const std::string &key, const std::string &value, const std::uint64_t timeout); - void batch_put(const std::vector &kvs, const std::uint64_t timeout); - void remove(const std::string &key, const std::uint64_t timeout); - void remove_range(const std::string &start_key, const std::string &end_key, const std::uint64_t timeout); - std::vector scan(const std::string &startKey, const std::string &endKey, std::uint32_t limit, const std::uint64_t timeout); - -private: - ::rust::cxxbridge1::Box _client; + public: + RawKVClient(const std::vector &pd_endpoints); + RawKVClient(const std::vector &pd_endpoints, const config &conf); + std::optional get(const std::string &key, + const std::uint64_t timeout); + void put(const std::string &key, const std::string &value, + const std::uint64_t timeout); + void batch_put(const std::vector &kvs, const std::uint64_t timeout); + void remove(const std::string &key, const std::uint64_t timeout); + void remove_range(const std::string &start_key, const std::string &end_key, + const std::uint64_t timeout); + std::vector scan(const std::string &startKey, + const std::string &endKey, std::uint32_t limit, + const std::uint64_t timeout); + + private: + ::rust::cxxbridge1::Box _client; }; -} // namespace tikv_client +} // namespace tikv_client -#endif //_TIKV_CLIENT_H_ +#endif //_TIKV_CLIENT_H_ diff --git a/src/lib.rs b/src/lib.rs index 495c754..9fc7594 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ // Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. use core::panic; -use std::ops; +use std::{ops, path::PathBuf}; use anyhow::Result; use cxx::{CxxString, CxxVector}; @@ -36,6 +36,17 @@ mod ffi { Unbounded, } + struct config { + pub ca_path: String, + pub cert_path: String, + pub key_path: String, + pub timeout: u64, + pub tcp_keepalive: u64, + pub keep_alive_timeout: u64, + pub dns_server_addr: String, + pub dns_search_domain: Vec, + } + #[namespace = "tikv_client_glue"] extern "Rust" { type TransactionClient; @@ -44,6 +55,11 @@ mod ffi { fn raw_client_new(pd_endpoints: &CxxVector) -> Result>; + fn raw_client_config( + pd_endpoints: &CxxVector, + config: config, + ) -> Result>; + fn raw_get(client: &RawKVClient, key: &CxxString, timeout_ms: u64) -> Result; @@ -149,6 +165,28 @@ struct RawKVClient { struct Transaction { inner: tikv_client::Transaction, } +fn raw_client_config( + pd_endpoints: &CxxVector, + config: config, +) -> Result> { + env_logger::builder() + .filter_level(log::LevelFilter::Info) + .init(); + let runtime = Runtime::new().unwrap(); + + let pd_endpoints = pd_endpoints + .iter() + .map(|str| str.to_str().map(ToOwned::to_owned)) + .collect::, _>>()?; + + Ok(Box::new(RawKVClient { + inner: runtime.block_on(tikv_client::RawClient::new_with_config( + pd_endpoints, + config.into(), + ))?, + rt: runtime, + })) +} fn raw_client_new(pd_endpoints: &CxxVector) -> Result> { env_logger::builder() @@ -421,3 +459,76 @@ fn to_bound_range( }; tikv_client::BoundRange::from((start_bound, end_bound)) } + +impl From for tikv_client::Config { + fn from(config: config) -> Self { + let ca_path: Option; + let cert_path: Option; + let key_path: Option; + let timeout: Duration; + let tcp_keepalive: Option; + let keep_alive_timeout: Duration; + let dns_server_addr: Option; + let dns_search_domain: Vec; + let default_config = tikv_client::Config::default(); + + if config.ca_path.is_empty() { + ca_path = default_config.ca_path; + } else { + ca_path = Some(PathBuf::from(config.ca_path)); + } + + if config.cert_path.is_empty() { + cert_path = default_config.cert_path; + } else { + cert_path = Some(PathBuf::from(config.cert_path)); + } + + if config.key_path.is_empty() { + key_path = default_config.key_path; + } else { + key_path = Some(PathBuf::from(config.key_path)); + } + + if config.timeout == 0 { + timeout = default_config.timeout; + } else { + timeout = Duration::from_millis(config.timeout); + } + + if config.tcp_keepalive == 0 { + tcp_keepalive = default_config.tcp_keepalive; + } else { + tcp_keepalive = Some(Duration::from_millis(config.tcp_keepalive)); + } + + if config.keep_alive_timeout == 0 { + keep_alive_timeout = default_config.keep_alive_timeout; + } else { + keep_alive_timeout = Duration::from_millis(config.keep_alive_timeout); + } + + if config.dns_server_addr.is_empty() { + dns_server_addr = default_config.dns_server_addr; + } else { + dns_server_addr = Some(config.dns_server_addr); + } + + if config.dns_search_domain.is_empty() { + dns_search_domain = default_config.dns_search_domain; + } else { + dns_search_domain = config.dns_search_domain; + } + + tikv_client::Config { + ca_path, + cert_path, + key_path, + timeout, + tcp_keepalive, + keep_alive_timeout, + dns_server_addr, + dns_search_domain, + } + } +} diff --git a/src/tikv_client.cpp b/src/tikv_client.cpp index 4d4a49a..12d3e28 100644 --- a/src/tikv_client.cpp +++ b/src/tikv_client.cpp @@ -8,167 +8,195 @@ using ::rust::cxxbridge1::Box; namespace tikv_client { KvPair::KvPair(std::string &&key, std::string &&value) - : key(std::move(key)) - , value(std::move(value)) -{} + : key(std::move(key)), value(std::move(value)) {} ffi::KvPair KvPair::to_ffi() { - ffi::KvPair f_pair; - f_pair.key.reserve(key.size()); - for (const auto &c : this->key) { - f_pair.key.emplace_back(static_cast(c)); - } - f_pair.value.reserve(value.size()); - for (const auto &c : this->value) { - f_pair.value.emplace_back(static_cast(c)); - } - return f_pair; -} - -TransactionClient::TransactionClient(const std::vector &pd_endpoints): - _client(tikv_client_glue::transaction_client_new(pd_endpoints)) {} - -RawKVClient::RawKVClient(const std::vector &pd_endpoints): - _client(tikv_client_glue::raw_client_new(pd_endpoints)) {} - -std::optional RawKVClient::get(const std::string &key, const std::uint64_t timeout) { - auto val = tikv_client_glue::raw_get(*_client,key,timeout); - if (val.is_none) { - return std::nullopt; - } else { - return std::string{val.value.begin(), val.value.end()}; - } -} - -void RawKVClient::put(const std::string &key, const std::string &value, const std::uint64_t timeout) { - tikv_client_glue::raw_put(*_client,key,value,timeout); -} - -void RawKVClient::batch_put(const std::vector &kv_pairs, const std::uint64_t timeout) { - std::vector pairs; - pairs.reserve(kv_pairs.size()); - for (auto pair: kv_pairs) { - pairs.emplace_back(pair.to_ffi()); - } - tikv_client_glue::raw_batch_put(*_client,pairs,timeout); -} - -std::vector RawKVClient::scan(const std::string &startKey, const std::string &endKey, std::uint32_t limit, const std::uint64_t timeout){ - auto kv_pairs = tikv_client_glue::raw_scan(*_client,startKey,endKey,limit,timeout); - std::vector result; - result.reserve(kv_pairs.size()); - for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { - result.emplace_back( - std::string{(iter->key).begin(), (iter->key).end()}, - std::string{(iter->value).begin(), (iter->value).end()} - ); - } - return result; + ffi::KvPair f_pair; + f_pair.key.reserve(key.size()); + for (const auto &c : this->key) { + f_pair.key.emplace_back(static_cast(c)); + } + f_pair.value.reserve(value.size()); + for (const auto &c : this->value) { + f_pair.value.emplace_back(static_cast(c)); + } + return f_pair; +} + +config get_default_config() { + config conf; + conf.ca_path = ""; + conf.cert_path = ""; + conf.key_path = ""; + conf.timeout = 10000; + conf.tcp_keepalive = 10000; + conf.keep_alive_timeout = 3000; + conf.dns_server_addr = ""; + conf.dns_search_domain = rust::cxxbridge1::Vec(); + return conf; +} + +TransactionClient::TransactionClient( + const std::vector &pd_endpoints) + : _client(tikv_client_glue::transaction_client_new(pd_endpoints)) {} + +RawKVClient::RawKVClient(const std::vector &pd_endpoints) + : _client(tikv_client_glue::raw_client_new(pd_endpoints)) {} + +RawKVClient::RawKVClient(const std::vector &pd_endpoints, + const config &conf) + : _client(tikv_client_glue::raw_client_config(pd_endpoints, conf)) {} + +std::optional RawKVClient::get(const std::string &key, + const std::uint64_t timeout) { + auto val = tikv_client_glue::raw_get(*_client, key, timeout); + if (val.is_none) { + return std::nullopt; + } else { + return std::string{val.value.begin(), val.value.end()}; + } +} + +void RawKVClient::put(const std::string &key, const std::string &value, + const std::uint64_t timeout) { + tikv_client_glue::raw_put(*_client, key, value, timeout); +} + +void RawKVClient::batch_put(const std::vector &kv_pairs, + const std::uint64_t timeout) { + std::vector pairs; + pairs.reserve(kv_pairs.size()); + for (auto pair : kv_pairs) { + pairs.emplace_back(pair.to_ffi()); + } + tikv_client_glue::raw_batch_put(*_client, pairs, timeout); +} + +std::vector RawKVClient::scan(const std::string &startKey, + const std::string &endKey, + std::uint32_t limit, + const std::uint64_t timeout) { + auto kv_pairs = + tikv_client_glue::raw_scan(*_client, startKey, endKey, limit, timeout); + std::vector result; + result.reserve(kv_pairs.size()); + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + result.emplace_back( + std::string{(iter->key).begin(), (iter->key).end()}, + std::string{(iter->value).begin(), (iter->value).end()}); + } + return result; } void RawKVClient::remove(const std::string &key, const std::uint64_t timeout) { - tikv_client_glue::raw_delete(*_client,key,timeout); + tikv_client_glue::raw_delete(*_client, key, timeout); } -void RawKVClient::remove_range(const std::string &start_key,const std::string &end_key, const std::uint64_t timeout) { - tikv_client_glue::raw_delete_range(*_client,start_key,end_key,timeout); +void RawKVClient::remove_range(const std::string &start_key, + const std::string &end_key, + const std::uint64_t timeout) { + tikv_client_glue::raw_delete_range(*_client, start_key, end_key, timeout); } Transaction TransactionClient::begin() { - return Transaction(transaction_client_begin(*_client)); + return Transaction(transaction_client_begin(*_client)); } Transaction TransactionClient::begin_pessimistic() { - return Transaction(transaction_client_begin_pessimistic(*_client)); + return Transaction(transaction_client_begin_pessimistic(*_client)); } - -Transaction::Transaction(Box txn) : _txn(std::move(txn)) {} +Transaction::Transaction(Box txn) + : _txn(std::move(txn)) {} std::optional Transaction::get(const std::string &key) { - auto val = transaction_get(*_txn, key); - if (val.is_none) { - return std::nullopt; - } else { - return std::string{val.value.begin(), val.value.end()}; - } + auto val = transaction_get(*_txn, key); + if (val.is_none) { + return std::nullopt; + } else { + return std::string{val.value.begin(), val.value.end()}; + } } std::optional Transaction::get_for_update(const std::string &key) { - auto val = transaction_get_for_update(*_txn, key); - if (val.is_none) { - return std::nullopt; - } else { - return std::string{val.value.begin(), val.value.end()}; - } -} - -std::vector Transaction::batch_get(const std::vector &keys) { - auto kv_pairs = transaction_batch_get(*_txn, keys); - std::vector result; - result.reserve(kv_pairs.size()); - for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { - result.emplace_back( - std::string{(iter->key).begin(), (iter->key).end()}, - std::string{(iter->value).begin(), (iter->value).end()} - ); - } - return result; -} - -std::vector Transaction::batch_get_for_update(const std::vector &keys) { - auto kv_pairs = transaction_batch_get_for_update(*_txn, keys); - std::vector result; - result.reserve(kv_pairs.size()); - for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { - result.emplace_back( - std::string{(iter->key).begin(), (iter->key).end()}, - std::string{(iter->value).begin(), (iter->value).end()} - ); - } - return result; -} - - -std::vector Transaction::scan(const std::string &start, Bound start_bound, const std::string &end, Bound end_bound, std::uint32_t limit) { - auto kv_pairs = transaction_scan(*_txn, start, start_bound, end, end_bound, limit); - std::vector result; - result.reserve(kv_pairs.size()); - for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { - result.emplace_back( - std::string{(iter->key).begin(), (iter->key).end()}, - std::string{(iter->value).begin(), (iter->value).end()} - ); - } - return result; -} - -std::vector Transaction::scan_keys(const std::string &start, Bound start_bound, const std::string &end, Bound end_bound, std::uint32_t limit) { - auto keys = transaction_scan_keys(*_txn, start, start_bound, end, end_bound, limit); - std::vector result; - result.reserve(keys.size()); - for (auto iter = keys.begin(); iter != keys.end(); ++iter) { - result.emplace_back(std::string{(iter->key).begin(), (iter->key).end()}); - } - return result; + auto val = transaction_get_for_update(*_txn, key); + if (val.is_none) { + return std::nullopt; + } else { + return std::string{val.value.begin(), val.value.end()}; + } +} + +std::vector Transaction::batch_get( + const std::vector &keys) { + auto kv_pairs = transaction_batch_get(*_txn, keys); + std::vector result; + result.reserve(kv_pairs.size()); + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + result.emplace_back( + std::string{(iter->key).begin(), (iter->key).end()}, + std::string{(iter->value).begin(), (iter->value).end()}); + } + return result; +} + +std::vector Transaction::batch_get_for_update( + const std::vector &keys) { + auto kv_pairs = transaction_batch_get_for_update(*_txn, keys); + std::vector result; + result.reserve(kv_pairs.size()); + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + result.emplace_back( + std::string{(iter->key).begin(), (iter->key).end()}, + std::string{(iter->value).begin(), (iter->value).end()}); + } + return result; +} + +std::vector Transaction::scan(const std::string &start, + Bound start_bound, const std::string &end, + Bound end_bound, std::uint32_t limit) { + auto kv_pairs = + transaction_scan(*_txn, start, start_bound, end, end_bound, limit); + std::vector result; + result.reserve(kv_pairs.size()); + for (auto iter = kv_pairs.begin(); iter != kv_pairs.end(); ++iter) { + result.emplace_back( + std::string{(iter->key).begin(), (iter->key).end()}, + std::string{(iter->value).begin(), (iter->value).end()}); + } + return result; +} + +std::vector Transaction::scan_keys(const std::string &start, + Bound start_bound, + const std::string &end, + Bound end_bound, + std::uint32_t limit) { + auto keys = + transaction_scan_keys(*_txn, start, start_bound, end, end_bound, limit); + std::vector result; + result.reserve(keys.size()); + for (auto iter = keys.begin(); iter != keys.end(); ++iter) { + result.emplace_back(std::string{(iter->key).begin(), (iter->key).end()}); + } + return result; } void Transaction::put(const std::string &key, const std::string &value) { - transaction_put(*_txn, key, value); + transaction_put(*_txn, key, value); } void Transaction::batch_put(const std::vector &kvs) { - for (auto iter = kvs.begin(); iter != kvs.end(); ++iter) { - transaction_put(*_txn, iter->key, iter->value); - } + for (auto iter = kvs.begin(); iter != kvs.end(); ++iter) { + transaction_put(*_txn, iter->key, iter->value); + } } void Transaction::remove(const std::string &key) { - transaction_delete(*_txn, key); + transaction_delete(*_txn, key); } -void Transaction::commit() { - transaction_commit(*_txn); -} +void Transaction::commit() { transaction_commit(*_txn); } -} +} // namespace tikv_client