-
Notifications
You must be signed in to change notification settings - Fork 109
*: implement LOCK and UNLOCK of tables #448
Conversation
@@ -61,6 +61,10 @@ func (h *Handler) ConnectionClosed(c *mysql.Conn) { | |||
delete(h.c, c.ConnectionID) | |||
h.mu.Unlock() | |||
|
|||
if err := h.e.Catalog.UnlockTables(nil, c.ConnectionID); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the tables would keep locked forever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it fails, you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you can retry UNLOCK TABLES
. If it fails it's because the tables Unlock
failed, so nothing we can do there, as the implementation of that method depends on the tables.
@erizocosmico can you rebase please? |
c.locks[id][db] = make(tableLocks) | ||
} | ||
|
||
c.locks[id][db][table] = struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we plan (in the future) lock all DB or Session (not only tables, rows), but if yes then maybe flat structure, e.g. c.locks["id.db.table"]
may work better, because you don't need to create nested structs. Moreover when you unlock you have to propagate this info to the higher levels, instead of delete one key.
But frankly it's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, we use the elements of each separate step. c.locks[id] to get all the locks for a session and then c.locks[id][db] to get the tables. We can't do that with a single key
|
||
func (l *lockableTable) Lock(ctx *sql.Context, write bool) error { | ||
if write { | ||
l.writeLocks++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we count locks?
Isn't it 1/0 (SET/UNSET) for the same session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...or is it just counter for number of read/writes for unlock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is just a counter for the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we add this statement to readonly.go rule?
sql/parse/parse_test.go
Outdated
@@ -788,6 +789,34 @@ var fixtures = map[string]sql.Node{ | |||
}, | |||
plan.NewUnresolvedTable("bar", "foo"), | |||
), | |||
`UNLOCK TABLES`: plan.NewUnlockTables(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you test table names with numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
decb850
to
eb15e75
Compare
Rebased @ajnavarro |
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
fe2182a
to
ed3102f
Compare
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@ajnavarro added to readonly |
Closes #410