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

sink: fix concurrent map access in sink manager (#2249) #2299

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
4 changes: 2 additions & 2 deletions cdc/sink/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func NewManager(ctx context.Context, backendSink Sink, errCh chan error, checkpo

// CreateTableSink creates a table sink
func (m *Manager) CreateTableSink(tableID model.TableID, checkpointTs model.Ts) Sink {
m.tableSinksMu.Lock()
defer m.tableSinksMu.Unlock()
if _, exist := m.tableSinks[tableID]; exist {
log.Panic("the table sink already exists", zap.Uint64("tableID", uint64(tableID)))
}
Expand All @@ -67,8 +69,6 @@ func (m *Manager) CreateTableSink(tableID model.TableID, checkpointTs model.Ts)
buffer: make([]*model.RowChangedEvent, 0, 128),
emittedTs: checkpointTs,
}
m.tableSinksMu.Lock()
defer m.tableSinksMu.Unlock()
m.tableSinks[tableID] = sink
return sink
}
Expand Down
8 changes: 7 additions & 1 deletion cdc/sink/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ func (s *managerSuite) TestManagerRandom(c *check.C) {
var wg sync.WaitGroup
tableSinks := make([]Sink, goroutineNum)
for i := 0; i < goroutineNum; i++ {
tableSinks[i] = manager.CreateTableSink(model.TableID(i), 0)
i := i
wg.Add(1)
go func() {
defer wg.Done()
tableSinks[i] = manager.CreateTableSink(model.TableID(i), 0)
}()
}
wg.Wait()
for i := 0; i < goroutineNum; i++ {
i := i
tableSink := tableSinks[i]
Expand Down