End an unassigned key with ended and remove no key of the chain (issue 1093)
ADR 0408 section 4 says no key of the chain is removed, a delete marker included. The Backend loses Remove and the Chain RemoveAssignment. An unassignment, and the end of a value only pulled in by another, write the value again with ended set, by compare-and-set; assigning it again writes a fresh standing value over it. A value with ended or a state is no assignment (Assignment.Stands) to the assignment lists, the joins, forgetting a module, seat holdings, the given values, the move and the assignment-changed event.
This commit is contained in:
+2
-12
@@ -41,7 +41,7 @@ func OnTheBus(ctx context.Context, conn *nats.Conn, holds Holds) (*Chain, error)
|
||||
return New(builds, rollouts, assignments, holds), nil
|
||||
}
|
||||
|
||||
// busBucket is a Backend on a key-value bucket. It calls no delete and no purge: the type has none to call.
|
||||
// busBucket is a Backend on a key-value bucket. It calls no delete and no purge: the type has none to call (ADR 0408 §4).
|
||||
type busBucket struct{ kv jetstream.KeyValue }
|
||||
|
||||
func entryOf(e jetstream.KeyValueEntry) Entry {
|
||||
@@ -76,16 +76,6 @@ func (b busBucket) Update(ctx context.Context, key string, value []byte, revisio
|
||||
return rev, err
|
||||
}
|
||||
|
||||
func (b busBucket) Remove(ctx context.Context, key string, revision uint64) error {
|
||||
// A delete marker, never a purge: the key's earlier values stay in the bucket's history.
|
||||
err := b.kv.Delete(ctx, key, jetstream.LastRevision(revision))
|
||||
var apiErr *jetstream.APIError
|
||||
if errors.As(err, &apiErr) && apiErr.ErrorCode == jetstream.JSErrCodeStreamWrongLastSequence {
|
||||
return ErrMoved
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (b busBucket) Keys(ctx context.Context) ([]string, error) {
|
||||
keys, err := b.kv.Keys(ctx)
|
||||
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||
@@ -137,7 +127,7 @@ func (b busBucket) History(ctx context.Context, key string) ([]Entry, error) {
|
||||
out := make([]Entry, 0, len(all))
|
||||
for _, e := range all {
|
||||
if e.Operation() != jetstream.KeyValuePut {
|
||||
continue
|
||||
continue // a marker an earlier mirror left; nothing of the chain makes one
|
||||
}
|
||||
out = append(out, entryOf(e))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user