diff --git a/worker/backup_processor.go b/worker/backup_processor.go index 4719485b647..2345ad5c07d 100644 --- a/worker/backup_processor.go +++ b/worker/backup_processor.go @@ -70,7 +70,7 @@ func NewBackupProcessor(db *badger.DB, req *pb.BackupRequest) *BackupProcessor { Request: req, threads: make([]*threadLocal, backupNumGo), } - if db != nil { + if req.SinceTs > 0 && db != nil { bp.txn = db.NewTransactionAt(req.ReadTs, false) } for i := range bp.threads { @@ -98,6 +98,9 @@ type LoadResult struct { } func (pr *BackupProcessor) Close() { + if pr.txn == nil { + return + } for _, th := range pr.threads { th.itr.Close() } @@ -158,8 +161,13 @@ func (pr *BackupProcessor) WriteBackup(ctx context.Context) (*pb.BackupResponse, tl := pr.threads[itr.ThreadId] tl.alloc = itr.Alloc - bitr := tl.itr // Use the threadlocal iterator because "itr" has the sinceTs set. - bitr.Seek(key) + bitr := itr + // Use the threadlocal iterator because "itr" has the sinceTs set and + // it will not be able to read all the data. + if tl.itr != nil { + bitr = tl.itr + bitr.Seek(key) + } kvList, dropOp, err := tl.toBackupList(key, bitr) if err != nil {