From 3d300e51ddd9870d31e0ebfce01d8850588f8693 Mon Sep 17 00:00:00 2001 From: codchen Date: Wed, 28 Jun 2023 10:29:10 +0800 Subject: [PATCH 1/2] add logs --- store/cachekv/store.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 59cb434b4..5996414db 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -2,6 +2,7 @@ package cachekv import ( "bytes" + "fmt" "io" "sort" "sync" @@ -47,7 +48,13 @@ func (b mapCacheBackend) Range(f func(string, *types.CValue) bool) { keys = append(keys, k) } for _, key := range keys { - val, _ := b.Get(key) + val, ok := b.Get(key) + if !ok { + panic(fmt.Sprintf("Range is supposed to be atomic but is not when getting %s", key)) + } + if val == nil { + panic(fmt.Sprintf("cache backend is not supposed to have nil values but got one for %s", key)) + } if !f(key, val) { break } @@ -165,6 +172,10 @@ func (store *Store) Write() { // Not the best, but probably not a bottleneck depending. keys := make([]string, 0, store.cache.Len()) + parent := store.parent + storeType := parent.GetStoreType() + cacheLen := store.cache.Len() + fmt.Printf("store %s has a cache size of %d\n", storeType, cacheLen) store.cache.Range(func(key string, dbValue *types.CValue) bool { if dbValue.Dirty() { keys = append(keys, key) From e60c8cd67a37c4087be98ea5fb52b6ffd6bf7bc1 Mon Sep 17 00:00:00 2001 From: codchen Date: Wed, 28 Jun 2023 15:37:19 +0800 Subject: [PATCH 2/2] push --- store/cachekv/store.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 5996414db..68c6f86d4 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -2,6 +2,7 @@ package cachekv import ( "bytes" + "encoding/base64" "fmt" "io" "sort" @@ -38,18 +39,24 @@ func (b mapCacheBackend) Len() int { } func (b mapCacheBackend) Delete(key string) { + fmt.Printf("delete key %s\n", base64.StdEncoding.EncodeToString([]byte(key))) delete(b.m, key) } func (b mapCacheBackend) Range(f func(string, *types.CValue) bool) { // this is always called within a mutex so all operations below are atomic keys := []string{} + fmt.Printf("klen: %d\n", len(b.m)) for k := range b.m { keys = append(keys, k) } for _, key := range keys { val, ok := b.Get(key) if !ok { + fmt.Printf("Keys: %d, len: %d, Len: %d\n", len(keys), len(b.m), b.Len()) + if _, ok := b.m[key]; !ok { + panic(fmt.Sprintf("invalid key %s", base64.StdEncoding.EncodeToString([]byte(key)))) + } panic(fmt.Sprintf("Range is supposed to be atomic but is not when getting %s", key)) } if val == nil { @@ -158,6 +165,7 @@ func (store *Store) Delete(key []byte) { defer telemetry.MeasureSince(time.Now(), "store", "cachekv", "delete") types.AssertValidKey(key) + fmt.Println("store delete") store.setCacheValue(key, nil, true, true) store.eventManager.EmitResourceAccessWriteEvent("delete", store.storeKey, key, []byte{}) } @@ -172,10 +180,8 @@ func (store *Store) Write() { // Not the best, but probably not a bottleneck depending. keys := make([]string, 0, store.cache.Len()) - parent := store.parent - storeType := parent.GetStoreType() cacheLen := store.cache.Len() - fmt.Printf("store %s has a cache size of %d\n", storeType, cacheLen) + fmt.Printf("store %s has a cache size of %d\n", store.storeKey, cacheLen) store.cache.Range(func(key string, dbValue *types.CValue) bool { if dbValue.Dirty() { keys = append(keys, key) @@ -207,6 +213,7 @@ func (store *Store) Write() { // Clear the cache using the map clearing idiom // and not allocating fresh objects. // Please see https://bencher.orijtech.com/perfclinic/mapclearing/ + fmt.Printf("store %s delete all\n", store.storeKey) store.cache.DeleteAll() store.deleted.Range(func(key, value any) bool { store.deleted.Delete(key)