Don't use multiple UNIQUE constraints; it will cause deadlocks
This commit is contained in:
parent
c8d3f6486d
commit
0af5f5efaf
|
@ -837,11 +837,11 @@ class SQLBaseStore(object):
|
||||||
return curr_time
|
return curr_time
|
||||||
|
|
||||||
logger.debug("Got js: %r", js)
|
logger.debug("Got js: %r", js)
|
||||||
d = json.loads(js)
|
d = json.loads(str(js).decode("utf8"))
|
||||||
start_time = update_counter("decode_json", start_time)
|
start_time = update_counter("decode_json", start_time)
|
||||||
|
|
||||||
logger.debug("Got internal_metadata: %r", internal_metadata)
|
logger.debug("Got internal_metadata: %r", internal_metadata)
|
||||||
internal_metadata = json.loads(internal_metadata)
|
internal_metadata = json.loads(str(internal_metadata).decode("utf8"))
|
||||||
start_time = update_counter("decode_internal", start_time)
|
start_time = update_counter("decode_internal", start_time)
|
||||||
|
|
||||||
ev = FrozenEvent(d, internal_metadata_dict=internal_metadata)
|
ev = FrozenEvent(d, internal_metadata_dict=internal_metadata)
|
||||||
|
|
|
@ -179,7 +179,7 @@ class EventsStore(SQLBaseStore):
|
||||||
)
|
)
|
||||||
txn.execute(
|
txn.execute(
|
||||||
sql,
|
sql,
|
||||||
(metadata_json.decode("UTF-8"), event.event_id,)
|
(buffer(metadata_json), event.event_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
|
@ -224,14 +224,14 @@ class EventsStore(SQLBaseStore):
|
||||||
values={
|
values={
|
||||||
"event_id": event.event_id,
|
"event_id": event.event_id,
|
||||||
"room_id": event.room_id,
|
"room_id": event.room_id,
|
||||||
"internal_metadata": metadata_json.decode("UTF-8"),
|
"internal_metadata": buffer(metadata_json),
|
||||||
"json": encode_canonical_json(event_dict).decode("UTF-8"),
|
"json": buffer(encode_canonical_json(event_dict)),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
content = encode_canonical_json(
|
content = buffer(encode_canonical_json(
|
||||||
event.content
|
event.content
|
||||||
).decode("UTF-8")
|
))
|
||||||
|
|
||||||
vals = {
|
vals = {
|
||||||
"topological_ordering": event.depth,
|
"topological_ordering": event.depth,
|
||||||
|
@ -256,9 +256,9 @@ class EventsStore(SQLBaseStore):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
vals["unrecognized_keys"] = encode_canonical_json(
|
vals["unrecognized_keys"] = buffer(encode_canonical_json(
|
||||||
unrec
|
unrec
|
||||||
).decode("UTF-8")
|
))
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO events"
|
"INSERT INTO events"
|
||||||
|
|
|
@ -17,20 +17,22 @@ CREATE TABLE IF NOT EXISTS presence(
|
||||||
state VARCHAR(20),
|
state VARCHAR(20),
|
||||||
status_msg VARCHAR(150),
|
status_msg VARCHAR(150),
|
||||||
mtime BIGINT, -- miliseconds since last state change
|
mtime BIGINT, -- miliseconds since last state change
|
||||||
UNIQUE(user_id)
|
UNIQUE (user_id)
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
-- For each of /my/ users which possibly-remote users are allowed to see their
|
-- For each of /my/ users which possibly-remote users are allowed to see their
|
||||||
-- presence state
|
-- presence state
|
||||||
CREATE TABLE IF NOT EXISTS presence_allow_inbound(
|
CREATE TABLE IF NOT EXISTS presence_allow_inbound(
|
||||||
observed_user_id VARCHAR(150) NOT NULL,
|
observed_user_id VARCHAR(150) NOT NULL,
|
||||||
observer_user_id VARCHAR(150) -- a UserID,
|
observer_user_id VARCHAR(150) NOT NULL, -- a UserID,
|
||||||
|
UNIQUE (observed_user_id, observer_user_id)
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
-- For each of /my/ users (watcher), which possibly-remote users are they
|
-- For each of /my/ users (watcher), which possibly-remote users are they
|
||||||
-- watching?
|
-- watching?
|
||||||
CREATE TABLE IF NOT EXISTS presence_list(
|
CREATE TABLE IF NOT EXISTS presence_list(
|
||||||
user_id VARCHAR(150) NOT NULL,
|
user_id VARCHAR(150) NOT NULL,
|
||||||
observed_user_id VARCHAR(150), -- a UserID,
|
observed_user_id VARCHAR(150) NOT NULL, -- a UserID,
|
||||||
accepted BOOLEAN
|
accepted BOOLEAN NOT NULL,
|
||||||
|
UNIQUE (user_id, observed_user_id)
|
||||||
) ;
|
) ;
|
||||||
|
|
|
@ -35,8 +35,8 @@ CREATE TABLE IF NOT EXISTS user_ips (
|
||||||
device_id VARCHAR(150),
|
device_id VARCHAR(150),
|
||||||
ip VARCHAR(150) NOT NULL,
|
ip VARCHAR(150) NOT NULL,
|
||||||
user_agent VARCHAR(150) NOT NULL,
|
user_agent VARCHAR(150) NOT NULL,
|
||||||
last_seen BIGINT NOT NULL,
|
last_seen BIGINT NOT NULL
|
||||||
UNIQUE (user, access_token, ip, user_agent)
|
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS user_ips_user ON user_ips(user);
|
CREATE INDEX IF NOT EXISTS user_ips_user ON user_ips(user);
|
||||||
|
CREATE INDEX IF NOT EXISTS user_ips_user_ip ON user_ips(user, access_token, ip);
|
||||||
|
|
Loading…
Reference in New Issue