Files
seaweedfs/weed/command/filer_remote_sync_gone_test.go
T
ec1032d642 filer.remote.sync: a source chunk gone for good no longer wedges the write-back (#13220)
* filer.remote.sync: a source chunk gone for good no longer wedges the write-back

An entry whose chunk the volume servers answer 404 for, even with
readDeleted=true, can never be uploaded: the bytes no longer exist in the
cluster. A volume lost with its disk leaves such entries behind (for
example a filer restored from a metadata backup onto a new volume server
while some chunks had not been written back yet). filer.remote.sync
retried the create event forever, every ~2 s, and since a failing event
holds the directory's processed watermark, no later change under the
mount was ever written back again. We hit this in production: one photo's
chunk answered 404 for hours and more than 11,000 later changes waited
behind it.

Now, once the filer confirms the entry is still the one the event
described (the existing supersession check), the upload ends with
errSourceGone when:

- every location answered 404 for sourceGoneGrace (5 min) over
  sourceGoneMinAnswers (3) attempts in a row, or
- the master cannot locate the chunk's volume at all ("failed to locate",
  the whole volume lost with its disk) for sourceGoneLookupGrace (30 min,
  the filer deletion retry's figure for "volume not found").

It logs one ERROR line naming the path, the chunk's fid and the
destination, with a per-process count, and every caller treats the event
as handled so the offset advances. A path found gone is remembered with
its fid (bounded to 10,000), so later events of the same entry are skipped
at once; any other outcome (success, superseded, another error, a failed
supersession lookup) forgets it and starts the grace again, so a volume
server that has not loaded its volume yet, or a stale location, is not
mistaken for lost data.

Only the source decides. The upload body is wrapped in a recorder that
keeps the first error the chunk reader returned, because remote clients
wrap a body read failure in their own errors (the AWS SDK's RequestError
has no Unwrap). The recorder forwards ReadAt and Seek, so s3manager keeps
reading parts in place. A 404, 5xx, timeout or any other error from the
remote itself never reaches the recorder and keeps retrying as before.

A rename of an entry that was written back now deletes the old key only
after the new one is written: when the entry's local data is gone, the old
key keeps the last remote copy (logged) instead of being deleted before an
upload that can never succeed. The gateway's rename path, which deletes
first, does not acknowledge errSourceGone and keeps failing visibly.

util/http:
- GetAuthenticated (the encrypted chunk read) reports a 404 as ErrNotFound,
  as the unencrypted read paths already do, with the same error text;
  readEncryptedUrl wraps with %w instead of %v and treats a 404 as
  retryable, like the plain read, so it tries the other locations.
- A chunk read is ErrNotFound only when no location of the pass failed
  differently (NotFoundEverywhere): a 404 from one replica while another is
  down, answers 5xx or is throttled does not mean the chunk is gone. This
  is applied once in hedgedChunkPass (both RetriedFetchChunkData paths) and
  in the manifest's retriedStreamFetchChunkData loop.

Tests:
- filer_remote_sync_gone_test.go: a plain and an encrypted chunk served 404
  by a test volume server end in errSourceGone on the third attempt and are
  counted once; a remote that answers 404 with readable chunks never does;
  the tracker's grace, answer count, reset, fid change and remembered path;
  the lookup-miss grace; ReaderAt kept by the recorder; a rename keeps the
  old key when the entry is gone and deletes it after the write otherwise.
- TestGetAuthenticatedNotFound; TestRetriedFetchChunkDataNotFoundEverywhere
  (plain direct, plain stream, encrypted; a 404 and a 503 in either order
  is not ErrNotFound).
- Mutation checks: each fails with readEncryptedUrl back on %v, with the
  write error classified instead of the body's read error, with
  NotFoundEverywhere dropped from hedgedChunkPass, with the old key deleted
  first, and with the recorder hiding ReadAt.
- go vet and go test of weed/util/http, weed/command, weed/filer and
  weed/replication/... pass; weed/util/http also with -race.

* filer.remote.sync: renames keep the old key until the new one holds the content; gone is per entry; missing volumes opt-in

- A sighting is counted per entry content (the sorted chunk file ids),
  not per failing chunk. An uploader reads the parts of a ReaderAt body in
  parallel, so the chunk that fails first changes between attempts; keyed
  on it, the grace restarted every time and a large file missing several
  chunks held the offset forever. The tracker's `seen` map is bounded, and
  the log names the first chunk "and N more" instead of every fid.
- On every rename the old key is deleted only after the new one holds the
  content: also when the event's old entry carries no stamp (an upload
  whose stamp a rename in between refused leaves an unstamped copy), and
  in the superseded branch, where the old key is what uploadCurrentEntry
  copies a remote-only entry from. uploadCurrentEntry reports when the
  current entry's data is gone, and the old key stays then. A multipart or
  system path whose old key cannot be deleted no longer skips the stamp.
- A volume the master cannot locate counts only with
  -sourceGoneVolumeMissing=<duration> (default 0: never): a volume server
  that is down or in maintenance looks the same, and an entry written off
  is not retried. It suits a deployment whose master and volume server run
  as one process.
- filer.remote.gateway's rename writes the new key first, deletes the old
  object after, and keeps it when the source data is gone.

Tests: TestRetriedWriteFileSourceGoneAcrossChunks (two lost chunks read in
turn), TestSupersededRenameUploadsCurrentEntry "uncached between the check
and the upload" and "current entry's chunks gone: the old key stays",
TestRenameOfGoneEntryKeepsTheOldKey "old entry unstamped",
TestSourceGoneGraceFor (lookup miss off by default, on with the flag);
each fails with its fix undone. The test remote's DeleteFile removes the
object, as a real remote does.

* filer.remote.sync: evidence kinds apart, a gone entry counted once, the copy owns its source's cleanup; gateway keeps the old object on a superseded rename

- Lookup misses and 404s no longer share one run of sightings
  (sightingKey = content + grace): with -sourceGoneVolumeMissing set, a few
  minutes of "failed to locate" followed by one 404 met the 404 grace with
  the misses' start and answers.
- observe reports whether this call found the entry gone; a replayed event
  of an entry already gone is skipped without another log line or count.
- A superseded rename whose current entry is remote-only leaves the old key
  to completeRemoteOnlyRename, which removes its source only while it is
  the object the stamp describes; an unconditional delete after it could
  remove a replacement.
- filer.remote.gateway: a superseded rename keeps the old object (logged)
  instead of deleting it before the superseding event has written the new
  key.

Tests: TestSourceGoneTrackerCountsOnceAndKeepsEvidenceApart,
TestSupersededRenameUploadsCurrentEntry "the old key replaced during the
copy"; each fails with its fix undone. The gateway change has no test of its
own (its rename path needs a reachable filer).

* filer.remote.sync: drop -sourceGoneVolumeMissing, a lookup miss keeps retrying

A volume the master cannot locate looks the same whether it was lost or
its server is down, so no default can write such an entry off safely, and
a flag for the one-process layout is not worth carrying. Only a 404 from
every location counts as gone; a lookup miss retries as before.

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

* filer.remote.gateway: a superseded rename settles its old object

A rename the filer has moved past kept the renamed-from object for good,
so every rename followed by a delete or a rewrite before the gateway
reached it left an orphan on the remote. Settle it the way
filer.remote.sync's uploadCurrentEntry does: copy from it when the entry
has become remote-only, and otherwise delete it, since it no longer holds
the entry's content.

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

* filer.remote.sync, filer.remote.gateway: a superseded rename copied from a later rename's source settles its own old key

When the entry became remote-only through another rename onto it, the copy
reads that rename's source and removes it, and nothing read or removed the
event's own old key any more. Delete it then, in both commands.

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

* filer.remote.gateway: reset cached remote clients after the superseded-rename test

A cached client kept the previous run's recorder, so the test failed under
-count above one.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 14:15:37 -08:00

358 lines
15 KiB
Go

package command
import (
"bytes"
"errors"
"fmt"
"io"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/pb/remote_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
"google.golang.org/protobuf/proto"
)
func withSourceGone(t *testing.T, grace time.Duration, minAnswers int) {
t.Helper()
prevGrace, prevMin, prevWait := sourceGoneGrace, sourceGoneMinAnswers, util.RetryWaitTime
sourceGoneGrace, sourceGoneMinAnswers = grace, minAnswers
// one pass of the chunk fetch's and the upload's backoff loops
util.RetryWaitTime = 1100 * time.Millisecond
sourceGone = newSourceGoneTracker()
sourceGoneCount.Store(0)
t.Cleanup(func() {
sourceGoneGrace, sourceGoneMinAnswers, util.RetryWaitTime = prevGrace, prevMin, prevWait
sourceGone = newSourceGoneTracker()
sourceGoneCount.Store(0)
})
}
// TestRetriedWriteFileSourceGone: an entry the filer still holds whose chunk
// the volume server answers 404 for (a volume lost with its disk) ends in
// errSourceGone once the 404 has held, instead of failing its event forever
// and holding the directory's offset behind it. The encrypted read path
// (GetAuthenticated) must report the 404 as ErrNotFound too: production
// cells encrypt volume data.
func TestRetriedWriteFileSourceGone(t *testing.T) {
const dir = "/buckets/garden--blobs/camera"
for _, tc := range []struct {
name string
chunk *filer_pb.FileChunk
}{
{"plain chunk", &filer_pb.FileChunk{FileId: "79,2cb9d2dd0ea2", ETag: "e1", Size: 100}},
{"encrypted chunk", &filer_pb.FileChunk{FileId: "79,2cb9d2dd0ea2", ETag: "e1", Size: 100, CipherKey: make([]byte, 32)}},
} {
t.Run(tc.name, func(t *testing.T) {
withSourceGone(t, 0, 3)
entry := entryWith("snapshot.jpg", nil, tc.chunk)
entry.Attributes.FileSize = 100
filerClient, done := servingFilerClient(entry, map[string][]byte{}) // the chunk is gone
defer done()
dest := &remote_pb.RemoteStorageLocation{Name: "bunny", Bucket: "cells", Path: "/camera/snapshot.jpg"}
for call := 1; call <= 2; call++ {
_, err := retriedWriteFile(&captureRemote{}, filerClient, dir, entry, dest)
if err == nil || errors.Is(err, errSourceGone) || errors.Is(err, errSuperseded) {
t.Fatalf("call %d: err = %v, want the read failure itself while the 404 is young", call, err)
}
}
_, err := retriedWriteFile(&captureRemote{}, filerClient, dir, entry, dest)
if !errors.Is(err, errSourceGone) {
t.Fatalf("third call: err = %v, want errSourceGone", err)
}
if got := sourceGoneCount.Load(); got != 1 {
t.Errorf("counted %d gone entries, want 1", got)
}
want := fmt.Sprintf("%s/snapshot.jpg (fid 79,2cb9d2dd0ea2)", dir)
if msg := err.Error(); len(msg) < len(want) || msg[:len(want)] != want {
t.Errorf("err = %q, want it to start with %q", msg, want)
}
})
}
}
// TestRetriedWriteFileRemoteNotFoundIsNeverGone: only the source's own chunk
// reads decide. A remote that answers 404 (or anything else) to the upload,
// while the chunks read fine, is retried as before: skipping it would drop
// data that exists.
// TestRetriedWriteFileSourceGoneAcrossChunks: an uploader reads the parts of
// a ReaderAt body in parallel, so which lost chunk fails first changes from
// one attempt to the next. The sightings are of the same content and must
// add up, or a large file missing several chunks holds the offset forever.
func TestRetriedWriteFileSourceGoneAcrossChunks(t *testing.T) {
withSourceGone(t, 0, 3)
entry := entryWith("big.bin", nil,
&filer_pb.FileChunk{FileId: "7,01", ETag: "e1", Offset: 0, Size: 4},
&filer_pb.FileChunk{FileId: "8,02", ETag: "e2", Offset: 4, Size: 4})
entry.Attributes.FileSize = 8
filerClient, done := servingFilerClient(entry, map[string][]byte{}) // both chunks lost
defer done()
dest := &remote_pb.RemoteStorageLocation{Name: "bunny", Bucket: "cells", Path: "/big.bin"}
remote := &partReadingRemote{}
for call := 1; call <= 3; call++ {
_, err := retriedWriteFile(remote, filerClient, "/buckets/b", entry, dest)
if call < 3 && errors.Is(err, errSourceGone) {
t.Fatalf("call %d: gone before three sightings", call)
}
if call == 3 && !errors.Is(err, errSourceGone) {
t.Fatalf("call 3: err = %v, want errSourceGone after three sightings of the same entry", err)
}
}
if len(remote.offsets) < 2 || remote.offsets[0] == remote.offsets[1] {
t.Fatalf("precondition: the attempts read different parts, got offsets %v", remote.offsets)
}
}
// partReadingRemote reads one 4-byte part of the body per write, the next
// part on each call, as parallel part readers do in no fixed order.
type partReadingRemote struct {
recordingRemote
offsets []int64
}
func (r *partReadingRemote) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (*filer_pb.RemoteEntry, error) {
ra, ok := reader.(io.ReaderAt)
if !ok {
return nil, errors.New("body is not a ReaderAt")
}
off := int64(len(r.offsets)%2) * 4
r.offsets = append(r.offsets, off)
if _, err := ra.ReadAt(make([]byte, 4), off); err != nil {
return nil, fmt.Errorf("RequestError: send request failed\ncaused by: %v", err)
}
return r.recordingRemote.WriteFile(loc, entry, reader)
}
func TestRetriedWriteFileRemoteNotFoundIsNeverGone(t *testing.T) {
withSourceGone(t, 0, 1)
const dir = "/buckets/ingest"
entry := entryWith("lease.json", nil, chunk("3,01", "e1"))
filerClient := &stubFilerClient{entry: entryWith(entry.Name, nil, chunk("3,01", "e1"))}
dest := &remote_pb.RemoteStorageLocation{Name: "b2", Bucket: "tier", Path: "/lease.json"}
remoteErr := fmt.Errorf("https://s3.example.com/tier/lease.json: 404 Not Found: %w", util_http.ErrNotFound)
for call := 1; call <= 3; call++ {
_, err := retriedWriteFile(&failingRemote{err: remoteErr}, filerClient, dir, entry, dest)
if err == nil || errors.Is(err, errSourceGone) {
t.Fatalf("call %d: err = %v, want the remote's failure, never errSourceGone", call, err)
}
}
if got := sourceGoneCount.Load(); got != 0 {
t.Errorf("counted %d gone entries, want 0", got)
}
}
// TestSourceGoneTrackerGrace: a sighting counts as gone only after both the
// grace and the answer count, for the same chunk, with nothing else in
// between; a gone path is then skipped at once until something else happens.
func TestSourceGoneTrackerGrace(t *testing.T) {
withSourceGone(t, 5*time.Minute, 3)
t0 := time.Unix(1_800_000_000, 0)
tr := newSourceGoneTracker()
observe := func(path, key string, at time.Time) bool {
gone, _ := tr.observe(path, key, at)
return gone
}
if observe("/a", "1,01", t0) || observe("/a", "1,01", t0.Add(time.Minute)) || observe("/a", "1,01", t0.Add(2*time.Minute)) {
t.Fatal("gone before the grace ended")
}
if !observe("/a", "1,01", t0.Add(5*time.Minute)) {
t.Fatal("not gone after the grace and three answers")
}
// a later event of the same gone entry is skipped at once
if !observe("/a", "1,01", t0.Add(6*time.Minute)) {
t.Fatal("a known-gone entry waits for another grace")
}
// written back or failed otherwise since: the grace starts again
tr.forget("/a")
if observe("/a", "1,01", t0.Add(7*time.Minute)) {
t.Fatal("gone on the first answer after forget")
}
// an unknown path never matches the empty fid of a chunkless entry
if observe("/c", "", t0) {
t.Fatal("a first sighting with an empty fid counted as gone")
}
// many answers inside the grace are not enough
for i := 0; i < 10; i++ {
if observe("/b", "1,02", t0.Add(time.Duration(i)*time.Second)) {
t.Fatalf("answer %d: gone inside the grace", i)
}
}
tr.forget("/b")
if observe("/b", "1,02", t0.Add(6*time.Minute)) || observe("/b", "1,02", t0.Add(7*time.Minute)) || observe("/b", "1,02", t0.Add(8*time.Minute)) {
t.Fatal("gone without a full grace after forget")
}
// another chunk of the same path starts again too
if observe("/b", "1,03", t0.Add(20*time.Minute)) {
t.Fatal("gone on a new chunk's first answer")
}
}
// TestSourceGoneTrackerCountsOnce: a path is new-gone once; replayed events
// of it are skipped without another log line or count.
func TestSourceGoneTrackerCountsOnce(t *testing.T) {
withSourceGone(t, 5*time.Minute, 3)
t0 := time.Unix(1_800_000_000, 0)
entry := entryWith("x.jpg", nil, chunk("79,01", "e1"))
tr := newSourceGoneTracker()
key := chunkSetKey(entry)
for i, at := range []time.Duration{0, time.Minute, 5 * time.Minute} {
gone, isNew := tr.observe("/x", key, t0.Add(at))
if want := i == 2; gone != want || isNew != want {
t.Fatalf("answer %d: gone=%v new=%v, want %v %v", i, gone, isNew, want, want)
}
}
if gone, isNew := tr.observe("/x", key, t0.Add(6*time.Minute)); !gone || isNew {
t.Errorf("a replay of a gone path: gone=%v new=%v, want gone and not new", gone, isNew)
}
}
// TestIsSourceGone: only a 404 from every location of a chunk is a sighting.
func TestIsSourceGone(t *testing.T) {
for _, tc := range []struct {
err error
want bool
}{
{fmt.Errorf("http://v:8080/79,2cb9: 404 Not Found: %w", util_http.ErrNotFound), true},
// a volume the master cannot locate: a volume server that is down
// looks the same
{errors.New("failed to locate 79,2cb9d2dd0ea2"), false},
// a 404 on one replica while another failed otherwise
{util_http.NotFoundEverywhere(fmt.Errorf("a: %w", util_http.ErrNotFound), errors.New("b: 503 Service Unavailable")), false},
{errors.New("http://v:8080/79,2cb9: 500 Internal Server Error"), false},
{errors.New("read tcp: connection reset by peer"), false},
{nil, false},
} {
if got := isSourceGone(tc.err); got != tc.want {
t.Errorf("isSourceGone(%v) = %v, want %v", tc.err, got, tc.want)
}
}
}
// TestSourceReadRecorderKeepsReaderAt: the recorder must not hide a
// ReaderAt + Seeker body, or an S3 uploader buffers every part in memory.
func TestSourceReadRecorderKeepsReaderAt(t *testing.T) {
body, rec := newSourceReadRecorder(io.NewSectionReader(goneChunkReaderAt{}, 0, 10))
ra, okAt := body.(io.ReaderAt)
_, okSeek := body.(io.Seeker)
if !okAt || !okSeek {
t.Fatalf("body %T: ReaderAt %v, Seeker %v; want both", body, okAt, okSeek)
}
if _, err := ra.ReadAt(make([]byte, 4), 0); err == nil {
t.Fatal("ReadAt succeeded")
}
if !errors.Is(rec.readErr(), util_http.ErrNotFound) {
t.Errorf("recorded %v, want the ReadAt failure", rec.readErr())
}
if _, ok := mustReader(newSourceReadRecorder(bytes.NewBufferString("x"))).(io.ReaderAt); ok {
t.Error("a plain reader gained ReadAt")
}
}
type goneChunkReaderAt struct{}
func (goneChunkReaderAt) ReadAt([]byte, int64) (int, error) {
return 0, fmt.Errorf("http://v:8080/79,2cb9: 404 Not Found: %w", util_http.ErrNotFound)
}
func mustReader(r io.Reader, _ *sourceReadRecorder) io.Reader { return r }
// bodyReadingRemote reads the upload body before recording the write, as a
// real remote does; a body read failure fails the write.
type bodyReadingRemote struct{ *recordingRemote }
func (r bodyReadingRemote) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (*filer_pb.RemoteEntry, error) {
if _, err := io.ReadAll(reader); err != nil {
return nil, fmt.Errorf("RequestError: send request failed\ncaused by: %v", err)
}
return r.recordingRemote.WriteFile(loc, entry, reader)
}
// TestRenameOfGoneEntryKeepsTheOldKey: a written-back entry renamed after its
// local chunks were lost still has its content under the old key. The event
// is acknowledged as gone, and the old key is not deleted: it is the only
// copy left. With the chunks present, the old key goes once the new one is
// written.
func TestRenameOfGoneEntryKeepsTheOldKey(t *testing.T) {
const mountedDir = "/buckets"
mountLoc := &remote_pb.RemoteStorageLocation{Name: "bunny", Bucket: "cells", Path: "/"}
oldKey := &remote_pb.RemoteStorageLocation{Name: "bunny", Bucket: "cells", Path: "/b/src/photo.jpg"}
newKey := &remote_pb.RemoteStorageLocation{Name: "bunny", Bucket: "cells", Path: "/b/dst/photo.jpg"}
event := func(stamped bool) (*filer_pb.Entry, *filer_pb.SubscribeMetadataResponse) {
newEntry := entryWith("photo.jpg", nil, &filer_pb.FileChunk{FileId: "79,2cb9d2dd0ea2", ETag: "e1", Size: 4})
newEntry.Attributes.FileSize = 4
var stamp *filer_pb.RemoteEntry
if stamped {
stamp = &filer_pb.RemoteEntry{StorageName: "bunny", RemoteETag: "etag", RemoteSize: 4, RemoteMtime: 1786096669}
}
oldEntry := entryWith("photo.jpg", stamp, &filer_pb.FileChunk{FileId: "79,2cb9d2dd0ea2", ETag: "e1", Size: 4})
return newEntry, &filer_pb.SubscribeMetadataResponse{
Directory: "/buckets/b/src",
EventNotification: &filer_pb.EventNotification{
OldEntry: oldEntry,
NewParentPath: "/buckets/b/dst",
NewEntry: newEntry,
},
}
}
t.Run("chunks gone", func(t *testing.T) {
withSourceGone(t, 0, 1)
newEntry, resp := event(true)
filerClient, done := servingFilerClient(newEntry, map[string][]byte{})
defer done()
remote := bodyReadingRemote{&recordingRemote{}}
if err := processUpdateEvent(filerClient, filerClient, "", remote, mountedDir, mountLoc, resp); err != nil {
t.Fatalf("err = %v, want nil: the gone entry is acknowledged", err)
}
if len(remote.deletes) != 0 {
t.Errorf("deleted %+v; the old key holds the only copy", remote.deletes)
}
if len(remote.writes) != 0 {
t.Errorf("wrote %+v, want nothing", remote.writes)
}
if got := sourceGoneCount.Load(); got != 1 {
t.Errorf("counted %d gone entries, want 1", got)
}
})
t.Run("chunks gone, old entry unstamped", func(t *testing.T) {
// the upload's stamp was refused by the rename in between: the old
// key still holds the only copy
withSourceGone(t, 0, 1)
newEntry, resp := event(false)
filerClient, done := servingFilerClient(newEntry, map[string][]byte{})
defer done()
remote := bodyReadingRemote{&recordingRemote{}}
if err := processUpdateEvent(filerClient, filerClient, "", remote, mountedDir, mountLoc, resp); err != nil {
t.Fatalf("err = %v, want nil: the gone entry is acknowledged", err)
}
if len(remote.deletes) != 0 {
t.Errorf("deletes = %+v; the old key holds the only copy", remote.deletes)
}
})
t.Run("chunks present", func(t *testing.T) {
withSourceGone(t, 0, 1)
newEntry, resp := event(true)
filerClient, done := servingFilerClient(newEntry, map[string][]byte{"79,2cb9d2dd0ea2": []byte("jpeg")})
defer done()
remote := bodyReadingRemote{&recordingRemote{}}
if err := processUpdateEvent(filerClient, filerClient, "", remote, mountedDir, mountLoc, resp); err != nil {
t.Fatalf("err = %v", err)
}
if len(remote.writes) != 1 || !proto.Equal(remote.writes[0], newKey) {
t.Errorf("writes = %+v, want the new key", remote.writes)
}
if len(remote.deletes) != 1 || !proto.Equal(remote.deletes[0], oldKey) {
t.Errorf("deletes = %+v, want the old key once the new one is written", remote.deletes)
}
})
}