-
Notifications
You must be signed in to change notification settings - Fork 261
/
primary_key_utils.go
97 lines (82 loc) · 2 KB
/
primary_key_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2023 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package logtailreplay
import (
"bytes"
"math"
"github.com/matrixorigin/matrixone/pkg/container/types"
)
func (p *PartitionState) PrimaryKeyMayBeModified(
from types.TS,
to types.TS,
keys [][]byte,
) bool {
p.shared.Lock()
lastFlushTimestamp := p.shared.lastFlushTimestamp
p.shared.Unlock()
if !lastFlushTimestamp.IsEmpty() {
if from.LessEq(lastFlushTimestamp) {
return true
}
}
iter := p.primaryIndex.Copy().Iter()
pivot := RowEntry{
Time: types.BuildTS(math.MaxInt64, math.MaxUint32),
}
idxEntry := &PrimaryIndexEntry{}
defer iter.Release()
for _, key := range keys {
idxEntry.Bytes = key
for ok := iter.Seek(idxEntry); ok; ok = iter.Next() {
entry := iter.Item()
if !bytes.Equal(entry.Bytes, key) {
break
}
if entry.Time.GreaterEq(from) {
return true
}
// some legacy deletion entries may not indexed, check all rows for changes
pivot.BlockID = entry.BlockID
pivot.RowID = entry.RowID
rowIter := p.rows.Iter()
seek := false
for {
if !seek {
seek = true
if !rowIter.Seek(pivot) {
break
}
} else {
if !rowIter.Next() {
break
}
}
row := rowIter.Item()
if row.BlockID.Compare(entry.BlockID) != 0 {
break
}
if !row.RowID.Equal(entry.RowID) {
break
}
if row.Time.GreaterEq(from) {
rowIter.Release()
return true
}
}
rowIter.Release()
}
iter.First()
}
return false
}