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

adding new mysql shell backup engine #16295

Merged
merged 44 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1f70afb
adding new mysql shell backup engine
rvrangel Jun 27, 2024
58005ab
change flags
rvrangel Jul 2, 2024
b74a87f
fix TestHelpOutput
rvrangel Jul 10, 2024
c51ee4b
add unit test for scanLinesToLogger
rvrangel Jul 19, 2024
6e59215
PR feedback
rvrangel Jul 23, 2024
abe1d11
Merge branch 'master' into mysqlshell-backup
rvrangel Jul 23, 2024
3ca4b3b
PR feedback + fix tests
rvrangel Jul 25, 2024
d26b5c3
more improvements
rvrangel Aug 7, 2024
0a5fda4
fix unit test
rvrangel Aug 7, 2024
4aae34b
Merge branch 'master' into mysqlshell-backup
rvrangel Aug 13, 2024
7116317
fix tests
rvrangel Aug 13, 2024
c2d41ac
PR feedback
rvrangel Aug 21, 2024
8c6c665
regenerate ci workflows
rvrangel Aug 21, 2024
0bb5631
add mysql-shell package as part of the standard mysql CI dependencies
rvrangel Aug 21, 2024
82a288c
use dumpInstances() instead
rvrangel Aug 21, 2024
d9407f2
remove case XtraBackup, MySQLShell
rvrangel Aug 21, 2024
287a500
Merge branch 'master' into mysqlshell-backup
rvrangel Aug 21, 2024
31ba57e
make generate_ci_workflows
rvrangel Aug 21, 2024
31c27b5
update flags and operator.yaml
rvrangel Sep 4, 2024
e62ae95
removing DeleteBeforeRestore
rvrangel Sep 5, 2024
99f08ea
fixing tests
rvrangel Sep 9, 2024
589c81b
Merge branch 'master' into mysqlshell-backup
rvrangel Sep 9, 2024
4257ae4
Revert "fixing tests"
rvrangel Sep 10, 2024
e958558
Revert "removing DeleteBeforeRestore"
rvrangel Sep 10, 2024
2e8c441
make generate_ci_workflows
rvrangel Sep 10, 2024
64b52e6
Merge branch 'master' into mysqlshell-backup
rvrangel Sep 10, 2024
75b2b76
make generate_ci_workflows
rvrangel Sep 10, 2024
85fba81
deleting users + other dbs
rvrangel Sep 12, 2024
21f2604
update flags
rvrangel Sep 12, 2024
47dc753
make sure vitess default matches mysqlshell's
rvrangel Sep 13, 2024
5c08cc7
do not remove users if not loading them
rvrangel Sep 13, 2024
e37dbbb
changelog notice
rvrangel Sep 13, 2024
4418592
Merge branch 'master' into mysqlshell-backup
rvrangel Sep 13, 2024
9243f22
add ShouldStartMySQLAfterRestore()
rvrangel Sep 18, 2024
4e79a02
backup_pitr testing: validate rejoining replication stream
shlomi-noach Sep 19, 2024
7e77e86
test replication stream in ExecTestIncrementalBackupAndRestoreToTimes…
shlomi-noach Sep 19, 2024
1d5aaab
Merge branch 'main' into mysqlshell-backup
shlomi-noach Sep 19, 2024
1fa6191
Merge branch 'backup-pitr-replication' into mysqlshell-backup
shlomi-noach Sep 19, 2024
3c655a1
add missing grant
rvrangel Sep 20, 2024
4e0a0e2
update vitess operator example
rvrangel Sep 20, 2024
9218186
PR feedback
rvrangel Sep 23, 2024
301e95c
Merge remote-tracking branch 'origin/main' into mysqlshell-backup
shlomi-noach Sep 23, 2024
ae42af7
resolved conflict
shlomi-noach Sep 24, 2024
bc2cff2
add missing grant
rvrangel Sep 24, 2024
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
6 changes: 6 additions & 0 deletions go/flags/endtoend/vtbackup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ Flags:
--mysql-shutdown-timeout duration how long to wait for mysqld shutdown (default 5m0s)
--mysql_port int mysql port (default 3306)
--mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess")
--mysql_shell_backup_location string location where the backup will be stored
--mysql_shell_dump_flags string flags to pass to mysql shell dump utility. This should be a JSON string and will be saved in the MANIFEST (default "{\"threads\": 2}")
--mysql_shell_flags string execution flags to pass to mysqlsh binary to be used during dump/load (default "--defaults-file=/dev/null --js -h localhost")
--mysql_shell_load_flags string flags to pass to mysql shell load utility. This should be a JSON string (default "{\"threads\": 4, \"updateGtidSet\": \"replace\", \"skipBinlog\": true, \"progressFile\": \"\"}")
--mysql_shell_should_drain decide if we should drain while taking a backup or continue to serving traffic
--mysql_shell_speedup_restore speed up restore by disabling redo logging and double write buffer during the restore process
Copy link
Member

Choose a reason for hiding this comment

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

New flags need to use dashes as separators.

--mysql_socket string path to the mysql socket
--mysql_timeout duration how long to wait for mysqld startup (default 5m0s)
--opentsdb_uri string URI of opentsdb /api/put method
Expand Down
6 changes: 6 additions & 0 deletions go/flags/endtoend/vtcombo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ Flags:
--mysql_server_tls_min_version string Configures the minimal TLS version negotiated when SSL is enabled. Defaults to TLSv1.2. Options: TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3.
--mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess")
--mysql_server_write_timeout duration connection write timeout
--mysql_shell_backup_location string location where the backup will be stored
--mysql_shell_dump_flags string flags to pass to mysql shell dump utility. This should be a JSON string and will be saved in the MANIFEST (default "{\"threads\": 2}")
--mysql_shell_flags string execution flags to pass to mysqlsh binary to be used during dump/load (default "--defaults-file=/dev/null --js -h localhost")
--mysql_shell_load_flags string flags to pass to mysql shell load utility. This should be a JSON string (default "{\"threads\": 4, \"updateGtidSet\": \"replace\", \"skipBinlog\": true, \"progressFile\": \"\"}")
--mysql_shell_should_drain decide if we should drain while taking a backup or continue to serving traffic
--mysql_shell_speedup_restore speed up restore by disabling redo logging and double write buffer during the restore process
--mysql_slow_connect_warn_threshold duration Warn if it takes more than the given threshold for a mysql connection to establish
--mysql_tcp_version string Select tcp, tcp4, or tcp6 to control the socket type. (default "tcp")
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
Expand Down
6 changes: 6 additions & 0 deletions go/flags/endtoend/vttablet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ Flags:
--mycnf_tmp_dir string mysql tmp directory
--mysql-shutdown-timeout duration timeout to use when MySQL is being shut down. (default 5m0s)
--mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess")
--mysql_shell_backup_location string location where the backup will be stored
--mysql_shell_dump_flags string flags to pass to mysql shell dump utility. This should be a JSON string and will be saved in the MANIFEST (default "{\"threads\": 2}")
--mysql_shell_flags string execution flags to pass to mysqlsh binary to be used during dump/load (default "--defaults-file=/dev/null --js -h localhost")
--mysql_shell_load_flags string flags to pass to mysql shell load utility. This should be a JSON string (default "{\"threads\": 4, \"updateGtidSet\": \"replace\", \"skipBinlog\": true, \"progressFile\": \"\"}")
--mysql_shell_should_drain decide if we should drain while taking a backup or continue to serving traffic
--mysql_shell_speedup_restore speed up restore by disabling redo logging and double write buffer during the restore process
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
--mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions)
--onclose_timeout duration wait no more than this for OnClose handlers before stopping (default 10s)
Expand Down
6 changes: 6 additions & 0 deletions go/flags/endtoend/vttestserver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ Flags:
--mysql_bind_host string which host to bind vtgate mysql listener to (default "localhost")
--mysql_only If this flag is set only mysql is initialized. The rest of the vitess components are not started. Also, the output specifies the mysql unix socket instead of the vtgate port.
--mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess")
--mysql_shell_backup_location string location where the backup will be stored
--mysql_shell_dump_flags string flags to pass to mysql shell dump utility. This should be a JSON string and will be saved in the MANIFEST (default "{\"threads\": 2}")
--mysql_shell_flags string execution flags to pass to mysqlsh binary to be used during dump/load (default "--defaults-file=/dev/null --js -h localhost")
--mysql_shell_load_flags string flags to pass to mysql shell load utility. This should be a JSON string (default "{\"threads\": 4, \"updateGtidSet\": \"replace\", \"skipBinlog\": true, \"progressFile\": \"\"}")
--mysql_shell_should_drain decide if we should drain while taking a backup or continue to serving traffic
--mysql_shell_speedup_restore speed up restore by disabling redo logging and double write buffer during the restore process
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
--mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions)
--no_scatter when set to true, the planner will fail instead of producing a plan that includes scatter queries
Expand Down
20 changes: 20 additions & 0 deletions go/vt/mysqlctl/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ limitations under the License.
package mysqlctl

import (
"bufio"
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
Expand All @@ -29,6 +31,7 @@ import (

"vitess.io/vitess/go/textutil"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
"vitess.io/vitess/go/vt/proto/vtrpc"
Expand Down Expand Up @@ -500,3 +503,20 @@ func Restore(ctx context.Context, params RestoreParams) (*BackupManifest, error)
params.Logger.Infof("Restore: complete")
return manifest, nil
}

// scanLinesToLogger scans full lines from the given Reader and sends them to
// the given Logger until EOF.
func scanLinesToLogger(prefix string, reader io.Reader, logger logutil.Logger, doneFunc func()) {
defer doneFunc()

scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line := scanner.Text()
logger.Infof("%s: %s", prefix, line)
}
if err := scanner.Err(); err != nil {
// This is usually run in a background goroutine, so there's no point
// returning an error. Just log it.
logger.Warningf("error scanning lines from %s: %v", prefix, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice we do not have a unit test for this function. Having moved it around, perhaps now is a good opportunity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I can probably add it there 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unit test added for this function

}
32 changes: 27 additions & 5 deletions go/vt/mysqlctl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ import (
"path"
"reflect"
"sort"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/fakesqldb"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
Expand Down Expand Up @@ -714,3 +713,26 @@ func TestShouldRestore(t *testing.T) {
assert.False(t, b)
assert.NoError(t, err)
}

func Test_scanLinesToLogger(t *testing.T) {
rvrangel marked this conversation as resolved.
Show resolved Hide resolved
reader, writer := io.Pipe()
logger := logutil.NewMemoryLogger()
var wg sync.WaitGroup

wg.Add(1)
go scanLinesToLogger("test", reader, logger, wg.Done)

for i := range 100 {
_, err := writer.Write([]byte(fmt.Sprintf("foobar %d\n", i)))
require.NoError(t, err)
}

writer.Close()
wg.Wait()

require.Equal(t, 100, len(logger.Events))

for i, event := range logger.Events {
require.Equal(t, fmt.Sprintf("test: foobar %d", i), event.Value)
}
}
Loading
Loading