~drizzle-trunk/libdrizzle/jenkins-Libdrizzle-21

« back to all changes in this revision

Viewing changes to libdrizzle/binlog.cc

  • Committer: Continuous Integration
  • Date: 2012-12-29 18:57:32 UTC
  • mfrom: (69.1.2 5.1-binlog-csums)
  • Revision ID: ci@drizzle.org-20121229185732-dvsy9poxj16ho9sa
Merge lp:~linuxjedi/libdrizzle/5.1-binlog-csums Build: jenkins-Libdrizzle-18

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
#include "config.h"
39
39
#include "libdrizzle/common.h"
 
40
#include <zlib.h>
40
41
 
41
42
drizzle_result_st *drizzle_start_binlog(drizzle_st *con,
42
43
                                            uint32_t server_id,
47
48
  uint8_t data[128];
48
49
  uint8_t *ptr;
49
50
  uint8_t len= 0, fn_len= 0;
 
51
  drizzle_result_st *result;
 
52
 
 
53
  // Hack in 5.6 to say that client support checksums
 
54
  result= drizzle_query_str(con, "SET @master_binlog_checksum='NONE'", ret_ptr);
 
55
  drizzle_result_free(result);
 
56
  if (*ret_ptr != DRIZZLE_RETURN_OK)
 
57
  {
 
58
    return NULL;
 
59
  }
50
60
 
51
61
  ptr= data;
52
62
 
297
307
      con->buffer_size-= 27;
298
308
      con->packet_size-= 27;
299
309
      binlog_event->data= (uint8_t*)realloc(binlog_event->data, binlog_event->length);
300
 
      memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length);
 
310
      /* 5.6.1 or higher is automatic checksums on */
 
311
      if (binlog_event->type == DRIZZLE_EVENT_TYPE_FORMAT_DESCRIPTION)
 
312
      {
 
313
        if (strncmp((const char*)con->buffer_ptr + 2, DRIZZLE_BINLOG_CHECKSUM_VERSION, strlen(DRIZZLE_BINLOG_CHECKSUM_VERSION)) <= 0)
 
314
        {
 
315
          con->result->binlog_checksums= true;
 
316
        }
 
317
      }
 
318
      /* A checksum is basically a CRC32 at the end of the event data (4 bytes) */
 
319
      if (con->result->binlog_checksums)
 
320
      {
 
321
        memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length - DRIZZLE_BINLOG_CRC32_LEN);
 
322
      }
 
323
      else
 
324
      {
 
325
        memcpy(binlog_event->data, con->buffer_ptr, binlog_event->length);
 
326
      }
301
327
      con->buffer_ptr+= binlog_event->length;
302
328
      con->buffer_size-= binlog_event->length;
303
329
      con->packet_size-= binlog_event->length;
304
 
    }
 
330
      /* Remove the CRC32 from the event length */
 
331
      if (con->result->binlog_checksums)
 
332
      {
 
333
        binlog_event->length-= DRIZZLE_BINLOG_CRC32_LEN;
 
334
      }
 
335
    }
 
336
 
 
337
    /* Check if checksum is correct
 
338
     * each event is checksummed individually, the checksum is the last 4 bytes
 
339
     * of the binary log event
 
340
     * */
 
341
    if (con->result->binlog_checksums)
 
342
    {
 
343
      uint32_t event_crc;
 
344
      memcpy(&binlog_event->checksum, binlog_event->raw_data + (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN), DRIZZLE_BINLOG_CRC32_LEN);
 
345
      event_crc= crc32(0, binlog_event->raw_data, (binlog_event->raw_length - DRIZZLE_BINLOG_CRC32_LEN));
 
346
      if (event_crc != binlog_event->checksum)
 
347
      {
 
348
        drizzle_set_error(con, __func__, "CRC doesn't match: 0x%lX, 0x%lX", event_crc, binlog_event->checksum);
 
349
        return DRIZZLE_RETURN_BINLOG_CRC;
 
350
      }
 
351
    }
 
352
 
305
353
    if (con->packet_size != 0)
306
354
    {
307
355
      drizzle_set_error(con, "drizzle_state_binlog_read",