-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix errors and add isolation tests for OSM API
This commit fixes two issues with the osm range update API: 1. Deadlock between two concurrent range updates. Two transactions concurrently attempting to update the range of the OSM chunk by calling hypertable_osm_range_update would deadlock because the dimension slice tuple was first locked with a FOR KEY SHARE lock, then a FOR UPDATE lock was requested before proceeding with the dimension slice tuple udpate. This commit fixes the deadlock by taking FOR UPDATE lock on the tuple from the start, before proceeding to update it. 2. Tuple concurrently updated error for hypertable tuple. When one session tries to update the range of the OSM chunk and another enables compression on the hypertable, the update failed with tuple concurrently updated error. This commit fixes this by first locking the hypertable tuple with a FOR UPDATE lock before proceeding to UPDATE it. Isolation tests for OSM range API are also added.
- Loading branch information
Showing
7 changed files
with
395 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
Parsed test spec with 8 sessions | ||
|
||
starting permutation: LockDimSliceTuple UR1b UR1u UR2b UR2u UnlockDimSliceTuple UR1c UR2c | ||
step LockDimSliceTuple: | ||
BEGIN; | ||
SELECT range_start, range_end FROM _timescaledb_catalog.dimension_slice | ||
WHERE id IN ( SELECT ds.id FROM | ||
_timescaledb_catalog.chunk ch, _timescaledb_catalog.chunk_constraint cc, | ||
_timescaledb_catalog.dimension_slice ds, _timescaledb_catalog.hypertable ht | ||
WHERE ht.table_name like 'osm_test' AND cc.chunk_id = ch.id AND ht.id = ch.hypertable_id | ||
AND ds.id = cc.dimension_slice_id AND ch.osm_chunk = true | ||
) FOR UPDATE; | ||
|
||
range_start| range_end | ||
-------------------+------------------- | ||
9223372036854775806|9223372036854775807 | ||
(1 row) | ||
|
||
step UR1b: BEGIN; | ||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); <waiting ...> | ||
step UR2b: BEGIN; | ||
step UR2u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); <waiting ...> | ||
step UnlockDimSliceTuple: ROLLBACK; | ||
step UR1u: <... completed> | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step UR1c: COMMIT; | ||
step UR2u: <... completed> | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step UR2c: COMMIT; | ||
|
||
starting permutation: LockDimSliceTuple DTb UR1b DropOsmChunk UR1u UnlockDimSliceTuple DTc UR1c | ||
step LockDimSliceTuple: | ||
BEGIN; | ||
SELECT range_start, range_end FROM _timescaledb_catalog.dimension_slice | ||
WHERE id IN ( SELECT ds.id FROM | ||
_timescaledb_catalog.chunk ch, _timescaledb_catalog.chunk_constraint cc, | ||
_timescaledb_catalog.dimension_slice ds, _timescaledb_catalog.hypertable ht | ||
WHERE ht.table_name like 'osm_test' AND cc.chunk_id = ch.id AND ht.id = ch.hypertable_id | ||
AND ds.id = cc.dimension_slice_id AND ch.osm_chunk = true | ||
) FOR UPDATE; | ||
|
||
range_start| range_end | ||
-------------------+------------------- | ||
9223372036854775806|9223372036854775807 | ||
(1 row) | ||
|
||
step DTb: BEGIN; | ||
step UR1b: BEGIN; | ||
step DropOsmChunk: | ||
SELECT _timescaledb_functions.drop_chunk(chunk_table::regclass) | ||
FROM ( | ||
SELECT format('%I.%I', c.schema_name, c.table_name) as chunk_table | ||
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.hypertable ht | ||
WHERE ht.id = c.hypertable_id AND ht.table_name = 'osm_test' | ||
) sq; | ||
<waiting ...> | ||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); <waiting ...> | ||
step UnlockDimSliceTuple: ROLLBACK; | ||
step DropOsmChunk: <... completed> | ||
drop_chunk | ||
---------- | ||
t | ||
(1 row) | ||
|
||
step DTc: COMMIT; | ||
step UR1u: <... completed> | ||
ERROR: chunk deleted by other transaction | ||
step UR1c: COMMIT; | ||
|
||
starting permutation: LockDimSliceTuple DTb UR1b UR1u DropOsmChunk UnlockDimSliceTuple UR1c DTc | ||
step LockDimSliceTuple: | ||
BEGIN; | ||
SELECT range_start, range_end FROM _timescaledb_catalog.dimension_slice | ||
WHERE id IN ( SELECT ds.id FROM | ||
_timescaledb_catalog.chunk ch, _timescaledb_catalog.chunk_constraint cc, | ||
_timescaledb_catalog.dimension_slice ds, _timescaledb_catalog.hypertable ht | ||
WHERE ht.table_name like 'osm_test' AND cc.chunk_id = ch.id AND ht.id = ch.hypertable_id | ||
AND ds.id = cc.dimension_slice_id AND ch.osm_chunk = true | ||
) FOR UPDATE; | ||
|
||
range_start| range_end | ||
-------------------+------------------- | ||
9223372036854775806|9223372036854775807 | ||
(1 row) | ||
|
||
step DTb: BEGIN; | ||
step UR1b: BEGIN; | ||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); <waiting ...> | ||
step DropOsmChunk: | ||
SELECT _timescaledb_functions.drop_chunk(chunk_table::regclass) | ||
FROM ( | ||
SELECT format('%I.%I', c.schema_name, c.table_name) as chunk_table | ||
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.hypertable ht | ||
WHERE ht.id = c.hypertable_id AND ht.table_name = 'osm_test' | ||
) sq; | ||
<waiting ...> | ||
step UnlockDimSliceTuple: ROLLBACK; | ||
step UR1u: <... completed> | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step UR1c: COMMIT; | ||
step DropOsmChunk: <... completed> | ||
drop_chunk | ||
---------- | ||
t | ||
(1 row) | ||
|
||
step DTc: COMMIT; | ||
|
||
starting permutation: LHTb LockHypertableTuple Cb UR1b Cenable UR1u UnlockHypertableTuple Ccommit UR1c | ||
step LHTb: BEGIN; | ||
step LockHypertableTuple: | ||
SELECT table_name, compression_state, compressed_hypertable_id, status | ||
FROM _timescaledb_catalog.hypertable WHERE table_name = 'osm_test' FOR UPDATE; | ||
|
||
table_name|compression_state|compressed_hypertable_id|status | ||
----------+-----------------+------------------------+------ | ||
osm_test | 0| | 3 | ||
(1 row) | ||
|
||
step Cb: BEGIN; | ||
step UR1b: BEGIN; | ||
step Cenable: | ||
ALTER TABLE osm_test set (timescaledb.compress); | ||
<waiting ...> | ||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); <waiting ...> | ||
step UnlockHypertableTuple: ROLLBACK; | ||
step Cenable: <... completed> | ||
step Ccommit: COMMIT; | ||
step UR1u: <... completed> | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step UR1c: COMMIT; | ||
|
||
starting permutation: Ab UR1b UR1u Aadd UR1c Ac | ||
step Ab: BEGIN; | ||
step UR1b: BEGIN; | ||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step Aadd: ALTER TABLE osm_test ADD COLUMN b INTEGER; | ||
step UR1c: COMMIT; | ||
step Ac: COMMIT; | ||
|
||
starting permutation: Ab UR1b Aadd UR1u UR1c Ac | ||
step Ab: BEGIN; | ||
step UR1b: BEGIN; | ||
step Aadd: ALTER TABLE osm_test ADD COLUMN b INTEGER; | ||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step UR1c: COMMIT; | ||
step Ac: COMMIT; | ||
|
||
starting permutation: LHTb Utest2b UR1b LockHypertableTuple UR1u Utest2u Utest2c UnlockHypertableTuple UR1c | ||
step LHTb: BEGIN; | ||
step Utest2b: BEGIN; | ||
step UR1b: BEGIN; | ||
step LockHypertableTuple: | ||
SELECT table_name, compression_state, compressed_hypertable_id, status | ||
FROM _timescaledb_catalog.hypertable WHERE table_name = 'osm_test' FOR UPDATE; | ||
|
||
table_name|compression_state|compressed_hypertable_id|status | ||
----------+-----------------+------------------------+------ | ||
osm_test | 0| | 3 | ||
(1 row) | ||
|
||
step UR1u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test', 0, 10); <waiting ...> | ||
step Utest2u: SELECT _timescaledb_functions.hypertable_osm_range_update('osm_test2', 0, 20); | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step Utest2c: COMMIT; | ||
step UnlockHypertableTuple: ROLLBACK; | ||
step UR1u: <... completed> | ||
hypertable_osm_range_update | ||
--------------------------- | ||
f | ||
(1 row) | ||
|
||
step UR1c: COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.