~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blitzdb/blitzdata.cc

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
21
21
#include "ha_blitz.h"
22
22
 
23
23
using namespace std;
24
24
using namespace drizzled;
25
25
 
 
26
#define BLITZ_TC_EXTRA_MMAP_SIZE (1024 * 1024 * 256)
 
27
#define BLITZ_TC_BUCKET_NUM 1000000
 
28
 
26
29
int BlitzData::startup(const char *path) {
27
30
  int rv = 0;
28
31
 
46
49
  return rv;
47
50
}
48
51
 
49
 
/* Similar to UNIX touch(1) but generates a tuned TCHDB file. */
 
52
/* Similar to UNIX touch(1) but generates a TCHDB file. */
50
53
int BlitzData::create_data_table(drizzled::message::Table &proto,
51
54
                                 drizzled::Table &table_info,
52
 
                                 const drizzled::identifier::Table &identifier) {
53
 
 
54
 
  std::string path = identifier.getPath() + BLITZ_DATA_EXT;
55
 
 
56
 
  uint64_t autoinc = (proto.options().has_auto_increment_value())
57
 
                     ? proto.options().auto_increment_value() - 1 : 0;
58
 
 
59
 
  uint64_t hash_buckets = (blitz_estimated_rows == 0) ? BLITZ_TC_BUCKETS
60
 
                                                      : blitz_estimated_rows;
61
 
  int n_options = proto.engine().options_size();
62
 
 
63
 
  for (int i = 0; i < n_options; i++) {
64
 
    if (proto.engine().options(i).name() == "estimated_rows" ||
65
 
        proto.engine().options(i).name() == "ESTIMATED_ROWS") {
66
 
      std::istringstream stream(proto.engine().options(i).state());
67
 
      stream >> hash_buckets;
68
 
 
69
 
      if (hash_buckets <= 0)
70
 
        hash_buckets = BLITZ_TC_BUCKETS;
71
 
    }
72
 
  }
73
 
 
74
 
  if (data_table != NULL)
75
 
    return HA_ERR_GENERIC;
76
 
 
77
 
  if ((data_table = tchdbnew()) == NULL)
78
 
    return HA_ERR_OUT_OF_MEM;
79
 
 
80
 
  if (!tchdbtune(data_table, hash_buckets, -1, -1, 0)) {
81
 
    tchdbdel(data_table);
82
 
    return HA_ERR_CRASHED_ON_USAGE;
83
 
  }
84
 
 
85
 
  if (!tchdbopen(data_table, path.c_str(), (HDBOWRITER | HDBOCREAT))) {
86
 
    tchdbdel(data_table);
87
 
    return HA_ERR_CRASHED_ON_USAGE;
88
 
  }
89
 
 
90
 
  /* Write the Meta Data for this Table. */
91
 
  tc_meta_buffer = tchdbopaque(data_table);
 
55
                                 const drizzled::TableIdentifier &identifier) {
 
56
  uint64_t autoinc = 0;
 
57
  int mode = (HDBOWRITER | HDBOCREAT);
 
58
  int rv;
 
59
 
 
60
  if ((rv = open_data_table(identifier.getPath().c_str(), mode)) != 0)
 
61
    return rv;
 
62
 
 
63
  autoinc = (proto.options().has_auto_increment_value())
 
64
            ? proto.options().auto_increment_value() - 1 : 0;
 
65
 
92
66
  write_meta_autoinc(autoinc);
93
 
  write_meta_keycount(table_info.getShare()->keys);
 
67
  write_meta_keycount(table_info.s->keys);
94
68
 
95
 
  /* We're Done. */
96
 
  if (close_data_table() != 0)
 
69
  if ((rv = close_data_table()) != 0)
97
70
    return HA_ERR_CRASHED_ON_USAGE;
98
71
 
99
 
  return 0;
 
72
  return rv;
100
73
}
101
74
 
102
75
int BlitzData::open_data_table(const char *path, const int mode) {
110
83
    return HA_ERR_CRASHED_ON_USAGE;
111
84
  }
112
85
 
 
86
  if (!tchdbtune(data_table, BLITZ_TC_BUCKET_NUM, -1, -1, 0)) {
 
87
    tchdbdel(data_table);
 
88
    return HA_ERR_CRASHED_ON_USAGE;
 
89
  }
 
90
 
113
91
  if (!tchdbsetxmsiz(data_table, BLITZ_TC_EXTRA_MMAP_SIZE)) {
114
92
    tchdbdel(data_table);
115
93
    return HA_ERR_CRASHED_ON_USAGE;
154
132
  }
155
133
 
156
134
  tchdbdel(data_table);
157
 
  data_table = NULL;
158
 
  tc_meta_buffer = NULL;
159
135
  return 0;
160
136
}
161
137