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

FLASH-275/276/277/278/281/282: Complete DDL implementation #110

Merged
merged 135 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
a514e64
Widen schema syncer with sync all semantic, add background schema syn…
zanmato1984 Jun 11, 2019
4a79bb7
Merge branch 'master' into ddl
zanmato1984 Jun 12, 2019
0eafdd4
Finish widen some data types to avoid data rewriting during apply ddl
zanmato1984 Jun 12, 2019
9d69885
Merge branch 'master' into ddl
zanmato1984 Jun 12, 2019
5b648cc
Add update_timestamp into table info
zanmato1984 Jun 17, 2019
647bbbb
Refine read and flush to be more robust for schema change
zanmato1984 Jun 21, 2019
bf25957
Fix nullable for overflow check when decode region cache
zanmato1984 Jun 21, 2019
095ca6c
Add schema state enum
zanmato1984 Jun 23, 2019
dd50f03
Support column type change in schema syncer
zanmato1984 Jun 23, 2019
363ecc7
Fix comment
zanmato1984 Jun 23, 2019
18ed32e
Add mock functions for TiDB DDL
zanmato1984 Jun 23, 2019
402132a
Fix rvalue ref
zanmato1984 Jun 24, 2019
02ad15e
Fix some bugs in schema syncer and mock tidb
zanmato1984 Jun 24, 2019
fb2b960
Adjust test
zanmato1984 Jun 24, 2019
718d1c0
Add alter test
zanmato1984 Jun 24, 2019
463836e
Not do data conversion for alter txn table, as we already stored wide…
zanmato1984 Jun 25, 2019
e86d96a
Fix typo
zanmato1984 Jun 25, 2019
6988bdb
Fix mock tidb reverse type mapping
zanmato1984 Jun 25, 2019
7fb48af
Enhance overflow checking when flushing
zanmato1984 Jun 25, 2019
9ad7a1c
Enhance alter test
zanmato1984 Jun 25, 2019
509ee1c
Refine some code
zanmato1984 Jul 1, 2019
f26a75e
Remove table region mapping when drop table
zanmato1984 Jul 2, 2019
261b3d2
Adjust drop order
zanmato1984 Jul 2, 2019
47d17fc
Print file path in mutable test script when error
zanmato1984 Jul 2, 2019
d409926
Fix insert widen data through sql
zanmato1984 Jul 2, 2019
40379bf
Fix some txn tests
zanmato1984 Jul 2, 2019
ebd897a
Fix widen data write of import statement
zanmato1984 Jul 3, 2019
98d09cf
DDL read and update by tikv's meta (#103)
hanfei1991 Jul 12, 2019
423363a
Add schema version check before reading
zanmato1984 Jul 12, 2019
c6f32a6
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 12, 2019
d563bdf
Merge master
zanmato1984 Jul 12, 2019
31e84ac
Fix build error
zanmato1984 Jul 12, 2019
0b483b4
Format
zanmato1984 Jul 12, 2019
a888d93
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 12, 2019
5411052
Reorg schema syncer code
zanmato1984 Jul 15, 2019
45831f6
Add lock control in schema syncer interface
zanmato1984 Jul 15, 2019
745850e
Refinement
zanmato1984 Jul 15, 2019
26b6dd7
Add sync schema on read
zanmato1984 Jul 16, 2019
9314f91
fix bug during creating column: use a wrong db name (#107)
hanfei1991 Jul 16, 2019
d1ac4f4
Simplify schema syncer interface and adjust mock stuff
zanmato1984 Jul 16, 2019
d3e2298
Rename default schema version setting
zanmato1984 Jul 18, 2019
e690046
Compensate last commit
zanmato1984 Jul 18, 2019
149a114
fix ddl sync for table drop and truncate (#109)
hanfei1991 Jul 18, 2019
f942f8a
Add schema sync on read and simplify schema syncer interface and adju…
zanmato1984 Jul 18, 2019
89b849d
Merge master
zanmato1984 Jul 18, 2019
2e67d08
Fix build error
zanmato1984 Jul 18, 2019
ffbdc92
Fix build error
zanmato1984 Jul 18, 2019
2c57e8c
Merge dll branch
zanmato1984 Jul 18, 2019
49b3fdf
Remove curl library
zanmato1984 Jul 18, 2019
b5c2a85
Remove curl from builder image
zanmato1984 Jul 18, 2019
e515c30
Remove useless codes, init schema syncer based on pd config
zanmato1984 Jul 18, 2019
fa38d54
Merge branch 'master' into ddl
zanmato1984 Jul 18, 2019
e084771
Minor fix to schema debug
zanmato1984 Jul 18, 2019
e89c697
Fix alter tmt and pass tests
zanmato1984 Jul 18, 2019
293c880
Merge ddl
zanmato1984 Jul 18, 2019
aa8072a
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 18, 2019
5623239
Remove useless codes (#112)
zanmato1984 Jul 18, 2019
14bc79b
Merge ddl
zanmato1984 Jul 18, 2019
074f521
Fix build fail
zanmato1984 Jul 18, 2019
a1e9b57
Merge remote
zanmato1984 Jul 18, 2019
76f973d
Fix alter tmt and pass schema tests (#114)
zanmato1984 Jul 19, 2019
448696c
sync default value from tidb to flash (#113)
hanfei1991 Jul 19, 2019
3140836
Add lock for mock schema syncer
zanmato1984 Jul 19, 2019
23ff96c
Fix schema sync service init context
zanmato1984 Jul 19, 2019
fb638a7
Adjust schema tests
zanmato1984 Jul 19, 2019
fc10c2e
Not sync if no schema change detected
zanmato1984 Jul 19, 2019
d3b0af9
Adjust txn mock tests
zanmato1984 Jul 19, 2019
9590357
Merge ddl
zanmato1984 Jul 19, 2019
2237d2e
[DDL] Pass all txn tests (#116)
zanmato1984 Jul 19, 2019
4eb977a
Merge master and format
zanmato1984 Jul 19, 2019
f6c7275
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 19, 2019
517793b
Fix default value bug
zanmato1984 Jul 19, 2019
0e510f3
Rename some tests
zanmato1984 Jul 19, 2019
4dad596
Fix empty default value bug (#117)
zanmato1984 Jul 19, 2019
32e9f3d
Remove sync schema test
zanmato1984 Jul 19, 2019
bbe3743
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 19, 2019
c6d4f86
Remove a lot useless code
zanmato1984 Jul 19, 2019
9851e66
Refine schema sync on read, and add drop on read test
zanmato1984 Jul 20, 2019
1a6a1c4
Remove a lot useless code (#118)
zanmato1984 Jul 20, 2019
b001bcc
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 20, 2019
33fb39d
Refine schema sync on read logic and add test (#120)
zanmato1984 Jul 22, 2019
d29f518
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 22, 2019
52baefc
add schema_version for TableInfo (#122)
hanfei1991 Jul 22, 2019
72aa0f2
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 22, 2019
6242a3d
fix bug for drop table; (#123)
hanfei1991 Jul 22, 2019
11f261d
Support rename mock tidb table
zanmato1984 Jul 22, 2019
a689b8a
Add rename tests
zanmato1984 Jul 22, 2019
80ea634
add logs for debug (#126)
hanfei1991 Jul 22, 2019
00bd504
Add mock truncate table and tests
zanmato1984 Jul 22, 2019
4f7c2d9
Test rename table (#124)
zanmato1984 Jul 22, 2019
bc79718
tiny fix (#127)
hanfei1991 Jul 22, 2019
34984cd
Add rename/truncate on read/write test and alter on read test
zanmato1984 Jul 22, 2019
3fcc650
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 22, 2019
4fe0e7b
Add rename/truncate on read/write test and alter on read test (#128)
zanmato1984 Jul 23, 2019
8e806e6
support for alter column. (#129)
hanfei1991 Jul 23, 2019
027a1c6
Fix mis-widen internal columns
zanmato1984 Jul 23, 2019
21eeb8e
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 23, 2019
6126544
Merge master
zanmato1984 Jul 23, 2019
af063aa
Support rename table. (#130)
hanfei1991 Jul 23, 2019
19a1abb
Fix fragile txn mock test
zanmato1984 Jul 23, 2019
79b92a5
Merge branch 'ddl' of github.com:pingcap/tics into ddl
zanmato1984 Jul 23, 2019
6f1c6ad
Merge branch 'ddl' into ddl-ruoxi
zanmato1984 Jul 23, 2019
d8b9f0d
Fix mis-widen internal columns (#133)
zanmato1984 Jul 24, 2019
38ea54c
Fix fragile txn mock test again
zanmato1984 Jul 24, 2019
e3caf12
Merge branch 'ddl-ruoxi' into ddl
zanmato1984 Jul 24, 2019
e02344f
Remove useless code
zanmato1984 Jul 24, 2019
f461c16
Resolve a dead lock problem during bootstraping. (#134)
hanfei1991 Jul 24, 2019
22679aa
Fix dead lock in learner read (#135)
zanmato1984 Jul 24, 2019
bb200fa
Adjust order of region check and lock by region scanner creation (#136)
zanmato1984 Jul 24, 2019
5dbae9f
Address comments
zanmato1984 Jul 24, 2019
605acbc
address comment
hanfei1991 Jul 25, 2019
6e19709
[FLASH-358] Support Region DeleteRange (#139)
solotzg Jul 25, 2019
2dbb362
Address comments
zanmato1984 Jul 30, 2019
9628ef4
Merge branch 'master' into ddl
zanmato1984 Jul 30, 2019
0852980
Merge branch 'master' into ddl
zanmato1984 Jul 30, 2019
772b5aa
Merge branch 'ddl' of github.com:pingcap/tics into ddl
zanmato1984 Jul 30, 2019
77b8c33
Fix test config based on new ddl
zanmato1984 Jul 30, 2019
fc04e2a
fix drop db bug
hanfei1991 Jul 30, 2019
795384e
Merge branch 'master' into ddl
zanmato1984 Jul 30, 2019
c8f9570
refine log
hanfei1991 Jul 31, 2019
02219d1
Fix a ignore db config bug and add verbose pd addr
zanmato1984 Jul 31, 2019
0ad4c47
Merge branch 'ddl' of github.com:pingcap/tics into ddl
zanmato1984 Jul 31, 2019
da51a7d
Enlarge pd/kv/db startup waiting time
zanmato1984 Jul 31, 2019
caba195
Merge branch 'master' into ddl
zanmato1984 Jul 31, 2019
d8505b4
Remove useless commands
zanmato1984 Aug 1, 2019
510b409
format client-c
hanfei1991 Aug 1, 2019
f885b95
Merge branch 'ddl' of github.com:pingcap/tics into ddl
zanmato1984 Aug 5, 2019
75d271f
Address comments
zanmato1984 Aug 5, 2019
56b594b
address comments
hanfei1991 Aug 5, 2019
688892f
hot fix
hanfei1991 Aug 5, 2019
573a569
Fix failed test
zanmato1984 Aug 5, 2019
89170bc
Merge branch 'ddl' of github.com:pingcap/tics into ddl
zanmato1984 Aug 5, 2019
274aa5c
Fix mutable tests by using no schema syncer
zanmato1984 Aug 5, 2019
81eb519
Merge branch 'master' into ddl
solotzg Aug 5, 2019
152aeab
fix. optimize background thread pool. (#153)
solotzg Aug 5, 2019
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
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_contrib_lib.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; }
zanmato1984 marked this conversation as resolved.
Show resolved Hide resolved

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
52 changes: 31 additions & 21 deletions contrib/client-c/include/tikv/Backoff.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
#pragma once

#include <iostream>
#include <cmath>
#include <unistd.h>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>

#include <common/CltException.h>

namespace pingcap {
namespace kv {
namespace pingcap
{
namespace kv
{

enum Jitter {
enum Jitter
{
NoJitter = 1,
FullJitter,
EqualJitter,
DecorrJitter
};

enum BackoffType {
enum BackoffType
{
boTiKVRPC = 0,
boTxnLock,
boTxnLockFast,
Expand All @@ -28,28 +32,31 @@ enum BackoffType {
boServerBusy
};

inline int expo(int base, int cap, int n) {
return std::min(double(cap), double(base) * std::pow(2.0, double(n)));
}
inline int expo(int base, int cap, int n) { return std::min(double(cap), double(base) * std::pow(2.0, double(n))); }

struct Backoff {
struct Backoff
{
int base;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t may be more accurate, but not a big deal

int cap;
int jitter;
int last_sleep;
int attempts;

Backoff(int base_, int cap_, Jitter jitter_) : base(base_), cap(cap_), jitter(jitter_), attempts(0) {
if (base < 2) {
Backoff(int base_, int cap_, Jitter jitter_) : base(base_), cap(cap_), jitter(jitter_), attempts(0)
{
if (base < 2)
{
base = 2;
}
last_sleep = base;
}

int sleep () {
int sleep()
{
int sleep_time = 0;
int v = 0;
switch(jitter) {
switch (jitter)
{
case NoJitter:
sleep_time = expo(base, cap, attempts);
break;
Expand All @@ -59,31 +66,34 @@ struct Backoff {
break;
case EqualJitter:
v = expo(base, cap, attempts);
sleep_time = v/2 + rand() % (v/2);
sleep_time = v / 2 + rand() % (v / 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is a little jumpy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break;
case DecorrJitter:
sleep_time = int(std::min(double(cap), double(base + rand() % (last_sleep*3-base))));
sleep_time = int(std::min(double(cap), double(base + rand() % (last_sleep * 3 - base))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment would be nice, I don't really get it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
::usleep(sleep_time);
attempts ++;
attempts++;
last_sleep = sleep_time;
return last_sleep;
}
};

constexpr int readIndexMaxBackoff = 20000;
constexpr int GetMaxBackoff = 20000;
constexpr int scanMaxBackoff = 20000;

using BackoffPtr = std::shared_ptr<Backoff>;

struct Backoffer {
struct Backoffer
{
std::map<BackoffType, BackoffPtr> backoff_map;
size_t total_sleep; // ms
size_t max_sleep; // ms
size_t max_sleep; // ms

Backoffer(size_t max_sleep_) : total_sleep(0), max_sleep(max_sleep_) {}

void backoff(BackoffType tp, const Exception & exc);
};

}
}
} // namespace kv
} // namespace pingcap
Loading