Skip to content

Commit 4e09cbe

Browse files
committed
Add empty / miss lru cache
Empties were handled by the leaf cache previously
1 parent 2e9036d commit 4e09cbe

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

execution_chain/db/aristo/aristo_init/rocks_db/rdb_desc.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type
6262
rdBranchLru*: LruCache[VertexID, (VertexID, uint16)]
6363
rdBranchSize*: int
6464

65+
rdEmptyLru*: LruCache[VertexID,tuple[]] ## Read cache
66+
6567
AristoCFs* = enum
6668
## Column family symbols/handles and names used on the database
6769
AdmCF = "AriAdm" ## Admin column family name

execution_chain/db/aristo/aristo_init/rocks_db/rdb_get.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ proc getVtx*(
196196
)
197197
return ok(move(rc.value))
198198

199+
block:
200+
var rc =
201+
if GetVtxFlag.PeekCache in flags:
202+
rdb.rdEmptyLru.peek(rvid.vid)
203+
else:
204+
rdb.rdEmptyLru.get(rvid.vid)
205+
if rc.isOk():
206+
rdbVtxLruStats[rvid.to(RdbStateType)][RdbVertexType.Empty].inc(true)
207+
return ok(VertexRef(nil))
208+
199209
# Otherwise fetch from backend database
200210
# A threadvar is used to avoid allocating an environment for onData
201211
var res {.threadvar.}: Result[VertexRef, AristoError]
@@ -210,6 +220,9 @@ proc getVtx*(
210220

211221
if not gotData:
212222
rdbVtxLruStats[rvid.to(RdbStateType)][RdbVertexType.Empty].inc(false)
223+
if GetVtxFlag.PeekCache notin flags:
224+
rdb.rdEmptyLru.put(rvid.vid, default(tuple[]))
225+
213226
return ok(VertexRef(nil))
214227

215228
if res.isErr():

execution_chain/db/aristo/aristo_init/rocks_db/rdb_init.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ proc init*(rdb: var RdbInst, opts: DbOptions, baseDb: RocksDbInstanceRef) =
9999
rdb.rdKeyLru = typeof(rdb.rdKeyLru).init(rdb.rdKeySize)
100100
rdb.rdVtxLru = typeof(rdb.rdVtxLru).init(rdb.rdVtxSize)
101101
rdb.rdBranchLru = typeof(rdb.rdBranchLru).init(rdb.rdBranchSize)
102+
rdb.rdEmptyLru = typeof(rdb.rdEmptyLru).init(rdb.rdVtxSize) # reuse vtx cache size
102103

103104
if opts.rdbPrintStats:
104105
let

execution_chain/db/aristo/aristo_init/rocks_db/rdb_put.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ proc putVtx*(
105105
else:
106106
discard rdb.rdVtxLru.update(rvid.vid, vtx)
107107

108+
rdb.rdEmptyLru.del(rvid.vid)
109+
108110
if key.isValid:
109111
if rdb.rdKeyLru.len < rdb.rdKeyLru.capacity:
110112
rdb.rdKeyLru.put(rvid.vid, key)
@@ -126,6 +128,9 @@ proc putVtx*(
126128
rdb.rdVtxLru.del rvid.vid
127129
rdb.rdKeyLru.del rvid.vid
128130

131+
if rdb.rdEmptyLru.len < rdb.rdEmptyLru.capacity:
132+
rdb.rdEmptyLru.put(rvid.vid, default(tuple[]))
133+
129134
ok()
130135

131136
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)