17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
21
#include "ha_blitz.h"
23
23
using namespace std;
24
24
using namespace drizzled;
26
#define BLITZ_TC_EXTRA_MMAP_SIZE (1024 * 1024 * 256)
27
#define BLITZ_TC_BUCKET_NUM 1000000
26
29
int BlitzData::startup(const char *path) {
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) {
54
std::string path = identifier.getPath() + BLITZ_DATA_EXT;
56
uint64_t autoinc = (proto.options().has_auto_increment_value())
57
? proto.options().auto_increment_value() - 1 : 0;
59
uint64_t hash_buckets = (blitz_estimated_rows == 0) ? BLITZ_TC_BUCKETS
60
: blitz_estimated_rows;
61
int n_options = proto.engine().options_size();
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;
69
if (hash_buckets <= 0)
70
hash_buckets = BLITZ_TC_BUCKETS;
74
if (data_table != NULL)
75
return HA_ERR_GENERIC;
77
if ((data_table = tchdbnew()) == NULL)
78
return HA_ERR_OUT_OF_MEM;
80
if (!tchdbtune(data_table, hash_buckets, -1, -1, 0)) {
82
return HA_ERR_CRASHED_ON_USAGE;
85
if (!tchdbopen(data_table, path.c_str(), (HDBOWRITER | HDBOCREAT))) {
87
return HA_ERR_CRASHED_ON_USAGE;
90
/* Write the Meta Data for this Table. */
91
tc_meta_buffer = tchdbopaque(data_table);
55
const drizzled::TableIdentifier &identifier) {
57
int mode = (HDBOWRITER | HDBOCREAT);
60
if ((rv = open_data_table(identifier.getPath().c_str(), mode)) != 0)
63
autoinc = (proto.options().has_auto_increment_value())
64
? proto.options().auto_increment_value() - 1 : 0;
92
66
write_meta_autoinc(autoinc);
93
write_meta_keycount(table_info.getShare()->keys);
67
write_meta_keycount(table_info.s->keys);
96
if (close_data_table() != 0)
69
if ((rv = close_data_table()) != 0)
97
70
return HA_ERR_CRASHED_ON_USAGE;
102
75
int BlitzData::open_data_table(const char *path, const int mode) {
110
83
return HA_ERR_CRASHED_ON_USAGE;
86
if (!tchdbtune(data_table, BLITZ_TC_BUCKET_NUM, -1, -1, 0)) {
88
return HA_ERR_CRASHED_ON_USAGE;
113
91
if (!tchdbsetxmsiz(data_table, BLITZ_TC_EXTRA_MMAP_SIZE)) {
114
92
tchdbdel(data_table);
115
93
return HA_ERR_CRASHED_ON_USAGE;