Skip to content

Commit

Permalink
snapshot getter with mutex
Browse files Browse the repository at this point in the history
Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 committed Dec 17, 2024
1 parent 43d2db7 commit 64f5373
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/unionstore/memdb_art.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ func (db *artDBWithContext) SnapshotIterReverse(upper, lower []byte) Iterator {
return db.ART.SnapshotIterReverse(upper, lower)
}

// SnapshotGetter returns a Getter for a snapshot of MemBuffer.
func (db *artDBWithContext) SnapshotGetter() Getter {
return db.ART.SnapshotGetter()
return &SnapshotGetter{
mu: &db.RWMutex,
getter: db.ART.SnapshotGetter(),
}
}
5 changes: 4 additions & 1 deletion internal/unionstore/memdb_rbt.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,8 @@ func (db *rbtDBWithContext) SnapshotIterReverse(upper, lower []byte) Iterator {

// SnapshotGetter returns a Getter for a snapshot of MemBuffer.
func (db *rbtDBWithContext) SnapshotGetter() Getter {
return db.RBT.SnapshotGetter()
return &SnapshotGetter{
mu: &db.RWMutex,
getter: db.RBT.SnapshotGetter(),
}
}
12 changes: 12 additions & 0 deletions internal/unionstore/union_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ package unionstore

import (
"context"
"sync"
"time"

tikverr "github.com/tikv/client-go/v2/error"
Expand Down Expand Up @@ -254,3 +255,14 @@ var (
_ MemBuffer = &rbtDBWithContext{}
_ MemBuffer = &artDBWithContext{}
)

type SnapshotGetter struct {
mu *sync.RWMutex
getter Getter
}

func (getter *SnapshotGetter) Get(ctx context.Context, key []byte) ([]byte, error) {
getter.mu.RLock()
defer getter.mu.RUnlock()
return getter.getter.Get(ctx, key)
}

0 comments on commit 64f5373

Please sign in to comment.