Skip to content

Commit

Permalink
WL#11417 - DevAPI : Support locking modes: NOWAIT and SKIP LOCKED
Browse files Browse the repository at this point in the history
Add support for NOWAIT and SKIP LOCKED options when doing a locking read
in the X plugin.

RB: 18440
Reviewed by: Grzegorz Szwarc <grzegorz.szwarc@oracle.com>
Reviewed by: Lukasz Kotula <lukasz.kotula@oracle.com>

Approved by: Horst Hunger <horst.hunger@oracle.com>
  • Loading branch information
Tomasz Stepniak committed Jan 25, 2018
1 parent 13bf7c4 commit 9b2f121
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 396 deletions.
14 changes: 14 additions & 0 deletions mysql-test/suite/x/r/features.result
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ send Mysqlx.Expect.Open {

ok

[Verification of Mysqlx.Crud.Find::locking_options (17.13)]
send Mysqlx.Expect.Open {
cond {
condition_key: 2
condition_value: "17.13"
}
}

ok

[Verification of all features in single request]
send Mysqlx.Expect.Open {
cond {
Expand All @@ -28,6 +38,10 @@ send Mysqlx.Expect.Open {
condition_key: 2
condition_value: "17.12"
}
cond {
condition_key: 2
condition_value: "17.13"
}
}

ok
Expand Down
172 changes: 167 additions & 5 deletions mysql-test/suite/x/r/find_row_locking.result
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

1 rows affected

1 rows affected

0 rows affected
connecting...
active session is now 'session1'
Expand All @@ -32,7 +34,7 @@ switched to session session2

0 rows affected
doc
{"a": 1, "_id": "2"}
{"a": 2, "_id": "2"}
command ok
doc
{"a": 1, "_id": "1"}
Expand All @@ -58,7 +60,7 @@ switched to session session2

0 rows affected
doc
{"a": 1, "_id": "2"}
{"a": 2, "_id": "2"}
command ok
Got expected error: Lock wait timeout exceeded; try restarting transaction (code 1205)
Verify [Expecting performance_schema.data_locks to be not empty]
Expand All @@ -82,10 +84,10 @@ switched to session session2

0 rows affected
doc
{"a": 1, "_id": "2"}
{"a": 2, "_id": "2"}
command ok
doc
{"a": 1, "_id": "3"}
{"a": 30, "_id": "3"}
command ok
Got expected error: Lock wait timeout exceeded; try restarting transaction (code 1205)
Verify [Expecting performance_schema.data_locks to be not empty]
Expand All @@ -109,7 +111,7 @@ switched to session session2

0 rows affected
doc
{"a": 1, "_id": "2"}
{"a": 2, "_id": "2"}
command ok
Got expected error: Lock wait timeout exceeded; try restarting transaction (code 1205)
Verify [Expecting performance_schema.data_locks to be not empty]
Expand All @@ -120,6 +122,166 @@ switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### Locking with aggregate #########
######### Shared lock with grouping #########
switched to session session1
Verify [Expecting performance_schema.data_locks to be empty]

0 rows affected
doc
{"a": 1, "_id": "1"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session2

0 rows affected
doc
{"a": 1}
{"a": 2}
{"a": 30}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session1

0 rows affected
switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### Exclusive lock with grouping #########
switched to session session1
Verify [Expecting performance_schema.data_locks to be empty]

0 rows affected
doc
{"a": 1, "_id": "1"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session2

0 rows affected
doc
{"a": 1}
{"a": 2}
{"a": 30}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session1

0 rows affected
switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### Locking options #########
######### Shared lock with NOWAIT #########
switched to session session1
Verify [Expecting performance_schema.data_locks to be empty]

0 rows affected
doc
{"a": 1, "_id": "1"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session2

0 rows affected
Got expected error: Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set. (code 3572)
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session1

0 rows affected
switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### Shared lock with SKIP LOCKED #########
switched to session session1
Verify [Expecting performance_schema.data_locks to be empty]

0 rows affected
doc
{"a": 1, "_id": "1"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session2

0 rows affected
doc
{"a": 2, "_id": "2"}
{"a": 30, "_id": "3"}
{"a": 30, "_id": "4"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session1

0 rows affected
switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### Exclusive lock with NOWAIT #########
switched to session session1
Verify [Expecting performance_schema.data_locks to be empty]

0 rows affected
doc
{"a": 1, "_id": "1"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session2

0 rows affected
Got expected error: Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set. (code 3572)
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session1

0 rows affected
switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### Exclusive lock with SKIP LOCKED #########
switched to session session1
Verify [Expecting performance_schema.data_locks to be empty]

0 rows affected
doc
{"a": 1, "_id": "1"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session2

0 rows affected
doc
{"a": 2, "_id": "2"}
{"a": 30, "_id": "3"}
{"a": 30, "_id": "4"}
command ok
Verify [Expecting performance_schema.data_locks to be not empty]
switched to session session1

0 rows affected
switched to session session2

0 rows affected
Verify [Expecting performance_schema.data_locks to be empty]
######### NOWAIT set but no locking #########
Mysqlx.Error {
severity: ERROR
code: 5169
msg: "Invalid \"find\" message, \"locking\" field is required when \"locking_options\" is set."
sql_state: "HY000"
}

######### SKIP LOCKED set but no locking #########
Mysqlx.Error {
severity: ERROR
code: 5169
msg: "Invalid \"find\" message, \"locking\" field is required when \"locking_options\" is set."
sql_state: "HY000"
}

closing session session2
Mysqlx.Ok {
msg: "bye!"
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/x/t/features.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Mysqlx.Expect.Close {
-->varlet %ALL_COND%
-->callmacro Verify_feature_existence Mysqlx.Crud.Insert::upsert 18.6
-->callmacro Verify_feature_existence Mysqlx.Crud.Find::locking 17.12
-->callmacro Verify_feature_existence Mysqlx.Crud.Find::locking_options 17.13
-->callmacro Verify_expect_open all features in single request %ALL_COND%
EOF

Expand Down
Loading

0 comments on commit 9b2f121

Please sign in to comment.