mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
chore: wait for known missing changes during the initial cluster store sync
This commit is contained in:
@@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
@@ -75,6 +76,35 @@ func (s *Store) DBVersion(ctx context.Context) (int64, error) {
|
||||
return version, nil
|
||||
}
|
||||
|
||||
type MissingChange struct {
|
||||
ActorID string
|
||||
StartVersion int64
|
||||
EndVersion int64
|
||||
}
|
||||
|
||||
// KnownMissingChanges returns a list of currently known missing changes in the Corrosion database.
|
||||
func (s *Store) KnownMissingChanges(ctx context.Context) ([]MissingChange, error) {
|
||||
rows, err := s.corro.QueryContext(ctx, "SELECT actor_id, start, end FROM __corro_bookkeeping_gaps")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query missing changes: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var changes []MissingChange
|
||||
for rows.Next() {
|
||||
var c MissingChange
|
||||
var actorBytes []byte
|
||||
if err = rows.Scan(&actorBytes, &c.StartVersion, &c.EndVersion); err != nil {
|
||||
return nil, fmt.Errorf("scan missing change: %w", err)
|
||||
}
|
||||
|
||||
c.ActorID = hex.EncodeToString(actorBytes)
|
||||
changes = append(changes, c)
|
||||
}
|
||||
|
||||
return changes, nil
|
||||
}
|
||||
|
||||
func (s *Store) CreateMachine(ctx context.Context, m *pb.MachineInfo) error {
|
||||
mJSON, err := protojson.Marshal(m)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user