2022-07-29 15:17:28 +08:00
|
|
|
//go:build rocksdb
|
|
|
|
// +build rocksdb
|
2021-01-05 17:47:59 +08:00
|
|
|
|
|
|
|
package rocksdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2021-10-01 11:16:03 +08:00
|
|
|
gorocksdb "github.com/linxGnu/grocksdb"
|
2021-01-05 17:47:59 +08:00
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
2021-01-05 17:47:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2021-01-06 17:42:43 +08:00
|
|
|
if !t.skipLevel0 || level > 0 {
|
|
|
|
entry := filer.Entry{}
|
|
|
|
if err := entry.DecodeAttributesAndChunks(val); err == nil {
|
|
|
|
if entry.TtlSec > 0 &&
|
|
|
|
entry.Crtime.Add(time.Duration(entry.TtlSec)*time.Second).Before(time.Now()) {
|
|
|
|
return true, nil
|
|
|
|
}
|
2021-01-05 17:47:59 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-06 17:42:43 +08:00
|
|
|
return false, val
|
2021-01-05 17:47:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TTLFilter) Name() string {
|
|
|
|
return "TTLFilter"
|
|
|
|
}
|
2021-10-01 11:16:03 +08:00
|
|
|
func (t *TTLFilter) SetIgnoreSnapshots(value bool) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TTLFilter) Destroy() {
|
|
|
|
}
|