Skip to content

Commit

Permalink
feature: support route insert sql to shadow table (#278)
Browse files Browse the repository at this point in the history
* refactor: optimize sequence generator

* feature: support route insert sql to shadow table
  • Loading branch information
dk-lockdown authored Dec 10, 2022
1 parent 67d9506 commit 5a461ec
Show file tree
Hide file tree
Showing 17 changed files with 818 additions and 694 deletions.
6 changes: 6 additions & 0 deletions docker/conf/config_shd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ app_config:
global_tables:
- country
- countrylanguage
- pt_city_0
logic_tables:
- db_name: world
table_name: city
Expand All @@ -56,6 +57,11 @@ app_config:
topology:
"0": 0-4
"1": 5-9
shadow_rules:
- table_name: city
column: country_code
expr: "%s == \"US\""
shadow_table_prefix: pt_

data_source_cluster:
- name: world_0
Expand Down
20 changes: 15 additions & 5 deletions docker/scripts/world_0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
DROP TABLE IF EXISTS `city_0`;
CREATE TABLE `city_0` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
`population` int NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

DROP TABLE IF EXISTS `pt_city_0`;
CREATE TABLE `pt_city_0` (
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -454,7 +464,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_1`;
CREATE TABLE `city_1` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -881,7 +891,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_2`;
CREATE TABLE `city_2` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -1308,7 +1318,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_3`;
CREATE TABLE `city_3` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -1735,7 +1745,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_4`;
CREATE TABLE `city_4` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down
10 changes: 5 additions & 5 deletions docker/scripts/world_1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
DROP TABLE IF EXISTS `city_5`;
CREATE TABLE `city_5` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -455,7 +455,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_6`;
CREATE TABLE `city_6` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -882,7 +882,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_7`;
CREATE TABLE `city_7` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -1309,7 +1309,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_8`;
CREATE TABLE `city_8` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -1736,7 +1736,7 @@ COMMIT;
-- ----------------------------
DROP TABLE IF EXISTS `city_9`;
CREATE TABLE `city_9` (
`id` int NOT NULL DEFAULT '0',
`id` bigint NOT NULL DEFAULT '0',
`name` char(35) NOT NULL DEFAULT '',
`country_code` char(3) NOT NULL DEFAULT '',
`district` char(20) NOT NULL DEFAULT '',
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/agiledragon/gomonkey/v2 v2.7.0
github.com/antonmedv/expr v1.9.0
github.com/cespare/xxhash/v2 v2.1.2
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548
github.com/cznic/parser v0.0.0-20181122101858-d773202d5b1f
Expand All @@ -18,6 +19,7 @@ require (
github.com/golang-module/carbon v1.6.6
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.8
github.com/huandu/go-clone v1.4.1
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pingcap/check v0.0.0-20211026125417-57bd13f7b5f0
Expand Down
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/HdrHistogram/hdrhistogram-go v1.1.0 h1:6dpdDPTRoo78HxAJ6T1HfMiKSnqhgRRqzCuPshRkQ7I=
Expand Down Expand Up @@ -125,6 +126,8 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antonmedv/expr v1.9.0 h1:j4HI3NHEdgDnN9p6oI6Ndr0G5QryMY0FNxT4ONrFDGU=
github.com/antonmedv/expr v1.9.0/go.mod h1:5qsM3oLGDND7sDmQGDXHkYfkjYMUX14qsgqmHhwGEk8=
github.com/apache/thrift v0.0.0-20181112125854-24918abba929/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.1-0.20201008052519-daf620915714/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/appleboy/gin-jwt/v2 v2.6.3/go.mod h1:MfPYA4ogzvOcVkRwAxT7quHOtQmVKDpTwxyUrC2DNw0=
Expand Down Expand Up @@ -356,6 +359,7 @@ github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5/go.mod h1:Eo87+Kg/
github.com/d2g/hardwareaddr v0.0.0-20190221164911-e7d9fbe030e4/go.mod h1:bMl4RjIciD2oAxI7DmWRx6gbeqrkoLqv3MV0vzNad+I=
github.com/danjacques/gofslock v0.0.0-20191023191349-0a45f885bc37 h1:X6mKGhCFOxrKeeHAjv/3UvT6e5RRxW6wRdlqlV6/H4w=
github.com/danjacques/gofslock v0.0.0-20191023191349-0a45f885bc37/go.mod h1:DC3JtzuG7kxMvJ6dZmf2ymjNyoXwgtklr7FN+Um2B0U=
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -443,6 +447,8 @@ github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXt
github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E=
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -715,6 +721,10 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
github.com/huandu/go-clone v1.4.1 h1:QQYjiLadyxOvdwgZoH8f1xGkvvf4+Cm8be7fo9W2QQA=
github.com/huandu/go-clone v1.4.1/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE=
github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/hypnoglow/gormzap v0.3.0/go.mod h1:5Wom8B7Jl2oK0Im9hs6KQ+Kl92w4Y7gKCrj66rhyvw0=
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
Expand Down Expand Up @@ -824,6 +834,8 @@ github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
Expand All @@ -847,7 +859,9 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
Expand Down Expand Up @@ -1055,6 +1069,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down Expand Up @@ -1108,6 +1123,7 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqn
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/tview v0.0.0-20200219210816-cd38d7432498/go.mod h1:6lkG1x+13OShEf0EaOCaTQYyB7d5nSbb181KtjlS+84=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand All @@ -1122,6 +1138,7 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
github.com/sanity-io/litter v1.2.0/go.mod h1:JF6pZUFgu2Q0sBZ+HSV35P8TVPI1TTzEwyu9FXAw2W4=
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
Expand Down Expand Up @@ -1181,6 +1198,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down Expand Up @@ -1556,6 +1574,7 @@ golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
1 change: 1 addition & 0 deletions pkg/cond/algo_number_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (shard *NumberRange) AllShards() Condition {
func (shard *NumberRange) AllowFullScan() bool {
return shard.allowFullScan
}

func (shard *NumberRange) NextID() (int64, error) {
if shard.idGenerator != nil {
return shard.idGenerator.NextID()
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ type (
Config Parameters `yaml:"config,omitempty" json:"config,omitempty"`
}

ShadowRule struct {
TableName string `yaml:"table_name" json:"table_name"`
Column string `yaml:"column" json:"column"`
Expr string `yaml:"expr" json:"expr"`
ShadowTablePrefix string `yaml:"shadow_table_prefix" json:"shadow_table_prefix"`
}

SequenceGenerator struct {
Type SequenceType `yaml:"type" json:"type"`
Config Parameters `yaml:"config,omitempty" json:"config,omitempty"`
Expand All @@ -97,6 +104,7 @@ type (
DBGroups []*DataSourceRefGroup `yaml:"db_groups" json:"db_groups"`
GlobalTables []string `yaml:"global_tables" json:"global_tables"`
LogicTables []*LogicTable `yaml:"logic_tables" json:"logic_tables"`
ShadowRules []*ShadowRule `yaml:"shadow_rules" json:"shadow_rules"`
TransactionTimeout int32 `yaml:"transaction_timeout" json:"transaction_timeout"`
}
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/sharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func NewShardingExecutor(conf *config.Executor) (proto.Executor, error) {
PostFilters: make([]proto.DBPostFilter, 0),
config: shardingConfig,
executors: executorSlice,
optimizer: optimize.NewOptimizer(conf.AppID,
globalTables, executorSlice, executorMap, algorithms, topologies),
optimizer: optimize.NewOptimizer(conf.AppID, globalTables, shardingConfig.ShadowRules,
executorSlice, executorMap, algorithms, topologies),
localTransactionMap: &sync.Map{},
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/misc/hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
GlobalLockHint = "GlobalLock"
UseDBHint = "UseDB"
TraceParentHint = "TraceParent"
ShadowHint = "Shadow"
)

func HasXIDHint(hints []*ast.TableOptimizerHint) (bool, string) {
Expand Down Expand Up @@ -72,6 +73,15 @@ func HasTraceParentHint(hints []*ast.TableOptimizerHint) (bool, string) {
return false, ""
}

func HasShadowHint(hints []*ast.TableOptimizerHint) bool {
for _, hint := range hints {
if strings.EqualFold(hint.HintName.String(), ShadowHint) {
return true
}
}
return false
}

func NewXIDHint(xid string) *ast.TableOptimizerHint {
return &ast.TableOptimizerHint{
HintName: model.CIStr{
Expand Down
9 changes: 5 additions & 4 deletions pkg/optimize/optimize_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"

"github.com/huandu/go-clone"
"github.com/pkg/errors"

"github.com/cectc/dbpack/pkg/plan"
Expand Down Expand Up @@ -54,8 +55,8 @@ func (o Optimizer) optimizeCreateIndex(ctx context.Context, stmt *ast.CreateInde
}
for db, tables := range topology.DBs {
for _, table := range tables {
cp := *stmt
newStmt := &cp
statement := clone.Clone(stmt)
newStmt := statement.(*ast.CreateIndexStmt)
newStmt.Table.Name.O = table
directlyQueryPlan := &plan.DirectQueryPlan{
Stmt: newStmt,
Expand Down Expand Up @@ -93,8 +94,8 @@ func (o Optimizer) optimizeDropIndex(ctx context.Context, stmt *ast.DropIndexStm
}
for db, tables := range topology.DBs {
for _, table := range tables {
cp := *stmt
newStmt := &cp
statement := clone.Clone(stmt)
newStmt := statement.(*ast.DropIndexStmt)
newStmt.Table.Name.O = table
directlyQueryPlan := &plan.DirectQueryPlan{
Stmt: newStmt,
Expand Down
Loading

0 comments on commit 5a461ec

Please sign in to comment.