Commit 6c302207 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-26858 Spider: Remove dead code related to HandlerSocket

Remove the dead-code, in Spider, which is related to the Spider's
HandlerSocket support. The code has been disabled for a long time
and it is unlikely that the code will be enabled.

- rm all files under storage/spider/hs_client/ except hs_compat.h
- rm storage/spider/spd_db_handlersocket.*
- unifdef -UHS_HAS_SQLCOM -UHAVE_HANDLERSOCKET \
  -m storage/spider/spd_* storage/spider/ha_spider.* storage/spider/hs_client/*
- remove relevant files from storage/spider/CMakeLists.txt
parent 0c440abd
......@@ -17,10 +17,7 @@ SET(SPIDER_SOURCES
spd_param.cc spd_sys_table.cc spd_trx.cc spd_db_conn.cc spd_conn.cc
spd_table.cc spd_direct_sql.cc spd_udf.cc spd_ping_table.cc
spd_copy_tables.cc spd_i_s.cc spd_malloc.cc ha_spider.cc spd_udf.def
spd_db_mysql.cc spd_db_handlersocket.cc spd_db_oracle.cc
spd_group_by_handler.cc spd_db_include.cc
hs_client/config.cpp hs_client/escape.cpp hs_client/fatal.cpp
hs_client/hstcpcli.cpp hs_client/socket.cpp hs_client/string_util.cpp
spd_db_mysql.cc spd_db_oracle.cc spd_group_by_handler.cc spd_db_include.cc
)
IF(DEFINED ENV{ORACLE_HOME})
......
This diff is collapsed.
......@@ -55,10 +55,6 @@ class ha_spider final : public handler
SPIDER_SHARE *share;
ulonglong spider_thread_id;
ulonglong trx_conn_adjustment;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
ulonglong trx_hs_r_conn_adjustment;
ulonglong trx_hs_w_conn_adjustment;
#endif
uint mem_calc_id;
const char *mem_calc_func_name;
const char *mem_calc_file_name;
......@@ -71,14 +67,6 @@ class ha_spider final : public handler
char *conn_keys_first_ptr;
char **conn_keys;
SPIDER_CONN **conns;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
char **hs_r_conn_keys;
SPIDER_CONN **hs_r_conns;
ulonglong *hs_r_conn_ages;
char **hs_w_conn_keys;
SPIDER_CONN **hs_w_conns;
ulonglong *hs_w_conn_ages;
#endif
/* for active-standby mode */
uint *conn_link_idx;
uchar *conn_can_fo;
......@@ -179,27 +167,8 @@ class ha_spider final : public handler
uchar *m_handler_opened;
uint *m_handler_id;
char **m_handler_cid;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
uchar *r_handler_opened;
uint *r_handler_id;
uint *r_handler_index;
uchar *w_handler_opened;
uint *w_handler_id;
uint *w_handler_index;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
uchar *do_hs_direct_update;
uint32 **hs_r_ret_fields;
uint32 **hs_w_ret_fields;
size_t *hs_r_ret_fields_num;
size_t *hs_w_ret_fields_num;
uchar *tmp_column_bitmap;
#endif
#endif
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
bool do_direct_update;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
bool maybe_do_hs_direct_update;
#endif
uint direct_update_kinds;
#endif
spider_index_rnd_init prev_index_rnd_init;
......@@ -938,26 +907,6 @@ class ha_spider final : public handler
int reset_sql_sql(
ulong sql_type
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int reset_hs_sql(
ulong sql_type
);
int reset_hs_keys(
ulong sql_type
);
int reset_hs_upds(
ulong sql_type
);
int reset_hs_strs(
ulong sql_type
);
int reset_hs_strs_pos(
ulong sql_type
);
int push_back_hs_upds(
SPIDER_HS_STRING_REF &info
);
#endif
int append_tmp_table_and_sql_for_bka(
const key_range *start_key
);
......@@ -968,17 +917,9 @@ class ha_spider final : public handler
int reuse_union_table_and_sql_for_bka();
int append_insert_sql_part();
int append_update_sql_part();
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
int append_increment_update_set_sql_part();
#endif
#endif
int append_update_set_sql_part();
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
int append_direct_update_set_sql_part();
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int append_direct_update_set_hs_part();
#endif
#endif
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
int append_dup_update_pushdown_sql_part(
......@@ -1045,13 +986,6 @@ class ha_spider final : public handler
const key_range *end_key,
ulong sql_type
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int append_key_where_hs_part(
const key_range *start_key,
const key_range *end_key,
ulong sql_type
);
#endif
int append_match_where_sql_part(
ulong sql_type
);
......@@ -1106,13 +1040,6 @@ class ha_spider final : public handler
longlong limit,
ulong sql_type
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int append_limit_hs_part(
longlong offset,
longlong limit,
ulong sql_type
);
#endif
int reappend_limit_sql_part(
longlong offset,
longlong limit,
......@@ -1124,11 +1051,6 @@ class ha_spider final : public handler
int append_insert_values_sql_part(
ulong sql_type
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int append_insert_values_hs_part(
ulong sql_type
);
#endif
int append_into_sql_part(
ulong sql_type
);
......@@ -1197,9 +1119,6 @@ class ha_spider final : public handler
bool support_use_handler_sql(
int use_handler
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
bool support_bulk_access_hs() const;
#endif
int init_union_table_name_pos_sql();
int set_union_table_name_pos_sql();
int append_lock_tables_list();
......
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_ALLOCATOR_HPP
#define DENA_ALLOCATOR_HPP
#if 0
extern "C" {
#include <tlsf.h>
};
#define DENA_MALLOC(x) tlsf_malloc(x)
#define DENA_REALLOC(x, y) tlsf_realloc(x, y)
#define DENA_FREE(x) tlsf_free(x)
#define DENA_NEWCHAR(x) static_cast<char *>(tlsf_malloc(x))
#define DENA_DELETE(x) tlsf_free(x)
#endif
#if 1
#define DENA_MALLOC(x) malloc(x)
#define DENA_REALLOC(x, y) realloc(x, y)
#define DENA_FREE(x) free(x)
#define DENA_NEWCHAR(x) (new char[x])
#define DENA_DELETE(x) (delete [] x)
#endif
#if 1
#define DENA_ALLOCA_ALLOCATE(typ, len) \
(typ *) (alloca((len) * sizeof(typ)))
#define DENA_ALLOCA_FREE(x)
#else
#define DENA_ALLOCA_ALLOCATE(typ, len) \
(typ *) (malloc((len) * sizeof(typ)))
#define DENA_ALLOCA_FREE(x) free(x)
#endif
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_AUTO_ADDRINFO_HPP
#define DENA_AUTO_ADDRINFO_HPP
#ifndef __WIN__
#include <netdb.h>
#endif
#include "util.hpp"
namespace dena {
struct auto_addrinfo : private noncopyable {
auto_addrinfo() : addr(0) { }
~auto_addrinfo() {
reset();
}
void reset(addrinfo *a = 0) {
if (addr != 0) {
freeaddrinfo(addr);
}
addr = a;
}
const addrinfo *get() const { return addr; }
int resolve(const char *node, const char *service, int flags = 0,
int family = AF_UNSPEC, int socktype = SOCK_STREAM, int protocol = 0) {
reset();
addrinfo hints;
hints.ai_flags = flags;
hints.ai_family = family;
hints.ai_socktype = socktype;
hints.ai_protocol = protocol;
return getaddrinfo(node, service, &hints, &addr);
}
private:
addrinfo *addr;
};
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_AUTO_FILE_HPP
#define DENA_AUTO_FILE_HPP
/*
#ifndef __WIN__
#include <dirent.h>
#endif
*/
#include "util.hpp"
namespace dena {
struct auto_file : private noncopyable {
auto_file() : fd(-1) { }
~auto_file() {
reset();
}
int get() const { return fd; }
int close() {
if (fd < 0) {
return 0;
}
const int r = ::close(fd);
fd = -1;
return r;
}
void reset(int x = -1) {
if (fd >= 0) {
this->close();
}
fd = x;
}
private:
int fd;
};
/*
struct auto_dir : private noncopyable {
auto_dir() : dp(0) { }
~auto_dir() {
reset();
}
DIR *get() const { return dp; }
void reset(DIR *d = 0) {
if (dp != 0) {
closedir(dp);
}
dp = d;
}
private:
DIR *dp;
};
*/
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_AUTO_PTRCONTAINER_HPP
#define DENA_AUTO_PTRCONTAINER_HPP
namespace dena {
/*
template <typename Tcnt>
struct auto_ptrcontainer {
typedef Tcnt container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::pointer pointer;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
typedef typename container_type::difference_type difference_type;
typedef typename container_type::iterator iterator;
typedef typename container_type::const_iterator const_iterator;
typedef typename container_type::reverse_iterator reverse_iterator;
typedef typename container_type::const_reverse_iterator
const_reverse_iterator;
iterator begin() { return cnt.begin(); }
const_iterator begin() const { return cnt.begin(); }
iterator end() { return cnt.end(); }
const_iterator end() const { return cnt.end(); }
reverse_iterator rbegin() { return cnt.rbegin(); }
reverse_iterator rend() { return cnt.rend(); }
const_reverse_iterator rbegin() const { return cnt.rbegin(); }
const_reverse_iterator rend() const { return cnt.rend(); }
size_type size() const { return cnt.size(); }
size_type max_size() const { return cnt.max_size(); }
bool empty() const { return cnt.empty(); }
reference front() { return cnt.front(); }
const_reference front() const { cnt.front(); }
reference back() { return cnt.back(); }
const_reference back() const { cnt.back(); }
void swap(auto_ptrcontainer& x) { cnt.swap(x.cnt); }
~auto_ptrcontainer() {
for (iterator i = begin(); i != end(); ++i) {
delete *i;
}
}
template <typename Tap> void push_back_ptr(Tap& ap) {
cnt.push_back(ap.get());
ap.release();
}
void erase_ptr(iterator i) {
delete *i;
cnt.erase(i);
}
reference operator [](size_type n) { return cnt[n]; }
const_reference operator [](size_type n) const { return cnt[n]; }
void clear() { cnt.clear(); }
private:
Tcnt cnt;
};
*/
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#include <my_global.h>
#include "mysql_version.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "config.hpp"
namespace dena {
unsigned int verbose_level = 0;
uchar *
conf_get_key(
conf_param *param,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
*length = param->key.length();
return (uchar*) param->key.ptr();
}
config::config()
{
if (my_hash_init(PSI_INSTRUMENT_ME, &conf_hash, &my_charset_bin, 32, 0, 0,
(my_hash_get_key) conf_get_key, 0, 0))
init = FALSE;
else
init = TRUE;
return;
}
config::~config()
{
if (init)
{
conf_param *param;
while ((param = (conf_param *) my_hash_element(&conf_hash, 0)))
{
my_hash_delete(&conf_hash, (uchar*) param);
delete param;
}
my_hash_free(&conf_hash);
}
}
conf_param *
config::find(const String& key) const
{
if (init)
return (conf_param *) my_hash_search(&conf_hash, (const uchar*) key.ptr(),
key.length());
else
return NULL;
}
conf_param *
config::find(const char *key) const
{
if (init)
return (conf_param *) my_hash_search(&conf_hash, (const uchar*) key,
strlen(key));
else
return NULL;
}
String
config::get_str(const String& key, const String& def) const
{
DENA_VERBOSE(30, list_all_params());
conf_param *param = find(key);
if (!param) {
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key.ptr(),
def.ptr()));
return def;
}
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", key.ptr(),
param->val.ptr()));
return param->val;
}
String
config::get_str(const char *key, const char *def) const
{
DENA_VERBOSE(30, list_all_params());
conf_param *param = find(key);
if (!param) {
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key, def));
return String(def, strlen(def), &my_charset_bin);
}
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n",
key, param->val.ptr()));
return param->val;
}
long long
config::get_int(const String& key, long long def) const
{
int err;
DENA_VERBOSE(30, list_all_params());
conf_param *param = find(key);
if (!param) {
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key.ptr(),
def));
return def;
}
const long long r = my_strtoll10(param->val.ptr(), (char**) NULL, &err);
if (err) {
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(err)\n", key.ptr(),
def));
return def;
}
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key.ptr(), r));
return r;
}
long long
config::get_int(const char *key, long long def) const
{
int err;
DENA_VERBOSE(30, list_all_params());
conf_param *param = find(key);
if (!param) {
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key, def));
return def;
}
const long long r = my_strtoll10(param->val.ptr(), (char**) NULL, &err);
if (err) {
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(err)\n", key, def));
return def;
}
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key, r));
return r;
}
bool
config::replace(const char *key, const char *val)
{
uint32 val_len = strlen(val);
conf_param *param = find(key);
if (!param) {
/* create */
if (!(param = new conf_param()))
return TRUE;
uint32 key_len = strlen(key);
if (
param->key.reserve(key_len + 1) ||
param->val.reserve(val_len + 1)
) {
delete param;
return TRUE;
}
param->key.q_append(key, key_len);
param->val.q_append(val, val_len);
param->key.c_ptr_safe();
param->val.c_ptr_safe();
if (my_hash_insert(&conf_hash, (uchar*) param))
{
delete param;
return TRUE;
}
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(create)\n",
param->key.ptr(), param->val.ptr()));
return FALSE;
}
/* replace */
param->val.length(0);
if (param->val.reserve(val_len + 1))
return TRUE;
param->val.q_append(val, val_len);
param->val.c_ptr_safe();
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(replace)\n",
param->key.ptr(), param->val.ptr()));
return FALSE;
}
bool
config::replace(const char *key, long long val)
{
char val_str[22];
sprintf(val_str, "%lld", val);
return replace(key, val_str);
}
bool
config::compare(const char *key, const char *val)
{
conf_param *param = find(key);
if (!param)
return FALSE;
return !strcmp(param->val.ptr(), val);
}
void
config::list_all_params() const
{
conf_param *param;
DENA_VERBOSE(10, fprintf(stderr, "list_all_params start\n"));
for(ulong i = 0; i < conf_hash.records; i++)
{
if ((param = (conf_param *) my_hash_element((HASH *) &conf_hash, i)))
{
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n",
param->key.ptr(), param->val.ptr()));
}
}
DENA_VERBOSE(10, fprintf(stderr, "list_all_params end\n"));
}
config&
config::operator =(const config& x)
{
DENA_VERBOSE(10, fprintf(stderr, "config operator = start"));
if (this != &x && init && x.init) {
conf_param *param, *new_param;
for(ulong i = 0; i < x.conf_hash.records; i++)
{
if ((param = (conf_param *) my_hash_element((HASH *) &x.conf_hash, i)))
if ((new_param = new conf_param()))
{
if (
!new_param->key.copy(param->key) &&
!new_param->val.copy(param->val)
) {
new_param->key.c_ptr_safe();
new_param->val.c_ptr_safe();
DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n",
new_param->key.ptr(), new_param->val.ptr()));
if (my_hash_insert(&conf_hash, (uchar*) new_param))
delete new_param;
} else
delete new_param;
}
}
}
DENA_VERBOSE(10, fprintf(stderr, "config operator = end %p", this));
return *this;
}
void
parse_args(int argc, char **argv, config& conf)
{
conf_param *param;
for (int i = 1; i < argc; ++i) {
const char *const arg = argv[i];
const char *const eq = strchr(arg, '=');
if (eq == 0) {
continue;
}
if (!(param = new conf_param()))
continue;
uint32 key_len = (uint32)(eq - arg);
uint32 val_len = strlen(eq + 1);
if (
param->key.reserve(key_len + 1) ||
param->val.reserve(val_len + 1)
) {
delete param;
continue;
}
param->key.q_append(arg, key_len);
param->val.q_append(eq + 1, val_len);
param->key.c_ptr_safe();
param->val.c_ptr_safe();
if (my_hash_insert(&conf.conf_hash, (uchar*) param))
{
delete param;
continue;
}
}
param = conf.find("verbose");
if (param) {
verbose_level = atoi(param->val.c_ptr());
}
}
};
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_CONFIG_HPP
#define DENA_CONFIG_HPP
#include "mysql_version.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#define DENA_VERBOSE(lv, x) if (dena::verbose_level >= (lv)) { (x); }
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
#define INFO_KIND_HS_RET_FIELDS 1
#define INFO_KIND_HS_APPEND_STRING_REF 3
#define INFO_KIND_HS_CLEAR_STRING_REF 4
#define INFO_KIND_HS_INCREMENT_BEGIN 5
#define INFO_KIND_HS_INCREMENT_END 6
#define INFO_KIND_HS_DECREMENT_BEGIN 7
#define INFO_KIND_HS_DECREMENT_END 8
#endif
namespace dena {
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
struct uint32_info {
size_t info_size;
uint32 *info;
};
#endif
struct conf_param {
String key;
String val;
};
uchar *conf_get_key(
conf_param *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
);
struct config {
bool init;
HASH conf_hash;
config();
~config();
conf_param *find(const String& key) const;
conf_param *find(const char *key) const;
String get_str(const String& key, const String& def =
String("", &my_charset_bin)) const;
String get_str(const char *key, const char *def = "") const;
long long get_int(const String& key, long long def = 0) const;
long long get_int(const char *key, long long def = 0) const;
bool replace(const char *key, const char *val);
bool replace(const char *key, long long val);
bool compare(const char *key, const char *val);
void list_all_params() const;
config& operator =(const config& x);
};
void parse_args(int argc, char **argv, config& conf);
extern unsigned int verbose_level;
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#include <my_global.h>
#include "mysql_version.h"
#include "hs_compat.h"
#include "escape.hpp"
#include "string_buffer.hpp"
#include "fatal.hpp"
#include "string_util.hpp"
#define DBG_OP(x)
#define DBG_BUF(x)
namespace dena {
enum special_char_t {
special_char_escape_prefix = 0x01, /* SOH */
special_char_noescape_min = 0x10, /* DLE */
special_char_escape_shift = 0x40, /* '@' */
};
void
escape_string(char *& wp, const char *start, const char *finish)
{
while (start != finish) {
const unsigned char c = *start;
if (c >= special_char_noescape_min) {
wp[0] = c; /* no need to escape */
} else {
wp[0] = special_char_escape_prefix;
++wp;
wp[0] = c + special_char_escape_shift;
}
++start;
++wp;
}
}
void
escape_string(string_buffer& ar, const char *start, const char *finish)
{
const size_t buflen = (finish - start) * 2;
char *const wp_begin = ar.make_space(buflen);
char *wp = wp_begin;
escape_string(wp, start, finish);
ar.space_wrote(wp - wp_begin);
}
bool
unescape_string(char *& wp, const char *start, const char *finish)
{
/* works even if wp == start */
while (start != finish) {
const unsigned char c = *start;
if (c != special_char_escape_prefix) {
wp[0] = c;
} else if (start + 1 != finish) {
++start;
const unsigned char cn = *start;
if (cn < special_char_escape_shift) {
return false;
}
wp[0] = cn - special_char_escape_shift;
} else {
return false;
}
++start;
++wp;
}
return true;
}
bool
unescape_string(string_buffer& ar, const char *start, const char *finish)
{
const size_t buflen = finish - start;
char *const wp_begin = ar.make_space(buflen);
char *wp = wp_begin;
const bool r = unescape_string(wp, start, finish);
ar.space_wrote(wp - wp_begin);
return r;
}
uint32
read_ui32(char *& start, char *finish)
{
char *const n_begin = start;
read_token(start, finish);
char *const n_end = start;
uint32 v = 0;
for (char *p = n_begin; p != n_end; ++p) {
const char ch = p[0];
if (ch >= '0' && ch <= '9') {
v *= 10;
v += (ch - '0');
}
}
return v;
}
void
write_ui32(string_buffer& buf, uint32 v)
{
char *wp = buf.make_space(12);
int len = snprintf(wp, 12, "%u", v);
if (len > 0) {
buf.space_wrote(len);
}
}
void
write_ui64(string_buffer& buf, uint64 v)
{
char *wp = buf.make_space(22);
int len = snprintf(wp, 22, "%llu", static_cast<unsigned long long>(v));
if (len > 0) {
buf.space_wrote(len);
}
}
};
// vim:sw=2:ai
/*
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
* See COPYRIGHT.txt for details.
*/
#include "string_buffer.hpp"
#include "string_ref.hpp"
#include "string_util.hpp"
#ifndef DENA_ESCAPE_HPP
#define DENA_ESCAPE_HPP
namespace dena {
void escape_string(char *& wp, const char *start, const char *finish);
void escape_string(string_buffer& ar, const char *start, const char *finish);
bool unescape_string(char *& wp, const char *start, const char *finish);
/* unescaped_string() works even if wp == start */
bool unescape_string(string_buffer& ar, const char *start, const char *finish);
uint32 read_ui32(char *& start, char *finish);
void write_ui32(string_buffer& buf, uint32 v);
void write_ui64(string_buffer& buf, uint64 v);
inline bool
is_null_expression(const char *start, const char *finish)
{
return (finish == start + 1 && start[0] == 0);
}
inline void
read_token(char *& start, char *finish)
{
char *const p = memchr_char(start, '\t', finish - start);
if (p == 0) {
start = finish;
} else {
start = p;
}
}
inline void
skip_token_delim_fold(char *& start, char *finish)
{
while (start != finish && start[0] == '\t') {
++start;
}
}
inline void
skip_one(char *& start, char *finish)
{
if (start != finish) {
++start;
}
}
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#include <my_global.h>
#include "mysql_version.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "fatal.hpp"
namespace dena {
/*
const int opt_syslog = LOG_ERR | LOG_PID | LOG_CONS;
*/
void
fatal_abort(const String& message)
{
fprintf(stderr, "FATAL_COREDUMP: %s\n", message.ptr());
/*
syslog(opt_syslog, "FATAL_COREDUMP: %s", message.ptr());
*/
abort();
}
void
fatal_abort(const char *message)
{
fprintf(stderr, "FATAL_COREDUMP: %s\n", message);
/*
syslog(opt_syslog, "FATAL_COREDUMP: %s", message);
*/
abort();
}
};
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_FATAL_HPP
#define DENA_FATAL_HPP
#include "mysql_version.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
namespace dena {
void fatal_abort(const String& message);
void fatal_abort(const char *message);
};
#endif
This diff is collapsed.
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_HSTCPCLI_HPP
#define DENA_HSTCPCLI_HPP
#define HANDLERSOCKET_MYSQL_UTIL 1
#include "mysql_version.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "config.hpp"
#include "socket.hpp"
#include "string_ref.hpp"
#include "string_buffer.hpp"
namespace dena {
struct hstcpcli_filter {
string_ref filter_type;
string_ref op;
size_t ff_offset;
string_ref val;
hstcpcli_filter() : ff_offset(0) { }
};
struct hstcpcli_i;
typedef hstcpcli_i *hstcpcli_ptr;
struct hstresult {
hstresult();
virtual ~hstresult();
string_buffer readbuf;
size_t response_end_offset;
size_t num_flds;
size_t cur_row_offset;
size_t cur_row_size;
DYNAMIC_ARRAY flds;
};
struct hstcpcli_i {
virtual ~hstcpcli_i() = default;
virtual void close() = 0;
virtual int reconnect() = 0;
virtual bool stable_point() = 0;
virtual void request_buf_auth(const char *secret, const char *typ) = 0;
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
const char *tbl, const char *idx, const char *retflds,
const char *filflds = 0) = 0;
virtual void request_buf_exec_generic(size_t pst_id, const string_ref& op,
const string_ref *kvs, size_t kvslen, uint32 limit, uint32 skip,
const string_ref& mod_op, const string_ref *mvs, size_t mvslen,
const hstcpcli_filter *fils = 0, size_t filslen = 0,
int invalues_keypart = -1, const string_ref *invalues = 0,
size_t invalueslen = 0) = 0; // FIXME: too long
virtual size_t request_buf_append(const char *start, const char *finish) = 0;
virtual void request_reset() = 0;
virtual int request_send() = 0;
virtual int response_recv(size_t& num_flds_r) = 0;
virtual int get_result(hstresult& result) = 0;
virtual const string_ref *get_next_row() = 0;
virtual const string_ref *get_next_row_from_result(hstresult& result) = 0;
virtual size_t get_row_size() = 0;
virtual size_t get_row_size_from_result(hstresult& result) = 0;
virtual void response_buf_remove() = 0;
virtual int get_error_code() = 0;
virtual String& get_error() = 0;
virtual void clear_error() = 0;
virtual int set_timeout(int send_timeout, int recv_timeout) = 0;
virtual size_t get_num_req_bufd() = 0;
virtual size_t get_num_req_sent() = 0;
virtual size_t get_num_req_rcvd() = 0;
virtual size_t get_response_end_offset() = 0;
virtual const char *get_readbuf_begin() = 0;
virtual const char *get_readbuf_end() = 0;
virtual const char *get_writebuf_begin() = 0;
virtual size_t get_writebuf_size() = 0;
virtual void write_error_to_log(const char *func_name, const char *file_name,
ulong line_no) = 0;
static hstcpcli_ptr create(const socket_args& args);
};
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_MUTEX_HPP
#define DENA_MUTEX_HPP
#include "fatal.hpp"
#include "util.hpp"
namespace dena {
struct condition;
struct mutex : private noncopyable {
friend struct condition;
mutex() {
if (pthread_mutex_init(&mtx, 0) != 0) {
fatal_abort("pthread_mutex_init");
}
}
~mutex() {
if (pthread_mutex_destroy(&mtx) != 0) {
fatal_abort("pthread_mutex_destroy");
}
}
void lock() const {
if (pthread_mutex_lock(&mtx) != 0) {
fatal_abort("pthread_mutex_lock");
}
}
void unlock() const {
if (pthread_mutex_unlock(&mtx) != 0) {
fatal_abort("pthread_mutex_unlock");
}
}
private:
mutable pthread_mutex_t mtx;
};
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#include <my_global.h>
#include <my_config.h>
#ifndef __WIN__
#include <sys/types.h>
#include <sys/un.h>
#endif
#include "mysql_version.h"
#include "hs_compat.h"
#include <my_global.h>
#include "sql_priv.h"
#include "probes_mysql.h"
#include "socket.hpp"
#include "string_util.hpp"
#include "fatal.hpp"
/*
struct sockaddr_un {
short sun_family;
char sun_path[108];
};
*/
namespace dena {
void
ignore_sigpipe()
{
#if defined(SIGPIPE) && !defined(__WIN__)
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
fatal_abort("SIGPIPE SIG_IGN");
}
#endif
}
void
socket_args::set(const config& conf)
{
timeout = (int) conf.get_int("timeout", 600);
listen_backlog = (int) conf.get_int("listen_backlog", 256);
String node = conf.get_str("host", "");
String port = conf.get_str("port", "");
if (node.length() || port.length()) {
if (family == AF_UNIX || !strcmp(node.c_ptr(), "/")) {
set_unix_domain(port.c_ptr());
} else {
const char *nd = !node.length() ? 0 : node.c_ptr();
if (resolve(nd, port.c_ptr()) != 0) {
String message("getaddrinfo failed: ", &my_charset_bin);
message.reserve(node.length() + sizeof(":") - 1 + port.length());
message.append(node);
message.q_append(":", sizeof(":") - 1);
message.append(port);
fatal_abort(message);
}
}
}
sndbuf = (int) conf.get_int("sndbuf", 0);
rcvbuf = (int) conf.get_int("rcvbuf", 0);
}
void
socket_args::set_unix_domain(const char *path)
{
#ifndef __WIN__
family = AF_UNIX;
addr = sockaddr_storage();
addrlen = sizeof(sockaddr_un);
sockaddr_un *const ap = reinterpret_cast<sockaddr_un *>(&addr);
ap->sun_family = AF_UNIX;
strncpy(ap->sun_path, path, sizeof(ap->sun_path) - 1);
#endif
}
int
socket_args::resolve(const char *node, const char *service)
{
const int flags = (node == 0) ? AI_PASSIVE : 0;
auto_addrinfo ai;
addr = sockaddr_storage();
addrlen = 0;
const int r = ai.resolve(node, service, flags, family, socktype, protocol);
if (r != 0) {
return r;
}
memcpy(&addr, ai.get()->ai_addr, ai.get()->ai_addrlen);
addrlen = ai.get()->ai_addrlen;
return 0;
}
int
socket_set_timeout(auto_file& fd, const socket_args& args, String& err_r)
{
if (!args.nonblocking) {
#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
if (args.recv_timeout != 0) {
#ifndef __WIN__
struct timeval tv;
tv.tv_sec = args.recv_timeout;
tv.tv_usec = 0;
#else
int tv = args.recv_timeout * 1000;
#endif
if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVTIMEO,
#ifndef __WIN__
(const void *) &tv,
#else
(const char *) &tv,
#endif
sizeof(tv)) != 0) {
return errno_string("setsockopt SO_RCVTIMEO", errno, err_r);
}
}
if (args.send_timeout != 0) {
#ifndef __WIN__
struct timeval tv;
tv.tv_sec = args.send_timeout;
tv.tv_usec = 0;
#else
int tv = args.send_timeout * 1000;
#endif
if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDTIMEO,
#ifndef __WIN__
(const void *) &tv,
#else
(const char *) &tv,
#endif
sizeof(tv)) != 0) {
return errno_string("setsockopt SO_SNDTIMEO", errno, err_r);
}
}
#endif
}
return 0;
}
int
socket_set_options(auto_file& fd, const socket_args& args, String& err_r)
{
if (args.timeout != 0 && !args.nonblocking) {
#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
#ifndef __WIN__
struct timeval tv;
tv.tv_sec = args.timeout;
tv.tv_usec = 0;
#else
int tv = args.timeout * 1000;
#endif
if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVTIMEO,
#ifndef __WIN__
(const void *) &tv,
#else
(const char *) &tv,
#endif
sizeof(tv)) != 0) {
return errno_string("setsockopt SO_RCVTIMEO", errno, err_r);
}
#ifndef __WIN__
tv.tv_sec = args.timeout;
tv.tv_usec = 0;
#else
tv = args.timeout * 1000;
#endif
if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDTIMEO,
#ifndef __WIN__
(const void *) &tv,
#else
(const char *) &tv,
#endif
sizeof(tv)) != 0) {
return errno_string("setsockopt SO_RCVTIMEO", errno, err_r);
}
#endif
}
#ifndef __WIN__
if (args.nonblocking && fcntl(fd.get(), F_SETFL, O_NONBLOCK) != 0) {
return errno_string("fcntl O_NONBLOCK", errno, err_r);
}
#endif
if (args.sndbuf != 0) {
const int v = args.sndbuf;
if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDBUF,
#ifndef __WIN__
(const void *) &v,
#else
(const char *) &v,
#endif
sizeof(v)) != 0) {
return errno_string("setsockopt SO_SNDBUF", errno, err_r);
}
}
if (args.rcvbuf != 0) {
const int v = args.rcvbuf;
if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVBUF,
#ifndef __WIN__
(const void *) &v,
#else
(const char *) &v,
#endif
sizeof(v)) != 0) {
return errno_string("setsockopt SO_RCVBUF", errno, err_r);
}
}
return 0;
}
int
socket_open(auto_file& fd, const socket_args& args, String& err_r)
{
fd.reset((int) socket(args.family, args.socktype, args.protocol));
if (fd.get() < 0) {
return errno_string("socket", errno, err_r);
}
return socket_set_options(fd, args, err_r);
}
int
socket_connect(auto_file& fd, const socket_args& args, String& err_r)
{
int r = 0;
if ((r = socket_open(fd, args, err_r)) != 0) {
return r;
}
if (connect(fd.get(), reinterpret_cast<const sockaddr *>(&args.addr),
args.addrlen) != 0) {
if (!args.nonblocking
#ifndef __WIN__
|| errno != EINPROGRESS
#endif
) {
return errno_string("connect", errno, err_r);
}
}
return 0;
}
int
socket_bind(auto_file& fd, const socket_args& args, String& err_r)
{
fd.reset((int) socket(args.family, args.socktype, args.protocol));
if (fd.get() < 0) {
return errno_string("socket", errno, err_r);
}
if (args.reuseaddr) {
#ifndef __WIN__
if (args.family == AF_UNIX) {
const sockaddr_un *const ap =
reinterpret_cast<const sockaddr_un *>(&args.addr);
if (unlink(ap->sun_path) != 0 && errno != ENOENT) {
return errno_string("unlink uds", errno, err_r);
}
} else {
#endif
int v = 1;
if (setsockopt(fd.get(), SOL_SOCKET, SO_REUSEADDR,
#ifndef __WIN__
(const void *) &v,
#else
(const char *) &v,
#endif
sizeof(v)) != 0) {
return errno_string("setsockopt SO_REUSEADDR", errno, err_r);
}
#ifndef __WIN__
}
#endif
}
if (bind(fd.get(), reinterpret_cast<const sockaddr *>(&args.addr),
args.addrlen) != 0) {
return errno_string("bind", errno, err_r);
}
if (listen(fd.get(), args.listen_backlog) != 0) {
return errno_string("listen", errno, err_r);
}
#ifndef __WIN__
if (args.nonblocking && fcntl(fd.get(), F_SETFL, O_NONBLOCK) != 0) {
return errno_string("fcntl O_NONBLOCK", errno, err_r);
}
#endif
return 0;
}
int
socket_accept(int listen_fd, auto_file& fd, const socket_args& args,
sockaddr_storage& addr_r, socklen_t& addrlen_r, String& err_r)
{
fd.reset((int) accept(listen_fd, reinterpret_cast<sockaddr *>(&addr_r),
&addrlen_r));
if (fd.get() < 0) {
return errno_string("accept", errno, err_r);
}
return socket_set_options(fd, args, err_r);
}
};
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_SOCKET_HPP
#define DENA_SOCKET_HPP
#include "mysql_version.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "auto_addrinfo.hpp"
#include "auto_file.hpp"
#include "config.hpp"
namespace dena {
struct socket_args {
sockaddr_storage addr;
socklen_t addrlen;
int family;
int socktype;
int protocol;
int timeout;
int send_timeout;
int recv_timeout;
int listen_backlog;
bool reuseaddr;
bool nonblocking;
bool use_epoll;
int sndbuf;
int rcvbuf;
socket_args() : addr(), addrlen(0), family(AF_INET), socktype(SOCK_STREAM),
protocol(0), timeout(600), send_timeout(600), recv_timeout(600),
listen_backlog(256), reuseaddr(true), nonblocking(false), use_epoll(false),
sndbuf(0), rcvbuf(0) { }
void set(const config& conf);
void set_unix_domain(const char *path);
int resolve(const char *node, const char *service);
};
void ignore_sigpipe();
int socket_set_timeout(auto_file& fd, const socket_args& args, String& err_r);
int socket_bind(auto_file& fd, const socket_args& args, String& err_r);
int socket_connect(auto_file& fd, const socket_args& args, String& err_r);
int socket_accept(int listen_fd, auto_file& fd, const socket_args& args,
sockaddr_storage& addr_r, socklen_t& addrlen_r, String& err_r);
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_STRING_BUFFER_HPP
#define DENA_STRING_BUFFER_HPP
/*
#include <stdlib.h>
#include <string.h>
*/
#include "util.hpp"
#include "allocator.hpp"
#include "fatal.hpp"
namespace dena {
struct string_buffer : private noncopyable {
string_buffer() : buffer(0), begin_offset(0), end_offset(0), alloc_size(0) { }
~string_buffer() {
real_free();
}
void real_free() {
if (alloc_size) {
DENA_FREE(buffer);
buffer = 0;
begin_offset = 0;
end_offset = 0;
alloc_size = 0;
}
}
size_t real_size() {
return alloc_size;
}
const char *begin() const {
return buffer + begin_offset;
}
const char *end() const {
return buffer + end_offset;
}
char *begin() {
return buffer + begin_offset;
}
char *end() {
return buffer + end_offset;
}
size_t size() const {
return end_offset - begin_offset;
}
void clear() {
begin_offset = end_offset = 0;
}
void resize(size_t len) {
if (size() < len) {
reserve(len);
memset(buffer + end_offset, 0, len - size());
}
end_offset = begin_offset + len;
}
void reserve(size_t len) {
if (alloc_size >= begin_offset + len) {
return;
}
size_t asz = alloc_size;
while (asz < begin_offset + len) {
if (asz == 0) {
asz = 16;
}
const size_t asz_n = asz << 1;
if (asz_n < asz) {
fatal_abort("string_buffer::resize() overflow");
}
asz = asz_n;
}
void *const p = DENA_REALLOC(buffer, asz);
if (p == 0) {
fatal_abort("string_buffer::resize() realloc");
}
buffer = static_cast<char *>(p);
alloc_size = asz;
}
void erase_front(size_t len) {
if (len >= size()) {
clear();
} else {
begin_offset += len;
}
}
char *make_space(size_t len) {
reserve(size() + len);
return buffer + end_offset;
}
void space_wrote(size_t len) {
len = len < alloc_size - end_offset ? len : alloc_size - end_offset;
end_offset += len;
}
template <size_t N>
void append_literal(const char (& str)[N]) {
append(str, str + N - 1);
}
void append(const char *start, const char *finish) {
const size_t len = finish - start;
reserve(size() + len);
memcpy(buffer + end_offset, start, len);
end_offset += len;
}
void append_2(const char *s1, const char *f1, const char *s2,
const char *f2) {
const size_t l1 = f1 - s1;
const size_t l2 = f2 - s2;
reserve(end_offset + l1 + l2);
memcpy(buffer + end_offset, s1, l1);
memcpy(buffer + end_offset + l1, s2, l2);
end_offset += l1 + l2;
}
void swap(string_buffer& sb) {
char *tmp_buffer = buffer;
size_t tmp_begin_offset = begin_offset;
size_t tmp_end_offset = end_offset;
size_t tmp_alloc_size = alloc_size;
buffer = sb.buffer;
begin_offset = sb.begin_offset;
end_offset = sb.end_offset;
alloc_size = sb.alloc_size;
sb.buffer = tmp_buffer;
sb.begin_offset = tmp_begin_offset;
sb.end_offset = tmp_end_offset;
sb.alloc_size = tmp_alloc_size;
}
private:
char *buffer;
size_t begin_offset;
size_t end_offset;
size_t alloc_size;
};
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_STRING_REF_HPP
#define DENA_STRING_REF_HPP
namespace dena {
struct string_wref {
typedef char value_type;
char *begin() const { return start; }
char *end() const { return start + length; }
size_t size() const { return length; }
private:
char *start;
size_t length;
public:
string_wref(char *s = 0, size_t len = 0) : start(s), length(len) { }
};
struct string_ref {
typedef const char value_type;
const char *begin() const { return start; }
const char *end() const { return start + length; }
size_t size() const { return length; }
void set(const char *s, size_t len) { start = s; length = len; }
void set(const char *s, const char *f) { start = s; length = f - s; }
private:
const char *start;
size_t length;
public:
string_ref(const char *s = 0, size_t len = 0) : start(s), length(len) { }
string_ref(const char *s, const char *f) : start(s), length(f - s) { }
string_ref(const string_wref& w) : start(w.begin()), length(w.size()) { }
};
template <size_t N> inline bool
operator ==(const string_ref& x, const char (& y)[N]) {
return (x.size() == N - 1) && (::memcmp(x.begin(), y, N - 1) == 0);
}
inline bool
operator ==(const string_ref& x, const string_ref& y) {
return (x.size() == y.size()) &&
(::memcmp(x.begin(), y.begin(), x.size()) == 0);
}
inline bool
operator !=(const string_ref& x, const string_ref& y) {
return (x.size() != y.size()) ||
(::memcmp(x.begin(), y.begin(), x.size()) != 0);
}
struct string_ref_list_wrap {
string_ref_list_wrap() {
if (SPD_INIT_DYNAMIC_ARRAY2(&string_ref_list, sizeof(string_ref),
NULL, 16, 16, MYF(MY_WME)))
string_ref_list_init = FALSE;
else
string_ref_list_init = TRUE;
}
virtual ~string_ref_list_wrap() {
if (string_ref_list_init) delete_dynamic(&string_ref_list); }
void clear() {
if (string_ref_list_init) string_ref_list.elements = 0; }
void push_back(string_ref &e) {
if (string_ref_list_init) insert_dynamic(&string_ref_list, (uchar*) &e);
return; }
size_t size() {
return string_ref_list_init ? string_ref_list.elements : 0; }
bool resize(size_t new_size) {
if (string_ref_list_init) {
if (string_ref_list.max_element < new_size && allocate_dynamic(
&string_ref_list, new_size)) return TRUE;
string_ref_list.elements = new_size;
return FALSE;
}
return TRUE;
}
bool empty() {
return string_ref_list_init ? string_ref_list.elements ?
FALSE : TRUE : TRUE; }
string_ref &operator [](size_t n) {
return ((string_ref *) (string_ref_list.buffer +
string_ref_list.size_of_element * n))[0]; }
bool string_ref_list_init;
DYNAMIC_ARRAY string_ref_list;
};
inline String *
q_append_str(String *str, const char *p) {
uint32 p_len = strlen(p);
if (str->reserve(p_len)) return NULL;
str->q_append(p, p_len); return str;
}
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011-2017 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#include <my_global.h>
#include "mysql_version.h"
#include "hs_compat.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "string_util.hpp"
namespace dena {
string_wref
get_token(char *& wp, char *wp_end, char delim)
{
char *const wp_begin = wp;
char *const p = memchr_char(wp_begin, delim, wp_end - wp_begin);
if (p == 0) {
wp = wp_end;
return string_wref(wp_begin, wp_end - wp_begin);
}
wp = p + 1;
return string_wref(wp_begin, p - wp_begin);
}
uint32
atoi_uint32_nocheck(const char *start, const char *finish)
{
uint32 v = 0;
for (; start != finish; ++start) {
const char c = *start;
if (c < '0' || c > '9') {
break;
}
v *= 10;
v += (uint32) (c - '0');
}
return v;
}
long long
atoll_nocheck(const char *start, const char *finish)
{
long long v = 0;
bool negative = false;
if (start != finish) {
if (start[0] == '-') {
++start;
negative = true;
} else if (start[0] == '+') {
++start;
}
}
for (; start != finish; ++start) {
const char c = *start;
if (c < '0' || c > '9') {
break;
}
v *= 10;
if (negative) {
v -= (long long) (c - '0');
} else {
v += (long long) (c - '0');
}
}
return v;
}
void
append_uint32(string_buffer& buf, uint32 v)
{
char *const wp = buf.make_space(64);
const int len = snprintf(wp, 64, "%lu", static_cast<unsigned long>(v));
if (len > 0) {
buf.space_wrote(len);
}
}
/*
String *
to_stdstring(uint32 v)
{
char buf[64];
int str_len;
String *str;
str_len = snprintf(buf, sizeof(buf), "%lu", static_cast<unsigned long>(v));
if ((str = new String(str_len + 1)))
str->q_append(buf, str_len);
return str;
}
*/
int
errno_string(const char *s, int en, String& err_r)
{
char buf[64];
int str_len;
str_len = snprintf(buf, sizeof(buf), "%s: %d", s, en);
if (!err_r.reserve(str_len + 1))
err_r.q_append(buf, str_len);
return en;
}
size_t
split(char delim, const string_ref& buf, string_ref *parts,
size_t parts_len)
{
size_t i = 0;
const char *start = buf.begin();
const char *const finish = buf.end();
for (i = 0; i < parts_len; ++i) {
const char *const p = memchr_char(start, delim, finish - start);
if (p == 0) {
parts[i] = string_ref(start, finish - start);
++i;
break;
}
parts[i] = string_ref(start, p - start);
start = p + 1;
}
const size_t r = i;
for (; i < parts_len; ++i) {
parts[i] = string_ref();
}
return r;
}
size_t
split(char delim, const string_wref& buf, string_wref *parts,
size_t parts_len)
{
size_t i = 0;
char *start = buf.begin();
char *const finish = buf.end();
for (i = 0; i < parts_len; ++i) {
char *const p = memchr_char(start, delim, finish - start);
if (p == 0) {
parts[i] = string_wref(start, finish - start);
++i;
break;
}
parts[i] = string_wref(start, p - start);
start = p + 1;
}
const size_t r = i;
for (; i < parts_len; ++i) {
parts[i] = string_wref();
}
return r;
}
size_t
split(char delim, const string_ref& buf, DYNAMIC_ARRAY& parts_r)
{
size_t i = 0;
const char *start = buf.begin();
const char *finish = buf.end();
while (true) {
const char *p = memchr_char(start, delim, finish - start);
if (p == 0) {
string_ref param(start, finish - start);
insert_dynamic(&parts_r, (uchar *) &param);
break;
}
string_ref param(start, p - start);
insert_dynamic(&parts_r, (uchar *) &param);
start = p + 1;
}
const size_t r = i;
return r;
}
size_t
split(char delim, const string_wref& buf, DYNAMIC_ARRAY& parts_r)
{
size_t i = 0;
char *start = buf.begin();
char *finish = buf.end();
while (true) {
char *p = memchr_char(start, delim, finish - start);
if (p == 0) {
string_wref param(start, finish - start);
insert_dynamic(&parts_r, (uchar *) &param);
break;
}
string_wref param(start, p - start);
insert_dynamic(&parts_r, (uchar *) &param);
start = p + 1;
}
const size_t r = i;
return r;
}
};
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_STRING_UTIL_HPP
#define DENA_STRING_UTIL_HPP
#include "string_buffer.hpp"
#include "string_ref.hpp"
namespace dena {
inline const char *
memchr_char(const char *s, int c, size_t n)
{
return static_cast<const char *>(memchr(s, c, n));
}
inline char *
memchr_char(char *s, int c, size_t n)
{
return static_cast<char *>(memchr(s, c, n));
}
string_wref get_token(char *& wp, char *wp_end, char delim);
uint32 atoi_uint32_nocheck(const char *start, const char *finish);
/*
String *to_stdstring(uint32 v);
*/
void append_uint32(string_buffer& buf, uint32 v);
long long atoll_nocheck(const char *start, const char *finish);
int errno_string(const char *s, int en, String& err_r);
size_t split(char delim, const string_ref& buf, string_ref *parts,
size_t parts_len);
size_t split(char delim, const string_wref& buf, string_wref *parts,
size_t parts_len);
size_t split(char delim, const string_ref& buf,
DYNAMIC_ARRAY& parts_r);
size_t split(char delim, const string_wref& buf,
DYNAMIC_ARRAY& parts_r);
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
* Copyright (C) 2011 Kentoku SHIBA
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_THREAD_HPP
#define DENA_THREAD_HPP
#include "fatal.hpp"
namespace dena {
/*
template <typename T>
struct thread : private noncopyable {
template <typename Ta> thread(const Ta& arg, size_t stack_sz = 256 * 1024)
: obj(arg), thr(0), need_join(false), stack_size(stack_sz) { }
template <typename Ta0, typename Ta1> thread(const Ta0& a0,
volatile Ta1& a1, size_t stack_sz = 256 * 1024)
: obj(a0, a1), thr(0), need_join(false), stack_size(stack_sz) { }
~thread() {
join();
}
void start() {
if (!start_nothrow()) {
fatal_abort("thread::start");
}
}
bool start_nothrow() {
if (need_join) {
return need_join;
}
void *const arg = this;
pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
fatal_abort("pthread_attr_init");
}
if (pthread_attr_setstacksize(&attr, stack_size) != 0) {
fatal_abort("pthread_attr_setstacksize");
}
const int r = pthread_create(&thr, &attr, thread_main, arg);
if (pthread_attr_destroy(&attr) != 0) {
fatal_abort("pthread_attr_destroy");
}
if (r != 0) {
return need_join;
}
need_join = true;
return need_join;
}
void join() {
if (!need_join) {
return;
}
int e = 0;
if ((e = pthread_join(thr, 0)) != 0) {
fatal_abort("pthread_join");
}
need_join = false;
}
T& operator *() { return obj; }
T *operator ->() { return &obj; }
private:
static void *thread_main(void *arg) {
thread *p = static_cast<thread *>(arg);
p->obj();
return 0;
}
private:
T obj;
pthread_t thr;
bool need_join;
size_t stack_size;
};
*/
};
#endif
// vim:sw=2:ai
/*
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
* See COPYRIGHT.txt for details.
*/
#ifndef DENA_UTIL_HPP
#define DENA_UTIL_HPP
namespace dena {
/* boost::noncopyable */
struct noncopyable {
noncopyable() = default;
private:
noncopyable(const noncopyable&);
noncopyable& operator =(const noncopyable&);
};
};
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -1217,11 +1217,6 @@ int spider_db_close_handler(
uint tgt_conn_kind
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
void spider_db_hs_request_buf_reset(
SPIDER_CONN *conn
);
#endif
bool spider_db_conn_is_network_error(
int error_num
......
This diff is collapsed.
This diff is collapsed.
......@@ -15,9 +15,6 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#include "hs_compat.h"
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#include "hstcpcli.hpp"
#endif
#define SPIDER_DBTON_SIZE 15
......@@ -91,26 +88,6 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_TABLE_NAME_STR "`table_name`"
#define SPIDER_SQL_TABLE_NAME_LEN sizeof(SPIDER_SQL_TABLE_NAME_STR) - 1
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#define SPIDER_SQL_HS_EQUAL_STR "="
#define SPIDER_SQL_HS_EQUAL_LEN (sizeof(SPIDER_SQL_HS_EQUAL_STR) - 1)
#define SPIDER_SQL_HS_GT_STR ">"
#define SPIDER_SQL_HS_GT_LEN (sizeof(SPIDER_SQL_HS_GT_STR) - 1)
#define SPIDER_SQL_HS_GTEQUAL_STR ">="
#define SPIDER_SQL_HS_GTEQUAL_LEN (sizeof(SPIDER_SQL_HS_GTEQUAL_STR) - 1)
#define SPIDER_SQL_HS_LT_STR "<"
#define SPIDER_SQL_HS_LT_LEN (sizeof(SPIDER_SQL_HS_LT_STR) - 1)
#define SPIDER_SQL_HS_INSERT_STR "+"
#define SPIDER_SQL_HS_INSERT_LEN (sizeof(SPIDER_SQL_HS_INSERT_STR) - 1)
#define SPIDER_SQL_HS_UPDATE_STR "U"
#define SPIDER_SQL_HS_UPDATE_LEN (sizeof(SPIDER_SQL_HS_UPDATE_STR) - 1)
#define SPIDER_SQL_HS_DELETE_STR "D"
#define SPIDER_SQL_HS_DELETE_LEN (sizeof(SPIDER_SQL_HS_DELETE_STR) - 1)
#define SPIDER_SQL_HS_INCREMENT_STR "+"
#define SPIDER_SQL_HS_INCREMENT_LEN (sizeof(SPIDER_SQL_HS_INCREMENT_STR) - 1)
#define SPIDER_SQL_HS_DECREMENT_STR "-"
#define SPIDER_SQL_HS_DECREMENT_LEN (sizeof(SPIDER_SQL_HS_DECREMENT_STR) - 1)
#endif
#define SPIDER_SQL_HS_LTEQUAL_STR "<="
#define SPIDER_SQL_HS_LTEQUAL_LEN (sizeof(SPIDER_SQL_HS_LTEQUAL_STR) - 1)
......@@ -202,16 +179,9 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_LOP_CHK_PRM_PRF_LEN (sizeof(SPIDER_SQL_LOP_CHK_PRM_PRF_STR) - 1)
#define SPIDER_CONN_KIND_MYSQL (1 << 0)
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#define SPIDER_CONN_KIND_HS_READ (1 << 2)
#define SPIDER_CONN_KIND_HS_WRITE (1 << 3)
#endif
#define SPIDER_SQL_KIND_SQL (1 << 0)
#define SPIDER_SQL_KIND_HANDLER (1 << 1)
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#define SPIDER_SQL_KIND_HS (1 << 2)
#endif
#define SPIDER_SQL_TYPE_SELECT_SQL (1 << 0)
#define SPIDER_SQL_TYPE_INSERT_SQL (1 << 1)
......@@ -689,70 +659,6 @@ class spider_fields
);
};
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#define SPIDER_HS_UINT32_INFO dena::uint32_info
#define SPIDER_HS_STRING_REF dena::string_ref
#ifndef HANDLERSOCKET_MYSQL_UTIL
#define SPIDER_HS_VECTOR std::vector
class spider_db_hs_string_ref_buffer
{
SPIDER_HS_VECTOR<SPIDER_HS_STRING_REF> hs_conds;
public:
spider_db_hs_string_ref_buffer();
~spider_db_hs_string_ref_buffer();
int init();
void clear();
int push_back(
SPIDER_HS_STRING_REF &cond
);
SPIDER_HS_STRING_REF *ptr();
uint size();
};
#else
class spider_db_hs_string_ref_buffer
{
bool hs_da_init;
DYNAMIC_ARRAY hs_conds;
uint hs_conds_id;
const char *hs_conds_func_name;
const char *hs_conds_file_name;
ulong hs_conds_line_no;
public:
spider_db_hs_string_ref_buffer();
~spider_db_hs_string_ref_buffer();
int init();
void clear();
int push_back(
SPIDER_HS_STRING_REF &cond
);
SPIDER_HS_STRING_REF *ptr();
uint size();
};
#endif
class spider_db_hs_str_buffer
{
bool hs_da_init;
DYNAMIC_ARRAY hs_conds;
uint hs_conds_id;
const char *hs_conds_func_name;
const char *hs_conds_file_name;
ulong hs_conds_line_no;
public:
spider_db_hs_str_buffer();
~spider_db_hs_str_buffer();
int init();
void clear();
spider_string *add(
uint *strs_pos,
const char *str,
uint str_len
);
};
#define SPIDER_DB_HS_STRING_REF_BUFFER spider_db_hs_string_ref_buffer
#define SPIDER_DB_HS_STR_BUFFER spider_db_hs_str_buffer
#endif
struct st_spider_db_request_key
{
......@@ -1155,54 +1061,6 @@ class spider_db_conn
SPIDER_DB_RESULT **res1,
SPIDER_DB_RESULT **res2
) = 0;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
virtual int append_sql(
char *sql,
ulong sql_length,
st_spider_db_request_key *request_key
) = 0;
virtual int append_open_handler(
uint handler_id,
const char *db_name,
const char *table_name,
const char *index_name,
const char *sql,
st_spider_db_request_key *request_key
) = 0;
virtual int append_select(
uint handler_id,
spider_string *sql,
SPIDER_DB_HS_STRING_REF_BUFFER *keys,
int limit,
int skip,
st_spider_db_request_key *request_key
) = 0;
virtual int append_insert(
uint handler_id,
SPIDER_DB_HS_STRING_REF_BUFFER *upds,
st_spider_db_request_key *request_key
) = 0;
virtual int append_update(
uint handler_id,
spider_string *sql,
SPIDER_DB_HS_STRING_REF_BUFFER *keys,
SPIDER_DB_HS_STRING_REF_BUFFER *upds,
int limit,
int skip,
bool increment,
bool decrement,
st_spider_db_request_key *request_key
) = 0;
virtual int append_delete(
uint handler_id,
spider_string *sql,
SPIDER_DB_HS_STRING_REF_BUFFER *keys,
int limit,
int skip,
st_spider_db_request_key *request_key
) = 0;
virtual void reset_request_queue() = 0;
#endif
virtual size_t escape_string(
char *to,
const char *from,
......@@ -1336,11 +1194,6 @@ class spider_db_handler
virtual int append_insert_part() = 0;
virtual int append_update_part() = 0;
virtual int append_delete_part() = 0;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
virtual int append_increment_update_set_part() = 0;
#endif
#endif
virtual int append_update_set_part() = 0;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
virtual int append_direct_update_set_part() = 0;
......@@ -1579,23 +1432,6 @@ class spider_db_handler
virtual int reset_sql(
ulong sql_type
) = 0;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
virtual int reset_keys(
ulong sql_type
) = 0;
virtual int reset_upds(
ulong sql_type
) = 0;
virtual int reset_strs(
ulong sql_type
) = 0;
virtual int reset_strs_pos(
ulong sql_type
) = 0;
virtual int push_back_upds(
SPIDER_HS_STRING_REF &info
) = 0;
#endif
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
virtual int set_sql_for_exec(
ulong sql_type,
......@@ -1958,18 +1794,7 @@ typedef struct st_spider_result_list
SPIDER_RESULT *current;
KEY *key_info;
int key_order;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
ulonglong hs_upd_rows;
SPIDER_DB_RESULT *hs_result;
SPIDER_DB_RESULT_BUFFER *hs_result_buf;
bool hs_has_result;
SPIDER_DB_CONN *hs_conn;
#endif
#ifdef HA_CAN_BULK_ACCESS
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
uchar *hs_r_bulk_open_index;
uchar *hs_w_bulk_open_index;
#endif
#endif
spider_string *sqls;
int ha_read_kind;
......
This diff is collapsed.
......@@ -560,54 +560,6 @@ class spider_db_mbase: public spider_db_conn
uint binlog_pos_length,
SPIDER_DB_RESULT **res
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int append_sql(
char *sql,
ulong sql_length,
st_spider_db_request_key *request_key
);
int append_open_handler(
uint handler_id,
const char *db_name,
const char *table_name,
const char *index_name,
const char *sql,
st_spider_db_request_key *request_key
);
int append_select(
uint handler_id,
spider_string *sql,
SPIDER_DB_HS_STRING_REF_BUFFER *keys,
int limit,
int skip,
st_spider_db_request_key *request_key
);
int append_insert(
uint handler_id,
SPIDER_DB_HS_STRING_REF_BUFFER *upds,
st_spider_db_request_key *request_key
);
int append_update(
uint handler_id,
spider_string *sql,
SPIDER_DB_HS_STRING_REF_BUFFER *keys,
SPIDER_DB_HS_STRING_REF_BUFFER *upds,
int limit,
int skip,
bool increment,
bool decrement,
st_spider_db_request_key *request_key
);
int append_delete(
uint handler_id,
spider_string *sql,
SPIDER_DB_HS_STRING_REF_BUFFER *keys,
int limit,
int skip,
st_spider_db_request_key *request_key
);
void reset_request_queue();
#endif
size_t escape_string(
char *to,
const char *from,
......@@ -798,9 +750,6 @@ class spider_mbase_handler: public spider_db_handler
spider_string *exec_ha_sql;
bool reading_from_bulk_tmp_table;
bool filled_up;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
SPIDER_DB_HS_STRING_REF_BUFFER hs_upds;
#endif
SPIDER_INT_HLD *union_table_name_pos_first;
SPIDER_INT_HLD *union_table_name_pos_current;
public:
......@@ -907,14 +856,6 @@ class spider_mbase_handler: public spider_db_handler
int append_delete(
spider_string *str
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
int append_increment_update_set_part();
int append_increment_update_set(
spider_string *str
);
#endif
#endif
int append_update_set_part();
int append_update_set(
spider_string *str
......@@ -1445,23 +1386,6 @@ class spider_mbase_handler: public spider_db_handler
int reset_sql(
ulong sql_type
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
int reset_keys(
ulong sql_type
);
int reset_upds(
ulong sql_type
);
int reset_strs(
ulong sql_type
);
int reset_strs_pos(
ulong sql_type
);
int push_back_upds(
SPIDER_HS_STRING_REF &info
);
#endif
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
int set_sql_for_exec(
ulong sql_type,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -73,12 +73,6 @@ int spider_param_reset_sql_alloc(
THD *thd,
int reset_sql_alloc
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
longlong spider_param_hs_result_free_size(
THD *thd,
longlong hs_result_free_size
);
#endif
int spider_param_multi_split_read(
THD *thd,
int multi_split_read
......@@ -261,11 +255,6 @@ int spider_param_sts_bg_mode(
double spider_param_ping_interval_at_trx_start(
THD *thd
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
double spider_param_hs_ping_interval(
THD *thd
);
#endif
int spider_param_auto_increment_mode(
THD *thd,
int auto_increment_mode
......@@ -320,28 +309,6 @@ int spider_param_udf_ct_bulk_insert_interval(
longlong spider_param_udf_ct_bulk_insert_rows(
longlong udf_ct_bulk_insert_rows
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
uint spider_param_hs_r_conn_recycle_mode(
THD *thd
);
uint spider_param_hs_r_conn_recycle_strict(
THD *thd
);
uint spider_param_hs_w_conn_recycle_mode(
THD *thd
);
uint spider_param_hs_w_conn_recycle_strict(
THD *thd
);
int spider_param_use_hs_read(
THD *thd,
int use_hs_read
);
int spider_param_use_hs_write(
THD *thd,
int use_hs_write
);
#endif
int spider_param_use_handler(
THD *thd,
int use_handler
......
This diff is collapsed.
......@@ -372,14 +372,6 @@ bool spider_check_pk_update(
TABLE *table
);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
bool spider_check_hs_pk_update(
ha_spider *spider,
key_range *key
);
#endif
#endif
void spider_set_tmp_share_pointer(
SPIDER_SHARE *tmp_share,
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment