1 /***********************************************************************
2 
3 Copyright (c) 2011, 2021, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 ***********************************************************************/
26 /**************************************************//**
27 @file innodb_engine.h
28 
29 Created 03/15/2011      Jimmy Yang
30 *******************************************************/
31 
32 #ifndef INNODB_ENGINE_H
33 #define INNODB_ENGINE_H
34 
35 #include "config.h"
36 
37 #include <pthread.h>
38 
39 #include <memcached/engine.h>
40 #include <memcached/util.h>
41 #include <memcached/visibility.h>
42 #include <innodb_utility.h>
43 #include <innodb_config.h>
44 
45 /** Default settings that determine the number of write operation for
46 a connection before committing the transaction */
47 #define	CONN_NUM_WRITE_COMMIT	1
48 
49 /** Default settings that determine the number of read operation for
50 a connection before committing the transaction */
51 #define CONN_NUM_READ_COMMIT	1048510
52 
53 /** Structure contains the cursor information for each connection */
54 typedef struct innodb_conn_data_struct		innodb_conn_data_t;
55 
56 /** Connection specific data */
57 struct innodb_conn_data_struct {
58 	ib_crsr_t	read_crsr;	/*!< read only cursor for the
59 					connection */
60 	ib_crsr_t	idx_read_crsr;	/*!< index cursor for read */
61 	ib_trx_t	crsr_trx;	/*!< transaction for write cursor */
62 	ib_crsr_t       crsr;		/*!< data cursor */
63 	ib_crsr_t       idx_crsr;	/*!< index cursor */
64 	ib_tpl_t	read_tpl;	/*!< read tuple */
65 	ib_tpl_t	sel_tpl;	/*!< read tuple */
66 	ib_tpl_t	tpl;		/*!< read tuple */
67 	ib_tpl_t	idx_tpl;	/*!< read tuple */
68 	void*		result;		/*!< result info */
69 	void*		row_buf;	/*!< row buffer to cache row read */
70 	ib_ulint_t	row_buf_len;	/*!< row buffer len */
71 	void*		cmd_buf;	/*!< buffer for incoming command */
72 	ib_ulint_t	cmd_buf_len;	/*!< cmd buffer len */
73 	bool		result_in_use;	/*!< result set or above row_buf
74 					contain active result set */
75 	bool		use_default_mem;/*!<  whether to use default engine
76 					(memcached) memory */
77 	void*		mul_col_buf;	/*!< buffer to construct final result
78 					from multiple mapped column */
79 	ib_ulint_t	mul_col_buf_len;/*!< mul_col_buf len */
80 	bool            in_use;		/*!< whether the connection
81 					is processing a request */
82 	bool		is_stale;	/*!< connection closed, this is
83 					stale */
84 	bool		is_flushing;	/*!< if flush is running. */
85 	bool            is_waiting_for_mdl;
86 					/*!< Used to detrmine if the connection is
87 					locked and waiting on MDL */
88 	void*		conn_cookie;	/*!< connection cookie */
89 	uint64_t	n_total_reads;	/*!< number of reads */
90 	uint64_t	n_reads_since_commit;
91 					/*!< number of reads since
92 					last commit */
93 	uint64_t        n_total_writes;	/*!< number of updates, including
94 					write/update/delete */
95 	uint64_t	n_writes_since_commit;
96 					/*!< number of updates since
97 					last commit */
98 	void*		thd;		/*!< MySQL THD, used for binlog */
99 	void*		mysql_tbl;	/*!< MySQL TABLE, used for binlog */
100 	meta_cfg_info_t*conn_meta;	/*!< metadata info for this
101 					connection */
102 	pthread_mutex_t	curr_conn_mutex;/*!< mutex protect current connection */
103 	UT_LIST_NODE_T(innodb_conn_data_t)
104 			conn_list;	/*!< list ptr */
105 };
106 
107 typedef UT_LIST_BASE_NODE_T(innodb_conn_data_t)		conn_list_t;
108 
109 /** The InnoDB engine global data. Some layout are common to NDB memcached
110 engine and InnoDB memcached engine */
111 typedef struct innodb_engine {
112 	/* members all common to Memcached Engines */
113 	ENGINE_HANDLE_V1	engine;		/*!< this InnoDB Memcached
114 						engine */
115 	SERVER_HANDLE_V1	server;		/*!< Memcached server */
116 	GET_SERVER_API		get_server_api;	/*!< call back to get Memcached
117 						server common functions */
118 	ENGINE_HANDLE*		default_engine;	/*!< default memcached engine */
119 
120 	struct {
121 		size_t		nthreads;	/*!< number of threads handling
122 						connections */
123 		bool		cas_enabled;	/*!< whether cas is enabled */
124 	} server_options;
125 
126 	union {
127 		engine_info	info;		/*!< engine specific info */
128 		char		buffer[sizeof(engine_info)
129 				       * (LAST_REGISTERED_ENGINE_FEATURE + 1)];
130 						/*!< buffer to store customized
131 						engine info */
132 	} info;
133 
134 	bool			initialized;	/*!< whether engine data
135 						initialized */
136 	bool			connected;	/*!< whether connection
137 						established */
138 	bool			clean_stale_conn;
139 						/*!< whether bk thread is
140 						cleaning stale connections. */
141 
142 	/* following are InnoDB specific variables */
143 	bool			enable_binlog;	/*!< whether binlog is enabled
144 						for InnoDB Memcached */
145 	bool			enable_mdl;	/*!< whether MDL is enabled
146 						for InnoDB Memcached */
147 	ib_trx_level_t		trx_level;	/*!< transaction isolation
148 						level */
149 	ib_ulint_t		bk_commit_interval;
150 						/*!< background commit
151 						interval in seconds */
152 	int			cfg_status;	/*!< configure status */
153 	meta_cfg_info_t*	meta_info;	/*!< default metadata info from
154 						configuration */
155 	conn_list_t		conn_data;	/*!< list of data specific for
156 						connections */
157 	pthread_mutex_t		conn_mutex;	/*!< mutex synchronizes
158 						connection specific data */
159 	pthread_mutex_t		cas_mutex;	/*!< mutex synchronizes
160 						CAS */
161 	pthread_mutex_t		flush_mutex;	/*!< mutex synchronizes
162 						flush and DMLs. */
163 	pthread_t		bk_thd_for_commit;/*!< background thread for
164 						committing long running
165 						transactions */
166 	ib_cb_t*		innodb_cb;	/*!< pointer to callback
167 						functions */
168 	uint64_t		read_batch_size;/*!< configured read batch
169 						size */
170 	uint64_t		write_batch_size;/*!< configured write batch
171 						size */
172 	hash_table_t*		meta_hash;	/*!< hash table for metadata */
173 } innodb_engine_t;
174 
175 #endif /* INNODB_ENGINE_H */
176