mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
relax relationship between corrosion service, init cluster with new store
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"uncloud/internal/corrosion"
|
||||
"uncloud/internal/machine/api/pb"
|
||||
)
|
||||
|
||||
//go:embed schema.sql
|
||||
var Schema string
|
||||
var (
|
||||
//go:embed schema.sql
|
||||
Schema string
|
||||
|
||||
ErrKeyNotFound = errors.New("key not found")
|
||||
)
|
||||
|
||||
// Store is a cluster store backed by a distributed Corrosion database.
|
||||
type Store struct {
|
||||
@@ -19,6 +25,28 @@ func New(corro *corrosion.APIClient) *Store {
|
||||
return &Store{corro: corro}
|
||||
}
|
||||
|
||||
func (s *Store) Get(ctx context.Context, key string, value any) error {
|
||||
rows, err := s.corro.QueryContext(ctx, "SELECT value FROM cluster WHERE key = ?", key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !rows.Next() {
|
||||
if rows.Err() != nil {
|
||||
return rows.Err()
|
||||
}
|
||||
return ErrKeyNotFound
|
||||
}
|
||||
if err = rows.Scan(value); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) Put(ctx context.Context, key string, value any) error {
|
||||
_, err := s.corro.ExecContext(ctx, "INSERT OR REPLACE INTO cluster (key, value) VALUES (?, ?)", key, value)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Store) CreateMachine(machine *pb.MachineInfo) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user