sqldata/sqldatacmd.cpp
// Callback function for table data validation task
Callback function for table data validation task
Callback function for table data validation task
void SqlDataCmd::CallbackValidationRows(SqlDataReply *reply)
{
	if(reply == NULL)
		return;
	if(reply->_cmd_subtype != SQLDATA_CMD_ALL_COMPLETE)
		_log.Log("\n  %s - ", reply->_s_name);
	if(reply->_cmd_subtype == SQLDATA_CMD_STARTED)
	{
		_log.Log("Started (%d of %d, session %d)", _validate_table_num, _total_tables, reply->session_id);
		_validate_table_num++;
	}
	else
	if(reply->_cmd_subtype == SQLDATA_CMD_COMPLETE)
	{
		std::string table_diff;
		if(reply->_s_rc == -1 || reply->_t_rc == -1)
		{
			_log.Log("Failed");
			_failed_tables++;
		}
		else
		if(reply->_s_int1 != reply->_t_int1 || reply->_int1 != 0)
		{
			_log.Log("Not Equal");
			_tables_diff++;
			table_diff = reply->_s_name;
			table_diff += " (";
			table_diff += reply->data2;
			table_diff += ")";
			_tables_diff_list.push_back(table_diff);
		}
		else
		{
			_log.Log("Ok");
			_tables_equal++;
		}
		char time_fmt[21], s_time_fmt[21], t_time_fmt[21];
		Str::FormatTime(reply->_time_spent, time_fmt);
		Str::FormatTime(reply->_s_time_spent, s_time_fmt);
		Str::FormatTime(reply->_t_time_spent, t_time_fmt);
		_log.Log(" (%s, session %d)\n", time_fmt, reply->session_id);
		double s_speed_rows = 0, t_speed_rows = 0;
		if(reply->_s_int1 != 0 && reply->_s_time_spent != 0)
			s_speed_rows = ((double)reply->_s_int1)/((double)reply->_s_time_spent) * 1000.0;
		if(reply->_t_int1 != 0 && reply->_t_time_spent != 0)
			t_speed_rows = ((double)reply->_t_int1)/((double)reply->_t_time_spent) * 1000.0;
		double s_speed_bytes = 0, t_speed_bytes = 0;
		if(reply->_s_bigint1 != 0 && reply->_s_time_spent != 0)
			s_speed_bytes = ((double)reply->_s_bigint1)/((double)reply->_s_time_spent)*1000.0;
		if(reply->_t_bigint1 != 0 && reply->_t_time_spent != 0)
			t_speed_bytes = ((double)reply->_t_bigint1)/((double)reply->_t_time_spent)*1000.0;
		char s_bytes_fmt[21], t_bytes_fmt[21];
		char s_speed_bytes_fmt[21], t_speed_bytes_fmt[21];
		Str::FormatByteSize((double)reply->_s_bigint1, s_bytes_fmt);
		Str::FormatByteSize((double)reply->_t_bigint1, t_bytes_fmt);
		Str::FormatByteSize(s_speed_bytes, s_speed_bytes_fmt);
		Str::FormatByteSize(t_speed_bytes, t_speed_bytes_fmt);
		_log.Log("    Source:    ");
		if(reply->_s_rc == -1)
		{
			if(reply->s_error == SQL_DBAPI_NOT_EXISTS_ERROR)
				_log.Log("Table does not exist");
			else
				_log.Log("Error: %s", reply->s_native_error_text);
		}
		else
			_log.Log("%d row%s", reply->_s_int1, SUFFIX(reply->_s_int1));
		_log.Log(" (%s read", s_time_fmt);
		if(reply->_s_int1 > 0)
			_log.Log(", %.0lf rows/sec, %s, %s/sec)\n", s_speed_rows, s_bytes_fmt, s_speed_bytes_fmt);
		else
			_log.Log(")\n");
		_log.Log("    Target:    ");
		if(reply->_t_rc == -1)
		{
			if(reply->t_error == SQL_DBAPI_NOT_EXISTS_ERROR)
				_log.Log("Table does not exist");
			else
				_log.Log("Error: %s", reply->t_native_error_text);
		}
		else
			_log.Log("%d row%s", reply->_t_int1, SUFFIX(reply->_t_int1));
		_log.Log(" (%s read", t_time_fmt);
		if(reply->_t_int1 > 0)
			_log.Log(", %.0lf rows/sec, %s, %s/sec)", t_speed_rows, t_bytes_fmt, t_speed_bytes_fmt);
		else
			_log.Log(")");
		if(reply->_int1 != 0)
			_log.Log("\n    Not Equal: %d row%s, %d of %d column%s (%s)", reply->_int1, SUFFIX(reply->_int1),
						reply->_int2, reply->_int3, SUFFIX(reply->_int3), reply->data2);  
		_log.Log("\n      Source query: %s", reply->s_sql_l.c_str()); 
		_log.Log("\n      Target query: %s", reply->t_sql_l.c_str()); 
	}
	else
	if(reply->_cmd_subtype == SQLDATA_CMD_ALL_COMPLETE)
	{
		char time_fmt[21];
		Str::FormatTime(Os::GetTickCount() - _command_start, time_fmt);
		if(_tables_diff > 0)
		{
			_log.Log("\n\nFound differences (%d table%s):\n", _tables_diff, SUFFIX(_tables_diff));
			for(std::list<std::string>::iterator i = _tables_diff_list.begin(); i != _tables_diff_list.end(); i++)
				_log.Log("\n  %s", i->c_str());
		}
		_log.Log("\n\nSummary:\n\n");
		_log.Log("  Tables:           %d (%d compared, %d failed)\n", _total_tables, _total_tables - _failed_tables, _failed_tables);
		_log.Log("  Equal tables:     %d\n", _tables_equal);
		_log.Log("  Different tables: %d\n", _tables_diff);
		_log.Log("  Validation time:  %s\n", time_fmt);
	}
}
void SqlDataCmd :: CallbackValidationRows ( SqlDataReply * reply ) { if ( reply == NULL ) return ; if ( reply -> _cmd_subtype != SQLDATA_CMD_ALL_COMPLETE ) _log . Log ( " \n " , reply -> _s_name ) ; if ( reply -> _cmd_subtype == SQLDATA_CMD_STARTED ) { _log . Log ( " " , _validate_table_num , _total_tables , reply -> session_id ) ; _validate_table_num ++ ; } else if ( reply -> _cmd_subtype == SQLDATA_CMD_COMPLETE ) { std :: string table_diff ; if ( reply -> _s_rc == -1 || reply -> _t_rc == -1 ) { _log . Log ( " " ) ; _failed_tables ++ ; } else if ( reply -> _s_int1 != reply -> _t_int1 || reply -> _int1 != 0 ) { _log . Log ( " " ) ; _tables_diff ++ ; table_diff = reply -> _s_name ; table_diff += " " ; table_diff += reply -> data2 ; table_diff += " " ; _tables_diff_list . push_back ( table_diff ) ; } else { _log . Log ( " " ) ; _tables_equal ++ ; } char time_fmt [ 21 ] , s_time_fmt [ 21 ] , t_time_fmt [ 21 ] ; Str :: FormatTime ( reply -> _time_spent , time_fmt ) ; Str :: FormatTime ( reply -> _s_time_spent , s_time_fmt ) ; Str :: FormatTime ( reply -> _t_time_spent , t_time_fmt ) ; _log . Log ( " \n " , time_fmt , reply -> session_id ) ; double s_speed_rows = 0 , t_speed_rows = 0 ; if ( reply -> _s_int1 != 0 && reply -> _s_time_spent != 0 ) s_speed_rows = ( ( double ) reply -> _s_int1 ) / ( ( double ) reply -> _s_time_spent ) * 1000.0 ; if ( reply -> _t_int1 != 0 && reply -> _t_time_spent != 0 ) t_speed_rows = ( ( double ) reply -> _t_int1 ) / ( ( double ) reply -> _t_time_spent ) * 1000.0 ; double s_speed_bytes = 0 , t_speed_bytes = 0 ; if ( reply -> _s_bigint1 != 0 && reply -> _s_time_spent != 0 ) s_speed_bytes = ( ( double ) reply -> _s_bigint1 ) / ( ( double ) reply -> _s_time_spent ) * 1000.0 ; if ( reply -> _t_bigint1 != 0 && reply -> _t_time_spent != 0 ) t_speed_bytes = ( ( double ) reply -> _t_bigint1 ) / ( ( double ) reply -> _t_time_spent ) * 1000.0 ; char s_bytes_fmt [ 21 ] , t_bytes_fmt [ 21 ] ; char s_speed_bytes_fmt [ 21 ] , t_speed_bytes_fmt [ 21 ] ; Str :: FormatByteSize ( ( double ) reply -> _s_bigint1 , s_bytes_fmt ) ; Str :: FormatByteSize ( ( double ) reply -> _t_bigint1 , t_bytes_fmt ) ; Str :: FormatByteSize ( s_speed_bytes , s_speed_bytes_fmt ) ; Str :: FormatByteSize ( t_speed_bytes , t_speed_bytes_fmt ) ; _log . Log ( " " ) ; if ( reply -> _s_rc == -1 ) { if ( reply -> s_error == SQL_DBAPI_NOT_EXISTS_ERROR ) _log . Log ( " " ) ; else _log . Log ( " " , reply -> s_native_error_text ) ; } else _log . Log ( " " , reply -> _s_int1 , SUFFIX ( reply -> _s_int1 ) ) ; _log . Log ( " " , s_time_fmt ) ; if ( reply -> _s_int1 > 0 ) _log . Log ( " \n " , s_speed_rows , s_bytes_fmt , s_speed_bytes_fmt ) ; else _log . Log ( " \n " ) ; _log . Log ( " " ) ; if ( reply -> _t_rc == -1 ) { if ( reply -> t_error == SQL_DBAPI_NOT_EXISTS_ERROR ) _log . Log ( " " ) ; else _log . Log ( " " , reply -> t_native_error_text ) ; } else _log . Log ( " " , reply -> _t_int1 , SUFFIX ( reply -> _t_int1 ) ) ; _log . Log ( " " , t_time_fmt ) ; if ( reply -> _t_int1 > 0 ) _log . Log ( " " , t_speed_rows , t_bytes_fmt , t_speed_bytes_fmt ) ; else _log . Log ( " " ) ; if ( reply -> _int1 != 0 ) _log . Log ( " \n " , reply -> _int1 , SUFFIX ( reply -> _int1 ) , reply -> _int2 , reply -> _int3 , SUFFIX ( reply -> _int3 ) , reply -> data2 ) ; _log . Log ( " \n " , reply -> s_sql_l . c_str ( ) ) ; _log . Log ( " \n " , reply -> t_sql_l . c_str ( ) ) ; } else if ( reply -> _cmd_subtype == SQLDATA_CMD_ALL_COMPLETE ) { char time_fmt [ 21 ] ; Str :: FormatTime ( Os :: GetTickCount ( ) - _command_start , time_fmt ) ; if ( _tables_diff > 0 ) { _log . Log ( " \n \n \n " , _tables_diff , SUFFIX ( _tables_diff ) ) ; for ( std :: list < std :: string > :: iterator i = _tables_diff_list . begin ( ) ; i != _tables_diff_list . end ( ) ; i ++ ) _log . Log ( " \n " , i -> c_str ( ) ) ; } _log . Log ( " \n \n \n \n " ) ; _log . Log ( " \n " , _total_tables , _total_tables - _failed_tables , _failed_tables ) ; _log . Log ( " \n " , _tables_equal ) ; _log . Log ( " \n " , _tables_diff ) ; _log . Log ( " \n " , time_fmt ) ; } }
Callback function for table data validation task
Callback function for table data validation task
// Object name // A single table validated // Operation result // There is a difference in row count or different data in rows // The same row count // Format time // Calculate number of rows read per unit of time // Format numbers // Show differences // All tables validated // Format validation time