Skip to content

Commit 9591d66

Browse files
authored
Fix WAL file buildup (#3603)
Due to the wrong CF being passed to the database flush mechanism during sync, the sync KVT would remain unflushed as a memtable and thus prevent the WAL from being released - given that a new wal is created for every flush, this would lead to a buildup of small WAL files (50k and counting on my hoodi node) after a sync. At the same time, we don't really need to flush the KVT at every commit since the skiplist permits efficient lookups (unlike the vector memtable used for bulk updates to the state).
1 parent 1cfc89f commit 9591d66

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ proc rollback*(rdb: var RdbInst, session: SharedWriteBatchRef) =
4646
proc commit*(rdb: var RdbInst, session: SharedWriteBatchRef): Result[void,(AristoError,string)] =
4747
if not session.isClosed():
4848
defer: session.close()
49-
rdb.baseDb.commit(session, rdb.vtxCol).isOkOr:
49+
rdb.baseDb.commit(session, rdb.vtxCol, true).isOkOr:
5050
const errSym = RdbBeDriverWriteError
5151
when extraTraceMessages:
5252
trace logTxt "commit", error=errSym, info=error

execution_chain/db/core_db/backend/aristo_rocksdb.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ proc toDbOpts*(opts: DbOptions): DbOptionsRef =
4242
# https://github.com/facebook/rocksdb/blob/af50823069818fc127438e39fef91d2486d6e76c/include/rocksdb/options.h#L1276
4343
dbOpts.rowCache = cacheCreateLRU(opts.rowCacheSize, autoClose = true)
4444

45+
# The WAL is shared between column families and a single small unflushed CF
46+
# (like the sync cache) can keep the WAL growing for a long time - this both
47+
# causes poor startup times and results in an ever-growing number of WAL files.
48+
# The default value is very large, specially given that each manual flush
49+
# of the aristo table creates a new log file.
50+
# https://github.com/facebook/rocksdb/blob/af50823069818fc127438e39fef91d2486d6e76c/include/rocksdb/options.h#L719
51+
let writeBufferSize =
52+
if opts.writeBufferSize > 0: opts.writeBufferSize else: defaultWriteBufferSize
53+
54+
dbOpts.maxTotalWalSize = 3 * writeBufferSize + 1024 * 1024
55+
4556
dbOpts.keepLogFileNum = 16 # No point keeping 1000 log files around...
4657

4758
# Parallelize L0 -> Ln compaction

execution_chain/db/core_db/backend/rocksdb_desc.nim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,20 @@ proc close*(session: SharedWriteBatchRef) =
5858
session.closes = 0
5959

6060
proc commit*(
61-
rdb: RocksDbInstanceRef, session: SharedWriteBatchRef, cf: ColFamilyReadWrite
61+
rdb: RocksDbInstanceRef,
62+
session: SharedWriteBatchRef,
63+
cf: ColFamilyReadWrite,
64+
flush: bool,
6265
): Result[void, string] =
6366
session.commits += 1
64-
session.families.add cf
67+
68+
if flush:
69+
session.families.add cf
70+
6571
if session.commits == session.refs:
6672
# Write to disk if everyone that opened a session also committed it
6773
?rdb.db.write(session.batch)
74+
6875
# This flush forces memtables to be written to disk, which is necessary given
6976
# the use of vector memtables which have very bad lookup performance.
7077
rdb.db.flush(session.families.mapIt(it.handle())).isOkOr:
@@ -80,7 +87,6 @@ proc open*(
8087
dbOpts: DbOptionsRef,
8188
cfs: openArray[(string, ColFamilyOptionsRef)],
8289
): Result[RocksDbInstanceRef, string] =
83-
8490
let ecdbDir = baseDir.ecdbDir
8591

8692
if not dirExists(ecdbDir):

execution_chain/db/kvt/kvt_init/rocks_db.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ proc putKvpFn(db: RdbBackendRef, cf: static[KvtCFs]): PutKvpFn =
122122
return
123123

124124

125-
proc putEndFn(db: RdbBackendRef): PutEndFn =
125+
proc putEndFn(db: RdbBackendRef, cf: static[KvtCFs]): PutEndFn =
126126
result =
127127
proc(hdl: PutHdlRef): Result[void,KvtError] =
128128
let hdl = hdl.endSession db
@@ -133,7 +133,7 @@ proc putEndFn(db: RdbBackendRef): PutEndFn =
133133
return err(hdl.error)
134134

135135
# Commit session
136-
db.rdb.commit(hdl.session).isOkOr:
136+
db.rdb.commit(hdl.session, cf).isOkOr:
137137
when extraTraceMessages:
138138
trace "putEndFn: failed", error=($error[0]), info=error[1]
139139
return err(error[0])
@@ -170,7 +170,7 @@ proc rocksDbKvtBackend*(baseDb: RocksDbInstanceRef, cf: static[KvtCFs]): KvtDbRe
170170

171171
db.putBegFn = putBegFn be
172172
db.putKvpFn = putKvpFn(be, cf)
173-
db.putEndFn = putEndFn be
173+
db.putEndFn = putEndFn(be, cf)
174174

175175
db.closeFn = closeFn be
176176
db.getBackendFn = getBackendFn be

execution_chain/db/kvt/kvt_init/rocks_db/rdb_put.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ proc rollback*(rdb: var RdbInst, session: SharedWriteBatchRef) =
4949
if not session.isClosed():
5050
session.close()
5151

52-
proc commit*(rdb: var RdbInst, session: SharedWriteBatchRef): Result[void,(KvtError,string)] =
52+
proc commit*(
53+
rdb: var RdbInst, session: SharedWriteBatchRef, cf: static[KvtCFs]
54+
): Result[void, (KvtError, string)] =
5355
if not session.isClosed():
5456
defer: session.close()
55-
rdb.baseDb.commit(session, rdb.store[KvtGeneric]).isOkOr:
57+
rdb.baseDb.commit(session, rdb.store[cf], false).isOkOr:
5658
const errSym = RdbBeDriverWriteError
5759
when extraTraceMessages:
5860
trace logTxt "commit", error=errSym, info=error

0 commit comments

Comments
 (0)