mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* volume: apply a tailed size-0 record as a delete when the key exists A delete and an empty write both reach the tail receiver as a size-0 .dat record. Writing every one as a live needle turned each delete caught by volume.move's tail into a 200-empty object. Treat the record as a delete when the key already has a record on the receiver, and as an empty write otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * rust volume: apply a tailed size-0 record as a delete when the key exists Mirrors the Go tail receiver: a size-0 record for a key that already has a record here is a delete, otherwise an empty write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: volume.merge applies a size-0 record as a delete when the key exists The tail stream carries deletes as size-0 records, and volume.merge wrote each one to the merged copy as a live empty needle, so every delete in the volume came back as a 200-empty object on all replicas. A size-0 record for a key already written in the merged stream is now a delete on the target; for a new key it stays an empty write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: volume.merge reads a size-0 record as a delete only after its own replica's record Replicas append the same write at their own times, so a fresh empty write can reach the merge twice when the copies are further apart than the dedup window. Tracking keys across all replicas made the second copy a delete. Track, per source replica, the keys it has returned (duplicates the merge skips included): a size-0 record is a delete only when its own replica wrote the key before, which is the only way a replica appends a delete. A delete for a key the merged copy already deleted sends nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: volume.merge verification counts the deletes the merge applied Applying deletes lets a correct merge hold fewer live needles than a replica that missed a delete, and the live-count check then refused it and kept the divergent replicas. Every key live on a replica is either live or deleted in the merged copy, so compare that replica's live count with the merged live count plus the keys the merge deleted. An empty merged copy is still refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: tail receiver looks a size-0 record's key up in the needle map The receiver read the needle to decide whether a size-0 record deletes an existing key. A read reports a needle past its TTL as not found, so a delete for it was written as a live empty needle, which reads ignore TTL for. Look the key up in the needle map instead (Volume.LookupNeedle). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * rust volume: tail receiver looks a size-0 record's key up in the needle map Mirror Go: write_tailed_needle read the needle to decide whether a size-0 record deletes an existing key, and a read reports a needle past its TTL as not found, so the delete became a live empty needle. Look the key up in the needle map instead (Volume::lookup_needle). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: volume.merge keeps a merged delete when a late empty copy follows A replica that missed a delete can hold its copy of the empty write stamped after the other replica's delete. As that replica's first record for the key it was written, reviving the deleted key. A size-0 record now never revives a key the merged copy already deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: volume.merge refuses more replicas than its key history has bits Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
func TestWriteTailedNeedleSizeZeroRecords(t *testing.T) {
|
|
store := storage.NewStore(nil, "localhost", 8080, 18080, "http://localhost:8080", "store-id",
|
|
[]string{t.TempDir()}, []int32{10}, []util.MinFreeSpace{{}}, "", storage.NeedleMapInMemory,
|
|
[]types.DiskType{types.HardDriveType}, nil, 0, stats.DefaultDiskIOProbeConfig())
|
|
t.Cleanup(store.Close)
|
|
if err := store.AddVolume(1, "", storage.NeedleMapInMemory, "000", "", 0, needle.Version3, 0, types.HardDriveType, 0); err != nil {
|
|
t.Fatalf("add volume: %v", err)
|
|
}
|
|
const live, deleted, fresh = types.NeedleId(1), types.NeedleId(2), types.NeedleId(3)
|
|
for _, n := range []*needle.Needle{
|
|
{Id: live, Cookie: 7, Data: []byte("live")},
|
|
{Id: deleted, Cookie: 7, Data: []byte("deleted")},
|
|
} {
|
|
if err := writeTailedNeedle(store, 1, n); err != nil {
|
|
t.Fatalf("write %d: %v", n.Id, err)
|
|
}
|
|
}
|
|
if _, err := store.DeleteVolumeNeedle(1, &needle.Needle{Id: deleted}, false); err != nil {
|
|
t.Fatalf("delete %d: %v", deleted, err)
|
|
}
|
|
v := store.GetVolume(1)
|
|
fileCount, deletedCount := v.FileCount(), v.DeletedCount()
|
|
|
|
for _, id := range []types.NeedleId{live, deleted, fresh} {
|
|
if err := writeTailedNeedle(store, 1, &needle.Needle{Id: id, Cookie: 7}); err != nil {
|
|
t.Fatalf("tail size-0 record for %d: %v", id, err)
|
|
}
|
|
}
|
|
|
|
read := func(id types.NeedleId) (int, error) {
|
|
return store.ReadVolumeNeedle(1, &needle.Needle{Id: id}, nil, nil)
|
|
}
|
|
if _, err := read(live); !errors.Is(err, storage.ErrorDeleted) {
|
|
t.Errorf("size-0 record after a write: read err = %v, want deleted", err)
|
|
}
|
|
if _, err := read(deleted); !errors.Is(err, storage.ErrorDeleted) {
|
|
t.Errorf("size-0 record after a delete: read err = %v, want deleted", err)
|
|
}
|
|
if size, err := read(fresh); err != nil || size != 0 {
|
|
t.Errorf("size-0 record for a new key: read = %d, %v, want an empty needle", size, err)
|
|
}
|
|
if got, want := v.FileCount(), fileCount+1; got != want {
|
|
t.Errorf("file count = %d, want %d", got, want)
|
|
}
|
|
if got, want := v.DeletedCount(), deletedCount+1; got != want {
|
|
t.Errorf("deleted count = %d, want %d", got, want)
|
|
}
|
|
|
|
if err := writeTailedNeedle(store, 1, &needle.Needle{Id: fresh, Cookie: 7}); err != nil {
|
|
t.Fatalf("second size-0 record for %d: %v", fresh, err)
|
|
}
|
|
if _, err := read(fresh); !errors.Is(err, storage.ErrorDeleted) {
|
|
t.Errorf("second size-0 record: read err = %v, want deleted", err)
|
|
}
|
|
}
|