Skip to content

Commit 340070e

Browse files
author
Jimmy Yang
committed
First batch of changes to implement memcached binlog operations. The
binlog operation is now controlled by "innodb_eng->enable_binlog", but will link to a InnoDB memcached configure variable in the next checkin.
1 parent 6a7db49 commit 340070e

File tree

16 files changed

+884
-32
lines changed

16 files changed

+884
-32
lines changed

CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ ENDIF()
205205

206206
# Add safemutex for debug configurations, except on Windows
207207
# (safemutex has never worked on Windows)
208-
IF(WITH_DEBUG AND NOT WIN32)
209-
FOREACH(LANG C CXX)
210-
SET(CMAKE_${LANG}_FLAGS_DEBUG
211-
"${CMAKE_${LANG}_FLAGS_DEBUG} -DSAFE_MUTEX")
212-
ENDFOREACH()
213-
ENDIF()
208+
#IF(WITH_DEBUG AND NOT WIN32)
209+
# FOREACH(LANG C CXX)
210+
# SET(CMAKE_${LANG}_FLAGS_DEBUG
211+
# "${CMAKE_${LANG}_FLAGS_DEBUG} -DSAFE_MUTEX")
212+
# ENDFOREACH()
213+
#ENDIF()
214214

215215

216216
# Set commonly used variables

plugin/innodb_memcached/innodb_memcache/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SET(INNODB_ENGINE_SOURCES
4343
src/innodb_engine.c
4444
src/innodb_api.c
4545
src/embedded_default_engine.c
46+
src/handler_api.cc
4647
cache-src/assoc.c
4748
cache-src/items.c
4849
cache-src/slabs.c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/*****************************************************************************
2+
3+
Copyright (c) 2011, Oracle and/or its affiliates. All Rights Reserved.
4+
5+
This program is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License as published by the Free Software
7+
Foundation; version 2 of the License.
8+
9+
This program is distributed in the hope that it will be useful, but WITHOUT
10+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License along with
14+
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15+
Place, Suite 330, Boston, MA 02111-1307 USA
16+
17+
****************************************************************************/
18+
19+
/**************************************************//**
20+
@file handler_api.h
21+
22+
Created 3/14/2011 Jimmy Yang
23+
*******************************************************/
24+
25+
#ifndef MYSQL_DML_H
26+
#define MYSQL_DML_H
27+
28+
29+
#define MYSQL_SERVER 1
30+
31+
#include <my_global.h>
32+
#include <sql_priv.h>
33+
#include <stdlib.h>
34+
#include <ctype.h>
35+
#include <mysql_version.h>
36+
#include <mysql/plugin.h>
37+
#include <my_dir.h>
38+
#include "my_pthread.h"
39+
#include "my_sys.h"
40+
#include "m_string.h"
41+
#include "sql_plugin.h"
42+
#include "table.h"
43+
#include "sql_class.h"
44+
#include <sql_base.h>
45+
#include "key.h"
46+
#include "lock.h"
47+
#include "transaction.h"
48+
#include "sql_handler.h"
49+
#include "handler.h"
50+
51+
52+
typedef struct field_arg {
53+
unsigned int num_arg;
54+
int* len;
55+
char** value;
56+
} field_arg_t;
57+
58+
#define MCI_ADD_FIELD(m_args, m_fld, m_value, m_len) \
59+
do { \
60+
(m_args)->len[m_fld] = m_len; \
61+
(m_args)->value[m_fld] = (char*)(m_value); \
62+
} while(0)
63+
64+
#define MCI_CREATE_FIELD(field, num_fld) \
65+
do { \
66+
field->len = (int*)malloc(num_fld * sizeof(*(field->len)));\
67+
memset(field->len, 0, num_fld * sizeof(*(field->len))); \
68+
field->value = (char**)malloc(num_fld \
69+
* sizeof(*(field->value)));\
70+
field->num_arg = num_fld; \
71+
} while(0)
72+
73+
#define MCI_FREE_FIELD(field) \
74+
do { \
75+
free(field->len); \
76+
free(field->value); \
77+
field->num_arg = 0; \
78+
} while(0)
79+
80+
extern "C" {
81+
/**********************************************************************//**
82+
Creates a THD object.
83+
@return a pointer to the THD object, NULL if failed */
84+
void*
85+
handler_create_thd(void);
86+
/*====================*/
87+
88+
/**********************************************************************//**
89+
Creates a MySQL TABLE object with specified database name and table name.
90+
@return a pointer to the TABLE object, NULL if does not exist */
91+
void*
92+
handler_open_table(
93+
/*===============*/
94+
void* thd, /*!< in: THD* */
95+
const char* db_name, /*!< in: database name */
96+
const char* table_name, /*!< in: table name */
97+
int lock_mode); /*!< in: lock mode */
98+
99+
/**********************************************************************//**
100+
Wrapper of function binlog_log_row() to binlog an operation on a row */
101+
void
102+
handler_binlog_row(
103+
/*===============*/
104+
void* my_table); /*!< in: Table metadata */
105+
106+
/**********************************************************************//**
107+
Flush binlog from cache to binlog file */
108+
void
109+
handler_binlog_flush(
110+
/*=================*/
111+
void* my_thd, /*!< in: THD* */
112+
void* my_table); /*!< in: TABLE structure */
113+
114+
/**********************************************************************//**
115+
Flush binlog from cache to binlog file */
116+
void
117+
handler_binlog_flush(
118+
/*=================*/
119+
void* my_thd, /*!< in: THD* */
120+
void* my_table); /*!< in: Table metadata */
121+
122+
/**********************************************************************//**
123+
Reset TABLE->record[0] */
124+
void
125+
handler_rec_init(
126+
void* table); /*!< in: Table metadata */
127+
128+
/**********************************************************************//**
129+
Set up a char based field in TABLE->record[0] */
130+
void
131+
handler_rec_setup_str(
132+
/*==================*/
133+
void* table, /*!< in/out: TABLE structure */
134+
int field_id, /*!< in: Field ID for the field */
135+
const char* str, /*!< in: string to set */
136+
int len); /*!< in: length of string */
137+
138+
/**********************************************************************//**
139+
Set up an integer field in TABLE->record[0] */
140+
void
141+
handler_rec_setup_int(
142+
/*==================*/
143+
void* table, /*!< in/out: TABLE structure */
144+
int field_id, /*!< in: Field ID for the field */
145+
int value, /*!< in: value to set */
146+
bool unsigned_flag); /*!< in: whether it is unsigned */
147+
/**********************************************************************//**
148+
Unlock a table and commit the transaction
149+
return 0 if fail to commit the transaction */
150+
int
151+
handler_unlock_table(
152+
/*=================*/
153+
void* my_thd, /*!< in: thread */
154+
void* my_table, /*!< in: Table metadata */
155+
int my_lock_mode); /*!< in: lock mode */
156+
/**********************************************************************//**
157+
close an handler */
158+
void
159+
handler_close_thd(
160+
/*==============*/
161+
void* my_thd); /*!< in: thread */
162+
}
163+
164+
/**********************************************************************//**
165+
binlog a row operation */
166+
extern
167+
int
168+
binlog_log_row(
169+
/*============*/
170+
TABLE* table, /*!< in: ptr to TABLE */
171+
const uchar *before_record, /*!< in: Before image of record */
172+
const uchar *after_record, /*!< in: Current image of record */
173+
Log_func* log_func); /*!< in: Log function */
174+
175+
extern void ha_close_connection(THD* thd);
176+
177+
#ifdef HANDLER_API_MEMCACHED
178+
/**********************************************************************//**
179+
Search table for a record with particular search criteria
180+
@return a pointer to table->record[0] */
181+
uchar*
182+
handler_select_rec(
183+
/*===============*/
184+
THD* thd, /*!< in: thread */
185+
TABLE* table, /*!< in: TABLE structure */
186+
field_arg_t* srch_args, /*!< in: field to search */
187+
int idx_to_use); /*!< in: index to use */
188+
/**********************************************************************//**
189+
Insert a record to the table
190+
return 0 if successfully inserted */
191+
int
192+
handler_insert_rec(
193+
/*===============*/
194+
THD* thd, /*!< in: thread */
195+
TABLE* table, /*!< in: TABLE structure */
196+
field_arg_t* store_args); /*!< in: inserting row data */
197+
/**********************************************************************//**
198+
Update a record
199+
return 0 if successfully inserted */
200+
int
201+
handler_update_rec(
202+
/*===============*/
203+
THD* thd, /*!< in: thread */
204+
TABLE* table, /*!< in: TABLE structure */
205+
field_arg_t* store_args); /*!< in: update row data */
206+
207+
/**********************************************************************//**
208+
Delete a record
209+
return 0 if successfully inserted */
210+
int
211+
handler_delete_rec(
212+
/*===============*/
213+
THD* thd, /*!< in: thread */
214+
TABLE* table); /*!< in: TABLE structure */
215+
216+
/**********************************************************************//**
217+
Lock a table
218+
return A lock structure pointer on success, NULL on error */
219+
MYSQL_LOCK *
220+
handler_lock_table(
221+
/*===============*/
222+
THD* thd, /*!< in: thread */
223+
TABLE* table, /*!< in: Table metadata */
224+
enum thr_lock_type lock_mode); /*!< in: lock mode */
225+
226+
#endif /* HANDLER_API_MEMCACHED */
227+
#endif
228+

plugin/innodb_memcached/innodb_memcache/include/innodb_api.h

+86-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,84 @@ Created 03/15/2011 Jimmy Yang
3030
#include "innodb_engine.h"
3131
#include "assert.h"
3232

33+
/**********************************************************************//**
34+
Creates a THD object.
35+
@return a pointer to the THD object, NULL if failed */
36+
extern
37+
void*
38+
handler_create_thd(void);
39+
/*====================*/
40+
41+
/**********************************************************************//**
42+
Creates a table object with specified database name and table name.
43+
@return a pointer to the TABLE object, NULL if does not exist */
44+
extern
45+
void*
46+
handler_open_table(
47+
/*===============*/
48+
void* thd, /*!< in: thread */
49+
const char* db_name, /*!< in: database name */
50+
const char* table_name, /*!< in: table name */
51+
int lock_mode); /*!< in: lock mode */
52+
53+
/**********************************************************************//**
54+
Wrapper of function binlog_log_row() to binlog an operation on a row */
55+
extern
56+
void
57+
handler_binlog_row(
58+
/*===============*/
59+
void* my_table); /*!< in: table metadata */
60+
61+
/**********************************************************************//**
62+
Flush binlog from cache to binlog file */
63+
extern
64+
void
65+
handler_binlog_flush(
66+
/*=================*/
67+
void* my_thd, /*!< in: THD* */
68+
void* my_table); /*!< in: Table metadata */
69+
70+
/**********************************************************************//**
71+
Reset TABLE->record[0] */
72+
extern
73+
void
74+
handler_rec_init(
75+
/*=============*/
76+
void* table); /*!< in/out: TABLE structure */
77+
78+
/**********************************************************************//**
79+
Set up a char based field in TABLE->record[0] */
80+
extern
81+
void
82+
handler_rec_setup_str(
83+
/*==================*/
84+
void* my_table, /*!< in/out: TABLE structure */
85+
int field_id, /*!< in: Field ID for the field */
86+
const char* str, /*!< in: string to set */
87+
int len); /*!< in: length of string */
88+
89+
/**********************************************************************//**
90+
Set up an integer field in TABLE->record[0] */
91+
extern
92+
void
93+
handler_rec_setup_int(
94+
/*==============*/
95+
void* my_table, /*!< in/out: TABLE structure */
96+
int field_id, /*!< in: Field ID for the field */
97+
int value, /*!< in: value to set */
98+
bool unsigned_flag); /*!< in: whether it is unsigned */
99+
100+
/**********************************************************************//**
101+
Unlock a table and commit the transaction
102+
return 0 if fail to commit the transaction */
103+
int
104+
handler_unlock_table(
105+
/*=================*/
106+
void* my_thd, /*!< in: thread */
107+
void* my_table, /*!< in: Table metadata */
108+
int my_lock_mode); /*!< in: lock mode */
109+
110+
33111
typedef struct mci_column {
34112
char* m_str;
35113
int m_len;
@@ -56,7 +134,6 @@ typedef struct mci_items {
56134
int mci_add_num;
57135
} mci_item_t;
58136

59-
60137
/*************************************************************//**
61138
Register InnoDB Callback functions */
62139
void
@@ -72,6 +149,8 @@ innodb_api_begin(
72149
innodb_engine_t*engine, /*!< in: InnoDB Memcached engine */
73150
const char* dbname, /*!< in: database name */
74151
const char* name, /*!< in: table name */
152+
innodb_conn_data_t* conn_data,
153+
/*!< in: connnection specific data */
75154
ib_trx_t ib_trx, /*!< in: transaction */
76155
ib_crsr_t* crsr, /*!< out: innodb cursor */
77156
ib_crsr_t* idx_crsr, /*!< out: innodb index cursor */
@@ -213,6 +292,12 @@ innodb_cb_trx_commit(
213292
/*=================*/
214293
ib_trx_t ib_trx);
215294

295+
ib_err_t
296+
innodb_cb_close_thd(
297+
/*=================*/
298+
void* thd);
299+
300+
216301
ib_err_t
217302
innodb_cb_cursor_new_trx(
218303
/*=====================*/

plugin/innodb_memcached/innodb_memcache/include/innodb_cb_api.h

+7
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ ib_err_t
293293
/*==============*/
294294
ib_crsr_t ib_crsr);
295295

296+
typedef
297+
ib_err_t
298+
(*CB_CLOSE_THD)(
299+
/*==============*/
300+
void* thd);
301+
296302
typedef
297303
ib_err_t
298304
(*CB_CURSOR_OPEN_INDEX_USING_NAME)(
@@ -342,5 +348,6 @@ CB_TABLE_TRUNCATE ib_cb_table_truncate;
342348
CB_CURSOR_FIRST ib_cb_cursor_first;
343349
CB_CURSOR_LAST ib_cb_cursor_last;
344350
CB_CURSOR_OPEN_INDEX_USING_NAME ib_cb_cursor_open_index_using_name;
351+
CB_CLOSE_THD ib_cb_close_thd;
345352

346353
#endif

0 commit comments

Comments
 (0)