mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-08 15:41:15 +02:00
* rust volume: stop a VolumeCopy whose caller has gone VolumeCopy runs its copy in a detached tokio::spawn and reports progress with the send error discarded, so nothing observes the client leaving. When the caller cancels the RPC -- which weed-admin's batch balance does routinely, starting far more copies than it finishes -- the server streamed the whole volume from the source, wrote it to disk, and mounted it. The destination is then left holding a volume nobody took delivery of: its index cache is never reclaimed, and under replication=000 one volume id ends up on two servers, both writable, which concurrent writes can diverge. Three checks now reach the task: - Every chunk in copy_file_from_source, via the sender's is_closed(). This is the one that matters in practice. The first progress report is 128MB in, so for a smaller volume -- the ordinary balance move -- no send ever happens and its result says nothing; only the closed channel does. The sender is passed for the .idx and .vif copies too, with reporting gated separately, so those phases notice as well. - The throttle sleep, which for a throttled copy runs for seconds at a time, now races the sender's closed() instead of being slept through. - Immediately before mount_volume, and once at the top of the task. Cancellation surfaces as an ordinary Err(Status::cancelled), so it lands in the existing error branch that already removes the partial .dat/.idx/ .vif and the .note. That branch also logs now: the error otherwise went to a channel nobody was reading, leaving the operator with the balancer's "delete that copy, then re-run the move" and no cause. This also clears the stranded read-only sources reported on the issue. They are downstream of the orphan mount, not a separate defect: LiveMoveVolume's cleanup probes the target before undoing the freeze (volume_move.go:95, "the server can finish the copy and mount the target even when the client loses the stream"), and when it finds a mounted copy it cannot attribute, or cannot delete, it deliberately keeps the source readonly rather than risk two writable replicas -- the messages at volume_move.go:110 and :123. With nothing mounted on the target the probe reports clean and the freeze is undone. On Go parity: the progress send result is honoured here too, matching `return false` in volume_grpc_copy.go. But that report is Go's only abort signal, and measured against a 120MiB volume -- above the throttler's activation threshold, below the 128MiB report interval -- a Go destination mounts an abandoned copy as well. The issue's premise that Go aborts holds only above the report interval. The Rust side now stops in both cases; the Go behaviour is worth its own issue. Tests: the integration test runs against both implementations and is green on Go, red on Rust before this change. Its 192MiB fixture is sized for two separate constraints, documented at the fixture: IoBytePerSecond is a no-op below ~100ms of wall clock (64MiB copies in ~110ms on a tmpfs loopback cluster), and the payload must exceed the 128MiB report interval for the Go leg to pass at all. The two Rust unit tests cover what the integration test cannot reach: cancellation detected with no progress report at all, and the cleanup of the partial files plus the .note. Fixes #11186 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0122W3eqt6gmLUMxmRoZdPAb * rust volume: surface VolumeCopy cancellation as Status::cancelled copy_file_from_source returned Result<_, String>, so the per-chunk cancellation path -- the one that matters in practice for volumes below the 128MB report interval -- was wrapped to Status::internal at the call sites. The spawn logging branch then classified it as a generic failure instead of the intended "abandoned by caller", defeating the logging change in the same PR for the case that occurs most often. Return Result<_, Status> from copy_file_from_source: Status::cancelled for caller-gone, Status::internal for the existing errors. Drop the .map_err(|e| Status::internal(e)) at the three call sites. The unit test now asserts the code is Cancelled, not just the message text, so the classification is locked in. * rust volume: close cancellation gaps in VolumeCopy Address two review findings on the same PR: 1. Roll back a mount that races a departing caller. The pre-mount is_closed() check cannot close the window between the check and mount_volume: if the receiver drops in that gap, the volume mounts and the final tx.send(Ok(...)) fails, but its error was discarded (let _ =), so the task returned Ok(()) and the error branch never ran. The destination then held an orphaned mounted replica — the exact defect this PR prevents. Fix: track a mounted flag. The final send now checks its result; on failure it returns Status::cancelled, and the error branch calls store.delete_volume (which unmounts AND removes the files) when mounted is true, instead of only unlinking. 2. Observe cancellation while awaiting the source stream. The per-chunk is_closed() check only runs after stream.message().await returns. A stalled source (slow disk, partition, GC pause) never delivers a chunk, so a caller that has already left cannot preempt the read: the task, the source connection, and the partial files (including the .note) all outlive the caller indefinitely. Fix: race stream.message() against progress_tx.closed() in a tokio::select!, so a departing caller preempts a stalled source. Adds test_volume_copy_after_mount_cancellation_rolls_back_mount to cover the after-mount rollback path. cargo test --release green (497 + 5 + 1 + 28). * rust volume: keep remote data on after-mount rollback, race RPC startup Two review findings on the after-mount rollback added inff51f6a: 1. The rollback called delete_volume(vid, false, false), i.e. keep_remote_data=false. A remote-tier copy .vif points at the same cloud object the source replica references, so destroying the abandoned destination with keep_remote_data=false deletes the source remote data via Volume::destroy backend.delete_file_blocking. Use keep_remote_data=true, matching the pre-spawn delete_volume at the top of volume_copy. 2. client.copy_file(copy_req).await (the initial RPC establishment) was not raced against progress_tx.closed(). If the source stalls before sending response headers, the per-message select! added inff51f6ais never reached, and the task, source connection, and preallocated files outlive a departed caller. Race the RPC establishment against progress_tx.closed() the same way. cargo test --release green (497 + 5 + 1 + 28). * rust volume: race master-configuration wait against caller cancellation try_get_master_configuration().await was the last un-raced await in the VolumeCopy task before copy_file_from_source. A stalled master (or slow leader election) would hold the task and its .note past a departing caller, since the per-chunk cancellation checks are never reached. Race it against tx.closed() the same way the source stream reads already are. cargo test --release green (497 + 5 + 1 + 28). * rust volume: fix after-mount rollback test to actually reach that path The previous version of test_volume_copy_after_mount_cancellation_rolls_back_mount dropped the response immediately after volume_copy returned, so tx.is_closed() was already true at the spawn first check and the task returned before mount_volume. The test was green for the wrong reason: the mounted flag, the rollback, and the keep_remote_data=true line were all uncovered. Use the store write lock as a seam: take it immediately after volume_copy returns so the task runs the copy to completion with the caller still attached, passes the pre-mount is_closed() check, then parks entering the mount block. Drop the response (caller gone) and release the guard: the task mounts, fails the final tx.send, and must roll back via delete_volume. Verified by setting the rollback guard to if false: the test fails with "destination still holds a mounted volume". With the rollback enabled, probe eprintlns confirmed the full path: about to mount -> mounted = true -> final send failed -> rolling back mount -> rollback done. cargo test --release green (497 + 5 + 1 + 28). --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Chris Lu <chris.lu@gmail.com>
396 lines
15 KiB
Go
396 lines
15 KiB
Go
package volume_server_grpc_test
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"math/rand"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/test/volume_server/framework"
|
|
"github.com/seaweedfs/seaweedfs/test/volume_server/matrix"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
)
|
|
|
|
func TestVolumeSyncStatusAndReadVolumeFileStatus(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test in short mode")
|
|
}
|
|
|
|
clusterHarness := framework.StartVolumeCluster(t, matrix.P1())
|
|
conn, grpcClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress())
|
|
defer conn.Close()
|
|
|
|
httpClient := framework.NewHTTPClient()
|
|
const volumeID = uint32(41)
|
|
framework.AllocateVolume(t, grpcClient, volumeID, "")
|
|
fid := framework.NewFileID(volumeID, 1, 0x11112222)
|
|
uploadResp := framework.UploadBytes(t, httpClient, clusterHarness.VolumeAdminURL(), fid, []byte("sync-status-payload"))
|
|
_ = framework.ReadAllAndClose(t, uploadResp)
|
|
if uploadResp.StatusCode != http.StatusCreated {
|
|
t.Fatalf("upload expected 201, got %d", uploadResp.StatusCode)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
syncResp, err := grpcClient.VolumeSyncStatus(ctx, &volume_server_pb.VolumeSyncStatusRequest{VolumeId: volumeID})
|
|
if err != nil {
|
|
t.Fatalf("VolumeSyncStatus failed: %v", err)
|
|
}
|
|
if syncResp.GetVolumeId() != volumeID {
|
|
t.Fatalf("VolumeSyncStatus volume id mismatch: got %d want %d", syncResp.GetVolumeId(), volumeID)
|
|
}
|
|
|
|
statusResp, err := grpcClient.ReadVolumeFileStatus(ctx, &volume_server_pb.ReadVolumeFileStatusRequest{VolumeId: volumeID})
|
|
if err != nil {
|
|
t.Fatalf("ReadVolumeFileStatus failed: %v", err)
|
|
}
|
|
if statusResp.GetVolumeId() != volumeID {
|
|
t.Fatalf("ReadVolumeFileStatus volume id mismatch: got %d want %d", statusResp.GetVolumeId(), volumeID)
|
|
}
|
|
if statusResp.GetVersion() == 0 {
|
|
t.Fatalf("ReadVolumeFileStatus expected non-zero version")
|
|
}
|
|
if syncResp.GetTailOffset() == 0 {
|
|
t.Fatalf("VolumeSyncStatus expected non-zero tail offset after upload")
|
|
}
|
|
if syncResp.GetTailOffset() != statusResp.GetDatFileSize() {
|
|
t.Fatalf("VolumeSyncStatus tail offset mismatch: got %d want %d", syncResp.GetTailOffset(), statusResp.GetDatFileSize())
|
|
}
|
|
}
|
|
|
|
func TestCopyAndStreamMethodsMissingVolumePaths(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test in short mode")
|
|
}
|
|
|
|
clusterHarness := framework.StartVolumeCluster(t, matrix.P1())
|
|
conn, grpcClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress())
|
|
defer conn.Close()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
_, err := grpcClient.VolumeSyncStatus(ctx, &volume_server_pb.VolumeSyncStatusRequest{VolumeId: 98761})
|
|
if err == nil {
|
|
t.Fatalf("VolumeSyncStatus should fail for missing volume")
|
|
}
|
|
|
|
incrementalStream, err := grpcClient.VolumeIncrementalCopy(ctx, &volume_server_pb.VolumeIncrementalCopyRequest{VolumeId: 98762, SinceNs: 0})
|
|
if err == nil {
|
|
_, err = incrementalStream.Recv()
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "not found volume") {
|
|
t.Fatalf("VolumeIncrementalCopy missing-volume error mismatch: %v", err)
|
|
}
|
|
|
|
readAllStream, err := grpcClient.ReadAllNeedles(ctx, &volume_server_pb.ReadAllNeedlesRequest{VolumeIds: []uint32{98763}})
|
|
if err == nil {
|
|
_, err = readAllStream.Recv()
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "not found volume") {
|
|
t.Fatalf("ReadAllNeedles missing-volume error mismatch: %v", err)
|
|
}
|
|
|
|
copyFileStream, err := grpcClient.CopyFile(ctx, &volume_server_pb.CopyFileRequest{VolumeId: 98764, Ext: ".dat", StopOffset: 1})
|
|
if err == nil {
|
|
_, err = copyFileStream.Recv()
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "not found volume") {
|
|
t.Fatalf("CopyFile missing-volume error mismatch: %v", err)
|
|
}
|
|
|
|
_, err = grpcClient.ReadVolumeFileStatus(ctx, &volume_server_pb.ReadVolumeFileStatusRequest{VolumeId: 98765})
|
|
if err == nil || !strings.Contains(err.Error(), "not found volume") {
|
|
t.Fatalf("ReadVolumeFileStatus missing-volume error mismatch: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestVolumeCopyAndReceiveFileMaintenanceRejection(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test in short mode")
|
|
}
|
|
|
|
clusterHarness := framework.StartVolumeCluster(t, matrix.P1())
|
|
conn, grpcClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress())
|
|
defer conn.Close()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
stateResp, err := grpcClient.GetState(ctx, &volume_server_pb.GetStateRequest{})
|
|
if err != nil {
|
|
t.Fatalf("GetState failed: %v", err)
|
|
}
|
|
_, err = grpcClient.SetState(ctx, &volume_server_pb.SetStateRequest{
|
|
State: &volume_server_pb.VolumeServerState{Maintenance: true, Version: stateResp.GetState().GetVersion()},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("SetState maintenance=true failed: %v", err)
|
|
}
|
|
|
|
copyStream, err := grpcClient.VolumeCopy(ctx, &volume_server_pb.VolumeCopyRequest{VolumeId: 1, SourceDataNode: "127.0.0.1:1234"})
|
|
if err == nil {
|
|
_, err = copyStream.Recv()
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "maintenance mode") {
|
|
t.Fatalf("VolumeCopy maintenance error mismatch: %v", err)
|
|
}
|
|
|
|
receiveClient, err := grpcClient.ReceiveFile(ctx)
|
|
if err != nil {
|
|
t.Fatalf("ReceiveFile client creation failed: %v", err)
|
|
}
|
|
_ = receiveClient.Send(&volume_server_pb.ReceiveFileRequest{
|
|
Data: &volume_server_pb.ReceiveFileRequest_Info{
|
|
Info: &volume_server_pb.ReceiveFileInfo{VolumeId: 1, Ext: ".dat"},
|
|
},
|
|
})
|
|
_, err = receiveClient.CloseAndRecv()
|
|
if err == nil || !strings.Contains(err.Error(), "maintenance mode") {
|
|
t.Fatalf("ReceiveFile maintenance error mismatch: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestVolumeCopySuccessFromPeerAndMountsDestination(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test in short mode")
|
|
}
|
|
|
|
clusterHarness := framework.StartDualVolumeCluster(t, matrix.P1())
|
|
sourceConn, sourceClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress(0))
|
|
defer sourceConn.Close()
|
|
destConn, destClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress(1))
|
|
defer destConn.Close()
|
|
|
|
const volumeID = uint32(42)
|
|
framework.AllocateVolume(t, sourceClient, volumeID, "")
|
|
|
|
httpClient := framework.NewHTTPClient()
|
|
fid := framework.NewFileID(volumeID, 880001, 0x12345678)
|
|
payload := []byte("volume-copy-success-payload")
|
|
uploadResp := framework.UploadBytes(t, httpClient, clusterHarness.VolumeAdminURL(0), fid, payload)
|
|
_ = framework.ReadAllAndClose(t, uploadResp)
|
|
if uploadResp.StatusCode != http.StatusCreated {
|
|
t.Fatalf("upload to source expected 201, got %d", uploadResp.StatusCode)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
copyStream, err := destClient.VolumeCopy(ctx, &volume_server_pb.VolumeCopyRequest{
|
|
VolumeId: volumeID,
|
|
Collection: "",
|
|
SourceDataNode: clusterHarness.VolumeAdminAddress(0) + "." + strings.Split(clusterHarness.VolumeGRPCAddress(0), ":")[1],
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("VolumeCopy start failed: %v", err)
|
|
}
|
|
|
|
sawFinalAppendTimestamp := false
|
|
for {
|
|
msg, recvErr := copyStream.Recv()
|
|
if recvErr == io.EOF {
|
|
break
|
|
}
|
|
if recvErr != nil {
|
|
t.Fatalf("VolumeCopy recv failed: %v", recvErr)
|
|
}
|
|
if msg.GetLastAppendAtNs() > 0 {
|
|
sawFinalAppendTimestamp = true
|
|
}
|
|
}
|
|
if !sawFinalAppendTimestamp {
|
|
t.Fatalf("VolumeCopy expected final response with last_append_at_ns")
|
|
}
|
|
|
|
destReadResp := framework.ReadBytes(t, httpClient, clusterHarness.VolumeAdminURL(1), fid)
|
|
destReadBody := framework.ReadAllAndClose(t, destReadResp)
|
|
if destReadResp.StatusCode != http.StatusOK {
|
|
t.Fatalf("read from copied destination expected 200, got %d", destReadResp.StatusCode)
|
|
}
|
|
if string(destReadBody) != string(payload) {
|
|
t.Fatalf("destination copied payload mismatch: got %q want %q", string(destReadBody), string(payload))
|
|
}
|
|
}
|
|
|
|
func TestVolumeCopyOverwritesExistingDestinationVolume(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test in short mode")
|
|
}
|
|
|
|
clusterHarness := framework.StartDualVolumeCluster(t, matrix.P1())
|
|
sourceConn, sourceClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress(0))
|
|
defer sourceConn.Close()
|
|
destConn, destClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress(1))
|
|
defer destConn.Close()
|
|
|
|
const volumeID = uint32(43)
|
|
framework.AllocateVolume(t, sourceClient, volumeID, "")
|
|
framework.AllocateVolume(t, destClient, volumeID, "")
|
|
|
|
httpClient := framework.NewHTTPClient()
|
|
fid := framework.NewFileID(volumeID, 880002, 0x23456789)
|
|
sourcePayload := []byte("volume-copy-overwrite-source")
|
|
destPayload := []byte("volume-copy-overwrite-destination-old")
|
|
|
|
sourceUploadResp := framework.UploadBytes(t, httpClient, clusterHarness.VolumeAdminURL(0), fid, sourcePayload)
|
|
_ = framework.ReadAllAndClose(t, sourceUploadResp)
|
|
if sourceUploadResp.StatusCode != http.StatusCreated {
|
|
t.Fatalf("upload to source expected 201, got %d", sourceUploadResp.StatusCode)
|
|
}
|
|
|
|
destUploadResp := framework.UploadBytes(t, httpClient, clusterHarness.VolumeAdminURL(1), fid, destPayload)
|
|
_ = framework.ReadAllAndClose(t, destUploadResp)
|
|
if destUploadResp.StatusCode != http.StatusCreated {
|
|
t.Fatalf("upload to destination expected 201, got %d", destUploadResp.StatusCode)
|
|
}
|
|
|
|
destReadBeforeResp := framework.ReadBytes(t, httpClient, clusterHarness.VolumeAdminURL(1), fid)
|
|
destReadBeforeBody := framework.ReadAllAndClose(t, destReadBeforeResp)
|
|
if destReadBeforeResp.StatusCode != http.StatusOK {
|
|
t.Fatalf("destination pre-copy read expected 200, got %d", destReadBeforeResp.StatusCode)
|
|
}
|
|
if string(destReadBeforeBody) != string(destPayload) {
|
|
t.Fatalf("destination pre-copy payload mismatch: got %q want %q", string(destReadBeforeBody), string(destPayload))
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
copyStream, err := destClient.VolumeCopy(ctx, &volume_server_pb.VolumeCopyRequest{
|
|
VolumeId: volumeID,
|
|
Collection: "",
|
|
SourceDataNode: clusterHarness.VolumeAdminAddress(0) + "." + strings.Split(clusterHarness.VolumeGRPCAddress(0), ":")[1],
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("VolumeCopy overwrite start failed: %v", err)
|
|
}
|
|
|
|
sawFinalAppendTimestamp := false
|
|
for {
|
|
msg, recvErr := copyStream.Recv()
|
|
if recvErr == io.EOF {
|
|
break
|
|
}
|
|
if recvErr != nil {
|
|
t.Fatalf("VolumeCopy overwrite recv failed: %v", recvErr)
|
|
}
|
|
if msg.GetLastAppendAtNs() > 0 {
|
|
sawFinalAppendTimestamp = true
|
|
}
|
|
}
|
|
if !sawFinalAppendTimestamp {
|
|
t.Fatalf("VolumeCopy overwrite expected final response with last_append_at_ns")
|
|
}
|
|
|
|
destReadAfterResp := framework.ReadBytes(t, httpClient, clusterHarness.VolumeAdminURL(1), fid)
|
|
destReadAfterBody := framework.ReadAllAndClose(t, destReadAfterResp)
|
|
if destReadAfterResp.StatusCode != http.StatusOK {
|
|
t.Fatalf("destination post-copy read expected 200, got %d", destReadAfterResp.StatusCode)
|
|
}
|
|
if string(destReadAfterBody) != string(sourcePayload) {
|
|
t.Fatalf("destination post-copy payload mismatch: got %q want %q", string(destReadAfterBody), string(sourcePayload))
|
|
}
|
|
}
|
|
|
|
// A VolumeCopy whose caller goes away must not leave a mounted volume behind on
|
|
// the destination. weed-admin's batch balance routinely starts far more copies
|
|
// than it finishes, and each abandoned copy that still mounts costs the
|
|
// destination a volume it was never asked to hold: a per-volume index cache that
|
|
// is never reclaimed, and — under replication=000 — a second writable copy of a
|
|
// volume id that two writers can diverge.
|
|
//
|
|
// The copy is throttled so it is demonstrably still in flight when the caller
|
|
// cancels; the assertion before the cancel keeps the test from passing
|
|
// vacuously if the throttle ever stops biting.
|
|
func TestVolumeCopyCancelledByCallerDoesNotMountDestination(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test in short mode")
|
|
}
|
|
|
|
clusterHarness := framework.StartDualVolumeCluster(t, matrix.P1())
|
|
sourceConn, sourceClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress(0))
|
|
defer sourceConn.Close()
|
|
destConn, destClient := framework.DialVolumeServer(t, clusterHarness.VolumeGRPCAddress(1))
|
|
defer destConn.Close()
|
|
|
|
const volumeID = uint32(44)
|
|
const payloadMiB = 192
|
|
framework.AllocateVolume(t, sourceClient, volumeID, "")
|
|
|
|
// The fixture size is load-bearing twice over; do not shrink it to save CI
|
|
// time without reading both reasons.
|
|
//
|
|
// First, the copy has to still be running when the caller cancels, and the
|
|
// only lever for that is IoBytePerSecond. It is a no-op below ~100ms of wall
|
|
// clock — the throttler never re-checks within its first window — and on a
|
|
// tmpfs loopback cluster 64 MiB copies in ~110ms.
|
|
//
|
|
// Second, 192 MiB is above the 128 MiB progress-report interval, which is
|
|
// what lets this test be green on Go: a failing stream.Send from that report
|
|
// is Go's only abort signal. Measured below the interval (120 MiB), a Go
|
|
// destination mounts the abandoned copy too, so a smaller fixture would fail
|
|
// the Go leg without any Rust change.
|
|
//
|
|
// The bytes are pseudo-random because the volume server gzips compressible
|
|
// uploads; a repeating payload lands on disk as a few KB and the throttle
|
|
// never bites.
|
|
httpClient := framework.NewHTTPClient()
|
|
chunk := make([]byte, 1024*1024)
|
|
if _, err := rand.New(rand.NewSource(11186)).Read(chunk); err != nil {
|
|
t.Fatalf("generate payload: %v", err)
|
|
}
|
|
for i := 0; i < payloadMiB; i++ {
|
|
fid := framework.NewFileID(volumeID, uint64(880100+i), 0x3456789a)
|
|
uploadResp := framework.UploadBytes(t, httpClient, clusterHarness.VolumeAdminURL(0), fid, chunk)
|
|
_ = framework.ReadAllAndClose(t, uploadResp)
|
|
if uploadResp.StatusCode != http.StatusCreated {
|
|
t.Fatalf("upload %d to source expected 201, got %d", i, uploadResp.StatusCode)
|
|
}
|
|
}
|
|
|
|
// 192 MiB at 16 MiB/s is about twelve seconds of copying.
|
|
copyCtx, cancelCopy := context.WithCancel(context.Background())
|
|
defer cancelCopy()
|
|
_, err := destClient.VolumeCopy(copyCtx, &volume_server_pb.VolumeCopyRequest{
|
|
VolumeId: volumeID,
|
|
Collection: "",
|
|
SourceDataNode: clusterHarness.VolumeAdminAddress(0) + "." + strings.Split(clusterHarness.VolumeGRPCAddress(0), ":")[1],
|
|
IoBytePerSecond: 16 * 1024 * 1024,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("VolumeCopy start failed: %v", err)
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
// Premise: the copy must still be running when we cancel. If the
|
|
// destination has already mounted, the throttle no longer bites and the
|
|
// rest of this test would prove nothing.
|
|
premiseCtx, cancelPremise := context.WithTimeout(context.Background(), 5*time.Second)
|
|
_, premiseErr := destClient.ReadVolumeFileStatus(premiseCtx, &volume_server_pb.ReadVolumeFileStatusRequest{VolumeId: volumeID})
|
|
cancelPremise()
|
|
if premiseErr == nil {
|
|
t.Fatalf("copy of volume %d already completed before the cancel; raise payloadMiB or lower IoBytePerSecond", volumeID)
|
|
}
|
|
|
|
cancelCopy()
|
|
|
|
// Well past the ~10s the unabandoned copy would have needed: the volume
|
|
// must never appear on the destination.
|
|
deadline := time.Now().Add(25 * time.Second)
|
|
for time.Now().Before(deadline) {
|
|
pollCtx, cancelPoll := context.WithTimeout(context.Background(), 5*time.Second)
|
|
_, statusErr := destClient.ReadVolumeFileStatus(pollCtx, &volume_server_pb.ReadVolumeFileStatusRequest{VolumeId: volumeID})
|
|
cancelPoll()
|
|
if statusErr == nil {
|
|
t.Fatalf("destination mounted volume %d after its VolumeCopy caller cancelled", volumeID)
|
|
}
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
}
|