Ejemplo n.º 1
0
 /**
  * 数据装载一致性监控
  *
  * @access public static
  * @return Mixture
  */
 public static function import_consist_monitor()
 {
     $mysql = \Myfox\Lib\Mysql::instance('default');
     $tables = $mysql->getAll($mysql->query(sprintf("SHOW TABLES LIKE '%sroute_info%%'", $mysql->option('prefix'))));
     $status = array();
     $offset = (int) strtotime(Setting::get('monitor_consist_check'));
     foreach ($tables as $table) {
         $table = end($table);
         $split = $mysql->getAll($mysql->query(sprintf('SELECT real_table,hosts_list,route_text,table_name FROM %s WHERE modtime >= %d AND route_flag IN (%d, %d)', $table, $offset, Router::FLAG_IMPORT_END, Router::FLAG_NORMAL_USE)));
         if (empty($split)) {
             continue;
         }
         foreach ($split as $row) {
             $server = array();
             foreach (explode(',', trim($row['hosts_list'], '{},$')) as $id) {
                 $server[] = self::hostname($id);
             }
             $result = Consist::check($row['real_table'], $server);
             if (is_array($result)) {
                 $status[] = array('table' => $row['table_name'], 'route' => $row['route_text'], 'bucket' => $row['real_table'], 'checks' => $result);
             }
         }
     }
     Setting::set('monitor_consist_check', date('Y-m-d H:i:s'));
     return $status;
 }
Ejemplo n.º 2
0
 public function test_should_consist_works_fine()
 {
     try {
         Consist::check('test.c1', array());
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertTrue($e instanceof \Myfox\Lib\Exception);
         $this->assertContains("Empty server list for consistency check", $e->getMessage());
     }
     $this->assertTrue(Consist::check('i_am_not_exists.lalalla', array('edp1_9801', 'edp2_9902')));
     $this->assertTrue(Consist::check('mirror_0.mirror_583_2', array('edp1_9801', 'edp2_9902')));
 }