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

Remove conflicting sqlite tables that are "reserved" (shadow fts4 tables) #9003

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9003.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix 'object name reserved for internal use' errors with recent versions of SQLite.
11 changes: 11 additions & 0 deletions scripts-dev/make_full_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,23 @@ else
fi

# Delete schema_version, applied_schema_deltas and applied_module_schemas tables
# Also delete any shadow tables from fts4
# This needs to be done after synapse_port_db is run
echo "Dropping unwanted db tables..."
SQL="
DROP TABLE schema_version;
DROP TABLE applied_schema_deltas;
DROP TABLE applied_module_schemas;
DROP TABLE event_search_content;
DROP TABLE event_search_segments;
DROP TABLE event_search_segdir;
DROP TABLE event_search_docsize;
DROP TABLE event_search_stat;
DROP TABLE user_directory_search_content;
DROP TABLE user_directory_search_segments;
DROP TABLE user_directory_search_segdir;
DROP TABLE user_directory_search_docsize;
DROP TABLE user_directory_search_stat;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, there is documentation about this script at synapse/storage/databases/main/schema/full_schemas/README.md

Copy link
Contributor Author

@MadLittleMods MadLittleMods Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested these changes as the script seems to fail for me before it gets there. Also is there a way to run without a postgres username? (I had to comment that part of the shell script out)

$ ./scripts-dev/make_full_schema.sh -o ./

...

Creating port tables...
Setting up sequence generators...
scripts/synapse_port_db:630: RuntimeWarning: coroutine 'DatabasePool.runInteraction' was never awaited
  await self._setup_user_id_seq()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2021-01-04 17:48:57,303 - synapse_port_db - 704 - ERROR -
Traceback (most recent call last):
  File "scripts/synapse_port_db", line 631, in run
    await self._setup_events_stream_seqs()
  File "scripts/synapse_port_db", line 910, in _setup_events_stream_seqs
    return await self.postgres_store.db_pool.runInteraction(
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 632, in runInteraction
    result = await self.runWithConnection(
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 712, in runWithConnection
    return await make_deferred_yieldable(
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/threadpool.py", line 250, in inContext
    result = inContext.theWork()
  File "/Users/eric/Documents/github/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 "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 306, in _runWithConnection
    compat.reraise(excValue, excTraceback)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/compat.py", line 464, in reraise
    raise exception.with_traceback(traceback)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 297, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 707, in inner_func
    return func(db_conn, *args, **kwargs)
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 510, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "scripts/synapse_port_db", line 907, in _setup_events_stream_seqs_set_pos
    (curr_backward_id + 1,),
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
Traceback (most recent call last):
  File "scripts/synapse_port_db", line 631, in run
    await self._setup_events_stream_seqs()
  File "scripts/synapse_port_db", line 910, in _setup_events_stream_seqs
    return await self.postgres_store.db_pool.runInteraction(
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 632, in runInteraction
    result = await self.runWithConnection(
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 712, in runWithConnection
    return await make_deferred_yieldable(
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/threadpool.py", line 250, in inContext
    result = inContext.theWork()
  File "/Users/eric/Documents/github/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 "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 306, in _runWithConnection
    compat.reraise(excValue, excTraceback)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/python/compat.py", line 464, in reraise
    raise exception.with_traceback(traceback)
  File "/Users/eric/Documents/github/synapse/env/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 297, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 707, in inner_func
    return func(db_conn, *args, **kwargs)
  File "/Users/eric/Documents/github/synapse/synapse/storage/database.py", line 510, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "scripts/synapse_port_db", line 907, in _setup_events_stream_seqs_set_pos
    (curr_backward_id + 1,),
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

"
sqlite3 "$SQLITE_DB" <<< "$SQL"
psql $POSTGRES_DB_NAME -U "$POSTGRES_USERNAME" -w <<< "$SQL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ CREATE TABLE IF NOT EXISTS "user_threepids" ( user_id TEXT NOT NULL, medium TEXT
CREATE INDEX user_threepids_user_id ON user_threepids(user_id);
CREATE VIRTUAL TABLE event_search USING fts4 ( event_id, room_id, sender, key, value )
/* event_search(event_id,room_id,sender,"key",value) */;
CREATE TABLE IF NOT EXISTS 'event_search_content'(docid INTEGER PRIMARY KEY, 'c0event_id', 'c1room_id', 'c2sender', 'c3key', 'c4value');
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
CREATE TABLE IF NOT EXISTS 'event_search_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
CREATE TABLE IF NOT EXISTS 'event_search_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
CREATE TABLE IF NOT EXISTS 'event_search_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
CREATE TABLE IF NOT EXISTS 'event_search_stat'(id INTEGER PRIMARY KEY, value BLOB);
CREATE TABLE guest_access( event_id TEXT NOT NULL, room_id TEXT NOT NULL, guest_access TEXT NOT NULL, UNIQUE (event_id) );
CREATE TABLE history_visibility( event_id TEXT NOT NULL, room_id TEXT NOT NULL, history_visibility TEXT NOT NULL, UNIQUE (event_id) );
CREATE TABLE room_tags( user_id TEXT NOT NULL, room_id TEXT NOT NULL, tag TEXT NOT NULL, content TEXT NOT NULL, CONSTRAINT room_tag_uniqueness UNIQUE (user_id, room_id, tag) );
Expand Down Expand Up @@ -149,11 +144,6 @@ CREATE INDEX device_lists_outbound_last_success_idx ON device_lists_outbound_las
CREATE TABLE user_directory_stream_pos ( Lock CHAR(1) NOT NULL DEFAULT 'X' UNIQUE, stream_id BIGINT, CHECK (Lock='X') );
CREATE VIRTUAL TABLE user_directory_search USING fts4 ( user_id, value )
/* user_directory_search(user_id,value) */;
CREATE TABLE IF NOT EXISTS 'user_directory_search_content'(docid INTEGER PRIMARY KEY, 'c0user_id', 'c1value');
CREATE TABLE IF NOT EXISTS 'user_directory_search_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
CREATE TABLE IF NOT EXISTS 'user_directory_search_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
CREATE TABLE IF NOT EXISTS 'user_directory_search_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
CREATE TABLE IF NOT EXISTS 'user_directory_search_stat'(id INTEGER PRIMARY KEY, value BLOB);
CREATE TABLE blocked_rooms ( room_id TEXT NOT NULL, user_id TEXT NOT NULL );
CREATE UNIQUE INDEX blocked_rooms_idx ON blocked_rooms(room_id);
CREATE TABLE IF NOT EXISTS "local_media_repository_url_cache"( url TEXT, response_code INTEGER, etag TEXT, expires_ts BIGINT, og TEXT, media_id TEXT, download_ts BIGINT );
Expand Down