# Tests specific of MyISAM's online backup.

--source include/not_embedded.inc
--source include/have_debug_sync.inc
--source include/have_myisam_or_maria_default.inc

#
# Cleanup from former test cases
#
--disable_warnings
SET DEBUG_SYNC= 'RESET';
USE test;
DROP DATABASE IF EXISTS mysqltest;
let $MYSQLD_BACKUPDIR= `SELECT @@backupdir`;
--error 0,1
remove_file $MYSQLD_BACKUPDIR/bup_myisam_sync.bak;
--enable_warnings

#
# Create database.
#
CREATE DATABASE mysqltest;
USE mysqltest;

#
# Create table with long records (causing records' length to be stored
# in a long format in the backup log).
#
CREATE TABLE t1 (c1 LONGTEXT);

    #
    # Create a worker connection, using mysqltest as its default database.
    #
    --echo
    --echo connection backup: Start backup
    connect (backup,localhost,root,,mysqltest);

    # Activate the sync point for BACKUP. Before starting the prepare phase,
    # BACKUP reaches the sync point "before_backup_data_prepare", which will
    # emit the signal "bup_sync" and then wait for the signal "bup_finish"
    # to be emitted by another connection.
    SET DEBUG_SYNC= 'before_backup_data_prepare SIGNAL bup_sync
                     WAIT_FOR bup_finish';
    send BACKUP DATABASE mysqltest TO 'bup_myisam_sync.bak';

--echo
--echo connection default: Wait for BACKUP to reach its sync point
connection default;
SET DEBUG_SYNC= 'now WAIT_FOR bup_sync';

--echo Insert data
INSERT INTO t1 VALUES ("text");
let $1=16;
while ($1)
{
  UPDATE t1 SET c1=concat(c1,c1);
  dec $1;
}
SELECT LENGTH(c1) FROM t1;
CHECKSUM TABLE t1;

--echo
--echo # Verify that the MyISAM Key Cache is enabled.
--echo # See Bug#44068 (RESTORE can disable the MyISAM Key Cache).
SELECT SUM(VARIABLE_VALUE) > 0 AS key_cache_is_enabled
  FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
  VARIABLE_NAME LIKE 'Key_blocks_%used';
--echo

--echo Signal BACKUP to finish
SET DEBUG_SYNC= 'now SIGNAL bup_finish';

    --echo
    --echo connection backup: Fetch result
    connection backup;
    --replace_column 1 #
    reap;
    DROP DATABASE mysqltest;

    --replace_column 1 #
    RESTORE FROM 'bup_myisam_sync.bak';

    SELECT LENGTH(c1) FROM t1;
    CHECKSUM TABLE t1;
    CHECK TABLE t1 EXTENDED;

    disconnect backup;

--echo
--echo connection default: cleanup
connection default;
remove_file $MYSQLD_BACKUPDIR/bup_myisam_sync.bak;
SET DEBUG_SYNC= 'RESET';

--echo
--echo # Verify that the MyISAM Key Cache is still enabled.
--echo # See Bug#44068 (RESTORE can disable the MyISAM Key Cache).
SELECT SUM(VARIABLE_VALUE) > 0 AS key_cache_is_enabled
  FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
  VARIABLE_NAME LIKE 'Key_blocks_%used';
--echo

#
# Cleanup from this test case
#
--echo # final cleanup
USE test;
DROP DATABASE mysqltest;
SET DEBUG_SYNC= 'RESET';

