...

Source file src/github.com/syndtr/goleveldb/leveldb/opt/options.go

Documentation: github.com/syndtr/goleveldb/leveldb/opt

     1  // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
     2  // All rights reserved.
     3  //
     4  // Use of this source code is governed by a BSD-style license that can be
     5  // found in the LICENSE file.
     6  
     7  // Package opt provides sets of options used by LevelDB.
     8  package opt
     9  
    10  import (
    11  	"math"
    12  
    13  	"github.com/syndtr/goleveldb/leveldb/cache"
    14  	"github.com/syndtr/goleveldb/leveldb/comparer"
    15  	"github.com/syndtr/goleveldb/leveldb/filter"
    16  )
    17  
    18  const (
    19  	KiB = 1024
    20  	MiB = KiB * 1024
    21  	GiB = MiB * 1024
    22  )
    23  
    24  var (
    25  	DefaultBlockCacher                   = LRUCacher
    26  	DefaultBlockCacheCapacity            = 8 * MiB
    27  	DefaultBlockRestartInterval          = 16
    28  	DefaultBlockSize                     = 4 * KiB
    29  	DefaultCompactionExpandLimitFactor   = 25
    30  	DefaultCompactionGPOverlapsFactor    = 10
    31  	DefaultCompactionL0Trigger           = 4
    32  	DefaultCompactionSourceLimitFactor   = 1
    33  	DefaultCompactionTableSize           = 2 * MiB
    34  	DefaultCompactionTableSizeMultiplier = 1.0
    35  	DefaultCompactionTotalSize           = 10 * MiB
    36  	DefaultCompactionTotalSizeMultiplier = 10.0
    37  	DefaultCompressionType               = SnappyCompression
    38  	DefaultIteratorSamplingRate          = 1 * MiB
    39  	DefaultOpenFilesCacher               = LRUCacher
    40  	DefaultWriteBuffer                   = 4 * MiB
    41  	DefaultWriteL0PauseTrigger           = 12
    42  	DefaultWriteL0SlowdownTrigger        = 8
    43  	DefaultFilterBaseLg                  = 11
    44  	DefaultMaxManifestFileSize           = int64(64 * MiB)
    45  )
    46  
    47  // Cacher is a caching algorithm.
    48  type Cacher interface {
    49  	New(capacity int) cache.Cacher
    50  }
    51  
    52  type cacherFunc struct {
    53  	NewFunc func(capacity int) cache.Cacher
    54  }
    55  
    56  func (f *cacherFunc) New(capacity int) cache.Cacher {
    57  	if f != nil && f.NewFunc != nil {
    58  		return f.NewFunc(capacity)
    59  	}
    60  	return nil
    61  }
    62  
    63  func CacherFunc(f func(capacity int) cache.Cacher) Cacher {
    64  	return &cacherFunc{f}
    65  }
    66  
    67  type passthroughCacher struct {
    68  	Cacher cache.Cacher
    69  }
    70  
    71  func (p *passthroughCacher) New(capacity int) cache.Cacher {
    72  	return p.Cacher
    73  }
    74  
    75  // PassthroughCacher can be used to passthrough pre-initialized
    76  // 'cacher instance'. This is useful for sharing cache over multiple
    77  // DB instances.
    78  //
    79  // Shared cache example:
    80  //
    81  //     fileCache := opt.NewLRU(500)
    82  //     blockCache := opt.NewLRU(8 * opt.MiB)
    83  // 	   options := &opt.Options{
    84  //         OpenFilesCacher: fileCache,
    85  //         BlockCacher: blockCache,
    86  //     }
    87  //     db1, err1 := leveldb.OpenFile("path/to/db1", options)
    88  //     ...
    89  //     db2, err2 := leveldb.OpenFile("path/to/db2", options)
    90  //     ...
    91  func PassthroughCacher(x cache.Cacher) Cacher {
    92  	return &passthroughCacher{x}
    93  }
    94  
    95  // NewLRU creates LRU 'passthrough cacher'.
    96  func NewLRU(capacity int) Cacher {
    97  	return PassthroughCacher(cache.NewLRU(capacity))
    98  }
    99  
   100  var (
   101  	// LRUCacher is the LRU-cache algorithm.
   102  	LRUCacher = CacherFunc(cache.NewLRU)
   103  
   104  	// NoCacher is the value to disable caching algorithm.
   105  	NoCacher = CacherFunc(nil)
   106  )
   107  
   108  // Compression is the 'sorted table' block compression algorithm to use.
   109  type Compression uint
   110  
   111  func (c Compression) String() string {
   112  	switch c {
   113  	case DefaultCompression:
   114  		return "default"
   115  	case NoCompression:
   116  		return "none"
   117  	case SnappyCompression:
   118  		return "snappy"
   119  	}
   120  	return "invalid"
   121  }
   122  
   123  const (
   124  	DefaultCompression Compression = iota
   125  	NoCompression
   126  	SnappyCompression
   127  	nCompression
   128  )
   129  
   130  // Strict is the DB 'strict level'.
   131  type Strict uint
   132  
   133  const (
   134  	// If present then a corrupted or invalid chunk or block in manifest
   135  	// journal will cause an error instead of being dropped.
   136  	// This will prevent database with corrupted manifest to be opened.
   137  	StrictManifest Strict = 1 << iota
   138  
   139  	// If present then journal chunk checksum will be verified.
   140  	StrictJournalChecksum
   141  
   142  	// If present then a corrupted or invalid chunk or block in journal
   143  	// will cause an error instead of being dropped.
   144  	// This will prevent database with corrupted journal to be opened.
   145  	StrictJournal
   146  
   147  	// If present then 'sorted table' block checksum will be verified.
   148  	// This has effect on both 'read operation' and compaction.
   149  	StrictBlockChecksum
   150  
   151  	// If present then a corrupted 'sorted table' will fails compaction.
   152  	// The database will enter read-only mode.
   153  	StrictCompaction
   154  
   155  	// If present then a corrupted 'sorted table' will halts 'read operation'.
   156  	StrictReader
   157  
   158  	// If present then leveldb.Recover will drop corrupted 'sorted table'.
   159  	StrictRecovery
   160  
   161  	// This only applicable for ReadOptions, if present then this ReadOptions
   162  	// 'strict level' will override global ones.
   163  	StrictOverride
   164  
   165  	// StrictAll enables all strict flags.
   166  	StrictAll = StrictManifest | StrictJournalChecksum | StrictJournal | StrictBlockChecksum | StrictCompaction | StrictReader | StrictRecovery
   167  
   168  	// DefaultStrict is the default strict flags. Specify any strict flags
   169  	// will override default strict flags as whole (i.e. not OR'ed).
   170  	DefaultStrict = StrictJournalChecksum | StrictBlockChecksum | StrictCompaction | StrictReader
   171  
   172  	// NoStrict disables all strict flags. Override default strict flags.
   173  	NoStrict = ^StrictAll
   174  )
   175  
   176  // Options holds the optional parameters for the DB at large.
   177  type Options struct {
   178  	// AltFilters defines one or more 'alternative filters'.
   179  	// 'alternative filters' will be used during reads if a filter block
   180  	// does not match with the 'effective filter'.
   181  	//
   182  	// The default value is nil
   183  	AltFilters []filter.Filter
   184  
   185  	// BlockCacher provides cache algorithm for LevelDB 'sorted table' block caching.
   186  	// Specify NoCacher to disable caching algorithm.
   187  	//
   188  	// The default value is LRUCacher.
   189  	BlockCacher Cacher
   190  
   191  	// BlockCacheCapacity defines the capacity of the 'sorted table' block caching.
   192  	// Use -1 for zero, this has same effect as specifying NoCacher to BlockCacher.
   193  	//
   194  	// The default value is 8MiB.
   195  	BlockCacheCapacity int
   196  
   197  	// BlockCacheEvictRemoved allows enable forced-eviction on cached block belonging
   198  	// to removed 'sorted table'.
   199  	//
   200  	// The default if false.
   201  	BlockCacheEvictRemoved bool
   202  
   203  	// BlockRestartInterval is the number of keys between restart points for
   204  	// delta encoding of keys.
   205  	//
   206  	// The default value is 16.
   207  	BlockRestartInterval int
   208  
   209  	// BlockSize is the minimum uncompressed size in bytes of each 'sorted table'
   210  	// block.
   211  	//
   212  	// The default value is 4KiB.
   213  	BlockSize int
   214  
   215  	// CompactionExpandLimitFactor limits compaction size after expanded.
   216  	// This will be multiplied by table size limit at compaction target level.
   217  	//
   218  	// The default value is 25.
   219  	CompactionExpandLimitFactor int
   220  
   221  	// CompactionGPOverlapsFactor limits overlaps in grandparent (Level + 2) that a
   222  	// single 'sorted table' generates.
   223  	// This will be multiplied by table size limit at grandparent level.
   224  	//
   225  	// The default value is 10.
   226  	CompactionGPOverlapsFactor int
   227  
   228  	// CompactionL0Trigger defines number of 'sorted table' at level-0 that will
   229  	// trigger compaction.
   230  	//
   231  	// The default value is 4.
   232  	CompactionL0Trigger int
   233  
   234  	// CompactionSourceLimitFactor limits compaction source size. This doesn't apply to
   235  	// level-0.
   236  	// This will be multiplied by table size limit at compaction target level.
   237  	//
   238  	// The default value is 1.
   239  	CompactionSourceLimitFactor int
   240  
   241  	// CompactionTableSize limits size of 'sorted table' that compaction generates.
   242  	// The limits for each level will be calculated as:
   243  	//   CompactionTableSize * (CompactionTableSizeMultiplier ^ Level)
   244  	// The multiplier for each level can also fine-tuned using CompactionTableSizeMultiplierPerLevel.
   245  	//
   246  	// The default value is 2MiB.
   247  	CompactionTableSize int
   248  
   249  	// CompactionTableSizeMultiplier defines multiplier for CompactionTableSize.
   250  	//
   251  	// The default value is 1.
   252  	CompactionTableSizeMultiplier float64
   253  
   254  	// CompactionTableSizeMultiplierPerLevel defines per-level multiplier for
   255  	// CompactionTableSize.
   256  	// Use zero to skip a level.
   257  	//
   258  	// The default value is nil.
   259  	CompactionTableSizeMultiplierPerLevel []float64
   260  
   261  	// CompactionTotalSize limits total size of 'sorted table' for each level.
   262  	// The limits for each level will be calculated as:
   263  	//   CompactionTotalSize * (CompactionTotalSizeMultiplier ^ Level)
   264  	// The multiplier for each level can also fine-tuned using
   265  	// CompactionTotalSizeMultiplierPerLevel.
   266  	//
   267  	// The default value is 10MiB.
   268  	CompactionTotalSize int
   269  
   270  	// CompactionTotalSizeMultiplier defines multiplier for CompactionTotalSize.
   271  	//
   272  	// The default value is 10.
   273  	CompactionTotalSizeMultiplier float64
   274  
   275  	// CompactionTotalSizeMultiplierPerLevel defines per-level multiplier for
   276  	// CompactionTotalSize.
   277  	// Use zero to skip a level.
   278  	//
   279  	// The default value is nil.
   280  	CompactionTotalSizeMultiplierPerLevel []float64
   281  
   282  	// Comparer defines a total ordering over the space of []byte keys: a 'less
   283  	// than' relationship. The same comparison algorithm must be used for reads
   284  	// and writes over the lifetime of the DB.
   285  	//
   286  	// The default value uses the same ordering as bytes.Compare.
   287  	Comparer comparer.Comparer
   288  
   289  	// Compression defines the 'sorted table' block compression to use.
   290  	//
   291  	// The default value (DefaultCompression) uses snappy compression.
   292  	Compression Compression
   293  
   294  	// DisableBufferPool allows disable use of util.BufferPool functionality.
   295  	//
   296  	// The default value is false.
   297  	DisableBufferPool bool
   298  
   299  	// DisableBlockCache allows disable use of cache.Cache functionality on
   300  	// 'sorted table' block.
   301  	//
   302  	// The default value is false.
   303  	DisableBlockCache bool
   304  
   305  	// DisableCompactionBackoff allows disable compaction retry backoff.
   306  	//
   307  	// The default value is false.
   308  	DisableCompactionBackoff bool
   309  
   310  	// DisableLargeBatchTransaction allows disabling switch-to-transaction mode
   311  	// on large batch write. If enable batch writes large than WriteBuffer will
   312  	// use transaction.
   313  	//
   314  	// The default is false.
   315  	DisableLargeBatchTransaction bool
   316  
   317  	// DisableSeeksCompaction allows disabling 'seeks triggered compaction'.
   318  	// The purpose of 'seeks triggered compaction' is to optimize database so
   319  	// that 'level seeks' can be minimized, however this might generate many
   320  	// small compaction which may not preferable.
   321  	//
   322  	// The default is false.
   323  	DisableSeeksCompaction bool
   324  
   325  	// ErrorIfExist defines whether an error should returned if the DB already
   326  	// exist.
   327  	//
   328  	// The default value is false.
   329  	ErrorIfExist bool
   330  
   331  	// ErrorIfMissing defines whether an error should returned if the DB is
   332  	// missing. If false then the database will be created if missing, otherwise
   333  	// an error will be returned.
   334  	//
   335  	// The default value is false.
   336  	ErrorIfMissing bool
   337  
   338  	// Filter defines an 'effective filter' to use. An 'effective filter'
   339  	// if defined will be used to generate per-table filter block.
   340  	// The filter name will be stored on disk.
   341  	// During reads LevelDB will try to find matching filter from
   342  	// 'effective filter' and 'alternative filters'.
   343  	//
   344  	// Filter can be changed after a DB has been created. It is recommended
   345  	// to put old filter to the 'alternative filters' to mitigate lack of
   346  	// filter during transition period.
   347  	//
   348  	// A filter is used to reduce disk reads when looking for a specific key.
   349  	//
   350  	// The default value is nil.
   351  	Filter filter.Filter
   352  
   353  	// IteratorSamplingRate defines approximate gap (in bytes) between read
   354  	// sampling of an iterator. The samples will be used to determine when
   355  	// compaction should be triggered.
   356  	// Use negative value to disable iterator sampling.
   357  	// The iterator sampling is disabled if DisableSeeksCompaction is true.
   358  	//
   359  	// The default is 1MiB.
   360  	IteratorSamplingRate int
   361  
   362  	// NoSync allows completely disable fsync.
   363  	//
   364  	// The default is false.
   365  	NoSync bool
   366  
   367  	// NoWriteMerge allows disabling write merge.
   368  	//
   369  	// The default is false.
   370  	NoWriteMerge bool
   371  
   372  	// OpenFilesCacher provides cache algorithm for open files caching.
   373  	// Specify NoCacher to disable caching algorithm.
   374  	//
   375  	// The default value is LRUCacher.
   376  	OpenFilesCacher Cacher
   377  
   378  	// OpenFilesCacheCapacity defines the capacity of the open files caching.
   379  	// Use -1 for zero, this has same effect as specifying NoCacher to OpenFilesCacher.
   380  	//
   381  	// The default value is 200 on MacOS and 500 on other.
   382  	OpenFilesCacheCapacity int
   383  
   384  	// If true then opens DB in read-only mode.
   385  	//
   386  	// The default value is false.
   387  	ReadOnly bool
   388  
   389  	// Strict defines the DB strict level.
   390  	Strict Strict
   391  
   392  	// WriteBuffer defines maximum size of a 'memdb' before flushed to
   393  	// 'sorted table'. 'memdb' is an in-memory DB backed by an on-disk
   394  	// unsorted journal.
   395  	//
   396  	// LevelDB may held up to two 'memdb' at the same time.
   397  	//
   398  	// The default value is 4MiB.
   399  	WriteBuffer int
   400  
   401  	// WriteL0StopTrigger defines number of 'sorted table' at level-0 that will
   402  	// pause write.
   403  	//
   404  	// The default value is 12.
   405  	WriteL0PauseTrigger int
   406  
   407  	// WriteL0SlowdownTrigger defines number of 'sorted table' at level-0 that
   408  	// will trigger write slowdown.
   409  	//
   410  	// The default value is 8.
   411  	WriteL0SlowdownTrigger int
   412  
   413  	// FilterBaseLg is the log size for filter block to create a bloom filter.
   414  	//
   415  	// The default value is 11(as well as 2KB)
   416  	FilterBaseLg int
   417  
   418  	// MaxManifestFileSize is the maximum size limit of the MANIFEST-****** file.
   419  	// When the MANIFEST-****** file grows beyond this size, LevelDB will create
   420  	// a new MANIFEST file.
   421  	//
   422  	// The default value is 64 MiB.
   423  	MaxManifestFileSize int64
   424  }
   425  
   426  func (o *Options) GetAltFilters() []filter.Filter {
   427  	if o == nil {
   428  		return nil
   429  	}
   430  	return o.AltFilters
   431  }
   432  
   433  func (o *Options) GetBlockCacher() Cacher {
   434  	if o == nil || o.BlockCacher == nil {
   435  		return DefaultBlockCacher
   436  	}
   437  	return o.BlockCacher
   438  }
   439  
   440  func (o *Options) GetBlockCacheCapacity() int {
   441  	if o == nil || o.BlockCacheCapacity == 0 {
   442  		return DefaultBlockCacheCapacity
   443  	} else if o.BlockCacheCapacity < 0 {
   444  		return 0
   445  	}
   446  	return o.BlockCacheCapacity
   447  }
   448  
   449  func (o *Options) GetBlockCacheEvictRemoved() bool {
   450  	if o == nil {
   451  		return false
   452  	}
   453  	return o.BlockCacheEvictRemoved
   454  }
   455  
   456  func (o *Options) GetBlockRestartInterval() int {
   457  	if o == nil || o.BlockRestartInterval <= 0 {
   458  		return DefaultBlockRestartInterval
   459  	}
   460  	return o.BlockRestartInterval
   461  }
   462  
   463  func (o *Options) GetBlockSize() int {
   464  	if o == nil || o.BlockSize <= 0 {
   465  		return DefaultBlockSize
   466  	}
   467  	return o.BlockSize
   468  }
   469  
   470  func (o *Options) GetCompactionExpandLimit(level int) int {
   471  	factor := DefaultCompactionExpandLimitFactor
   472  	if o != nil && o.CompactionExpandLimitFactor > 0 {
   473  		factor = o.CompactionExpandLimitFactor
   474  	}
   475  	return o.GetCompactionTableSize(level+1) * factor
   476  }
   477  
   478  func (o *Options) GetCompactionGPOverlaps(level int) int {
   479  	factor := DefaultCompactionGPOverlapsFactor
   480  	if o != nil && o.CompactionGPOverlapsFactor > 0 {
   481  		factor = o.CompactionGPOverlapsFactor
   482  	}
   483  	return o.GetCompactionTableSize(level+2) * factor
   484  }
   485  
   486  func (o *Options) GetCompactionL0Trigger() int {
   487  	if o == nil || o.CompactionL0Trigger == 0 {
   488  		return DefaultCompactionL0Trigger
   489  	}
   490  	return o.CompactionL0Trigger
   491  }
   492  
   493  func (o *Options) GetCompactionSourceLimit(level int) int {
   494  	factor := DefaultCompactionSourceLimitFactor
   495  	if o != nil && o.CompactionSourceLimitFactor > 0 {
   496  		factor = o.CompactionSourceLimitFactor
   497  	}
   498  	return o.GetCompactionTableSize(level+1) * factor
   499  }
   500  
   501  func (o *Options) GetCompactionTableSize(level int) int {
   502  	var (
   503  		base = DefaultCompactionTableSize
   504  		mult float64
   505  	)
   506  	if o != nil {
   507  		if o.CompactionTableSize > 0 {
   508  			base = o.CompactionTableSize
   509  		}
   510  		if level < len(o.CompactionTableSizeMultiplierPerLevel) && o.CompactionTableSizeMultiplierPerLevel[level] > 0 {
   511  			mult = o.CompactionTableSizeMultiplierPerLevel[level]
   512  		} else if o.CompactionTableSizeMultiplier > 0 {
   513  			mult = math.Pow(o.CompactionTableSizeMultiplier, float64(level))
   514  		}
   515  	}
   516  	if mult == 0 {
   517  		mult = math.Pow(DefaultCompactionTableSizeMultiplier, float64(level))
   518  	}
   519  	return int(float64(base) * mult)
   520  }
   521  
   522  func (o *Options) GetCompactionTotalSize(level int) int64 {
   523  	var (
   524  		base = DefaultCompactionTotalSize
   525  		mult float64
   526  	)
   527  	if o != nil {
   528  		if o.CompactionTotalSize > 0 {
   529  			base = o.CompactionTotalSize
   530  		}
   531  		if level < len(o.CompactionTotalSizeMultiplierPerLevel) && o.CompactionTotalSizeMultiplierPerLevel[level] > 0 {
   532  			mult = o.CompactionTotalSizeMultiplierPerLevel[level]
   533  		} else if o.CompactionTotalSizeMultiplier > 0 {
   534  			mult = math.Pow(o.CompactionTotalSizeMultiplier, float64(level))
   535  		}
   536  	}
   537  	if mult == 0 {
   538  		mult = math.Pow(DefaultCompactionTotalSizeMultiplier, float64(level))
   539  	}
   540  	return int64(float64(base) * mult)
   541  }
   542  
   543  func (o *Options) GetComparer() comparer.Comparer {
   544  	if o == nil || o.Comparer == nil {
   545  		return comparer.DefaultComparer
   546  	}
   547  	return o.Comparer
   548  }
   549  
   550  func (o *Options) GetCompression() Compression {
   551  	if o == nil || o.Compression <= DefaultCompression || o.Compression >= nCompression {
   552  		return DefaultCompressionType
   553  	}
   554  	return o.Compression
   555  }
   556  
   557  func (o *Options) GetDisableBufferPool() bool {
   558  	if o == nil {
   559  		return false
   560  	}
   561  	return o.DisableBufferPool
   562  }
   563  
   564  func (o *Options) GetDisableBlockCache() bool {
   565  	if o == nil {
   566  		return false
   567  	}
   568  	return o.DisableBlockCache
   569  }
   570  
   571  func (o *Options) GetDisableCompactionBackoff() bool {
   572  	if o == nil {
   573  		return false
   574  	}
   575  	return o.DisableCompactionBackoff
   576  }
   577  
   578  func (o *Options) GetDisableLargeBatchTransaction() bool {
   579  	if o == nil {
   580  		return false
   581  	}
   582  	return o.DisableLargeBatchTransaction
   583  }
   584  
   585  func (o *Options) GetDisableSeeksCompaction() bool {
   586  	if o == nil {
   587  		return false
   588  	}
   589  	return o.DisableSeeksCompaction
   590  }
   591  
   592  func (o *Options) GetErrorIfExist() bool {
   593  	if o == nil {
   594  		return false
   595  	}
   596  	return o.ErrorIfExist
   597  }
   598  
   599  func (o *Options) GetErrorIfMissing() bool {
   600  	if o == nil {
   601  		return false
   602  	}
   603  	return o.ErrorIfMissing
   604  }
   605  
   606  func (o *Options) GetFilter() filter.Filter {
   607  	if o == nil {
   608  		return nil
   609  	}
   610  	return o.Filter
   611  }
   612  
   613  func (o *Options) GetIteratorSamplingRate() int {
   614  	if o == nil || o.IteratorSamplingRate == 0 {
   615  		return DefaultIteratorSamplingRate
   616  	} else if o.IteratorSamplingRate < 0 {
   617  		return 0
   618  	}
   619  	return o.IteratorSamplingRate
   620  }
   621  
   622  func (o *Options) GetNoSync() bool {
   623  	if o == nil {
   624  		return false
   625  	}
   626  	return o.NoSync
   627  }
   628  
   629  func (o *Options) GetNoWriteMerge() bool {
   630  	if o == nil {
   631  		return false
   632  	}
   633  	return o.NoWriteMerge
   634  }
   635  
   636  func (o *Options) GetOpenFilesCacher() Cacher {
   637  	if o == nil || o.OpenFilesCacher == nil {
   638  		return DefaultOpenFilesCacher
   639  	}
   640  	return o.OpenFilesCacher
   641  }
   642  
   643  func (o *Options) GetOpenFilesCacheCapacity() int {
   644  	if o == nil || o.OpenFilesCacheCapacity == 0 {
   645  		return DefaultOpenFilesCacheCapacity
   646  	} else if o.OpenFilesCacheCapacity < 0 {
   647  		return 0
   648  	}
   649  	return o.OpenFilesCacheCapacity
   650  }
   651  
   652  func (o *Options) GetReadOnly() bool {
   653  	if o == nil {
   654  		return false
   655  	}
   656  	return o.ReadOnly
   657  }
   658  
   659  func (o *Options) GetStrict(strict Strict) bool {
   660  	if o == nil || o.Strict == 0 {
   661  		return DefaultStrict&strict != 0
   662  	}
   663  	return o.Strict&strict != 0
   664  }
   665  
   666  func (o *Options) GetWriteBuffer() int {
   667  	if o == nil || o.WriteBuffer <= 0 {
   668  		return DefaultWriteBuffer
   669  	}
   670  	return o.WriteBuffer
   671  }
   672  
   673  func (o *Options) GetWriteL0PauseTrigger() int {
   674  	if o == nil || o.WriteL0PauseTrigger == 0 {
   675  		return DefaultWriteL0PauseTrigger
   676  	}
   677  	return o.WriteL0PauseTrigger
   678  }
   679  
   680  func (o *Options) GetWriteL0SlowdownTrigger() int {
   681  	if o == nil || o.WriteL0SlowdownTrigger == 0 {
   682  		return DefaultWriteL0SlowdownTrigger
   683  	}
   684  	return o.WriteL0SlowdownTrigger
   685  }
   686  
   687  func (o *Options) GetFilterBaseLg() int {
   688  	if o == nil || o.FilterBaseLg <= 0 {
   689  		return DefaultFilterBaseLg
   690  	}
   691  	return o.FilterBaseLg
   692  }
   693  
   694  // ReadOptions holds the optional parameters for 'read operation'. The
   695  // 'read operation' includes Get, Find and NewIterator.
   696  type ReadOptions struct {
   697  	// DontFillCache defines whether block reads for this 'read operation'
   698  	// should be cached. If false then the block will be cached. This does
   699  	// not affects already cached block.
   700  	//
   701  	// The default value is false.
   702  	DontFillCache bool
   703  
   704  	// Strict will be OR'ed with global DB 'strict level' unless StrictOverride
   705  	// is present. Currently only StrictReader that has effect here.
   706  	Strict Strict
   707  }
   708  
   709  func (ro *ReadOptions) GetDontFillCache() bool {
   710  	if ro == nil {
   711  		return false
   712  	}
   713  	return ro.DontFillCache
   714  }
   715  
   716  func (ro *ReadOptions) GetStrict(strict Strict) bool {
   717  	if ro == nil {
   718  		return false
   719  	}
   720  	return ro.Strict&strict != 0
   721  }
   722  
   723  // WriteOptions holds the optional parameters for 'write operation'. The
   724  // 'write operation' includes Write, Put and Delete.
   725  type WriteOptions struct {
   726  	// NoWriteMerge allows disabling write merge.
   727  	//
   728  	// The default is false.
   729  	NoWriteMerge bool
   730  
   731  	// Sync is whether to sync underlying writes from the OS buffer cache
   732  	// through to actual disk, if applicable. Setting Sync can result in
   733  	// slower writes.
   734  	//
   735  	// If false, and the machine crashes, then some recent writes may be lost.
   736  	// Note that if it is just the process that crashes (and the machine does
   737  	// not) then no writes will be lost.
   738  	//
   739  	// In other words, Sync being false has the same semantics as a write
   740  	// system call. Sync being true means write followed by fsync.
   741  	//
   742  	// The default value is false.
   743  	Sync bool
   744  }
   745  
   746  func (wo *WriteOptions) GetNoWriteMerge() bool {
   747  	if wo == nil {
   748  		return false
   749  	}
   750  	return wo.NoWriteMerge
   751  }
   752  
   753  func (wo *WriteOptions) GetSync() bool {
   754  	if wo == nil {
   755  		return false
   756  	}
   757  	return wo.Sync
   758  }
   759  
   760  func GetStrict(o *Options, ro *ReadOptions, strict Strict) bool {
   761  	if ro.GetStrict(StrictOverride) {
   762  		return ro.GetStrict(strict)
   763  	}
   764  	return o.GetStrict(strict) || ro.GetStrict(strict)
   765  }
   766  
   767  func (o *Options) GetMaxManifestFileSize() int64 {
   768  	if o == nil || o.MaxManifestFileSize <= 0 {
   769  		return DefaultMaxManifestFileSize
   770  	}
   771  	return o.MaxManifestFileSize
   772  }
   773  

View as plain text