~mysqlatfacebook/mysqlatfacebook/tools

« back to all changes in this revision

Viewing changes to faker/binlog.c

  • Committer: Domas Mituzas
  • Date: 2013-04-22 04:08:55 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: domas@fb.com-20130422040855-zcmp44juphhixcr8
* Handle end-of-file better
* Handle reconnects better
* Add more configuration options
* Support MySQL 5.6 checksummed binlog format

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    binlog->vbuffer = malloc(BINLOG_BUFFER);
35
35
    setvbuf(fd, binlog->vbuffer, _IOFBF, BINLOG_BUFFER);
36
36
 
 
37
    guint32 magic;
 
38
    if (!fread(&magic, sizeof(magic), 1, binlog->fd)
 
39
        || magic != 1852400382)
 
40
        goto err;
 
41
 
37
42
    if (!fread(&binlog->fde, sizeof(binlog->fde), 1, binlog->fd)
38
 
        || binlog->fde.magic != 1852400382
39
43
        || binlog->fde.event_type != FORMAT_DESCRIPTION_EVENT
40
44
        || binlog->fde.binlog_version != 4)
41
45
        goto err;
42
46
 
 
47
    int blhl = binlog->fde.event_length - sizeof(binlog->fde);
 
48
    binlog->header_lengths_length = blhl;
 
49
    binlog->header_lengths = malloc(blhl);
 
50
 
 
51
    if (!fread(binlog->header_lengths, blhl, 1, binlog->fd))
 
52
        goto err;
 
53
 
 
54
    // None on pre-5.6 condition, we default to 4 bytes for all unknown algos
 
55
    binlog->checksum_algo = blhl < 40 ? 0 : binlog->header_lengths[blhl - 5];
 
56
 
 
57
    if (binlog->checksum_algo)
 
58
        binlog->checksum_size = 4;
 
59
 
43
60
    binlog->filename = filename;
44
61
    binlog->position = binlog->fde.next_position;
45
62
 
84
101
            qeh = binlog->buffer;
85
102
            char *db = binlog->buffer + sizeof(*qeh) + qeh->status_length;
86
103
            void *query = db + qeh->db_length + 1;
87
 
            guint32 query_length = body_length - (query - binlog->buffer);
 
104
            guint32 query_length =
 
105
                body_length - (query - binlog->buffer) - binlog->checksum_size;
88
106
 
89
107
            // Fill in event structure, return it too
90
108
            event = g_new0(EVENT, 1);
104
122
 
105
123
            binlog->position += eh.event_length;
106
124
            return event;
107
 
        case STOP_EVENT:
108
 
        case ROTATE_EVENT:
109
 
            return NULL;
110
125
        case INTVAR_EVENT:
111
126
            iv = binlog->buffer;
112
127
            switch (iv->type) {