github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/store/iavl/oec_flat_kv.go (about) 1 package iavl 2 3 import "fmt" 4 5 func (st *Store) getFlatKV(key []byte) []byte { 6 if st.flatKVStore == nil { 7 return nil 8 } 9 return st.flatKVStore.Get(key) 10 } 11 12 func (st *Store) setFlatKV(key, value []byte) { 13 if st.flatKVStore == nil { 14 return 15 } 16 st.flatKVStore.Set(key, value) 17 } 18 19 func (st *Store) commitFlatKV(version int64) { 20 if st.flatKVStore == nil { 21 return 22 } 23 st.flatKVStore.Commit(version) 24 } 25 26 func (st *Store) hasFlatKV(key []byte) bool { 27 if st.flatKVStore == nil { 28 return false 29 } 30 return st.flatKVStore.Has(key) 31 } 32 33 func (st *Store) deleteFlatKV(key []byte) { 34 if st.flatKVStore == nil { 35 return 36 } 37 st.flatKVStore.Delete(key) 38 } 39 40 func (st *Store) resetFlatKVCount() { 41 if st.flatKVStore == nil { 42 return 43 } 44 st.flatKVStore.ResetCount() 45 } 46 47 func (st *Store) GetFlatKVReadTime() int { 48 if st.flatKVStore == nil { 49 return 0 50 } 51 return st.flatKVStore.GetDBReadTime() 52 } 53 54 func (st *Store) GetFlatKVWriteTime() int { 55 if st.flatKVStore == nil { 56 return 0 57 } 58 return st.flatKVStore.GetDBWriteTime() 59 } 60 61 func (st *Store) GetFlatKVReadCount() int { 62 if st.flatKVStore == nil { 63 return 0 64 } 65 return st.flatKVStore.GetDBReadCount() 66 } 67 68 func (st *Store) GetFlatKVWriteCount() int { 69 if st.flatKVStore == nil { 70 return 0 71 } 72 return st.flatKVStore.GetDBWriteCount() 73 } 74 75 func (st *Store) ValidateFlatVersion() error { 76 if !st.flatKVStore.Enable() { 77 return nil 78 } 79 80 treeVersion := st.tree.Version() 81 flatVersion := st.flatKVStore.GetLatestVersion() 82 if flatVersion != 0 && flatVersion != treeVersion { 83 return fmt.Errorf("the version of flat db(%d) does not match the version of iavl tree(%d), you can delete flat.db and restart node", 84 flatVersion, treeVersion) 85 } 86 return nil 87 }