Don't use multiple UNIQUE constraints; it will cause deadlocks

This commit is contained in:
Erik Johnston 2015-04-07 12:08:35 +01:00
parent c8d3f6486d
commit 0af5f5efaf
4 changed files with 17 additions and 15 deletions

View File

@ -837,11 +837,11 @@ class SQLBaseStore(object):
return curr_time
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)
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)
ev = FrozenEvent(d, internal_metadata_dict=internal_metadata)

View File

@ -179,7 +179,7 @@ class EventsStore(SQLBaseStore):
)
txn.execute(
sql,
(metadata_json.decode("UTF-8"), event.event_id,)
(buffer(metadata_json), event.event_id,)
)
sql = (
@ -224,14 +224,14 @@ class EventsStore(SQLBaseStore):
values={
"event_id": event.event_id,
"room_id": event.room_id,
"internal_metadata": metadata_json.decode("UTF-8"),
"json": encode_canonical_json(event_dict).decode("UTF-8"),
"internal_metadata": buffer(metadata_json),
"json": buffer(encode_canonical_json(event_dict)),
},
)
content = encode_canonical_json(
content = buffer(encode_canonical_json(
event.content
).decode("UTF-8")
))
vals = {
"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
).decode("UTF-8")
))
sql = (
"INSERT INTO events"

View File

@ -17,20 +17,22 @@ CREATE TABLE IF NOT EXISTS presence(
state VARCHAR(20),
status_msg VARCHAR(150),
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
-- presence state
CREATE TABLE IF NOT EXISTS presence_allow_inbound(
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
-- watching?
CREATE TABLE IF NOT EXISTS presence_list(
user_id VARCHAR(150) NOT NULL,
observed_user_id VARCHAR(150), -- a UserID,
accepted BOOLEAN
observed_user_id VARCHAR(150) NOT NULL, -- a UserID,
accepted BOOLEAN NOT NULL,
UNIQUE (user_id, observed_user_id)
) ;

View File

@ -35,8 +35,8 @@ CREATE TABLE IF NOT EXISTS user_ips (
device_id VARCHAR(150),
ip VARCHAR(150) NOT NULL,
user_agent VARCHAR(150) NOT NULL,
last_seen BIGINT NOT NULL,
UNIQUE (user, access_token, ip, user_agent)
last_seen BIGINT NOT NULL
) ;
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);