@@ -29,6 +29,7 @@ import (
2929 "github.com/spf13/cobra"
3030
3131 "github.com/dgraph-io/badger/v2"
32+ "github.com/dgraph-io/badger/v2/options"
3233 "github.com/dgraph-io/badger/v2/pb"
3334 "github.com/dgraph-io/badger/v2/y"
3435)
5354
5455 sizeWritten uint64
5556 entriesWritten uint64
57+
58+ valueThreshold int
59+ numVersions int
60+ maxCacheSize int64
61+ keepBlockIdxInCache bool
62+ keepBlocksInCache bool
63+ maxBfCacheSize int64
64+ vlogMaxEntries uint32
65+ loadBloomsOnOpen bool
66+ detectConflicts bool
67+ compression bool
5668)
5769
5870const (
@@ -69,6 +81,26 @@ func init() {
6981 "Force compact level 0 on close." )
7082 writeBenchCmd .Flags ().BoolVarP (& sorted , "sorted" , "s" , false , "Write keys in sorted order." )
7183 writeBenchCmd .Flags ().BoolVarP (& showLogs , "logs" , "l" , false , "Show Badger logs." )
84+ writeBenchCmd .Flags ().IntVarP (& valueThreshold , "value-th" , "t" , 1 << 10 , "Value threshold" )
85+ writeBenchCmd .Flags ().IntVarP (& numVersions , "num-version" , "n" , 1 , "Number of versions to keep" )
86+ writeBenchCmd .Flags ().Int64VarP (& maxCacheSize , "max-cache" , "C" , 1 << 30 , "Max size of cache" )
87+ writeBenchCmd .Flags ().BoolVarP (& keepBlockIdxInCache , "keep-bidx" , "b" , true ,
88+ "Keep block indices in cache" )
89+ writeBenchCmd .Flags ().BoolVarP (& keepBlocksInCache , "keep-blocks" , "B" , true ,
90+ "Keep blocks in cache" )
91+ writeBenchCmd .Flags ().Int64VarP (& maxBfCacheSize , "max-bf-cache" , "c" , 500 << 20 ,
92+ "Maximum Bloom Filter Cache Size" )
93+ writeBenchCmd .Flags ().Uint32Var (& vlogMaxEntries , "vlog-maxe" , 10000 , "Value log Max Entries" )
94+ writeBenchCmd .Flags ().StringVarP (& encryptionKey , "encryption-key" , "e" , "" ,
95+ "If it is true, badger will encrypt all the data stored on the disk." )
96+ writeBenchCmd .Flags ().StringVar (& loadingMode , "loading-mode" , "mmap" ,
97+ "Mode for accessing SSTables" )
98+ writeBenchCmd .Flags ().BoolVar (& loadBloomsOnOpen , "load-blooms" , false ,
99+ "Load Bloom filter on DB open." )
100+ writeBenchCmd .Flags ().BoolVar (& detectConflicts , "conficts" , false ,
101+ "If true, it badger will detect the conflicts" )
102+ writeBenchCmd .Flags ().BoolVar (& compression , "compression" , false ,
103+ "If true, badger will use ZSTD mode" )
72104}
73105
74106func writeRandom (db * badger.DB , num uint64 ) error {
@@ -157,11 +189,30 @@ func writeSorted(db *badger.DB, num uint64) error {
157189}
158190
159191func writeBench (cmd * cobra.Command , args []string ) error {
192+ var cmode options.CompressionType
193+ if compression {
194+ cmode = options .ZSTD
195+ } else {
196+ cmode = options .None
197+ }
198+ mode := getLoadingMode (loadingMode )
160199 opt := badger .DefaultOptions (sstDir ).
161200 WithValueDir (vlogDir ).
162201 WithTruncate (truncate ).
163202 WithSyncWrites (false ).
164- WithCompactL0OnClose (force )
203+ WithCompactL0OnClose (force ).
204+ WithValueThreshold (valueThreshold ).
205+ WithNumVersionsToKeep (numVersions ).
206+ WithMaxCacheSize (maxCacheSize ).
207+ WithKeepBlockIndicesInCache (keepBlockIdxInCache ).
208+ WithKeepBlocksInCache (keepBlocksInCache ).
209+ WithMaxBfCacheSize (maxBfCacheSize ).
210+ WithValueLogMaxEntries (vlogMaxEntries ).
211+ WithTableLoadingMode (mode ).
212+ WithEncryptionKey ([]byte (encryptionKey )).
213+ WithLoadBloomsOnOpen (loadBloomsOnOpen ).
214+ WithDetectConflicts (detectConflicts ).
215+ WithCompression (cmode )
165216
166217 if ! showLogs {
167218 opt = opt .WithLogger (nil )
0 commit comments