Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit f1361c2

Browse files
committed
add locks to meta record status
1 parent 8b6a99b commit f1361c2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

idx/metatags/meta_record_status.go

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/rand"
55
"fmt"
66
"io"
7+
"sync"
78
)
89

910
var (
@@ -15,6 +16,7 @@ var (
1516
)
1617

1718
type MetaRecordStatusByOrg struct {
19+
sync.RWMutex
1820
byOrg map[uint32]metaRecordStatus
1921
}
2022

@@ -93,6 +95,9 @@ func (u UUID) String() string {
9395
// it returns a boolean indicating whether a reload of the meta records is necessary and
9496
// if it is then the second returned value is the batch id that needs to be loaded
9597
func (m *MetaRecordStatusByOrg) Update(orgId uint32, newBatch UUID, newCreatedAt, newLastUpdate uint64) (bool, UUID) {
98+
m.Lock()
99+
defer m.Unlock()
100+
96101
status, ok := m.byOrg[orgId]
97102
if !ok {
98103
m.byOrg[orgId] = metaRecordStatus{
@@ -125,6 +130,9 @@ func (m *MetaRecordStatusByOrg) Update(orgId uint32, newBatch UUID, newCreatedAt
125130
}
126131

127132
func (m *MetaRecordStatusByOrg) GetStatus(orgId uint32) (UUID, uint64, uint64) {
133+
m.RLock()
134+
defer m.RUnlock()
135+
128136
status, ok := m.byOrg[orgId]
129137
if !ok {
130138
return DefaultBatchId, 0, 0

0 commit comments

Comments
 (0)