1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 - 2010 Toru Maesaka
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
/* Unlike the data dictionary, don't tune the btree by default
24
since the default configuration satisfies BlitzDB's default
25
performance requirements. Tuning parameters will be made dynamic
26
in the upcoming releases. */
27
int BlitzTree::open(const char *path, const int key_num, int mode) {
30
if ((btree = tcbdbnew()) == NULL)
31
return drizzled::HA_ERR_OUT_OF_MEM;
33
if (!tcbdbsetmutex(btree)) {
35
return drizzled::HA_ERR_GENERIC;
38
if (blitz_estimated_rows != 0) {
39
uint64_t tree_buckets = blitz_estimated_rows / 10;
40
if (!tcbdbtune(btree, 0, 0, tree_buckets, -1, -1, 0)) {
42
return drizzled::HA_ERR_GENERIC;
46
if (!tcbdbsetcmpfunc(btree, blitz_keycmp_cb, this)) {
48
return drizzled::HA_ERR_GENERIC;
51
snprintf(buf, FN_REFLEN, "%s_%02d%s", path, key_num, BLITZ_INDEX_EXT);
53
if (!tcbdbopen(btree, buf, mode)) {
55
return drizzled::HA_ERR_CRASHED_ON_USAGE;
61
/* Similar to UNIX touch(1) but generates a TCBDB file. */
62
int BlitzTree::create(const char *path, const int key_num) {
65
if ((rv = this->open(path, key_num, (BDBOWRITER | BDBOCREAT))) != 0)
68
if ((rv = this->close()) != 0)
74
int BlitzTree::drop(const char *path, const int key_num) {
76
snprintf(buf, FN_REFLEN, "%s_%02d%s", path, key_num, BLITZ_INDEX_EXT);
80
int BlitzTree::rename(const char *from, const char *to, const int key_num) {
81
char from_buf[FN_REFLEN];
82
char to_buf[FN_REFLEN];
84
snprintf(from_buf, FN_REFLEN, "%s_%02d%s", from, key_num, BLITZ_INDEX_EXT);
85
snprintf(to_buf, FN_REFLEN, "%s_%02d%s", to, key_num, BLITZ_INDEX_EXT);
87
return drizzled::internal::my_rename(from_buf, to_buf, MYF(0));
90
int BlitzTree::close(void) {
93
if (!tcbdbclose(btree)) {
95
return drizzled::HA_ERR_CRASHED_ON_USAGE;
102
bool BlitzTree::create_cursor(BlitzCursor *bc) {
106
if ((bc->cursor = tcbdbcurnew(btree)) == NULL)
115
void BlitzTree::destroy_cursor(BlitzCursor *bc) {
119
tcbdbcurdel(bc->cursor);
123
int BlitzTree::write(const char *key, const size_t klen) {
124
return (tcbdbputdup(btree, key, klen, "", 0)) ? 0 : -1;
127
int BlitzTree::write_unique(const char *key, const size_t klen) {
128
if (!tcbdbputkeep(btree, key, klen, "", 0)) {
129
if (tcbdbecode(btree) == TCEKEEP) {
130
errno = drizzled::HA_ERR_FOUND_DUPP_KEY;
131
return drizzled::HA_ERR_FOUND_DUPP_KEY;
137
int BlitzTree::delete_key(const char *key, const int klen) {
138
return (tcbdbout(btree, key, klen)) ? 0 : -1;
141
int BlitzTree::delete_all(void) {
142
return (tcbdbvanish(btree)) ? 0 : -1;
145
uint64_t BlitzTree::records(void) {
146
return tcbdbrnum(btree);