Skip to content

Commit

Permalink
proxy: forbid radon cleanup admin when readonly #578
Browse files Browse the repository at this point in the history
[summary]
Part of radon admin operations api need to add restrictions when radon in readonly.
[test case]
src/proxy/admin_cleanup_test.go
[patch codecov]
src/proxy/query.go 88.2%
  • Loading branch information
zhyass authored and BohuTANG committed Mar 18, 2020
1 parent 926da9a commit d08fd5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/proxy/admin_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,22 @@ func TestCleanupDropErr(t *testing.T) {
assert.NotNil(t, err)
}
}

func TestCleanupReadOnly(t *testing.T) {
log := xlog.NewStdLog(xlog.Level(xlog.PANIC))
fakedbs, proxy, cleanup := MockProxy(log)
defer cleanup()

address := proxy.Address()
client, err := driver.NewConn("mock", "mock", address, "", "utf8")
assert.Nil(t, err)

// set radon readonly.
proxy.SetReadOnly(true)
query := "radon cleanup"
fakedbs.AddQuery(query, &sqltypes.Result{})
_, err = client.FetchAll(query, -1)
want := "The MySQL server is running with the --read-only option so it cannot execute this statement (errno 1290) (sqlstate 42000)"
got := err.Error()
assert.Equal(t, want, got)
}
2 changes: 1 addition & 1 deletion src/proxy/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (spanner *Spanner) IsDDL(node sqlparser.Statement) bool {
func (spanner *Spanner) IsAdminCmd(node sqlparser.Statement) bool {
if node, ok := node.(*sqlparser.Radon); ok {
switch node.Action {
case sqlparser.AttachStr, sqlparser.DetachStr, sqlparser.ReshardStr:
case sqlparser.AttachStr, sqlparser.DetachStr, sqlparser.ReshardStr, sqlparser.CleanupStr:
return true
}
}
Expand Down

0 comments on commit d08fd5e

Please sign in to comment.