Skip to content

Commit

Permalink
go/vt/mysqlctl: add configurable read buffer to builtin backups (#12073)
Browse files Browse the repository at this point in the history
* go/vt/mysqlctl: add configurable read buffer to builtin backups

Signed-off-by: Max Englander <[email protected]>

* pr review: use uint

Signed-off-by: Max Englander <[email protected]>

* doc/releasenotes: v16 --builtinbackup-file-read-buffer-size and --builtinbackup-file-write-buffer-size

Signed-off-by: Max Englander <[email protected]>

* update flags txt

Signed-off-by: Max Englander <[email protected]>

* make part of v17

Signed-off-by: Max Englander <[email protected]>

* Update doc/releasenotes/17_0_0_summary.md

Co-authored-by: Deepthi Sigireddi <[email protected]>
Signed-off-by: Max Englander <[email protected]>

* improve wording -block

Signed-off-by: Max Englander <[email protected]>

---------

Signed-off-by: Max Englander <[email protected]>
Signed-off-by: Max Englander <[email protected]>
Co-authored-by: Deepthi Sigireddi <[email protected]>
  • Loading branch information
maxenglander and deepthi authored Feb 9, 2023
1 parent 07c85db commit b22b419
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
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 defaults may be tuned with, respectively `--builtinbackup-file-read-buffer-size` and `--builtinbackup-file-write-buffer-size`.

- `--builtinbackup-file-read-buffer-size`: read files using an IO buffer of this many bytes. Golang defaults are used when set to 0.
- `--builtinbackup-file-write-buffer-size`: write files using an IO buffer of this many bytes. Golang defaults are used when set to 0. (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 using an IO buffer of this many bytes. Golang defaults are used when set to 0.
--builtinbackup-file-write-buffer-size uint write files using an IO buffer of this many bytes. Golang defaults are used when set to 0. (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 using an IO buffer of this many bytes. Golang defaults are used when set to 0.
--builtinbackup-file-write-buffer-size uint write files using an IO buffer of this many bytes. Golang defaults are used when set to 0. (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 using an IO buffer of this many bytes. Golang defaults are used when set to 0.
--builtinbackup-file-write-buffer-size uint write files using an IO buffer of this many bytes. Golang defaults are used when set to 0. (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
27 changes: 22 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,17 @@ var (
BuiltinBackupMysqldTimeout = 10 * time.Minute

builtinBackupProgress = 5 * time.Second

// Controls the size of the IO buffer used when reading files during backups.
builtinBackupFileReadBufferSize uint

// Controls the size of the IO buffer used when writing files during restores.
builtinBackupFileWriteBufferSize uint = 2 * 1024 * 1024 /* 2 MiB */

// Controls the size of the IO buffer used when writing to backupstorage
// engines during backups. The backupstorage may be a physical file,
// network, or something else.
builtinBackupStorageWriteBufferSize = 2 * 1024 * 1024 /* 2 MiB */
)

// BuiltinBackupEngine encapsulates the logic of the builtin engine
Expand Down Expand Up @@ -123,6 +133,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 using an IO buffer of this many bytes. Golang defaults are used when set to 0.")
fs.UintVar(&builtinBackupFileWriteBufferSize, "builtinbackup-file-write-buffer-size", builtinBackupFileWriteBufferSize, "write files using an IO buffer of this many bytes. Golang defaults are used when set to 0.")
}

// isIncrementalBackup is a convenience function to check whether the params indicate an incremental backup request
Expand Down Expand Up @@ -569,7 +581,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 +682,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 +703,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 +892,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*/
xtrabackupBinaryName = "xtrabackup"
xtrabackupEngineName = "xtrabackup"
xbstream = "xbstream"
Expand Down

0 comments on commit b22b419

Please sign in to comment.