Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libs/wire-subsystems/src/Wire/ConversationStore/Cassandra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,14 @@ interpretConversationStoreToCassandraAndPostgres client = interpret $ \case
True -> interpretConversationStoreToPostgres $ ConvStore.getConversationEpoch cid
GetConversations cids -> do
logEffect "ConversationStore.GetConversations"
-- Here we must take all these locks because its not sufficient to just
-- lookup in both DBs and then de-dupe to deal with this edge case:
--
-- 1. During migration, the delete in Cassandra gets lost
-- 2. Before the next lookup, the conversation gets deleted from PG and the
-- delete in Cassandra still gets lost
-- 3. If we don't lock and cleanup, we are at a risk of resurrecting this
-- conv.
withMigrationLocksAndConvCleanup client LockShared (Seconds 2) cids $ do
let indexByConvId = foldr (\storedConv -> Map.insert storedConv.id_ storedConv) Map.empty
cassConvs <- indexByConvId <$> localConversations client cids
Expand Down Expand Up @@ -1181,6 +1189,14 @@ interpretConversationStoreToCassandraAndPostgres client = interpret $ \case
True -> interpretConversationStoreToPostgres (ConvStore.isConversationAlive cid)
SelectConversations uid cids -> do
logEffect "ConversationStore.SelectConversations"
-- Here we must take all these locks because its not sufficient to just
-- lookup in both DBs and then de-dupe to deal with this edge case:
--
-- 1. During migration, the delete in Cassandra gets lost
-- 2. Before the next lookup, the conversation gets deleted from PG and the
-- delete in Cassandra still gets lost
-- 3. If we don't lock and cleanup, we are at a risk of resurrecting this
-- conv.
withMigrationLocksAndConvCleanup client LockShared (Seconds 2) cids $ do
cassConvs <- embedClient client $ localConversationIdsOf uid cids
pgConvs <- interpretConversationStoreToPostgres $ ConvStore.selectConversations uid cids
Expand Down