mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-06 21:29:02 +00:00
refactor(api): replace map[string]uint64 with api.StoreVersion for store version handling
This commit is contained in:
1 parent
e4455e936a
commit
e50c5fbe57
8 files changed
+37
-22
No files matched your search
+1
-1
@@ -458,7 +458,7 @@ func (cli *CLI) AddMachine(ctx context.Context, opts AddMachineOptions) (_ *clie
|
||||
}
|
||||
|
||||
// Snapshot the cluster store version so the new machine can catch up before participating.
|
||||
var storeVersion map[string]uint64
|
||||
var storeVersion api.StoreVersion
|
||||
inspectResp, err = c.MachineClient.InspectMachine(ctx, &emptypb.Empty{})
|
||||
if err != nil {
|
||||
// TODO(lhf): remove Unimplemented check when v0.17.0 is released.
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/psviderski/uncloud/internal/machine/network"
|
||||
"github.com/psviderski/uncloud/internal/secret"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,7 +32,7 @@ type State struct {
|
||||
// MinStoreVersion is the cluster store version this machine must reach before participating.
|
||||
// Per-actor vector (Corrosion actor UUID → max processed db_version) captured from an existing
|
||||
// member at join time. Cleared once reached.
|
||||
MinStoreVersion map[string]uint64 `json:",omitempty"`
|
||||
MinStoreVersion api.StoreVersion `json:",omitempty"`
|
||||
// CorrosionAPIToken authenticates requests to the local Corrosion API.
|
||||
CorrosionAPIToken secret.Secret `json:",omitempty"`
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
)
|
||||
|
||||
// ErrInvalidStoreVersion indicates an invalid actor UUID in a store version vector.
|
||||
@@ -27,7 +28,7 @@ var ErrInvalidStoreVersion = errors.New("invalid store version")
|
||||
//
|
||||
// The method observes native replication without initiating synchronisation.
|
||||
// An empty minVersion requires no replication. The context controls cancellation and the deadline.
|
||||
func (s *Store) WaitForVersion(ctx context.Context, minVersion map[string]uint64) error {
|
||||
func (s *Store) WaitForVersion(ctx context.Context, minVersion api.StoreVersion) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/psviderski/uncloud/api/pb"
|
||||
"github.com/psviderski/uncloud/internal/corrosion"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
@@ -81,14 +82,14 @@ func (s *Store) Delete(ctx context.Context, key string) error {
|
||||
// limitations documented there.
|
||||
//
|
||||
// Capturing a vector does not wait for replication or prevent further writes.
|
||||
func (s *Store) Version(ctx context.Context) (map[string]uint64, error) {
|
||||
func (s *Store) Version(ctx context.Context) (api.StoreVersion, error) {
|
||||
rows, err := s.corro.QueryContext(ctx, "SELECT site_id, db_version FROM crsql_db_versions")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query crsql_db_versions: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
versions := make(map[string]uint64)
|
||||
versions := make(api.StoreVersion)
|
||||
for rows.Next() {
|
||||
var (
|
||||
siteID []byte
|
||||
|
||||
Reference in new issue
Block a user