Example #1
0
function sig_handler($signo)
{
    global $cdc;
    switch ($signo) {
        case SIGTERM:
        case SIGHUP:
        case SIGINT:
            FlexCDC::shutdown_plugins($cdc);
            die1(0);
    }
}
 public function testInstaller()
 {
     global $settings;
     $cdc = new FlexCDC($settings);
     $this->assertTrue($cdc->get_source() && $cdc->get_dest());
     $conn = $cdc->get_source();
     mysql_query('DROP DATABASE IF EXISTS test') or die(mysql_error() . "\n");
     #keep moving up directories looking for the installer.  error out when we can move no further up
     while (1) {
         $this->assertTrue(chdir('..'));
         if (file_exists('./install.sql')) {
             break;
         }
     }
     $output = `test/sandbox/use -uroot -pmsandbox < install.sql`;
     echo md5($output);
     $this->assertTrue(md5($output) == "b83cfd9e5fd29f1c458f8d4070c86511");
     $sql = "CREATE DATABASE IF NOT EXISTS test";
     mysql_query($sql, $conn);
     $sql = "CREATE TABLE test.t1 (c1 int primary key)";
     mysql_query($sql, $conn);
     $sql = "CALL flexviews.create_mvlog('test','t1')";
     mysql_query($sql, $conn);
     $sql = "INSERT INTO test.t1 values (1),(2),(3)";
     mysql_query($sql, $conn);
     $sql = "CREATE TABLE test.t2 (c1 int, c2 int, primary key(c2), key(c1))";
     mysql_query($sql, $conn);
     $sql = "CALL flexviews.create_mvlog('test','t2')";
     mysql_query($sql, $conn);
     $sql = "INSERT INTO test.t2 values (1,1),(2,2),(3,3),(1,4)";
     mysql_query($sql, $conn);
     #VERIFY THAT FLEXCDC IS WORKING - The consumer is going to run in the background
     sleep(1);
     $sql = "select count(*) from flexviews.test_t1";
     $stmt = mysql_query($sql, $conn) or die(mysql_error() . "\n");
     return $cdc;
 }
        die('Could not fork a new process!\\n');
    } elseif ($pid == 0) {
        #we are now in a child process, and the capture_changes
        #below will be daemonized
        pcntl_signal(SIGTERM, "sig_handler");
        pcntl_signal(SIGHUP, "sig_handler");
    } else {
        #return control to the shell
        exit(0);
    }
}
#support pid file
if (!empty($params['pid'])) {
    if (file_exists($params['pid'])) {
        $pid = trim(file_get_contents($params['pid']));
        $ps = `ps -p{$pid}`;
        if (preg_match('/php/i', $ps)) {
            echo "Already running!\n";
            exit(1000);
        } else {
            echo "Stale lockfile detected.\n";
        }
    }
    file_put_contents($params['pid'], getmypid());
}
$error_log = "cleanup_history.err";
$cdc = new FlexCDC($settings);
while (1) {
    $cdc->purge_table_change_history();
    sleep(600);
}
Example #4
0
 function create_mvlog($v_schema_name, $v_table_name)
 {
     $v_done = FALSE;
     $v_column_name = NULL;
     $v_data_type = NULL;
     $v_sql = NULL;
     $cursor_sql = "SELECT COLUMN_NAME, IF(COLUMN_TYPE='TIMESTAMP', 'TIMESTAMP', COLUMN_TYPE) COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='{$v_table_name}' AND TABLE_SCHEMA = '{$v_schema_name}'";
     $cur_columns = my_mysql_query($cursor_sql, $this->source);
     $v_sql = '';
     while (1) {
         if ($v_sql != '') {
             $v_sql = FlexCDC::concat($v_sql, ', ');
         }
         $row = mysql_fetch_array($cur_columns);
         if ($row === false) {
             $v_done = true;
         }
         if ($row) {
             $v_column_name = '`' . $row[0] . '`';
             $v_data_type = $row[1];
         }
         if ($v_done) {
             mysql_free_result($cur_columns);
             break;
         }
         $v_sql = FlexCDC::concat($v_sql, $v_column_name, ' ', $v_data_type);
     }
     if (trim($v_sql) == "") {
         trigger_error('Could not access table:' . $v_table_name, E_USER_ERROR);
     }
     $v_sql = FlexCDC::concat('CREATE TABLE IF NOT EXISTS`', $this->mvlogDB, '`.`', $v_schema_name, '_', $v_table_name, '` ( dml_type INT DEFAULT 0, uow_id BIGINT, `fv$server_id` INT UNSIGNED,fv$gsn bigint, ', $v_sql, 'KEY(uow_id, dml_type) ) ENGINE=INNODB');
     $create_stmt = my_mysql_query($v_sql, $this->dest);
     if (!$create_stmt) {
         die1('COULD NOT CREATE MVLOG. ' . $v_sql . "\n");
     }
     $exec_sql = " INSERT IGNORE INTO `" . $this->mvlogDB . "`.`" . $this->mvlogs . "`( table_schema , table_name , mvlog_name ) values('{$v_schema_name}', '{$v_table_name}', '" . $v_schema_name . "_" . $v_table_name . "')";
     my_mysql_query($exec_sql) or die1($exec_sql . ':' . mysql_error($this->dest) . "\n");
     return true;
 }
Example #5
0
{
    $cg = new Console_Getopt();
    $args = $cg->readPHPArgv();
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'force==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    if (PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
$params = get_commandline();
$settings = false;
#support specifying location of .ini file on command line
if (!empty($params['ini'])) {
    $settings = @parse_ini_file($params['ini'], true);
}
$cdc = new FlexCDC($settings);
#this will read settings from the INI file and initialize
#the database and capture the source master position
echo "setup starting\n";
$cdc->setup(in_array('force', array_keys($params)));
echo "setup completed\n";
Example #6
0
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'schema==', 'table==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    if (PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
$params = get_commandline();
$settings = false;
#support specifying location of .ini file on command line
if (!empty($params['ini'])) {
    $settings = @parse_ini_file($params['ini'], true);
}
require_once 'include/flexcdc.php';
$cdc = new FlexCDC($settings);
if (empty($params['schema']) || empty($params['table'])) {
    die("usage: add_table.php --schema=<SCHEMA> --table=<TABLE>\nWhere SCHEMA is the name of the database and table is the name of the table\n");
}
if (!$cdc->create_mvlog($params['schema'], $params['table'])) {
    die("failure: Could not create the log table\n");
}
echo "success\n";
Example #7
0
 public function setup($force = false)
 {
     #FlexSBR only needs a single state table
     return parent::setup($force, 'binlog_consumer_status');
 }
    array_shift($args);
    $shortOpts = 'h::v::';
    $longOpts = array('ini=', 'schema==', 'table==');
    $params = $cg->getopt2($args, $shortOpts, $longOpts);
    if (PEAR::isError($params)) {
        echo 'Error: ' . $params->getMessage() . "\n";
        exit(1);
    }
    $new_params = array();
    foreach ($params[0] as $param) {
        $param[0] = str_replace('--', '', $param[0]);
        $new_params[$param[0]] = $param[1];
    }
    unset($params);
    return $new_params;
}
$params = get_commandline();
$settings = false;
#support specifying location of .ini file on command line
if (!empty($params['ini'])) {
    $settings = @parse_ini_file($params['ini'], true);
}
require_once 'include/flexcdc.php';
$cdc = new FlexCDC($settings);
if (empty($params['schema']) || empty($params['table'])) {
    die("usage: drop_changelog.php --schema=<SCHEMA> --table=<TABLE>\nWhere SCHEMA is the name of the database and table is the name of the table\n");
}
if (!$cdc->drop_mvlog($params['schema'], $params['table'])) {
    die("failure: Could not drop the change log table\n");
}
echo "success\n";
Example #9
0
        #we are now in a child process, and the capture_changes
        #below will be daemonized
        pcntl_signal(SIGTERM, "sig_handler");
        pcntl_signal(SIGHUP, "sig_handler");
    } else {
        #return control to the shell
        exit(0);
    }
}
#support pid file
if (!empty($params['pid'])) {
    if (file_exists($params['pid'])) {
        $pid = trim(file_get_contents($params['pid']));
        $ps = `ps -p{$pid}`;
        if (preg_match('/php/i', $ps)) {
            echo "Already running!\n";
            exit(1000);
        } else {
            echo "Stale lockfile detected.\n";
        }
    }
    file_put_contents($params['pid'], getmypid());
}
if (empty($settings['flexcdc']['error_log'])) {
    $error_log = "flexcdc.err";
} else {
    $error_log = $settings['flexcdc']['error_log'];
}
$cdc = new FlexCDC($settings);
#capture changes forever (-1):
$cdc->capture_changes(-1);