Skip to content

Commit 6256f66

Browse files
committed
Add empty / miss lru cache
Empties were handled by the leaf cache previously
1 parent 23ee1bc commit 6256f66

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
@@ -203,6 +203,16 @@ proc getVtx*(
203203
)
204204
return ok(move(rc.value))
205205

206+
block:
207+
var rc =
208+
if GetVtxFlag.PeekCache in flags:
209+
rdb.rdEmptyLru.peek(rvid.vid)
210+
else:
211+
rdb.rdEmptyLru.get(rvid.vid)
212+
if rc.isOk():
213+
rdbVtxLruStats[rvid.to(RdbStateType)][RdbVertexType.Empty].inc(true)
214+
return ok(VertexRef(nil))
215+
206216
# Otherwise fetch from backend database
207217
# A threadvar is used to avoid allocating an environment for onData
208218
var res {.threadvar.}: Result[VertexRef, AristoError]
@@ -217,6 +227,9 @@ proc getVtx*(
217227

218228
if not gotData:
219229
rdbVtxLruStats[rvid.to(RdbStateType)][RdbVertexType.Empty].inc(false)
230+
if GetVtxFlag.PeekCache notin flags:
231+
rdb.rdEmptyLru.put(rvid.vid, default(tuple[]))
232+
220233
return ok(VertexRef(nil))
221234

222235
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)