storage: add predicate tracking to the WAL
parent
4fb7bf1730
commit
e10939b8af
|
@ -520,7 +520,7 @@ func (e *Engine) DeleteBucketRange(orgID, bucketID platform.ID, min, max int64)
|
|||
}
|
||||
|
||||
// Add the delete to the WAL to be replayed if there is a crash or shutdown.
|
||||
if _, err := e.wal.DeleteBucketRange(orgID, bucketID, min, max); err != nil {
|
||||
if _, err := e.wal.DeleteBucketRange(orgID, bucketID, min, max, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -519,7 +519,7 @@ func (l *WAL) CloseSegment() error {
|
|||
|
||||
// DeleteBucketRange deletes the data inside of the bucket between the two times, returning
|
||||
// the segment ID for the operation.
|
||||
func (l *WAL) DeleteBucketRange(orgID, bucketID influxdb.ID, min, max int64) (int, error) {
|
||||
func (l *WAL) DeleteBucketRange(orgID, bucketID influxdb.ID, min, max int64, pred []byte) (int, error) {
|
||||
if !l.enabled {
|
||||
return -1, nil
|
||||
}
|
||||
|
@ -529,6 +529,7 @@ func (l *WAL) DeleteBucketRange(orgID, bucketID influxdb.ID, min, max int64) (in
|
|||
BucketID: bucketID,
|
||||
Min: min,
|
||||
Max: max,
|
||||
Predicate: pred,
|
||||
}
|
||||
|
||||
id, err := l.writeToLog(entry)
|
||||
|
@ -995,6 +996,7 @@ type DeleteBucketRangeWALEntry struct {
|
|||
OrgID influxdb.ID
|
||||
BucketID influxdb.ID
|
||||
Min, Max int64
|
||||
Predicate []byte
|
||||
}
|
||||
|
||||
// MarshalBinary returns a binary representation of the entry in a new byte slice.
|
||||
|
@ -1005,7 +1007,7 @@ func (w *DeleteBucketRangeWALEntry) MarshalBinary() ([]byte, error) {
|
|||
|
||||
// UnmarshalBinary deserializes the byte slice into w.
|
||||
func (w *DeleteBucketRangeWALEntry) UnmarshalBinary(b []byte) error {
|
||||
if len(b) != 2*influxdb.IDLength+16 {
|
||||
if len(b) < 2*influxdb.IDLength+16 {
|
||||
return ErrWALCorrupt
|
||||
}
|
||||
|
||||
|
@ -1017,13 +1019,19 @@ func (w *DeleteBucketRangeWALEntry) UnmarshalBinary(b []byte) error {
|
|||
}
|
||||
w.Min = int64(binary.BigEndian.Uint64(b[2*influxdb.IDLength : 2*influxdb.IDLength+8]))
|
||||
w.Max = int64(binary.BigEndian.Uint64(b[2*influxdb.IDLength+8 : 2*influxdb.IDLength+16]))
|
||||
w.Predicate = b[2*influxdb.IDLength+16:]
|
||||
|
||||
// Maintain backwards compatability where no predicate bytes means nil
|
||||
if len(w.Predicate) == 0 {
|
||||
w.Predicate = nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalSize returns the number of bytes the entry takes when marshaled.
|
||||
func (w *DeleteBucketRangeWALEntry) MarshalSize() int {
|
||||
return 2*influxdb.IDLength + 16
|
||||
return 2*influxdb.IDLength + 16 + len(w.Predicate)
|
||||
}
|
||||
|
||||
// Encode converts the entry into a byte stream using b if it is large enough.
|
||||
|
@ -1047,6 +1055,7 @@ func (w *DeleteBucketRangeWALEntry) Encode(b []byte) ([]byte, error) {
|
|||
copy(b[influxdb.IDLength:], bucketID)
|
||||
binary.BigEndian.PutUint64(b[2*influxdb.IDLength:], uint64(w.Min))
|
||||
binary.BigEndian.PutUint64(b[2*influxdb.IDLength+8:], uint64(w.Max))
|
||||
copy(b[2*influxdb.IDLength+16:], w.Predicate)
|
||||
|
||||
return b[:sz], nil
|
||||
}
|
||||
|
|
|
@ -226,6 +226,7 @@ func TestWALWriter_DeleteBucketRange(t *testing.T) {
|
|||
BucketID: influxdb.ID(2),
|
||||
Min: 3,
|
||||
Max: 4,
|
||||
Predicate: []byte("predicate"),
|
||||
}
|
||||
|
||||
if err := w.Write(mustMarshalEntry(entry)); err != nil {
|
||||
|
@ -453,6 +454,10 @@ func TestDeleteBucketRangeWALEntry_UnmarshalBinary(t *testing.T) {
|
|||
BucketID: influxdb.ID(rand.Int63()) + 1,
|
||||
Min: rand.Int63(),
|
||||
Max: rand.Int63(),
|
||||
Predicate: make([]byte, rand.Intn(100)),
|
||||
}
|
||||
if len(in.Predicate) == 0 {
|
||||
in.Predicate = nil
|
||||
}
|
||||
|
||||
b, err := in.MarshalBinary()
|
||||
|
@ -477,6 +482,7 @@ func TestWriteWALSegment_UnmarshalBinary_DeleteBucketRangeWALCorrupt(t *testing.
|
|||
BucketID: influxdb.ID(2),
|
||||
Min: 3,
|
||||
Max: 4,
|
||||
Predicate: []byte("predicate"),
|
||||
}
|
||||
|
||||
b, err := w.MarshalBinary()
|
||||
|
|
Loading…
Reference in New Issue