feat(storage): expose backup restoration and maintenance tools

This commit is contained in:
eezd committed 2026-10-25 13:22:16 +08:00
1 parent 88492fdcde
commit 9449a1aa65
18 files changed
+2194 -61

No files matched your search

+17
View File
@@ -24,6 +24,7 @@ type Event struct {
type Hub struct {
mu sync.Mutex
clients map[chan []byte]struct{}
closed bool
}
func NewHub() *Hub { return &Hub{clients: map[chan []byte]struct{}{}} }
@@ -32,6 +33,11 @@ func NewHub() *Hub { return &Hub{clients: map[chan []byte]struct{}{}} }
func (h *Hub) Subscribe() (<-chan []byte, func()) {
ch := make(chan []byte, 64)
h.mu.Lock()
if h.closed {
close(ch)
h.mu.Unlock()
return ch, func() {}
}
h.clients[ch] = struct{}{}
h.mu.Unlock()
return ch, func() {
@@ -64,3 +70,14 @@ func (h *Hub) Broadcast(events ...Event) {
}
}
}
// Close 禁止新订阅,并通知现有连接关闭,供实例恢复重新打开数据库使用。
func (h *Hub) Close() {
h.mu.Lock()
defer h.mu.Unlock()
h.closed = true
for ch := range h.clients {
delete(h.clients, ch)
close(ch)
}
}