@@ -43,11 +43,13 @@ var ErrDeleteRequestNotFound = errors.New("could not find matching delete reques
43
43
type DeleteRequestsStore interface {
44
44
AddDeleteRequestGroup (ctx context.Context , req []DeleteRequest ) ([]DeleteRequest , error )
45
45
GetDeleteRequestsByStatus (ctx context.Context , status DeleteRequestStatus ) ([]DeleteRequest , error )
46
+ GetAllDeleteRequests (ctx context.Context ) ([]DeleteRequest , error )
46
47
GetAllDeleteRequestsForUser (ctx context.Context , userID string ) ([]DeleteRequest , error )
47
48
UpdateStatus (ctx context.Context , req DeleteRequest , newStatus DeleteRequestStatus ) error
48
49
GetDeleteRequestGroup (ctx context.Context , userID , requestID string ) ([]DeleteRequest , error )
49
50
RemoveDeleteRequests (ctx context.Context , req []DeleteRequest ) error
50
51
GetCacheGenerationNumber (ctx context.Context , userID string ) (string , error )
52
+ MergeShardedRequests (ctx context.Context , requestToAdd DeleteRequest , requestsToRemove []DeleteRequest ) error
51
53
Stop ()
52
54
Name () string
53
55
}
@@ -99,6 +101,7 @@ func (ds *deleteRequestsStore) AddDeleteRequestGroup(ctx context.Context, reqs [
99
101
results = append (results , newReq )
100
102
ds .writeDeleteRequest (newReq , writeBatch )
101
103
}
104
+ ds .updateCacheGen (reqs [0 ].UserID , writeBatch )
102
105
103
106
if err := ds .indexClient .BatchWrite (ctx , writeBatch ); err != nil {
104
107
return nil , err
@@ -107,6 +110,18 @@ func (ds *deleteRequestsStore) AddDeleteRequestGroup(ctx context.Context, reqs [
107
110
return results , nil
108
111
}
109
112
113
+ func (ds * deleteRequestsStore ) MergeShardedRequests (ctx context.Context , requestToAdd DeleteRequest , requestsToRemove []DeleteRequest ) error {
114
+ writeBatch := ds .indexClient .NewWriteBatch ()
115
+
116
+ ds .writeDeleteRequest (requestToAdd , writeBatch )
117
+
118
+ for _ , req := range requestsToRemove {
119
+ ds .removeRequest (req , writeBatch )
120
+ }
121
+
122
+ return ds .indexClient .BatchWrite (ctx , writeBatch )
123
+ }
124
+
110
125
func newRequest (req DeleteRequest , requestID []byte , createdAt model.Time , seqNumber int ) (DeleteRequest , error ) {
111
126
req .RequestID = string (requestID )
112
127
req .Status = StatusReceived
@@ -124,14 +139,15 @@ func (ds *deleteRequestsStore) writeDeleteRequest(req DeleteRequest, writeBatch
124
139
// Add an entry with userID, requestID, and sequence number as range key and status as value to make it easy
125
140
// to manage and lookup status. We don't want to set anything in hash key here since we would want to find
126
141
// delete requests by just status
127
- writeBatch .Add (DeleteRequestsTableName , string (deleteRequestID ), []byte (userIDAndRequestID ), []byte (StatusReceived ))
142
+ writeBatch .Add (DeleteRequestsTableName , string (deleteRequestID ), []byte (userIDAndRequestID ), []byte (req . Status ))
128
143
129
144
// Add another entry with additional details like creation time, time range of delete request and the logQL requests in value
130
- rangeValue := fmt .Sprintf ("%x:%x:%x" , int64 (ds . now () ), int64 (req .StartTime ), int64 (req .EndTime ))
145
+ rangeValue := fmt .Sprintf ("%x:%x:%x" , int64 (req . CreatedAt ), int64 (req .StartTime ), int64 (req .EndTime ))
131
146
writeBatch .Add (DeleteRequestsTableName , fmt .Sprintf ("%s:%s" , deleteRequestDetails , userIDAndRequestID ), []byte (rangeValue ), []byte (req .Query ))
147
+ }
132
148
133
- // create a gen number for this result
134
- writeBatch .Add (DeleteRequestsTableName , fmt .Sprintf ("%s:%s" , cacheGenNum , req . UserID ), []byte {}, generateCacheGenNumber ())
149
+ func ( ds * deleteRequestsStore ) updateCacheGen ( userID string , writeBatch index. WriteBatch ) {
150
+ writeBatch .Add (DeleteRequestsTableName , fmt .Sprintf ("%s:%s" , cacheGenNum , userID ), []byte {}, generateCacheGenNumber ())
135
151
}
136
152
137
153
// backwardCompatibleDeleteRequestHash generates the hash key for a delete request.
@@ -172,6 +188,14 @@ func (ds *deleteRequestsStore) GetDeleteRequestsByStatus(ctx context.Context, st
172
188
})
173
189
}
174
190
191
+ // GetAllDeleteRequests returns all the delete requests.
192
+ func (ds * deleteRequestsStore ) GetAllDeleteRequests (ctx context.Context ) ([]DeleteRequest , error ) {
193
+ return ds .queryDeleteRequests (ctx , index.Query {
194
+ TableName : DeleteRequestsTableName ,
195
+ HashValue : string (deleteRequestID ),
196
+ })
197
+ }
198
+
175
199
// GetAllDeleteRequestsForUser returns all delete requests for a user.
176
200
func (ds * deleteRequestsStore ) GetAllDeleteRequestsForUser (ctx context.Context , userID string ) ([]DeleteRequest , error ) {
177
201
return ds .queryDeleteRequests (ctx , index.Query {
@@ -188,11 +212,6 @@ func (ds *deleteRequestsStore) UpdateStatus(ctx context.Context, req DeleteReque
188
212
writeBatch := ds .indexClient .NewWriteBatch ()
189
213
writeBatch .Add (DeleteRequestsTableName , string (deleteRequestID ), []byte (userIDAndRequestID ), []byte (newStatus ))
190
214
191
- if newStatus == StatusProcessed {
192
- // remove runtime filtering for deleted data
193
- writeBatch .Add (DeleteRequestsTableName , fmt .Sprintf ("%s:%s" , cacheGenNum , req .UserID ), []byte {}, generateCacheGenNumber ())
194
- }
195
-
196
215
return ds .indexClient .BatchWrite (ctx , writeBatch )
197
216
}
198
217
@@ -319,20 +338,22 @@ func unmarshalDeleteRequestDetails(itr index.ReadBatchIterator, req DeleteReques
319
338
return DeleteRequest {}, nil
320
339
}
321
340
322
- if err = requestWithDetails .SetQuery (string (itr .Value ())); err != nil {
323
- return DeleteRequest {}, err
324
- }
341
+ requestWithDetails .Query = string (itr .Value ())
325
342
326
343
return requestWithDetails , nil
327
344
}
328
345
329
346
// RemoveDeleteRequests the passed delete requests
330
347
func (ds * deleteRequestsStore ) RemoveDeleteRequests (ctx context.Context , reqs []DeleteRequest ) error {
348
+ if len (reqs ) == 0 {
349
+ return nil
350
+ }
331
351
writeBatch := ds .indexClient .NewWriteBatch ()
332
352
333
353
for _ , r := range reqs {
334
354
ds .removeRequest (r , writeBatch )
335
355
}
356
+ ds .updateCacheGen (reqs [0 ].UserID , writeBatch )
336
357
337
358
return ds .indexClient .BatchWrite (ctx , writeBatch )
338
359
}
@@ -344,9 +365,6 @@ func (ds *deleteRequestsStore) removeRequest(req DeleteRequest, writeBatch index
344
365
// Add another entry with additional details like creation time, time range of delete request and selectors in value
345
366
rangeValue := fmt .Sprintf ("%x:%x:%x" , int64 (req .CreatedAt ), int64 (req .StartTime ), int64 (req .EndTime ))
346
367
writeBatch .Delete (DeleteRequestsTableName , fmt .Sprintf ("%s:%s" , deleteRequestDetails , userIDAndRequestID ), []byte (rangeValue ))
347
-
348
- // ensure caches are invalidated
349
- writeBatch .Add (DeleteRequestsTableName , fmt .Sprintf ("%s:%s" , cacheGenNum , req .UserID ), []byte {}, []byte (strconv .FormatInt (time .Now ().UnixNano (), 10 )))
350
368
}
351
369
352
370
func (ds * deleteRequestsStore ) Name () string {
0 commit comments