fix(cache): enhance sequence generation atomicity and concurrency safety
Implement Lua scripts for atomic sequence incrementing and cold-start initialization in Redis to prevent race conditions. Improve the sequence buffer manager with CAS-like logic to prevent interval leakage during concurrent allocations. Update the message repository to use `SELECT ... FOR UPDATE` and conditional updates for `last_seq` to ensure database consistency during high concurrency. - Add `nextSeqLua` and `initSeqLua` for atomic Redis operations - Implement thread-safe buffer management in `seq_buffer.go` - Add row-level locking in `message_repo.go` - Update service layers to support group-aware sequence retrieval
This commit is contained in:
@@ -473,7 +473,7 @@ func (s *groupService) broadcastMemberJoinNotice(groupID string, targetUserID st
|
||||
}
|
||||
// 从 Redis 获取下一个 seq
|
||||
if s.conversationCache != nil {
|
||||
seq, seqErr := s.conversationCache.GetNextSeq(context.Background(), conv.ID)
|
||||
seq, seqErr := s.conversationCache.GetNextSeqWithGroup(context.Background(), conv.ID, true)
|
||||
if seqErr != nil {
|
||||
zap.L().Warn("get next seq failed, skipping system message",
|
||||
zap.String("convID", conv.ID),
|
||||
@@ -1398,7 +1398,7 @@ func (s *groupService) MuteMember(userID string, groupID string, targetUserID st
|
||||
|
||||
// 从 Redis 获取下一个 seq
|
||||
if s.conversationCache != nil {
|
||||
seq, seqErr := s.conversationCache.GetNextSeq(context.Background(), conv.ID)
|
||||
seq, seqErr := s.conversationCache.GetNextSeqWithGroup(context.Background(), conv.ID, true)
|
||||
if seqErr != nil {
|
||||
zap.L().Warn("get next seq failed, skipping system message",
|
||||
zap.String("convID", conv.ID),
|
||||
|
||||
Reference in New Issue
Block a user