Browse Source
Merge pull request #1730 from qieqieplus/rocksdb
Merge pull request #1730 from qieqieplus/rocksdb
impl: TTL per entry for rocksdb; fix package namepull/1734/head
Chris Lu
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 16 deletions
@ -0,0 +1,41 @@ |
|||
//+build rocksdb
|
|||
|
|||
package rocksdb |
|||
|
|||
import ( |
|||
"time" |
|||
|
|||
"github.com/tecbot/gorocksdb" |
|||
|
|||
"github.com/chrislusf/seaweedfs/weed/filer" |
|||
) |
|||
|
|||
type TTLFilter struct { |
|||
skipLevel0 bool |
|||
} |
|||
|
|||
func NewTTLFilter() gorocksdb.CompactionFilter { |
|||
return &TTLFilter{ |
|||
skipLevel0: true, |
|||
} |
|||
} |
|||
|
|||
func (t *TTLFilter) Filter(level int, key, val []byte) (remove bool, newVal []byte) { |
|||
// decode could be slow, causing write stall
|
|||
// level >0 sst can run compaction in parallel
|
|||
if t.skipLevel0 && level == 0 { |
|||
return false, val |
|||
} |
|||
entry := filer.Entry{} |
|||
if err := entry.DecodeAttributesAndChunks(val); err == nil { |
|||
if entry.TtlSec == 0 || |
|||
entry.Crtime.Add(time.Duration(entry.TtlSec)*time.Second).After(time.Now()) { |
|||
return false, val |
|||
} |
|||
} |
|||
return true, nil |
|||
} |
|||
|
|||
func (t *TTLFilter) Name() string { |
|||
return "TTLFilter" |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue