Skip to content

Commit

Permalink
memdb: fix memdb snapshot get/iter is not actually snapshot (tikv#1393)…
Browse files Browse the repository at this point in the history
… (tikv#1436)

Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 authored Sep 10, 2024
1 parent 1828776 commit 8784102
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
api_version: [v1ttl, v2]
api_version: [v1ttl]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:
- name: Lint
uses: golangci/[email protected]
with:
version: v1.52.2
version: v1.55.2

2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ linters:
enable:
- bodyclose
- deadcode
- depguard
#- depguard
- exportloopref
- gofmt
- goimports
Expand Down
6 changes: 4 additions & 2 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import (

const (
// DefStoreLivenessTimeout is the default value for store liveness timeout.
DefStoreLivenessTimeout = "1s"
DefGrpcInitialWindowSize = 1 << 27 // 128MiB
DefStoreLivenessTimeout = "1s"
// DefGrpcInitialWindowSize is the default value for initial window size on a stream.
DefGrpcInitialWindowSize = 1 << 27 // 128MiB
// DefGrpcInitialConnWindowSize is the default value for initial window size on a connection.
DefGrpcInitialConnWindowSize = 1 << 27 // 128MiB
)

Expand Down
9 changes: 6 additions & 3 deletions internal/locate/region_request_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ func testStaleRead(s *testRegionCacheStaleReadSuite, r *RegionCacheTestCase, zon
}

type Option[T interface{}] struct {
//nolint: structcheck
inner *T
}

Expand All @@ -645,9 +646,11 @@ func (o Option[T]) Inner() *T {
}

type RegionCacheTestCase struct {
debug bool
do func(s *testRegionCacheStaleReadSuite)
extra []func(s *testRegionCacheStaleReadSuite)
//nolint: structcheck
debug bool
do func(s *testRegionCacheStaleReadSuite)
extra []func(s *testRegionCacheStaleReadSuite)
//nolint: structcheck
recoverable bool
// local peer is leader
leaderRegionValid bool
Expand Down
2 changes: 1 addition & 1 deletion internal/unionstore/memdb_arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (l *memdbVlog) getSnapshotValue(addr memdbArenaAddr, snap *MemDBCheckpoint)
if result.isNull() {
return nil, false
}
return l.getValue(addr), true
return l.getValue(result), true
}

func (l *memdbVlog) selectValueHistory(addr memdbArenaAddr, predicate func(memdbArenaAddr) bool) memdbArenaAddr {
Expand Down
39 changes: 39 additions & 0 deletions internal/unionstore/memdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,3 +840,42 @@ func TestUnsetTemporaryFlag(t *testing.T) {
require.Nil(err)
require.False(flags.HasNeedConstraintCheckInPrewrite())
}

func TestSnapshotGetIter(t *testing.T) {
assert := assert.New(t)
buffer := newMemDB()
var getters []Getter
var iters []Iterator
for i := 0; i < 100; i++ {
expectValue := i
if expectValue > 50 {
expectValue = 50
}
assert.Nil(buffer.Set([]byte{byte(0)}, []byte{byte(i)}))
// getter
getter := buffer.SnapshotGetter()
val, err := getter.Get([]byte{byte(0)})
assert.Nil(err)
assert.Equal(val, []byte{byte(expectValue)})
getters = append(getters, getter)
// iter
iter := buffer.SnapshotIter(nil, nil)
assert.Nil(err)
assert.Equal(iter.Key(), []byte{byte(0)})
assert.Equal(iter.Value(), []byte{byte(expectValue)})
iter.Close()
iters = append(iters, buffer.SnapshotIter(nil, nil))
if i == 50 {
_ = buffer.Staging()
}
}
for _, getter := range getters {
val, err := getter.Get([]byte{byte(0)})
assert.Nil(err)
assert.Equal(val, []byte{byte(50)})
}
for _, iter := range iters {
assert.Equal(iter.Key(), []byte{byte(0)})
assert.Equal(iter.Value(), []byte{byte(50)})
}
}
3 changes: 3 additions & 0 deletions oracle/oracles/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type lastTSOPointer struct {
p unsafe.Pointer
}

// NewLastTSOPointer creates a lastTSOPointer.
//
//nolint:golint
func NewLastTSOPointer(last *lastTSO) *lastTSOPointer {
return &lastTSOPointer{p: unsafe.Pointer(last)}
}
Expand Down

0 comments on commit 8784102

Please sign in to comment.