Skip to content

Commit 86f3d68

Browse files
committed
Badger for caching in s3 connector
1 parent 884a3aa commit 86f3d68

File tree

4 files changed

+659
-4
lines changed

4 files changed

+659
-4
lines changed

internal/storage/block_buffer.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,22 @@ type BlockBuffer struct {
1818
maxBlocks int
1919
}
2020

21-
// NewBlockBuffer creates a new block buffer
21+
// IBlockBuffer defines the interface for block buffer implementations
22+
type IBlockBuffer interface {
23+
Add(blocks []common.BlockData, actualSizeBytes int64) bool
24+
Flush() []common.BlockData
25+
ShouldFlush() bool
26+
Size() (int64, int)
27+
IsEmpty() bool
28+
GetData() []common.BlockData
29+
GetBlocksInRange(chainId *big.Int, startBlock, endBlock *big.Int) []common.BlockData
30+
GetBlockByNumber(chainId *big.Int, blockNumber *big.Int) *common.BlockData
31+
GetMaxBlockNumber(chainId *big.Int) *big.Int
32+
Clear()
33+
Stats() BufferStats
34+
}
35+
36+
// NewBlockBuffer creates a new in-memory block buffer
2237
func NewBlockBuffer(maxSizeMB int64, maxBlocks int) *BlockBuffer {
2338
return &BlockBuffer{
2439
data: make([]common.BlockData, 0),
@@ -27,6 +42,12 @@ func NewBlockBuffer(maxSizeMB int64, maxBlocks int) *BlockBuffer {
2742
}
2843
}
2944

45+
// NewBlockBufferWithBadger creates a new Badger-backed block buffer for better memory management
46+
// This uses ephemeral storage with optimized settings for caching
47+
func NewBlockBufferWithBadger(maxSizeMB int64, maxBlocks int) (IBlockBuffer, error) {
48+
return NewBadgerBlockBuffer(maxSizeMB, maxBlocks)
49+
}
50+
3051
// Add adds blocks to the buffer and returns true if flush is needed
3152
func (b *BlockBuffer) Add(blocks []common.BlockData, actualSizeBytes int64) bool {
3253
if len(blocks) == 0 {

0 commit comments

Comments
 (0)