~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blitzdb/ha_blitz.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include "config.h"
21
 
 
22
21
#include "ha_blitz.h"
23
 
#include <drizzled/plugin/storage_engine.h>
24
22
 
25
23
using namespace std;
26
24
using namespace drizzled;
27
 
namespace po= boost::program_options;
28
25
 
29
26
static pthread_mutex_t blitz_utility_mutex;
30
27
 
67
64
 
68
65
  int doCreateTable(drizzled::Session &session,
69
66
                    drizzled::Table &table_arg,
70
 
                    const drizzled::identifier::Table &identifier,
 
67
                    const drizzled::TableIdentifier &identifier,
71
68
                    drizzled::message::Table &table_proto);
72
69
 
73
70
  int doRenameTable(drizzled::Session &session,
74
 
                    const drizzled::identifier::Table &from_identifier,
75
 
                    const drizzled::identifier::Table &to_identifier);
 
71
                    const drizzled::TableIdentifier &from_identifier,
 
72
                    const drizzled::TableIdentifier &to_identifier);
76
73
 
77
74
  int doDropTable(drizzled::Session &session,
78
 
                  const drizzled::identifier::Table &identifier);
 
75
                  const drizzled::TableIdentifier &identifier);
79
76
 
80
77
  int doGetTableDefinition(drizzled::Session &session,
81
 
                           const drizzled::identifier::Table &identifier,
 
78
                           const drizzled::TableIdentifier &identifier,
82
79
                           drizzled::message::Table &table_proto);
83
80
 
84
81
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
85
 
                             const drizzled::identifier::Schema &schema_identifier,
86
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
 
82
                             const drizzled::SchemaIdentifier &schema_identifier,
 
83
                             drizzled::TableIdentifiers &set_of_identifiers);
87
84
 
88
85
  bool doDoesTableExist(drizzled::Session &session,
89
 
                        const drizzled::identifier::Table &identifier);
 
86
                        const drizzled::TableIdentifier &identifier);
90
87
 
91
88
  bool validateCreateTableOption(const std::string &key,
92
89
                                 const std::string &state);
123
120
 
124
121
int BlitzEngine::doCreateTable(drizzled::Session &,
125
122
                               drizzled::Table &table,
126
 
                               const drizzled::identifier::Table &identifier,
 
123
                               const drizzled::TableIdentifier &identifier,
127
124
                               drizzled::message::Table &proto) {
128
125
  BlitzData dict;
129
126
  BlitzTree btree;
164
161
}
165
162
 
166
163
int BlitzEngine::doRenameTable(drizzled::Session &,
167
 
                               const drizzled::identifier::Table &from,
168
 
                               const drizzled::identifier::Table &to) {
 
164
                               const drizzled::TableIdentifier &from,
 
165
                               const drizzled::TableIdentifier &to) {
169
166
  int rv = 0;
170
167
 
171
168
  BlitzData blitz_table;
172
169
  uint32_t nkeys;
173
170
 
174
 
  BlitzData dict;
175
 
  int ecode;
176
 
  /* Write the table definition to system table. */
177
 
  if ((ecode = dict.open_system_table(from.getPath(), HDBOWRITER)) != 0)
178
 
    return ecode;
179
 
 
180
 
  drizzled::message::Table proto;
181
 
  char *proto_string;
182
 
  int proto_string_len;
183
 
 
184
 
  proto_string = dict.get_system_entry(BLITZ_TABLE_PROTO_KEY.c_str(),
185
 
                                       BLITZ_TABLE_PROTO_KEY.length(),
186
 
                                       &proto_string_len);
187
 
 
188
 
  if (proto_string == NULL) {
189
 
    return ENOMEM;
190
 
  }
191
 
 
192
 
  if (!proto.ParseFromArray(proto_string, proto_string_len)) {
193
 
    free(proto_string);
194
 
    return HA_ERR_CRASHED_ON_USAGE;
195
 
  }
196
 
 
197
 
  free(proto_string);
198
 
 
199
 
  proto.set_name(to.getTableName());
200
 
  proto.set_schema(to.getSchemaName());
201
 
  proto.set_catalog(to.getCatalogName());
202
 
 
203
 
  if (!dict.write_table_definition(proto)) {
204
 
    dict.close_system_table();
205
 
    return HA_ERR_CRASHED_ON_USAGE;
206
 
  }
207
 
 
208
 
  dict.close_system_table();
209
 
 
210
171
  /* Find out the number of indexes in this table. This information
211
172
     is required because BlitzDB creates a file for each indexes.*/
212
173
  if (blitz_table.open_data_table(from.getPath().c_str(), HDBOREADER) != 0)
243
204
}
244
205
 
245
206
int BlitzEngine::doDropTable(drizzled::Session &,
246
 
                             const drizzled::identifier::Table &identifier) {
 
207
                             const drizzled::TableIdentifier &identifier) {
247
208
  BlitzData dict;
248
209
  BlitzTree btree;
249
210
  char buf[FN_REFLEN];
284
245
}
285
246
 
286
247
int BlitzEngine::doGetTableDefinition(drizzled::Session &,
287
 
                                      const drizzled::identifier::Table &identifier,
 
248
                                      const drizzled::TableIdentifier &identifier,
288
249
                                      drizzled::message::Table &proto) {
289
250
  struct stat stat_info;
290
251
  std::string path(identifier.getPath());
326
287
}
327
288
 
328
289
void BlitzEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
329
 
                                        const drizzled::identifier::Schema &schema_id,
330
 
                                        drizzled::identifier::Table::vector &ids) {
 
290
                                        const drizzled::SchemaIdentifier &schema_id,
 
291
                                        drizzled::TableIdentifiers &ids) {
331
292
  drizzled::CachedDirectory::Entries entries = directory.getEntries();
332
293
 
333
294
  for (drizzled::CachedDirectory::Entries::iterator entry_iter = entries.begin();
346
307
      char uname[NAME_LEN + 1];
347
308
      uint32_t file_name_len;
348
309
 
349
 
      file_name_len = identifier::Table::filename_to_tablename(filename->c_str(),
 
310
      file_name_len = TableIdentifier::filename_to_tablename(filename->c_str(),
350
311
                                                             uname,
351
312
                                                             sizeof(uname));
352
313
 
353
314
      uname[file_name_len - sizeof(BLITZ_DATA_EXT) + 1]= '\0';
354
 
      ids.push_back(identifier::Table(schema_id, uname));
 
315
      ids.push_back(TableIdentifier(schema_id, uname));
355
316
    }
356
317
  }
357
318
}
358
319
 
359
320
bool BlitzEngine::doDoesTableExist(drizzled::Session &,
360
 
                                   const drizzled::identifier::Table &identifier) {
 
321
                                   const drizzled::TableIdentifier &identifier) {
361
322
  std::string proto_path(identifier.getPath());
362
323
  proto_path.append(BLITZ_DATA_EXT);
363
324
 
499
460
 
500
461
int ha_blitz::doStartTableScan(bool scan) {
501
462
  /* Obtain the query type for this scan */
502
 
  sql_command_type = getTable()->getSession()->getSqlCommand();
 
463
  sql_command_type = session_sql_command(getTable()->getSession());
503
464
  table_scan = scan;
504
465
  table_based = true;
505
466
 
624
585
 
625
586
int ha_blitz::doStartIndexScan(uint32_t key_num, bool) {
626
587
  active_index = key_num;
627
 
  sql_command_type = getTable()->getSession()->getSqlCommand();
 
588
  sql_command_type = session_sql_command(getTable()->getSession());
628
589
 
629
590
  /* This is unlikely to happen but just for assurance, re-obtain
630
591
     the lock if this thread already has a certain lock. This makes
1143
1104
      *pos++ = 1;
1144
1105
    }
1145
1106
 
1146
 
    /* Here we normalize VARTEXT1 to VARTEXT2 for simplicity. */
1147
 
    if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1148
 
      /* Extract the length of the string from the row. */
1149
 
      uint16_t data_len = *(uint8_t *)(row + key_part->offset);
1150
 
 
1151
 
      /* Copy the length of the string. Use 2 bytes. */
1152
 
      int2store(pos, data_len);
1153
 
      pos += sizeof(data_len);
1154
 
 
1155
 
      /* Copy the string data */
1156
 
      memcpy(pos, row + key_part->offset + sizeof(uint8_t), data_len);
1157
 
      pos += data_len;
1158
 
    } else {
1159
 
      end = key_part->field->pack(pos, row + key_part->offset);
1160
 
      offset = end - pos;
1161
 
      pos += offset;
1162
 
    }
 
1107
    end = key_part->field->pack(pos, row + key_part->offset);
 
1108
    offset = end - pos;
 
1109
    pos += offset;
1163
1110
  }
1164
1111
 
1165
1112
  return ((char *)pos - pack_to);
1207
1154
 
1208
1155
  for (; key_part != key_part_end; key_part++) {
1209
1156
    if (key_part->null_bit) {
1210
 
      pos++;
1211
1157
      rv++;
1212
1158
      if (*key == 0)
1213
1159
        continue;
1214
1160
    }
1215
1161
 
1216
 
    if (key_part->type == HA_KEYTYPE_VARTEXT1 ||
1217
 
        key_part->type == HA_KEYTYPE_VARTEXT2) {
 
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) {
1218
1166
      len = uint2korr(pos);
1219
1167
      rv += len + sizeof(uint16_t);
1220
1168
    } else {
1258
1206
        continue;
1259
1207
    }
1260
1208
 
1261
 
    /* Normalize a VARTEXT1 key to VARTEXT2. */
 
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. */
1262
1214
    if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1263
 
      uint16_t str_len = *(uint16_t *)key_pos;
1264
 
 
1265
 
      /* Copy the length of the string over to key buffer. */
1266
 
      int2store(keybuf_pos, str_len);
1267
 
      keybuf_pos += sizeof(str_len);
1268
 
 
1269
 
      /* Copy the actual value over to the key buffer. */
1270
 
      memcpy(keybuf_pos, key_pos + sizeof(str_len), str_len);
1271
 
      keybuf_pos += str_len;
1272
 
 
1273
 
      /* NULL byte + Length of str (2 byte) + Actual String. */
1274
 
      offset = 1 + sizeof(str_len) + str_len;
 
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;
1275
1223
    } else {
1276
1224
      end = key_part->field->pack(keybuf_pos, key_pos);
1277
1225
      offset = end - keybuf_pos;
1481
1429
 
1482
1430
  pthread_mutex_init(&blitz_utility_mutex, NULL);
1483
1431
  context.add(blitz_engine);
1484
 
  context.registerVariable(new sys_var_uint64_t_ptr("estimated-rows",
1485
 
                                                    &blitz_estimated_rows));
1486
1432
  return 0;
1487
1433
}
1488
1434
 
1502
1448
  return true;
1503
1449
}
1504
1450
 
1505
 
static void blitz_init_options(drizzled::module::option_context &context)
1506
 
{
1507
 
  context("estimated-rows",
1508
 
          po::value<uint64_t>(&blitz_estimated_rows)->default_value(0),
1509
 
          N_("Estimated number of rows that a BlitzDB table will store."));
1510
 
}
1511
 
 
1512
 
DRIZZLE_PLUGIN(blitz_init, NULL, blitz_init_options);
 
1451
static DRIZZLE_SYSVAR_ULONGLONG (
 
1452
  estimated_rows,
 
1453
  blitz_estimated_rows,
 
1454
  PLUGIN_VAR_RQCMDARG,
 
1455
  "Estimated number of rows that a BlitzDB table will store.",
 
1456
  NULL,
 
1457
  NULL,
 
1458
  0,
 
1459
  0,
 
1460
  UINT64_MAX,
 
1461
  0
 
1462
);
 
1463
 
 
1464
static drizzle_sys_var *blitz_system_variables[] = {
 
1465
  DRIZZLE_SYSVAR(estimated_rows),
 
1466
  NULL
 
1467
};
 
1468
 
 
1469
DRIZZLE_PLUGIN(blitz_init, blitz_system_variables, NULL);