s3: publish a recovered PUT's event at its commit stamp (#13265)

* s3: publish a recovered PUT's event at the stored entry's commit stamp

A PUT whose create committed but lost its answer, and that recovery
then found stored, published its event at the gateway's clock. A later
write to the same key that carries its filer stamp could then sort
before it. Both recovery paths now take the stamp the committing filer
gave the stored entry, as recovered multipart completions do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq: return the context error when it ends a topic configure

A start whose context ended during ConfigureTopic on the last broker
answered with the RPC's text, so errors.Is(err, context.Canceled) did
not hold for it as it does for a context that ends before an attempt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq: name the broker whose topic configure failed

doConfigureTopic built lastErr with the broker address but returned the
bare RPC error, so a failed configure did not say which broker refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-12-02 03:38:58 -08:00
1 parent 5a8e774e36
commit 2574cedfd3
5 files changed
+65 -21

No files matched your search

@@ -542,6 +542,37 @@ func TestNewTopicPublisherStopsWhenItsContextEnds(t *testing.T) {
}
}
func TestNewTopicPublisherStopsWhenItsContextEndsDuringConfigure(t *testing.T) {
fb := startFakeBroker(t, &fakeBroker{stallConfigure: true})
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
_, err := NewTopicPublisher(ctx, &PublisherConfiguration{
Topic: topic.NewTopic("test", t.Name()),
PartitionCount: 1,
Brokers: []string{fb.addr},
PublisherName: "test",
})
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("NewTopicPublisher = %v, want context.DeadlineExceeded", err)
}
}
func TestNewTopicPublisherNamesTheBrokerThatFailedConfigure(t *testing.T) {
saved := configureTopicTimeout
configureTopicTimeout = 100 * time.Millisecond
t.Cleanup(func() { configureTopicTimeout = saved })
hung := startFakeBroker(t, &fakeBroker{stallConfigure: true})
_, err := NewTopicPublisher(context.Background(), &PublisherConfiguration{
Topic: topic.NewTopic("test", t.Name()),
PartitionCount: 1,
Brokers: []string{hung.addr},
PublisherName: "test",
})
if err == nil || !strings.Contains(err.Error(), hung.addr) {
t.Fatalf("NewTopicPublisher = %v, want an error naming %s", err, hung.addr)
}
}
func TestNewTopicPublisherMovesPastABrokerThatHangsOnConfigure(t *testing.T) {
saved := configureTopicTimeout
configureTopicTimeout = 100 * time.Millisecond
+5 -2
View File
@@ -423,12 +423,15 @@ func (p *TopicPublisher) doConfigureTopic(ctx context.Context) (err error) {
lastErr = nil
return nil
} else {
lastErr = fmt.Errorf("%s: %v", brokerAddress, err)
lastErr = fmt.Errorf("%s: %w", brokerAddress, err)
}
}
if ctx.Err() != nil {
return ctx.Err()
}
if lastErr != nil {
return fmt.Errorf("doConfigureTopic %s: %v", p.config.Topic, err)
return fmt.Errorf("doConfigureTopic %s: %w", p.config.Topic, lastErr)
}
return nil
}
+15 -10
View File
@@ -37,14 +37,19 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
}
t.Run("stored entry is this PUT's — route landed", func(t *testing.T) {
f := &fakeLookupFiler{entry: &filer_pb.Entry{Name: "o", Chunks: []*filer_pb.FileChunk{{FileId: "5,01637037d6", Size: 55}}}}
f := &fakeLookupFiler{entry: &filer_pb.Entry{Name: "o", Chunks: []*filer_pb.FileChunk{{FileId: "5,01637037d6", Size: 55}}, CommitTsNs: 1234}}
s3a, owner := newS3a(t, f)
entryCreated := false
var commitLogTsNs int64
ran := false
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, &commitLogTsNs, chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrNone || !entryCreated {
t.Fatalf("code=%v entryCreated=%v", code, entryCreated)
}
// the event takes the stamp the route committed with, not the gateway clock
if commitLogTsNs != 1234 {
t.Fatalf("commit stamp %d, want the stored entry's 1234", commitLogTsNs)
}
if ran {
t.Fatal("re-committed an entry the route already stored")
}
@@ -55,7 +60,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
s3a, owner := newS3a(t, f)
entryCreated := false
ran := false
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrServiceUnavailable {
t.Fatalf("code = %v, want ServiceUnavailable", code)
}
@@ -71,7 +76,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
entryCreated := false
ran := false
var gotCond *filer_pb.WriteCondition
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive, func(cond *filer_pb.WriteCondition) s3err.ErrorCode {
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksAlive, func(cond *filer_pb.WriteCondition) s3err.ErrorCode {
ran = true
gotCond = cond
return s3err.ErrExistingObjectIsDirectory
@@ -93,7 +98,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
s3a, owner := newS3a(t, f)
entryCreated := false
ran := false
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksDead, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksDead, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrServiceUnavailable || ran {
t.Fatalf("code=%v ran=%v — re-committed over a directory with possibly-deleted chunks", code, ran)
}
@@ -105,7 +110,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
s3a := ambiguousRouteServer(t, deadAddr, matchAddr)
entryCreated := false
ran := false
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", deadAddr, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", deadAddr, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrServiceUnavailable || entryCreated || ran {
t.Fatalf("code=%v entryCreated=%v ran=%v — a match behind an unresolved lookup must not finalize", code, entryCreated, ran)
}
@@ -117,7 +122,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
entryCreated := false
ran := false
var gotCond *filer_pb.WriteCondition
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive, func(cond *filer_pb.WriteCondition) s3err.ErrorCode { ran = true; gotCond = cond; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksAlive, func(cond *filer_pb.WriteCondition) s3err.ErrorCode { ran = true; gotCond = cond; return s3err.ErrNone })
if code != s3err.ErrNone || !ran {
t.Fatalf("code=%v ran=%v — proven-absent entry did not reach createUnderLock", code, ran)
}
@@ -131,7 +136,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
s3a, owner := newS3a(t, f)
entryCreated := false
ran := false
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksDead, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksDead, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrServiceUnavailable || ran {
t.Fatalf("code=%v ran=%v — re-committed an entry over possibly-deleted chunks", code, ran)
}
@@ -142,7 +147,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
s3a, owner := newS3a(t, f)
entryCreated := false
ran := false
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrServiceUnavailable || ran {
t.Fatalf("code=%v ran=%v — uncertain state still committed", code, ran)
}
@@ -154,7 +159,7 @@ func TestCreateAfterAmbiguousRoute(t *testing.T) {
entryCreated := false
ran := false
finalize := &putFinalize{afterCreate: func(*filer_pb.Entry) s3err.ErrorCode { return s3err.ErrInternalError }}
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, finalize, &entryCreated, chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
code := s3a.createAfterAmbiguousRoute(filePath, "b", "o", owner, &filer_pb.Entry{Name: "o"}, uploaded, finalize, &entryCreated, new(int64), chunksAlive, func(*filer_pb.WriteCondition) s3err.ErrorCode { ran = true; return s3err.ErrNone })
if code != s3err.ErrInternalError || ran {
t.Fatalf("code=%v ran=%v", code, ran)
}
+8 -6
View File
@@ -1285,7 +1285,7 @@ func (s3a *S3ApiServer) putToFiler(r *http.Request, filePath string, dataReader
}
if routedAmbiguous {
createFn = func() s3err.ErrorCode {
return s3a.createAfterAmbiguousRoute(filePath, bucket, object, owner, entry, chunkResult.FileChunks, finalize, &entryCreated, s3a.uploadedChunksExist, createUnderLock)
return s3a.createAfterAmbiguousRoute(filePath, bucket, object, owner, entry, chunkResult.FileChunks, finalize, &entryCreated, &commitLogTsNs, s3a.uploadedChunksExist, createUnderLock)
}
}
createCode = s3a.withObjectWriteLock(bucket, object, preconditionFn, createFn)
@@ -1305,9 +1305,9 @@ func (s3a *S3ApiServer) putToFiler(r *http.Request, filePath string, dataReader
if upload, ok := multipartPartUpload(r); ok {
routeObject = upload.object
}
landed, absent := s3a.confirmCreateLanded(filePath, bucket, object, routeObject, entry, chunkResult.FileChunks, finalize)
landed, absent, landedTsNs := s3a.confirmCreateLanded(filePath, bucket, object, routeObject, entry, chunkResult.FileChunks, finalize)
if landed {
createCode = s3err.ErrNone
createCode, commitLogTsNs = s3err.ErrNone, landedTsNs
}
// The filer forwards a conditional create to its ring owner, which
// the lookups may not reach; only a refusal proves it never committed.
@@ -1370,7 +1370,7 @@ const createLookupTimeout = 10 * time.Second
// verifiably-live chunks or a directory conflict with them falls through to
// the normal create — an empty upload has nothing to verify, so neither the
// absent nor the lookalike-entry outcome is provable for it.
func (s3a *S3ApiServer) createAfterAmbiguousRoute(filePath, bucket, object string, owner pb.ServerAddress, entry *filer_pb.Entry, uploaded []*filer_pb.FileChunk, finalize *putFinalize, entryCreated *bool, chunksExist func(ctx context.Context, chunks []*filer_pb.FileChunk) bool, createUnderLock func(cond *filer_pb.WriteCondition) s3err.ErrorCode) s3err.ErrorCode {
func (s3a *S3ApiServer) createAfterAmbiguousRoute(filePath, bucket, object string, owner pb.ServerAddress, entry *filer_pb.Entry, uploaded []*filer_pb.FileChunk, finalize *putFinalize, entryCreated *bool, commitLogTsNs *int64, chunksExist func(ctx context.Context, chunks []*filer_pb.FileChunk) bool, createUnderLock func(cond *filer_pb.WriteCondition) s3err.ErrorCode) s3err.ErrorCode {
dir, name := path.Dir(filePath), path.Base(filePath)
lookupCtx, cancel := context.WithTimeout(context.Background(), createLookupTimeout)
defer cancel()
@@ -1426,6 +1426,7 @@ func (s3a *S3ApiServer) createAfterAmbiguousRoute(filePath, bucket, object strin
return s3err.ErrInternalError
}
*entryCreated = true
*commitLogTsNs = existing.GetCommitTsNs()
if finalize != nil && finalize.afterCreate != nil {
if code := finalize.afterCreate(entry); code != s3err.ErrNone {
// Same undo the create path applies when post-create
@@ -1529,7 +1530,7 @@ func chunkNeedleExists(ctx context.Context, fileUrl, jwt string) bool {
// have committed on to lack the entry, the only outcome where the uploaded
// chunks are orphaned. routeObject picks the owner filers to check: the object
// itself, or for a staged part the object its upload completes into.
func (s3a *S3ApiServer) confirmCreateLanded(filePath, bucket, object, routeObject string, entry *filer_pb.Entry, uploaded []*filer_pb.FileChunk, finalize *putFinalize) (landed, absent bool) {
func (s3a *S3ApiServer) confirmCreateLanded(filePath, bucket, object, routeObject string, entry *filer_pb.Entry, uploaded []*filer_pb.FileChunk, finalize *putFinalize) (landed, absent bool, commitLogTsNs int64) {
dir, name := path.Dir(filePath), path.Base(filePath)
owner := s3a.routableWriteOwner(bucket, routeObject)
lookupCtx, cancel := context.WithTimeout(context.Background(), createLookupTimeout)
@@ -1565,6 +1566,7 @@ func (s3a *S3ApiServer) confirmCreateLanded(filePath, bucket, object, routeObjec
return s3err.ErrNone
}
glog.Warningf("putToFiler: create entry for %s failed but the entry exists, treating the write as successful", filePath)
commitLogTsNs = existing.GetCommitTsNs()
if finalize == nil || finalize.afterCreate == nil {
landed = true
return s3err.ErrNone
@@ -1579,7 +1581,7 @@ func (s3a *S3ApiServer) confirmCreateLanded(filePath, bucket, object, routeObjec
landed = true
return s3err.ErrNone
})
return landed, absent
return landed, absent, commitLogTsNs
}
// createTargetFilers lists the filers a failed create could have committed on:
@@ -74,7 +74,7 @@ func TestAmbiguousRouteRecoveryCreatesMissingParent(t *testing.T) {
addr := s3a.option.Filers[0]
f.put("/buckets/b/d", &filer_pb.Entry{Name: "o", Chunks: []*filer_pb.FileChunk{{FileId: "5,01637037d6", Size: 55}}})
entryCreated := false
code := s3a.createAfterAmbiguousRoute("/buckets/b/d/o", "b", "d/o", addr, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, chunksAlive,
code := s3a.createAfterAmbiguousRoute("/buckets/b/d/o", "b", "d/o", addr, &filer_pb.Entry{Name: "o"}, uploaded, nil, &entryCreated, new(int64), chunksAlive,
func(*filer_pb.WriteCondition) s3err.ErrorCode {
t.Fatal("re-committed an entry the route already stored")
return s3err.ErrNone
@@ -118,8 +118,11 @@ func TestConfirmCreateLandedCreatesMissingParent(t *testing.T) {
f := newParentFailFiler()
f.mkdirFails = mkdirFails
s3a := parentRecoveryServer(t, f)
f.put("/buckets/b/d", &filer_pb.Entry{Name: "o", Chunks: []*filer_pb.FileChunk{{FileId: "5,01637037d6", Size: 55}}})
landed, absent := s3a.confirmCreateLanded("/buckets/b/d/o", "b", "d/o", "d/o", &filer_pb.Entry{Name: "o"}, uploaded, nil)
f.put("/buckets/b/d", &filer_pb.Entry{Name: "o", Chunks: []*filer_pb.FileChunk{{FileId: "5,01637037d6", Size: 55}}, CommitTsNs: 1234})
landed, absent, commitLogTsNs := s3a.confirmCreateLanded("/buckets/b/d/o", "b", "d/o", "d/o", &filer_pb.Entry{Name: "o"}, uploaded, nil)
if landed && commitLogTsNs != 1234 {
t.Fatalf("commit stamp %d, want the stored entry's 1234", commitLogTsNs)
}
if absent || landed == mkdirFails || f.isDir("/buckets/b", "d") == mkdirFails {
t.Fatalf("mkdirFails=%v: landed=%v absent=%v dir=%v", mkdirFails, landed, absent, f.isDir("/buckets/b", "d"))
}