24
24
#include "config.h"
25
#include <drizzled/definitions.h>
26
#include <drizzled/gettext.h>
27
#include <drizzled/replication_services.h>
28
#include <drizzled/algorithm/crc32.h>
29
25
#include <sys/types.h>
30
26
#include <sys/stat.h>
32
28
#include <limits.h>
35
30
#include <iostream>
37
32
#include <algorithm>
39
34
#include <unistd.h>
40
#include <drizzled/message/transaction.pb.h>
41
#include <drizzled/message/statement_transform.h>
42
#include <drizzled/message/transaction_manager.h>
43
#include <drizzled/util/convert.h>
35
#include "drizzled/definitions.h"
36
#include "drizzled/gettext.h"
37
#include "drizzled/replication_services.h"
38
#include "drizzled/algorithm/crc32.h"
39
#include "drizzled/message/transaction.pb.h"
40
#include "drizzled/message/statement_transform.h"
41
#include "drizzled/message/transaction_manager.h"
42
#include "drizzled/util/convert.h"
45
44
#include <google/protobuf/io/coded_stream.h>
46
45
#include <google/protobuf/io/zero_copy_stream_impl.h>
248
260
("help", N_("Display help and exit"))
249
261
("checksum", N_("Perform checksum"))
250
262
("ignore-events", N_("Ignore event messages"))
251
("input-file", po::value< vector<string> >(), N_("Transaction log file"));
263
("input-file", po::value< vector<string> >(), N_("Transaction log file"))
264
("raw", N_("Print raw Protobuf messages instead of SQL"))
266
po::value<int>(&opt_start_pos),
267
N_("Start reading from the given file position"))
269
po::value<uint64_t>(&opt_transaction_id),
270
N_("Only output for the given transaction ID"));
254
273
* We allow one positional argument that will be transaction file name
271
290
if (vm.count("help") || not vm.count("input-file"))
273
fprintf(stderr, _("Usage: %s [options] TRANSACTION_LOG \n"),
275
fprintf(stderr, _("OPTIONS:\n"));
276
fprintf(stderr, _("--help : Display help and exit\n"));
277
fprintf(stderr, _("--checksum : Perform checksum\n"));
278
fprintf(stderr, _("--ignore-events : Ignore event messages\n"));
292
cerr << desc << endl;
297
* Specifying both a transaction ID and a start position
300
if (vm.count("start-pos") && vm.count("transaction-id"))
302
cerr << _("Cannot use --start-pos and --transaction-id together\n");
282
306
bool do_checksum= vm.count("checksum") ? true : false;
283
307
bool ignore_events= vm.count("ignore-events") ? true : false;
308
bool print_as_raw= vm.count("raw") ? true : false;
285
310
string filename= vm["input-file"].as< vector<string> >()[0];
286
file= open(filename.c_str(), O_RDONLY);
311
int file= open(filename.c_str(), O_RDONLY);
289
fprintf(stderr, _("Cannot open file: %s\n"), filename.c_str());
314
cerr << _("Cannot open file: ") << filename << endl;
351
386
char errmsg[STRERROR_MAX];
352
387
strerror_r(errno, errmsg, sizeof(errmsg));
353
fprintf(stderr, _("Could not read transaction message.\n"));
354
fprintf(stderr, _("GPB ERROR: %s.\n"), errmsg);
388
cerr << _("Could not read transaction message.\n");
389
cerr << _("GPB ERROR: ") << errmsg << endl;;
356
391
hexdump.reserve(length * 4);
357
392
bytesToHexdumpFormat(hexdump, reinterpret_cast<const unsigned char *>(buffer), length);
358
fprintf(stderr, _("HEXDUMP:\n\n%s\n"), hexdump.c_str());
393
cerr << _("HEXDUMP:\n\n") << hexdump << endl;
362
397
result= transaction.ParseFromArray(buffer, static_cast<int32_t>(length));
363
398
if (result == false)
365
fprintf(stderr, _("Unable to parse command. Got error: %s.\n"), transaction.InitializationErrorString().c_str());
400
cerr << _("Unable to parse command. Got error: ")
401
<< transaction.InitializationErrorString() << endl;
366
402
if (buffer != NULL)
369
405
hexdump.reserve(length * 4);
370
406
bytesToHexdumpFormat(hexdump, reinterpret_cast<const unsigned char *>(buffer), length);
371
fprintf(stderr, _("HEXDUMP:\n\n%s\n"), hexdump.c_str());
407
cerr << _("HEXDUMP:\n\n") << hexdump << endl;
376
if (not isEndTransaction(transaction))
412
const message::TransactionContext trx= transaction.transaction_context();
413
uint64_t transaction_id= trx.transaction_id();
416
* If we are given a transaction ID, we only look for that one and
419
if (vm.count("transaction-id"))
378
trx_mgr.store(transaction);
421
if (opt_transaction_id == transaction_id)
423
printTransaction(transaction, ignore_events, print_as_raw);
427
/* Need to get the checksum bytes out of stream */
428
coded_input->ReadLittleEndian32(&checksum);
429
previous_length = length;
435
* No transaction ID given, so process all messages.
382
const message::TransactionContext trx= transaction.transaction_context();
383
uint64_t transaction_id= trx.transaction_id();
386
* If there are any previous Transaction messages for this transaction,
387
* store this one, then output all of them together.
389
if (trx_mgr.contains(transaction_id))
439
if (not isEndTransaction(transaction))
391
441
trx_mgr.store(transaction);
393
uint32_t size= trx_mgr.getTransactionBufferSize(transaction_id);
398
message::Transaction new_trx;
399
trx_mgr.getTransactionMessage(new_trx, transaction_id, idx);
400
printTransaction(new_trx, ignore_events);
404
/* No longer need this transaction */
405
trx_mgr.remove(transaction_id);
409
printTransaction(transaction, ignore_events);
446
* If there are any previous Transaction messages for this transaction,
447
* store this one, then output all of them together.
449
if (trx_mgr.contains(transaction_id))
451
trx_mgr.store(transaction);
453
uint32_t size= trx_mgr.getTransactionBufferSize(transaction_id);
458
message::Transaction new_trx;
459
trx_mgr.getTransactionMessage(new_trx, transaction_id, idx);
460
printTransaction(new_trx, ignore_events, print_as_raw);
464
/* No longer need this transaction */
465
trx_mgr.remove(transaction_id);
469
printTransaction(transaction, ignore_events, print_as_raw);
472
} /* end ! vm.count("transaction-id") */
413
474
/* Skip 4 byte checksum */
414
475
coded_input->ReadLittleEndian32(&checksum);