-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,9 @@ type store struct { | |
|
||
ig ConsistentIndexGetter | ||
|
||
cache map[revision]mvccpb.KeyValue | ||
clock sync.RWMutex | ||
|
||
b backend.Backend | ||
kvindex index | ||
|
||
|
@@ -125,6 +128,8 @@ func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, ig ConsistentI | |
b: b, | ||
ig: ig, | ||
kvindex: newTreeIndex(lg), | ||
cache: map[revision]mvccpb.KeyValue{}, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
zyfo2
Owner
|
||
clock: sync.RWMutex{}, | ||
|
||
le: le, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"go.etcd.io/etcd/mvcc/mvccpb" | ||
"go.etcd.io/etcd/pkg/traceutil" | ||
"go.uber.org/zap" | ||
"strconv" | ||
) | ||
|
||
type storeTxnRead struct { | ||
|
@@ -140,9 +141,16 @@ func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions | |
limit = len(revpairs) | ||
} | ||
|
||
kvs := make([]mvccpb.KeyValue, limit) | ||
kvs := make([]*mvccpb.KeyValue, limit) | ||
revBytes := newRevBytes() | ||
for i, revpair := range revpairs[:len(kvs)] { | ||
tr.s.clock.RLock() | ||
v, exists := tr.s.cache[revpair] | ||
tr.s.clock.RUnlock() | ||
if exists { | ||
kvs[i] = &v | ||
continue | ||
} | ||
revToBytes(revpair, revBytes) | ||
_, vs := tr.tx.UnsafeRange(keyBucketName, revBytes, nil, 0) | ||
if len(vs) != 1 { | ||
|
@@ -156,7 +164,8 @@ func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions | |
plog.Fatalf("range cannot find rev (%d,%d)", revpair.main, revpair.sub) | ||
} | ||
} | ||
if err := kvs[i].Unmarshal(vs[0]); err != nil { | ||
x := mvccpb.KeyValue{} | ||
if err := x.Unmarshal(vs[0]); err != nil { | ||
if tr.s.lg != nil { | ||
tr.s.lg.Fatal( | ||
"failed to unmarshal mvccpb.KeyValue", | ||
|
@@ -165,6 +174,12 @@ func (tr *storeTxnRead) rangeKeys(key, end []byte, curRev int64, ro RangeOptions | |
} else { | ||
plog.Fatalf("cannot unmarshal event: %v", err) | ||
} | ||
} else { | ||
kvs[i] = &x | ||
tr.s.clock.Lock() | ||
This comment has been minimized.
Sorry, something went wrong.
chaochn47
|
||
tr.s.cache[revpair] = x | ||
tr.s.clock.Unlock() | ||
plog.Warning("caching " + strconv.Itoa(i)) | ||
} | ||
} | ||
tr.trace.Step("range keys from bolt db") | ||
|
IMHO, another "hot" key to revision mapping to reduce the size of map is needed.