@@ -25,6 +25,8 @@ const MemStoreMaxSizeBytes uint64 = 1024 * 1024 * 1024 // 1gb
2525const NumSSTablesToTriggerCompaction int = 10
2626const DefaultCompactionMaxSizeBytes uint64 = 5 * 1024 * 1024 * 1024 // 5gb
2727const DefaultCompactionInterval = 5 * time .Second
28+ const DefaultWriteBufferSizeBytes uint64 = 4 * 1024 * 1024 // 4Mb
29+ const DefaultReadBufferSizeBytes uint64 = 4 * 1024 * 1024 // 4Mb
2830
2931var ErrNotFound = errors .New ("ErrNotFound" )
3032var ErrNotOpenedYet = errors .New ("database has not been opened yet, please call Open() first" )
@@ -90,6 +92,9 @@ type DB struct {
9092 compactionTicker * time.Ticker
9193 compactionTickerStopChannel chan interface {}
9294 doneCompactionChannel chan bool
95+
96+ writeBufferSizeBytes uint64
97+ readBufferSizeBytes uint64
9398}
9499
95100func (db * DB ) Open () error {
@@ -327,6 +332,8 @@ func NewSimpleDB(basePath string, extraOptions ...ExtraOption) (*DB, error) {
327332 NumSSTablesToTriggerCompaction ,
328333 DefaultCompactionMaxSizeBytes ,
329334 DefaultCompactionInterval ,
335+ DefaultWriteBufferSizeBytes ,
336+ DefaultReadBufferSizeBytes ,
330337 }
331338
332339 for _ , extraOption := range extraOptions {
@@ -364,6 +371,8 @@ func NewSimpleDB(basePath string, extraOptions ...ExtraOption) (*DB, error) {
364371 doneFlushChannel : doneFlushChan ,
365372 compactionTickerStopChannel : compactionTimerStopChannel ,
366373 doneCompactionChannel : doneCompactionChan ,
374+ readBufferSizeBytes : extraOpts .readBufferSizeBytes ,
375+ writeBufferSizeBytes : extraOpts .writeBufferSizeBytes ,
367376 }, nil
368377}
369378
@@ -377,6 +386,8 @@ type ExtraOptions struct {
377386 compactionFileThreshold int
378387 compactionMaxSizeBytes uint64
379388 compactionRunInterval time.Duration
389+ writeBufferSizeBytes uint64
390+ readBufferSizeBytes uint64
380391}
381392
382393type ExtraOption func (options * ExtraOptions )
@@ -433,3 +444,17 @@ func CompactionMaxSizeBytes(n uint64) ExtraOption {
433444 args .compactionMaxSizeBytes = n
434445 }
435446}
447+
448+ // WriteBufferSizeBytes is the write buffer size for all buffer used by simple db.
449+ func WriteBufferSizeBytes (n uint64 ) ExtraOption {
450+ return func (args * ExtraOptions ) {
451+ args .writeBufferSizeBytes = n
452+ }
453+ }
454+
455+ // ReadBufferSizeBytes is the read buffer size for all buffer used by simple db.
456+ func ReadBufferSizeBytes (n uint64 ) ExtraOption {
457+ return func (args * ExtraOptions ) {
458+ args .readBufferSizeBytes = n
459+ }
460+ }
0 commit comments