Skip to content

Commit b94c78e

Browse files
committed
Add comments about TiDB syntax
1 parent b104c63 commit b94c78e

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

mysql/resource_ti_resource_group.go

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func resourceTiResourceGroup() *schema.Resource {
6868
Required: true,
6969
ForceNew: true,
7070
},
71+
// TODO: allow a centralized way to check if there's capacity remaining to use
7172
"resource_units": {
7273
Type: schema.TypeInt,
7374
Required: true,
@@ -82,10 +83,9 @@ func resourceTiResourceGroup() *schema.Resource {
8283
//},
8384
},
8485
"priority": {
85-
Type: schema.TypeString,
86-
Default: DefaultResourceGroup.Priority,
87-
ForceNew: false,
88-
// TiDB has these as capitalized but we lowercase for user consistency
86+
Type: schema.TypeString,
87+
Default: DefaultResourceGroup.Priority,
88+
ForceNew: false,
8989
ValidateFunc: validation.StringInSlice([]string{"high", "medium", "low"}, false),
9090
Optional: true,
9191
},
@@ -95,15 +95,46 @@ func resourceTiResourceGroup() *schema.Resource {
9595
ForceNew: false,
9696
Optional: true,
9797
},
98+
/*
99+
QUERY_LIMIT=(EXEC_ELAPSED='60s', ACTION=KILL, WATCH=EXACT DURATION='10m')
100+
*/
98101
"query_limit": {
99102
Type: schema.TypeString,
100103
Default: DefaultResourceGroup.QueryLimit,
101104
ForceNew: false,
102105
Optional: true,
103-
// TODO: add validation
104-
// ValidateFunc: validation.StringInSlice([]string{"HIGH", "MEDIUM", "LOW"}, true),
106+
/*
107+
108+
ValidateFunc: func(i interface{}, s string) ([]string, []error) {
109+
arg := i.(string)
110+
pieces := strings.Split(arg, ",")
111+
for _, p := range pieces {
112+
kv := strings.SplitN(strings.TrimSpace(p), "=", 2)
113+
k := kv[0]
114+
v := kv[1]
115+
switch(k) {
116+
case "EXEC_ELAPSED":
117+
// must be 60s format
118+
// regex for \d+s
119+
break
120+
case "ACTION":
121+
options := []string{"DRYRUN", "COOLDOWN", "KILL"}
122+
slice.Includes()
123+
124+
break
125+
case "WATCH":
126+
// WATCH=SIMILAR DURATION '60s' where SIMILAR | EXACT | PLAN
127+
break
128+
default:
129+
// throw error
130+
131+
132+
}
133+
}
134+
*/
135+
},
105136
},
106-
// TODO: include query limits and background
137+
// TODO: include background
107138
},
108139
}
109140
}
@@ -211,7 +242,13 @@ func DeleteResourceGroup(ctx context.Context, d *schema.ResourceData, meta inter
211242
func getResourceGroupFromDB(db *sql.DB, name string) (ResourceGroup, error) {
212243
rg := ResourceGroup{Name: name}
213244

214-
query := `SELECT NAME, RU_PER_SEC, LOWER(PRIORITY), if(BURSTABLE = 'YES', TRUE, FALSE), IFNULL(QUERY_LIMIT,"()") FROM information_schema.resource_groups WHERE NAME = ?`
245+
/*
246+
Coerce types on SQL side into good types for golang
247+
Burstable is a varchar(3) so we coerce to BOOLEAN
248+
QUERY_LIMIT is nullable in DB, but we coerce to standard "empty" string type of "()"
249+
Lowercase priority for less configuration variability
250+
*/
251+
query := `SELECT NAME, RU_PER_SEC, LOWER(PRIORITY), BURSTABLE = 'YES' as BURSTABLE, IFNULL(QUERY_LIMIT,"()") FROM information_schema.resource_groups WHERE NAME = ?`
215252

216253
ctx := context.Background()
217254
tflog.SetField(ctx, "query", query)

0 commit comments

Comments
 (0)