~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blitzdb/blitzindex.cc

  • Committer: Monty Taylor
  • Date: 2009-12-08 23:39:39 UTC
  • mto: (1240.1.8 build)
  • mto: This revision was merged to the branch mainline in revision 1241.
  • Revision ID: mordred@inaugust.com-20091208233939-w0v4o04xer9pqqhu
Make range test shut up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 - 2010 Toru Maesaka
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
#include "ha_blitz.h"
22
 
 
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) {
28
 
  char buf[FN_REFLEN];
29
 
 
30
 
  if ((btree = tcbdbnew()) == NULL)
31
 
    return drizzled::HA_ERR_OUT_OF_MEM;
32
 
 
33
 
  if (!tcbdbsetmutex(btree)) {
34
 
    tcbdbdel(btree);
35
 
    return drizzled::HA_ERR_GENERIC;
36
 
  }
37
 
 
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)) {
41
 
      tcbdbdel(btree);
42
 
      return drizzled::HA_ERR_GENERIC;
43
 
    }
44
 
  }
45
 
 
46
 
  if (!tcbdbsetcmpfunc(btree, blitz_keycmp_cb, this)) {
47
 
    tcbdbdel(btree);
48
 
    return drizzled::HA_ERR_GENERIC;
49
 
  }
50
 
 
51
 
  snprintf(buf, FN_REFLEN, "%s_%02d%s", path, key_num, BLITZ_INDEX_EXT);
52
 
 
53
 
  if (!tcbdbopen(btree, buf, mode)) {
54
 
    tcbdbdel(btree);
55
 
    return drizzled::HA_ERR_CRASHED_ON_USAGE;
56
 
  }
57
 
 
58
 
  return 0;
59
 
}
60
 
 
61
 
/* Similar to UNIX touch(1) but generates a TCBDB file. */
62
 
int BlitzTree::create(const char *path, const int key_num) {
63
 
  int rv;
64
 
 
65
 
  if ((rv = this->open(path, key_num, (BDBOWRITER | BDBOCREAT))) != 0)
66
 
    return rv;
67
 
 
68
 
  if ((rv = this->close()) != 0)
69
 
    return rv;
70
 
 
71
 
  return rv;
72
 
}
73
 
 
74
 
int BlitzTree::drop(const char *path, const int key_num) {
75
 
  char buf[FN_REFLEN];
76
 
  snprintf(buf, FN_REFLEN, "%s_%02d%s", path, key_num, BLITZ_INDEX_EXT);
77
 
  return unlink(buf);
78
 
}
79
 
 
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];
83
 
 
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);
86
 
 
87
 
  return drizzled::internal::my_rename(from_buf, to_buf, MYF(0));
88
 
}
89
 
 
90
 
int BlitzTree::close(void) {
91
 
  assert(btree);
92
 
 
93
 
  if (!tcbdbclose(btree)) {
94
 
    tcbdbdel(btree);
95
 
    return drizzled::HA_ERR_CRASHED_ON_USAGE;
96
 
  }
97
 
 
98
 
  tcbdbdel(btree);
99
 
  return 0;
100
 
}
101
 
 
102
 
bool BlitzTree::create_cursor(BlitzCursor *bc) {
103
 
  if (bc == NULL)
104
 
    return false;
105
 
 
106
 
  if ((bc->cursor = tcbdbcurnew(btree)) == NULL)
107
 
    return false;
108
 
 
109
 
  bc->tree = this;
110
 
  bc->active = true;
111
 
  bc->moved = false;
112
 
  return true;
113
 
}
114
 
 
115
 
void BlitzTree::destroy_cursor(BlitzCursor *bc) {
116
 
  if (bc == NULL)
117
 
    return;
118
 
 
119
 
  tcbdbcurdel(bc->cursor);
120
 
  return;
121
 
}
122
 
 
123
 
int BlitzTree::write(const char *key, const size_t klen) {
124
 
  return (tcbdbputdup(btree, key, klen, "", 0)) ? 0 : -1;
125
 
}
126
 
 
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;
132
 
    }
133
 
  }
134
 
  return 0;
135
 
}
136
 
 
137
 
int BlitzTree::delete_key(const char *key, const int klen) {
138
 
  return (tcbdbout(btree, key, klen)) ? 0 : -1;
139
 
}
140
 
 
141
 
int BlitzTree::delete_all(void) {
142
 
  return (tcbdbvanish(btree)) ? 0 : -1;
143
 
}
144
 
 
145
 
uint64_t BlitzTree::records(void) {
146
 
  return tcbdbrnum(btree);
147
 
}