351
352
cout << "COMMIT;" << endl;
355
static void processTransactionMessage(TransactionManager &trx_mgr,
356
const message::Transaction &transaction,
361
if (not isEndTransaction(transaction))
363
trx_mgr.store(transaction);
367
const message::TransactionContext trx= transaction.transaction_context();
368
uint64_t transaction_id= trx.transaction_id();
371
* If there are any previous Transaction messages for this transaction,
372
* store this one, then output all of them together.
374
if (trx_mgr.contains(transaction_id))
376
trx_mgr.store(transaction);
378
uint32_t size= trx_mgr.getTransactionBufferSize(transaction_id);
383
message::Transaction new_trx;
384
trx_mgr.getTransactionMessage(new_trx, transaction_id, idx);
387
printTransactionSummary(new_trx, ignore_events);
391
printTransaction(new_trx, ignore_events, print_as_raw);
396
/* No longer need this transaction */
397
trx_mgr.remove(transaction_id);
403
printTransactionSummary(transaction, ignore_events);
407
printTransaction(transaction, ignore_events, print_as_raw);
354
413
int main(int argc, char* argv[])
356
415
GOOGLE_PROTOBUF_VERIFY_VERSION;
357
416
int opt_start_pos= 0;
358
417
uint64_t opt_transaction_id= 0;
418
uint64_t opt_start_transaction_id= 0;
419
uint32_t opt_drizzle_port= 0;
420
string current_user, opt_password, opt_protocol, current_host;
421
bool use_drizzle_protocol= false;
361
424
* Setup program options
363
426
po::options_description desc("Program options");
364
427
desc.add_options()
365
428
("help", N_("Display help and exit"))
429
("use-innodb-replication-log", N_("Read from the innodb transaction log"))
430
("user,u", po::value<string>(¤t_user)->default_value(""),
431
N_("User for login if not current user."))
432
("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
433
N_("Port number to use for connection."))
434
("password,P", po::value<string>(&opt_password)->default_value(""),
435
N_("Password to use when connecting to server"))
436
("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
437
N_("The protocol of connection (mysql or drizzle)."))
366
438
("checksum", N_("Perform checksum"))
367
439
("ignore-events", N_("Ignore event messages"))
368
440
("input-file", po::value< vector<string> >(), N_("Transaction log file"))
418
495
bool do_checksum= vm.count("checksum") ? true : false;
496
bool use_innodb_replication_log= vm.count("use-innodb-replication-log") ? true : false;
419
497
bool ignore_events= vm.count("ignore-events") ? true : false;
420
498
bool print_as_raw= vm.count("raw") ? true : false;
422
string filename= vm["input-file"].as< vector<string> >()[0];
424
TransactionFileReader fileReader;
426
if (not fileReader.openFile(filename, opt_start_pos))
428
cerr << fileReader.getErrorString() << endl;
432
message::Transaction transaction;
433
TransactionManager trx_mgr;
434
uint32_t checksum= 0;
436
while (fileReader.getNextTransaction(transaction, &checksum))
438
const message::TransactionContext trx= transaction.transaction_context();
439
uint64_t transaction_id= trx.transaction_id();
442
* If we are given a transaction ID, we only look for that one and
499
bool summarize= vm.count("summarize") ? true : false;
501
if (use_innodb_replication_log)
503
TransactionLogConnection *connection = new TransactionLogConnection(current_host, opt_drizzle_port,
504
current_user, opt_password, use_drizzle_protocol);
445
507
if (vm.count("transaction-id"))
447
if (opt_transaction_id == transaction_id)
448
printTransaction(transaction, ignore_events, print_as_raw);
454
* No transaction ID given, so process all messages.
509
query_string.append("SELECT transaction_message_binary, transaction_length FROM DATA_DICTIONARY.INNODB_REPLICATION_LOG WHERE transaction_id=");
510
query_string.append(boost::lexical_cast<string>(opt_transaction_id));
512
else if (vm.count("start-transaction-id"))
514
query_string.append("SELECT transaction_message_binary, transaction_length FROM DATA_DICTIONARY.INNODB_REPLICATION_LOG WHERE transaction_id >=");
515
query_string.append(boost::lexical_cast<string>(opt_start_transaction_id));
516
query_string.append(" ORDER BY transaction_id ASC");
458
if (not isEndTransaction(transaction))
520
query_string= "SELECT transaction_message_binary, transaction_length FROM DATA_DICTIONARY.INNODB_REPLICATION_LOG";
523
drizzle_result_st *result= connection->query(query_string);
526
while ((row= drizzle_row_next(result)))
528
char* data= (char*)row[0];
529
uint64_t length= (row[1]) ? boost::lexical_cast<uint64_t>(row[1]) : 0;
531
message::Transaction transaction;
532
TransactionManager trx_mgr;
534
transaction.ParseFromArray(data, length);
536
processTransactionMessage(trx_mgr, transaction,
537
summarize, ignore_events, print_as_raw);
540
else // file based transaction log
542
string filename= vm["input-file"].as< vector<string> >()[0];
544
TransactionFileReader fileReader;
546
if (not fileReader.openFile(filename, opt_start_pos))
548
cerr << fileReader.getErrorString() << endl;
552
message::Transaction transaction;
553
TransactionManager trx_mgr;
554
uint32_t checksum= 0;
556
while (fileReader.getNextTransaction(transaction, &checksum))
558
const message::TransactionContext trx= transaction.transaction_context();
559
uint64_t transaction_id= trx.transaction_id();
562
* If we are given a transaction ID, we only look for that one and
565
if (vm.count("transaction-id"))
460
trx_mgr.store(transaction);
567
if (opt_transaction_id == transaction_id)
569
processTransactionMessage(trx_mgr, transaction, summarize,
570
ignore_events, print_as_raw);
465
* If there are any previous Transaction messages for this transaction,
466
* store this one, then output all of them together.
580
* No transaction ID given, so process all messages.
468
if (trx_mgr.contains(transaction_id))
470
trx_mgr.store(transaction);
472
uint32_t size= trx_mgr.getTransactionBufferSize(transaction_id);
477
message::Transaction new_trx;
478
trx_mgr.getTransactionMessage(new_trx, transaction_id, idx);
479
if (vm.count("summarize"))
480
printTransactionSummary(new_trx, ignore_events);
482
printTransaction(new_trx, ignore_events, print_as_raw);
486
/* No longer need this transaction */
487
trx_mgr.remove(transaction_id);
491
if (vm.count("summarize"))
492
printTransactionSummary(transaction, ignore_events);
494
printTransaction(transaction, ignore_events, print_as_raw);
582
processTransactionMessage(trx_mgr, transaction, summarize,
583
ignore_events, print_as_raw);
588
uint32_t calculated= fileReader.checksumLastReadTransaction();
589
if (checksum != calculated)
591
cerr << _("Checksum failed. Wanted ")
497
} /* end ! vm.count("transaction-id") */
600
string error= fileReader.getErrorString();
501
uint32_t calculated= fileReader.checksumLastReadTransaction();
502
if (checksum != calculated)
504
cerr << _("Checksum failed. Wanted ")
604
cerr << error << endl;
514
string error= fileReader.getErrorString();
518
cerr << error << endl;