mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
fix(storage): retain protected intents through fence cleanup and close
This commit is contained in:
1 parent
74aab9a442
commit
bb9a22da21
2 files changed
+36
No files matched your search
@@ -49,6 +49,12 @@ func TestHeadBeltOldCASUnconfirmedKeepsIntentsAndFrontier(t *testing.T) {
|
||||
if got, err := s.Read(0); err != nil || !bytes.Equal(got, want) {
|
||||
t.Fatalf("local acknowledged bytes changed: %v", err)
|
||||
}
|
||||
if err := layer.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(liveIntents(t, f)) == 0 {
|
||||
t.Fatal("Close removed unconfirmed publication roots")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadBeltLowerEpochConflictFencesWithoutCleanup(t *testing.T) {
|
||||
@@ -80,4 +86,31 @@ func TestHeadBeltLowerEpochConflictFencesWithoutCleanup(t *testing.T) {
|
||||
if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, ErrChunkLayerFenced) || f.stats().cas != calls {
|
||||
t.Fatalf("fenced owner retried publication: %v", err)
|
||||
}
|
||||
if err := layer.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(liveIntents(t, f)) == 0 {
|
||||
t.Fatal("Close removed fenced publication roots")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadBeltTakeoverWaitsBeforeConfirmation(t *testing.T) {
|
||||
f := newFakeChunkRemote()
|
||||
f.head = chunkHead{Gen: 1, Epoch: 1, Holder: "old", Chunks: map[uint64]chunkRef{}}
|
||||
var committedAt time.Time
|
||||
f.afterCAS = func(f *fakeChunkRemote) {
|
||||
committedAt = time.Now()
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
||||
defer cancel()
|
||||
head, err := ClaimChunkHead(ctx, f, ChunkLayerConfig{Epoch: 2, Holder: "new"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if committedAt.IsZero() || time.Since(committedAt) < 5*time.Second || f.stats().getHeads != 2 {
|
||||
t.Fatal("takeover served before cooling and its confirmation read")
|
||||
}
|
||||
if head.Gen != 2 || head.Epoch != 2 || head.Holder != "new" {
|
||||
t.Fatal("confirmed the wrong owner", head)
|
||||
}
|
||||
}
|
||||
@@ -1750,6 +1750,9 @@ func (l *chunkLayerImpl) dropIntents(ctx context.Context, ids []string) {
|
||||
// once, rather than rescanning every cached chunk for each delete.
|
||||
l.stMu.Lock()
|
||||
keep := make(map[string]bool)
|
||||
for _, id := range l.pendingIntents {
|
||||
keep[id] = true
|
||||
}
|
||||
for idx, sc := range l.reusable {
|
||||
if l.closed || l.fenced || sc.ver != l.chunkVersion(idx) || sc.headGen != l.head.Gen {
|
||||
delete(l.reusable, idx)
|
||||
|
||||
Reference in new issue
Block a user