Skip to content

Commit 28d47ce

Browse files
authored
fix: race condition in lids and pos in indexator (#279)
1 parent 1f9c436 commit 28d47ce

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

frac/active_docs_positions.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ import (
77
)
88

99
type DocsPositions struct {
10-
mu sync.RWMutex
11-
idToPos map[seq.ID]seq.DocPos
12-
lidToPos []seq.DocPos
10+
mu sync.RWMutex
11+
idToPos map[seq.ID]seq.DocPos
1312
}
1413

1514
func NewSyncDocsPositions() *DocsPositions {
1615
dp := DocsPositions{
17-
lidToPos: make([]seq.DocPos, 0),
18-
idToPos: make(map[seq.ID]seq.DocPos),
16+
idToPos: make(map[seq.ID]seq.DocPos),
1917
}
20-
dp.lidToPos = append(dp.lidToPos, 0) // systemID
2118
return &dp
2219
}
2320

@@ -54,7 +51,6 @@ func (dp *DocsPositions) SetMultiple(ids []seq.ID, pos []seq.DocPos) []seq.ID {
5451
dp.idToPos[id] = pos[i]
5552
}
5653

57-
dp.lidToPos = append(dp.lidToPos, pos[i])
5854
appended = append(appended, id)
5955
}
6056
return appended

frac/active_sealing_source.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ import (
4040
// All iterators work with pre-sorted data and return information
4141
// in an order optimal for creating disk index structures.
4242
type ActiveSealingSource struct {
43-
params common.SealParams // Sealing parameters
44-
info *common.Info // fraction Info
45-
created time.Time // Creation time of the source
46-
sortedLIDs []uint32 // Sorted LIDs (Local ID)
47-
oldToNewLIDs []uint32 // Mapping from old LIDs to new ones (after sorting)
48-
mids *UInt64s // MIDs
49-
rids *UInt64s // RIDs
50-
fields []string // Sorted field names
51-
fieldsMaxTIDs []uint32 // Maximum TIDs for each field
52-
tids []uint32 // Sorted TIDs (Token ID)
53-
tokens [][]byte // Tokens (values) by TID
54-
lids []*TokenLIDs // LID lists for each token
55-
docPosOrig []seq.DocPos // Original document positions
56-
docPosSorted []seq.DocPos // Document positions after sorting
57-
blocksOffsets []uint64 // Document block offsets
58-
docsReader *storage.DocsReader // Document storage reader
59-
lastErr error // Last error
43+
params common.SealParams // Sealing parameters
44+
info *common.Info // fraction Info
45+
created time.Time // Creation time of the source
46+
sortedLIDs []uint32 // Sorted LIDs (Local ID)
47+
oldToNewLIDs []uint32 // Mapping from old LIDs to new ones (after sorting)
48+
mids *UInt64s // MIDs
49+
rids *UInt64s // RIDs
50+
fields []string // Sorted field names
51+
fieldsMaxTIDs []uint32 // Maximum TIDs for each field
52+
tids []uint32 // Sorted TIDs (Token ID)
53+
tokens [][]byte // Tokens (values) by TID
54+
lids []*TokenLIDs // LID lists for each token
55+
docPosMap map[seq.ID]seq.DocPos // Original document positions
56+
docPosSorted []seq.DocPos // Document positions after sorting
57+
blocksOffsets []uint64 // Document block offsets
58+
docsReader *storage.DocsReader // Document storage reader
59+
lastErr error // Last error
6060
}
6161

6262
// NewActiveSealingSource creates a new data source for sealing
@@ -84,7 +84,7 @@ func NewActiveSealingSource(active *Active, params common.SealParams) (*ActiveSe
8484
fieldsMaxTIDs: fieldsMaxTIDs,
8585
tokens: active.TokenList.tidToVal,
8686
lids: active.TokenList.tidToLIDs,
87-
docPosOrig: active.DocsPositions.lidToPos,
87+
docPosMap: active.DocsPositions.idToPos,
8888
blocksOffsets: active.DocBlocks.vals,
8989
docsReader: &active.sortReader,
9090
}
@@ -237,7 +237,7 @@ func (src *ActiveSealingSource) IDsBlocks(blockSize int) iter.Seq2[[]seq.ID, []s
237237

238238
// Use sorted or original positions
239239
if len(src.docPosSorted) == 0 {
240-
pos = append(pos, src.docPosOrig[lid])
240+
pos = append(pos, src.docPosMap[id])
241241
} else {
242242
pos = append(pos, src.docPosSorted[i+1]) // +1 for system document
243243
}

0 commit comments

Comments
 (0)