@@ -47,8 +47,13 @@ type Client interface {
47
47
GetRegionsByStoreID (context.Context , uint64 ) (* RegionsInfo , error )
48
48
GetHotReadRegions (context.Context ) (* StoreHotPeersInfos , error )
49
49
GetHotWriteRegions (context.Context ) (* StoreHotPeersInfos , error )
50
+ GetRegionStatusByKey (context.Context , []byte , []byte ) (* RegionStats , error )
50
51
GetStores (context.Context ) (* StoresInfo , error )
52
+ GetPlacementRulesByGroup (context.Context , string ) ([]* Rule , error )
53
+ SetPlacementRule (context.Context , * Rule ) error
54
+ DeletePlacementRule (context.Context , string , string ) error
51
55
GetMinResolvedTSByStoresIDs (context.Context , []uint64 ) (uint64 , map [uint64 ]uint64 , error )
56
+ AccelerateSchedule (context.Context , []byte , []byte ) error
52
57
Close ()
53
58
}
54
59
@@ -154,7 +159,7 @@ func (c *client) execDuration(name string, duration time.Duration) {
154
159
// it consistent with the current implementation of some clients (e.g. TiDB).
155
160
func (c * client ) requestWithRetry (
156
161
ctx context.Context ,
157
- name , uri string ,
162
+ name , uri , method string ,
158
163
res interface {},
159
164
) error {
160
165
var (
@@ -163,7 +168,7 @@ func (c *client) requestWithRetry(
163
168
)
164
169
for idx := 0 ; idx < len (c .pdAddrs ); idx ++ {
165
170
addr = c .pdAddrs [idx ]
166
- err = c .request (ctx , name , addr , uri , res )
171
+ err = c .request (ctx , name , fmt . Sprintf ( "%s%s" , addr , uri ), method , res )
167
172
if err == nil {
168
173
break
169
174
}
@@ -175,16 +180,15 @@ func (c *client) requestWithRetry(
175
180
176
181
func (c * client ) request (
177
182
ctx context.Context ,
178
- name , addr , uri string ,
183
+ name , url , method string ,
179
184
res interface {},
180
185
) error {
181
- reqURL := fmt .Sprintf ("%s%s" , addr , uri )
182
186
logFields := []zap.Field {
183
187
zap .String ("name" , name ),
184
- zap .String ("url" , reqURL ),
188
+ zap .String ("url" , url ),
185
189
}
186
190
log .Debug ("[pd] request the http url" , logFields ... )
187
- req , err := http .NewRequestWithContext (ctx , http . MethodGet , reqURL , nil )
191
+ req , err := http .NewRequestWithContext (ctx , method , url , nil )
188
192
if err != nil {
189
193
log .Error ("[pd] create http request failed" , append (logFields , zap .Error (err ))... )
190
194
return errors .Trace (err )
@@ -229,7 +233,7 @@ func (c *client) request(
229
233
// GetRegionByID gets the region info by ID.
230
234
func (c * client ) GetRegionByID (ctx context.Context , regionID uint64 ) (* RegionInfo , error ) {
231
235
var region RegionInfo
232
- err := c .requestWithRetry (ctx , "GetRegionByID" , RegionByID (regionID ), & region )
236
+ err := c .requestWithRetry (ctx , "GetRegionByID" , RegionByID (regionID ), http . MethodGet , & region )
233
237
if err != nil {
234
238
return nil , err
235
239
}
@@ -239,7 +243,7 @@ func (c *client) GetRegionByID(ctx context.Context, regionID uint64) (*RegionInf
239
243
// GetRegionByKey gets the region info by key.
240
244
func (c * client ) GetRegionByKey (ctx context.Context , key []byte ) (* RegionInfo , error ) {
241
245
var region RegionInfo
242
- err := c .requestWithRetry (ctx , "GetRegionByKey" , RegionByKey (key ), & region )
246
+ err := c .requestWithRetry (ctx , "GetRegionByKey" , RegionByKey (key ), http . MethodGet , & region )
243
247
if err != nil {
244
248
return nil , err
245
249
}
@@ -249,7 +253,7 @@ func (c *client) GetRegionByKey(ctx context.Context, key []byte) (*RegionInfo, e
249
253
// GetRegions gets the regions info.
250
254
func (c * client ) GetRegions (ctx context.Context ) (* RegionsInfo , error ) {
251
255
var regions RegionsInfo
252
- err := c .requestWithRetry (ctx , "GetRegions" , Regions , & regions )
256
+ err := c .requestWithRetry (ctx , "GetRegions" , Regions , http . MethodGet , & regions )
253
257
if err != nil {
254
258
return nil , err
255
259
}
@@ -259,7 +263,7 @@ func (c *client) GetRegions(ctx context.Context) (*RegionsInfo, error) {
259
263
// GetRegionsByKey gets the regions info by key range. If the limit is -1, it will return all regions within the range.
260
264
func (c * client ) GetRegionsByKey (ctx context.Context , startKey , endKey []byte , limit int ) (* RegionsInfo , error ) {
261
265
var regions RegionsInfo
262
- err := c .requestWithRetry (ctx , "GetRegionsByKey" , RegionsByKey (startKey , endKey , limit ), & regions )
266
+ err := c .requestWithRetry (ctx , "GetRegionsByKey" , RegionsByKey (startKey , endKey , limit ), http . MethodGet , & regions )
263
267
if err != nil {
264
268
return nil , err
265
269
}
@@ -269,7 +273,7 @@ func (c *client) GetRegionsByKey(ctx context.Context, startKey, endKey []byte, l
269
273
// GetRegionsByStoreID gets the regions info by store ID.
270
274
func (c * client ) GetRegionsByStoreID (ctx context.Context , storeID uint64 ) (* RegionsInfo , error ) {
271
275
var regions RegionsInfo
272
- err := c .requestWithRetry (ctx , "GetRegionsByStoreID" , RegionsByStoreID (storeID ), & regions )
276
+ err := c .requestWithRetry (ctx , "GetRegionsByStoreID" , RegionsByStoreID (storeID ), http . MethodGet , & regions )
273
277
if err != nil {
274
278
return nil , err
275
279
}
@@ -279,7 +283,7 @@ func (c *client) GetRegionsByStoreID(ctx context.Context, storeID uint64) (*Regi
279
283
// GetHotReadRegions gets the hot read region statistics info.
280
284
func (c * client ) GetHotReadRegions (ctx context.Context ) (* StoreHotPeersInfos , error ) {
281
285
var hotReadRegions StoreHotPeersInfos
282
- err := c .requestWithRetry (ctx , "GetHotReadRegions" , HotRead , & hotReadRegions )
286
+ err := c .requestWithRetry (ctx , "GetHotReadRegions" , HotRead , http . MethodGet , & hotReadRegions )
283
287
if err != nil {
284
288
return nil , err
285
289
}
@@ -289,23 +293,57 @@ func (c *client) GetHotReadRegions(ctx context.Context) (*StoreHotPeersInfos, er
289
293
// GetHotWriteRegions gets the hot write region statistics info.
290
294
func (c * client ) GetHotWriteRegions (ctx context.Context ) (* StoreHotPeersInfos , error ) {
291
295
var hotWriteRegions StoreHotPeersInfos
292
- err := c .requestWithRetry (ctx , "GetHotWriteRegions" , HotWrite , & hotWriteRegions )
296
+ err := c .requestWithRetry (ctx , "GetHotWriteRegions" , HotWrite , http . MethodGet , & hotWriteRegions )
293
297
if err != nil {
294
298
return nil , err
295
299
}
296
300
return & hotWriteRegions , nil
297
301
}
298
302
303
+ // GetRegionStatusByKey gets the region status by key range.
304
+ func (c * client ) GetRegionStatusByKey (ctx context.Context , startKey , endKey []byte ) (* RegionStats , error ) {
305
+ var regionStats RegionStats
306
+ err := c .requestWithRetry (
307
+ ctx , "GetRegionStatusByKey" ,
308
+ RegionStatsByStartEndKey (string (startKey ), string (endKey )), http .MethodGet ,
309
+ & regionStats ,
310
+ )
311
+ if err != nil {
312
+ return nil , err
313
+ }
314
+ return & regionStats , nil
315
+ }
316
+
299
317
// GetStores gets the stores info.
300
318
func (c * client ) GetStores (ctx context.Context ) (* StoresInfo , error ) {
301
319
var stores StoresInfo
302
- err := c .requestWithRetry (ctx , "GetStores" , Stores , & stores )
320
+ err := c .requestWithRetry (ctx , "GetStores" , Stores , http . MethodGet , & stores )
303
321
if err != nil {
304
322
return nil , err
305
323
}
306
324
return & stores , nil
307
325
}
308
326
327
+ // GetPlacementRulesByGroup gets the placement rules by group.
328
+ func (c * client ) GetPlacementRulesByGroup (ctx context.Context , group string ) ([]* Rule , error ) {
329
+ var rules []* Rule
330
+ err := c .requestWithRetry (ctx , "GetPlacementRulesByGroup" , PlacementRulesByGroup (group ), http .MethodGet , & rules )
331
+ if err != nil {
332
+ return nil , err
333
+ }
334
+ return rules , nil
335
+ }
336
+
337
+ // SetPlacementRule sets the placement rule.
338
+ func (c * client ) SetPlacementRule (ctx context.Context , rule * Rule ) error {
339
+ return c .requestWithRetry (ctx , "SetPlacementRule" , PlacementRule , http .MethodPost , nil )
340
+ }
341
+
342
+ // DeletePlacementRule deletes the placement rule.
343
+ func (c * client ) DeletePlacementRule (ctx context.Context , group , id string ) error {
344
+ return c .requestWithRetry (ctx , "DeletePlacementRule" , PlacementRuleByGroupAndID (group , id ), http .MethodDelete , nil )
345
+ }
346
+
309
347
// GetMinResolvedTSByStoresIDs get min-resolved-ts by stores IDs.
310
348
func (c * client ) GetMinResolvedTSByStoresIDs (ctx context.Context , storeIDs []uint64 ) (uint64 , map [uint64 ]uint64 , error ) {
311
349
uri := MinResolvedTSPrefix
@@ -326,7 +364,7 @@ func (c *client) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs []uin
326
364
IsRealTime bool `json:"is_real_time,omitempty"`
327
365
StoresMinResolvedTS map [uint64 ]uint64 `json:"stores_min_resolved_ts"`
328
366
}{}
329
- err := c .requestWithRetry (ctx , "GetMinResolvedTSByStoresIDs" , uri , & resp )
367
+ err := c .requestWithRetry (ctx , "GetMinResolvedTSByStoresIDs" , uri , http . MethodGet , & resp )
330
368
if err != nil {
331
369
return 0 , nil , err
332
370
}
@@ -335,3 +373,8 @@ func (c *client) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs []uin
335
373
}
336
374
return resp .MinResolvedTS , resp .StoresMinResolvedTS , nil
337
375
}
376
+
377
+ // AccelerateSchedule accelerates the scheduling of the regions within the given key range.
378
+ func (c * client ) AccelerateSchedule (ctx context.Context , startKey , endKey []byte ) error {
379
+ return c .requestWithRetry (ctx , "AccelerateSchedule" , accelerateSchedule , http .MethodPost , nil )
380
+ }
0 commit comments