diff --git a/go/vt/mysqlctl/backupstorage/interface.go b/go/vt/mysqlctl/backupstorage/interface.go index 03e7b64949c..e4c2e6bc18d 100644 --- a/go/vt/mysqlctl/backupstorage/interface.go +++ b/go/vt/mysqlctl/backupstorage/interface.go @@ -30,6 +30,10 @@ var ( // BackupStorageImplementation is the implementation to use // for BackupStorage. Exported for test purposes. BackupStorageImplementation = flag.String("backup_storage_implementation", "", "which implementation to use for the backup storage feature") + // FileSizeUnknown is a special value indicating that the file size is not known. + // This is typically used while creating a file programmatically, where it is + // impossible to compute the final size on disk ahead of time. + FileSizeUnknown = int64(-1) ) // BackupHandle describes an individual backup. @@ -50,7 +54,9 @@ type BackupHandle interface { // The context is valid for the duration of the writes, until the // WriteCloser is closed. // filesize should not be treated as an exact value but rather - // as an approximate value + // as an approximate value. + // A filesize of -1 should be treated as a special value indicating that + // the file size is unknown. AddFile(ctx context.Context, filename string, filesize int64) (io.WriteCloser, error) // EndBackup stops and closes a backup. The contents should be kept. diff --git a/go/vt/mysqlctl/builtinbackupengine.go b/go/vt/mysqlctl/builtinbackupengine.go index 5f8af216dc0..f49f8fdf780 100644 --- a/go/vt/mysqlctl/builtinbackupengine.go +++ b/go/vt/mysqlctl/builtinbackupengine.go @@ -303,7 +303,7 @@ func (be *BuiltinBackupEngine) backupFiles(ctx context.Context, params BackupPar } // open the MANIFEST - wc, err := bh.AddFile(ctx, backupManifestFileName, 0) + wc, err := bh.AddFile(ctx, backupManifestFileName, backupstorage.FileSizeUnknown) if err != nil { return vterrors.Wrapf(err, "cannot add %v to backup", backupManifestFileName) } diff --git a/go/vt/mysqlctl/cephbackupstorage/ceph.go b/go/vt/mysqlctl/cephbackupstorage/ceph.go index 29b76e1b15e..80c37ceb828 100644 --- a/go/vt/mysqlctl/cephbackupstorage/ceph.go +++ b/go/vt/mysqlctl/cephbackupstorage/ceph.go @@ -88,7 +88,8 @@ func (bh *CephBackupHandle) AddFile(ctx context.Context, filename string, filesi // Give PutObject() the read end of the pipe. object := objName(bh.dir, bh.name, filename) - _, err := bh.client.PutObjectWithContext(ctx, bucket, object, reader, -1, minio.PutObjectOptions{ContentType: "application/octet-stream"}) + // If filesize is unknown, the caller should pass in -1 and we will pass it through. + _, err := bh.client.PutObjectWithContext(ctx, bucket, object, reader, filesize, minio.PutObjectOptions{ContentType: "application/octet-stream"}) if err != nil { // Signal the writer that an error occurred, in case it's not done writing yet. reader.CloseWithError(err) diff --git a/go/vt/mysqlctl/xtrabackupengine.go b/go/vt/mysqlctl/xtrabackupengine.go index fc9e27e2523..08d18638bce 100644 --- a/go/vt/mysqlctl/xtrabackupengine.go +++ b/go/vt/mysqlctl/xtrabackupengine.go @@ -158,7 +158,7 @@ func (be *XtrabackupEngine) ExecuteBackup(ctx context.Context, params BackupPara // open the MANIFEST params.Logger.Infof("Writing backup MANIFEST") - mwc, err := bh.AddFile(ctx, backupManifestFileName, 0) + mwc, err := bh.AddFile(ctx, backupManifestFileName, backupstorage.FileSizeUnknown) if err != nil { return false, vterrors.Wrapf(err, "cannot add %v to backup", backupManifestFileName) }