~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/transaction_reader.cc

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include <drizzled/global.h>
25
25
#include <drizzled/gettext.h>
 
26
#include <drizzled/replication_services.h>
 
27
#include <drizzled/hash/crc32.h>
26
28
#include <sys/types.h>
27
29
#include <sys/stat.h>
28
30
#include <fcntl.h>
29
31
#include <iostream>
30
32
#include <string>
 
33
#include <algorithm>
31
34
#include <vector>
32
35
#include <unistd.h>
33
36
#include <drizzled/message/transaction.pb.h>
42
45
 
43
46
static void printStatement(const message::Statement &statement)
44
47
{
45
 
  cout << "/* Start Timestamp: " << statement.start_timestamp() << " ";
46
 
  cout << " End Timestamp: " << statement.end_timestamp() << " */" << endl;
47
 
 
48
48
  vector<string> sql_strings;
49
49
 
50
50
  message::transformStatementToSql(statement, sql_strings, message::DRIZZLE);
70
70
{
71
71
  const message::TransactionContext trx= transaction.transaction_context();
72
72
 
73
 
  cout << "/* SERVER ID: " << trx.server_id() << " TRX ID: " << trx.transaction_id() << " */ " << endl;
74
 
 
75
73
  size_t num_statements= transaction.statement_size();
76
74
  size_t x;
77
75
 
87
85
  GOOGLE_PROTOBUF_VERIFY_VERSION;
88
86
  int file;
89
87
 
90
 
  if (argc != 2)
 
88
  if (argc < 2 || argc > 3)
91
89
  {
92
 
    fprintf(stderr, _("Usage: %s TRANSACTION_LOG\n"), argv[0]);
 
90
    fprintf(stderr, _("Usage: %s TRANSACTION_LOG [--checksum] \n"), argv[0]);
93
91
    return -1;
94
92
  }
95
93
 
102
100
    return -1;
103
101
  }
104
102
 
 
103
  bool do_checksum= false;
 
104
 
 
105
  if (argc == 3)
 
106
  {
 
107
    string checksum_arg(argv[2]);
 
108
    transform(checksum_arg.begin(), checksum_arg.end(), checksum_arg.begin(), ::tolower);
 
109
 
 
110
    if ("--checksum" == checksum_arg)
 
111
      do_checksum= true;
 
112
  }
 
113
 
105
114
  protobuf::io::ZeroCopyInputStream *raw_input= new protobuf::io::FileInputStream(file);
106
115
  protobuf::io::CodedInputStream *coded_input= new protobuf::io::CodedInputStream(raw_input);
107
116
 
108
117
  char *buffer= NULL;
109
118
  char *temp_buffer= NULL;
110
 
  uint64_t length= 0;
111
 
  uint64_t previous_length= 0;
 
119
  uint32_t length= 0;
 
120
  uint32_t previous_length= 0;
 
121
  uint32_t checksum= 0;
112
122
  bool result= true;
 
123
  uint32_t message_type= 0;
113
124
 
114
125
  /* Read in the length of the command */
115
 
  while (result == true && coded_input->ReadLittleEndian64(&length) == true)
 
126
  while (result == true && 
 
127
         coded_input->ReadLittleEndian32(&message_type) == true &&
 
128
         coded_input->ReadLittleEndian32(&length) == true)
116
129
  {
117
 
    if (length > SIZE_MAX)
118
 
    {
119
 
      fprintf(stderr, _("Attempted to read record bigger than SIZE_MAX\n"));
 
130
    if (message_type != ReplicationServices::TRANSACTION)
 
131
    {
 
132
      fprintf(stderr, _("Found a non-transaction message in log.  Currently, not supported.\n"));
 
133
      exit(1);
 
134
    }
 
135
 
 
136
    if (length > INT_MAX)
 
137
    {
 
138
      fprintf(stderr, _("Attempted to read record bigger than INT_MAX\n"));
120
139
      exit(1);
121
140
    }
122
141
 
126
145
       * First time around...just malloc the length.  This block gets rid
127
146
       * of a GCC warning about uninitialized temp_buffer.
128
147
       */
129
 
      temp_buffer= (char *) malloc((size_t) length);
 
148
      temp_buffer= (char *) malloc(static_cast<size_t>(length));
130
149
    }
131
150
    /* No need to allocate if we have a buffer big enough... */
132
151
    else if (length > previous_length)
133
152
    {
134
 
      temp_buffer= (char *) realloc(buffer, (size_t) length);
 
153
      temp_buffer= (char *) realloc(buffer, static_cast<size_t>(length));
135
154
    }
136
155
 
137
156
    if (temp_buffer == NULL)
153
172
      break;
154
173
    }
155
174
 
156
 
    result= transaction.ParseFromArray(buffer, static_cast<size_t>(length));
 
175
    result= transaction.ParseFromArray(buffer, static_cast<int32_t>(length));
157
176
    if (result == false)
158
177
    {
159
178
      fprintf(stderr, _("Unable to parse command. Got error: %s.\n"), transaction.InitializationErrorString().c_str());
165
184
    /* Print the transaction */
166
185
    printTransaction(transaction);
167
186
 
 
187
    /* Skip 4 byte checksum */
 
188
    coded_input->ReadLittleEndian32(&checksum);
 
189
 
 
190
    if (do_checksum)
 
191
    {
 
192
      if (checksum != drizzled::hash::crc32(buffer, static_cast<size_t>(length)))
 
193
      {
 
194
        fprintf(stderr, _("Checksum failed. Wanted %" PRIu32 " got %" PRIu32 "\n"), checksum, drizzled::hash::crc32(buffer, static_cast<size_t>(length)));
 
195
      }
 
196
    }
 
197
 
168
198
    previous_length= length;
169
199
  }
170
200
  if (buffer)