You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
895 B

  1. //+build rocksdb
  2. package rocksdb
  3. import (
  4. "time"
  5. gorocksdb "github.com/linxGnu/grocksdb"
  6. "github.com/chrislusf/seaweedfs/weed/filer"
  7. )
  8. type TTLFilter struct {
  9. skipLevel0 bool
  10. }
  11. func NewTTLFilter() gorocksdb.CompactionFilter {
  12. return &TTLFilter{
  13. skipLevel0: true,
  14. }
  15. }
  16. func (t *TTLFilter) Filter(level int, key, val []byte) (remove bool, newVal []byte) {
  17. // decode could be slow, causing write stall
  18. // level >0 sst can run compaction in parallel
  19. if !t.skipLevel0 || level > 0 {
  20. entry := filer.Entry{}
  21. if err := entry.DecodeAttributesAndChunks(val); err == nil {
  22. if entry.TtlSec > 0 &&
  23. entry.Crtime.Add(time.Duration(entry.TtlSec)*time.Second).Before(time.Now()) {
  24. return true, nil
  25. }
  26. }
  27. }
  28. return false, val
  29. }
  30. func (t *TTLFilter) Name() string {
  31. return "TTLFilter"
  32. }
  33. func (t *TTLFilter) SetIgnoreSnapshots(value bool) {
  34. }
  35. func (t *TTLFilter) Destroy() {
  36. }