Skip to content

Commit 9373b1d

Browse files
authored
Merge pull request #2427 from CortexFoundation/dev
change the mechanism to schedule freezer sync
2 parents f327602 + 795e864 commit 9373b1d

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

core/rawdb/freezer_batch.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ import (
2626
"github.com/CortexFoundation/CortexTheseus/rlp"
2727
)
2828

29-
// This is the maximum amount of data that will be buffered in memory
30-
// for a single freezer table batch.
31-
const freezerBatchBufferLimit = 2 * 1024 * 1024
29+
const (
30+
// This is the maximum amount of data that will be buffered in memory
31+
// for a single freezer table batch.
32+
freezerBatchBufferLimit = 2 * 1024 * 1024
33+
34+
// freezerTableFlushThreshold defines the threshold for triggering a freezer
35+
// table sync operation. If the number of accumulated uncommitted items exceeds
36+
// this value, a sync will be scheduled.
37+
freezerTableFlushThreshold = 512
38+
)
3239

3340
// freezerBatch is a write operation of multiple items on a freezer.
3441
type freezerBatch struct {
@@ -202,14 +209,17 @@ func (batch *freezerTableBatch) commit() error {
202209

203210
// Update headBytes of table.
204211
batch.t.headBytes += dataSize
212+
items := batch.curItem - batch.t.items.Load()
205213
batch.t.items.Store(batch.curItem)
206214

207215
// Update metrics.
208216
batch.t.sizeGauge.Inc(dataSize + indexSize)
209217
batch.t.writeMeter.Mark(dataSize + indexSize)
210218

211219
// Periodically sync the table, todo (rjl493456442) make it configurable?
212-
if time.Since(batch.t.lastSync) > 30*time.Second {
220+
batch.t.uncommitted += items
221+
if batch.t.uncommitted > freezerTableFlushThreshold && time.Since(batch.t.lastSync) > 30*time.Second {
222+
batch.t.uncommitted = 0
213223
batch.t.lastSync = time.Now()
214224
return batch.t.Sync()
215225
}

core/rawdb/freezer_table.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ type freezerTable struct {
113113
headId uint32 // number of the currently active head file
114114
tailId uint32 // number of the earliest file
115115

116-
metadata *freezerTableMeta // metadata of the table
117-
lastSync time.Time // Timestamp when the last sync was performed
116+
metadata *freezerTableMeta // metadata of the table
117+
uncommitted uint64 // Count of items written without flushing to file
118+
lastSync time.Time // Timestamp when the last sync was performed
118119

119120
headBytes int64 // Number of bytes written to the head file
120121
readMeter metrics.Meter // Meter for measuring the effective amount of data read

0 commit comments

Comments
 (0)