Commit cb06186b authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

tsio: use a postgres lock at series creation time

Concurrent series table creation yields a deadlock,
probably related to the foreign key to the `changeset-series`
common table. We must serialize creation (without affecting
high-level code).
parent c0a9bd3e03ad
......@@ -1258,8 +1258,9 @@ def test_parallel(engine, tsh):
]
errors = []
ns = tsh.namespace
def insert(ts, name, author):
tsh = TimeSerie()
tsh = TimeSerie(namespace=ns)
with engine.begin() as cn:
try:
tsh.insert(cn, ts, name, author)
......@@ -1267,5 +1268,7 @@ def test_parallel(engine, tsh):
errors.append(e)
pool(insert, args)
# we got a deadlock
assert len(errors)
assert not len(errors)
for name in 'abcd':
assert len(tsh.get(engine, name))
......@@ -30,6 +30,7 @@ class TimeSerie(SeriesServices):
metadatacache = None
registry_map = None
serie_tablename = None
create_lock_id = None
def __init__(self, namespace='tsh'):
self.namespace = namespace
......@@ -38,6 +39,7 @@ class TimeSerie(SeriesServices):
self.metadatacache = {}
self.registry_map = {}
self.serie_tablename = {}
self.create_lock_id = sum(ord(c) for c in namespace)
def insert(self, cn, newts, seriename, author,
metadata=None,
......@@ -415,6 +417,11 @@ class TimeSerie(SeriesServices):
# initial insertion
if len(newts) == 0:
return None
# at creation time we take an exclusive lock to avoid
# a deadlock on created tables against the changeset-series fk
cn.execute(
'select pg_advisory_xact_lock({})'.format(self.create_lock_id)
)
self._register_serie(cn, seriename, newts)
snapshot = Snapshot(cn, self, seriename)
csid = self._newchangeset(cn, author, insertion_date, metadata)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment