~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/transaction_log/utilities/transaction_reader.cc

  • Committer: Lee Bieber
  • Date: 2011-01-19 01:50:26 UTC
  • mfrom: (2095.1.5 build)
  • Revision ID: kalebral@gmail.com-20110119015026-j1ukv30cz662e51e
Merge Shrews - Refactor the TransactionServices public interface
Merge Monty - fix bug 583375: support configure option to specify static/dynamic build for a plugin
Merge Shrews - fix bug 702505: transaction_reader utility does not check for errors from statement transformation
Merge Vijay - Convert structs to classes
Merge Joe - 702529: PRINT_TRANSACTION_MESSAGE udf does not output UUID

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
static const char *replace_with_spaces= "\n\r";
52
52
 
53
 
static void printStatement(const message::Statement &statement, string &output)
 
53
static void printErrorMessage(enum message::TransformSqlError err)
 
54
{
 
55
  switch (err)
 
56
  {
 
57
    case message::MISSING_HEADER:
 
58
    {
 
59
      cerr << "Data segment without a header\n";
 
60
      break;
 
61
    }
 
62
    case message::MISSING_DATA:
 
63
    {
 
64
      cerr << "Header segment without a data segment\n";
 
65
      break;
 
66
    }
 
67
    case message::UUID_MISMATCH:
 
68
    {
 
69
      cerr << "UUID on objects did not match\n";
 
70
      break;
 
71
    }
 
72
    default:
 
73
    {
 
74
      cerr << "Unhandled error\n";
 
75
      break;
 
76
    }
 
77
  }
 
78
}
 
79
 
 
80
/**
 
81
 * Transform the given Statement message into a printable SQL string.
 
82
 *
 
83
 * @param[in] statement The Statement protobuf message to transform.
 
84
 * @param[out] output Storage for the printable string.
 
85
 *
 
86
 * @retval true Success
 
87
 * @retval false Error
 
88
 */
 
89
static bool printStatement(const message::Statement &statement, string &output)
54
90
{
55
91
  vector<string> sql_strings;
56
 
 
57
 
  message::transformStatementToSql(statement,
58
 
                                   sql_strings,
59
 
                                   message::DRIZZLE,
60
 
                                   true /* already in transaction */);
 
92
  enum message::TransformSqlError err;
 
93
 
 
94
  err= message::transformStatementToSql(statement,
 
95
                                        sql_strings,
 
96
                                        message::DRIZZLE,
 
97
                                        true /* already in transaction */);
 
98
 
 
99
  if (err != message::NONE)
 
100
  {
 
101
    printErrorMessage(err);
 
102
    return false;
 
103
  }
61
104
 
62
105
  for (vector<string>::iterator sql_string_iter= sql_strings.begin();
63
106
       sql_string_iter != sql_strings.end();
93
136
 
94
137
    output.append(sql + ";\n");
95
138
  }
 
139
  
 
140
  return true;
96
141
}
97
142
 
98
143
static bool isEndStatement(const message::Statement &statement)
284
329
  }
285
330
}
286
331
 
287
 
static void printTransaction(const message::Transaction &transaction,
 
332
/**
 
333
 * Transform the given Transaction message into printable SQL strings.
 
334
 *
 
335
 * @param[in] transaction The Transaction protobuf message to transform.
 
336
 * @param[in] ignore_events If true, Event messages are not output.
 
337
 * @param[in] print_as_raw If true, print as raw protobuf instead of SQL.
 
338
 *
 
339
 * @retval true Success
 
340
 * @retval false Error
 
341
 */
 
342
static bool printTransaction(const message::Transaction &transaction,
288
343
                             bool ignore_events,
289
344
                             bool print_as_raw)
290
345
{
305
360
      else
306
361
        printEvent(transaction.event());
307
362
    }
308
 
    return;
 
363
    return true;
309
364
  }
310
365
 
311
366
  if (print_as_raw)
312
367
  {
313
368
    transaction.PrintDebugString();
314
 
    return;
 
369
    return true;
315
370
  }
316
371
 
317
372
  size_t num_statements= transaction.statement_size();
346
401
      should_commit= false;
347
402
 
348
403
    string output;
349
 
    printStatement(statement, output);
350
 
    
 
404
 
 
405
    if (not printStatement(statement, output))
 
406
    {
 
407
      return false;
 
408
    }
 
409
 
351
410
    if (isEndStatement(statement))
352
411
    {
353
412
      /* A complete, non-segmented statement */
394
453
   */
395
454
  if (should_commit)
396
455
    cout << "COMMIT;" << endl;
 
456
  
 
457
  return true;
397
458
}
398
459
 
399
 
static void processTransactionMessage(TransactionManager &trx_mgr, 
 
460
static bool processTransactionMessage(TransactionManager &trx_mgr, 
400
461
                                      const message::Transaction &transaction, 
401
462
                                      bool summarize,
402
463
                                      bool ignore_events,
432
493
        }
433
494
        else
434
495
        {
435
 
          printTransaction(new_trx, ignore_events, print_as_raw);
 
496
          if (not printTransaction(new_trx, ignore_events, print_as_raw))
 
497
          {
 
498
            return false;
 
499
          }
436
500
        }
437
501
        idx++;
438
502
      }
448
512
      }
449
513
      else
450
514
      {
451
 
        printTransaction(transaction, ignore_events, print_as_raw);
 
515
        if (not printTransaction(transaction, ignore_events, print_as_raw))
 
516
        {
 
517
          return false;
 
518
        }
452
519
      }
453
520
    }
454
521
  }
 
522
  
 
523
  return true;
455
524
}
456
525
 
 
526
/**
 
527
 * @retval  0 Process completed successfully.
 
528
 * @retval -1 Process encountered an error.
 
529
 */
457
530
int main(int argc, char* argv[])
458
531
{
459
532
  GOOGLE_PROTOBUF_VERIFY_VERSION;
577
650
 
578
651
      transaction.ParseFromArray(data, length);
579
652
 
580
 
      processTransactionMessage(trx_mgr, transaction, 
581
 
                                summarize, ignore_events, print_as_raw);
 
653
      if (not processTransactionMessage(trx_mgr, transaction, 
 
654
                                        summarize, ignore_events,
 
655
                                        print_as_raw))
 
656
      {
 
657
        return -1;
 
658
      }
582
659
    }    
583
660
  }
584
661
  else // file based transaction log 
610
687
      {
611
688
        if (opt_transaction_id == transaction_id)
612
689
        {
613
 
          processTransactionMessage(trx_mgr, transaction, summarize, 
614
 
                                    ignore_events, print_as_raw);
 
690
          if (not processTransactionMessage(trx_mgr, transaction, summarize, 
 
691
                                            ignore_events, print_as_raw))
 
692
          {
 
693
            return -1;
 
694
          }
615
695
        }
616
696
        else
617
697
        {
623
703
        /*
624
704
         * No transaction ID given, so process all messages.
625
705
         */
626
 
        processTransactionMessage(trx_mgr, transaction, summarize,
627
 
                                  ignore_events, print_as_raw);
 
706
        if (not processTransactionMessage(trx_mgr, transaction, summarize,
 
707
                                          ignore_events, print_as_raw))
 
708
        {
 
709
          return -1;
 
710
        }
628
711
      }  
629
712
 
630
713
      if (do_checksum)
646
729
    if (error != "EOF")
647
730
    {
648
731
      cerr << error << endl;
649
 
      return 1;
 
732
      return -1;
650
733
    }
651
734
  }
652
735