mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
6f49519053
* chore: revert tool pkg version. (#2476)
* feat: update go mod pkg to latest.
* revert tool pkg version.
* feat: update grafana template (#2484)
* feat: update web front images (#2487)
* fix: import del cache (#2492)
* fix:update recive name to same (#2493)
* fix: fix-validate message. (#2499)
* h (#2501)
* refactor: refactor workflows structure. (#2511)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* fix: solve uncorrect outdated msg get. (#2513)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* feat: update issue translator in workflows (#2521)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* feat: update issue translator.
* fix: pass getMinioImageThumbnailKey error. (#2532)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* feat: update issue translator.
* fix: pass getMinioImageThumbnailKey error.
* docs: update CLA comments contents. (#2534)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* docs: update CLA comments contents.
* update workflow file.
* fix: the log key value is not aligned (#2527)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* fix 细节 (#2525)
1、统一结构体方法 receiver,都用 pointer
2、使用 errors.Is 来做错误判断
3、修复单词拼写的错误
* Fix config (#2541)
* feat: remove double quotation marks
* feat: test
* feat: default close prometheus
* Fix: solve conversation blocking in private chat when non friendship. (#2542)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: update contribute cla.
* fix: solve conversations bug.
* fix:get msg error (#2494)
* fix:mgo delete err (#2496)
* fix:doPut error (#2495)
* feat: update set conversation logic. (#2544)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* feat: update set conversation logic.
* content format.
* update setConversation logic.
* update conversation logic.
* update conversation logic.
* update logic.
* update logic.
* Groupmsg (#2548)
* feat: add EnableHistoryForNewMembers
* feat: change name
* refactor: move first create conversation
* fix: set min seq
* feat: implement `SetGroupInfoEX` interface. (#2552)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* feat: implement `SetGroupInfoEX` interface.
* remove null interface.
* update router.
* fix: set min seq (#2556)
* fix:log
* fix: set min seq
* Fix push (#2559)
* fix:log
* fix: add log
* fix: del return
* fix: push config
* feat: add push err log and extend push wait time
* feat: group config
* feat: add log in write binary msg
* feat: Modify Prometheus data scraping ports and reserve port space.
* feat: change group rpc num
* feat: change log
* fix: remove quotation mark
* fix: read seq is written to mongo, online status redis cluster is supported (#2558)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* fix: invitation to join group notification opuser is null (#2562)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* Fix set convsation (#2564)
* fix: set conversation unequal check
* fix: check update list
* fix: delay deleteObject func. (#2566)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* fix: memory queue optimization (#2568)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* fix: fill opUser in invite tips (#2578)
* fix: fill opUser in invite tips
* fix: del code
* feat: update group notification when set to null. (#2590)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* feat: update group notification when set to null.
* update log standard.
* feat: add long time push msg in prometheus (#2584)
* feat: add long time push msg in prometheus
* fix: log print
* fix: go mod
* fix: log msg
* fix: log init
* feat: push msg
* feat: go mod ,remove cgo package
* feat: remove error log
* feat: test dummy push
* feat:redis pool config
* feat: push to kafka log
* feat: supports getting messages based on session ID and seq (#2582)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* feat: implement request batch count limit. (#2591)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* fix: getting messages based on session ID and seq (#2595)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* feat: avoid pulling messages from sessions with a large number of max seq values of 0 (#2602)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* refactor: improve db structure in `storage/controller` (#2604)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* refactor: improve db structure in `storage/controller`
* feat: implement offline push using kafka (#2600)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* feat: implement offline push.
* feat: implement batch Push spilt
* update go mod
* feat: implement kafka producer and consumer.
* update format,
* add PushMQ log.
* feat: update Handler logic.
* update MQ logic.
* update
* update
* fix: update OfflinePushConsumerHandler.
* feat: API supports gzip (#2609)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* Fix err (#2608)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* feat: add rocksTimeout
* feat: wrap logs
* feat: add logs
* feat: listen config
* feat: enable listen TIME_WAIT port
* feat: add logs
* feat: cache batch
* chore: enable fullUserCache
* feat: push rpc num
* feat: push err
* feat: with operationID
* feat: sleep
* feat: change 1s
* feat: change log
* feat: implement Getbatch in rpcCache.
* feat: print getOnline cost
* feat: change log
* feat: change kafka and push config
* feat: del interface
* feat: fix err
* feat: change config
* feat: go mod
* feat: change config
* feat: change config
* feat: add sleep in push
* feat: warn logs
* feat: logs
* feat: logs
* feat: change port
* feat: start config
* feat: remove port reuse
* feat: prometheus config
* feat: prometheus config
* feat: prometheus config
* feat: add long time send msg to grafana
* feat: init
* feat: init
* feat: implement offline push.
* feat: batch get user online
* feat: implement batch Push spilt
* update go mod
* Revert "feat: change port"
This reverts commit 06d5e944
* feat: change port
* feat: change config
* feat: implement kafka producer and consumer.
* update format,
* add PushMQ log.
* feat: get all online users and init push
* feat: lock in online cache
* feat: config
* fix: init online status
* fix: add logs
* fix: userIDs
* fix: add logs
* feat: update Handler logic.
* update MQ logic.
* update
* update
* fix: method name
* fix: update OfflinePushConsumerHandler.
* fix: prommetrics
* fix: add logs
* fix: ctx
* fix: log
* fix: config
* feat: change port
* fix: atomic online cache status
---------
Co-authored-by: Monet Lee <monet_lee@163.com>
* feature: add GetConversationsHasReadAndMaxSeq interface to the WebSocket API. (#2611)
* fix: lru lock (#2613)
* fix: lru lock
* fix: lru lock
* fix: lru lock
* fix: nil pointer error on close (#2618)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
* go.mod
* fix: nil pointer error on close
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* feat: create group can push notification (#2617)
* fix: blockage caused by listen error (#2620)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
* go.mod
* fix: nil pointer error on close
* fix: listen error
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* fix: go.mod (#2621)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
* go.mod
* fix: nil pointer error on close
* fix: listen error
* fix: listen error
* update go.mod
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* feat: improve searchMsg implement. (#2614)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* remove unused script.
* feat: improve searchMsg implement.
* update mongo config.
* Fix lock (#2622)
* fix:log
* fix: lock
* fix: update setGroupInfoEX field name. (#2625)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* fix: update setGroupInfoEX field name.
* fix: update setGroupInfoEX field name (#2626)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* fix: update setGroupInfoEX field name.
* fix: update setGroupInfoEX field name
* feat: msg gateway add log (#2631)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
* go.mod
* fix: nil pointer error on close
* fix: listen error
* fix: listen error
* update go.mod
* feat: add log
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* fix: update setGroupInfoEx func name and field. (#2634)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* fix: update setGroupInfoEx func name and field.
* refactor: update groupinfoEx field.
* refactor: update database name in mongodb.yml
* add groupName Condition
* fix: fix setConversations req fill. (#2645)
* refactor: refactor workflows contents.
* add tool workflows.
* update field.
* fix: remove chat error.
* Fix err.
* fix error.
* remove cn comment.
* update workflows files.
* update infra config.
* move workflows.
* feat: update bot.
* fix: solve uncorrect outdated msg get.
* update get docIDs logic.
* update
* update skip logic.
* fix
* update.
* fix: delay deleteObject func.
* remove unused content.
* update log type.
* feat: implement request batch count limit.
* update
* update
* fix: fix setConversations req fill.
* fix: GetMsgBySeqs boundary issues (#2647)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
* go.mod
* fix: nil pointer error on close
* fix: listen error
* fix: listen error
* update go.mod
* feat: add log
* fix: token parse token value
* fix: GetMsgBySeqs boundary issues
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* fix: the attribute version is obsolete, remove it (#2644)
* refactor: update Userregister request field. (#2650)
* Test Workflow (#2640)
* feat: cicd
* feat: cicd
* fix: cicd
* fix: cicd
* fix: cicd
* fix: cicd
* fix: kick group member callback (#2643)
* fix: kill group member callback
* fix: change port
* fix: change port
* fix: route (#2654)
* feat: add GetSpecifiedBlacks interface. (#2656)
* Upgrade the Google Firebase version. (#2638)
* Fix token (#2653)
* fix: kick token
* fix: kick token
* fix: change config
* feat: get not notify conversationIDs (#2658)
* feat: get not notify conversationIDs
* feat: api
* fix: database
* fix: change name
* feat: GetPinnedConversationIDs (#2660)
* feat: GetPinnedConversationIDs
* feat: api
* Upgrade the FCM SDK to version 4, and use the SendEach method instead of the SendAll method. (#2633)
Co-authored-by: Monet Lee <monet_lee@163.com>
* feat: implement GetSpecifiedUserGroupRequestInfo interface. (#2661)
* feat: implement GetSpecifiedUserGroupRequestInfo interface.
* update mongo config.
* feat: provide the interface required by js sdk (#2664)
* fix: redis support acquisition time
* fix: GetActiveConversation
* feat: jssdk GetConversations, GetActiveConversation
* feat: jssdk GetConversations, GetActiveConversation
* feat: jssdk GetConversations, GetActiveConversation
* feat: jssdk GetConversations, GetActiveConversation
* feat: jssdk GetConversations, GetActiveConversation
* feat: improve get admin role memberIDs implement. (#2666)
* feat: implement GetSpecifiedUserGroupRequestInfo interface.
* update mongo config.
* feat: improve get admin role memberIDs implement.
* remove unused contents.
* remove unused contents.
* remove todo implement.
* fix: fix update groupName invalid. (#2673)
* refactor: change platform to platformID (#2670)
* feat: don`t return nil data (#2675)
Co-authored-by: Monet Lee <monet_lee@163.com>
* refactor: update fields type in userStatus and check registered. (#2676)
* fix: usertoken auth. (#2677)
* refactor: update fields type in userStatus and check registered.
* fix: usertoken auth.
* update contents.
* update content.
* update
* fix
* update pb file.
* feat: add friend agree after callback (#2680)
* fix: sn not sort (#2682)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* update gomake version
* update gomake version
* fix: seq conversion bug
* fix: redis pipe exec
* fix: ImportFriends
* fix: A large number of logs keysAndValues length is not even
* feat: mark read aggregate write
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* feat: online status supports redis cluster
* merge
* merge
* read seq is written to mongo
* read seq is written to mongo
* fix: invitation to join group notification
* fix: friend op_user_id
* feat: optimizing asynchronous context
* feat: optimizing memamq size
* feat: add GetSeqMessage
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: GroupApplicationAgreeMemberEnterNotification
* feat: go.mod
* feat: go.mod
* feat: join group notification and get seq
* feat: join group notification and get seq
* feat: avoid pulling messages from sessions with a large number of max seq values of 0
* feat: API supports gzip
* go.mod
* fix: nil pointer error on close
* fix: listen error
* fix: listen error
* update go.mod
* feat: add log
* fix: token parse token value
* fix: GetMsgBySeqs boundary issues
* fix: sn_ not sort
* fix: sn_ not sort
* fix: sn_ not sort
---------
Co-authored-by: withchao <withchao@users.noreply.github.com>
* refactor: add GetAdminToken interface. (#2684)
* refactor: add GetAdminToken interface.
* update config.
* fix: admin token (#2686)
* fix: update workflows logic. (#2688)
* refactor: add GetAdminToken interface.
* update config.
* update workflows logic.
* fix: admin token (#2687)
* update the front image (#2692)
* update the front image
* update version
* feat: improve publish docker image workflows (#2697)
* refactor: add GetAdminToken interface.
* update config.
* update workflows logic.
* feat: improve publish docker image workflows
* update condition logic.
* fix: update load file logic. (#2700)
* refactor: add GetAdminToken interface.
* update config.
* update workflows logic.
* feat: improve publish docker image workflows
* update condition logic.
* fix: update load file logic.
* feat: Msg filter (#2703)
* feat: msg filter
* feat: msg filter
* feat: msg filter
---------
Co-authored-by: Monet Lee <monet_lee@163.com>
Co-authored-by: icey-yu <119291641+icey-yu@users.noreply.github.com>
Co-authored-by: Kevin Lee <59052025+lgz5689@users.noreply.github.com>
Co-authored-by: qinguoyi <1532979219@qq.com>
Co-authored-by: chao <48119764+withchao@users.noreply.github.com>
Co-authored-by: withchao <withchao@users.noreply.github.com>
Co-authored-by: Mew151 <dgqypl@gmail.com>
Co-authored-by: 蔡相跃 <caixiangyue007@gmail.com>
Co-authored-by: 暴走的大猩猩 <Hz_testing@163.com>
Co-authored-by: Libo <zhaolibo1989@foxmail.com>
Co-authored-by: skiffer-git <72860476+skiffer-git@users.noreply.github.com>
520 lines
16 KiB
Go
520 lines
16 KiB
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/dtm-labs/rockscache"
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/cachekey"
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
|
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
|
"github.com/openimsdk/tools/errs"
|
|
"github.com/openimsdk/tools/log"
|
|
"github.com/redis/go-redis/v9"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func NewSeqConversationCacheRedis(rdb redis.UniversalClient, mgo database.SeqConversation) cache.SeqConversationCache {
|
|
return &seqConversationCacheRedis{
|
|
rdb: rdb,
|
|
mgo: mgo,
|
|
lockTime: time.Second * 3,
|
|
dataTime: time.Hour * 24 * 365,
|
|
minSeqExpireTime: time.Hour,
|
|
rocks: rockscache.NewClient(rdb, *GetRocksCacheOptions()),
|
|
}
|
|
}
|
|
|
|
type seqConversationCacheRedis struct {
|
|
rdb redis.UniversalClient
|
|
mgo database.SeqConversation
|
|
rocks *rockscache.Client
|
|
lockTime time.Duration
|
|
dataTime time.Duration
|
|
minSeqExpireTime time.Duration
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) getMinSeqKey(conversationID string) string {
|
|
return cachekey.GetMallocMinSeqKey(conversationID)
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) SetMinSeq(ctx context.Context, conversationID string, seq int64) error {
|
|
return s.SetMinSeqs(ctx, map[string]int64{conversationID: seq})
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) GetMinSeq(ctx context.Context, conversationID string) (int64, error) {
|
|
return getCache(ctx, s.rocks, s.getMinSeqKey(conversationID), s.minSeqExpireTime, func(ctx context.Context) (int64, error) {
|
|
return s.mgo.GetMinSeq(ctx, conversationID)
|
|
})
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) getSingleMaxSeq(ctx context.Context, conversationID string) (map[string]int64, error) {
|
|
seq, err := s.GetMaxSeq(ctx, conversationID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]int64{conversationID: seq}, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) getSingleMaxSeqWithTime(ctx context.Context, conversationID string) (map[string]database.SeqTime, error) {
|
|
seq, err := s.GetMaxSeqWithTime(ctx, conversationID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]database.SeqTime{conversationID: seq}, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) batchGetMaxSeq(ctx context.Context, keys []string, keyConversationID map[string]string, seqs map[string]int64) error {
|
|
result := make([]*redis.StringCmd, len(keys))
|
|
pipe := s.rdb.Pipeline()
|
|
for i, key := range keys {
|
|
result[i] = pipe.HGet(ctx, key, "CURR")
|
|
}
|
|
if _, err := pipe.Exec(ctx); err != nil && !errors.Is(err, redis.Nil) {
|
|
return errs.Wrap(err)
|
|
}
|
|
var notFoundKey []string
|
|
for i, r := range result {
|
|
req, err := r.Int64()
|
|
if err == nil {
|
|
seqs[keyConversationID[keys[i]]] = req
|
|
} else if errors.Is(err, redis.Nil) {
|
|
notFoundKey = append(notFoundKey, keys[i])
|
|
} else {
|
|
return errs.Wrap(err)
|
|
}
|
|
}
|
|
for _, key := range notFoundKey {
|
|
conversationID := keyConversationID[key]
|
|
seq, err := s.GetMaxSeq(ctx, conversationID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
seqs[conversationID] = seq
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) batchGetMaxSeqWithTime(ctx context.Context, keys []string, keyConversationID map[string]string, seqs map[string]database.SeqTime) error {
|
|
result := make([]*redis.SliceCmd, len(keys))
|
|
pipe := s.rdb.Pipeline()
|
|
for i, key := range keys {
|
|
result[i] = pipe.HMGet(ctx, key, "CURR", "TIME")
|
|
}
|
|
if _, err := pipe.Exec(ctx); err != nil && !errors.Is(err, redis.Nil) {
|
|
return errs.Wrap(err)
|
|
}
|
|
var notFoundKey []string
|
|
for i, r := range result {
|
|
val, err := r.Result()
|
|
if len(val) != 2 {
|
|
return errs.WrapMsg(err, "batchGetMaxSeqWithTime invalid result", "key", keys[i], "res", val)
|
|
}
|
|
if val[0] == nil {
|
|
notFoundKey = append(notFoundKey, keys[i])
|
|
continue
|
|
}
|
|
seq, err := s.parseInt64(val[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
mill, err := s.parseInt64(val[1])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
seqs[keyConversationID[keys[i]]] = database.SeqTime{Seq: seq, Time: mill}
|
|
}
|
|
for _, key := range notFoundKey {
|
|
conversationID := keyConversationID[key]
|
|
seq, err := s.GetMaxSeqWithTime(ctx, conversationID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
seqs[conversationID] = seq
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
|
switch len(conversationIDs) {
|
|
case 0:
|
|
return map[string]int64{}, nil
|
|
case 1:
|
|
return s.getSingleMaxSeq(ctx, conversationIDs[0])
|
|
}
|
|
keys := make([]string, 0, len(conversationIDs))
|
|
keyConversationID := make(map[string]string, len(conversationIDs))
|
|
for _, conversationID := range conversationIDs {
|
|
key := s.getSeqMallocKey(conversationID)
|
|
if _, ok := keyConversationID[key]; ok {
|
|
continue
|
|
}
|
|
keys = append(keys, key)
|
|
keyConversationID[key] = conversationID
|
|
}
|
|
if len(keys) == 1 {
|
|
return s.getSingleMaxSeq(ctx, conversationIDs[0])
|
|
}
|
|
slotKeys, err := groupKeysBySlot(ctx, s.rdb, keys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
seqs := make(map[string]int64, len(conversationIDs))
|
|
for _, keys := range slotKeys {
|
|
if err := s.batchGetMaxSeq(ctx, keys, keyConversationID, seqs); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return seqs, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) GetMaxSeqsWithTime(ctx context.Context, conversationIDs []string) (map[string]database.SeqTime, error) {
|
|
switch len(conversationIDs) {
|
|
case 0:
|
|
return map[string]database.SeqTime{}, nil
|
|
case 1:
|
|
return s.getSingleMaxSeqWithTime(ctx, conversationIDs[0])
|
|
}
|
|
keys := make([]string, 0, len(conversationIDs))
|
|
keyConversationID := make(map[string]string, len(conversationIDs))
|
|
for _, conversationID := range conversationIDs {
|
|
key := s.getSeqMallocKey(conversationID)
|
|
if _, ok := keyConversationID[key]; ok {
|
|
continue
|
|
}
|
|
keys = append(keys, key)
|
|
keyConversationID[key] = conversationID
|
|
}
|
|
if len(keys) == 1 {
|
|
return s.getSingleMaxSeqWithTime(ctx, conversationIDs[0])
|
|
}
|
|
slotKeys, err := groupKeysBySlot(ctx, s.rdb, keys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
seqs := make(map[string]database.SeqTime, len(conversationIDs))
|
|
for _, keys := range slotKeys {
|
|
if err := s.batchGetMaxSeqWithTime(ctx, keys, keyConversationID, seqs); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return seqs, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) getSeqMallocKey(conversationID string) string {
|
|
return cachekey.GetMallocSeqKey(conversationID)
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) setSeq(ctx context.Context, key string, owner int64, currSeq int64, lastSeq int64, mill int64) (int64, error) {
|
|
if lastSeq < currSeq {
|
|
return 0, errs.New("lastSeq must be greater than currSeq")
|
|
}
|
|
// 0: success
|
|
// 1: success the lock has expired, but has not been locked by anyone else
|
|
// 2: already locked, but not by yourself
|
|
script := `
|
|
local key = KEYS[1]
|
|
local lockValue = ARGV[1]
|
|
local dataSecond = ARGV[2]
|
|
local curr_seq = tonumber(ARGV[3])
|
|
local last_seq = tonumber(ARGV[4])
|
|
local mallocTime = ARGV[5]
|
|
if redis.call("EXISTS", key) == 0 then
|
|
redis.call("HSET", key, "CURR", curr_seq, "LAST", last_seq, "TIME", mallocTime)
|
|
redis.call("EXPIRE", key, dataSecond)
|
|
return 1
|
|
end
|
|
if redis.call("HGET", key, "LOCK") ~= lockValue then
|
|
return 2
|
|
end
|
|
redis.call("HDEL", key, "LOCK")
|
|
redis.call("HSET", key, "CURR", curr_seq, "LAST", last_seq, "TIME", mallocTime)
|
|
redis.call("EXPIRE", key, dataSecond)
|
|
return 0
|
|
`
|
|
result, err := s.rdb.Eval(ctx, script, []string{key}, owner, int64(s.dataTime/time.Second), currSeq, lastSeq, mill).Int64()
|
|
if err != nil {
|
|
return 0, errs.Wrap(err)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// malloc size=0 is to get the current seq size>0 is to allocate seq
|
|
func (s *seqConversationCacheRedis) malloc(ctx context.Context, key string, size int64) ([]int64, error) {
|
|
// 0: success
|
|
// 1: need to obtain and lock
|
|
// 2: already locked
|
|
// 3: exceeded the maximum value and locked
|
|
script := `
|
|
local key = KEYS[1]
|
|
local size = tonumber(ARGV[1])
|
|
local lockSecond = ARGV[2]
|
|
local dataSecond = ARGV[3]
|
|
local mallocTime = ARGV[4]
|
|
local result = {}
|
|
if redis.call("EXISTS", key) == 0 then
|
|
local lockValue = math.random(0, 999999999)
|
|
redis.call("HSET", key, "LOCK", lockValue)
|
|
redis.call("EXPIRE", key, lockSecond)
|
|
table.insert(result, 1)
|
|
table.insert(result, lockValue)
|
|
table.insert(result, mallocTime)
|
|
return result
|
|
end
|
|
if redis.call("HEXISTS", key, "LOCK") == 1 then
|
|
table.insert(result, 2)
|
|
return result
|
|
end
|
|
local curr_seq = tonumber(redis.call("HGET", key, "CURR"))
|
|
local last_seq = tonumber(redis.call("HGET", key, "LAST"))
|
|
if size == 0 then
|
|
redis.call("EXPIRE", key, dataSecond)
|
|
table.insert(result, 0)
|
|
table.insert(result, curr_seq)
|
|
table.insert(result, last_seq)
|
|
local setTime = redis.call("HGET", key, "TIME")
|
|
if setTime then
|
|
table.insert(result, setTime)
|
|
else
|
|
table.insert(result, 0)
|
|
end
|
|
return result
|
|
end
|
|
local max_seq = curr_seq + size
|
|
if max_seq > last_seq then
|
|
local lockValue = math.random(0, 999999999)
|
|
redis.call("HSET", key, "LOCK", lockValue)
|
|
redis.call("HSET", key, "CURR", last_seq)
|
|
redis.call("HSET", key, "TIME", mallocTime)
|
|
redis.call("EXPIRE", key, lockSecond)
|
|
table.insert(result, 3)
|
|
table.insert(result, curr_seq)
|
|
table.insert(result, last_seq)
|
|
table.insert(result, lockValue)
|
|
table.insert(result, mallocTime)
|
|
return result
|
|
end
|
|
redis.call("HSET", key, "CURR", max_seq)
|
|
redis.call("HSET", key, "TIME", ARGV[4])
|
|
redis.call("EXPIRE", key, dataSecond)
|
|
table.insert(result, 0)
|
|
table.insert(result, curr_seq)
|
|
table.insert(result, last_seq)
|
|
table.insert(result, mallocTime)
|
|
return result
|
|
`
|
|
result, err := s.rdb.Eval(ctx, script, []string{key}, size, int64(s.lockTime/time.Second), int64(s.dataTime/time.Second), time.Now().UnixMilli()).Int64Slice()
|
|
if err != nil {
|
|
return nil, errs.Wrap(err)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) wait(ctx context.Context) error {
|
|
timer := time.NewTimer(time.Second / 4)
|
|
defer timer.Stop()
|
|
select {
|
|
case <-timer.C:
|
|
return nil
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
}
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) setSeqRetry(ctx context.Context, key string, owner int64, currSeq int64, lastSeq int64, mill int64) {
|
|
for i := 0; i < 10; i++ {
|
|
state, err := s.setSeq(ctx, key, owner, currSeq, lastSeq, mill)
|
|
if err != nil {
|
|
log.ZError(ctx, "set seq cache failed", err, "key", key, "owner", owner, "currSeq", currSeq, "lastSeq", lastSeq, "count", i+1)
|
|
if err := s.wait(ctx); err != nil {
|
|
return
|
|
}
|
|
continue
|
|
}
|
|
switch state {
|
|
case 0: // ideal state
|
|
case 1:
|
|
log.ZWarn(ctx, "set seq cache lock not found", nil, "key", key, "owner", owner, "currSeq", currSeq, "lastSeq", lastSeq)
|
|
case 2:
|
|
log.ZWarn(ctx, "set seq cache lock to be held by someone else", nil, "key", key, "owner", owner, "currSeq", currSeq, "lastSeq", lastSeq)
|
|
default:
|
|
log.ZError(ctx, "set seq cache lock unknown state", nil, "key", key, "owner", owner, "currSeq", currSeq, "lastSeq", lastSeq)
|
|
}
|
|
return
|
|
}
|
|
log.ZError(ctx, "set seq cache retrying still failed", nil, "key", key, "owner", owner, "currSeq", currSeq, "lastSeq", lastSeq)
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) getMallocSize(conversationID string, size int64) int64 {
|
|
if size == 0 {
|
|
return 0
|
|
}
|
|
var basicSize int64
|
|
if msgprocessor.IsGroupConversationID(conversationID) {
|
|
basicSize = 100
|
|
} else {
|
|
basicSize = 50
|
|
}
|
|
basicSize += size
|
|
return basicSize
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) Malloc(ctx context.Context, conversationID string, size int64) (int64, error) {
|
|
seq, _, err := s.mallocTime(ctx, conversationID, size)
|
|
return seq, err
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) mallocTime(ctx context.Context, conversationID string, size int64) (int64, int64, error) {
|
|
if size < 0 {
|
|
return 0, 0, errs.New("size must be greater than 0")
|
|
}
|
|
key := s.getSeqMallocKey(conversationID)
|
|
for i := 0; i < 10; i++ {
|
|
states, err := s.malloc(ctx, key, size)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
switch states[0] {
|
|
case 0: // success
|
|
return states[1], states[3], nil
|
|
case 1: // not found
|
|
mallocSize := s.getMallocSize(conversationID, size)
|
|
seq, err := s.mgo.Malloc(ctx, conversationID, mallocSize)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
s.setSeqRetry(ctx, key, states[1], seq+size, seq+mallocSize, states[2])
|
|
return seq, 0, nil
|
|
case 2: // locked
|
|
if err := s.wait(ctx); err != nil {
|
|
return 0, 0, err
|
|
}
|
|
continue
|
|
case 3: // exceeded cache max value
|
|
currSeq := states[1]
|
|
lastSeq := states[2]
|
|
mill := states[4]
|
|
mallocSize := s.getMallocSize(conversationID, size)
|
|
seq, err := s.mgo.Malloc(ctx, conversationID, mallocSize)
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
if lastSeq == seq {
|
|
s.setSeqRetry(ctx, key, states[3], currSeq+size, seq+mallocSize, mill)
|
|
return currSeq, states[4], nil
|
|
} else {
|
|
log.ZWarn(ctx, "malloc seq not equal cache last seq", nil, "conversationID", conversationID, "currSeq", currSeq, "lastSeq", lastSeq, "mallocSeq", seq)
|
|
s.setSeqRetry(ctx, key, states[3], seq+size, seq+mallocSize, mill)
|
|
return seq, mill, nil
|
|
}
|
|
default:
|
|
log.ZError(ctx, "malloc seq unknown state", nil, "state", states[0], "conversationID", conversationID, "size", size)
|
|
return 0, 0, errs.New(fmt.Sprintf("unknown state: %d", states[0]))
|
|
}
|
|
}
|
|
log.ZError(ctx, "malloc seq retrying still failed", nil, "conversationID", conversationID, "size", size)
|
|
return 0, 0, errs.New("malloc seq waiting for lock timeout", "conversationID", conversationID, "size", size)
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) GetMaxSeq(ctx context.Context, conversationID string) (int64, error) {
|
|
return s.Malloc(ctx, conversationID, 0)
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) GetMaxSeqWithTime(ctx context.Context, conversationID string) (database.SeqTime, error) {
|
|
seq, mill, err := s.mallocTime(ctx, conversationID, 0)
|
|
if err != nil {
|
|
return database.SeqTime{}, err
|
|
}
|
|
return database.SeqTime{Seq: seq, Time: mill}, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) SetMinSeqs(ctx context.Context, seqs map[string]int64) error {
|
|
keys := make([]string, 0, len(seqs))
|
|
for conversationID, seq := range seqs {
|
|
keys = append(keys, s.getMinSeqKey(conversationID))
|
|
if err := s.mgo.SetMinSeq(ctx, conversationID, seq); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return DeleteCacheBySlot(ctx, s.rocks, keys)
|
|
}
|
|
|
|
// GetCacheMaxSeqWithTime only get the existing cache, if there is no cache, no cache will be generated
|
|
func (s *seqConversationCacheRedis) GetCacheMaxSeqWithTime(ctx context.Context, conversationIDs []string) (map[string]database.SeqTime, error) {
|
|
if len(conversationIDs) == 0 {
|
|
return map[string]database.SeqTime{}, nil
|
|
}
|
|
key2conversationID := make(map[string]string)
|
|
keys := make([]string, 0, len(conversationIDs))
|
|
for _, conversationID := range conversationIDs {
|
|
key := s.getSeqMallocKey(conversationID)
|
|
if _, ok := key2conversationID[key]; ok {
|
|
continue
|
|
}
|
|
key2conversationID[key] = conversationID
|
|
keys = append(keys, key)
|
|
}
|
|
slotKeys, err := groupKeysBySlot(ctx, s.rdb, keys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := make(map[string]database.SeqTime)
|
|
for _, keys := range slotKeys {
|
|
if len(keys) == 0 {
|
|
continue
|
|
}
|
|
pipe := s.rdb.Pipeline()
|
|
cmds := make([]*redis.SliceCmd, 0, len(keys))
|
|
for _, key := range keys {
|
|
cmds = append(cmds, pipe.HMGet(ctx, key, "CURR", "TIME"))
|
|
}
|
|
if _, err := pipe.Exec(ctx); err != nil {
|
|
return nil, errs.Wrap(err)
|
|
}
|
|
for i, cmd := range cmds {
|
|
val, err := cmd.Result()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(val) != 2 {
|
|
return nil, errs.WrapMsg(err, "GetCacheMaxSeqWithTime invalid result", "key", keys[i], "res", val)
|
|
}
|
|
if val[0] == nil {
|
|
continue
|
|
}
|
|
seq, err := s.parseInt64(val[0])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mill, err := s.parseInt64(val[1])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
conversationID := key2conversationID[keys[i]]
|
|
res[conversationID] = database.SeqTime{Seq: seq, Time: mill}
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (s *seqConversationCacheRedis) parseInt64(val any) (int64, error) {
|
|
switch v := val.(type) {
|
|
case nil:
|
|
return 0, nil
|
|
case int:
|
|
return int64(v), nil
|
|
case int64:
|
|
return v, nil
|
|
case string:
|
|
res, err := strconv.ParseInt(v, 10, 64)
|
|
if err != nil {
|
|
return 0, errs.WrapMsg(err, "invalid string not int64", "value", v)
|
|
}
|
|
return res, nil
|
|
default:
|
|
return 0, errs.New("invalid result not int64", "resType", fmt.Sprintf("%T", v), "value", v)
|
|
}
|
|
}
|