Stream ordering and out of order insertions.

Handle the fact that events can be persisted out of order, and so to get
the "current max" stream token becomes non trivial - as we need to make
sure that *all* stream tokens less than the current max have also
successfully been persisted.
This commit is contained in:
Erik Johnston 2015-04-09 11:41:36 +01:00
parent 22d7a59306
commit 8ad0f4912e
No known key found for this signature in database
GPG key ID: 3ADA06EDC753D11E
5 changed files with 153 additions and 65 deletions

View file

@ -413,12 +413,10 @@ class StreamStore(SQLBaseStore):
"get_recent_events_for_room", get_recent_events_for_room_txn
)
@cached(num_args=0)
@defer.inlineCallbacks
def get_room_events_max_id(self):
return self.runInteraction(
"get_room_events_max_id",
self._get_room_events_max_id_txn
)
token = yield self._stream_id_gen.get_max_token(self)
defer.returnValue("s%d" % (token,))
@defer.inlineCallbacks
def _get_min_token(self):
@ -433,21 +431,6 @@ class StreamStore(SQLBaseStore):
defer.returnValue(self.min_token)
def _get_room_events_max_id_txn(self, txn):
txn.execute(
"SELECT MAX(stream_ordering) as m FROM events"
)
res = self.cursor_to_dict(txn)
logger.debug("get_room_events_max_id: %s", res)
if not res or not res[0] or not res[0]["m"]:
return "s0"
key = res[0]["m"]
return "s%d" % (key,)
@staticmethod
def _set_before_and_after(events, rows):
for event, row in zip(events, rows):