Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions changelog.d/5-internal/WPB-7416
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Galley's internal `DELETE /i/client/:clientID` now early-exits before visiting all conversations if the client is already gone.
Galley now reports debug logs for every call to Cassandra.
1 change: 1 addition & 0 deletions services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ library
Galley.Cassandra.Team
Galley.Cassandra.TeamFeatures
Galley.Cassandra.TeamNotifications
Galley.Cassandra.Util
Galley.Data.Conversation
Galley.Data.Conversation.Types
Galley.Data.Scope
Expand Down
21 changes: 15 additions & 6 deletions services/galley/src/Galley/API/Clients.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Polysemy
import Polysemy.Error
import Polysemy.Input
import Polysemy.TinyLog qualified as P
import System.Logger.Message
import Wire.API.Conversation hiding (Member)
import Wire.API.Federation.API
import Wire.API.Federation.API.Galley
Expand Down Expand Up @@ -111,12 +112,20 @@ rmClientH ::
UserId ::: ClientId ->
Sem r Response
rmClientH (usr ::: cid) = do
lusr <- qualifyLocal usr
let nRange1000 = toRange (Proxy @1000) :: Range 1 1000 Int32
firstConvIds <- Query.conversationIdsPageFrom lusr (GetPaginatedConversationIds Nothing nRange1000)
goConvs nRange1000 firstConvIds lusr

E.deleteClient usr cid
clients <- E.getClients [usr]
if (cid `elem` clientIds usr clients)
then do
lusr <- qualifyLocal usr
let nRange1000 = toRange (Proxy @1000) :: Range 1 1000 Int32
firstConvIds <- Query.conversationIdsPageFrom lusr (GetPaginatedConversationIds Nothing nRange1000)
goConvs nRange1000 firstConvIds lusr
E.deleteClient usr cid
else
P.debug
( field "user" (idToText usr)
. field "client" (clientToText cid)
. msg (val "rmClientH: client already gone")
)
pure empty
where
goConvs :: Range 1 1000 Int32 -> ConvIdsPage -> Local UserId -> Sem r ()
Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ import Galley.Cassandra.LegalHold
import Galley.Cassandra.Proposal
import Galley.Cassandra.SearchVisibility
import Galley.Cassandra.Services
import Galley.Cassandra.SubConversation (interpretSubConversationStoreToCassandra)
import Galley.Cassandra.SubConversation
import Galley.Cassandra.Team
import Galley.Cassandra.TeamFeatures
import Galley.Cassandra.TeamNotifications
import Galley.Effects
import Galley.Effects.FireAndForget (interpretFireAndForget)
import Galley.Effects.FireAndForget
import Galley.Effects.WaiRoutes.IO
import Galley.Env
import Galley.External
Expand Down
25 changes: 19 additions & 6 deletions services/galley/src/Galley/Cassandra/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Data.Id
import Data.List.Split (chunksOf)
import Galley.Cassandra.Queries qualified as Cql
import Galley.Cassandra.Store
import Galley.Cassandra.Util
import Galley.Effects.ClientStore (ClientStore (..))
import Galley.Env
import Galley.Monad
Expand All @@ -37,6 +38,7 @@ import Galley.Types.Clients qualified as Clients
import Imports
import Polysemy
import Polysemy.Input
import Polysemy.TinyLog
import UnliftIO qualified

updateClient :: Bool -> UserId -> ClientId -> Client ()
Expand All @@ -60,13 +62,24 @@ eraseClients user = retry x5 (write Cql.rmClients (params LocalQuorum (Identity
interpretClientStoreToCassandra ::
( Member (Embed IO) r,
Member (Input ClientState) r,
Member (Input Env) r
Member (Input Env) r,
Member TinyLog r
) =>
Sem (ClientStore ': r) a ->
Sem r a
interpretClientStoreToCassandra = interpret $ \case
GetClients uids -> embedClient $ lookupClients uids
CreateClient uid cid -> embedClient $ updateClient True uid cid
DeleteClient uid cid -> embedClient $ updateClient False uid cid
DeleteClients uid -> embedClient $ eraseClients uid
UseIntraClientListing -> embedApp . view $ options . settings . intraListing
GetClients uids -> do
logEffect "ClientStore.GetClients"
embedClient $ lookupClients uids
CreateClient uid cid -> do
logEffect "ClientStore.CreateClient"
embedClient $ updateClient True uid cid
DeleteClient uid cid -> do
logEffect "ClientStore.DeleteClient"
embedClient $ updateClient False uid cid
DeleteClients uid -> do
logEffect "ClientStore.DeleteClients"
embedClient $ eraseClients uid
UseIntraClientListing -> do
logEffect "ClientStore.UseIntraClientListing"
embedApp . view $ options . settings . intraListing
26 changes: 20 additions & 6 deletions services/galley/src/Galley/Cassandra/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,43 @@ import Data.Code
import Data.Map qualified as Map
import Galley.Cassandra.Queries qualified as Cql
import Galley.Cassandra.Store
import Galley.Cassandra.Util
import Galley.Data.Types
import Galley.Data.Types qualified as Code
import Galley.Effects.CodeStore (CodeStore (..))
import Galley.Env
import Imports
import Polysemy
import Polysemy.Input
import Polysemy.TinyLog
import Wire.API.Password

interpretCodeStoreToCassandra ::
( Member (Embed IO) r,
Member (Input ClientState) r,
Member (Input Env) r
Member (Input Env) r,
Member TinyLog r
) =>
Sem (CodeStore ': r) a ->
Sem r a
interpretCodeStoreToCassandra = interpret $ \case
GetCode k s -> embedClient $ lookupCode k s
CreateCode code mPw -> embedClient $ insertCode code mPw
DeleteCode k s -> embedClient $ deleteCode k s
MakeKey cid -> Code.mkKey cid
GenerateCode cid s t -> Code.generate cid s t
GetCode k s -> do
logEffect "CodeStore.GetCode"
embedClient $ lookupCode k s
CreateCode code mPw -> do
logEffect "CodeStore.CreateCode"
embedClient $ insertCode code mPw
DeleteCode k s -> do
logEffect "CodeStore.DeleteCode"
embedClient $ deleteCode k s
MakeKey cid -> do
logEffect "CodeStore.MakeKey"
Code.mkKey cid
GenerateCode cid s t -> do
logEffect "CodeStore.GenerateCode"
Code.generate cid s t
GetConversationCodeURI mbHost -> do
logEffect "CodeStore.GetConversationCodeURI"
env <- input
case env ^. convCodeURI of
Left uri -> pure (Just uri)
Expand Down
97 changes: 73 additions & 24 deletions services/galley/src/Galley/Cassandra/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Galley.Cassandra.Conversation.MLS
import Galley.Cassandra.Conversation.Members
import Galley.Cassandra.Queries qualified as Cql
import Galley.Cassandra.Store
import Galley.Cassandra.Util
import Galley.Data.Conversation
import Galley.Data.Conversation.Types
import Galley.Effects.ConversationStore (ConversationStore (..))
Expand Down Expand Up @@ -450,27 +451,75 @@ interpretConversationStoreToCassandra ::
Sem (ConversationStore ': r) a ->
Sem r a
interpretConversationStoreToCassandra = interpret $ \case
CreateConversationId -> Id <$> embed nextRandom
CreateConversation loc nc -> embedClient $ createConversation loc nc
CreateMLSSelfConversation lusr -> embedClient $ createMLSSelfConversation lusr
GetConversation cid -> embedClient $ getConversation cid
GetConversationEpoch cid -> embedClient $ getConvEpoch cid
GetConversations cids -> localConversations cids
GetConversationMetadata cid -> embedClient $ conversationMeta cid
GetGroupInfo cid -> embedClient $ getGroupInfo cid
IsConversationAlive cid -> embedClient $ isConvAlive cid
SelectConversations uid cids -> embedClient $ localConversationIdsOf uid cids
GetRemoteConversationStatus uid cids -> embedClient $ remoteConversationStatus uid cids
SetConversationType cid ty -> embedClient $ updateConvType cid ty
SetConversationName cid value -> embedClient $ updateConvName cid value
SetConversationAccess cid value -> embedClient $ updateConvAccess cid value
SetConversationReceiptMode cid value -> embedClient $ updateConvReceiptMode cid value
SetConversationMessageTimer cid value -> embedClient $ updateConvMessageTimer cid value
SetConversationEpoch cid epoch -> embedClient $ updateConvEpoch cid epoch
SetConversationCipherSuite cid cs -> embedClient $ updateConvCipherSuite cid cs
DeleteConversation cid -> embedClient $ deleteConversation cid
SetGroupInfo cid gib -> embedClient $ setGroupInfo cid gib
AcquireCommitLock gId epoch ttl -> embedClient $ acquireCommitLock gId epoch ttl
ReleaseCommitLock gId epoch -> embedClient $ releaseCommitLock gId epoch
UpdateToMixedProtocol cid ct cs -> updateToMixedProtocol cid ct cs
UpdateToMLSProtocol cid -> updateToMLSProtocol cid
CreateConversationId -> do
logEffect "ConversationStore.CreateConversationId"
Id <$> embed nextRandom
CreateConversation loc nc -> do
logEffect "ConversationStore.CreateConversation"
embedClient $ createConversation loc nc
CreateMLSSelfConversation lusr -> do
logEffect "ConversationStore.CreateMLSSelfConversation"
embedClient $ createMLSSelfConversation lusr
GetConversation cid -> do
logEffect "ConversationStore.GetConversation"
embedClient $ getConversation cid
GetConversationEpoch cid -> do
logEffect "ConversationStore.GetConversationEpoch"
embedClient $ getConvEpoch cid
GetConversations cids -> do
logEffect "ConversationStore.GetConversations"
localConversations cids
GetConversationMetadata cid -> do
logEffect "ConversationStore.GetConversationMetadata"
embedClient $ conversationMeta cid
GetGroupInfo cid -> do
logEffect "ConversationStore.GetGroupInfo"
embedClient $ getGroupInfo cid
IsConversationAlive cid -> do
logEffect "ConversationStore.IsConversationAlive"
embedClient $ isConvAlive cid
SelectConversations uid cids -> do
logEffect "ConversationStore.SelectConversations"
embedClient $ localConversationIdsOf uid cids
GetRemoteConversationStatus uid cids -> do
logEffect "ConversationStore.GetRemoteConversationStatus"
embedClient $ remoteConversationStatus uid cids
SetConversationType cid ty -> do
logEffect "ConversationStore.SetConversationType"
embedClient $ updateConvType cid ty
SetConversationName cid value -> do
logEffect "ConversationStore.SetConversationName"
embedClient $ updateConvName cid value
SetConversationAccess cid value -> do
logEffect "ConversationStore.SetConversationAccess"
embedClient $ updateConvAccess cid value
SetConversationReceiptMode cid value -> do
logEffect "ConversationStore.SetConversationReceiptMode"
embedClient $ updateConvReceiptMode cid value
SetConversationMessageTimer cid value -> do
logEffect "ConversationStore.SetConversationMessageTimer"
embedClient $ updateConvMessageTimer cid value
SetConversationEpoch cid epoch -> do
logEffect "ConversationStore.SetConversationEpoch"
embedClient $ updateConvEpoch cid epoch
SetConversationCipherSuite cid cs -> do
logEffect "ConversationStore.SetConversationCipherSuite"
embedClient $ updateConvCipherSuite cid cs
DeleteConversation cid -> do
logEffect "ConversationStore.DeleteConversation"
embedClient $ deleteConversation cid
SetGroupInfo cid gib -> do
logEffect "ConversationStore.SetGroupInfo"
embedClient $ setGroupInfo cid gib
AcquireCommitLock gId epoch ttl -> do
logEffect "ConversationStore.AcquireCommitLock"
embedClient $ acquireCommitLock gId epoch ttl
ReleaseCommitLock gId epoch -> do
logEffect "ConversationStore.ReleaseCommitLock"
embedClient $ releaseCommitLock gId epoch
UpdateToMixedProtocol cid ct cs -> do
logEffect "ConversationStore.UpdateToMixedProtocol"
updateToMixedProtocol cid ct cs
UpdateToMLSProtocol cid -> do
logEffect "ConversationStore.UpdateToMLSProtocol"
updateToMLSProtocol cid
90 changes: 67 additions & 23 deletions services/galley/src/Galley/Cassandra/Conversation/Members.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ import Galley.Cassandra.Instances ()
import Galley.Cassandra.Queries qualified as Cql
import Galley.Cassandra.Services
import Galley.Cassandra.Store
import Galley.Cassandra.Util
import Galley.Effects.MemberStore (MemberStore (..))
import Galley.Types.Conversations.Members
import Galley.Types.ToUserRole
import Galley.Types.UserList
import Imports hiding (Set, cs)
import Polysemy
import Polysemy.Input
import Polysemy.TinyLog
import UnliftIO qualified
import Wire.API.Conversation.Member hiding (Member)
import Wire.API.Conversation.Role
Expand Down Expand Up @@ -390,34 +392,76 @@ removeAllMLSClients groupId = do

interpretMemberStoreToCassandra ::
( Member (Embed IO) r,
Member (Input ClientState) r
Member (Input ClientState) r,
Member TinyLog r
) =>
Sem (MemberStore ': r) a ->
Sem r a
interpretMemberStoreToCassandra = interpret $ \case
CreateMembers cid ul -> embedClient $ addMembers cid ul
CreateMembersInRemoteConversation rcid uids ->
CreateMembers cid ul -> do
logEffect "MemberStore.CreateMembers"
embedClient $ addMembers cid ul
CreateMembersInRemoteConversation rcid uids -> do
logEffect "MemberStore.CreateMembersInRemoteConversation"
embedClient $ addLocalMembersToRemoteConv rcid uids
CreateBotMember sr bid cid -> embedClient $ addBotMember sr bid cid
GetLocalMember cid uid -> embedClient $ member cid uid
GetLocalMembers cid -> embedClient $ members cid
GetAllLocalMembers -> embedClient allMembers
GetRemoteMember cid uid -> embedClient $ lookupRemoteMember cid (tDomain uid) (tUnqualified uid)
GetRemoteMembers rcid -> embedClient $ lookupRemoteMembers rcid
CheckLocalMemberRemoteConv uid rcnv -> fmap (not . null) $ embedClient $ lookupLocalMemberRemoteConv uid rcnv
SelectRemoteMembers uids rcnv -> embedClient $ filterRemoteConvMembers uids rcnv
SetSelfMember qcid luid upd -> embedClient $ updateSelfMember qcid luid upd
SetOtherMember lcid quid upd ->
CreateBotMember sr bid cid -> do
logEffect "MemberStore.CreateBotMember"
embedClient $ addBotMember sr bid cid
GetLocalMember cid uid -> do
logEffect "MemberStore.GetLocalMember"
embedClient $ member cid uid
GetLocalMembers cid -> do
logEffect "MemberStore.GetLocalMembers"
embedClient $ members cid
GetAllLocalMembers -> do
logEffect "MemberStore.GetAllLocalMembers"
embedClient allMembers
GetRemoteMember cid uid -> do
logEffect "MemberStore.GetRemoteMember"
embedClient $ lookupRemoteMember cid (tDomain uid) (tUnqualified uid)
GetRemoteMembers rcid -> do
logEffect "MemberStore.GetRemoteMembers"
embedClient $ lookupRemoteMembers rcid
CheckLocalMemberRemoteConv uid rcnv -> do
logEffect "MemberStore.CheckLocalMemberRemoteConv"
fmap (not . null) $ embedClient $ lookupLocalMemberRemoteConv uid rcnv
SelectRemoteMembers uids rcnv -> do
logEffect "MemberStore.SelectRemoteMembers"
embedClient $ filterRemoteConvMembers uids rcnv
SetSelfMember qcid luid upd -> do
logEffect "MemberStore.SetSelfMember"
embedClient $ updateSelfMember qcid luid upd
SetOtherMember lcid quid upd -> do
logEffect "MemberStore.SetOtherMember"
embedClient $ updateOtherMemberLocalConv lcid quid upd
DeleteMembers cnv ul -> embedClient $ removeMembersFromLocalConv cnv ul
DeleteMembersInRemoteConversation rcnv uids ->
DeleteMembers cnv ul -> do
logEffect "MemberStore.DeleteMembers"
embedClient $ removeMembersFromLocalConv cnv ul
DeleteMembersInRemoteConversation rcnv uids -> do
logEffect "MemberStore.DeleteMembersInRemoteConversation"
embedClient $
removeLocalMembersFromRemoteConv rcnv uids
AddMLSClients lcnv quid cs -> embedClient $ addMLSClients lcnv quid cs
PlanClientRemoval lcnv cids -> embedClient $ planMLSClientRemoval lcnv cids
RemoveMLSClients lcnv quid cs -> embedClient $ removeMLSClients lcnv quid cs
RemoveAllMLSClients gid -> embedClient $ removeAllMLSClients gid
LookupMLSClients lcnv -> embedClient $ lookupMLSClients lcnv
LookupMLSClientLeafIndices lcnv -> embedClient $ lookupMLSClientLeafIndices lcnv
GetRemoteMembersByDomain dom -> embedClient $ lookupRemoteMembersByDomain dom
GetLocalMembersByDomain dom -> embedClient $ lookupLocalMembersByDomain dom
AddMLSClients lcnv quid cs -> do
logEffect "MemberStore.AddMLSClients"
embedClient $ addMLSClients lcnv quid cs
PlanClientRemoval lcnv cids -> do
logEffect "MemberStore.PlanClientRemoval"
embedClient $ planMLSClientRemoval lcnv cids
RemoveMLSClients lcnv quid cs -> do
logEffect "MemberStore.RemoveMLSClients"
embedClient $ removeMLSClients lcnv quid cs
RemoveAllMLSClients gid -> do
logEffect "MemberStore.RemoveAllMLSClients"
embedClient $ removeAllMLSClients gid
LookupMLSClients lcnv -> do
logEffect "MemberStore.LookupMLSClients"
embedClient $ lookupMLSClients lcnv
LookupMLSClientLeafIndices lcnv -> do
logEffect "MemberStore.LookupMLSClientLeafIndices"
embedClient $ lookupMLSClientLeafIndices lcnv
GetRemoteMembersByDomain dom -> do
logEffect "MemberStore.GetRemoteMembersByDomain"
embedClient $ lookupRemoteMembersByDomain dom
GetLocalMembersByDomain dom -> do
logEffect "MemberStore.GetLocalMembersByDomain"
embedClient $ lookupLocalMembersByDomain dom
Loading