filer: draw the remote cache commit's fence after its re-read

The re-read can import the object from the remote and log that event; an
entry changed during the download is returned with this fence, which has to
cover the import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 14:57:06 -08:00
1 parent d4f529fcdb
commit 76b683b5bc
2 files changed
+58 -6

No files matched your search

+3 -1
View File
@@ -326,8 +326,10 @@ func (fs *FilerServer) doCacheRemoteObjectToLocalCluster(ctx context.Context, re
commitLock := fs.entryLockTable.AcquireLock("CacheRemoteObjectToLocalCluster", lockPath, util.ExclusiveLock)
defer fs.entryLockTable.ReleaseLock(lockPath, commitLock)
commitLogTsNs := fs.filer.LogFenceTsNs()
current, err := fs.filer.FindEntry(ctx, lockPath)
// After the re-read, which can import the object from the remote and log
// that event itself.
commitLogTsNs := fs.filer.LogFenceTsNs()
if err != nil {
fs.filer.DeleteUncommittedChunks(ctx, chunks)
if err == filer_pb.ErrNotFound {
@@ -45,10 +45,10 @@ func (remoteCacheVolume) FetchAndWriteNeedle(context.Context, *volume_server_pb.
return &volume_server_pb.FetchAndWriteNeedleResponse{ETag: "etag"}, nil
}
// With the wall clock behind the log, caching a remote object fences its
// commit above the log floor and below the commit's own event.
func TestCacheRemoteObjectLogTsNsAcrossClockStep(t *testing.T) {
fs, store, _ := newRemoteMountTestServer(t)
// startRemoteCacheCluster points fs at a fake master that assigns every chunk
// to volume.
func startRemoteCacheCluster(t *testing.T, fs *FilerServer, volume volume_server_pb.VolumeServerServer) {
t.Helper()
dialOption := grpc.WithTransportCredentials(insecure.NewCredentials())
fs.grpcDialOption = dialOption
@@ -57,7 +57,7 @@ func TestCacheRemoteObjectLogTsNsAcrossClockStep(t *testing.T) {
port := lis.Addr().(*net.TCPAddr).Port
volumeAddr := pb.NewServerAddressWithGrpcPort(lis.Addr().String(), port)
volumeServer := grpc.NewServer()
volume_server_pb.RegisterVolumeServerServer(volumeServer, remoteCacheVolume{})
volume_server_pb.RegisterVolumeServerServer(volumeServer, volume)
go volumeServer.Serve(lis)
t.Cleanup(volumeServer.Stop)
@@ -72,6 +72,13 @@ func TestCacheRemoteObjectLogTsNsAcrossClockStep(t *testing.T) {
waitCtx, cancelWait := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelWait()
require.NotEmpty(t, fs.filer.MasterClient.GetMaster(waitCtx), "fake master did not become available")
}
// With the wall clock behind the log, caching a remote object fences its
// commit above the log floor and below the commit's own event.
func TestCacheRemoteObjectLogTsNsAcrossClockStep(t *testing.T) {
fs, store, _ := newRemoteMountTestServer(t)
startRemoteCacheCluster(t, fs, remoteCacheVolume{})
obj := remoteOnlyFileEntry("/buckets/b/obj.bin")
store.entries[string(obj.FullPath)] = obj
@@ -118,3 +125,46 @@ func TestLookupFenceCoversRemoteImport(t *testing.T) {
require.Greater(t, delivered, before, "import logged no event")
require.GreaterOrEqual(t, resp.LogTsNs, delivered, "lookup fence below the import event it reflects")
}
// remoteCacheVolumeHook runs onFetch while the remote object downloads.
type remoteCacheVolumeHook struct {
remoteCacheVolume
onFetch func()
}
func (v remoteCacheVolumeHook) FetchAndWriteNeedle(ctx context.Context, req *volume_server_pb.FetchAndWriteNeedleRequest) (*volume_server_pb.FetchAndWriteNeedleResponse, error) {
v.onFetch()
return v.remoteCacheVolume.FetchAndWriteNeedle(ctx, req)
}
// An entry that leaves the store during the download is imported again by the
// commit's re-read; the fence returned with that entry must cover the import.
func TestCacheRemoteObjectFenceCoversReimport(t *testing.T) {
fs, store, _ := newRemoteMountTestServer(t)
for _, dir := range []string{"/buckets", "/buckets/b"} {
entry := newFileEntry(dir, 1)
entry.Attr.Mode = os.ModeDir | 0o755
store.entries[dir] = entry
}
obj := remoteOnlyFileEntry("/buckets/b/obj.bin")
store.entries[string(obj.FullPath)] = obj
fs.filer.BuildGuardedRemoteClient = func(context.Context, *remote_pb.RemoteConf, bool) (remote_storage.RemoteStorageClient, error) {
return remoteStatClient{}, nil
}
startRemoteCacheCluster(t, fs, remoteCacheVolumeHook{onFetch: func() {
store.mu.Lock()
delete(store.entries, string(obj.FullPath))
store.mu.Unlock()
}})
before := fs.filer.LocalMetaLogBuffer.LastTsNs.Load()
resp, err := fs.CacheRemoteObjectToLocalCluster(context.Background(), &filer_pb.CacheRemoteObjectToLocalClusterRequest{
Directory: "/buckets/b", Name: "obj.bin",
})
require.NoError(t, err)
require.Nil(t, resp.MetadataEvent, "re-imported entry was committed over")
require.Empty(t, resp.GetEntry().GetChunks(), "re-imported entry was cached")
delivered := fs.filer.LocalMetaLogBuffer.LastTsNs.Load()
require.Greater(t, delivered, before, "re-import logged no event")
require.GreaterOrEqual(t, resp.LogTsNs, delivered, "fence below the re-import event it reflects")
}