Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Port script fails when DB has no backfilled events. #8618

Closed
erikjohnston opened this issue Oct 21, 2020 · 0 comments · Fixed by #8729
Closed

Port script fails when DB has no backfilled events. #8618

erikjohnston opened this issue Oct 21, 2020 · 0 comments · Fixed by #8729
Assignees
Labels
z-bug (Deprecated Label)

Comments

@erikjohnston
Copy link
Member

Traceback (most recent call last):
  File "/home/twilight/temp/synapse/env/bin/synapse_port_db", line 632, in run
    await self._setup_events_stream_seqs()
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/synapse/storage/database.py", line 569, in runInteraction
    result = await self.runWithConnection(
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/synapse/storage/database.py", line 646, in runWithConnection
    return await make_deferred_yieldable(
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/python/threadpool.py", line 250, in inContext
    result = inContext.theWork()
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/python/threadpool.py", line 266, in <lambda>
    inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 306, in _runWithConnection
    compat.reraise(excValue, excTraceback)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/python/compat.py", line 464, in reraise
    raise exception.with_traceback(traceback)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 297, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/synapse/storage/database.py", line 641, in inner_func
    return func(conn, *args, **kwargs)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/synapse/storage/database.py", line 447, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "/home/twilight/temp/synapse/env/bin/synapse_port_db", line 823, in r
    txn.execute(
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/synapse/storage/database.py", line 212, in execute
    self._do_execute(self.txn.execute, sql, *args)
  File "/home/twilight/temp/synapse/env/lib/python3.8/site-packages/synapse/storage/database.py", line 238, in _do_execute
    return func(sql, *args)
psycopg2.errors.InvalidParameterValue: RESTART value (-1) cannot be less than MINVALUE (1)

Fix is:

diff --git a/scripts/synapse_port_db b/scripts/synapse_port_db
index 6c7664ad4..9794d004f 100755
--- a/scripts/synapse_port_db
+++ b/scripts/synapse_port_db
@@ -818,7 +818,7 @@ class Porter(object):
                     "ALTER SEQUENCE events_stream_seq RESTART WITH %s", (next_id,)
                 )
 
-            txn.execute("SELECT -MIN(stream_ordering) FROM events")
+            txn.execute("SELECT GREATEST(-MIN(stream_ordering), 1) FROM events")
             curr_id = txn.fetchone()[0]
             if curr_id:
                 next_id = curr_id + 1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
z-bug (Deprecated Label)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants