From 709a92cee89709811c51cac7d8c66922093be673 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 18 Aug 2014 16:00:46 +0100 Subject: SQL doesn't allow AUTOINCREMENT on non PRIMARY KEY columns. --- synapse/storage/__init__.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'synapse/storage/__init__.py') diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index 9f78f3f9bd..b846081d49 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -45,6 +45,9 @@ class DataStore(RoomMemberStore, RoomStore, self.event_factory = hs.get_event_factory() self.hs = hs + self.min_token_deferred = self._get_min_token() + self.min_token = None + @defer.inlineCallbacks def persist_event(self, event, backfilled=False): if event.type == RoomMemberEvent.TYPE: @@ -82,7 +85,7 @@ class DataStore(RoomMemberStore, RoomStore, @defer.inlineCallbacks def _store_event(self, event, backfilled): # FIXME (erikj): This should be removed when we start amalgamating - # event and pdu storage. + # event and pdu storage yield self.hs.get_federation().fill_out_prev_events(event) vals = { @@ -95,7 +98,10 @@ class DataStore(RoomMemberStore, RoomStore, } if backfilled: - vals["token_ordering"] = "-1" + if not self.min_token_deferred.called: + yield self.min_token_deferred + self.min_token -= 1 + vals["token_ordering"] = self.min_token unrec = { k: v @@ -151,6 +157,17 @@ class DataStore(RoomMemberStore, RoomStore, defer.returnValue([self._parse_event_from_row(r) for r in results]) + @defer.inlineCallbacks + def _get_min_token(self): + row = yield self._execute( + None, + "SELECT MIN(token_ordering) FROM events" + ) + + self.min_token = rows[0][0] if rows and rows[0] else 0 + + defer.returnValue(self.min_token) + def schema_path(schema): """ Get a filesystem path for the named database schema -- cgit 1.4.1