watchtower: update DeleteCommittedUpdate to delete all

This commit updates the DeleteCommittedUpdate DB method to delete all of
a given session's committed updates instead of just one at a time. The
reason for this is that in an upcoming commit, we will introduce a
"Terminal" session state - once we have deleted a committed update for a
session it should be considered "Terminal" and there is never a case
where we would only want to delete one committed update and not the
rest. So we want these two actions (deleting committed updates of a
session and setting it's status to terminal) to be atomic.
This commit is contained in:
Elle Mouton
2023-11-30 11:31:04 +02:00
parent a3bf2c70e5
commit 1ae802812c
4 changed files with 55 additions and 51 deletions

View File

@@ -136,9 +136,9 @@ type DB interface {
// space.
GetDBQueue(namespace []byte) wtdb.Queue[*wtdb.BackupID]
// DeleteCommittedUpdate deletes the committed update belonging to the
// given session and with the given sequence number from the db.
DeleteCommittedUpdate(id *wtdb.SessionID, seqNum uint16) error
// DeleteCommittedUpdates deletes all the committed updates belonging to
// the given session from the db.
DeleteCommittedUpdates(id *wtdb.SessionID) error
}
// AuthDialer connects to a remote node using an authenticated transport, such

View File

@@ -211,14 +211,13 @@ func (q *sessionQueue) Stop(final bool) error {
update.BackupID, err)
continue
}
}
err = q.cfg.DB.DeleteCommittedUpdate(
q.ID(), update.SeqNum,
)
if final {
err = q.cfg.DB.DeleteCommittedUpdates(q.ID())
if err != nil {
log.Errorf("could not delete committed "+
"update %d for session %s",
update.SeqNum, q.ID())
"updates for session %s", q.ID())
}
}