mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Apparently we can't do txn.rollback(), so raise and catch an exception instead.
This commit is contained in:
parent
c1a25756c2
commit
e062f2dfa8
@ -47,6 +47,11 @@ import os
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class _RollbackButIsFineException(Exception):
|
||||||
|
""" This exception is used to rollback a transaction without implying
|
||||||
|
something went wrong.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class DataStore(RoomMemberStore, RoomStore,
|
class DataStore(RoomMemberStore, RoomStore,
|
||||||
RegistrationStore, StreamStore, ProfileStore, FeedbackStore,
|
RegistrationStore, StreamStore, ProfileStore, FeedbackStore,
|
||||||
@ -71,13 +76,16 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
self.min_token -= 1
|
self.min_token -= 1
|
||||||
stream_ordering = self.min_token
|
stream_ordering = self.min_token
|
||||||
|
|
||||||
latest = yield self._db_pool.runInteraction(
|
try:
|
||||||
self._persist_pdu_event_txn,
|
latest = yield self._db_pool.runInteraction(
|
||||||
pdu=pdu,
|
self._persist_pdu_event_txn,
|
||||||
event=event,
|
pdu=pdu,
|
||||||
backfilled=backfilled,
|
event=event,
|
||||||
stream_ordering=stream_ordering,
|
backfilled=backfilled,
|
||||||
)
|
stream_ordering=stream_ordering,
|
||||||
|
)
|
||||||
|
except _RollbackButIsFineException as e:
|
||||||
|
pass
|
||||||
defer.returnValue(latest)
|
defer.returnValue(latest)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@ -175,12 +183,12 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
try:
|
try:
|
||||||
self._simple_insert_txn(txn, "events", vals)
|
self._simple_insert_txn(txn, "events", vals)
|
||||||
except:
|
except:
|
||||||
logger.exception(
|
logger.warn(
|
||||||
"Failed to persist, probably duplicate: %s",
|
"Failed to persist, probably duplicate: %s",
|
||||||
event.event_id
|
event.event_id,
|
||||||
|
exc_info=True,
|
||||||
)
|
)
|
||||||
txn.rollback()
|
raise _RollbackButIsFineException("_persist_event")
|
||||||
return
|
|
||||||
|
|
||||||
if not backfilled and hasattr(event, "state_key"):
|
if not backfilled and hasattr(event, "state_key"):
|
||||||
vals = {
|
vals = {
|
||||||
|
Loading…
Reference in New Issue
Block a user