Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unsafe concurrent consuming api of rocksmq #39544

Merged
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: 1 addition & 1 deletion internal/rootcoord/dml_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestDmlChannels(t *testing.T) {
defer paramtable.Get().Reset(Params.CommonCfg.PreCreatedTopicEnabled.Key)
defer paramtable.Get().Reset(Params.CommonCfg.TopicNames.Key)

assert.Panics(t, func() { newDmlChannels(ctx, factory, dmlChanPrefix, totalDmlChannelNum) })
newDmlChannels(ctx, factory, dmlChanPrefix, totalDmlChannelNum)
}

func TestDmChannelsFailure(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/mq/mqimpl/rocksmq/client/client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
GroupName: consumer.consumerName,
MsgMutex: consumer.msgMutex,
}
c.server.RegisterConsumer(cons)
if err := c.server.RegisterConsumer(cons); err != nil {
return nil, err
}

Check warning on line 116 in pkg/mq/mqimpl/rocksmq/client/client_impl.go

View check run for this annotation

Codecov / codecov/patch

pkg/mq/mqimpl/rocksmq/client/client_impl.go#L115-L116

Added lines #L115 - L116 were not covered by tests

if options.SubscriptionInitialPosition == common.SubscriptionPositionLatest {
err = c.server.SeekToLatest(options.Topic, options.SubscriptionName)
Expand Down
9 changes: 6 additions & 3 deletions pkg/mq/mqimpl/rocksmq/server/rocksmq_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,7 @@ func (rmq *rocksmq) CreateTopic(topicName string) error {
return nil
}

if _, ok := topicMu.Load(topicName); !ok {
topicMu.Store(topicName, new(sync.Mutex))
}
topicMu.LoadOrStore(topicName, new(sync.Mutex))

// msgSizeKey -> msgSize
// topicIDKey -> topic creating time
Expand Down Expand Up @@ -550,6 +548,11 @@ func (rmq *rocksmq) RegisterConsumer(consumer *Consumer) error {
if rmq.isClosed() {
return errors.New(RmqNotServingErrMsg)
}
ll, _ := topicMu.LoadOrStore(consumer.Topic, new(sync.Mutex))
mu, _ := ll.(*sync.Mutex)
mu.Lock()
defer mu.Unlock()

start := time.Now()
if vals, ok := rmq.consumers.Load(consumer.Topic); ok {
for _, v := range vals.([]*Consumer) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mq/mqimpl/rocksmq/server/rocksmq_retention.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func initRetentionInfo(kv *rocksdbkv.RocksdbKV, db *gorocksdb.DB) (*retentionInf
for _, key := range topicKeys {
topic := key[len(TopicIDTitle):]
ri.topicRetetionTime.Insert(topic, time.Now().Unix())
topicMu.Store(topic, new(sync.Mutex))
topicMu.LoadOrStore(topic, new(sync.Mutex))
}
return ri, nil
}
Expand Down
Loading