@@ -17,11 +17,26 @@ var ErrInvalidTombstoneEntry = errors.New("invalid tombstone entry")
17
17
var tombstoneBucketName = []byte ("tombstones" )
18
18
19
19
type TombstoneEntry struct {
20
+ // Key the entry was stored under. This is needed for backward
21
+ // compatibility: if the logic for generating keys changes, we
22
+ // will still be able to delete old entries.
23
+ key []byte
20
24
Index uint64
21
25
AppendedAt int64
22
26
* metastorev1.Tombstones
23
27
}
24
28
29
+ func (e TombstoneEntry ) Name () string {
30
+ switch {
31
+ case e .Tombstones .Blocks != nil :
32
+ return e .Tombstones .Blocks .Name
33
+ case e .Tombstones .Shard != nil :
34
+ return e .Tombstones .Shard .Name
35
+ default :
36
+ return ""
37
+ }
38
+ }
39
+
25
40
type TombstoneStore struct { bucketName []byte }
26
41
27
42
func NewTombstoneStore () * TombstoneStore {
@@ -83,20 +98,29 @@ func marshalTombstoneEntry(e TombstoneEntry) store.KV {
83
98
}
84
99
85
100
func marshalTombstoneEntryKey (e TombstoneEntry ) []byte {
86
- b := make ([]byte , 16 )
101
+ if e .key != nil {
102
+ b := make ([]byte , len (e .key ))
103
+ copy (b , e .key )
104
+ return b
105
+ }
106
+ name := e .Name ()
107
+ b := make ([]byte , 16 + len (name ))
87
108
binary .BigEndian .PutUint64 (b [0 :8 ], e .Index )
88
109
binary .BigEndian .PutUint64 (b [8 :16 ], uint64 (e .AppendedAt ))
110
+ copy (b [16 :], name )
89
111
return b
90
112
}
91
113
92
- func unmarshalTombstoneEntry (dst * TombstoneEntry , e store.KV ) error {
93
- if len (e .Key ) < 16 {
114
+ func unmarshalTombstoneEntry (e * TombstoneEntry , kv store.KV ) error {
115
+ if len (kv .Key ) < 16 {
94
116
return ErrInvalidTombstoneEntry
95
117
}
96
- dst .Index = binary .BigEndian .Uint64 (e .Key [0 :8 ])
97
- dst .AppendedAt = int64 (binary .BigEndian .Uint64 (e .Key [8 :16 ]))
98
- dst .Tombstones = new (metastorev1.Tombstones )
99
- if err := dst .Tombstones .UnmarshalVT (e .Value ); err != nil {
118
+ e .key = make ([]byte , len (kv .Key ))
119
+ copy (e .key , kv .Key )
120
+ e .Index = binary .BigEndian .Uint64 (kv .Key [0 :8 ])
121
+ e .AppendedAt = int64 (binary .BigEndian .Uint64 (kv .Key [8 :16 ]))
122
+ e .Tombstones = new (metastorev1.Tombstones )
123
+ if err := e .Tombstones .UnmarshalVT (kv .Value ); err != nil {
100
124
return fmt .Errorf ("%w: %w" , ErrInvalidTombstoneEntry , err )
101
125
}
102
126
return nil
0 commit comments