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

Make cdcRecordsStorage Len threadsafe #1301

Merged
merged 1 commit into from
Feb 15, 2024
Merged
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
15 changes: 8 additions & 7 deletions flow/connectors/utils/cdc_records/cdc_records_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"
"os"
"runtime"
"sync/atomic"
"time"

"github.com/cockroachdb/pebble"
Expand All @@ -32,7 +33,7 @@ func encVal(val any) ([]byte, error) {
type cdcRecordsStore struct {
inMemoryRecords map[model.TableWithPkey]model.Record
pebbleDB *pebble.DB
numRecords int
numRecords atomic.Int32
flowJobName string
dbFolderName string
numRecordsSwitchThreshold int
Expand All @@ -45,7 +46,7 @@ func NewCDCRecordsStore(flowJobName string) *cdcRecordsStore {
return &cdcRecordsStore{
inMemoryRecords: make(map[model.TableWithPkey]model.Record),
pebbleDB: nil,
numRecords: 0,
numRecords: atomic.Int32{},
flowJobName: flowJobName,
dbFolderName: fmt.Sprintf("%s/%s_%s", os.TempDir(), flowJobName, shared.RandomString(8)),
numRecordsSwitchThreshold: peerdbenv.PeerDBCDCDiskSpillRecordsThreshold(),
Expand Down Expand Up @@ -138,7 +139,7 @@ func (c *cdcRecordsStore) Set(logger log.Logger, key *model.TableWithPkey, rec m
}
}
}
c.numRecords++
c.numRecords.Add(1)
return nil
}

Expand Down Expand Up @@ -181,12 +182,12 @@ func (c *cdcRecordsStore) Get(key model.TableWithPkey) (model.Record, bool, erro
return nil, false, nil
}

func (c *cdcRecordsStore) IsEmpty() bool {
return c.numRecords == 0
func (c *cdcRecordsStore) Len() int {
return int(c.numRecords.Load())
}

func (c *cdcRecordsStore) Len() int {
return c.numRecords
func (c *cdcRecordsStore) IsEmpty() bool {
return c.Len() == 0
}

func (c *cdcRecordsStore) Close() error {
Expand Down
Loading