1
by brian
clean slate |
1 |
/* Copyright (C) 2003 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
16 |
#ifndef PLUGIN_CSV_HA_TINA_H
|
17 |
#define PLUGIN_CSV_HA_TINA_H
|
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
18 |
|
1183.1.2
by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted |
19 |
#include <drizzled/cursor.h> |
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
20 |
#include <drizzled/thr_lock.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
21 |
|
1
by brian
clean slate |
22 |
#include <sys/types.h> |
23 |
#include <sys/stat.h> |
|
24 |
#include "transparent_file.h" |
|
25 |
||
26 |
/*
|
|
27 |
Version for file format.
|
|
28 |
1 - Initial Version. That is, the version when the metafile was introduced.
|
|
29 |
*/
|
|
30 |
||
31 |
#define TINA_VERSION 1
|
|
32 |
||
1240.2.2
by Monty Taylor
Turned TINA_SHARE into TinaShare. |
33 |
class TinaShare |
34 |
{
|
|
35 |
TinaShare(); |
|
36 |
TinaShare(const TinaShare &); |
|
37 |
TinaShare& operator=(const TinaShare &); |
|
38 |
public: |
|
1749.3.18
by Brian Aker
Replace some of the CSV non-usage of identifier for path. |
39 |
explicit TinaShare(const std::string &name); |
1240.2.2
by Monty Taylor
Turned TINA_SHARE into TinaShare. |
40 |
~TinaShare(); |
41 |
||
42 |
std::string table_name; |
|
1749.3.18
by Brian Aker
Replace some of the CSV non-usage of identifier for path. |
43 |
std::string data_file_name; |
1240.2.2
by Monty Taylor
Turned TINA_SHARE into TinaShare. |
44 |
uint32_t use_count; |
1
by brian
clean slate |
45 |
/*
|
46 |
Here we save the length of the file for readers. This is updated by
|
|
47 |
inserts, updates and deletes. The var is initialized along with the
|
|
48 |
share initialization.
|
|
49 |
*/
|
|
50 |
off_t saved_data_file_length; |
|
51 |
pthread_mutex_t mutex; |
|
52 |
bool update_file_opened; |
|
53 |
bool tina_write_opened; |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
54 |
int meta_file; /* Meta file we use */ |
55 |
int tina_write_filedes; /* File Cursor for readers */ |
|
1
by brian
clean slate |
56 |
bool crashed; /* Meta file is crashed */ |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
57 |
drizzled::ha_rows rows_recorded; /* Number of rows in tables */ |
482
by Brian Aker
Remove uint. |
58 |
uint32_t data_file_version; /* Version of the data file used */ |
1240.2.2
by Monty Taylor
Turned TINA_SHARE into TinaShare. |
59 |
};
|
1
by brian
clean slate |
60 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
61 |
class ha_tina: public drizzled::Cursor |
1
by brian
clean slate |
62 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
63 |
drizzled::THR_LOCK_DATA lock; /* MySQL lock */ |
1240.2.2
by Monty Taylor
Turned TINA_SHARE into TinaShare. |
64 |
TinaShare *share; /* Shared lock info */ |
1
by brian
clean slate |
65 |
off_t current_position; /* Current position in the file during a file scan */ |
66 |
off_t next_position; /* Next position in the file scan */ |
|
67 |
off_t local_saved_data_file_length; /* save position for reads */ |
|
68 |
off_t temp_file_length; |
|
481
by Brian Aker
Remove all of uchar. |
69 |
unsigned char byte_buffer[IO_SIZE]; |
1
by brian
clean slate |
70 |
Transparent_file *file_buff; |
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
71 |
int data_file; /* File Cursor for readers */ |
72 |
int update_temp_file; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
73 |
drizzled::String buffer; |
1
by brian
clean slate |
74 |
/*
|
75 |
The chain contains "holes" in the file, occured because of
|
|
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
76 |
deletes/updates. It is used in doEndTableScan() to get rid of them
|
1
by brian
clean slate |
77 |
in the end of the query.
|
78 |
*/
|
|
1608.3.1
by Zimin
refactor CSV engine's tina_set |
79 |
std::vector< std::pair<off_t, off_t> > chain; |
482
by Brian Aker
Remove uint. |
80 |
uint32_t local_data_file_version; /* Saved version of the data file used */ |
1
by brian
clean slate |
81 |
bool records_is_known; |
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
82 |
drizzled::memory::Root blobroot; |
1
by brian
clean slate |
83 |
|
1608.3.1
by Zimin
refactor CSV engine's tina_set |
84 |
bool get_write_pos(off_t *end_pos, |
85 |
std::vector< std::pair<off_t, off_t> >::iterator &closest_hole); |
|
1
by brian
clean slate |
86 |
int open_update_temp_file_if_needed(); |
87 |
int init_tina_writer(); |
|
88 |
int init_data_file(); |
|
89 |
||
90 |
public: |
|
1869.1.4
by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy |
91 |
ha_tina(drizzled::plugin::StorageEngine &engine, drizzled::Table &table_arg); |
1
by brian
clean slate |
92 |
~ha_tina() |
93 |
{
|
|
94 |
if (file_buff) |
|
95 |
delete file_buff; |
|
96 |
}
|
|
77.1.6
by Monty Taylor
CSV is clean. |
97 |
const char *table_type(void) const { return "CSV"; } |
653
by Brian Aker
More solaris bits |
98 |
const char *index_type(uint32_t) |
77.1.6
by Monty Taylor
CSV is clean. |
99 |
{ return "NONE"; } |
1235.1.12
by Brian Aker
Clean up index interface before moving to SE. |
100 |
|
1
by brian
clean slate |
101 |
/*
|
102 |
Called in test_quick_select to determine if indexes should be used.
|
|
103 |
*/
|
|
104 |
virtual double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; } |
|
1235.1.12
by Brian Aker
Clean up index interface before moving to SE. |
105 |
|
1
by brian
clean slate |
106 |
/* The next method will never be called */
|
107 |
virtual bool fast_key_read() { return 1;} |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
108 |
/*
|
1749.3.18
by Brian Aker
Replace some of the CSV non-usage of identifier for path. |
109 |
@TODO return actual upper bound of number of records in the table.
|
1
by brian
clean slate |
110 |
(e.g. save number of records seen on full table scan and/or use file size
|
111 |
as upper bound)
|
|
112 |
*/
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
113 |
drizzled::ha_rows estimate_rows_upper_bound() { return HA_POS_ERROR; } |
1
by brian
clean slate |
114 |
|
1633.4.1
by Brian Aker
Merge ha_open to have doOpen() which passes identifier. |
115 |
int doOpen(const drizzled::TableIdentifier &identifier, int mode, uint32_t test_if_locked); |
116 |
int open(const char *, int , uint32_t ) { assert(0); return -1; } |
|
1
by brian
clean slate |
117 |
int close(void); |
1491.1.2
by Jay Pipes
Cursor::write_row() -> Cursor::doInsertRecord(). Cursor::ha_write_row() -> Cursor::insertRecord() |
118 |
int doInsertRecord(unsigned char * buf); |
1491.1.3
by Jay Pipes
Cursor::update_row() changed to doUpdateRecord() and updateRecord() |
119 |
int doUpdateRecord(const unsigned char * old_data, unsigned char * new_data); |
1491.1.4
by Jay Pipes
delete_row() is now deleteRecord() and doDeleteRecord() in Cursor |
120 |
int doDeleteRecord(const unsigned char * buf); |
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
121 |
int doStartTableScan(bool scan=1); |
481
by Brian Aker
Remove all of uchar. |
122 |
int rnd_next(unsigned char *buf); |
123 |
int rnd_pos(unsigned char * buf, unsigned char *pos); |
|
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
124 |
int doEndTableScan(); |
1749.3.18
by Brian Aker
Replace some of the CSV non-usage of identifier for path. |
125 |
TinaShare *get_share(const std::string &table_name); |
1240.2.1
by Monty Taylor
Fixed the CSV tina_open_tables HASH to be a std::map. |
126 |
int free_share(); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
127 |
int repair(drizzled::Session* session, drizzled::HA_CHECK_OPT* check_opt); |
1
by brian
clean slate |
128 |
/* This is required for SQL layer to know that we support autorepair */
|
481
by Brian Aker
Remove all of uchar. |
129 |
void position(const unsigned char *record); |
1
by brian
clean slate |
130 |
int info(uint); |
131 |
int delete_all_rows(void); |
|
1377.7.2
by Stewart Smith
make get_auto_increment pure virtual and force engines not supporting auto_increment to be explicit about it |
132 |
void get_auto_increment(uint64_t, uint64_t, |
133 |
uint64_t, |
|
134 |
uint64_t *, |
|
135 |
uint64_t *) |
|
136 |
{}
|
|
1
by brian
clean slate |
137 |
|
138 |
/* The following methods were added just for TINA */
|
|
481
by Brian Aker
Remove all of uchar. |
139 |
int encode_quote(unsigned char *buf); |
140 |
int find_current_row(unsigned char *buf); |
|
1
by brian
clean slate |
141 |
int chain_append(); |
142 |
};
|
|
143 |
||
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
144 |
#endif /* PLUGIN_CSV_HA_TINA_H */ |