From: Date: June 4 2007 11:02am Subject: bk commit into 5.0 tree (Justin.He:1.2476) BUG#27640 List-Archive: http://lists.mysql.com/commits/28030 X-Bug: 27640 Message-Id: <200706040902.l54926VP012666@dev3-240.dev.cn.tlan> Below is the list of changes that have just been committed into a local 5.0 repository of justin.he. When justin.he does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-06-04 17:01:59+08:00, Justin.He@stripped +2 -0 Bug #27640 backup id not displayed in the output of "ndb_mgm start backup wait completed" ndb/src/mgmclient/CommandInterpreter.cpp@stripped, 2007-06-04 17:01:57+08:00, Justin.He@stripped +93 -67 add a printLogEvent() function to print log event; filter "" with ndb_logevent_get_next() in event_thread_run(); filter "" with ndb_logevent_get_next() in executeStartBackup() and make executeStartBackup() same in both 5.0 and 5.1 ndb/src/mgmclient/Makefile.am@stripped, 2007-06-04 17:01:57+08:00, Justin.He@stripped +2 -1 add link to use nbd_logevent_get_next() # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: Justin.He # Host: dev3-240.dev.cn.tlan # Root: /home/justin.he/mysql/mysql-5.0/bug27640-5.0-ndb-bj --- 1.75/ndb/src/mgmclient/CommandInterpreter.cpp 2007-06-04 17:02:06 +08:00 +++ 1.76/ndb/src/mgmclient/CommandInterpreter.cpp 2007-06-04 17:02:06 +08:00 @@ -125,7 +125,7 @@ int executeStatus(int processId, const char* parameters, bool all); int executeEventReporting(int processId, const char* parameters, bool all); int executeDumpState(int processId, const char* parameters, bool all); - int executeStartBackup(char * parameters); + int executeStartBackup(char * parameters, bool interactive); int executeAbortBackup(char * parameters); int executeStop(Vector &command_list, unsigned command_pos, int *node_ids, int no_of_nodes); @@ -768,6 +768,41 @@ } } +/* +* print log event from mgmsrv to console screen +*/ +static void +printLogEvent(struct ndb_logevent* event) +{ + switch (event->type) { + case NDB_LE_BackupStarted: + ndbout_c("Backup %d started from node %d", + event->BackupStarted.backup_id, event->BackupStarted.starting_node); + break; + case NDB_LE_BackupFailedToStart: + ndbout_c("Backup request from %d failed to start. Error: %d", + event->BackupFailedToStart.starting_node, event->BackupFailedToStart.error); + break; + case NDB_LE_BackupCompleted: + ndbout_c("Backup %u started from node %u completed\n" + " StartGCP: %u StopGCP: %u\n" + " #Records: %u #LogRecords: %u\n" + " Data: %u bytes Log: %u bytes", + event->BackupCompleted.backup_id, event->BackupCompleted.starting_node, + event->BackupCompleted.start_gci, event->BackupCompleted.stop_gci, + event->BackupCompleted.n_records, event->BackupCompleted.n_log_records, + event->BackupCompleted.n_bytes, event->BackupCompleted.n_log_bytes); + break; + case NDB_LE_BackupAborted: + ndbout_c("Backup %d started from %d has been aborted. Error: %d", + event->BackupAborted.backup_id, event->BackupAborted.starting_node, + event->BackupAborted.error); + break; + default: + break; + } +} + //***************************************************************************** //***************************************************************************** @@ -784,27 +819,24 @@ int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 1, NDB_MGM_EVENT_CATEGORY_STARTUP, 0 }; - int fd = ndb_mgm_listen_event(handle, filter); - if (fd != NDB_INVALID_SOCKET) + + NdbLogEventHandle log_handle= NULL; + struct ndb_logevent log_event; + + log_handle= ndb_mgm_create_logevent_handle(handle, filter); + if (log_handle) { do_event_thread= 1; - char *tmp= 0; - char buf[1024]; - SocketInputStream in(fd,10); do { - if (tmp == 0) NdbSleep_MilliSleep(10); - if((tmp = in.gets(buf, 1024))) + if (ndb_logevent_get_next(log_handle, &log_event, 2000) <= 0) { - const char ping_token[]= ""; - if (memcmp(ping_token,tmp,sizeof(ping_token)-1)) - if(tmp && strlen(tmp)) - { - Guard g(printmutex); - ndbout << tmp; - } + NdbSleep_MilliSleep(10); + continue; } + Guard g(printmutex); + printLogEvent(&log_event); } while(do_event_thread); - NDB_CLOSE_SOCKET(fd); + ndb_mgm_destroy_logevent_handle(&log_handle); } else { @@ -1054,7 +1086,7 @@ else if(strcasecmp(firstToken, "START") == 0 && allAfterFirstToken != NULL && strncasecmp(allAfterFirstToken, "BACKUP", sizeof("BACKUP") - 1) == 0){ - m_error= executeStartBackup(allAfterFirstToken); + m_error= executeStartBackup(allAfterFirstToken, interactive); DBUG_RETURN(true); } else if(strcasecmp(firstToken, "ABORT") == 0 && @@ -2531,20 +2563,11 @@ * Backup *****************************************************************************/ int -CommandInterpreter::executeStartBackup(char* parameters) +CommandInterpreter::executeStartBackup(char* parameters, bool interactive) { struct ndb_mgm_reply reply; unsigned int backupId; -#if 0 - int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; - int fd = ndb_mgm_listen_event(m_mgmsrv, filter); - if (fd < 0) - { - ndbout << "Initializing start of backup failed" << endl; - printError(); - return fd; - } -#endif + Vector args; { BaseString(parameters).split(args); @@ -2557,25 +2580,20 @@ int sz= args.size(); int result; - if (sz == 2 && - args[1] == "NOWAIT") + int flags = 2; + if (sz == 2 && args[1] == "NOWAIT") { - result = ndb_mgm_start_backup(m_mgmsrv, 0, &backupId, &reply); + flags = 0; } - else if (sz == 1 || - (sz == 3 && - args[1] == "WAIT" && - args[2] == "COMPLETED")) + else if (sz == 1 || (sz == 3 && args[1] == "WAIT" && args[2] == "COMPLETED")) { + flags = 2; ndbout_c("Waiting for completed, this may take several minutes"); - result = ndb_mgm_start_backup(m_mgmsrv, 2, &backupId, &reply); } - else if (sz == 3 && - args[1] == "WAIT" && - args[2] == "STARTED") + else if (sz == 3 && args[1] == "WAIT" && args[2] == "STARTED") { ndbout_c("Waiting for started, this may take several minutes"); - result = ndb_mgm_start_backup(m_mgmsrv, 1, &backupId, &reply); + flags = 1; } else { @@ -2583,45 +2601,53 @@ return -1; } + /** + * If interactive...event listner is already running + */ + NdbLogEventHandle log_handle= NULL; + struct ndb_logevent log_event; + if (flags == 2 && !interactive) + { + int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0, 0 }; + log_handle = ndb_mgm_create_logevent_handle(m_mgmsrv, filter); + if (!log_handle) + { + ndbout << "Initializing start of backup failed" << endl; + printError(); + return -1; + } + } + result = ndb_mgm_start_backup(m_mgmsrv, flags, &backupId, &reply); + if (result != 0) { ndbout << "Backup failed" << endl; printError(); -#if 0 - close(fd); -#endif + + if (log_handle) + ndb_mgm_destroy_logevent_handle(&log_handle); return result; } -#if 0 - ndbout_c("Waiting for completed, this may take several minutes"); - char *tmp; - char buf[1024]; + + if (log_handle && !interactive) { - SocketInputStream in(fd); int count = 0; do { - tmp = in.gets(buf, 1024); - if(tmp) + if (ndb_logevent_get_next(log_handle, &log_event, 2000) <= 0) { - ndbout << tmp; - unsigned int id; - if(sscanf(tmp, "%*[^:]: Backup %d ", &id) == 1 && id == backupId){ - count++; - } + continue; + } + else + { + count++; + Guard g(m_print_mutex); + printLogEvent(&log_event); } - } while(count < 2); + } while(count < 2 && + (log_event.type == NDB_LE_BackupStarted || + log_event.type == NDB_LE_BackupCompleted)); + ndb_mgm_destroy_logevent_handle(&log_handle); } - SocketInputStream in(fd, 10); - do { - tmp = in.gets(buf, 1024); - if(tmp && tmp[0] != 0) - { - ndbout << tmp; - } - } while(tmp && tmp[0] != 0); - - close(fd); -#endif return 0; } --- 1.18/ndb/src/mgmclient/Makefile.am 2007-06-04 17:02:06 +08:00 +++ 1.19/ndb/src/mgmclient/Makefile.am 2007-06-04 17:02:06 +08:00 @@ -21,7 +21,8 @@ ../common/logger/liblogger.la \ ../common/portlib/libportlib.la \ ../common/util/libgeneral.la \ - ../common/portlib/libportlib.la + ../common/portlib/libportlib.la \ + ../common/debugger/libtrace.la ndb_mgm_SOURCES = main.cpp