watchtower/wtdb: add bolt db impl of Queue

This commit adds a new generic DiskQueueDB type which is an
bbolt implementation of the Queue interface.
This commit is contained in:
Elle Mouton
2023-02-09 12:35:28 +02:00
parent a946715b7e
commit 5cc7438d33
3 changed files with 592 additions and 3 deletions

View File

@@ -94,6 +94,10 @@ var (
// db-session-id -> last-channel-close-height
cClosableSessionsBkt = []byte("client-closable-sessions-bucket")
// cTaskQueue is a top-level bucket where the disk queue may store its
// content.
cTaskQueue = []byte("client-task-queue")
// ErrTowerNotFound signals that the target tower was not found in the
// database.
ErrTowerNotFound = errors.New("tower not found")
@@ -2060,6 +2064,15 @@ func (c *ClientDB) AckUpdate(id *SessionID, seqNum uint16,
}, func() {})
}
// GetDBQueue returns a BackupID Queue instance under the given namespace.
func (c *ClientDB) GetDBQueue(namespace []byte) Queue[*BackupID] {
return NewQueueDB[*BackupID](
c.db, namespace, func() *BackupID {
return &BackupID{}
},
)
}
// putChannelToSessionMapping adds the given session ID to a channel's
// cChanSessions bucket.
func putChannelToSessionMapping(chanDetails kvdb.RwBucket,