major changes
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 43s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m43s

This commit is contained in:
matst80
2025-12-04 20:56:54 +01:00
parent 6d5358b53b
commit f67eeb3c49
21 changed files with 572 additions and 242 deletions

View File

@@ -107,19 +107,27 @@ func (s *ControlServer[V]) AnnounceOwnership(ctx context.Context, req *messages.
}, nil
}
func toAny[V any](grain V) (*anypb.Any, error) {
data, err := json.Marshal(grain)
if err != nil {
return nil, err
}
return &anypb.Any{
Value: data,
}, nil
}
func (s *ControlServer[V]) Get(ctx context.Context, req *messages.GetRequest) (*messages.GetReply, error) {
grain, err := s.pool.Get(ctx, req.Id)
if err != nil {
return nil, err
}
data, err := json.Marshal(grain)
grainAny, err := toAny(grain)
if err != nil {
return nil, err
}
return &messages.GetReply{
Grain: &anypb.Any{
Value: data,
},
Grain: grainAny,
}, nil
}
@@ -163,16 +171,40 @@ func (s *ControlServer[V]) Apply(ctx context.Context, in *messages.ApplyRequest)
for i, anyMsg := range in.Messages {
msg, err := anyMsg.UnmarshalNew()
if err != nil {
return &messages.ApplyResult{Accepted: false}, fmt.Errorf("failed to unmarshal message: %w", err)
return nil, fmt.Errorf("failed to unmarshal message: %w", err)
}
msgs[i] = msg
}
_, err := s.pool.Apply(ctx, in.Id, msgs...)
r, err := s.pool.Apply(ctx, in.Id, msgs...)
if err != nil {
return &messages.ApplyResult{Accepted: false}, err
return nil, err
}
grainAny, err := toAny(r)
if err != nil {
return nil, err
}
mutList := make([]*messages.MutationResult, len(in.Messages))
for i, msg := range r.Mutations {
mut, err := anypb.New(msg.Mutation)
if err != nil {
return nil, err
}
var errString *string
if msg.Error != nil {
s := msg.Error.Error()
errString = &s
}
mutList[i] = &messages.MutationResult{
Type: msg.Type,
Message: mut,
Error: errString,
}
}
return &messages.ApplyResult{Accepted: true}, nil
return &messages.ApplyResult{
State: grainAny,
Mutations: mutList,
}, nil
}
// ControlPlane: Negotiate (merge host views)