1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1239.3.32
by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface. |
4 |
* Copyright (C) 2009 - 2010 Toru Maesaka
|
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
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 |
||
1800.3.1
by Vijay Samuel
Merge change of <config.h> to "config.h" |
20 |
#include "config.h" |
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
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. */
|
|
1239.3.32
by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface. |
27 |
int BlitzTree::open(const char *path, const int key_num, int mode) { |
1239.3.35
by Toru Maesaka
Made index file(s) droppable and renamable. |
28 |
char buf[FN_REFLEN]; |
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
29 |
|
30 |
if ((btree = tcbdbnew()) == NULL) |
|
31 |
return HA_ERR_OUT_OF_MEM; |
|
32 |
||
33 |
if (!tcbdbsetmutex(btree)) { |
|
34 |
tcbdbdel(btree); |
|
1239.3.129
by Toru Maesaka
Added a command line option for optimizing BlitzDB. |
35 |
return 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 HA_ERR_GENERIC; |
|
43 |
}
|
|
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
44 |
}
|
45 |
||
1239.3.41
by Toru Maesaka
Started hacking on the key comparator for B+Tree indexes. INT, BIGINT, DOUBLE and VARCHAR types are now supported. More to come. |
46 |
if (!tcbdbsetcmpfunc(btree, blitz_keycmp_cb, this)) { |
47 |
tcbdbdel(btree); |
|
1239.3.129
by Toru Maesaka
Added a command line option for optimizing BlitzDB. |
48 |
return HA_ERR_GENERIC; |
1239.3.41
by Toru Maesaka
Started hacking on the key comparator for B+Tree indexes. INT, BIGINT, DOUBLE and VARCHAR types are now supported. More to come. |
49 |
}
|
50 |
||
1239.3.35
by Toru Maesaka
Made index file(s) droppable and renamable. |
51 |
snprintf(buf, FN_REFLEN, "%s_%02d%s", path, key_num, BLITZ_INDEX_EXT); |
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
52 |
|
1239.3.35
by Toru Maesaka
Made index file(s) droppable and renamable. |
53 |
if (!tcbdbopen(btree, buf, mode)) { |
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
54 |
tcbdbdel(btree); |
55 |
return HA_ERR_CRASHED_ON_USAGE; |
|
56 |
}
|
|
57 |
||
58 |
return 0; |
|
59 |
}
|
|
60 |
||
61 |
/* Similar to UNIX touch(1) but generates a TCBDB file. */
|
|
1239.3.32
by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface. |
62 |
int BlitzTree::create(const char *path, const int key_num) { |
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
63 |
int rv; |
64 |
||
1239.3.32
by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface. |
65 |
if ((rv = this->open(path, key_num, (BDBOWRITER | BDBOCREAT))) != 0) |
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
66 |
return rv; |
67 |
||
68 |
if ((rv = this->close()) != 0) |
|
69 |
return rv; |
|
70 |
||
71 |
return rv; |
|
72 |
}
|
|
73 |
||
1239.3.35
by Toru Maesaka
Made index file(s) droppable and renamable. |
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 |
||
1239.3.121
by Toru Maesaka
Use internal::my_rename instead of std::rename to keep FreeBSD happy. |
87 |
return drizzled::internal::my_rename(from_buf, to_buf, MYF(0)); |
1239.3.35
by Toru Maesaka
Made index file(s) droppable and renamable. |
88 |
}
|
89 |
||
1239.3.10
by Toru Maesaka
Started hacking on indexing. Prep Work 1. |
90 |
int BlitzTree::close(void) { |
91 |
assert(btree); |
|
92 |
||
93 |
if (!tcbdbclose(btree)) { |
|
94 |
tcbdbdel(btree); |
|
95 |
return HA_ERR_CRASHED_ON_USAGE; |
|
96 |
}
|
|
97 |
||
98 |
tcbdbdel(btree); |
|
99 |
return 0; |
|
100 |
}
|
|
101 |
||
1239.3.113
by Toru Maesaka
Improved cursor resource management. TC's cursor allocation only happens once per worker now. |
102 |
bool BlitzTree::create_cursor(BlitzCursor *bc) { |
103 |
if (bc == NULL) |
|
104 |
return false; |
|
1239.3.106
by Toru Maesaka
First step in splitting BlitzTree's cursor object. |
105 |
|
1239.3.107
by Toru Maesaka
Removed dead code from BlitzDB. |
106 |
if ((bc->cursor = tcbdbcurnew(btree)) == NULL) |
1239.3.114
by Toru Maesaka
Fix for a CentOS build warning reported by the Build Farm. |
107 |
return false; |
1239.3.106
by Toru Maesaka
First step in splitting BlitzTree's cursor object. |
108 |
|
1239.3.108
by Toru Maesaka
Removed dead function declaration and worked on BlitzCursor object. |
109 |
bc->tree = this; |
1239.3.107
by Toru Maesaka
Removed dead code from BlitzDB. |
110 |
bc->active = true; |
111 |
bc->moved = false; |
|
1239.3.113
by Toru Maesaka
Improved cursor resource management. TC's cursor allocation only happens once per worker now. |
112 |
return true; |
1239.3.106
by Toru Maesaka
First step in splitting BlitzTree's cursor object. |
113 |
}
|
114 |
||
1239.3.107
by Toru Maesaka
Removed dead code from BlitzDB. |
115 |
void BlitzTree::destroy_cursor(BlitzCursor *bc) { |
116 |
if (bc == NULL) |
|
1239.3.106
by Toru Maesaka
First step in splitting BlitzTree's cursor object. |
117 |
return; |
118 |
||
1239.3.107
by Toru Maesaka
Removed dead code from BlitzDB. |
119 |
tcbdbcurdel(bc->cursor); |
1239.3.113
by Toru Maesaka
Improved cursor resource management. TC's cursor allocation only happens once per worker now. |
120 |
return; |
1239.3.106
by Toru Maesaka
First step in splitting BlitzTree's cursor object. |
121 |
}
|
122 |
||
1239.3.72
by Toru Maesaka
Fixed a critical concurrency bug that would cause inconsistency. Reworked BlitzTree and refactored memory management a little. |
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)) { |
|
1239.3.38
by Toru Maesaka
More work on indexing component. PK now gets a tree. |
129 |
if (tcbdbecode(btree) == TCEKEEP) { |
130 |
errno = HA_ERR_FOUND_DUPP_KEY; |
|
1239.3.61
by Toru Maesaka
Worked on reducing the execution path of row insertion and supported NULL for key values. Added tests for NULL values in full index scan. |
131 |
return HA_ERR_FOUND_DUPP_KEY; |
1239.3.38
by Toru Maesaka
More work on indexing component. PK now gets a tree. |
132 |
}
|
133 |
}
|
|
1239.3.61
by Toru Maesaka
Worked on reducing the execution path of row insertion and supported NULL for key values. Added tests for NULL values in full index scan. |
134 |
return 0; |
1239.3.38
by Toru Maesaka
More work on indexing component. PK now gets a tree. |
135 |
}
|
136 |
||
1239.3.109
by Toru Maesaka
Still not optimal but the cursor object is now separated between workers. This build survived sysbench's read-only OLTP test. |
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 |
}
|