~drizzle-developers/ubuntu/karmic/drizzle/ppa

« back to all changes in this revision

Viewing changes to plugin/blitzdb/ha_blitz.cc

  • Committer: Monty Taylor
  • Date: 2010-11-10 22:59:29 UTC
  • mfrom: (1308.1.27 ubuntu)
  • Revision ID: mordred@inaugust.com-20101110225929-fd7pqkg4xtuidm10
* New upstream release.
* New upstream release.
* drizzledump.1 manpage shipping in tarball now.
* Removed quilt patches for things applied upstream.
* Added support for RabbitMQ plugin.
* Added support for libnotify error message plugin.
* Added build depend on libboost-iostreams-dev.
* Karmic PPA

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
  BlitzData blitz_table;
169
169
  uint32_t nkeys;
170
170
 
 
171
  BlitzData dict;
 
172
  int ecode;
 
173
  /* Write the table definition to system table. */
 
174
  if ((ecode = dict.open_system_table(from.getPath(), HDBOWRITER)) != 0)
 
175
    return ecode;
 
176
 
 
177
  drizzled::message::Table proto;
 
178
  char *proto_string;
 
179
  int proto_string_len;
 
180
 
 
181
  proto_string = dict.get_system_entry(BLITZ_TABLE_PROTO_KEY.c_str(),
 
182
                                       BLITZ_TABLE_PROTO_KEY.length(),
 
183
                                       &proto_string_len);
 
184
 
 
185
  if (proto_string == NULL) {
 
186
    return ENOMEM;
 
187
  }
 
188
 
 
189
  if (!proto.ParseFromArray(proto_string, proto_string_len)) {
 
190
    free(proto_string);
 
191
    return HA_ERR_CRASHED_ON_USAGE;
 
192
  }
 
193
 
 
194
  free(proto_string);
 
195
 
 
196
  proto.set_name(to.getTableName());
 
197
  proto.set_schema(to.getSchemaName());
 
198
  proto.set_catalog(to.getCatalogName());
 
199
 
 
200
  if (!dict.write_table_definition(proto)) {
 
201
    dict.close_system_table();
 
202
    return HA_ERR_CRASHED_ON_USAGE;
 
203
  }
 
204
 
 
205
  dict.close_system_table();
 
206
 
171
207
  /* Find out the number of indexes in this table. This information
172
208
     is required because BlitzDB creates a file for each indexes.*/
173
209
  if (blitz_table.open_data_table(from.getPath().c_str(), HDBOREADER) != 0)
1104
1140
      *pos++ = 1;
1105
1141
    }
1106
1142
 
1107
 
    end = key_part->field->pack(pos, row + key_part->offset);
1108
 
    offset = end - pos;
1109
 
    pos += offset;
 
1143
    /* Here we normalize VARTEXT1 to VARTEXT2 for simplicity. */
 
1144
    if (key_part->type == HA_KEYTYPE_VARTEXT1) {
 
1145
      /* Extract the length of the string from the row. */
 
1146
      uint16_t data_len = *(uint8_t *)(row + key_part->offset);
 
1147
 
 
1148
      /* Copy the length of the string. Use 2 bytes. */
 
1149
      int2store(pos, data_len);
 
1150
      pos += sizeof(data_len);
 
1151
 
 
1152
      /* Copy the string data */
 
1153
      memcpy(pos, row + key_part->offset + sizeof(uint8_t), data_len);
 
1154
      pos += data_len;
 
1155
    } else {
 
1156
      end = key_part->field->pack(pos, row + key_part->offset);
 
1157
      offset = end - pos;
 
1158
      pos += offset;
 
1159
    }
1110
1160
  }
1111
1161
 
1112
1162
  return ((char *)pos - pack_to);
1154
1204
 
1155
1205
  for (; key_part != key_part_end; key_part++) {
1156
1206
    if (key_part->null_bit) {
 
1207
      pos++;
1157
1208
      rv++;
1158
1209
      if (*key == 0)
1159
1210
        continue;
1160
1211
    }
1161
1212
 
1162
 
    if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1163
 
      len = *(uint8_t *)pos;
1164
 
      rv += len + sizeof(uint8_t);
1165
 
    } else if (key_part->type == HA_KEYTYPE_VARTEXT2) {
 
1213
    if (key_part->type == HA_KEYTYPE_VARTEXT1 ||
 
1214
        key_part->type == HA_KEYTYPE_VARTEXT2) {
1166
1215
      len = uint2korr(pos);
1167
1216
      rv += len + sizeof(uint16_t);
1168
1217
    } else {
1206
1255
        continue;
1207
1256
    }
1208
1257
 
1209
 
    /* This is a temporary workaround for a bug in Drizzle's VARCHAR
1210
 
       where a 1 byte representable length varchar's actual data is
1211
 
       positioned 2 bytes ahead of the beginning of the buffer. The
1212
 
       correct behavior is to be positioned 1 byte ahead. Furthermore,
1213
 
       this is only applicable with varchar keys on READ. */
 
1258
    /* Normalize a VARTEXT1 key to VARTEXT2. */
1214
1259
    if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1215
 
      /* Dereference the 1 byte length of the value. */
1216
 
      uint8_t varlen = *(uint8_t *)key_pos;
1217
 
      *keybuf_pos++ = varlen;
1218
 
 
1219
 
      /* Read the value by skipping 2 bytes. This is the workaround. */
1220
 
      memcpy(keybuf_pos, key_pos + sizeof(uint16_t), varlen);
1221
 
      offset = (sizeof(uint8_t) + varlen);
1222
 
      keybuf_pos += varlen;
 
1260
      uint16_t str_len = *(uint16_t *)key_pos;
 
1261
 
 
1262
      /* Copy the length of the string over to key buffer. */
 
1263
      int2store(keybuf_pos, str_len);
 
1264
      keybuf_pos += sizeof(str_len);
 
1265
 
 
1266
      /* Copy the actual value over to the key buffer. */
 
1267
      memcpy(keybuf_pos, key_pos + sizeof(str_len), str_len);
 
1268
      keybuf_pos += str_len;
 
1269
 
 
1270
      /* NULL byte + Length of str (2 byte) + Actual String. */
 
1271
      offset = 1 + sizeof(str_len) + str_len;
1223
1272
    } else {
1224
1273
      end = key_part->field->pack(keybuf_pos, key_pos);
1225
1274
      offset = end - keybuf_pos;