Giter VIP home page Giter VIP logo

client-c's Introduction

tikv_logo

Build Status Coverage Status CII Best Practices

TiKV is an open-source, distributed, and transactional key-value database. Unlike other traditional NoSQL systems, TiKV not only provides classical key-value APIs, but also transactional APIs with ACID compliance. Built in Rust and powered by Raft, TiKV was originally created by PingCAP to complement TiDB, a distributed HTAP database compatible with the MySQL protocol.

The design of TiKV ('Ti' stands for titanium) is inspired by some great distributed systems from Google, such as BigTable, Spanner, and Percolator, and some of the latest achievements in academia in recent years, such as the Raft consensus algorithm.

If you're interested in contributing to TiKV, or want to build it from source, see CONTRIBUTING.md.

cncf_logo cncf_logo

TiKV is a graduated project of the Cloud Native Computing Foundation (CNCF). If you are an organization that wants to help shape the evolution of technologies that are container-packaged, dynamically-scheduled and microservices-oriented, consider joining the CNCF. For details about who's involved and how TiKV plays a role, read the CNCF announcement.


With the implementation of the Raft consensus algorithm in Rust and consensus state stored in RocksDB, TiKV guarantees data consistency. Placement Driver (PD), which is introduced to implement auto-sharding, enables automatic data migration. The transaction model is similar to Google's Percolator with some performance improvements. TiKV also provides snapshot isolation (SI), snapshot isolation with lock (SQL: SELECT ... FOR UPDATE), and externally consistent reads and writes in distributed transactions.

TiKV has the following key features:

  • Geo-Replication

    TiKV uses Raft and the Placement Driver to support Geo-Replication.

  • Horizontal scalability

    With PD and carefully designed Raft groups, TiKV excels in horizontal scalability and can easily scale to 100+ TBs of data.

  • Consistent distributed transactions

    Similar to Google's Spanner, TiKV supports externally-consistent distributed transactions.

  • Coprocessor support

    Similar to HBase, TiKV implements a coprocessor framework to support distributed computing.

  • Cooperates with TiDB

    Thanks to the internal optimization, TiKV and TiDB can work together to be a compelling database solution with high horizontal scalability, externally-consistent transactions, support for RDBMS, and NoSQL design patterns.

Governance

See Governance.

Documentation

For instructions on deployment, configuration, and maintenance of TiKV,see TiKV documentation on our website. For more details on concepts and designs behind TiKV, see Deep Dive TiKV.

Note:

We have migrated our documentation from the TiKV's wiki page to the official website. The original Wiki page is discontinued. If you have any suggestions or issues regarding documentation, offer your feedback here.

TiKV adopters

You can view the list of TiKV Adopters.

TiKV software stack

The TiKV software stack

  • Placement Driver: PD is the cluster manager of TiKV, which periodically checks replication constraints to balance load and data automatically.
  • Store: There is a RocksDB within each Store and it stores data into the local disk.
  • Region: Region is the basic unit of Key-Value data movement. Each Region is replicated to multiple Nodes. These multiple replicas form a Raft group.
  • Node: A physical node in the cluster. Within each node, there are one or more Stores. Within each Store, there are many Regions.

When a node starts, the metadata of the Node, Store and Region are recorded into PD. The status of each Region and Store is reported to PD regularly.

Quick start

Deploy a playground with TiUP

The most quickest to try out TiKV with TiDB is using TiUP, a component manager for TiDB.

You can see this page for a step by step tutorial.

Deploy a playground with binary

TiKV is able to run separately with PD, which is the minimal deployment required.

  1. Download and extract binaries.
$ export TIKV_VERSION=v7.5.0
$ export GOOS=darwin  # only {darwin, linux} are supported
$ export GOARCH=amd64 # only {amd64, arm64} are supported
$ curl -O  https://tiup-mirrors.pingcap.com/tikv-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
$ curl -O  https://tiup-mirrors.pingcap.com/pd-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
$ tar -xzf tikv-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
$ tar -xzf pd-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
  1. Start PD instance.
$ ./pd-server --name=pd --data-dir=/tmp/pd/data --client-urls="http://127.0.0.1:2379" --peer-urls="http://127.0.0.1:2380" --initial-cluster="pd=http://127.0.0.1:2380" --log-file=/tmp/pd/log/pd.log
  1. Start TiKV instance.
$ ./tikv-server --pd-endpoints="127.0.0.1:2379" --addr="127.0.0.1:20160" --data-dir=/tmp/tikv/data --log-file=/tmp/tikv/log/tikv.log
  1. Install TiKV Client(Python) and verify the deployment, required Python 3.5+.
$ pip3 install -i https://test.pypi.org/simple/ tikv-client
from tikv_client import RawClient

client = RawClient.connect("127.0.0.1:2379")

client.put(b'foo', b'bar')
print(client.get(b'foo')) # b'bar'

client.put(b'foo', b'baz')
print(client.get(b'foo')) # b'baz'

Deploy a cluster with TiUP

You can see this manual of production-like cluster deployment presented by @c4pt0r.

Build from source

See CONTRIBUTING.md.

Client drivers

If you want to try the Go client, see Go Client.

Security

Security audit

A third-party security auditing was performed by Cure53. See the full report here.

Reporting Security Vulnerabilities

To report a security vulnerability, please send an email to TiKV-security group.

See Security for the process and policy followed by the TiKV project.

Communication

Communication within the TiKV community abides by TiKV Code of Conduct. Here is an excerpt:

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

Social Media

Slack

Join the TiKV community on Slack - Sign up and join channels on TiKV topics that interest you.

License

TiKV is under the Apache 2.0 license. See the LICENSE file for details.

Acknowledgments

  • Thanks etcd for providing some great open source tools.
  • Thanks RocksDB for their powerful storage engines.
  • Thanks rust-clippy. We do love the great project.

client-c's People

Contributors

birdstorm avatar breezewish avatar coocood avatar disksing avatar dveeden avatar fzhedu avatar gengliqi avatar guo-shaoge avatar hanfei1991 avatar hongyunyan avatar iosmanthus avatar jayson-huang avatar kolafish avatar leiysky avatar lidezhu avatar littlefall avatar lloyd-pottiger avatar schrodingerzhu avatar siddontang avatar solotzg avatar windtalker avatar xzhangxian1008 avatar yibin87 avatar yongman avatar ystaticy avatar ywqzzy avatar zanmato1984 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client-c's Issues

SafePoint Check in Scanner

Currently we only support get gc safe point from grpc api, but indeed, we should get safe point from etcd kv, and check if the safe point is out-date during mvcc scan.

compile error in googletest

Compile error in google test when using -DENABLE_TESTS=on.

 error: definition of implicit copy constructor for 'StartsWithMatcher<std::wstring>' is deprecated because it has a user-declared copy assignment operator

Unify the url of submodule to https url

The git clone protocol of some submodule is ssh, unify the url of submodule to https url.

[submodule "third_party/kvproto"]
	path = third_party/kvproto
	url = [email protected]:pingcap/kvproto.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = [email protected]:google/googletest.git
[submodule "third_party/libfiu"]
	path = third_party/libfiu
	url = https://github.com/albertito/libfiu.git

delete key

does client-c support deleting at present?

txn throw exception Region epoch not match after retries

./pd-server --version
Release Version: v4.0.0-rc.2-563-gaa22efb5-dirty
Edition: Community
Git Commit Hash: aa22efb50906e2d0fb1306bd2af6813969e46d73
Git Branch: master
UTC Build Time: 2021-05-27 04:38:59

Release Version: 5.1.0-alpha
Edition: Community
Git Commit Hash: cd905a208293c2b0c1fca9aa2756d5c26392b38c
Git Commit Branch: master
UTC Build Time: 2021-05-28 09:25:25
Rust Version: rustc 1.53.0-nightly (16bf626a3 2021-04-14)
Enable Features: jemalloc mem-profiling portable sse protobuf-codec test-engines-rocksdb cloud-aws cloud-gcp
Profile: release

src:
count=1000000
Txn txn(test_cluster.get());

try{
    char keyName[32];
    std::string keyValue( 512, 'x');

    auto begin_tm = timeSinceEpochMillisec();
    for( int i = 1;i<=count;i++){
        sprintf(keyName, "c%d", i);
        txn.set(keyName, keyValue);
    }
    txn.commit();
    auto end_tm = timeSinceEpochMillisec();
    printf("time:%ld\n", end_tm- begin_tm);
}
catch ( Exception & e) {
    std::cerr << "exception caught: " << e.displayText() << '\n';
}

[19:42:06] [(0)] Information: load store id 2001 address 172.16.16.21:20160
[19:43:33] [(0)] Warning: region {44103,3,29} find error: EpochNotMatch current epoch of region 44103 is conf_ver: 3 version: 30
[19:43:33] [(0)] Information: region stale for region {44103,3,29}.
[19:43:33] [(0)] Information: try drop region {44103,3,29}
[19:43:33] [(0)] Information: drop region 44103 because of send failure
[19:43:33] [(0)] Warning: region {44127,3,30} find error: peer is not leader for region 44127, leader may None
[19:43:33] [(0)] Information: report not leader but doesn't have new leader
[19:43:33] [(0)] Information: try drop region {44127,3,30}
[19:43:33] [(0)] Information: drop region 44127 because of send failure
[19:43:53] [(0)] Warning: write commit exception: Exception: Region epoch not match after retries: Region {44103,3,29} not in region cache.
exception caught: Exception: Region epoch not match after retries: Region {44103,3,29} not in region cache.

Coprocessor support.

If we want to support TiDB SQL in other languages, we must need a coprocessor support.

unused variable

[2021-08-17T06:17:00.986Z] /build/contrib/client-c/src/kv/2pc.cc: In member function 'void pingcap::kv::TwoPhaseCommitter::prewriteSingleBatch(pingcap::kv::Backoffer&, const pingcap::kv::TwoPhaseCommitter::BatchKeys&)':

[2021-08-17T06:17:00.986Z] /build/contrib/client-c/src/kv/2pc.cc:152:34: warning: unused variable 'v' [-Wunused-variable]

[2021-08-17T06:17:00.986Z]                  for (auto & [k, v] : mutations)

[2021-08-17T06:17:00.986Z]

Multi languages binding

This project should be packed as a shared lib with ffi interface so as to support other languages.

Refine MVCC Write

Currently, the MVCC Write is only used by test, some features is yet to add, like rollback asyncly after write fails. Maybe we'd better maintain serveral rollback queues rather than per rollback per thread.

Fix warnings

client-c/src/kv/LockResolver.cc: In member function ‘pingcap::kv::AsyncResolveDataPtr pingcap::kv::LockResolver::checkAllSecondaries(pingcap::kv::Backoffer&, pingcap::kv::LockPtr, pingcap::kv::TxnStatus&)’:
client-c/src/kv/LockResolver.cc:390:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (size_t i = 0; i < status.primary_lock->secondaries_size(); i++)
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from client-c/src/kv/2pc.cc:2:0:
client-c/include/pingcap/kv/2pc.h: In constructor ‘pingcap::kv::TwoPhaseCommitter::TwoPhaseCommitter(pingcap::kv::Txn*, bool)’:
client-c/include/pingcap/kv/2pc.h:110:14: warning: ‘pingcap::kv::TwoPhaseCommitter::log’ will be initialized after [-Wreorder]
     Logger * log;
              ^~~
client-c/include/pingcap/kv/2pc.h:106:10: warning:   ‘bool pingcap::kv::TwoPhaseCommitter::use_async_commit’ [-Wreorder]
     bool use_async_commit;
          ^~~~~~~~~~~~~~~~
client-c/src/kv/2pc.cc:42:1: warning:   when initialized here [-Wreorder]
 TwoPhaseCommitter::TwoPhaseCommitter(Txn * txn, bool _use_async_commit)
 ^~~~~~~~~~~~~~~~~
In file included from client-c/src/kv/2pc.cc:2:0:
client-c/include/pingcap/kv/2pc.h:106:10: warning: ‘pingcap::kv::TwoPhaseCommitter::use_async_commit’ will be initialized after [-Wreorder]
     bool use_async_commit;
          ^~~~~~~~~~~~~~~~
client-c/include/pingcap/kv/2pc.h:92:31: warning:   ‘std::chrono::milliseconds pingcap::kv::TwoPhaseCommitter::start_time’ [-Wreorder]
     std::chrono::milliseconds start_time;
                               ^~~~~~~~~~
client-c/src/kv/2pc.cc:42:1: warning:   when initialized here [-Wreorder]
 TwoPhaseCommitter::TwoPhaseCommitter(Txn * txn, bool _use_async_commit)
 ^~~~~~~~~~~~~~~~~
client-c/src/kv/2pc.cc: In member function ‘void pingcap::kv::TwoPhaseCommitter::prewriteSingleBatch(pingcap::kv::Backoffer&, const pingcap::kv::TwoPhaseCommitter::BatchKeys&)’:
client-c/src/kv/2pc.cc:152:34: warning: unused variable ‘v’ [-Wunused-variable]
                 for (auto & [k, v] : mutations)
                                  ^

Add compilation options -DENABLE_TESTS=ON cause project compile fail

Add compilation options such as:cmake -DENABLE_TESTS=ON ..
This command causes compilation to fail,As mentioned in the pingcap Developer Forum, grpc is compiled with dynamic libraries. The old version of clien-c can be compiled and used temporarily, but the latest version cannot. Moreover, we recommend using static libraries.Please fix it as soon as possible. Thank you

Check and resolve invalid stores periodicly

TiDB has a background goroutine to check validation of stores periodicly, while client-c will check it as soon as receiving an error.

I think it's better to implement such a eager way to update region cache.

Set grpc keepalive configuration for client

Currently, the keepalive configuration is not set for client.
So if a server is shut down abnormally, the client can not detect the failure of the server side thus it may hang forever.

Separating network layer from protocol/processing

I would recommend creating a separate protocol/processing layer from network layer which will allow for use in different languages and application stacks.
e.g. I would like to use TiKV in OpenResty (Nginx + Lua) stack where Nginx async socket needs to be used for network communication.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.