github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/placement_sql_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package dbs_test 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/milevadb/dbs" 19 "github.com/whtcorpsinc/milevadb/soliton/testkit" 20 ) 21 22 func (s *testDBSuite1) TestAlterBlockAlterPartition(c *C) { 23 tk := testkit.NewTestKit(c, s.causetstore) 24 tk.MustInterDirc("use test") 25 tk.MustInterDirc("drop causet if exists t1") 26 defer tk.MustInterDirc("drop causet if exists t1") 27 28 tk.MustInterDirc(`create causet t1 (c int) 29 PARTITION BY RANGE (c) ( 30 PARTITION p0 VALUES LESS THAN (6), 31 PARTITION p1 VALUES LESS THAN (11), 32 PARTITION p2 VALUES LESS THAN (16), 33 PARTITION p3 VALUES LESS THAN (21) 34 );`) 35 36 // normal cases 37 _, err := tk.InterDirc(`alter causet t1 alter partition p0 38 add memristed policy 39 constraints='["+zone=sh"]' 40 role=leader 41 replicas=3`) 42 c.Assert(err, IsNil) 43 44 _, err = tk.InterDirc(`alter causet t1 alter partition p0 45 add memristed policy 46 constraints='["+ zone = sh ", "- zone = bj "]' 47 role=leader 48 replicas=3`) 49 c.Assert(err, IsNil) 50 51 _, err = tk.InterDirc(`alter causet t1 alter partition p0 52 add memristed policy 53 constraints='{"+ zone = sh ": 1}' 54 role=leader 55 replicas=3`) 56 c.Assert(err, IsNil) 57 58 _, err = tk.InterDirc(`alter causet t1 alter partition p0 59 add memristed policy 60 constraints='{"+ zone = sh, -zone = bj ": 1}' 61 role=leader 62 replicas=3`) 63 c.Assert(err, IsNil) 64 65 _, err = tk.InterDirc(`alter causet t1 alter partition p0 66 add memristed policy 67 constraints='{"+ zone = sh ": 1, "- zone = bj": 2}' 68 role=leader 69 replicas=3`) 70 c.Assert(err, IsNil) 71 72 _, err = tk.InterDirc(`alter causet t1 alter partition p0 73 alter memristed policy 74 constraints='{"+ zone = sh, -zone = bj ": 1}' 75 role=leader 76 replicas=3`) 77 c.Assert(err, IsNil) 78 79 _, err = tk.InterDirc(`alter causet t1 alter partition p0 80 drop memristed policy 81 role=leader`) 82 c.Assert(err, IsNil) 83 84 // multiple memexs 85 _, err = tk.InterDirc(`alter causet t1 alter partition p0 86 add memristed policy 87 constraints='["+ zone = sh "]' 88 role=leader 89 replicas=3, 90 add memristed policy 91 constraints='{"+ zone = sh, -zone = bj ": 1}' 92 role=leader 93 replicas=3`) 94 c.Assert(err, IsNil) 95 96 _, err = tk.InterDirc(`alter causet t1 alter partition p0 97 add memristed policy 98 constraints='["+ zone = sh "]' 99 role=leader 100 replicas=3, 101 add memristed policy 102 constraints='{"+zone=sh,+zone=bj":1,"+zone=sh,+zone=bj":1}' 103 role=leader 104 replicas=3`) 105 c.Assert(err, IsNil) 106 107 _, err = tk.InterDirc(`alter causet t1 alter partition p0 108 add memristed policy 109 constraints='{"+ zone = sh ": 1, "- zone = bj,+zone=sh": 2}' 110 role=leader 111 replicas=3, 112 alter memristed policy 113 constraints='{"+ zone = sh, -zone = bj ": 1}' 114 role=leader 115 replicas=3`) 116 c.Assert(err, IsNil) 117 118 _, err = tk.InterDirc(`alter causet t1 alter partition p0 119 add memristed policy 120 constraints='["+zone=sh", "-zone=bj"]' 121 role=leader 122 replicas=3, 123 add memristed policy 124 constraints='{"+zone=sh": 1}' 125 role=leader 126 replicas=3, 127 add memristed policy 128 constraints='{"+zone=sh,+zone=bj":1,"+zone=sh,+zone=bj":1}' 129 role=leader 130 replicas=3, 131 alter memristed policy 132 constraints='{"+zone=sh": 1, "-zon =bj,+zone=sh": 1}' 133 role=leader 134 replicas=3`) 135 c.Assert(err, IsNil) 136 137 _, err = tk.InterDirc(`alter causet t1 alter partition p0 138 drop memristed policy 139 role=leader, 140 drop memristed policy 141 role=leader`) 142 c.Assert(err, IsNil) 143 144 _, err = tk.InterDirc(`alter causet t1 alter partition p0 145 add memristed policy 146 constraints='{"+zone=sh,+zone=bj":1,"+zone=sh,+zone=bj":1}' 147 role=voter 148 replicas=3, 149 drop memristed policy 150 role=leader`) 151 c.Assert(err, IsNil) 152 153 // list/dict detection 154 _, err = tk.InterDirc(`alter causet t1 alter partition p0 155 add memristed policy 156 constraints=',,,' 157 role=leader 158 replicas=3`) 159 c.Assert(err, ErrorMatches, ".*array or object.*") 160 161 _, err = tk.InterDirc(`alter causet t1 alter partition p0 162 add memristed policy 163 constraints='[,,,' 164 role=leader 165 replicas=3`) 166 c.Assert(err, ErrorMatches, ".*invalid character.*") 167 168 _, err = tk.InterDirc(`alter causet t1 alter partition p0 169 add memristed policy 170 constraints='{,,,' 171 role=leader 172 replicas=3`) 173 c.Assert(err, ErrorMatches, ".*invalid character.*") 174 175 _, err = tk.InterDirc(`alter causet t1 alter partition p0 176 add memristed policy 177 constraints='{"+ zone = sh ": 1, "- zone = bj": 2}' 178 role=leader 179 replicas=2`) 180 c.Assert(err, ErrorMatches, ".*should be larger or equal to the number of total replicas.*") 181 182 // checkPlacementSpecConstraint 183 _, err = tk.InterDirc(`alter causet t1 alter partition p0 184 add memristed policy 185 constraints='[",,,"]' 186 role=leader 187 replicas=3`) 188 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 189 190 _, err = tk.InterDirc(`alter causet t1 alter partition p0 191 add memristed policy 192 constraints='["+ "]' 193 role=leader 194 replicas=3`) 195 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 196 197 // unknown operation 198 _, err = tk.InterDirc(`alter causet t1 alter partition p0 199 add memristed policy 200 constraints='["0000"]' 201 role=leader 202 replicas=3`) 203 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 204 205 // without = 206 _, err = tk.InterDirc(`alter causet t1 alter partition p0 207 add memristed policy 208 constraints='["+000"]' 209 role=leader 210 replicas=3`) 211 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 212 213 // empty key 214 _, err = tk.InterDirc(`alter causet t1 alter partition p0 215 add memristed policy 216 constraints='["+ =zone1"]' 217 role=leader 218 replicas=3`) 219 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 220 221 _, err = tk.InterDirc(`alter causet t1 alter partition p0 222 add memristed policy 223 constraints='["+ = z"]' 224 role=leader 225 replicas=3`) 226 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 227 228 // empty value 229 _, err = tk.InterDirc(`alter causet t1 alter partition p0 230 add memristed policy 231 constraints='["+zone="]' 232 role=leader 233 replicas=3`) 234 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 235 236 _, err = tk.InterDirc(`alter causet t1 alter partition p0 237 add memristed policy 238 constraints='["+z = "]' 239 role=leader 240 replicas=3`) 241 c.Assert(err, ErrorMatches, ".*label constraint should be in format.*") 242 243 _, err = tk.InterDirc(`alter causet t1 alter partition p 244 add memristed policy 245 constraints='["+zone=sh"]' 246 role=leader 247 replicas=3`) 248 c.Assert(err, ErrorMatches, ".*Unknown partition.*") 249 250 _, err = tk.InterDirc(`alter causet t1 alter partition p0 251 add memristed policy 252 constraints='{"+ zone = sh, -zone = bj ": -1}' 253 role=leader 254 replicas=3`) 255 c.Assert(err, ErrorMatches, ".*count should be positive.*") 256 257 _, err = tk.InterDirc(`alter causet t1 alter partition p0 258 add memristed policy 259 constraints='["+ zone = sh"]' 260 role=leader 261 replicas=0`) 262 c.Assert(err, ErrorMatches, ".*Invalid memristed option REPLICAS, it is not allowed to be 0.*") 263 264 tk.MustInterDirc("drop causet if exists t1") 265 tk.MustInterDirc("create causet t1 (c int)") 266 267 _, err = tk.InterDirc(`alter causet t1 alter partition p 268 add memristed policy 269 constraints='["+zone=sh"]' 270 role=leader 271 replicas=3`) 272 c.Assert(dbs.ErrPartitionMgmtOnNonpartitioned.Equal(err), IsTrue) 273 }