RG1: the registry takes a publish ask once by its id
A publish carrying an ask id is kept in the state taken for ask-taken-bound (10m): a repeat while the act runs joins it, a repeat after it ended answers the act's state read afresh (the transfer's lacking parts, a held version ended, a transfer gone refused), never publishing twice. Builds: design 47 H2 §775, §820; H-A-359, H-A-381
This commit is contained in:
@@ -251,6 +251,25 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// A publish ask taken before answers the act's state read afresh and never publishes again (design 47 H2 §775;
|
||||
// H-A-381): an open transfer its lacking parts, a transfer gone with nothing held a refusal naming it.
|
||||
t.Run("a repeated ask answers the act's state", func(t *testing.T) {
|
||||
b := newBed(true)
|
||||
if _, err := b.h.Repeat(ArtifactSeat, builder, req("tr")); err == nil || !strings.Contains(err.Error(), "transfer tr is gone") {
|
||||
t.Errorf("a repeat of an act that never happened answered %v", err)
|
||||
}
|
||||
if _, err := b.h.Publish(ArtifactSeat, builder, req("tr")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
opened := len(b.h.Transfers.(memTransfers))
|
||||
if a, err := b.h.Repeat(ArtifactSeat, builder, req("tr")); err != nil || !reflect.DeepEqual(a.Missing, []string{part.Digest}) {
|
||||
t.Errorf("a repeat of an open transfer = %+v, %v", a, err)
|
||||
}
|
||||
if len(b.h.Transfers.(memTransfers)) != opened || len(b.said) != 0 {
|
||||
t.Errorf("a repeat acted: transfers %d, said %+v", len(b.h.Transfers.(memTransfers)), b.said)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("a transfer in parts, cut and resumed, hashed, numbered by the builder, published", func(t *testing.T) {
|
||||
b := newBed(true)
|
||||
a, err := b.h.Publish(ArtifactSeat, builder, req("t1"))
|
||||
|
||||
@@ -397,6 +397,38 @@ func (h *Holder) DropIdle() ([]string, error) { return h.receiver().DropIdle() }
|
||||
// already gone. It answers whether it dropped the transfer.
|
||||
func (h *Holder) Expired(id string) (bool, error) { return h.receiver().Expired(id) }
|
||||
|
||||
// Repeat is `publish` given again with an ask id the holder already took and whose first act ended (design 47 H2 §775;
|
||||
// H-A-381): it never publishes twice and keeps no answer, but answers the act's state as it stands, read afresh, which is
|
||||
// what the act answers when done: a version the store holds ended, an open transfer the parts it lacks; a transfer that
|
||||
// is gone, with nothing held, says the act never happened, and is refused naming it.
|
||||
func (h *Holder) Repeat(seat, caller string, r PublishRequest) (PublishAnswer, error) {
|
||||
if err := checkPublish(seat, r); err != nil {
|
||||
return PublishAnswer{}, err
|
||||
}
|
||||
if r.Version != "" {
|
||||
var ok bool
|
||||
err := h.timed("the store's read of what it holds (the program's registry)", func() (err error) {
|
||||
_, ok, err = h.Store.Held(r.Name, r.Version, r.Digest)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return PublishAnswer{}, fmt.Errorf("publish: the store cannot say whether it holds %s@%s: %w", r.Name, r.Version, err)
|
||||
} else if ok {
|
||||
return PublishAnswer{Transfer: r.Transfer, Ended: true}, nil
|
||||
}
|
||||
}
|
||||
t, found, err := h.Transfers.Get(r.Transfer)
|
||||
switch {
|
||||
case err != nil:
|
||||
return PublishAnswer{}, fmt.Errorf("publish: the transfer %s of a repeated ask cannot be read: %w", r.Transfer, err)
|
||||
case !found:
|
||||
return PublishAnswer{}, fmt.Errorf("publish: refused: the ask was taken before, and transfer %s is gone with nothing of %s held: the act did not happen", r.Transfer, r.Name)
|
||||
case t.Opener != caller:
|
||||
return PublishAnswer{}, fmt.Errorf("publish: refused for %s: transfer %s was opened by another caller", caller, r.Transfer)
|
||||
}
|
||||
return PublishAnswer{Transfer: t.ID, Missing: t.Lacks()}, nil
|
||||
}
|
||||
|
||||
func checkPublish(seat string, r PublishRequest) error {
|
||||
switch {
|
||||
case !slices.Contains(Seats, seat):
|
||||
|
||||
Reference in New Issue
Block a user