@@ -69,6 +69,8 @@ type FilterWriter = base.FilterWriter
69
69
// FilterPolicy exports the base.FilterPolicy type.
70
70
type FilterPolicy = base.FilterPolicy
71
71
72
+ var NoFilterPolicy = base .NoFilterPolicy
73
+
72
74
// KeySchema exports the colblk.KeySchema type.
73
75
type KeySchema = colblk.KeySchema
74
76
@@ -421,7 +423,7 @@ type LevelOptions struct {
421
423
// One such implementation is bloom.FilterPolicy(10) from the pebble/bloom
422
424
// package.
423
425
//
424
- // The default value means to use no filter .
426
+ // The default value is NoFilterPolicy .
425
427
FilterPolicy FilterPolicy
426
428
427
429
// FilterType defines whether an existing filter policy is applied at a
@@ -464,6 +466,9 @@ func (o *LevelOptions) EnsureDefaults() {
464
466
if o .Compression == nil {
465
467
o .Compression = func () Compression { return DefaultCompression }
466
468
}
469
+ if o .FilterPolicy == nil {
470
+ o .FilterPolicy = NoFilterPolicy
471
+ }
467
472
if o .IndexBlockSize <= 0 {
468
473
o .IndexBlockSize = o .BlockSize
469
474
}
@@ -1454,7 +1459,7 @@ func (o *Options) AddEventListener(l EventListener) {
1454
1459
func (o * Options ) initMaps () {
1455
1460
for i := range o .Levels {
1456
1461
l := & o .Levels [i ]
1457
- if l .FilterPolicy != nil {
1462
+ if l .FilterPolicy != NoFilterPolicy {
1458
1463
if o .Filters == nil {
1459
1464
o .Filters = make (map [string ]FilterPolicy )
1460
1465
}
@@ -1488,13 +1493,6 @@ func (o *Options) Clone() *Options {
1488
1493
return n
1489
1494
}
1490
1495
1491
- func filterPolicyName (p FilterPolicy ) string {
1492
- if p == nil {
1493
- return "none"
1494
- }
1495
- return p .Name ()
1496
- }
1497
-
1498
1496
func (o * Options ) String () string {
1499
1497
var buf bytes.Buffer
1500
1498
@@ -1612,7 +1610,7 @@ func (o *Options) String() string {
1612
1610
fmt .Fprintf (& buf , " block_size=%d\n " , l .BlockSize )
1613
1611
fmt .Fprintf (& buf , " block_size_threshold=%d\n " , l .BlockSizeThreshold )
1614
1612
fmt .Fprintf (& buf , " compression=%s\n " , resolveDefaultCompression (l .Compression ()))
1615
- fmt .Fprintf (& buf , " filter_policy=%s\n " , filterPolicyName ( l .FilterPolicy ))
1613
+ fmt .Fprintf (& buf , " filter_policy=%s\n " , l .FilterPolicy . Name ( ))
1616
1614
fmt .Fprintf (& buf , " filter_type=%s\n " , l .FilterType )
1617
1615
fmt .Fprintf (& buf , " index_block_size=%d\n " , l .IndexBlockSize )
1618
1616
fmt .Fprintf (& buf , " target_file_size=%d\n " , l .TargetFileSize )
@@ -2103,6 +2101,8 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
2103
2101
case "filter_policy" :
2104
2102
if hooks != nil && hooks .NewFilterPolicy != nil {
2105
2103
l .FilterPolicy , err = hooks .NewFilterPolicy (value )
2104
+ } else {
2105
+ l .FilterPolicy = NoFilterPolicy
2106
2106
}
2107
2107
case "filter_type" :
2108
2108
switch value {
0 commit comments