42
43
using namespace std;
43
44
using namespace drizzled;
46
#if !defined(HAVE_MEMCACHED_SERVER_FN)
47
typedef memcached_server_function memcached_server_fn;
51
memcached_return server_function(memcached_st *ptr,
52
memcached_server_st *server,
55
struct server_function_context
58
plugin::InfoSchemaTable *schema_table;
59
server_function_context(Table *table_arg,
60
plugin::InfoSchemaTable *schema_table_arg)
61
: table(table_arg), schema_table(schema_table_arg)
66
memcached_return server_function(memcached_st *memc,
67
memcached_server_st *server,
70
server_function_context *ctx= static_cast<server_function_context *>(context);
71
const CHARSET_INFO * const scs= system_charset_info;
73
char *server_name= memcached_server_name(memc, *server);
74
in_port_t server_port= memcached_server_port(memc, *server);
76
memcached_stat_st stats;
77
memcached_return ret= memcached_stat_servername(&stats, NULL,
78
server_name, server_port);
79
if (ret != MEMCACHED_SUCCESS)
81
my_printf_error(ER_UNKNOWN_ERROR, _("Unable get stats from memcached server %s. Got error from memcached_stat_servername()."), MYF(0), server_name);
85
char **list= memcached_stat_get_keys(memc, &stats, &ret);
88
ctx->table->setWriteSet(0);
89
ctx->table->setWriteSet(1);
91
ctx->table->field[0]->store(server_name, strlen(server_name), scs);
92
ctx->table->field[1]->store(server_port);
95
for (ptr= list; *ptr; ptr++)
97
char *value= memcached_stat_get_value(memc, &stats, *ptr, &ret);
99
ctx->table->setWriteSet(col);
100
ctx->table->field[col]->store(value,
107
/* store the actual record now */
108
ctx->schema_table->addRow(ctx->table->record[0], ctx->table->s->reclength);
109
return MEMCACHED_SUCCESS;
45
112
int MemcachedStatsISMethods::fillTable(Session *,
47
114
plugin::InfoSchemaTable *schema_table)
49
const CHARSET_INFO * const scs= system_charset_info;
50
116
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
51
117
const string servers_string= sysvar_holder.getServersString();
53
119
table->restoreRecordAsDefault();
56
memcached_st *serv= memcached_create(NULL);
120
if (servers_string.empty())
122
my_printf_error(ER_UNKNOWN_ERROR, _("No value in MEMCACHED_STATS_SERVERS variable."), MYF(0));
127
memcached_st *memc= memcached_create(NULL);
130
my_printf_error(ER_UNKNOWN_ERROR, _("Unable to create memcached struct. Got error from memcached_create()."), MYF(0));
57
134
memcached_server_st *tmp_serv=
58
135
memcached_servers_parse(servers_string.c_str());
59
memcached_server_push(serv, tmp_serv);
136
if (tmp_serv == NULL)
138
my_printf_error(ER_UNKNOWN_ERROR, _("Unable to create memcached server list. Got error from memcached_servers_parse(%s)."), MYF(0), servers_string.c_str());
139
memcached_free(memc);
143
memcached_server_push(memc, tmp_serv);
60
144
memcached_server_list_free(tmp_serv);
61
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
62
memcached_server_st *servers= memcached_server_list(serv);
64
for (uint32_t i= 0; i < memcached_server_count(serv); i++)
66
char **list= memcached_stat_get_keys(serv, &stats[i], &rc);
69
table->setWriteSet(0);
70
table->setWriteSet(1);
72
table->field[0]->store(memcached_server_name(serv, servers[i]),
75
table->field[1]->store(memcached_server_port(serv, servers[i]));
77
for (ptr= list; *ptr; ptr++)
79
char *value= memcached_stat_get_value(serv, &stats[i], *ptr, &rc);
81
table->setWriteSet(col);
82
table->field[col]->store(value,
89
/* store the actual record now */
90
schema_table->addRow(table->record[0], table->s->reclength);
93
memcached_stat_free(serv, stats);
146
memcached_server_fn callbacks[1];
148
callbacks[0]= server_function;
149
server_function_context context(table, schema_table);
151
memcached_server_cursor(memc, callbacks, &context, 1);
153
memcached_free(memc);