Skip to content

Commit

Permalink
Merge master into cop
Browse files Browse the repository at this point in the history
  • Loading branch information
zanmato1984 committed Aug 5, 2019
2 parents cb55df4 + 71e1b04 commit ed41c93
Show file tree
Hide file tree
Showing 2,026 changed files with 6,800 additions and 56,382 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,7 @@ build_docker
docker/builder/tics
tests/docker/data
tests/docker/log
tests/docker/config/tikv-learner.toml
tests/fullstack-test/dml/dml_gen/*
tests/mutable-test/mutable_dedup/skipping.visual.test/*
tests/mutable-test/mutable_dedup/small_parts.visual.test/*
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ include (cmake/find_capnp.cmake)
include (cmake/find_llvm.cmake)
include (cmake/find_grpc.cmake)
include (cmake/find_kvproto.cmake)
include (cmake/find_curl.cmake)
include (cmake/find_tipb.cmake)


Expand Down
7 changes: 0 additions & 7 deletions cmake/find_curl.cmake

This file was deleted.

12 changes: 7 additions & 5 deletions contrib/client-c/include/common/CltException.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
#pragma once

#include <Poco/Exception.h>
#include <exception>
#include <string>
#include <Poco/Exception.h>

namespace pingcap {
namespace pingcap
{

const int MismatchClusterIDCode = 1;
const int GRPCErrorCode = 2;
const int InitClusterIDFailed = 3;
const int UpdatePDLeaderFailed = 4;
const int TimeoutError = 5;
const int RegionUnavailable = 6;
const int LogicalError = 7;
const int LockError = 8;

class Exception : public Poco::Exception
{
public:
Exception() {} /// For deferred initialization.
Exception() {} /// For deferred initialization.
Exception(const std::string & msg, int code = 0) : Poco::Exception(msg, code) {}
Exception(const std::string & msg, const std::string & arg, int code = 0) : Poco::Exception(msg, arg, code) {}
Exception(const std::string & msg, const Exception & exc, int code = 0) : Poco::Exception(msg, exc, code) {}
explicit Exception(const Poco::Exception & exc) : Poco::Exception(exc.displayText()) {}

Exception * clone() const override { return new Exception(*this); }
void rethrow() const override { throw *this; }

};

}
} // namespace pingcap
3 changes: 2 additions & 1 deletion contrib/client-c/include/common/Log.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Poco/Logger.h>

namespace pingcap {
namespace pingcap
{
using Poco::Logger;
}
38 changes: 19 additions & 19 deletions contrib/client-c/include/pd/Client.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
#pragma once

#include <common/Log.h>
#include <kvproto/pdpb.grpc.pb.h>
#include <atomic>
#include <thread>
#include <condition_variable>
#include <mutex>
#include <shared_mutex>
#include <condition_variable>
#include <kvproto/pdpb.grpc.pb.h>
#include <common/Log.h>
#include <thread>
#include "IClient.h"

namespace pingcap{
namespace pd {
namespace pingcap
{
namespace pd
{

struct SecurityOption {
struct SecurityOption
{
std::string CAPath;
std::string CertPath;
std::string KeyPath;
};

class Client : public IClient {
class Client : public IClient
{
const int max_init_cluster_retries;

const std::chrono::seconds pd_timeout;
Expand All @@ -28,17 +32,14 @@ class Client : public IClient {
const std::chrono::seconds update_leader_interval;

public:

Client(const std::vector<std::string> & addrs);

~Client() override;

//uint64_t getClusterID() override;

// only implement a weak get ts.
uint64_t getTS() override {
throw "not implemented";
}
uint64_t getTS() override;

std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegion(std::string key) override;

Expand All @@ -59,17 +60,17 @@ class Client : public IClient {

void updateLeader();

void updateURLs(const ::google::protobuf::RepeatedPtrField<::pdpb::Member>& members);
void updateURLs(const ::google::protobuf::RepeatedPtrField<::pdpb::Member> & members);

void leaderLoop();

void switchLeader(const ::google::protobuf::RepeatedPtrField<std::string>&);
void switchLeader(const ::google::protobuf::RepeatedPtrField<std::string> &);

std::unique_ptr<pdpb::PD::Stub> leaderStub();

pdpb::GetMembersResponse getMembers(std::string);

pdpb::RequestHeader* requestHeader();
pdpb::RequestHeader * requestHeader();

std::shared_ptr<grpc::Channel> getOrCreateGRPCConn(const std::string &);

Expand All @@ -83,7 +84,7 @@ class Client : public IClient {

std::mutex gc_safepoint_mutex;

std::unordered_map<std::string, std::shared_ptr<grpc::Channel> > channel_map;
std::unordered_map<std::string, std::shared_ptr<grpc::Channel>> channel_map;

std::vector<std::string> urls;

Expand All @@ -100,9 +101,8 @@ class Client : public IClient {
std::atomic<bool> check_leader;

Logger * log;

};


}
}
} // namespace pd
} // namespace pingcap
24 changes: 13 additions & 11 deletions contrib/client-c/include/pd/IClient.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
#pragma once

#include<string>
#include<vector>
#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <kvproto/enginepb.pb.h>
#pragma GCC diagnostic pop

namespace pingcap {
namespace pd {
namespace pingcap
{
namespace pd
{

class IClient {
class IClient
{
public:
// virtual uint64_t getClusterID() = 0;
// virtual uint64_t getClusterID() = 0;

virtual ~IClient() {}

virtual uint64_t getTS() = 0;

virtual std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegion(std::string key) = 0;

// virtual std::pair<metapb::Region, metapb::Peer> getPrevRegion(std::string key) = 0;
// virtual std::pair<metapb::Region, metapb::Peer> getPrevRegion(std::string key) = 0;

virtual std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegionByID(uint64_t region_id) = 0;

virtual metapb::Store getStore(uint64_t store_id) = 0;

// virtual std::vector<metapb::Store> getAllStores() = 0;
// virtual std::vector<metapb::Store> getAllStores() = 0;

virtual uint64_t getGCSafePoint() = 0;

virtual bool isMock() = 0;

};

using ClientPtr = std::shared_ptr<IClient>;

}
}
} // namespace pd
} // namespace pingcap
42 changes: 15 additions & 27 deletions contrib/client-c/include/pd/MockPDClient.h
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
#pragma once

#include <limits>
#include <pd/IClient.h>
#include <limits>

namespace pingcap {
namespace pd {
namespace pingcap
{
namespace pd
{

using Clock = std::chrono::system_clock;
using Seconds = std::chrono::seconds;

class MockPDClient : public IClient {
class MockPDClient : public IClient
{
public:
MockPDClient() = default;

~MockPDClient() override {}

uint64_t getGCSafePoint() override
{
return (Clock::now() - Seconds(2)).time_since_epoch().count();
}
uint64_t getGCSafePoint() override { return 1000000000000000; }

uint64_t getTS() override
{
return Clock::now().time_since_epoch().count();
}
uint64_t getTS() override { return Clock::now().time_since_epoch().count(); }

std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegion(std::string) override {
throw "not implemented";
}
std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegion(std::string) override { throw "not implemented"; }

std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegionByID(uint64_t) override {
throw "not implemented";
}
std::tuple<metapb::Region, metapb::Peer, std::vector<metapb::Peer>> getRegionByID(uint64_t) override { throw "not implemented"; }

metapb::Store getStore(uint64_t) override {
throw "not implemented";
}
metapb::Store getStore(uint64_t) override { throw "not implemented"; }

bool isMock() override {
return true;
}
bool isMock() override { return true; }
};

}
}
} // namespace pd
} // namespace pingcap
Loading

0 comments on commit ed41c93

Please sign in to comment.