@@ -26,8 +26,8 @@ const (
2626)
2727
2828var (
29- ErrUnknownSpaceId = errors .New ("unknown space id" )
30- ErrNoLastRecordId = errors .New ("no last record id" )
29+ ErrUnknownSpaceId = errors .New ("unknown space id" )
30+ ErrNoDeletionLogId = errors .New ("no last record id" )
3131)
3232
3333const (
@@ -57,7 +57,8 @@ type IndexStorage interface {
5757 SpaceStatus (ctx context.Context , spaceId string ) (status SpaceStatus , err error )
5858 MarkArchived (ctx context.Context , spaceId string , compressedSize , uncompressedSize int64 ) (err error )
5959 MarkError (ctx context.Context , spaceId string , errString string ) (err error )
60- LastRecordId (ctx context.Context ) (id string , err error )
60+ DeletionLogId (ctx context.Context ) (id string , err error )
61+ SetDeletionLogId (ctx context.Context , id string ) (err error )
6162 FindOldestInactiveSpace (ctx context.Context , olderThan time.Duration , skip int ) (spaceId string , err error )
6263
6364 UpdateLastAccess (ctx context.Context , spaceId string ) (err error )
@@ -205,17 +206,29 @@ func (d *indexStorage) MarkArchived(ctx context.Context, spaceId string, compres
205206 return err
206207}
207208
208- func (d * indexStorage ) LastRecordId (ctx context.Context ) (id string , err error ) {
209+ func (d * indexStorage ) DeletionLogId (ctx context.Context ) (id string , err error ) {
209210 doc , err := d .settingsColl .FindId (ctx , lastDeletionIdKey )
210211 if err != nil {
211212 if errors .Is (err , anystore .ErrDocNotFound ) {
212- return "" , ErrNoLastRecordId
213+ return "" , ErrNoDeletionLogId
213214 }
214215 return "" , err
215216 }
216217 return doc .Value ().GetString (valueKey ), nil
217218}
218219
220+ func (d * indexStorage ) SetDeletionLogId (ctx context.Context , id string ) (err error ) {
221+ _ , err = d .settingsColl .UpsertId (ctx , lastDeletionIdKey , query .ModifyFunc (func (a * anyenc.Arena , v * anyenc.Value ) (result * anyenc.Value , modified bool , err error ) {
222+ prevKey := v .GetString (valueKey )
223+ if prevKey < id {
224+ v .Set (valueKey , a .NewString (id ))
225+ return v , true , nil
226+ }
227+ return v , false , nil
228+ }))
229+ return
230+ }
231+
219232func (d * indexStorage ) UpdateLastAccess (ctx context.Context , spaceId string ) (err error ) {
220233 now := time .Now ()
221234 if val , ok := d .lastAccessCache .Load (spaceId ); ok {
0 commit comments