Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/vt/mysqlctl: add configurable read buffer to builtin backups #12073

Merged
merged 8 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions doc/releasenotes/17_0_0_summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Summary

### Table of Contents

- **[Major Changes](#major-changes)**
- **[New command line flags and behavior](#new-flag)**
- [Builtin backup: read buffering flags](#builtin-backup-read-buffering-flags)

## <a id="major-changes"/> Major Changes

### <a id="new-flag"/> New command line flags and behavior

#### <a id="builtin-backup-read-buffering-flags" /> Backup --builtinbackup-file-read-buffer-size and --builtinbackup-file-write-buffer-size

Prior to v17 the builtin Backup Engine does not use read buffering for restores, and for backups uses a hardcoded write buffer size of 2097152 bytes.

In v17 these default may be tuned with, respectively `--builtinbackup-file-read-buffer-size` and `--builtinbackup-file-write-buffer-size`.
maxenglander marked this conversation as resolved.
Show resolved Hide resolved

- `--builtinbackup-file-read-buffer-size`: read files from disk in blocks of this many bytes. Golang defaults are used when set to 0.
- `--builtinbackup-file-write-buffer-size`: write files to disk in blocks of this many bytes. (default 2097152)

These flags are applicable to the following programs:

- `vtbackup`
- `vtctld`
- `vttablet`
- `vttestserver`
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtctld.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Usage of vtctld:
--backup_storage_compress if set, the backup files will be compressed. (default true)
--backup_storage_implementation string Which backup storage implementation to use for creating and restoring backups.
--backup_storage_number_blocks int if backup_storage_compress is true, backup_storage_number_blocks sets the number of blocks that can be processed, at once, before the writer blocks, during compression (default is 2). It should be equal to the number of CPUs available for compression. (default 2)
--builtinbackup-file-read-buffer-size uint read files from disk in blocks of this many bytes. Golang defaults are used when set to 0.
--builtinbackup-file-write-buffer-size uint write files to disk in blocks of this many bytes. (default 2097152)
--builtinbackup_mysqld_timeout duration how long to wait for mysqld to shutdown at the start of the backup. (default 10m0s)
--builtinbackup_progress duration how often to send progress updates when backing up large files. (default 5s)
--catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vttablet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Usage of vttablet:
--binlog_ssl_key string PITR restore parameter: Filename containing mTLS client private key for use in binlog server authentication.
--binlog_ssl_server_name string PITR restore parameter: TLS server name (common name) to verify against for the binlog server we are connecting to (If not set: use the hostname or IP supplied in --binlog_host).
--binlog_user string PITR restore parameter: username of binlog server.
--builtinbackup-file-read-buffer-size uint read files from disk in blocks of this many bytes. Golang defaults are used when set to 0.
--builtinbackup-file-write-buffer-size uint write files to disk in blocks of this many bytes. (default 2097152)
--builtinbackup_mysqld_timeout duration how long to wait for mysqld to shutdown at the start of the backup. (default 10m0s)
--builtinbackup_progress duration how often to send progress updates when backing up large files. (default 5s)
--catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vttestserver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Usage of vttestserver:
--backup_storage_block_size int if backup_storage_compress is true, backup_storage_block_size sets the byte size for each block while compressing (default is 250000). (default 250000)
--backup_storage_compress if set, the backup files will be compressed. (default true)
--backup_storage_number_blocks int if backup_storage_compress is true, backup_storage_number_blocks sets the number of blocks that can be processed, at once, before the writer blocks, during compression (default is 2). It should be equal to the number of CPUs available for compression. (default 2)
--builtinbackup-file-read-buffer-size uint read files from disk in blocks of this many bytes. Golang defaults are used when set to 0.
--builtinbackup-file-write-buffer-size uint write files to disk in blocks of this many bytes. (default 2097152)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have nothing to do with block device block sizes, right? If so, IMO it would be a little more clear to say chunks instead of blocks in this context. Or it may be even more clear/precise to say that we use a buffer of this size each time that we read/write backup data from disk?

--builtinbackup_mysqld_timeout duration how long to wait for mysqld to shutdown at the start of the backup. (default 10m0s)
--builtinbackup_progress duration how often to send progress updates when backing up large files. (default 5s)
--catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified
Expand Down
26 changes: 21 additions & 5 deletions go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
const (
builtinBackupEngineName = "builtin"
autoIncrementalFromPos = "auto"
writerBufferSize = 2 * 1024 * 1024
dataDictionaryFile = "mysql.ibd"
)

Expand All @@ -62,6 +61,16 @@ var (
BuiltinBackupMysqldTimeout = 10 * time.Minute

builtinBackupProgress = 5 * time.Second

// Controls the size of blocks read from disk during backups.
builtinBackupFileReadBufferSize uint

// Controls the size of blocks written to disk during restores.
builtinBackupFileWriteBufferSize uint = 2 * 1024 * 1024 /* 2 MiB */

// Controls the byte block size of writes to backupstorage during backups.
// The backupstorage may be a physical file, network, or something else.
builtinBackupStorageWriteBufferSize = 2 * 1024 * 1024 /* 2 MiB */
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior is that we use the same 2 MiB buffer when writing files to disk during restores or writing to backupstorage during backups.

Backupstorage may or may not go directly to disk, so I think it makes sense to decouple these buffers to they can be tuned independently.

I think it would be even better if builtinbackup didn't do any buffering when reading to or writing from backupstorage, and instead would be better to let each backupstorage engine decide how to handle read/write buffering, maybe with tunable flags.

)

// BuiltinBackupEngine encapsulates the logic of the builtin engine
Expand Down Expand Up @@ -123,6 +132,8 @@ func init() {
func registerBuiltinBackupEngineFlags(fs *pflag.FlagSet) {
fs.DurationVar(&BuiltinBackupMysqldTimeout, "builtinbackup_mysqld_timeout", BuiltinBackupMysqldTimeout, "how long to wait for mysqld to shutdown at the start of the backup.")
fs.DurationVar(&builtinBackupProgress, "builtinbackup_progress", builtinBackupProgress, "how often to send progress updates when backing up large files.")
fs.UintVar(&builtinBackupFileReadBufferSize, "builtinbackup-file-read-buffer-size", builtinBackupFileReadBufferSize, "read files from disk in blocks of this many bytes. Golang defaults are used when set to 0.")
fs.UintVar(&builtinBackupFileWriteBufferSize, "builtinbackup-file-write-buffer-size", builtinBackupFileWriteBufferSize, "write files to disk in blocks of this many bytes.")
}

// isIncrementalBackup is a convenience function to check whether the params indicate an incremental backup request
Expand Down Expand Up @@ -569,7 +580,7 @@ type backupPipe struct {
closed int32
}

func newBackupWriter(filename string, maxSize int64, w io.Writer) *backupPipe {
func newBackupWriter(filename string, writerBufferSize int, maxSize int64, w io.Writer) *backupPipe {
return &backupPipe{
crc32: crc32.NewIEEE(),
w: bufio.NewWriterSize(w, writerBufferSize),
Expand Down Expand Up @@ -670,10 +681,11 @@ func (be *BuiltinBackupEngine) backupFile(ctx context.Context, params BackupPara
}
}(name, fe.Name)

bw := newBackupWriter(fe.Name, fi.Size(), wc)
bw := newBackupWriter(fe.Name, builtinBackupStorageWriteBufferSize, fi.Size(), wc)
br := newBackupReader(fe.Name, fi.Size(), source)
go br.ReportProgress(builtinBackupProgress, params.Logger)

var reader io.Reader = br
var writer io.Writer = bw

// Create the gzip compression pipe, if necessary.
Expand All @@ -690,9 +702,13 @@ func (be *BuiltinBackupEngine) backupFile(ctx context.Context, params BackupPara
writer = compressor
}

if builtinBackupFileReadBufferSize > 0 {
reader = bufio.NewReaderSize(br, int(builtinBackupFileReadBufferSize))
}

// Copy from the source file to writer (optional gzip,
// optional pipe, tee, output file and hasher).
_, err = io.Copy(writer, br)
_, err = io.Copy(writer, reader)
if err != nil {
return vterrors.Wrap(err, "cannot copy data")
}
Expand Down Expand Up @@ -875,7 +891,7 @@ func (be *BuiltinBackupEngine) restoreFile(ctx context.Context, params RestorePa
bp := newBackupReader(name, 0, source)
go bp.ReportProgress(builtinBackupProgress, params.Logger)

dst := bufio.NewWriterSize(dstFile, writerBufferSize)
dst := bufio.NewWriterSize(dstFile, int(builtinBackupFileWriteBufferSize))
var reader io.Reader = bp

// Create the uncompresser if needed.
Expand Down
1 change: 1 addition & 0 deletions go/vt/mysqlctl/xtrabackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (

const (
streamModeTar = "tar"
writerBufferSize = 2 * 1024 * 1024 /*2 MiB*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this moved from builtin to this file? It's not actually used by xtrabackupengine AFAICT.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used!

buffer := bufio.NewWriterSize(file, writerBufferSize)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah it was already being used. And it is no longer used in builtin. 👍

xtrabackupBinaryName = "xtrabackup"
xtrabackupEngineName = "xtrabackup"
xbstream = "xbstream"
Expand Down