remove c language api and upgrade cpp api
This commit is contained in:
parent
77cf6eb7e9
commit
464658236d
Binary file not shown.
@ -1 +0,0 @@
|
||||
librocksdb.so.6.6.0
|
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
include ../Make.conf
|
||||
|
||||
SUBDIRS := c_api c_api_cc
|
||||
SUBDIRS := c_api_cc
|
||||
|
||||
include ../Make.rules
|
||||
|
@ -1,39 +0,0 @@
|
||||
LIB_PATH = ../../../..
|
||||
|
||||
include ../../Make.conf
|
||||
|
||||
SVN_REVISION = $(shell test -d .svn && (svn info | grep "Last Changed Rev" | cut -d " " -f 4))
|
||||
ifeq "$(SVN_REVISION)a" "a"
|
||||
SVN_REVISION = "(unknown)"
|
||||
endif
|
||||
|
||||
VPATH = ../../common
|
||||
################compile#############
|
||||
target = libdtc.a container_api.pic.o version.pic.o somain.pic.o libdtc.so libdtc.pic.a
|
||||
|
||||
# CLIENTAPI macro use for scope test only
|
||||
CFLAGS += -DCLIENTAPI
|
||||
CFLAGS += -pthread -I../../common -I../../stat $(ZINC)
|
||||
LIBS = $(Z_LIB) -ldl -lpthread
|
||||
|
||||
|
||||
filelist := dtc_req dtc_srv dtc_pool dtc_wrap dtc_wrapp \
|
||||
poller timer_list key_list table_def \
|
||||
log_client mem_check md5 value \
|
||||
section decode encode field_api \
|
||||
packet_base packet_client \
|
||||
task_base task_const net_addr udp_pool compress buffer thread
|
||||
|
||||
# for auto ln -sf
|
||||
libdtc_objs := $(patsubst %,%.o,$(filelist))
|
||||
libdtc.so: LDFLAGS += -Wl,--version-script,dtc_api.lst -e _so_start container_api.pic.o version.pic.o somain.pic.o
|
||||
libdtc_filename := libdtc-gcc-$(GCCVER)-r$(SVN_REVISION).so
|
||||
|
||||
###############install##############
|
||||
target_install = libdtc.a libdtc.pic.a libdtc.so dtc_api.h
|
||||
install_dir = ../../../bin
|
||||
%.a: install_dir = ../../../lib
|
||||
%.h: install_dir = ../../../include
|
||||
|
||||
include ../../Make.rules
|
||||
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: container_api.cc
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "container.h"
|
||||
#include "version.h"
|
||||
#include "dtc_int.h"
|
||||
|
||||
typedef IInternalService *(*QueryInternalServiceFunctionType)(const char *name, const char *instance);
|
||||
|
||||
IInternalService *query_internal_service(const char *name, const char *instance)
|
||||
{
|
||||
QueryInternalServiceFunctionType entry = NULL;
|
||||
entry = (QueryInternalServiceFunctionType)dlsym(RTLD_DEFAULT, "_QueryInternalService");
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
return entry(name, instance);
|
||||
}
|
||||
|
||||
static inline int field_type_to_key_type(int t)
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
return DField::Signed;
|
||||
|
||||
case DField::String:
|
||||
case DField::Binary:
|
||||
return DField::String;
|
||||
}
|
||||
|
||||
return DField::None;
|
||||
}
|
||||
|
||||
void NCServer::check_internal_service(void)
|
||||
{
|
||||
if (NCResultInternal::verify_class() == 0)
|
||||
return;
|
||||
|
||||
IInternalService *inst = query_internal_service("dtcd", this->tablename);
|
||||
|
||||
// not inside dtcd or tablename not found
|
||||
if (inst == NULL)
|
||||
return;
|
||||
|
||||
// version mismatch, internal service is unusable
|
||||
const char *version = inst->query_version_string();
|
||||
if (version == NULL || strcasecmp(version_detail, version) != 0)
|
||||
return;
|
||||
|
||||
// cast to DTC service
|
||||
IDTCService *inst1 = static_cast<IDTCService *>(inst);
|
||||
|
||||
DTCTableDefinition *tdef = inst1->query_table_definition();
|
||||
|
||||
// verify tablename etc
|
||||
if (tdef->is_same_table(tablename) == 0)
|
||||
return;
|
||||
|
||||
// verify and save key type
|
||||
int kt = field_type_to_key_type(tdef->key_type());
|
||||
if (kt == DField::None)
|
||||
// bad key type
|
||||
return;
|
||||
|
||||
if (keytype == DField::None)
|
||||
{
|
||||
keytype = kt;
|
||||
}
|
||||
else if (keytype != kt)
|
||||
{
|
||||
badkey = 1;
|
||||
errstr = "Key Type Mismatch";
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyinfo.key_fields() != 0)
|
||||
{
|
||||
// FIXME: checking keyinfo
|
||||
|
||||
// ZAP key info, use ordered name from server
|
||||
keyinfo.Clear();
|
||||
}
|
||||
// add NCKeyInfo
|
||||
for (int i = 0; i < tdef->key_fields(); i++)
|
||||
{
|
||||
kt = field_type_to_key_type(tdef->field_type(i));
|
||||
if (kt == DField::None)
|
||||
// bad key type
|
||||
return;
|
||||
keyinfo.add_key(tdef->field_name(i), kt);
|
||||
}
|
||||
|
||||
// OK, save it.
|
||||
// old tdef always NULL, because tablename didn't set, Server didn't complete
|
||||
this->tdef = tdef;
|
||||
this->admin_tdef = inst1->query_admin_table_definition();
|
||||
// useless here, internal DTCTableDefinition don't maintent a usage count
|
||||
tdef->INC();
|
||||
this->iservice = inst1;
|
||||
this->completed = 1;
|
||||
if (get_address() && iservice->match_listening_ports(get_address(), NULL))
|
||||
{
|
||||
executor = iservice->query_task_executor();
|
||||
}
|
||||
}
|
@ -1,974 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: dtc_api.h
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#ifndef __DTC_API_H__
|
||||
#define __DTC_API_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace DistributedTableCache
|
||||
{
|
||||
class Server;
|
||||
class ServerPool;
|
||||
class Request;
|
||||
class Result;
|
||||
|
||||
const int RequestSvrAdmin = 3;
|
||||
const int RequestGet = 4;
|
||||
const int RequestPurge = 5;
|
||||
const int RequestInsert = 6;
|
||||
const int RequestUpdate = 7;
|
||||
const int RequestDelete = 8;
|
||||
const int RequestReplace = 12;
|
||||
const int RequestFlush = 13;
|
||||
const int RequestInvalidate = 14;
|
||||
|
||||
//mem monior Request;2014/06/6;by seanzheng
|
||||
const int RequestMonitor = 15;
|
||||
|
||||
// sub-code of admin cmd
|
||||
const int RegisterHB = 1;
|
||||
const int LogoutHB = 2;
|
||||
const int GetKeyList = 3;
|
||||
const int GetUpdateKey = 4;
|
||||
const int GetRawData = 5;
|
||||
const int ReplaceRawData = 6;
|
||||
const int AdjustLRU = 7;
|
||||
const int VerifyHBT = 8;
|
||||
const int GetHBTime = 9;
|
||||
const int SET_READONLY = 10;
|
||||
const int SET_READWRITE = 11;
|
||||
const int QueryBinlogID = 12;
|
||||
const int NodeHandleChange = 13;
|
||||
const int Migrate = 14;
|
||||
const int ReloadClusterNodeList = 15;
|
||||
const int SetClusterNodeState = 16;
|
||||
const int change_node_address = 17;
|
||||
const int GetClusterState = 18;
|
||||
const int PurgeForHit = 19;
|
||||
const int ClearCache = 21;
|
||||
const int MigrateDB = 22;
|
||||
const int MigrateDBSwitch = 23;
|
||||
const int ColExpandStatus = 24;
|
||||
const int col_expand = 25;
|
||||
const int ColExpandDone = 26;
|
||||
const int ColExpandKey = 27;
|
||||
|
||||
const int KeyTypeNone = 0; // undefined
|
||||
const int KeyTypeInt = 1; // Signed Integer
|
||||
const int KeyTypeString = 4; // String, case insensitive, null ended
|
||||
|
||||
const int FieldTypeNone = 0; // undefined
|
||||
const int FieldTypeSigned = 1; // Signed Integer
|
||||
const int FieldTypeUnsigned = 2; // Unsigned Integer
|
||||
const int FieldTypeFloat = 3; // float
|
||||
const int FieldTypeString = 4; // String, case insensitive, null ended
|
||||
const int FieldTypeBinary = 5; // binary
|
||||
|
||||
void init_log(const char *app, const char *dir = NULL);
|
||||
void set_log_level(int n);
|
||||
int set_key_value_max(unsigned int count); // 设置批量操作一次最多多少个key(默认最多32个)
|
||||
#ifndef WIN32
|
||||
void write_log(int level,
|
||||
const char *file, const char *func, int lineno,
|
||||
const char *fmt, ...)
|
||||
__attribute__((format(printf, 5, 6)));
|
||||
#endif
|
||||
|
||||
class Result;
|
||||
class Server
|
||||
{
|
||||
private:
|
||||
void *addr;
|
||||
long check;
|
||||
|
||||
public:
|
||||
friend class Request;
|
||||
friend class Result;
|
||||
friend class ServerPool;
|
||||
|
||||
Server(void);
|
||||
~Server(void);
|
||||
Server(const Server &);
|
||||
void clone_tab_def(const Server &source);
|
||||
int set_address(const char *host, const char *port = 0);
|
||||
int set_table_name(const char *);
|
||||
//for compress
|
||||
void set_compress_level(int);
|
||||
//get address and tablename set by user
|
||||
const char *get_address(void) const;
|
||||
const char *get_table_name(void) const;
|
||||
//get address and tablename set by dtc frame,for plugin only;
|
||||
const char *get_server_address(void) const;
|
||||
const char *get_server_table_name(void) const;
|
||||
int int_key(void);
|
||||
int binary_key(void);
|
||||
int string_key(void);
|
||||
int add_key(const char *name, int type);
|
||||
int field_type(const char *name);
|
||||
const char *error_message(void) const;
|
||||
void set_timeout(int);
|
||||
void set_m_timeout(int);
|
||||
int Connect(void);
|
||||
void Close(void);
|
||||
int ping(void);
|
||||
void auto_ping(void);
|
||||
void SetFD(int); // UNSUPPORTED API
|
||||
void set_auto_update_tab(bool autoUpdate);
|
||||
void set_auto_reconnect(int autoReconnect);
|
||||
int decode_packet(Result &, const char *, int);
|
||||
int check_packet_size(const char *, int);
|
||||
|
||||
void set_access_key(const char *token);
|
||||
};
|
||||
|
||||
class Request
|
||||
{
|
||||
private:
|
||||
void *addr;
|
||||
long check;
|
||||
Request(const Request &);
|
||||
|
||||
public:
|
||||
friend class Server;
|
||||
friend class Result;
|
||||
friend class ServerPool;
|
||||
|
||||
Request(Server *srv, int op);
|
||||
Request(void);
|
||||
~Request(void);
|
||||
void Reset(void);
|
||||
void Reset(int);
|
||||
int attach_server(Server *srv);
|
||||
|
||||
void set_admin_code(int code);
|
||||
void set_hot_backup_id(long long);
|
||||
void set_master_hb_timestamp(long long);
|
||||
void set_slave_hb_timestamp(long long);
|
||||
|
||||
#define _REDIR_(op, t) \
|
||||
int op(const char *n, t a) { return op(n, (long long)a); }
|
||||
#define _REDIRF_(op, t) \
|
||||
int op(const char *n, t a) { return op(n, (double)a); }
|
||||
int Need(const char *);
|
||||
int Need(const char *, int);
|
||||
int field_type(const char *);
|
||||
void no_cache(void);
|
||||
void no_next_server(void);
|
||||
void limit(unsigned int, unsigned int);
|
||||
int EQ(const char *, long long);
|
||||
int NE(const char *, long long);
|
||||
int LT(const char *, long long);
|
||||
int LE(const char *, long long);
|
||||
int GT(const char *, long long);
|
||||
int GE(const char *, long long);
|
||||
int EQ(const char *, const char *);
|
||||
int NE(const char *, const char *);
|
||||
int EQ(const char *, const char *, int);
|
||||
int NE(const char *, const char *, int);
|
||||
|
||||
_REDIR_(EQ, unsigned long long);
|
||||
_REDIR_(EQ, long);
|
||||
_REDIR_(EQ, unsigned long);
|
||||
_REDIR_(EQ, int);
|
||||
_REDIR_(EQ, unsigned int);
|
||||
_REDIR_(EQ, short);
|
||||
_REDIR_(EQ, unsigned short);
|
||||
_REDIR_(EQ, char);
|
||||
_REDIR_(EQ, unsigned char);
|
||||
|
||||
_REDIR_(NE, unsigned long long);
|
||||
_REDIR_(NE, long);
|
||||
_REDIR_(NE, unsigned long);
|
||||
_REDIR_(NE, int);
|
||||
_REDIR_(NE, unsigned int);
|
||||
_REDIR_(NE, short);
|
||||
_REDIR_(NE, unsigned short);
|
||||
_REDIR_(NE, char);
|
||||
_REDIR_(NE, unsigned char);
|
||||
|
||||
_REDIR_(GT, unsigned long long);
|
||||
_REDIR_(GT, long);
|
||||
_REDIR_(GT, unsigned long);
|
||||
_REDIR_(GT, int);
|
||||
_REDIR_(GT, unsigned int);
|
||||
_REDIR_(GT, short);
|
||||
_REDIR_(GT, unsigned short);
|
||||
_REDIR_(GT, char);
|
||||
_REDIR_(GT, unsigned char);
|
||||
|
||||
_REDIR_(GE, unsigned long long);
|
||||
_REDIR_(GE, long);
|
||||
_REDIR_(GE, unsigned long);
|
||||
_REDIR_(GE, int);
|
||||
_REDIR_(GE, unsigned int);
|
||||
_REDIR_(GE, short);
|
||||
_REDIR_(GE, unsigned short);
|
||||
_REDIR_(GE, char);
|
||||
_REDIR_(GE, unsigned char);
|
||||
|
||||
_REDIR_(LT, unsigned long long);
|
||||
_REDIR_(LT, long);
|
||||
_REDIR_(LT, unsigned long);
|
||||
_REDIR_(LT, int);
|
||||
_REDIR_(LT, unsigned int);
|
||||
_REDIR_(LT, short);
|
||||
_REDIR_(LT, unsigned short);
|
||||
_REDIR_(LT, char);
|
||||
_REDIR_(LT, unsigned char);
|
||||
|
||||
_REDIR_(LE, unsigned long long);
|
||||
_REDIR_(LE, long);
|
||||
_REDIR_(LE, unsigned long);
|
||||
_REDIR_(LE, int);
|
||||
_REDIR_(LE, unsigned int);
|
||||
_REDIR_(LE, short);
|
||||
_REDIR_(LE, unsigned short);
|
||||
_REDIR_(LE, char);
|
||||
_REDIR_(LE, unsigned char);
|
||||
|
||||
int Set(const char *, long long);
|
||||
int OR(const char *, long long);
|
||||
int Add(const char *, long long);
|
||||
int Sub(const char *, long long);
|
||||
int Set(const char *, double);
|
||||
int Add(const char *, double);
|
||||
int Sub(const char *, double);
|
||||
int Set(const char *, const char *);
|
||||
int Set(const char *, const char *, int);
|
||||
|
||||
//just for compress,only support binary field
|
||||
int compress_set(const char *, const char *, int);
|
||||
//just compress and set. Don't need compressflag
|
||||
int compress_set_force(const char *, const char *, int);
|
||||
|
||||
//bits op
|
||||
int set_multi_bits(const char *, int, int, unsigned int);
|
||||
int set_bit(const char *f, int o) { return set_multi_bits(f, o, 1, 1); }
|
||||
int clear_bit(const char *f, int o) { return set_multi_bits(f, o, 1, 0); }
|
||||
|
||||
_REDIR_(Set, unsigned long long);
|
||||
_REDIR_(Set, long);
|
||||
_REDIR_(Set, unsigned long);
|
||||
_REDIR_(Set, int);
|
||||
_REDIR_(Set, unsigned int);
|
||||
_REDIR_(Set, short);
|
||||
_REDIR_(Set, unsigned short);
|
||||
_REDIR_(Set, char);
|
||||
_REDIR_(Set, unsigned char);
|
||||
_REDIRF_(Set, float);
|
||||
_REDIRF_(Set, long double);
|
||||
|
||||
_REDIR_(OR, unsigned long long);
|
||||
_REDIR_(OR, long);
|
||||
_REDIR_(OR, unsigned long);
|
||||
_REDIR_(OR, int);
|
||||
_REDIR_(OR, unsigned int);
|
||||
_REDIR_(OR, short);
|
||||
_REDIR_(OR, unsigned short);
|
||||
|
||||
_REDIR_(Add, unsigned long long);
|
||||
_REDIR_(Add, long);
|
||||
_REDIR_(Add, unsigned long);
|
||||
_REDIR_(Add, int);
|
||||
_REDIR_(Add, unsigned int);
|
||||
_REDIR_(Add, short);
|
||||
_REDIR_(Add, unsigned short);
|
||||
_REDIR_(Add, char);
|
||||
_REDIR_(Add, unsigned char);
|
||||
_REDIRF_(Add, float);
|
||||
_REDIRF_(Add, long double);
|
||||
|
||||
_REDIR_(Sub, unsigned long long);
|
||||
_REDIR_(Sub, long);
|
||||
_REDIR_(Sub, unsigned long);
|
||||
_REDIR_(Sub, int);
|
||||
_REDIR_(Sub, unsigned int);
|
||||
_REDIR_(Sub, short);
|
||||
_REDIR_(Sub, unsigned short);
|
||||
_REDIR_(Sub, char);
|
||||
_REDIR_(Sub, unsigned char);
|
||||
_REDIRF_(Sub, float);
|
||||
_REDIRF_(Sub, long double);
|
||||
#undef _REDIR_
|
||||
|
||||
void unset_key(void);
|
||||
int set_key(long long);
|
||||
int set_key(const char *);
|
||||
int set_key(const char *, int);
|
||||
#define _REDIR_(t) \
|
||||
int set_key(t a) { return set_key((long long)a); }
|
||||
_REDIR_(unsigned long long);
|
||||
_REDIR_(long);
|
||||
_REDIR_(unsigned long);
|
||||
_REDIR_(int);
|
||||
_REDIR_(unsigned int);
|
||||
_REDIR_(short);
|
||||
_REDIR_(unsigned short);
|
||||
_REDIR_(char);
|
||||
_REDIR_(unsigned char);
|
||||
#undef _REDIR_
|
||||
|
||||
int add_key_value(const char *name, long long v);
|
||||
int add_key_value(const char *name, const char *str);
|
||||
int add_key_value(const char *name, const char *ptr, int len);
|
||||
#define _REDIR_(t) \
|
||||
int add_key_value(const char *name, t a) { return add_key_value(name, (long long)a); }
|
||||
_REDIR_(unsigned long long);
|
||||
_REDIR_(long);
|
||||
_REDIR_(unsigned long);
|
||||
_REDIR_(int);
|
||||
_REDIR_(unsigned int);
|
||||
_REDIR_(short);
|
||||
_REDIR_(unsigned short);
|
||||
_REDIR_(char);
|
||||
_REDIR_(unsigned char);
|
||||
#undef _REDIR_
|
||||
|
||||
Result *execute(void);
|
||||
Result *execute(long long);
|
||||
Result *execute(const char *);
|
||||
Result *execute(const char *, int);
|
||||
|
||||
#define _REDIR_(t) \
|
||||
Result *execute(t a) { return execute((long long)a); }
|
||||
_REDIR_(unsigned long long);
|
||||
_REDIR_(long);
|
||||
_REDIR_(unsigned long);
|
||||
_REDIR_(int);
|
||||
_REDIR_(unsigned int);
|
||||
_REDIR_(short);
|
||||
_REDIR_(unsigned short);
|
||||
_REDIR_(char);
|
||||
_REDIR_(unsigned char);
|
||||
#undef _REDIR_
|
||||
|
||||
int execute(Result &);
|
||||
int execute(Result &, long long);
|
||||
int execute(Result &, const char *);
|
||||
int execute(Result &, const char *, int);
|
||||
|
||||
#define _REDIR_(t) \
|
||||
int execute(Result &r, t a) { return execute(r, (long long)a); }
|
||||
_REDIR_(unsigned long long);
|
||||
_REDIR_(long);
|
||||
_REDIR_(unsigned long);
|
||||
_REDIR_(int);
|
||||
_REDIR_(unsigned int);
|
||||
_REDIR_(short);
|
||||
_REDIR_(unsigned short);
|
||||
_REDIR_(char);
|
||||
_REDIR_(unsigned char);
|
||||
#undef _REDIR_
|
||||
|
||||
int encode_packet(char *&, int &, long long &);
|
||||
int encode_packet(char *&, int &, long long &, long long);
|
||||
int encode_packet(char *&, int &, long long &, const char *);
|
||||
int encode_packet(char *&, int &, long long &, const char *, int);
|
||||
|
||||
#define _REDIR_(t) \
|
||||
int encode_packet(char *&p, int &l, long long &m, t a) { return encode_packet(p, l, m, (long long)a); }
|
||||
_REDIR_(unsigned long long);
|
||||
_REDIR_(long);
|
||||
_REDIR_(unsigned long);
|
||||
_REDIR_(int);
|
||||
_REDIR_(unsigned int);
|
||||
_REDIR_(short);
|
||||
_REDIR_(unsigned short);
|
||||
_REDIR_(char);
|
||||
_REDIR_(unsigned char);
|
||||
#undef _REDIR_
|
||||
|
||||
int set_cache_id(long long);
|
||||
#define _REDIR_(t) \
|
||||
int set_cache_id(t a) { return set_cache_id((long long)a); }
|
||||
_REDIR_(unsigned long long);
|
||||
_REDIR_(long);
|
||||
_REDIR_(unsigned long);
|
||||
_REDIR_(int);
|
||||
_REDIR_(unsigned int);
|
||||
_REDIR_(short);
|
||||
_REDIR_(unsigned short);
|
||||
_REDIR_(char);
|
||||
_REDIR_(unsigned char);
|
||||
#undef _REDIR_
|
||||
const char *error_message(void) const;
|
||||
|
||||
//无源模式超时时间
|
||||
int set_expire_time(const char *key, int time);
|
||||
int get_expire_time(const char *key);
|
||||
};
|
||||
|
||||
class GetRequest : public Request
|
||||
{
|
||||
public:
|
||||
GetRequest(Server *srv) : Request(srv, RequestGet) {}
|
||||
GetRequest() : Request((Server *)0, RequestGet) {}
|
||||
};
|
||||
|
||||
class InsertRequest : public Request
|
||||
{
|
||||
public:
|
||||
InsertRequest(Server *srv) : Request(srv, RequestInsert) {}
|
||||
InsertRequest() : Request((Server *)0, RequestInsert) {}
|
||||
};
|
||||
|
||||
class DeleteRequest : public Request
|
||||
{
|
||||
public:
|
||||
DeleteRequest(Server *srv) : Request(srv, RequestDelete) {}
|
||||
DeleteRequest() : Request((Server *)0, RequestDelete) {}
|
||||
};
|
||||
|
||||
class UpdateRequest : public Request
|
||||
{
|
||||
public:
|
||||
UpdateRequest(Server *srv) : Request(srv, RequestUpdate) {}
|
||||
UpdateRequest() : Request((Server *)0, RequestUpdate) {}
|
||||
};
|
||||
|
||||
class PurgeRequest : public Request
|
||||
{
|
||||
public:
|
||||
PurgeRequest(Server *srv) : Request(srv, RequestPurge) {}
|
||||
PurgeRequest() : Request((Server *)0, RequestPurge) {}
|
||||
};
|
||||
|
||||
class ReplaceRequest : public Request
|
||||
{
|
||||
public:
|
||||
ReplaceRequest(Server *srv) : Request(srv, RequestReplace) {}
|
||||
ReplaceRequest() : Request((Server *)0, RequestReplace) {}
|
||||
};
|
||||
|
||||
class FlushRequest : public Request
|
||||
{
|
||||
public:
|
||||
FlushRequest(Server *srv) : Request(srv, RequestFlush) {}
|
||||
FlushRequest(void) : Request((Server *)0, RequestFlush) {}
|
||||
};
|
||||
|
||||
class InvalidateRequest : public Request
|
||||
{
|
||||
public:
|
||||
InvalidateRequest(Server *srv) : Request(srv, RequestInvalidate) {}
|
||||
};
|
||||
|
||||
class SvrAdminRequest : public Request
|
||||
{
|
||||
public:
|
||||
SvrAdminRequest(Server *srv) : Request(srv, RequestSvrAdmin) {}
|
||||
};
|
||||
|
||||
class MonitorRequest : public Request
|
||||
{
|
||||
public:
|
||||
MonitorRequest(Server *srv) : Request(srv, RequestMonitor) {}
|
||||
};
|
||||
|
||||
class Result
|
||||
{
|
||||
private:
|
||||
void *addr;
|
||||
long check;
|
||||
Result(const Result &);
|
||||
char *server_info() const;
|
||||
|
||||
public:
|
||||
friend class Server;
|
||||
friend class Request;
|
||||
friend class ServerPool;
|
||||
|
||||
Result(void);
|
||||
~Result(void);
|
||||
void Reset(void);
|
||||
|
||||
void set_error(int errcode, const char *from, const char *detail); // from will not dupped
|
||||
int result_code(void) const;
|
||||
const char *error_message(void) const;
|
||||
const char *error_from(void) const;
|
||||
long long hot_backup_id() const;
|
||||
long long master_hb_timestamp() const;
|
||||
long long slave_hb_timestamp() const;
|
||||
long long binlog_id() const;
|
||||
long long binlog_offset() const;
|
||||
long long mem_size() const;
|
||||
long long data_size() const;
|
||||
int num_rows(void) const;
|
||||
int total_rows(void) const;
|
||||
int affected_rows(void) const;
|
||||
int num_fields(void) const;
|
||||
const char *field_name(int n) const;
|
||||
int field_present(const char *name) const;
|
||||
int field_type(int n) const;
|
||||
long long Tag(void) const;
|
||||
void *TagPtr(void) const;
|
||||
long long Magic(void) const;
|
||||
long long server_timestamp(void) const;
|
||||
long long insert_id(void) const;
|
||||
long long int_key(void) const;
|
||||
const char *binary_key(void) const;
|
||||
const char *binary_key(int *) const;
|
||||
const char *binary_key(int &) const;
|
||||
const char *string_key(void) const;
|
||||
const char *string_key(int *) const;
|
||||
const char *string_key(int &) const;
|
||||
long long int_value(const char *) const;
|
||||
double float_value(const char *) const;
|
||||
const char *string_value(const char *) const;
|
||||
const char *string_value(const char *, int *) const;
|
||||
const char *string_value(const char *, int &) const;
|
||||
const char *binary_value(const char *) const;
|
||||
const char *binary_value(const char *, int *) const;
|
||||
const char *binary_value(const char *, int &) const;
|
||||
int uncompress_binary_value(const char *name, char **buf, int *lenp);
|
||||
//Uncompress Binary Value without check compressflag
|
||||
int uncompress_binary_value_force(const char *name, char **buf, int *lenp);
|
||||
const char *uncompress_error_message() const;
|
||||
long long int_value(int) const;
|
||||
double float_value(int) const;
|
||||
const char *string_value(int) const;
|
||||
const char *string_value(int, int *) const;
|
||||
const char *string_value(int, int &) const;
|
||||
const char *binary_value(int) const;
|
||||
const char *binary_value(int, int *) const;
|
||||
const char *binary_value(int, int &) const;
|
||||
int fetch_row(void);
|
||||
int rewind(void);
|
||||
};
|
||||
|
||||
class ServerPool
|
||||
{
|
||||
private:
|
||||
void *addr;
|
||||
long check;
|
||||
ServerPool(ServerPool &);
|
||||
|
||||
public:
|
||||
friend class Server;
|
||||
friend class Request;
|
||||
friend class Result;
|
||||
|
||||
ServerPool(int maxServers, int maxRequests);
|
||||
~ServerPool(void);
|
||||
|
||||
int get_epoll_fd(int size);
|
||||
int add_server(Server *srv, int mReq = 1, int mConn = 0);
|
||||
int add_request(Request *, long long);
|
||||
int add_request(Request *, long long, long long);
|
||||
int add_request(Request *, long long, const char *);
|
||||
int add_request(Request *, long long, const char *, int);
|
||||
int add_request(Request *, void *);
|
||||
int add_request(Request *, void *, long long);
|
||||
int add_request(Request *, void *, const char *);
|
||||
int add_request(Request *, void *, const char *, int);
|
||||
int execute(int msec);
|
||||
int execute_all(int msec);
|
||||
int cancel_request(int);
|
||||
int cancel_all_request(int type);
|
||||
int abort_request(int);
|
||||
int abort_all_request(int type);
|
||||
Result *get_result(void);
|
||||
Result *get_result(int);
|
||||
int get_result(Result &);
|
||||
int get_result(Result &, int);
|
||||
|
||||
int server_count(void) const;
|
||||
int request_count(int type) const;
|
||||
int request_state(int reqId) const;
|
||||
};
|
||||
|
||||
const int WAIT = 1;
|
||||
const int SEND = 2;
|
||||
const int RECV = 4;
|
||||
const int DONE = 8;
|
||||
const int ALL_STATE = WAIT | SEND | RECV | DONE;
|
||||
|
||||
enum
|
||||
{
|
||||
EC_ERROR_BASE = 2000,
|
||||
EC_BAD_COMMAND, // unsupported command
|
||||
EC_MISSING_SECTION, // missing mandatory section
|
||||
EC_EXTRA_SECTION, // incompatible section present
|
||||
EC_DUPLICATE_TAG, // same tag appear twice
|
||||
|
||||
EC_DUPLICATE_FIELD, //5: same field appear twice in .Need()
|
||||
EC_BAD_SECTION_LENGTH, // section length too short
|
||||
EC_BAD_VALUE_LENGTH, // value length not allow
|
||||
EC_BAD_STRING_VALUE, // string value w/o NULL
|
||||
EC_BAD_FLOAT_VALUE, // invalid float format
|
||||
|
||||
EC_BAD_FIELD_NUM, //10: invalid total field#
|
||||
EC_EXTRA_SECTION_DATA, // section length too large
|
||||
EC_BAD_VALUE_TYPE, // incompatible value type
|
||||
EC_BAD_OPERATOR, // incompatible operator/comparison
|
||||
EC_BAD_FIELD_ID, // invalid field ID
|
||||
|
||||
EC_BAD_FIELD_NAME, //15: invalud field name
|
||||
EC_BAD_FIELD_TYPE, // invalid field type
|
||||
EC_BAD_FIELD_SIZE, // invalid field size
|
||||
EC_TABLE_REDEFINED, // table defined twice
|
||||
EC_TABLE_MISMATCH, // request table != server table
|
||||
|
||||
EC_VERSION_MISMATCH, //20: unsupported protocol version
|
||||
EC_CHECKSUM_MISMATCH, // table hash not equal
|
||||
EC_NO_MORE_DATA, // End of Result
|
||||
EC_NEED_FULL_FIELDSET, // only full field set accepted by helper
|
||||
EC_BAD_KEY_TYPE, // key type incompatible
|
||||
|
||||
EC_BAD_KEY_SIZE, // 25: key size incompatible
|
||||
EC_SERVER_BUSY, //server error
|
||||
EC_BAD_SOCKET, // network failed
|
||||
EC_NOT_INITIALIZED, // object didn't initialized
|
||||
EC_BAD_HOST_STRING,
|
||||
|
||||
EC_BAD_TABLE_NAME, // 30
|
||||
EC_TASK_NEED_DELETE,
|
||||
EC_KEY_NEEDED,
|
||||
EC_SERVER_ERROR,
|
||||
EC_UPSTREAM_ERROR,
|
||||
|
||||
EC_KEY_OVERFLOW, // 35
|
||||
EC_BAD_MULTIKEY,
|
||||
EC_READONLY_FIELD,
|
||||
EC_BAD_ASYNC_CMD,
|
||||
EC_OUT_OF_KEY_RANGE,
|
||||
|
||||
EC_REQUEST_ABORTED, // 40
|
||||
EC_PARALLEL_MODE,
|
||||
EC_KEY_NOTEXIST,
|
||||
EC_SERVER_READONLY,
|
||||
EC_BAD_INVALID_FIELD,
|
||||
|
||||
EC_DUPLICATE_KEY, // 45
|
||||
EC_TOO_MANY_KEY_VALUE,
|
||||
EC_BAD_KEY_NAME,
|
||||
EC_BAD_RAW_DATA,
|
||||
EC_BAD_HOTBACKUP_JID,
|
||||
|
||||
EC_FULL_SYNC_COMPLETE, //50
|
||||
EC_FULL_SYNC_STAGE,
|
||||
EC_INC_SYNC_STAGE,
|
||||
EC_ERR_SYNC_STAGE,
|
||||
EC_NOT_ALLOWED_INSERT,
|
||||
|
||||
EC_COMPRESS_ERROR, //55
|
||||
EC_UNCOMPRESS_ERROR,
|
||||
EC_TASKPOOL,
|
||||
EC_STATE_ERROR,
|
||||
EC_DATA_NEEDED,
|
||||
|
||||
EC_TASK_TIMEOUT,
|
||||
|
||||
EC_BUSINESS_WITHOUT_EXPIRETIME, //62
|
||||
EC_EMPTY_TBDEF, //63
|
||||
EC_INVALID_KEY_VALUE, //64
|
||||
EC_INVALID_EXPIRETIME, //65
|
||||
|
||||
EC_GET_EXPIRETIME_END_OF_RESULT, //66
|
||||
|
||||
EC_ERR_MIGRATEDB_ILLEGAL,
|
||||
EC_ERR_MIGRATEDB_DUPLICATE,
|
||||
EC_ERR_MIGRATEDB_HELPER,
|
||||
|
||||
EC_ERR_MIGRATEDB_MIGRATING, // 70
|
||||
EC_ERR_MIGRATEDB_NOT_START,
|
||||
EC_ERR_MIGRATEDB_DISTINCT,
|
||||
EC_ERR_COL_EXPANDING,
|
||||
EC_ERR_COL_EXPAND_DUPLICATE,
|
||||
|
||||
EC_ERR_COL_EXPAND_DONE_DUPLICATE, // 75
|
||||
EC_ERR_COL_EXPAND_DONE_DISTINCT,
|
||||
EC_ERR_COL_EXPAND_NO_MEM,
|
||||
EC_ERR_COL_EXPAND_COLD,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ER_HASHCHK = 1000,
|
||||
ER_NISAMCHK = 1001,
|
||||
ER_NO = 1002,
|
||||
ER_YES = 1003,
|
||||
ER_CANT_CREATE_FILE = 1004,
|
||||
ER_CANT_CREATE_TABLE = 1005,
|
||||
ER_CANT_CREATE_DB = 1006,
|
||||
ER_DB_CREATE_EXISTS = 1007,
|
||||
ER_DB_DROP_EXISTS = 1008,
|
||||
ER_DB_DROP_DELETE = 1009,
|
||||
ER_DB_DROP_RMDIR = 1010,
|
||||
ER_CANT_DELETE_FILE = 1011,
|
||||
ER_CANT_FIND_SYSTEM_REC = 1012,
|
||||
ER_CANT_GET_STAT = 1013,
|
||||
ER_CANT_GET_WD = 1014,
|
||||
ER_CANT_LOCK = 1015,
|
||||
ER_CANT_OPEN_FILE = 1016,
|
||||
ER_FILE_NOT_FOUND = 1017,
|
||||
ER_CANT_READ_DIR = 1018,
|
||||
ER_CANT_SET_WD = 1019,
|
||||
ER_CHECKREAD = 1020,
|
||||
ER_DISK_FULL = 1021,
|
||||
ER_DUP_KEY = 1022,
|
||||
ER_ERROR_ON_CLOSE = 1023,
|
||||
ER_ERROR_ON_READ = 1024,
|
||||
ER_ERROR_ON_RENAME = 1025,
|
||||
ER_ERROR_ON_WRITE = 1026,
|
||||
ER_FILE_USED = 1027,
|
||||
ER_FILSORT_ABORT = 1028,
|
||||
ER_FORM_NOT_FOUND = 1029,
|
||||
ER_GET_ERRNO = 1030,
|
||||
ER_ILLEGAL_HA = 1031,
|
||||
ER_KEY_NOT_FOUND = 1032,
|
||||
ER_NOT_FORM_FILE = 1033,
|
||||
ER_NOT_KEYFILE = 1034,
|
||||
ER_OLD_KEYFILE = 1035,
|
||||
ER_OPEN_AS_READONLY = 1036,
|
||||
ER_OUTOFMEMORY = 1037,
|
||||
ER_OUT_OF_SORTMEMORY = 1038,
|
||||
ER_UNEXPECTED_EOF = 1039,
|
||||
ER_CON_COUNT_ERROR = 1040,
|
||||
ER_OUT_OF_RESOURCES = 1041,
|
||||
ER_BAD_HOST_ERROR = 1042,
|
||||
ER_HANDSHAKE_ERROR = 1043,
|
||||
ER_DBACCESS_DENIED_ERROR = 1044,
|
||||
ER_ACCESS_DENIED_ERROR = 1045,
|
||||
ER_NO_DB_ERROR = 1046,
|
||||
ER_UNKNOWN_COM_ERROR = 1047,
|
||||
ER_BAD_NULL_ERROR = 1048,
|
||||
ER_BAD_DB_ERROR = 1049,
|
||||
ER_TABLE_EXISTS_ERROR = 1050,
|
||||
ER_BAD_TABLE_ERROR = 1051,
|
||||
ER_NON_UNIQ_ERROR = 1052,
|
||||
ER_SERVER_SHUTDOWN = 1053,
|
||||
ER_BAD_FIELD_ERROR = 1054,
|
||||
ER_WRONG_FIELD_WITH_GROUP = 1055,
|
||||
ER_WRONG_GROUP_FIELD = 1056,
|
||||
ER_WRONG_SUM_SELECT = 1057,
|
||||
ER_WRONG_VALUE_COUNT = 1058,
|
||||
ER_TOO_LONG_IDENT = 1059,
|
||||
ER_DUP_FIELDNAME = 1060,
|
||||
ER_DUP_KEYNAME = 1061,
|
||||
ER_DUP_ENTRY = 1062,
|
||||
ER_WRONG_FIELD_SPEC = 1063,
|
||||
ER_PARSE_ERROR = 1064,
|
||||
ER_EMPTY_QUERY = 1065,
|
||||
ER_NONUNIQ_TABLE = 1066,
|
||||
ER_INVALID_DEFAULT = 1067,
|
||||
ER_MULTIPLE_PRI_KEY = 1068,
|
||||
ER_TOO_MANY_KEYS = 1069,
|
||||
ER_TOO_MANY_KEY_PARTS = 1070,
|
||||
ER_TOO_LONG_KEY = 1071,
|
||||
ER_KEY_COLUMN_DOES_NOT_EXITS = 1072,
|
||||
ER_BLOB_USED_AS_KEY = 1073,
|
||||
ER_TOO_BIG_FIELDLENGTH = 1074,
|
||||
ER_WRONG_AUTO_KEY = 1075,
|
||||
ER_READY = 1076,
|
||||
ER_NORMAL_SHUTDOWN = 1077,
|
||||
ER_GOT_SIGNAL = 1078,
|
||||
ER_SHUTDOWN_COMPLETE = 1079,
|
||||
ER_FORCING_CLOSE = 1080,
|
||||
ER_IPSOCK_ERROR = 1081,
|
||||
ER_NO_SUCH_INDEX = 1082,
|
||||
ER_WRONG_FIELD_TERMINATORS = 1083,
|
||||
ER_BLOBS_AND_NO_TERMINATED = 1084,
|
||||
ER_TEXTFILE_NOT_READABLE = 1085,
|
||||
ER_FILE_EXISTS_ERROR = 1086,
|
||||
ER_LOAD_INFO = 1087,
|
||||
ER_ALTER_INFO = 1088,
|
||||
ER_WRONG_SUB_KEY = 1089,
|
||||
ER_CANT_REMOVE_ALL_FIELDS = 1090,
|
||||
ER_CANT_DROP_FIELD_OR_KEY = 1091,
|
||||
ER_INSERT_INFO = 1092,
|
||||
ER_INSERT_TABLE_USED = 1093,
|
||||
ER_NO_SUCH_THREAD = 1094,
|
||||
ER_KILL_DENIED_ERROR = 1095,
|
||||
ER_NO_TABLES_USED = 1096,
|
||||
ER_TOO_BIG_SET = 1097,
|
||||
ER_NO_UNIQUE_LOGFILE = 1098,
|
||||
ER_TABLE_NOT_LOCKED_FOR_WRITE = 1099,
|
||||
ER_TABLE_NOT_LOCKED = 1100,
|
||||
ER_BLOB_CANT_HAVE_DEFAULT = 1101,
|
||||
ER_WRONG_DB_NAME = 1102,
|
||||
ER_WRONG_TABLE_NAME = 1103,
|
||||
ER_TOO_BIG_SELECT = 1104,
|
||||
ER_UNKNOWN_ERROR = 1105,
|
||||
ER_UNKNOWN_PROCEDURE = 1106,
|
||||
ER_WRONG_PARAMCOUNT_TO_PROCEDURE = 1107,
|
||||
ER_WRONG_PARAMETERS_TO_PROCEDURE = 1108,
|
||||
ER_UNKNOWN_TABLE = 1109,
|
||||
ER_FIELD_SPECIFIED_TWICE = 1110,
|
||||
ER_INVALID_GROUP_FUNC_USE = 1111,
|
||||
ER_UNSUPPORTED_EXTENSION = 1112,
|
||||
ER_TABLE_MUST_HAVE_COLUMNS = 1113,
|
||||
ER_RECORD_FILE_FULL = 1114,
|
||||
ER_UNKNOWN_CHARACTER_SET = 1115,
|
||||
ER_TOO_MANY_TABLES = 1116,
|
||||
ER_TOO_MANY_FIELDS = 1117,
|
||||
ER_TOO_BIG_ROWSIZE = 1118,
|
||||
ER_STACK_OVERRUN = 1119,
|
||||
ER_WRONG_OUTER_JOIN = 1120,
|
||||
ER_NULL_COLUMN_IN_INDEX = 1121,
|
||||
ER_CANT_FIND_UDF = 1122,
|
||||
ER_CANT_INITIALIZE_UDF = 1123,
|
||||
ER_UDF_NO_PATHS = 1124,
|
||||
ER_UDF_EXISTS = 1125,
|
||||
ER_CANT_OPEN_LIBRARY = 1126,
|
||||
ER_CANT_FIND_DL_ENTRY = 1127,
|
||||
ER_FUNCTION_NOT_DEFINED = 1128,
|
||||
ER_HOST_IS_BLOCKED = 1129,
|
||||
ER_HOST_NOT_PRIVILEGED = 1130,
|
||||
ER_PASSWORD_ANONYMOUS_USER = 1131,
|
||||
ER_PASSWORD_NOT_ALLOWED = 1132,
|
||||
ER_PASSWORD_NO_MATCH = 1133,
|
||||
ER_UPDATE_INFO = 1134,
|
||||
ER_CANT_CREATE_THREAD = 1135,
|
||||
ER_WRONG_VALUE_COUNT_ON_ROW = 1136,
|
||||
ER_CANT_REOPEN_TABLE = 1137,
|
||||
ER_INVALID_USE_OF_NULL = 1138,
|
||||
ER_REGEXP_ERROR = 1139,
|
||||
ER_MIX_OF_GROUP_FUNC_AND_FIELDS = 1140,
|
||||
ER_NONEXISTING_GRANT = 1141,
|
||||
ER_TABLEACCESS_DENIED_ERROR = 1142,
|
||||
ER_COLUMNACCESS_DENIED_ERROR = 1143,
|
||||
ER_ILLEGAL_GRANT_FOR_TABLE = 1144,
|
||||
ER_GRANT_WRONG_HOST_OR_USER = 1145,
|
||||
ER_NO_SUCH_TABLE = 1146,
|
||||
ER_NONEXISTING_TABLE_GRANT = 1147,
|
||||
ER_NOT_ALLOWED_COMMAND = 1148,
|
||||
ER_SYNTAX_ERROR = 1149,
|
||||
ER_DELAYED_CANT_CHANGE_LOCK = 1150,
|
||||
ER_TOO_MANY_DELAYED_THREADS = 1151,
|
||||
ER_ABORTING_CONNECTION = 1152,
|
||||
ER_NET_PACKET_TOO_LARGE = 1153,
|
||||
ER_NET_READ_ERROR_FROM_PIPE = 1154,
|
||||
ER_NET_FCNTL_ERROR = 1155,
|
||||
ER_NET_PACKETS_OUT_OF_ORDER = 1156,
|
||||
ER_NET_UNCOMPRESS_ERROR = 1157,
|
||||
ER_NET_READ_ERROR = 1158,
|
||||
ER_NET_READ_INTERRUPTED = 1159,
|
||||
ER_NET_ERROR_ON_WRITE = 1160,
|
||||
ER_NET_WRITE_INTERRUPTED = 1161,
|
||||
ER_TOO_LONG_STRING = 1162,
|
||||
ER_TABLE_CANT_HANDLE_BLOB = 1163,
|
||||
ER_TABLE_CANT_HANDLE_AUTO_INCREMENT = 1164,
|
||||
ER_DELAYED_INSERT_TABLE_LOCKED = 1165,
|
||||
ER_WRONG_COLUMN_NAME = 1166,
|
||||
ER_WRONG_KEY_COLUMN = 1167,
|
||||
ER_WRONG_MRG_TABLE = 1168,
|
||||
ER_DUP_UNIQUE = 1169,
|
||||
ER_BLOB_KEY_WITHOUT_LENGTH = 1170,
|
||||
ER_PRIMARY_CANT_HAVE_NULL = 1171,
|
||||
ER_TOO_MANY_ROWS = 1172,
|
||||
ER_REQUIRES_PRIMARY_KEY = 1173,
|
||||
ER_NO_RAID_COMPILED = 1174,
|
||||
ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE = 1175,
|
||||
ER_KEY_DOES_NOT_EXITS = 1176,
|
||||
ER_CHECK_NO_SUCH_TABLE = 1177,
|
||||
ER_CHECK_NOT_IMPLEMENTED = 1178,
|
||||
ER_CANT_DO_THIS_DURING_AN_TRANSACTION = 1179,
|
||||
ER_ERROR_DURING_COMMIT = 1180,
|
||||
ER_ERROR_DURING_ROLLBACK = 1181,
|
||||
ER_ERROR_DURING_FLUSH_LOGS = 1182,
|
||||
ER_ERROR_DURING_CHECKPOINT = 1183,
|
||||
ER_NEW_ABORTING_CONNECTION = 1184,
|
||||
ER_DUMP_NOT_IMPLEMENTED = 1185,
|
||||
ER_FLUSH_MASTER_BINLOG_CLOSED = 1186,
|
||||
ER_INDEX_REBUILD = 1187,
|
||||
ER_MASTER = 1188,
|
||||
ER_MASTER_NET_READ = 1189,
|
||||
ER_MASTER_NET_WRITE = 1190,
|
||||
ER_FT_MATCHING_KEY_NOT_FOUND = 1191,
|
||||
ER_LOCK_OR_ACTIVE_TRANSACTION = 1192,
|
||||
ER_UNKNOWN_SYSTEM_VARIABLE = 1193,
|
||||
ER_CRASHED_ON_USAGE = 1194,
|
||||
ER_CRASHED_ON_REPAIR = 1195,
|
||||
ER_WARNING_NOT_COMPLETE_ROLLBACK = 1196,
|
||||
ER_TRANS_CACHE_FULL = 1197,
|
||||
ER_SLAVE_MUST_STOP = 1198,
|
||||
ER_SLAVE_NOT_RUNNING = 1199,
|
||||
ER_BAD_SLAVE = 1200,
|
||||
ER_MASTER_INFO = 1201,
|
||||
ER_SLAVE_THREAD = 1202,
|
||||
ER_TOO_MANY_USER_CONNECTIONS = 1203,
|
||||
ER_SET_CONSTANTS_ONLY = 1204,
|
||||
ER_LOCK_WAIT_TIMEOUT = 1205,
|
||||
ER_LOCK_TABLE_FULL = 1206,
|
||||
ER_READ_ONLY_TRANSACTION = 1207,
|
||||
ER_DROP_DB_WITH_READ_LOCK = 1208,
|
||||
ER_CREATE_DB_WITH_READ_LOCK = 1209,
|
||||
ER_WRONG_ARGUMENTS = 1210,
|
||||
ER_NO_PERMISSION_TO_CREATE_USER = 1211,
|
||||
ER_UNION_TABLES_IN_DIFFERENT_DIR = 1212,
|
||||
ER_LOCK_DEADLOCK = 1213,
|
||||
ER_TABLE_CANT_HANDLE_FULLTEXT = 1214,
|
||||
ER_CANNOT_ADD_FOREIGN = 1215,
|
||||
ER_NO_REFERENCED_ROW = 1216,
|
||||
ER_ROW_IS_REFERENCED = 1217,
|
||||
ER_CONNECT_TO_MASTER = 1218,
|
||||
ER_QUERY_ON_MASTER = 1219,
|
||||
ER_ERROR_WHEN_EXECUTING_COMMAND = 1220,
|
||||
ER_WRONG_USAGE = 1221,
|
||||
ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT = 1222,
|
||||
ER_CANT_UPDATE_WITH_READLOCK = 1223,
|
||||
ER_MIXING_NOT_ALLOWED = 1224,
|
||||
ER_DUP_ARGUMENT = 1225,
|
||||
ER_USER_LIMIT_REACHED = 1226,
|
||||
ER_SPECIFIC_ACCESS_DENIED_ERROR = 1227,
|
||||
ER_LOCAL_VARIABLE = 1228,
|
||||
ER_GLOBAL_VARIABLE = 1229,
|
||||
ER_NO_DEFAULT = 1230,
|
||||
ER_WRONG_VALUE_FOR_VAR = 1231,
|
||||
ER_WRONG_TYPE_FOR_VAR = 1232,
|
||||
ER_VAR_CANT_BE_READ = 1233,
|
||||
ER_CANT_USE_OPTION_HERE = 1234,
|
||||
ER_NOT_SUPPORTED_YET = 1235,
|
||||
ER_MASTER_FATAL_ERROR_READING_BINLOG = 1236,
|
||||
ER_SLAVE_IGNORED_TABLE = 1237,
|
||||
ER_INCORRECT_GLOBAL_LOCAL_VAR = 1238,
|
||||
CR_UNKNOWN_ERROR = 1900,
|
||||
CR_SOCKET_CREATE_ERROR = 1901,
|
||||
CR_CONNECTION_ERROR = 1902,
|
||||
CR_CONN_HOST_ERROR = 1903,
|
||||
CR_IPSOCK_ERROR = 1904,
|
||||
CR_UNKNOWN_HOST = 1905,
|
||||
CR_SERVER_GONE_ERROR = 1906,
|
||||
CR_VERSION_ERROR = 1907,
|
||||
CR_OUT_OF_MEMORY = 1908,
|
||||
CR_WRONG_HOST_INFO = 1909,
|
||||
CR_LOCALHOST_CONNECTION = 1910,
|
||||
CR_TCP_CONNECTION = 1911,
|
||||
CR_SERVER_HANDSHAKE_ERR = 1912,
|
||||
CR_SERVER_LOST = 1913,
|
||||
CR_COMMANDS_OUT_OF_SYNC = 1914,
|
||||
CR_NAMEDPIPE_CONNECTION = 1915,
|
||||
CR_NAMEDPIPEWAIT_ERROR = 1916,
|
||||
CR_NAMEDPIPEOPEN_ERROR = 1917,
|
||||
CR_NAMEDPIPESETSTATE_ERROR = 1918,
|
||||
CR_CANT_READ_CHARSET = 1919,
|
||||
CR_NET_PACKET_TOO_LARGE = 1920,
|
||||
CR_EMBEDDED_CONNECTION = 1921,
|
||||
CR_PROBE_SLAVE_STATUS = 1922,
|
||||
CR_PROBE_SLAVE_HOSTS = 1923,
|
||||
CR_PROBE_SLAVE_CONNECT = 1924,
|
||||
CR_PROBE_MASTER_CONNECT = 1925,
|
||||
CR_SSL_CONNECTION_ERROR = 1926,
|
||||
CR_MALFORMED_PACKET = 1927,
|
||||
CR_WRONG_LICENSE = 1928,
|
||||
};
|
||||
}; // namespace DistributedTableCache
|
||||
|
||||
namespace DTC = DistributedTableCache;
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
global:
|
||||
*DistributedTableCache*;
|
||||
__invoke_dynamic_linker__;
|
||||
set_network_mode;
|
||||
set_server_address;
|
||||
set_server_tablename;
|
||||
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@ -1,494 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: dtc_int.h
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#ifndef __CHC_CLI_H
|
||||
#define __CHC_CLI_H
|
||||
|
||||
#include <table_def.h>
|
||||
#include <field_api.h>
|
||||
#include <packet.h>
|
||||
#include <unistd.h>
|
||||
#include <buffer_error.h>
|
||||
#include <log.h>
|
||||
#include "key_list.h"
|
||||
#include <task_request.h>
|
||||
#include <container.h>
|
||||
#include <net_addr.h>
|
||||
#include "udp_pool.h"
|
||||
#include "compress.h"
|
||||
#include "poll_thread.h"
|
||||
#include "lock.h"
|
||||
#include <map>
|
||||
|
||||
/*
|
||||
* Goal:
|
||||
* single transation (*)
|
||||
* batch transation (*)
|
||||
* async transation
|
||||
*/
|
||||
|
||||
class DTCTask;
|
||||
class Packet;
|
||||
|
||||
class NCResult;
|
||||
class NCResultInternal;
|
||||
class NCPool;
|
||||
struct NCTransation;
|
||||
class IDTCTaskExecutor;
|
||||
class IDTCService;
|
||||
|
||||
class NCBase
|
||||
{
|
||||
private:
|
||||
AtomicU32 _count;
|
||||
|
||||
public:
|
||||
NCBase(void) {}
|
||||
~NCBase(void) {}
|
||||
int INC(void) { return ++_count; }
|
||||
int DEC(void) { return --_count; }
|
||||
int CNT(void) { return _count.get(); };
|
||||
};
|
||||
|
||||
class NCRequest;
|
||||
class DataConnector;
|
||||
class NCServer : public NCBase
|
||||
{
|
||||
public: // global server state
|
||||
NCServer();
|
||||
NCServer(const NCServer &);
|
||||
~NCServer(void);
|
||||
|
||||
// base settings
|
||||
SocketAddress addr;
|
||||
char *tablename;
|
||||
char *appname;
|
||||
|
||||
static DataConnector *dc;
|
||||
|
||||
//for compress
|
||||
void set_compress_level(int level) { compressLevel = level; }
|
||||
int get_compress_level(void) { return compressLevel; }
|
||||
|
||||
//dtc set _server_address and _server_tablename for plugin
|
||||
static char *_server_address;
|
||||
static char *_server_tablename;
|
||||
|
||||
int keytype;
|
||||
int autoUpdateTable;
|
||||
int autoReconnect;
|
||||
static int _network_mode;
|
||||
NCKeyInfo keyinfo;
|
||||
|
||||
void clone_tab_def(const NCServer &source);
|
||||
int set_address(const char *h, const char *p = NULL);
|
||||
int set_table_name(const char *);
|
||||
const char *get_address(void) const { return addr.Name(); } //this addres is set by user
|
||||
const char *get_server_address(void) const { return _server_address; } //this address is set by dtc
|
||||
const char *get_server_table_name(void) const { return _server_tablename; }
|
||||
int is_dgram(void) const { return addr.socket_type() == SOCK_DGRAM; }
|
||||
int is_udp(void) const { return addr.socket_type() == SOCK_DGRAM && addr.socket_family() == AF_INET; }
|
||||
const char *get_table_name(void) const { return tablename; }
|
||||
int int_key(void);
|
||||
int string_key(void);
|
||||
int field_type(const char *);
|
||||
int is_completed(void) const { return completed; }
|
||||
int add_key(const char *name, uint8_t type);
|
||||
int key_field_cnt(void) const { return keyinfo.key_fields() ?: keytype != DField::None ? 1 : 0; }
|
||||
int allow_batch_key(void) const { return keyinfo.key_fields(); }
|
||||
int simple_batch_key(void) const { return keyinfo.key_fields() == 1 && keytype == keyinfo.key_type(0); }
|
||||
|
||||
void set_auto_update_tab(bool autoUpdate) { autoUpdateTable = autoUpdate ? 1 : 0; }
|
||||
void set_auto_reconnect(int reconnect) { autoReconnect = reconnect; }
|
||||
|
||||
// error state
|
||||
unsigned completed : 1;
|
||||
unsigned badkey : 1;
|
||||
unsigned badname : 1;
|
||||
unsigned autoping : 1;
|
||||
const char *errstr;
|
||||
|
||||
const char *error_message(void) const { return errstr; }
|
||||
|
||||
// table definition
|
||||
DTCTableDefinition *tdef;
|
||||
DTCTableDefinition *admin_tdef;
|
||||
|
||||
void save_definition(NCResult *);
|
||||
DTCTableDefinition *get_tab_def(int cmd) const;
|
||||
|
||||
std::string accessToken;
|
||||
int set_access_key(const char *token);
|
||||
|
||||
private: // serialNr manupulation
|
||||
uint64_t lastSN;
|
||||
|
||||
public:
|
||||
uint64_t NextSerialNr(void)
|
||||
{
|
||||
++lastSN;
|
||||
if (lastSN == 0)
|
||||
lastSN++;
|
||||
return lastSN;
|
||||
}
|
||||
uint64_t LastSerialNr(void) { return lastSN; }
|
||||
|
||||
private: // timeout settings
|
||||
int timeout;
|
||||
int realtmo;
|
||||
|
||||
public:
|
||||
void set_m_timeout(int n);
|
||||
int get_timeout(void) const { return timeout; }
|
||||
|
||||
private:
|
||||
int compressLevel;
|
||||
|
||||
private: // sync execution
|
||||
IDTCService *iservice;
|
||||
IDTCTaskExecutor *executor;
|
||||
int netfd;
|
||||
time_t lastAct;
|
||||
NCRequest *pingReq;
|
||||
|
||||
private:
|
||||
uint64_t agentTime;
|
||||
|
||||
public:
|
||||
void set_agent_time(int t) { agentTime = t; }
|
||||
uint64_t get_agent_time(void) { return agentTime; }
|
||||
|
||||
public:
|
||||
int Connect(void);
|
||||
int Reconnect(void);
|
||||
void Close(void);
|
||||
void SetFD(int fd)
|
||||
{
|
||||
Close();
|
||||
netfd = fd;
|
||||
update_timeout();
|
||||
}
|
||||
// stream, connected
|
||||
int send_packet_stream(Packet &);
|
||||
int decode_result_stream(NCResult &);
|
||||
// dgram, connected or connectless
|
||||
int send_packet_dgram(SocketAddress *peer, Packet &);
|
||||
int decode_result_dgram(SocketAddress *peer, NCResult &);
|
||||
// connectless
|
||||
NCUdpPort *get_global_port(void);
|
||||
void put_global_port(NCUdpPort *);
|
||||
|
||||
void TryPing(void);
|
||||
int ping(void);
|
||||
void auto_ping(void)
|
||||
{
|
||||
if (!is_dgram())
|
||||
autoping = 1;
|
||||
}
|
||||
NCResultInternal *execute_internal(NCRequest &rq, const DTCValue *kptr) { return executor->task_execute(rq, kptr); }
|
||||
int has_internal_executor(void) const { return executor != 0; }
|
||||
|
||||
private:
|
||||
int bind_temp_unix_socket(void);
|
||||
void update_timeout(void);
|
||||
// this method is weak, and don't exist in libdtc.a
|
||||
__attribute__((__weak__)) void check_internal_service(void);
|
||||
|
||||
public: // transation manager, impl at dtcpool.cc
|
||||
int async_connect(int &);
|
||||
NCPool *ownerPool;
|
||||
int ownerId;
|
||||
void set_owner(NCPool *, int);
|
||||
|
||||
NCResult *decode_buffer(const char *, int);
|
||||
static int check_packet_size(const char *, int);
|
||||
};
|
||||
|
||||
class NCRequest
|
||||
{
|
||||
public:
|
||||
NCServer *server;
|
||||
uint8_t cmd;
|
||||
uint8_t haskey;
|
||||
uint8_t flags;
|
||||
int err;
|
||||
DTCValue key;
|
||||
NCKeyValueList kvl;
|
||||
FieldValueByName ui;
|
||||
FieldValueByName ci;
|
||||
FieldSetByName fs;
|
||||
|
||||
DTCTableDefinition *tdef;
|
||||
char *tablename;
|
||||
int keytype;
|
||||
|
||||
unsigned int limitStart;
|
||||
unsigned int limitCount;
|
||||
int adminCode;
|
||||
|
||||
uint64_t hotBackupID;
|
||||
uint64_t master_hb_timestamp;
|
||||
uint64_t slave_hb_timestamp;
|
||||
|
||||
public:
|
||||
NCRequest(NCServer *, int op);
|
||||
~NCRequest(void);
|
||||
int attach_server(NCServer *);
|
||||
|
||||
void enable_no_cache(void) { flags |= DRequest::Flag::no_cache; }
|
||||
void enable_no_next_server(void) { flags |= DRequest::Flag::no_next_server; }
|
||||
void enable_no_result(void) { flags |= DRequest::Flag::NoResult; }
|
||||
int add_condition(const char *n, uint8_t op, uint8_t t, const DTCValue &v);
|
||||
int add_operation(const char *n, uint8_t op, uint8_t t, const DTCValue &v);
|
||||
int compress_set(const char *n, const char *v, int len);
|
||||
int compress_set_force(const char *n, const char *v, int len);
|
||||
int add_value(const char *n, uint8_t t, const DTCValue &v);
|
||||
int Need(const char *n, int);
|
||||
void limit(unsigned int st, unsigned int cnt)
|
||||
{
|
||||
if (cnt == 0)
|
||||
st = 0;
|
||||
limitStart = st;
|
||||
limitCount = cnt;
|
||||
}
|
||||
|
||||
int set_key(int64_t);
|
||||
int set_key(const char *, int);
|
||||
int unset_key(void);
|
||||
int unset_key_value(void);
|
||||
int field_type(const char *name) { return server ? server->field_type(name) : DField::None; }
|
||||
int add_key_value(const char *name, const DTCValue &v, uint8_t type);
|
||||
int set_cache_id(int dummy) { return err = -EINVAL; }
|
||||
void set_admin_code(int code) { adminCode = code; }
|
||||
void set_hot_backup_id(uint64_t v) { hotBackupID = v; }
|
||||
void set_master_hb_timestamp(uint64_t t) { master_hb_timestamp = t; }
|
||||
void set_slave_hb_timestamp(uint64_t t) { slave_hb_timestamp = t; }
|
||||
|
||||
// never return NULL
|
||||
NCResult *execute(const DTCValue *key = NULL);
|
||||
NCResult *execute_stream(const DTCValue *key = NULL);
|
||||
NCResult *execute_dgram(SocketAddress *peer, const DTCValue *key = NULL);
|
||||
NCResult *execute_network(const DTCValue *key = NULL);
|
||||
NCResult *execute_internal(const DTCValue *key = NULL);
|
||||
NCResult *execute(int64_t);
|
||||
NCResult *execute(const char *, int);
|
||||
NCResult *pre_check(const DTCValue *key); // return error result, NULL==success
|
||||
int set_compress_field_name(void); //Need compress flag for read,or set compressFlag for write
|
||||
int Encode(const DTCValue *key, Packet *);
|
||||
// return 1 if tdef changed...
|
||||
int set_tab_def(void);
|
||||
|
||||
int encode_buffer(char *&ptr, int &len, int64_t &magic, const DTCValue *key = NULL);
|
||||
int encode_buffer(char *&ptr, int &len, int64_t &magic, int64_t);
|
||||
int encode_buffer(char *&ptr, int &len, int64_t &magic, const char *, int);
|
||||
const char *error_message(void) const
|
||||
{
|
||||
return _errmsg;
|
||||
}
|
||||
|
||||
int set_expire_time(const char *key, int t);
|
||||
int get_expire_time(const char *key);
|
||||
|
||||
private:
|
||||
int set_compress_flag(const char *name)
|
||||
{
|
||||
if (tdef == NULL)
|
||||
return -EC_NOT_INITIALIZED;
|
||||
if (tdef->field_id(name) >= 64)
|
||||
{
|
||||
snprintf(_errmsg, sizeof(_errmsg), "compress error:field id must less than 64");
|
||||
return -EC_COMPRESS_ERROR;
|
||||
}
|
||||
compressFlag |= (1 << tdef->field_id(name));
|
||||
return 0;
|
||||
}
|
||||
uint64_t compressFlag; //field flag
|
||||
DTCCompress *gzip;
|
||||
int init_compress(void);
|
||||
char _errmsg[1024];
|
||||
};
|
||||
|
||||
class NCResultLocal
|
||||
{
|
||||
public:
|
||||
const uint8_t *vidmap;
|
||||
long long apiTag;
|
||||
int maxvid;
|
||||
DTCCompress *gzip;
|
||||
|
||||
public:
|
||||
NCResultLocal(DTCTableDefinition *tdef) : vidmap(NULL),
|
||||
apiTag(0),
|
||||
maxvid(0),
|
||||
gzip(NULL),
|
||||
_tdef(tdef),
|
||||
compressid(-1)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NCResultLocal(void)
|
||||
{
|
||||
FREE_CLEAR(vidmap);
|
||||
DELETE(gzip);
|
||||
}
|
||||
|
||||
virtual int field_id_virtual(int id) const
|
||||
{
|
||||
return id > 0 && id <= maxvid ? vidmap[id - 1] : 0;
|
||||
}
|
||||
|
||||
virtual void set_api_tag(long long t) { apiTag = t; }
|
||||
virtual long long get_api_tag(void) const { return apiTag; }
|
||||
|
||||
void set_virtual_map(FieldSetByName &fs)
|
||||
{
|
||||
if (fs.max_virtual_id())
|
||||
{
|
||||
fs.Resolve(_tdef, 0);
|
||||
vidmap = fs.virtual_map();
|
||||
maxvid = fs.max_virtual_id();
|
||||
}
|
||||
}
|
||||
|
||||
virtual int init_compress()
|
||||
{
|
||||
if (NULL == _tdef)
|
||||
{
|
||||
return -EC_CHECKSUM_MISMATCH;
|
||||
}
|
||||
|
||||
int iret = 0;
|
||||
compressid = _tdef->compress_field_id();
|
||||
if (compressid < 0)
|
||||
return 0;
|
||||
if (gzip == NULL)
|
||||
NEW(DTCCompress, gzip);
|
||||
if (gzip == NULL)
|
||||
return -ENOMEM;
|
||||
iret = gzip->set_buffer_len(_tdef->max_field_size());
|
||||
if (iret)
|
||||
return iret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual const int compress_id(void) const { return compressid; }
|
||||
|
||||
private:
|
||||
DTCTableDefinition *_tdef;
|
||||
uint64_t compressid;
|
||||
};
|
||||
|
||||
class NCResult : public NCResultLocal, public DTCTask
|
||||
{
|
||||
public:
|
||||
NCResult(DTCTableDefinition *tdef) : NCResultLocal(tdef), DTCTask(tdef, TaskRoleClient, 0)
|
||||
{
|
||||
if (tdef)
|
||||
tdef->INC();
|
||||
mark_allow_remote_table();
|
||||
}
|
||||
|
||||
NCResult(int err, const char *from, const char *msg) : NCResultLocal(NULL), DTCTask(NULL, TaskRoleClient, 1)
|
||||
{
|
||||
resultInfo.set_error_dup(err, from, msg);
|
||||
}
|
||||
virtual ~NCResult()
|
||||
{
|
||||
DTCTableDefinition *tdef = table_definition();
|
||||
DEC_DELETE(tdef);
|
||||
}
|
||||
};
|
||||
|
||||
class NCResultInternal : public NCResultLocal, public TaskRequest
|
||||
{
|
||||
public:
|
||||
NCResultInternal(DTCTableDefinition *tdef = NULL) : NCResultLocal(tdef)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NCResultInternal()
|
||||
{
|
||||
}
|
||||
|
||||
static inline int verify_class(void)
|
||||
{
|
||||
NCResultInternal *ir = 0;
|
||||
NCResult *er = reinterpret_cast<NCResult *>(ir);
|
||||
|
||||
NCResultLocal *il = (NCResultLocal *)ir;
|
||||
NCResultLocal *el = (NCResultLocal *)er;
|
||||
|
||||
DTCTask *it = (DTCTask *)ir;
|
||||
DTCTask *et = (DTCTask *)er;
|
||||
|
||||
long dl = reinterpret_cast<char *>(il) - reinterpret_cast<char *>(el);
|
||||
long dt = reinterpret_cast<char *>(it) - reinterpret_cast<char *>(et);
|
||||
return dl == 0 && dt == 0;
|
||||
}
|
||||
};
|
||||
|
||||
class DataConnector
|
||||
{
|
||||
struct businessStatistics
|
||||
{
|
||||
uint64_t TotalTime; // 10s内请求总耗时
|
||||
uint32_t TotalRequests; // 10s内请求总次数
|
||||
|
||||
public:
|
||||
businessStatistics()
|
||||
{
|
||||
TotalTime = 0;
|
||||
TotalRequests = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct bidCurve
|
||||
{
|
||||
uint32_t bid;
|
||||
uint32_t curve;
|
||||
bool operator<(const bidCurve &that) const
|
||||
{
|
||||
int sum1 = bid * 10 + curve;
|
||||
int sum2 = that.bid * 10 + that.curve;
|
||||
return sum1 < sum2;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
std::map<bidCurve, businessStatistics> mapBi;
|
||||
Mutex _lock; // 读写 TotalTime、TotalRequests时,加锁,防止脏数据
|
||||
static DataConnector *pDataConnector;
|
||||
DataConnector();
|
||||
~DataConnector();
|
||||
pthread_t threadid;
|
||||
|
||||
public:
|
||||
static DataConnector *getInstance()
|
||||
{
|
||||
if (pDataConnector == NULL)
|
||||
pDataConnector = new DataConnector();
|
||||
return pDataConnector;
|
||||
};
|
||||
|
||||
public:
|
||||
int send_data();
|
||||
int set_report_info(const std::string str, const uint32_t curve, const uint64_t t);
|
||||
void get_report_info(std::map<bidCurve, businessStatistics> &mapData);
|
||||
int set_bussiness_id(std::string str);
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,315 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: dtc_pool.h
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#ifndef __CHC_CLI_POOL_H
|
||||
#define __CHC_CLI_POOL_H
|
||||
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include "list.h"
|
||||
#include "poller.h"
|
||||
#include "timer_list.h"
|
||||
#include "dtc_int.h"
|
||||
#include "buffer_error.h"
|
||||
|
||||
class NCServerInfo;
|
||||
class NCPool;
|
||||
class NCConnection;
|
||||
|
||||
// transation is a internal async request
|
||||
class NCTransation : public ListObject<NCTransation>
|
||||
{
|
||||
public:
|
||||
// constructor/destructor equiv
|
||||
NCTransation(void);
|
||||
~NCTransation(void);
|
||||
/* clear transation state */
|
||||
void Clear(void);
|
||||
/* abort current transation, zero means succ */
|
||||
void Abort(int);
|
||||
/* transation succ with result */
|
||||
void Done(NCResult *res)
|
||||
{
|
||||
result = res;
|
||||
Abort(0);
|
||||
}
|
||||
/* get transation result */
|
||||
NCResult *get_result(void);
|
||||
/* adjust generation id */
|
||||
void round_gen_id(int m)
|
||||
{
|
||||
if (genId >= m)
|
||||
genId = 0;
|
||||
}
|
||||
|
||||
/* state & info management */
|
||||
int State(void) const { return state; }
|
||||
int gen_id(void) const { return genId; }
|
||||
int MatchSN(NCResult *res) const { return SN == res->versionInfo.serial_nr(); }
|
||||
/* send packet management */
|
||||
int Send(int fd) { return packet->Send(fd); }
|
||||
int attach_request(NCServerInfo *s, long long tag, NCRequest *req, DTCValue *key);
|
||||
void attach_connection(NCConnection *c);
|
||||
void SendOK(ListObject<NCTransation> *);
|
||||
void RecvOK(ListObject<NCTransation> *);
|
||||
|
||||
public: // constant member declare as static
|
||||
// owner info, associated server
|
||||
NCServerInfo *server;
|
||||
// attached connection, SEND, RECV
|
||||
NCConnection *conn;
|
||||
|
||||
private: // transient members is private
|
||||
// current transation state, WAIT, SEND, RECV, DONE
|
||||
int state;
|
||||
// internal transation generation id
|
||||
int genId;
|
||||
// associated request tag
|
||||
long long reqTag;
|
||||
// associated request SN, state SEND, RECV
|
||||
uint64_t SN;
|
||||
|
||||
// sending packet
|
||||
Packet *packet;
|
||||
|
||||
// execute result
|
||||
NCResult *result;
|
||||
};
|
||||
|
||||
class NCConnection : public ListObject<NCConnection>,
|
||||
public PollerObject
|
||||
{
|
||||
public:
|
||||
NCConnection(NCPool *, NCServerInfo *);
|
||||
~NCConnection(void);
|
||||
|
||||
int is_dgram(void) const;
|
||||
int is_async(void) const;
|
||||
/* starting state machine, by NCServerInfo::Connect */
|
||||
int Connect(void);
|
||||
/* attach transation to connection */
|
||||
void process_request(NCTransation *);
|
||||
/* flush send channel */
|
||||
void send_request(void);
|
||||
/* flush recv channel */
|
||||
int RecvResult(void);
|
||||
/* check connection hangup, recv zero bytes */
|
||||
int check_hangup(void);
|
||||
|
||||
/* abort all associated request */
|
||||
void abort_requests(int err);
|
||||
/* close connection */
|
||||
void Close(int err);
|
||||
/* abort current sending request, linger recv channel */
|
||||
void abort_send_side(int err);
|
||||
/* a valid result received */
|
||||
void done_result(void);
|
||||
/* connection is idle, usable for transation */
|
||||
void switch_to_idle(void);
|
||||
/* connection is async connecting */
|
||||
void switch_to_connecting(void);
|
||||
|
||||
virtual void input_notify(void);
|
||||
virtual void output_notify(void);
|
||||
virtual void hangup_notify(void);
|
||||
virtual void timer_notify(void);
|
||||
|
||||
private:
|
||||
/* associated server */
|
||||
NCServerInfo *serverInfo;
|
||||
/* queued transation in RECV state */
|
||||
ListObject<NCTransation> reqList;
|
||||
/* sending transation */
|
||||
NCTransation *sreq;
|
||||
/* decoding/decoded result */
|
||||
NCResult *result;
|
||||
/* connection state */
|
||||
int state;
|
||||
|
||||
int NETFD(void) const { return netfd; }
|
||||
|
||||
private:
|
||||
TimerMember<NCConnection> timer;
|
||||
SimpleReceiver receiver;
|
||||
};
|
||||
|
||||
typedef ListObject<NCConnection> NCConnectionList;
|
||||
|
||||
class NCPool : public PollerUnit,
|
||||
public TimerUnit
|
||||
{
|
||||
public:
|
||||
NCPool(int maxServers, int maxRequests);
|
||||
~NCPool();
|
||||
|
||||
int initialize_poller_unit(void);
|
||||
|
||||
int get_epoll_fd(int maxpoller);
|
||||
int add_server(NCServer *srv, int maxReq = 1, int maxConn = 0);
|
||||
int add_request(NCRequest *req, long long tag, DTCValue *key = 0);
|
||||
|
||||
void execute_one_loop(int timeout);
|
||||
int execute(int timeout);
|
||||
int execute_all(int timeout);
|
||||
|
||||
NCTransation *Id2Req(int) const;
|
||||
int cancel_request(int);
|
||||
int cancel_all_request(int);
|
||||
int abort_request(NCTransation *);
|
||||
int abort_request(int);
|
||||
int abort_all_request(int);
|
||||
NCResult *get_result(void);
|
||||
NCResult *get_result(int);
|
||||
|
||||
int count_request_state(int) const;
|
||||
int request_state(int) const;
|
||||
|
||||
public:
|
||||
NCTransation *get_transation_slot(void);
|
||||
void transation_finished(NCTransation *);
|
||||
NCResult *get_transation_result(NCTransation *);
|
||||
int get_transation_state(NCTransation *);
|
||||
|
||||
int server_count(void) const { return numServers; }
|
||||
int request_count(void) const { return numRequests; }
|
||||
int done_request_count(void) const { return doneRequests; }
|
||||
|
||||
private:
|
||||
int initFlag;
|
||||
int maxServers;
|
||||
int maxRequests;
|
||||
int numServers;
|
||||
int numRequests;
|
||||
int maxRequestId;
|
||||
int doneRequests;
|
||||
ListObject<NCTransation> freeList;
|
||||
ListObject<NCTransation> doneList;
|
||||
NCServerInfo *serverList;
|
||||
NCTransation *transList;
|
||||
|
||||
public:
|
||||
char *buf;
|
||||
};
|
||||
|
||||
class NCServerInfo : private TimerObject
|
||||
{
|
||||
public:
|
||||
NCServerInfo(void);
|
||||
~NCServerInfo(void);
|
||||
void Init(NCServer *, int, int);
|
||||
|
||||
/* prepare wake timer_notify */
|
||||
void mark_as_ready() { attach_ready_timer(owner); }
|
||||
virtual void timer_notify(void);
|
||||
/* four reason server has more work to do */
|
||||
/* more transation attached */
|
||||
void more_request_and_ready(void)
|
||||
{
|
||||
reqWait++;
|
||||
mark_as_ready();
|
||||
}
|
||||
/* more close connection, should reconnecting */
|
||||
void more_closed_connection_and_ready(void)
|
||||
{
|
||||
connRemain++;
|
||||
mark_as_ready();
|
||||
}
|
||||
/* more idle connection available */
|
||||
void connection_idle_and_ready(void) { mark_as_ready(); }
|
||||
/* more request can assign to idle pool */
|
||||
void request_done_and_ready(int oldstate);
|
||||
|
||||
/* one request scheduled to SEND state */
|
||||
void request_scheduled(void)
|
||||
{
|
||||
reqRemain--;
|
||||
reqSend++;
|
||||
}
|
||||
void request_sent(void)
|
||||
{
|
||||
reqSend--;
|
||||
reqRecv++;
|
||||
}
|
||||
|
||||
/* queue transation to this server */
|
||||
void queue_request(NCTransation *req)
|
||||
{
|
||||
req->ListAddTail(&reqList);
|
||||
more_request_and_ready();
|
||||
}
|
||||
/* one connecting aborted */
|
||||
void connecting_failed(void) { connError++; }
|
||||
void connecting_done(void) { connConnecting--; }
|
||||
|
||||
/* abort all waiting transations */
|
||||
void abort_wait_queue(int err);
|
||||
|
||||
int count_request_state(int type) const;
|
||||
|
||||
/* get a waiting transation */
|
||||
NCTransation *get_request_from_queue(void)
|
||||
{
|
||||
NCTransation *trans = reqList.NextOwner();
|
||||
trans->list_del();
|
||||
reqWait--;
|
||||
return trans;
|
||||
}
|
||||
|
||||
private:
|
||||
int Connect(void);
|
||||
ListObject<NCTransation> reqList;
|
||||
|
||||
public: // constant member declare as public
|
||||
/* associated ServerPool */
|
||||
NCPool *owner;
|
||||
/* basic server info */
|
||||
NCServer *info;
|
||||
TimerList *timerList;
|
||||
int mode; // 0--TCP 1--ASYNC 2--UDP
|
||||
/* total connection */
|
||||
int connTotal;
|
||||
|
||||
private: // transient member is private
|
||||
/* transation in state WAIT */
|
||||
int reqWait;
|
||||
/* transation in state SEND */
|
||||
int reqSend;
|
||||
/* transation in state RECV */
|
||||
int reqRecv;
|
||||
/* remain requests can assign to connection pool */
|
||||
int reqRemain;
|
||||
|
||||
/* remain connections can connect */
|
||||
int connRemain;
|
||||
/* number connections in connecting state */
|
||||
int connConnecting;
|
||||
/* number of connect error this round */
|
||||
int connError;
|
||||
/* busy connection count */
|
||||
inline int conn_working(void) const { return connTotal - connConnecting - connRemain; }
|
||||
|
||||
public: //except idleList for code conventional
|
||||
/* idle connection list */
|
||||
NCConnectionList idleList;
|
||||
/* busy connection list SEND,RECV,LINGER */
|
||||
NCConnectionList busyList;
|
||||
};
|
||||
|
||||
inline int NCConnection::is_dgram(void) const { return serverInfo->mode == 2; }
|
||||
inline int NCConnection::is_async(void) const { return serverInfo->mode; }
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,250 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: dtc_wrapp.cc
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
#include <value.h>
|
||||
#include <compiler.h>
|
||||
|
||||
#include "dtc_api.h"
|
||||
#include "dtc_pool.h"
|
||||
|
||||
using namespace DistributedTableCache;
|
||||
|
||||
#define CAST(type, var) type *var = (type *)addr
|
||||
#define CAST2(type, var, src) type *var = (type *)src->addr
|
||||
#define CAST3(type, var, src) type *var = (type *)src.addr
|
||||
|
||||
// WRAPPER for Server
|
||||
__EXPORT
|
||||
ServerPool::ServerPool(int ms, int mr)
|
||||
{
|
||||
NCPool *pl = new NCPool(ms, mr);
|
||||
addr = pl;
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
ServerPool::~ServerPool(void)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
delete pl;
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_server(Server *srv, int mreq, int mconn)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
CAST2(NCServer, s, srv);
|
||||
|
||||
return pl->add_server(s, mreq, mconn);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, long long tag)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
CAST2(NCRequest, r, req);
|
||||
|
||||
if (r->server == NULL)
|
||||
return -EC_NOT_INITIALIZED;
|
||||
|
||||
return pl->add_request(r, tag, NULL);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, void *tag)
|
||||
{
|
||||
return add_request(req, (long long)(long)tag);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, long long tag, long long k)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
CAST2(NCRequest, r, req);
|
||||
|
||||
if (r->server == NULL)
|
||||
return -EC_NOT_INITIALIZED;
|
||||
if (r->server->keytype != DField::Signed)
|
||||
return -EC_BAD_KEY_TYPE;
|
||||
|
||||
DTCValue v(k);
|
||||
return pl->add_request(r, tag, &v);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, void *tag, long long k)
|
||||
{
|
||||
return add_request(req, (long long)(long)tag, k);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, long long tag, const char *k)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
CAST2(NCRequest, r, req);
|
||||
|
||||
if (r->server == NULL)
|
||||
return -EC_NOT_INITIALIZED;
|
||||
if (r->server->keytype != DField::String)
|
||||
return -EC_BAD_KEY_TYPE;
|
||||
|
||||
DTCValue v(k);
|
||||
return pl->add_request(r, tag, &v);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, void *tag, const char *k)
|
||||
{
|
||||
return add_request(req, (long long)(long)tag, k);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, long long tag, const char *k, int l)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
CAST2(NCRequest, r, req);
|
||||
|
||||
if (r->server == NULL)
|
||||
return -EC_NOT_INITIALIZED;
|
||||
if (r->server->keytype != DField::String)
|
||||
return -EC_BAD_KEY_TYPE;
|
||||
|
||||
DTCValue v(k, l);
|
||||
return pl->add_request(r, tag, &v);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::add_request(Request *req, void *tag, const char *k, int l)
|
||||
{
|
||||
return add_request(req, (long long)(long)tag, k, l);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::execute(int msec)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->execute(msec);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::execute_all(int msec)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->execute_all(msec);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::cancel_request(int id)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->cancel_request(id);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::cancel_all_request(int type)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->cancel_all_request(type);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::abort_request(int id)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->abort_request(id);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::abort_all_request(int type)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->abort_all_request(type);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
Result *ServerPool::get_result(void)
|
||||
{
|
||||
return get_result(0);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
Result *ServerPool::get_result(int id)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
NCResult *a = pl->get_result(id);
|
||||
if ((long)a < 4096 && (long)a > -4095)
|
||||
return NULL;
|
||||
Result *s = new Result();
|
||||
s->addr = (void *)a;
|
||||
return s;
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::get_result(Result &s)
|
||||
{
|
||||
return get_result(s, 0);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::get_result(Result &s, int id)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
s.Reset();
|
||||
NCResult *a = pl->get_result(id);
|
||||
long iv = (long)a;
|
||||
if (iv < 4096 && iv > -4095)
|
||||
{
|
||||
s.addr = (void *)(new NCResult(iv, "API::executing", iv > 0 ? "Request not completed" : id ? "Invalid request" : "No more result"));
|
||||
return iv;
|
||||
}
|
||||
s.addr = (void *)a;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::server_count(void) const
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->server_count();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::request_count(int type) const
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
if (type == DONE)
|
||||
return pl->done_request_count();
|
||||
if (type == (WAIT | SEND | RECV | DONE))
|
||||
return pl->request_count();
|
||||
return pl->count_request_state(type);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::request_state(int reqId) const
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->request_state(reqId);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int ServerPool::get_epoll_fd(int size)
|
||||
{
|
||||
CAST(NCPool, pl);
|
||||
return pl->get_epoll_fd(size);
|
||||
}
|
||||
|
||||
const int ALL_STATE = WAIT | SEND | RECV | DONE;
|
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: key_list.cc
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <errno.h>
|
||||
|
||||
#include "mem_check.h"
|
||||
#include "protocol.h"
|
||||
#include "key_list.h"
|
||||
#include "buffer_error.h"
|
||||
|
||||
int NCKeyValueList::KeyValueMax = 32;
|
||||
|
||||
int NCKeyInfo::KeyIndex(const char *n) const
|
||||
{
|
||||
namemap_t::const_iterator i = keyMap.find(n);
|
||||
return i == keyMap.end() ? -1 : i->second;
|
||||
}
|
||||
|
||||
int NCKeyInfo::add_key(const char *name, int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DField::Signed:
|
||||
case DField::String:
|
||||
break;
|
||||
default:
|
||||
return -EC_BAD_KEY_TYPE;
|
||||
}
|
||||
if (KeyIndex(name) >= 0)
|
||||
{
|
||||
//return -EC_DUPLICATE_FIELD;
|
||||
|
||||
// ignore duplicate key field name
|
||||
// because NCKeyInfo may be initialized by check_internal_service()
|
||||
// add again must be allowed for code compatibility
|
||||
return 0;
|
||||
}
|
||||
int cnt = key_fields();
|
||||
if (cnt >= (int)(sizeof(keyType) / sizeof(keyType[0])))
|
||||
return -EC_BAD_MULTIKEY;
|
||||
keyName[cnt] = name;
|
||||
keyMap[name] = cnt;
|
||||
keyType[cnt] = type;
|
||||
keyCount++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NCKeyInfo::Equal(const NCKeyInfo &other) const
|
||||
{
|
||||
int n = key_fields();
|
||||
// key field count mis-match
|
||||
if (other.key_fields() != n)
|
||||
return 0;
|
||||
// key type mis-match
|
||||
if (memcmp(keyType, other.keyType, n) != 0)
|
||||
return 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
// key name mis-match
|
||||
if (strcasecmp(keyName[i], other.keyName[i]) != 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void NCKeyValueList::Unset(void)
|
||||
{
|
||||
if (kcount)
|
||||
{
|
||||
const int kn = key_fields();
|
||||
for (int i = 0; i < kcount; i++)
|
||||
{
|
||||
for (int j = 0; j < kn; j++)
|
||||
if (key_type(j) == DField::String || key_type(j) == DField::Binary)
|
||||
FREE(Value(i, j).bin.ptr);
|
||||
}
|
||||
|
||||
FREE_CLEAR(val);
|
||||
memset(fcount, 0, sizeof(fcount));
|
||||
kcount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int NCKeyValueList::add_value(const char *name, const DTCValue &v, int type)
|
||||
{
|
||||
const int kn = key_fields();
|
||||
|
||||
int col = keyinfo->KeyIndex(name);
|
||||
if (col < 0 || col >= kn)
|
||||
return -EC_BAD_KEY_NAME;
|
||||
|
||||
switch (key_type(col))
|
||||
{
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
if (type != DField::Signed && type != DField::Unsigned)
|
||||
return -EC_BAD_VALUE_TYPE;
|
||||
break;
|
||||
case DField::String:
|
||||
case DField::Binary:
|
||||
if (type != DField::String && type != DField::Binary)
|
||||
return -EC_BAD_VALUE_TYPE;
|
||||
if (v.bin.len > 255)
|
||||
return -EC_KEY_OVERFLOW;
|
||||
break;
|
||||
default:
|
||||
return -EC_BAD_KEY_TYPE;
|
||||
}
|
||||
|
||||
int row = fcount[col];
|
||||
if (row >= KeyValueMax)
|
||||
return -EC_TOO_MANY_KEY_VALUE; // key值太多
|
||||
if (row >= kcount)
|
||||
{
|
||||
if (REALLOC(val, (kcount + 1) * kn * sizeof(DTCValue)) == NULL)
|
||||
throw std::bad_alloc();
|
||||
memset(&Value(row, 0), 0, kn * sizeof(DTCValue));
|
||||
kcount++;
|
||||
}
|
||||
DTCValue &slot = Value(row, col);
|
||||
switch (key_type(col))
|
||||
{
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
slot = v;
|
||||
break;
|
||||
|
||||
case DField::String:
|
||||
case DField::Binary:
|
||||
slot.bin.len = v.bin.len;
|
||||
slot.bin.ptr = (char *)MALLOC(v.bin.len + 1);
|
||||
if (slot.bin.ptr == NULL)
|
||||
throw std::bad_alloc();
|
||||
memcpy(slot.bin.ptr, v.bin.ptr, v.bin.len);
|
||||
slot.bin.ptr[v.bin.len] = '\0';
|
||||
break;
|
||||
}
|
||||
fcount[col]++;
|
||||
return 0;
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: key_list.h
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#ifndef __CHC_KEYLIST_H
|
||||
#define __CHC_KEYLIST_H
|
||||
|
||||
#include <string.h>
|
||||
#include <map>
|
||||
|
||||
#include <value.h>
|
||||
|
||||
class NCKeyInfo
|
||||
{
|
||||
private:
|
||||
struct nocase
|
||||
{
|
||||
bool operator()(const char *const &a, const char *const &b) const
|
||||
{
|
||||
return strcasecmp(a, b) < 0;
|
||||
}
|
||||
};
|
||||
typedef std::map<const char *, int, nocase> namemap_t;
|
||||
|
||||
private:
|
||||
namemap_t keyMap;
|
||||
const char *keyName[8];
|
||||
uint8_t keyType[8];
|
||||
int keyCount;
|
||||
|
||||
public:
|
||||
// zero is KeyField::None
|
||||
void Clear(void)
|
||||
{
|
||||
keyCount = 0;
|
||||
memset(keyType, 0, sizeof(keyType));
|
||||
memset(keyName, 0, sizeof(keyName));
|
||||
keyMap.clear();
|
||||
}
|
||||
NCKeyInfo()
|
||||
{
|
||||
keyCount = 0;
|
||||
memset(keyType, 0, sizeof(keyType));
|
||||
memset(keyName, 0, sizeof(keyName));
|
||||
}
|
||||
NCKeyInfo(const NCKeyInfo &that)
|
||||
{
|
||||
keyCount = that.keyCount;
|
||||
memcpy(keyType, that.keyType, sizeof(keyType));
|
||||
memcpy(keyName, that.keyName, sizeof(keyName));
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
keyMap[keyName[i]] = i;
|
||||
}
|
||||
~NCKeyInfo() {}
|
||||
|
||||
int add_key(const char *name, int type);
|
||||
int Equal(const NCKeyInfo &other) const;
|
||||
int KeyIndex(const char *n) const;
|
||||
const char *key_name(int n) const { return keyName[n]; }
|
||||
int key_type(int id) const { return keyType[id]; }
|
||||
int key_fields(void) const { return keyCount; }
|
||||
};
|
||||
|
||||
class NCKeyValueList
|
||||
{
|
||||
public:
|
||||
static int KeyValueMax;
|
||||
|
||||
public:
|
||||
NCKeyInfo *keyinfo;
|
||||
DTCValue *val;
|
||||
int fcount[8];
|
||||
int kcount;
|
||||
|
||||
public:
|
||||
NCKeyValueList(void) : keyinfo(NULL), val(NULL), kcount(0)
|
||||
{
|
||||
memset(fcount, 0, sizeof(fcount));
|
||||
}
|
||||
~NCKeyValueList()
|
||||
{
|
||||
FREE_CLEAR(val);
|
||||
}
|
||||
int key_fields(void) const { return keyinfo->key_fields(); }
|
||||
int key_type(int id) const { return keyinfo->key_type(id); }
|
||||
int key_count(void) const { return kcount; }
|
||||
const char *key_name(int id) const { return keyinfo->key_name(id); }
|
||||
|
||||
void Unset(void);
|
||||
int add_value(const char *, const DTCValue &, int);
|
||||
DTCValue &Value(int row, int col) { return val[row * keyinfo->key_fields() + col]; }
|
||||
const DTCValue &Value(int row, int col) const { return val[row * keyinfo->key_fields() + col]; }
|
||||
DTCValue &operator()(int row, int col) { return Value(row, col); }
|
||||
const DTCValue &operator()(int row, int col) const { return Value(row, col); }
|
||||
int IsFlat(void) const
|
||||
{
|
||||
for (int i = 1; i < keyinfo->key_fields(); i++)
|
||||
if (fcount[0] != fcount[i])
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: log_client.cc
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include "dtc_api.h"
|
||||
#include <log.cc>
|
||||
|
||||
__EXPORT
|
||||
void DistributedTableCache::write_log(int level,
|
||||
const char *file, const char *func, int lineno,
|
||||
const char *fmt, ...)
|
||||
__attribute__((format(printf, 5, 6)))
|
||||
__attribute__((__alias__("_write_log_")));
|
@ -1,3 +0,0 @@
|
||||
注意事项:
|
||||
1.auto_dtcc++.sh 该脚本是需要root权限去执行的,它的作用是将dtc sdk 的动态库
|
||||
放置在 /usr/lib 目录下,并且执行命令 ldconfig 使配置生效
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: somain.c
|
||||
*
|
||||
* Description: entry function.
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#undef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <version.h>
|
||||
#include <compiler.h>
|
||||
|
||||
const char __invoke_dynamic_linker__[]
|
||||
__attribute__((section(".interp")))
|
||||
__HIDDEN =
|
||||
#if __x86_64__
|
||||
"/lib64/ld-linux-x86-64.so.2"
|
||||
#else
|
||||
"/lib/ld-linux.so.2"
|
||||
#endif
|
||||
;
|
||||
|
||||
__HIDDEN
|
||||
void _so_start(char *arg1, ...)
|
||||
{
|
||||
#define BANNER "DTC client API v" DTC_VERSION_DETAIL "\n" \
|
||||
" - TCP connection supported\n" \
|
||||
" - UDP connection supported\n" \
|
||||
" - UNIX stream connection supported\n" \
|
||||
" - embeded threading connection supported\n" \
|
||||
" - protocol packet encode/decode interface supported\n" \
|
||||
" - async execute (except embeded threading) supported \n"
|
||||
|
||||
int unused;
|
||||
unused = write(1, BANNER, sizeof(BANNER) - 1);
|
||||
_exit(0);
|
||||
}
|
@ -1,257 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: udp_pool.cc
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <pthread.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <alloca.h>
|
||||
#include "udp_pool.h"
|
||||
#include "log.h"
|
||||
|
||||
static unsigned int bindip = 0xFFFFFFFF;
|
||||
|
||||
unsigned int GetBindIp(void)
|
||||
{
|
||||
const char *name = getenv("DTCAPI_UDP_INTERFACE");
|
||||
|
||||
if (name == NULL || name[0] == 0 || strcmp(name, "*") == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr = NULL;
|
||||
int n = 0;
|
||||
int i;
|
||||
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
ifc.ifc_len = 0;
|
||||
ifc.ifc_req = NULL;
|
||||
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) == 0)
|
||||
{
|
||||
ifr = (struct ifreq *) alloca(ifc.ifc_len > 128 ? ifc.ifc_len : 128);
|
||||
ifc.ifc_req = ifr;
|
||||
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) == 0)
|
||||
n = ifc.ifc_len / sizeof(struct ifreq);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (strncmp(ifr[i].ifr_name, name, sizeof(ifr[i].ifr_name)) != 0)
|
||||
continue;
|
||||
|
||||
if (ifr[i].ifr_addr.sa_family == AF_INET)
|
||||
return ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr.s_addr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CreatePortIpv4(void)
|
||||
{
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if (bindip == 0xFFFFFFFF)
|
||||
bindip = GetBindIp();
|
||||
|
||||
if (bindip != 0)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = bindip;
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||
{
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int CreatePortIpv6(void)
|
||||
{
|
||||
int fd = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int CreatePortUnix(void)
|
||||
{
|
||||
int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
|
||||
struct sockaddr_un addr;
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path),
|
||||
"@dtcapi-global-%d-%d-%d", getpid(), fd, (int)time(NULL));
|
||||
socklen_t len = SUN_LEN(&addr);
|
||||
addr.sun_path[0] = 0;
|
||||
if (bind(fd, (const struct sockaddr *)&addr, len) < 0)
|
||||
{
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
struct NCUdpPortList {
|
||||
public:
|
||||
int stopped;
|
||||
int family;
|
||||
int (*newport)(void);
|
||||
pthread_mutex_t lock;
|
||||
NCUdpPort *list;
|
||||
public:
|
||||
NCUdpPort *Get(void);
|
||||
void Put(NCUdpPort *);
|
||||
public:
|
||||
~NCUdpPortList(void);
|
||||
};
|
||||
|
||||
// this destructor only called when unloading libdtc.so
|
||||
NCUdpPortList::~NCUdpPortList(void)
|
||||
{
|
||||
if (pthread_mutex_lock(&lock) == 0)
|
||||
{
|
||||
stopped = 1;
|
||||
while (list != NULL)
|
||||
{
|
||||
NCUdpPort *port = list;
|
||||
list = port->next;
|
||||
delete port;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
}
|
||||
|
||||
NCUdpPort *NCUdpPortList::Get(void)
|
||||
{
|
||||
NCUdpPort *port = NULL;
|
||||
|
||||
if (pthread_mutex_lock(&lock) == 0)
|
||||
{
|
||||
if (list != NULL)
|
||||
{
|
||||
port = list;
|
||||
list = port->next;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error("api mutex_lock error,may have fd leak");
|
||||
}
|
||||
|
||||
if (port != NULL)
|
||||
{
|
||||
if (getpid() == port->pid)
|
||||
{
|
||||
port->sn++;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete port;
|
||||
port = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (port == NULL)
|
||||
{
|
||||
int fd = newport();
|
||||
|
||||
if (fd > 0)
|
||||
{
|
||||
port = new NCUdpPort;
|
||||
port->fd = fd;
|
||||
unsigned int seed = fd + (long)port + (long) & port + (long)pthread_self() + (long)port;
|
||||
port->sn = rand_r(&seed);
|
||||
port->pid = getpid();
|
||||
port->timeout = -1;
|
||||
port->family = family;
|
||||
}
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
void NCUdpPortList::Put(NCUdpPort *port)
|
||||
{
|
||||
if (this != NULL && pthread_mutex_lock(&lock) == 0)
|
||||
{
|
||||
if(stopped) {
|
||||
// always delete port after unloading process
|
||||
port->Eat();
|
||||
} else {
|
||||
port->next = list;
|
||||
list = port;
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
port->Eat();
|
||||
}
|
||||
}
|
||||
|
||||
static NCUdpPortList ipv4List = { 0, AF_INET, CreatePortIpv4, PTHREAD_MUTEX_INITIALIZER, NULL };
|
||||
static NCUdpPortList ipv6List = { 0, AF_INET6, CreatePortIpv6, PTHREAD_MUTEX_INITIALIZER, NULL };
|
||||
static NCUdpPortList unixList = { 0, AF_UNIX, CreatePortUnix, PTHREAD_MUTEX_INITIALIZER, NULL };
|
||||
|
||||
struct NCUdpPortList *GetPortList(int family) {
|
||||
switch(family) {
|
||||
case AF_INET:
|
||||
return &ipv4List;
|
||||
case AF_INET6:
|
||||
return &ipv6List;
|
||||
case AF_UNIX:
|
||||
return &unixList;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NCUdpPort *NCUdpPort::Get(int family)
|
||||
{
|
||||
NCUdpPortList *portList = GetPortList(family);
|
||||
if(portList == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return portList->Get();
|
||||
}
|
||||
|
||||
void NCUdpPort::Put()
|
||||
{
|
||||
NCUdpPortList *portList = GetPortList(family);
|
||||
portList->Put(this);
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: udp_pool.h
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/08/2020 10:02:05 PM
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: Norton, yangshuang68@jd.com
|
||||
* Company: JD.com, Inc.
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
class NCPort
|
||||
{
|
||||
public:
|
||||
uint64_t sn;
|
||||
int fd;
|
||||
int timeout; //the timeout this socket is.
|
||||
|
||||
public:
|
||||
NCPort()
|
||||
{
|
||||
sn = 0;
|
||||
fd = -1;
|
||||
timeout = -1;
|
||||
}
|
||||
|
||||
NCPort(const NCPort &that)
|
||||
{
|
||||
sn = that.sn;
|
||||
fd = that.fd;
|
||||
timeout = that.timeout;
|
||||
}
|
||||
|
||||
~NCPort()
|
||||
{
|
||||
if (fd >= 0)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class NCUdpPortList;
|
||||
class NCUdpPort : public NCPort
|
||||
{
|
||||
public:
|
||||
int family;
|
||||
pid_t pid;
|
||||
|
||||
private:
|
||||
NCUdpPort *next;
|
||||
|
||||
private:
|
||||
NCUdpPort()
|
||||
{
|
||||
pid = -1;
|
||||
};
|
||||
~NCUdpPort(){};
|
||||
|
||||
public:
|
||||
friend class NCUdpPortList;
|
||||
static NCUdpPort *Get(int family); // get from cache
|
||||
void Put(); // put back cache
|
||||
void Eat()
|
||||
{
|
||||
delete this;
|
||||
} // eat and delete
|
||||
};
|
@ -8,29 +8,29 @@ ifeq "$(SVN_REVISION)a" "a"
|
||||
SVN_REVISION = "(unknown)"
|
||||
endif
|
||||
|
||||
VPATH = ../../common
|
||||
VPATH = ../../common ../../../../3rdlib/CA_API/
|
||||
################compile#############
|
||||
target = libdtc.a container_api.pic.o version.pic.o somain.pic.o libdtc.so libdtc.pic.a
|
||||
|
||||
# CLIENTAPI macro use for scope test only
|
||||
CFLAGS += -DCLIENTAPI
|
||||
CFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0
|
||||
CFLAGS += -pthread -I../../common -I../../stat -I../../../../3rdlib/CA_API/ $(ZINC)
|
||||
LIBS = ${Z_LIB} -ldl -lpthread $(CA_API_LIB)
|
||||
LIBS = ${Z_LIB} -ldl -lpthread $(CA_API_LIB) -L../../common -lcommon
|
||||
|
||||
filelist := dtcreq dtcsvr dtcpool dtcwrap dtcwrapp dtcqossvr \
|
||||
poller timerlist keylist table_def \
|
||||
log_client memcheck md5 value \
|
||||
section decode encode field_api \
|
||||
packet_base packet_client \
|
||||
task_base task_const sockaddr udppool compress buffer thread
|
||||
poller timer_list key_list table_def log_client mem_check \
|
||||
md5 value section decode encode field_api packet_base \
|
||||
packet_client task_base task_const net_addr udppool compress buffer thread
|
||||
#filelist := dtcreq
|
||||
|
||||
#liddtc.so: container_api.pic.o version.pic.o
|
||||
#lidttc.so: container_api.pic.o version.pic.o
|
||||
|
||||
# for auto ln -sf
|
||||
#libdtc_objs := $(patsubst %,%.o,$(filelist))
|
||||
#libdtc.so: LDFLAGS += -Wl,--version-script,dtcapi.lst -e _so_start container_api.pic.o version.pic.o somain.pic.o
|
||||
#libdtc_filename := libdtc-gcc-$(GCCVER)-r$(GIT_VERSION).so
|
||||
#libdtc_soname := libdtc.so.1
|
||||
libdtc_objs := $(patsubst %,%.o,$(filelist))
|
||||
libdtc.so: LDFLAGS += -Wl,--version-script,dtcapi.lst -e _so_start container_api.pic.o version.pic.o somain.pic.o
|
||||
libdtc_filename := libdtc-gcc-$(GCCVER)-r$(GIT_VERSION).so
|
||||
libdtc_soname := libdtc.so.1
|
||||
|
||||
###############install##############
|
||||
target_install = libdtc.a libdtc.pic.a libdtc.so dtcapi.h
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <unistd.h>
|
||||
#include <buffer_error.h>
|
||||
#include <log.h>
|
||||
#include "keylist.h"
|
||||
#include "key_list.h"
|
||||
#include <task_request.h>
|
||||
#include <container.h>
|
||||
#include <net_addr.h>
|
||||
@ -53,7 +53,7 @@ static const uint32_t kpi_sample_count[] =
|
||||
|
||||
|
||||
class DTCTask;
|
||||
class CPacket;
|
||||
class Packet;
|
||||
|
||||
class NCResult;
|
||||
class NCResultInternal;
|
||||
@ -177,10 +177,10 @@ public:
|
||||
void Close(void);
|
||||
void SetFD(int fd) { Close(); netfd = fd; UpdateTimeout(); }
|
||||
// stream, connected
|
||||
int SendPacketStream(CPacket &);
|
||||
int SendPacketStream(Packet &);
|
||||
int DecodeResultStream(NCResult &);
|
||||
// dgram, connected or connectless
|
||||
int SendPacketDgram(SocketAddress *peer, CPacket &);
|
||||
int SendPacketDgram(SocketAddress *peer, Packet &);
|
||||
int DecodeResultDgram(SocketAddress *peer, NCResult &);
|
||||
// connectless
|
||||
NCUdpPort *GetGlobalPort(void);
|
||||
@ -340,7 +340,7 @@ public:
|
||||
NCResult *Execute(const char *, int);
|
||||
NCResult *PreCheck(const DTCValue *key); // return error result, NULL==success
|
||||
int SetCompressFieldName(void);//Need compress flag for read,or set compressFlag for write
|
||||
int Encode(const DTCValue *key, CPacket *);
|
||||
int Encode(const DTCValue *key, Packet *);
|
||||
// return 1 if tdef changed...
|
||||
int SetTabDef(void);
|
||||
|
||||
|
@ -39,7 +39,7 @@ enum {
|
||||
|
||||
NCPool::NCPool(int ms, int mr)
|
||||
:
|
||||
CPollerUnit(1024+16)
|
||||
PollerUnit(1024+16)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -128,17 +128,17 @@ int NCServer::AsyncConnect(int &netfd)
|
||||
int err = -EC_NOT_INITIALIZED;
|
||||
netfd = -1;
|
||||
|
||||
if(addr.SocketFamily() != 0) {
|
||||
netfd = addr.CreateSocket();
|
||||
if(addr.socket_family() != 0) {
|
||||
netfd = addr.create_socket();
|
||||
if(netfd < 0) {
|
||||
err = -errno;
|
||||
} else if(addr.SocketFamily()==AF_UNIX && IsDgram() && BindTempUnixSocket() < 0) {
|
||||
} else if(addr.socket_family()==AF_UNIX && IsDgram() && BindTempUnixSocket() < 0) {
|
||||
err = -errno;
|
||||
close(netfd);
|
||||
netfd = -1;
|
||||
} else {
|
||||
fcntl(netfd, F_SETFL, O_RDWR|O_NONBLOCK);
|
||||
if(addr.ConnectSocket(netfd)==0)
|
||||
if(addr.connect_socket(netfd)==0)
|
||||
return 0;
|
||||
err = -errno;
|
||||
if(err!=-EINPROGRESS)
|
||||
@ -153,7 +153,7 @@ int NCServer::AsyncConnect(int &netfd)
|
||||
|
||||
NCConnection::NCConnection(NCPool *owner, NCServerInfo *si)
|
||||
:
|
||||
CPollerObject(owner),
|
||||
PollerObject(owner),
|
||||
timer(this)
|
||||
{
|
||||
serverInfo = si;
|
||||
@ -170,7 +170,7 @@ NCConnection::~NCConnection(void)
|
||||
/* remove partial result */
|
||||
DELETE(result);
|
||||
/* remove from all connection queue */
|
||||
ListDel();
|
||||
list_del();
|
||||
/* abort all associated requests */
|
||||
AbortRequests(-EC_REQUEST_ABORTED);
|
||||
serverInfo->MoreClosedConnectionAndReady();
|
||||
@ -185,9 +185,9 @@ void NCConnection::SwitchToIdle(void)
|
||||
ListMove(&serverInfo->idleList);
|
||||
serverInfo->ConnectionIdleAndReady();
|
||||
state = SS_CONNECTED;
|
||||
DisableOutput();
|
||||
EnableInput();
|
||||
timer.DisableTimer();
|
||||
disable_output();
|
||||
enable_input();
|
||||
timer.disable_timer();
|
||||
/* ApplyEvnets by caller */
|
||||
}
|
||||
|
||||
@ -195,10 +195,10 @@ void NCConnection::SwitchToIdle(void)
|
||||
void NCConnection::SwitchToConnecting(void)
|
||||
{
|
||||
state = SS_CONNECTING;
|
||||
timer.AttachTimer(serverInfo->timerList);
|
||||
timer.attach_timer(serverInfo->timerList);
|
||||
ListMove(&serverInfo->busyList);
|
||||
DisableInput();
|
||||
EnableOutput();
|
||||
enable_output();
|
||||
// no apply events, following AttachPoller will do it */
|
||||
}
|
||||
|
||||
@ -209,13 +209,13 @@ int NCConnection::Connect(void)
|
||||
if(err == 0) {
|
||||
SwitchToIdle();
|
||||
/* treat epollsize overflow as fd overflow */
|
||||
if(AttachPoller() < 0)
|
||||
if(attach_poller() < 0)
|
||||
return -EMFILE;
|
||||
/* AttachPoller will ApplyEvents automatically */
|
||||
} else if(err == -EINPROGRESS) {
|
||||
SwitchToConnecting();
|
||||
/* treat epollsize overflow as fd overflow */
|
||||
if(AttachPoller() < 0)
|
||||
if(attach_poller() < 0)
|
||||
return -EMFILE;
|
||||
/* AttachPoller will ApplyEvents automatically */
|
||||
}
|
||||
@ -231,11 +231,11 @@ void NCConnection::ProcessRequest(NCTransation *r)
|
||||
sreq->AttachConnection(this);
|
||||
|
||||
/* adjust server connection statistics */
|
||||
ListMoveTail(&serverInfo->busyList);
|
||||
list_move_tail(&serverInfo->busyList);
|
||||
serverInfo->RequestScheduled();
|
||||
|
||||
/* initial timing and flushing */
|
||||
timer.AttachTimer(serverInfo->timerList);
|
||||
timer.attach_timer(serverInfo->timerList);
|
||||
SendRequest();
|
||||
}
|
||||
|
||||
@ -269,7 +269,7 @@ void NCConnection::AbortSendSide(int err)
|
||||
// async connection, lingering
|
||||
ListMove(&serverInfo->busyList);
|
||||
state = SS_LINGER;
|
||||
timer.AttachTimer(serverInfo->timerList);
|
||||
timer.attach_timer(serverInfo->timerList);
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ void NCConnection::DoneResult(void)
|
||||
if(result)
|
||||
{
|
||||
/* searching SN */
|
||||
CListObject<NCTransation> *reqPtr = reqList.ListNext();
|
||||
ListObject<NCTransation> *reqPtr = reqList.ListNext();
|
||||
while(reqPtr != &reqList)
|
||||
{
|
||||
NCTransation *req = reqPtr->ListOwner();
|
||||
@ -309,7 +309,7 @@ void NCConnection::DoneResult(void)
|
||||
* ASYNC server always idle, no switch needed
|
||||
*/
|
||||
SwitchToIdle();
|
||||
ApplyEvents();
|
||||
apply_events();
|
||||
} else if(state == SS_LINGER) {
|
||||
/* close LINGER connection if all result done */
|
||||
if(reqList.ListEmpty())
|
||||
@ -339,28 +339,28 @@ int NCConnection::CheckHangup(void)
|
||||
void NCConnection::SendRequest(void)
|
||||
{
|
||||
int ret = sreq->Send(netfd);
|
||||
timer.DisableTimer();
|
||||
timer.disable_timer();
|
||||
switch (ret)
|
||||
{
|
||||
case SendResultMoreData:
|
||||
/* more data to send, enable EPOLLOUT and timer */
|
||||
EnableOutput();
|
||||
ApplyEvents();
|
||||
timer.AttachTimer(serverInfo->timerList);
|
||||
enable_output();
|
||||
apply_events();
|
||||
timer.attach_timer(serverInfo->timerList);
|
||||
break;
|
||||
|
||||
case SendResultDone:
|
||||
/* send OK, disable output and enable receiving */
|
||||
DisableOutput();
|
||||
EnableInput();
|
||||
disable_output();
|
||||
enable_input();
|
||||
sreq->SendOK(&reqList);
|
||||
sreq = NULL;
|
||||
serverInfo->RequestSent();
|
||||
/* fire up receiving timer */
|
||||
timer.AttachTimer(serverInfo->timerList);
|
||||
timer.attach_timer(serverInfo->timerList);
|
||||
if(IsAsync())
|
||||
{
|
||||
ListMoveTail(&serverInfo->idleList);
|
||||
list_move_tail(&serverInfo->idleList);
|
||||
serverInfo->ConnectionIdleAndReady();
|
||||
}
|
||||
#if 0
|
||||
@ -369,7 +369,7 @@ void NCConnection::SendRequest(void)
|
||||
RecvResult();
|
||||
}
|
||||
#endif
|
||||
ApplyEvents();
|
||||
apply_events();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -398,7 +398,7 @@ int NCConnection::RecvResult(void)
|
||||
ret = result->Decode(serverInfo->owner->buf, ret);
|
||||
} else
|
||||
ret = result->Decode(receiver);
|
||||
timer.DisableTimer();
|
||||
timer.disable_timer();
|
||||
switch (ret)
|
||||
{
|
||||
default:
|
||||
@ -427,7 +427,7 @@ int NCConnection::RecvResult(void)
|
||||
break;
|
||||
}
|
||||
if(sreq || !reqList.ListEmpty())
|
||||
timer.AttachTimer(serverInfo->timerList);
|
||||
timer.attach_timer(serverInfo->timerList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ void NCConnection::OutputNotify(void)
|
||||
SendRequest();
|
||||
break;
|
||||
default:
|
||||
DisableOutput();
|
||||
disable_output();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -475,7 +475,7 @@ void NCConnection::HangupNotify(void)
|
||||
delete this;
|
||||
}
|
||||
|
||||
void NCConnection::TimerNotify(void)
|
||||
void NCConnection::timer_notify(void)
|
||||
{
|
||||
if(sreq || !reqList.ListEmpty())
|
||||
{
|
||||
@ -531,7 +531,7 @@ void NCServerInfo::Init(NCServer *server, int maxReq, int maxConn)
|
||||
owner = server->ownerPool;
|
||||
int to = server->GetTimeout();
|
||||
if(to <= 0) to = 3600 * 1000; // 1 hour
|
||||
timerList = owner->GetTimerListByMSeconds( to );
|
||||
timerList = owner->get_timer_list_by_m_seconds( to );
|
||||
|
||||
mode = server->IsDgram() ? 2 : maxReq==maxConn ? 0 : 1;
|
||||
}
|
||||
@ -563,7 +563,7 @@ void NCServerInfo::AbortWaitQueue(int err)
|
||||
}
|
||||
}
|
||||
|
||||
void NCServerInfo::TimerNotify()
|
||||
void NCServerInfo::timer_notify()
|
||||
{
|
||||
while(reqRemain>0 && !reqList.ListEmpty())
|
||||
{
|
||||
@ -592,7 +592,7 @@ void NCServerInfo::TimerNotify()
|
||||
}
|
||||
}
|
||||
/* no more work, clear bogus ready timer */
|
||||
CTimerObject::DisableTimer();
|
||||
TimerObject::disable_timer();
|
||||
/* reset connect error count */
|
||||
connError = 0;
|
||||
}
|
||||
@ -629,7 +629,7 @@ NCTransation::~NCTransation(void)
|
||||
void NCTransation::Clear(void)
|
||||
{
|
||||
// detach from list, mostly freeList
|
||||
CListObject<NCTransation>::ResetList();
|
||||
ListObject<NCTransation>::ResetList();
|
||||
|
||||
// increase reqId
|
||||
genId++;
|
||||
@ -656,7 +656,7 @@ int NCTransation::AttachRequest(NCServerInfo *info, long long tag, NCRequest *re
|
||||
state = RS_WAIT;
|
||||
reqTag = tag;
|
||||
server = info;
|
||||
packet = new CPacket;
|
||||
packet = new Packet;
|
||||
int ret = req->Encode(key, packet);
|
||||
if(ret < 0) {
|
||||
/* encode error */
|
||||
@ -672,12 +672,12 @@ extern inline void NCTransation::AttachConnection(NCConnection *c) {
|
||||
conn = c;
|
||||
}
|
||||
|
||||
extern inline void NCTransation::SendOK(CListObject<NCTransation> *queue) {
|
||||
extern inline void NCTransation::SendOK(ListObject<NCTransation> *queue) {
|
||||
state = RS_RECV;
|
||||
ListAddTail(queue);
|
||||
}
|
||||
|
||||
extern inline void NCTransation::RecvOK(CListObject<NCTransation> *queue) {
|
||||
extern inline void NCTransation::RecvOK(ListObject<NCTransation> *queue) {
|
||||
state = RS_DONE;
|
||||
ListAddTail(queue);
|
||||
}
|
||||
@ -694,7 +694,7 @@ void NCTransation::Abort(int err)
|
||||
conn = NULL;
|
||||
|
||||
NCPool *owner = server->owner;
|
||||
ListDel();
|
||||
list_del();
|
||||
|
||||
server->RequestDoneAndReady(state);
|
||||
server = NULL;
|
||||
@ -776,11 +776,11 @@ int NCPool::AddRequest(NCRequest *req, long long tag, DTCValue *key)
|
||||
|
||||
void NCPool::ExecuteOneLoop(int timeout)
|
||||
{
|
||||
WaitPollerEvents(timeout);
|
||||
wait_poller_events(timeout);
|
||||
uint64_t now = GET_TIMESTAMP();
|
||||
ProcessPollerEvents();
|
||||
CheckExpired(now);
|
||||
CheckReady();
|
||||
process_poller_events();
|
||||
check_expired(now);
|
||||
check_ready();
|
||||
}
|
||||
|
||||
int NCPool::Execute(int timeout)
|
||||
@ -802,7 +802,7 @@ int NCPool::Execute(int timeout)
|
||||
#else
|
||||
msec = exp * 1000/TIMESTAMP_PRECISION;
|
||||
#endif
|
||||
ExecuteOneLoop(ExpireMicroSeconds(msec, 1));
|
||||
ExecuteOneLoop(expire_micro_seconds(msec, 1));
|
||||
}
|
||||
return doneRequests;
|
||||
}
|
||||
@ -826,7 +826,7 @@ int NCPool::ExecuteAll(int timeout)
|
||||
#else
|
||||
msec = exp * 1000/TIMESTAMP_PRECISION;
|
||||
#endif
|
||||
ExecuteOneLoop(ExpireMicroSeconds(msec, 1));
|
||||
ExecuteOneLoop(expire_micro_seconds(msec, 1));
|
||||
}
|
||||
return doneRequests;
|
||||
}
|
||||
@ -835,17 +835,17 @@ int NCPool::InitializePollerUnit(void)
|
||||
{
|
||||
if(initFlag==-1)
|
||||
{
|
||||
initFlag = CPollerUnit::InitializePollerUnit() >= 0;
|
||||
initFlag = PollerUnit::initialize_poller_unit() >= 0;
|
||||
}
|
||||
return initFlag;
|
||||
}
|
||||
|
||||
int NCPool::GetEpollFD(int mp)
|
||||
{
|
||||
if(initFlag == -1 && mp > CPollerUnit::GetMaxPollers())
|
||||
CPollerUnit::SetMaxPollers(mp);
|
||||
if(initFlag == -1 && mp > PollerUnit::get_max_pollers())
|
||||
PollerUnit::set_max_pollers(mp);
|
||||
InitializePollerUnit();
|
||||
return CPollerUnit::GetFD();
|
||||
return PollerUnit::get_fd();
|
||||
}
|
||||
|
||||
NCTransation * NCPool::Id2Req(int reqId) const
|
||||
|
@ -5,9 +5,9 @@
|
||||
|
||||
#include "list.h"
|
||||
#include "poller.h"
|
||||
#include "timerlist.h"
|
||||
#include "timer_list.h"
|
||||
#include "dtcint.h"
|
||||
#include "cache_error.h"
|
||||
#include "buffer_error.h"
|
||||
|
||||
class NCServerInfo;
|
||||
class NCPool;
|
||||
@ -15,7 +15,7 @@ class NCConnection;
|
||||
|
||||
// transation is a internal async request
|
||||
class NCTransation :
|
||||
public CListObject<NCTransation>
|
||||
public ListObject<NCTransation>
|
||||
{
|
||||
public:
|
||||
// constructor/destructor equiv
|
||||
@ -35,13 +35,13 @@ public:
|
||||
/* state & info management */
|
||||
int State(void) const { return state; }
|
||||
int GenId(void) const { return genId; }
|
||||
int MatchSN(NCResult *res) const { return SN == res->versionInfo.SerialNr(); }
|
||||
int MatchSN(NCResult *res) const { return SN == res->versionInfo.serial_nr(); }
|
||||
/* send packet management */
|
||||
int Send(int fd) { return packet->Send(fd); }
|
||||
int AttachRequest(NCServerInfo *s, long long tag, NCRequest *req, DTCValue *key);
|
||||
void AttachConnection(NCConnection *c);
|
||||
void SendOK(CListObject<NCTransation>*);
|
||||
void RecvOK(CListObject<NCTransation>*);
|
||||
void SendOK(ListObject<NCTransation>*);
|
||||
void RecvOK(ListObject<NCTransation>*);
|
||||
|
||||
public: // constant member declare as static
|
||||
// owner info, associated server
|
||||
@ -60,15 +60,15 @@ private:// transient members is private
|
||||
uint64_t SN;
|
||||
|
||||
// sending packet
|
||||
CPacket *packet;
|
||||
Packet *packet;
|
||||
|
||||
// execute result
|
||||
NCResult *result;
|
||||
};
|
||||
|
||||
class NCConnection :
|
||||
public CListObject<NCConnection>,
|
||||
public CPollerObject
|
||||
public ListObject<NCConnection>,
|
||||
public PollerObject
|
||||
{
|
||||
public:
|
||||
NCConnection(NCPool *, NCServerInfo *);
|
||||
@ -103,13 +103,13 @@ public:
|
||||
virtual void InputNotify(void);
|
||||
virtual void OutputNotify(void);
|
||||
virtual void HangupNotify(void);
|
||||
virtual void TimerNotify(void);
|
||||
virtual void timer_notify(void);
|
||||
|
||||
private:
|
||||
/* associated server */
|
||||
NCServerInfo *serverInfo;
|
||||
/* queued transation in RECV state */
|
||||
CListObject<NCTransation> reqList;
|
||||
ListObject<NCTransation> reqList;
|
||||
/* sending transation */
|
||||
NCTransation *sreq;
|
||||
/* decoding/decoded result */
|
||||
@ -120,15 +120,15 @@ private:
|
||||
int NETFD(void) const { return netfd; }
|
||||
|
||||
private:
|
||||
CTimerMember<NCConnection> timer;
|
||||
CSimpleReceiver receiver;
|
||||
TimerMember<NCConnection> timer;
|
||||
SimpleReceiver receiver;
|
||||
};
|
||||
|
||||
typedef CListObject<NCConnection> NCConnectionList;
|
||||
typedef ListObject<NCConnection> NCConnectionList;
|
||||
|
||||
class NCPool :
|
||||
public CPollerUnit,
|
||||
public CTimerUnit
|
||||
public PollerUnit,
|
||||
public TimerUnit
|
||||
{
|
||||
public:
|
||||
NCPool(int maxServers, int maxRequests);
|
||||
@ -172,8 +172,8 @@ private:
|
||||
int numRequests;
|
||||
int maxRequestId;
|
||||
int doneRequests;
|
||||
CListObject<NCTransation> freeList;
|
||||
CListObject<NCTransation> doneList;
|
||||
ListObject<NCTransation> freeList;
|
||||
ListObject<NCTransation> doneList;
|
||||
NCServerInfo *serverList;
|
||||
NCTransation *transList;
|
||||
public:
|
||||
@ -181,7 +181,7 @@ public:
|
||||
};
|
||||
|
||||
class NCServerInfo :
|
||||
private CTimerObject
|
||||
private TimerObject
|
||||
{
|
||||
public:
|
||||
NCServerInfo(void);
|
||||
@ -189,8 +189,8 @@ public:
|
||||
void Init(NCServer *, int, int);
|
||||
|
||||
/* prepare wake TimerNotify */
|
||||
void MarkAsReady() { AttachReadyTimer(owner); }
|
||||
virtual void TimerNotify(void);
|
||||
void MarkAsReady() { attach_ready_timer(owner); }
|
||||
virtual void timer_notify(void);
|
||||
/* four reason server has more work to do */
|
||||
/* more transation attached */
|
||||
void MoreRequestAndReady(void) { reqWait++; MarkAsReady(); }
|
||||
@ -224,21 +224,21 @@ public:
|
||||
NCTransation * GetRequestFromQueue(void)
|
||||
{
|
||||
NCTransation *trans = reqList.NextOwner();
|
||||
trans->ListDel();
|
||||
trans->list_del();
|
||||
reqWait--;
|
||||
return trans;
|
||||
}
|
||||
|
||||
private:
|
||||
int Connect(void);
|
||||
CListObject<NCTransation> reqList;
|
||||
ListObject<NCTransation> reqList;
|
||||
|
||||
public: // constant member declare as public
|
||||
/* associated ServerPool */
|
||||
NCPool *owner;
|
||||
/* basic server info */
|
||||
NCServer *info;
|
||||
CTimerList *timerList;
|
||||
TimerList *timerList;
|
||||
int mode; // 0--TCP 1--ASYNC 2--UDP
|
||||
/* total connection */
|
||||
int connTotal;
|
||||
|
@ -57,7 +57,7 @@ NCRequest::NCRequest(NCServer *s, int op)
|
||||
case DRequest::Monitor:
|
||||
break;
|
||||
default:
|
||||
op = DRequest::ResultCode;
|
||||
op = DRequest::result_code;
|
||||
}
|
||||
cmd = op;
|
||||
err = 0;
|
||||
@ -123,7 +123,7 @@ int NCRequest::AttachServer(NCServer *s)
|
||||
// no current tabledef
|
||||
} else if(tdef == server->tdef) {
|
||||
// same tabledef
|
||||
} else if(tdef->IsSameTable(server->tdef)) {
|
||||
} else if(tdef->is_same_table(server->tdef)) {
|
||||
// hash equal
|
||||
} else {
|
||||
// force re-resolve fieldnames
|
||||
@ -152,7 +152,7 @@ int NCRequest::Need(const char *n, int vid)
|
||||
return_err(-EC_NOT_INITIALIZED);
|
||||
if(cmd!=DRequest::Get && cmd!=DRequest::SvrAdmin)
|
||||
return_err(-EC_BAD_OPERATOR);
|
||||
int ret = fs.AddField(n, vid);
|
||||
int ret = fs.add_field(n, vid);
|
||||
if(ret) err = ret;
|
||||
return ret;
|
||||
}
|
||||
@ -177,7 +177,7 @@ int NCRequest::AddCondition(const char *n, uint8_t op, uint8_t t, const DTCValue
|
||||
default:
|
||||
return_err(-EC_BAD_FIELD_TYPE);
|
||||
}
|
||||
int ret = ci.AddValue(n, op, t, v);
|
||||
int ret = ci.add_value(n, op, t, v);
|
||||
if(ret) err = ret;
|
||||
return ret;
|
||||
}
|
||||
@ -219,7 +219,7 @@ int NCRequest::AddOperation(const char *n, uint8_t op, uint8_t t, const DTCValue
|
||||
default:
|
||||
return_err(-EC_BAD_FIELD_TYPE);
|
||||
}
|
||||
int ret = ui.AddValue(n, op, t, v);
|
||||
int ret = ui.add_value(n, op, t, v);
|
||||
if(ret) err = ret;
|
||||
return ret;
|
||||
}
|
||||
@ -244,9 +244,9 @@ int NCRequest::initCompress()
|
||||
return -EC_CHECKSUM_MISMATCH;
|
||||
if (server->GetCompressLevel())
|
||||
{
|
||||
gzip->SetCompressLevel(server->GetCompressLevel());
|
||||
gzip->set_compress_level(server->GetCompressLevel());
|
||||
}
|
||||
return gzip->SetBufferLen(tdef->MaxFieldSize());
|
||||
return gzip->set_buffer_len(tdef->max_field_size());
|
||||
}
|
||||
|
||||
int NCRequest::CompressSet(const char *n,const char * v,int len)
|
||||
@ -275,19 +275,19 @@ int NCRequest::CompressSet(const char *n,const char * v,int len)
|
||||
iret = initCompress();
|
||||
if (iret) return iret;
|
||||
}
|
||||
if (tdef->CompressFieldId() <= 0)
|
||||
if (tdef->compress_field_id() <= 0)
|
||||
{
|
||||
snprintf(_errmsg, sizeof(_errmsg), "compress error:DTC must add a field for compress(FieldType=2,FieldSize=8,DefaultValue=compressflag)");
|
||||
return -EC_COMPRESS_ERROR;
|
||||
}
|
||||
|
||||
if (tdef->FieldType(tdef->FieldId(n)) != DField::Binary)
|
||||
if (tdef->field_type(tdef->field_id(n)) != DField::Binary)
|
||||
{
|
||||
snprintf(_errmsg, sizeof(_errmsg), "compress error:compress just support binary field");
|
||||
return - EC_BAD_VALUE_TYPE;
|
||||
}
|
||||
|
||||
iret = gzip->Compress(v,len);
|
||||
iret = gzip->compress(v,len);
|
||||
if (iret)
|
||||
{
|
||||
if (iret==-111111)
|
||||
@ -299,7 +299,7 @@ int NCRequest::CompressSet(const char *n,const char * v,int len)
|
||||
iret = setCompressFlag(n);
|
||||
if (iret) return iret;
|
||||
|
||||
return AddOperation(n,DField::Set,DField::String,DTCValue::Make(gzip->GetBuf(),gzip->GetLen()));
|
||||
return AddOperation(n,DField::Set,DField::String,DTCValue::Make(gzip->get_buf(),gzip->get_len()));
|
||||
}
|
||||
|
||||
int NCRequest::CompressSetForce(const char *n,const char * v,int len)
|
||||
@ -329,13 +329,13 @@ int NCRequest::CompressSetForce(const char *n,const char * v,int len)
|
||||
if (iret) return iret;
|
||||
}
|
||||
|
||||
if (tdef->FieldType(tdef->FieldId(n)) != DField::Binary)
|
||||
if (tdef->field_type(tdef->field_id(n)) != DField::Binary)
|
||||
{
|
||||
snprintf(_errmsg, sizeof(_errmsg), "compress error:compress just support binary field");
|
||||
return - EC_BAD_VALUE_TYPE;
|
||||
}
|
||||
|
||||
iret = gzip->Compress(v,len);
|
||||
iret = gzip->compress(v,len);
|
||||
if (iret)
|
||||
{
|
||||
if (iret==-111111)
|
||||
@ -346,14 +346,14 @@ int NCRequest::CompressSetForce(const char *n,const char * v,int len)
|
||||
}
|
||||
if (iret) return iret;
|
||||
|
||||
return AddOperation(n,DField::Set,DField::String,DTCValue::Make(gzip->GetBuf(),gzip->GetLen()));
|
||||
return AddOperation(n,DField::Set,DField::String,DTCValue::Make(gzip->get_buf(),gzip->get_len()));
|
||||
}
|
||||
|
||||
int NCRequest::AddValue(const char *n, uint8_t t, const DTCValue &v)
|
||||
{
|
||||
if(server==NULL) return_err(-EC_NOT_INITIALIZED);
|
||||
if(cmd!=DRequest::Insert && cmd!=DRequest::Replace) return_err(-EC_BAD_COMMAND);
|
||||
int ret = ui.AddValue(n, DField::Set, t, v);
|
||||
int ret = ui.add_value(n, DField::Set, t, v);
|
||||
if(ret) err = ret;
|
||||
return ret;
|
||||
}
|
||||
@ -453,11 +453,11 @@ int NCRequest::SetTabDef(void)
|
||||
|
||||
int NCRequest::CheckKey(const DTCValue *kptr)
|
||||
{
|
||||
int keyType = tdef->KeyType();
|
||||
int keySize = tdef->KeySize();
|
||||
int keyType = tdef->key_type();
|
||||
int keySize = tdef->key_size();
|
||||
if(kptr){//多key查询时 kptr为空
|
||||
if(keyType == 1 || keyType == 2){
|
||||
return CheckIntValue( *kptr, keyType, keySize);
|
||||
return check_int_value( *kptr, keyType, keySize);
|
||||
}else if(keyType == 4 || keyType == 5){
|
||||
if(keySize < kptr->str.len)
|
||||
return -EC_BAD_FIELD_SIZE_ON_CHECKKEY;
|
||||
@ -468,7 +468,7 @@ int NCRequest::CheckKey(const DTCValue *kptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NCRequest::Encode(const DTCValue *kptr, CPacket *pkt)
|
||||
int NCRequest::Encode(const DTCValue *kptr, Packet *pkt)
|
||||
{
|
||||
int err;
|
||||
int force = SetTabDef();
|
||||
@ -482,7 +482,7 @@ int NCRequest::Encode(const DTCValue *kptr, CPacket *pkt)
|
||||
return err;
|
||||
}
|
||||
|
||||
if((err = pkt->EncodeRequest(*this, kptr)) != 0) {
|
||||
if((err = pkt->encode_request(*this, kptr)) != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
@ -500,7 +500,7 @@ NCResult *NCRequest::ExecuteStream(const DTCValue *kptr)
|
||||
|
||||
if(resend)
|
||||
{
|
||||
CPacket pk;
|
||||
Packet pk;
|
||||
|
||||
if((err=Encode(kptr, &pk)) < 0)
|
||||
{
|
||||
@ -532,7 +532,7 @@ NCResult *NCRequest::ExecuteStream(const DTCValue *kptr)
|
||||
}
|
||||
|
||||
NCResult *res = new NCResult(tdef);
|
||||
res->versionInfo.SetSerialNr(server->LastSerialNr());
|
||||
res->versionInfo.set_serial_nr(server->LastSerialNr());
|
||||
|
||||
err = server->DecodeResultStream(*res);
|
||||
|
||||
@ -549,14 +549,14 @@ NCResult *NCRequest::ExecuteStream(const DTCValue *kptr)
|
||||
}
|
||||
nrecv++;
|
||||
|
||||
if (res->versionInfo.SerialNr() != server->LastSerialNr())
|
||||
if (res->versionInfo.serial_nr() != server->LastSerialNr())
|
||||
{
|
||||
log_debug("SN different, receive again. my SN: %lu, result SN: %lu",
|
||||
(unsigned long)server->LastSerialNr(),
|
||||
(unsigned long)res->versionInfo.SerialNr());
|
||||
(unsigned long)res->versionInfo.serial_nr());
|
||||
// receive again
|
||||
resend = 0;
|
||||
} else if (res->ResultCode() == -EC_CHECKSUM_MISMATCH && nrecv <= 1)
|
||||
} else if (res->result_code() == -EC_CHECKSUM_MISMATCH && nrecv <= 1)
|
||||
{
|
||||
resend = 1;
|
||||
// tabledef changed, resend
|
||||
@ -568,17 +568,17 @@ NCResult *NCRequest::ExecuteStream(const DTCValue *kptr)
|
||||
else
|
||||
{
|
||||
// got valid result
|
||||
if (res->ResultCode() >= 0 && cmd == DRequest::Get)
|
||||
if (res->result_code() >= 0 && cmd == DRequest::Get)
|
||||
res->SetVirtualMap(fs);
|
||||
|
||||
if(0 != server->GetRemoveCount())
|
||||
server->ClearRemoveCount();
|
||||
|
||||
uint64_t time = 0;
|
||||
if(res->resultInfo.TagPresent(7)){
|
||||
char *t = res->resultInfo.TimeInfo();
|
||||
if(res->resultInfo.tag_present(7)){
|
||||
char *t = res->resultInfo.time_info();
|
||||
if(t){
|
||||
CTimeInfo *t_info = (CTimeInfo *)t;
|
||||
DTCTimeInfo *t_info = (DTCTimeInfo *)t;
|
||||
time = (t_info->time)>0 ? (t_info->time):0;
|
||||
server->SetAgentTime(time);
|
||||
}
|
||||
@ -607,7 +607,7 @@ NCResult *NCRequest::ExecuteDgram(SocketAddress *peer, const DTCValue *kptr)
|
||||
int err;
|
||||
|
||||
if (resend) {
|
||||
CPacket pk;
|
||||
Packet pk;
|
||||
|
||||
if ((err = Encode(kptr, &pk)) < 0)
|
||||
{
|
||||
@ -635,7 +635,7 @@ NCResult *NCRequest::ExecuteDgram(SocketAddress *peer, const DTCValue *kptr)
|
||||
}
|
||||
|
||||
NCResult *res = new NCResult(tdef);
|
||||
res->versionInfo.SetSerialNr(server->LastSerialNr());
|
||||
res->versionInfo.set_serial_nr(server->LastSerialNr());
|
||||
err = server->DecodeResultDgram(peer, *res);
|
||||
if(err < 0) {
|
||||
// network error encountered
|
||||
@ -643,25 +643,25 @@ NCResult *NCRequest::ExecuteDgram(SocketAddress *peer, const DTCValue *kptr)
|
||||
}
|
||||
nrecv++;
|
||||
|
||||
if (res->versionInfo.SerialNr() != server->LastSerialNr()) {
|
||||
if (res->versionInfo.serial_nr() != server->LastSerialNr()) {
|
||||
log_debug("SN different, receive again. my SN: %lu, result SN: %lu",
|
||||
(unsigned long)server->LastSerialNr(),
|
||||
(unsigned long)res->versionInfo.SerialNr());
|
||||
(unsigned long)res->versionInfo.serial_nr());
|
||||
// receive again
|
||||
resend = 0;
|
||||
} else if (res->ResultCode() == -EC_CHECKSUM_MISMATCH && nrecv <= 1) {
|
||||
} else if (res->result_code() == -EC_CHECKSUM_MISMATCH && nrecv <= 1) {
|
||||
resend = 1;
|
||||
// tabledef changed, resend
|
||||
} else {
|
||||
// got valid result
|
||||
if (res->ResultCode() >= 0 && cmd == DRequest::Get)
|
||||
if (res->result_code() >= 0 && cmd == DRequest::Get)
|
||||
res->SetVirtualMap(fs);
|
||||
|
||||
uint64_t time = 0;
|
||||
if(res->resultInfo.TagPresent(7)){
|
||||
char *t = res->resultInfo.TimeInfo();
|
||||
if(res->resultInfo.tag_present(7)){
|
||||
char *t = res->resultInfo.time_info();
|
||||
if(t){
|
||||
CTimeInfo *t_info = (CTimeInfo *)t;
|
||||
DTCTimeInfo *t_info = (DTCTimeInfo *)t;
|
||||
time = (t_info->time)>0 ? (t_info->time):0;
|
||||
server->SetAgentTime(time);
|
||||
}
|
||||
@ -734,7 +734,7 @@ NCResult *NCRequest::ExecuteInternal(const DTCValue *kptr)
|
||||
return_err_res(err, "API::sending", "internal client api execute error");
|
||||
}
|
||||
|
||||
if(res->ResultCode() >= 0 && cmd==DRequest::Get)
|
||||
if(res->result_code() >= 0 && cmd==DRequest::Get)
|
||||
res->SetVirtualMap(fs);
|
||||
|
||||
return reinterpret_cast<NCResult *>(res);
|
||||
@ -752,7 +752,7 @@ NCResult *NCRequest::PreCheck(const DTCValue *kptr) {
|
||||
return_err_res(err, "API::encoding", "Init Operation Error");
|
||||
if(server==NULL)
|
||||
return_err_res(-EC_NOT_INITIALIZED, "API::encoding", "Server Not Initialized");
|
||||
if(cmd==DRequest::ResultCode)
|
||||
if(cmd==DRequest::result_code)
|
||||
return_err_res(-EC_BAD_COMMAND, "API::encoding", "Unknown Request Type");
|
||||
if(server->badkey)
|
||||
return_err_res(-EC_BAD_KEY_TYPE, "API::encoding", "Key Type Mismatch");
|
||||
@ -800,13 +800,13 @@ NCResult *NCRequest::PreCheck(const DTCValue *kptr) {
|
||||
int NCRequest::SetCompressFieldName()
|
||||
{
|
||||
int iret = 0;
|
||||
if (tdef && tdef->CompressFieldId()>0)//启用压缩必定有这个字段
|
||||
if (tdef && tdef->compress_field_id()>0)//启用压缩必定有这个字段
|
||||
{
|
||||
if (gzip==NULL)//读请求需要need字段
|
||||
{
|
||||
if (cmd != DRequest::Get)
|
||||
return 0;
|
||||
iret = Need(tdef->FieldName(tdef->CompressFieldId()),0);
|
||||
iret = Need(tdef->field_name(tdef->compress_field_id()),0);
|
||||
if (iret)
|
||||
{
|
||||
snprintf(_errmsg, sizeof(_errmsg), "need CompressField error,errorcode is %d",iret);
|
||||
@ -817,12 +817,12 @@ int NCRequest::SetCompressFieldName()
|
||||
{
|
||||
if (cmd == DRequest::Insert||cmd == DRequest::Replace)
|
||||
{
|
||||
iret = AddOperation(tdef->FieldName(tdef->CompressFieldId()),//name
|
||||
iret = AddOperation(tdef->field_name(tdef->compress_field_id()),//name
|
||||
DField::Set,DField::Signed,DTCValue::Make(compressFlag));
|
||||
}
|
||||
else if (cmd == DRequest::Update)
|
||||
{
|
||||
iret = AddOperation(tdef->FieldName(tdef->CompressFieldId()),//name
|
||||
iret = AddOperation(tdef->field_name(tdef->compress_field_id()),//name
|
||||
DField::OR,DField::Signed,DTCValue::Make(compressFlag));
|
||||
}
|
||||
else
|
||||
@ -864,18 +864,14 @@ NCResult *NCRequest::Execute(const DTCValue *kptr) {
|
||||
|
||||
std::string accessKey = server->accessToken;
|
||||
|
||||
if(ret != NULL && ret->resultInfo.ResultCode() == -ETIMEDOUT){
|
||||
//server->dc->SetReportInfo(accessKey, CLIENT_CURVE, server->GetTimeout());
|
||||
if(ret != NULL && ret->resultInfo.result_code() == -ETIMEDOUT){
|
||||
server->dc->SetReportInfo(accessKey, AGENT_CURVE, server->GetTimeout());
|
||||
}else{
|
||||
//server->dc->SetReportInfo(accessKey, CLIENT_CURVE, timeInterval);
|
||||
server->dc->SetReportInfo(accessKey, AGENT_CURVE, (server->GetAgentTime() != 0)?server->GetAgentTime():timeInterval);
|
||||
}
|
||||
server->dc->SetReportInfo(accessKey, CLIENT_CURVE, timeInterval);
|
||||
|
||||
//top_percentile_report(accessKey, server->GetAddress(), timeInterval, ret ? ret->resultInfo.ResultCode() : 1, RT_SHARDING);
|
||||
//top_percentile_report(accessKey, "", timeInterval, ret ? ret->resultInfo.ResultCode() : 1, RT_ALL);
|
||||
server->dc->SetTopPercentileData(accessKey, server->GetAddress(), timeInterval, ret ? ret->resultInfo.ResultCode() : 1);
|
||||
server->dc->SetTopPercentileData(accessKey, server->GetAddress(), timeInterval, ret ? ret->resultInfo.result_code() : 1);
|
||||
|
||||
std::string stemp = accessKey.substr(0, 8);
|
||||
uint32_t bid = 0;
|
||||
@ -919,7 +915,7 @@ int NCRequest::EncodeBuffer(char *&ptr, int &len, int64_t &magic, const DTCValue
|
||||
NCResult *ret = PreCheck(kptr);
|
||||
if(ret!=NULL)
|
||||
{
|
||||
err = ret->ResultCode();
|
||||
err = ret->result_code();
|
||||
delete ret;
|
||||
return err;
|
||||
}
|
||||
@ -934,7 +930,7 @@ int NCRequest::EncodeBuffer(char *&ptr, int &len, int64_t &magic, const DTCValue
|
||||
return err;
|
||||
}
|
||||
|
||||
if((err = CPacket::EncodeSimpleRequest(*this, kptr, ptr, len)) != 0) {
|
||||
if((err = Packet::encode_simple_request(*this, kptr, ptr, len)) != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1001,9 +997,9 @@ int NCRequest::SetExpireTime(const char* key, int t){
|
||||
ret = AddOperation("_dtc_sys_expiretime", DField::Set, DField::Signed, DTCValue::Make(t));
|
||||
if(ret != 0) return ret;
|
||||
NCResult * rst = Execute(); //rst 不会为空
|
||||
ret = rst->ResultCode();
|
||||
ret = rst->result_code();
|
||||
if(ret != 0){
|
||||
log_error("set expireTime fail, errmsg:%s, errfrom:%s", rst->resultInfo.ErrorMessage(), rst->resultInfo.ErrorFrom());
|
||||
log_error("set expireTime fail, errmsg:%s, errfrom:%s", rst->resultInfo.error_message(), rst->resultInfo.error_from());
|
||||
}
|
||||
delete rst;
|
||||
rst = NULL;
|
||||
@ -1049,9 +1045,9 @@ int NCRequest::GetExpireTime(const char* key){
|
||||
return ret;
|
||||
}
|
||||
NCResult * rst = Execute(); //rst 不会为空
|
||||
ret = rst->ResultCode();
|
||||
ret = rst->result_code();
|
||||
if(ret < 0){
|
||||
log_error("get expireTime fail, errmsg:%s, errfrom:%s", rst->resultInfo.ErrorMessage(), rst->resultInfo.ErrorFrom());
|
||||
log_error("get expireTime fail, errmsg:%s, errfrom:%s", rst->resultInfo.error_message(), rst->resultInfo.error_from());
|
||||
delete rst;
|
||||
rst = NULL;
|
||||
return ret;
|
||||
@ -1063,30 +1059,30 @@ int NCRequest::GetExpireTime(const char* key){
|
||||
rst = NULL;
|
||||
return -EC_GET_EXPIRETIME_RESULT_NULL;
|
||||
}
|
||||
if(rst->result->TotalRows() <= 0){
|
||||
if(rst->result->total_rows() <= 0){
|
||||
log_error("get expireTime fail, no data exist in dtc for key:%s", key);
|
||||
delete rst;
|
||||
rst = NULL;
|
||||
return -EC_GET_EXPIRETIME_END_OF_RESULT;
|
||||
}
|
||||
ret = rst->result->DecodeRow();
|
||||
ret = rst->result->decode_row();
|
||||
if(ret < 0){
|
||||
log_error("get expireTime fail, fetch_row error, errmsg:%s, errfrom:%s", rst->resultInfo.ErrorMessage(), rst->resultInfo.ErrorFrom());
|
||||
log_error("get expireTime fail, fetch_row error, errmsg:%s, errfrom:%s", rst->resultInfo.error_message(), rst->resultInfo.error_from());
|
||||
delete rst;
|
||||
rst = NULL;
|
||||
return ret;
|
||||
}
|
||||
int expiretime = 0;
|
||||
int id = rst->FieldId("_dtc_sys_expiretime");
|
||||
int id = rst->field_id("_dtc_sys_expiretime");
|
||||
if(id >= 0) {
|
||||
const DTCValue *v;
|
||||
if(id==0 && !(rst->result->FieldPresent(0)))
|
||||
v = rst->ResultKey();
|
||||
if(id==0 && !(rst->result->field_present(0)))
|
||||
v = rst->result_key();
|
||||
else
|
||||
v = rst->result->FieldValue(id);
|
||||
v = rst->result->field_value(id);
|
||||
|
||||
if(v) {
|
||||
switch(rst->FieldType(id)) {
|
||||
switch(rst->field_type(id)) {
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
{
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "dtcint.h"
|
||||
#include <timestamp.h>
|
||||
#include <container.h>
|
||||
#include "curl_http.h"
|
||||
#include "json/json.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -178,7 +176,7 @@ int NCServer::SetAddress(const char *h, const char *p) {
|
||||
oldhost = strdupa(addr.Name());
|
||||
}
|
||||
|
||||
const char *err = addr.SetAddress(h, p);
|
||||
const char *err = addr.set_address(h, p);
|
||||
if(err) {
|
||||
this->errstr = err;
|
||||
return -EC_BAD_HOST_STRING;
|
||||
@ -192,14 +190,14 @@ int NCServer::SetAddress(const char *h, const char *p) {
|
||||
|
||||
//set network model
|
||||
executor = NULL;
|
||||
if(!_network_mode&&iservice && iservice->MatchListeningPorts(addr.Name(), NULL)) {
|
||||
executor = iservice->QueryTaskExecutor();
|
||||
DTCTableDefinition *t1 = iservice->QueryTableDefinition();
|
||||
if(!_network_mode&&iservice && iservice->match_listening_ports(addr.Name(), NULL)) {
|
||||
executor = iservice->query_task_executor();
|
||||
DTCTableDefinition *t1 = iservice->query_table_definition();
|
||||
if(t1 != this->tdef) {
|
||||
DEC_DELETE(this->tdef);
|
||||
this->tdef = t1;
|
||||
}
|
||||
DTCTableDefinition *t2 = iservice->QueryAdminTableDefinition();
|
||||
DTCTableDefinition *t2 = iservice->query_admin_table_definition();
|
||||
if(t2 != this->tdef) {
|
||||
DEC_DELETE(this->admin_tdef);
|
||||
this->admin_tdef = t2;
|
||||
@ -259,9 +257,9 @@ int NCServer::FieldType(const char *name) {
|
||||
Ping();
|
||||
|
||||
if(tdef != NULL){
|
||||
int id = tdef->FieldId(name);
|
||||
int id = tdef->field_id(name);
|
||||
if(id >= 0)
|
||||
return tdef->FieldType(id);
|
||||
return tdef->field_type(id);
|
||||
}
|
||||
|
||||
return DField::None;
|
||||
@ -345,12 +343,12 @@ int NCServer::Connect(void) {
|
||||
|
||||
int err = -EC_NOT_INITIALIZED;
|
||||
|
||||
if(addr.SocketFamily() != 0) {
|
||||
netfd = addr.CreateSocket();
|
||||
if(addr.socket_family() != 0) {
|
||||
netfd = addr.create_socket();
|
||||
if(netfd < 0) {
|
||||
log_error("create socket error: %d, %m", errno);
|
||||
err = -errno;
|
||||
} else if(addr.SocketFamily()==AF_UNIX && IsDgram() && BindTempUnixSocket() < 0) {
|
||||
} else if(addr.socket_family()==AF_UNIX && IsDgram() && BindTempUnixSocket() < 0) {
|
||||
log_error("bind unix socket error: %d, %m", errno);
|
||||
err = -errno;
|
||||
Close();
|
||||
@ -358,7 +356,7 @@ int NCServer::Connect(void) {
|
||||
int iRes = -1;
|
||||
//先将netfd设置为非阻塞模式,然后进行connect,返回0,则建立连接成功;返回其它失败
|
||||
fcntl(netfd, F_SETFL, fcntl(netfd, F_GETFL, 0) | O_NONBLOCK);
|
||||
if(addr.ConnectSocket(netfd)==0) {
|
||||
if(addr.connect_socket(netfd)==0) {
|
||||
iRes = 0;
|
||||
}
|
||||
else{
|
||||
@ -416,7 +414,7 @@ int NCServer::Reconnect(void) {
|
||||
if(netfd < 0)
|
||||
return -ENOTCONN;
|
||||
|
||||
if(addr.ConnectSocket(netfd)==0) {
|
||||
if(addr.connect_socket(netfd)==0) {
|
||||
return 0;
|
||||
}
|
||||
log_error("connect dtc server error: %d,%m", errno);
|
||||
@ -426,7 +424,7 @@ int NCServer::Reconnect(void) {
|
||||
return err;
|
||||
}
|
||||
|
||||
int NCServer::SendPacketStream(CPacket &pk) {
|
||||
int NCServer::SendPacketStream(Packet &pk) {
|
||||
int err;
|
||||
#ifndef SIOCOUTQ
|
||||
if(1) //if(!IsDgram())
|
||||
@ -479,12 +477,12 @@ int NCServer::DecodeResultStream(NCResult &tk)
|
||||
{
|
||||
if(netfd < 0)
|
||||
{
|
||||
tk.SetError(-ENOTCONN, "API::recving", "connection is closed");
|
||||
tk.set_error(-ENOTCONN, "API::recving", "connection is closed");
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
int err;
|
||||
CSimpleReceiver receiver(netfd);
|
||||
SimpleReceiver receiver(netfd);
|
||||
|
||||
uint64_t beginTime = 0;
|
||||
//log_debug("wait response time stamp = %lld", (long long)(beginTime = GET_TIMESTAMP()));
|
||||
@ -507,14 +505,14 @@ int NCServer::DecodeResultStream(NCResult &tk)
|
||||
// unsent bytes
|
||||
if(value > 0) {
|
||||
err = -EAGAIN;
|
||||
tk.SetError(err, "API::sending", "client send packet error");
|
||||
tk.set_error(err, "API::sending", "client send packet error");
|
||||
Close();
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
Close();
|
||||
// EAGAIN never return FatalError, should be DecodeWaitData
|
||||
tk.SetError(err, "API::recving", "client recv packet error");
|
||||
tk.set_error(err, "API::recving", "client recv packet error");
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -537,7 +535,7 @@ int NCServer::DecodeResultStream(NCResult &tk)
|
||||
log_debug("use time %ldms", (long)((GET_TIMESTAMP()-beginTime)/1000));
|
||||
|
||||
Close();
|
||||
tk.SetError(-ETIMEDOUT, "API::recving", "client recv packet timedout");
|
||||
tk.set_error(-ETIMEDOUT, "API::recving", "client recv packet timedout");
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
@ -547,18 +545,18 @@ int NCServer::DecodeResultStream(NCResult &tk)
|
||||
SaveDefinition(&tk);
|
||||
if(autoping) {
|
||||
time(&lastAct);
|
||||
err = tk.versionInfo.KeepAliveTimeout();
|
||||
err = tk.versionInfo.keep_alive_timeout();
|
||||
if(err<15) err = 15;
|
||||
lastAct += err - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NCServer::SendPacketDgram(SocketAddress *peer, CPacket &pk)
|
||||
int NCServer::SendPacketDgram(SocketAddress *peer, Packet &pk)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
while ((err = pk.SendTo(netfd, peer)) == SendResultMoreData)
|
||||
while ((err = pk.send_to(netfd, peer)) == SendResultMoreData)
|
||||
{
|
||||
if (errno == EINPROGRESS)
|
||||
{
|
||||
@ -663,7 +661,7 @@ int NCServer::DecodeResultDgram(SocketAddress *peer, NCResult &tk)
|
||||
{
|
||||
if(netfd < 0)
|
||||
{
|
||||
tk.SetError(-ENOTCONN, "API::recving", "connection is closed");
|
||||
tk.set_error(-ENOTCONN, "API::recving", "connection is closed");
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
@ -674,18 +672,18 @@ int NCServer::DecodeResultDgram(SocketAddress *peer, NCResult &tk)
|
||||
|
||||
log_debug("wait response time stamp = %lld", (long long)(beginTime = GET_TIMESTAMP()));
|
||||
|
||||
if(addr.SocketFamily() == AF_UNIX) {
|
||||
if(addr.socket_family() == AF_UNIX) {
|
||||
if(peer == NULL) {
|
||||
buf = RecvPacketPoll(netfd, timeout, len, saved_errno);
|
||||
} else {
|
||||
if(peer->ConnectSocket(netfd) < 0) {
|
||||
if(peer->connect_socket(netfd) < 0) {
|
||||
saved_errno = errno;
|
||||
log_error("connect dtc server error: %d,%m", saved_errno);
|
||||
if(saved_errno == EAGAIN) {
|
||||
// unix socket return EAGAIN if listen queue overflow
|
||||
saved_errno = EC_SERVER_BUSY;
|
||||
}
|
||||
tk.SetError(-saved_errno, "API::connecting", "client api connect server error");
|
||||
tk.set_error(-saved_errno, "API::connecting", "client api connect server error");
|
||||
return -saved_errno;
|
||||
}
|
||||
|
||||
@ -713,11 +711,11 @@ int NCServer::DecodeResultDgram(SocketAddress *peer, NCResult &tk)
|
||||
if(saved_errno == EAGAIN) {
|
||||
// change errcode to TIMEDOUT;
|
||||
saved_errno = ETIMEDOUT;
|
||||
tk.SetError(-ETIMEDOUT, "API::recving", "client recv packet timedout");
|
||||
tk.set_error(-ETIMEDOUT, "API::recving", "client recv packet timedout");
|
||||
} else {
|
||||
if(saved_errno==0)
|
||||
saved_errno = ECONNRESET;
|
||||
tk.SetError(-saved_errno, "API::recving", "connection reset by peer");
|
||||
tk.set_error(-saved_errno, "API::recving", "connection reset by peer");
|
||||
}
|
||||
return -saved_errno;
|
||||
}
|
||||
@ -727,7 +725,7 @@ int NCServer::DecodeResultDgram(SocketAddress *peer, NCResult &tk)
|
||||
switch(err) {
|
||||
case DecodeFatalError:
|
||||
log_error("socket[%d] decode udp data error: invalid packet content", netfd);
|
||||
tk.SetError(-ECONNRESET, "API::recving", "invalid packet content");
|
||||
tk.set_error(-ECONNRESET, "API::recving", "invalid packet content");
|
||||
FREE_IF(buf); // buf not eaten
|
||||
return -ECONNRESET;
|
||||
|
||||
@ -735,7 +733,7 @@ int NCServer::DecodeResultDgram(SocketAddress *peer, NCResult &tk)
|
||||
default:
|
||||
// UNREACHABLE, DecodePacket never return these code
|
||||
log_error("socket[%d] decode udp data error: %d, %m", netfd, errno);
|
||||
tk.SetError(-ETIMEDOUT, "API::recving", "client recv packet timedout");
|
||||
tk.set_error(-ETIMEDOUT, "API::recving", "client recv packet timedout");
|
||||
return -ETIMEDOUT;
|
||||
|
||||
case DecodeDataError:
|
||||
@ -754,7 +752,7 @@ int NCServer::DecodeResultDgram(SocketAddress *peer, NCResult &tk)
|
||||
//Get udpport form udppool
|
||||
NCUdpPort *NCServer::GetGlobalPort()
|
||||
{
|
||||
NCUdpPort *udpport = NCUdpPort::Get(addr.SocketFamily());
|
||||
NCUdpPort *udpport = NCUdpPort::Get(addr.socket_family());
|
||||
|
||||
if (udpport)
|
||||
{
|
||||
@ -789,28 +787,28 @@ void NCServer::PutGlobalPort(NCUdpPort *udpport)
|
||||
|
||||
void NCServer::SaveDefinition(NCResult *tk)
|
||||
{
|
||||
if(strcmp("*", tablename)!=0 && tk->ResultCode()==-EC_TABLE_MISMATCH) {
|
||||
if(strcmp("*", tablename)!=0 && tk->result_code()==-EC_TABLE_MISMATCH) {
|
||||
badname = 1;
|
||||
errstr = "Table Name Mismatch";
|
||||
return;
|
||||
}
|
||||
if(strcmp("*", tablename)!=0 && tk->ResultCode()==-EC_BAD_KEY_TYPE) {
|
||||
if(strcmp("*", tablename)!=0 && tk->result_code()==-EC_BAD_KEY_TYPE) {
|
||||
badkey = 1;
|
||||
errstr = "Key Type Mismatch";
|
||||
return;
|
||||
}
|
||||
|
||||
DTCTableDefinition *t = tk->RemoteTableDefinition();
|
||||
DTCTableDefinition *t = tk->remote_table_definition();
|
||||
if(t == NULL) return;
|
||||
|
||||
if(t->IsAdminTable()){
|
||||
if(t->is_admin_table()){
|
||||
if(admin_tdef)
|
||||
{
|
||||
if(admin_tdef->IsSameTable(t)) return;
|
||||
if(admin_tdef->is_same_table(t)) return;
|
||||
if(!autoUpdateTable){
|
||||
badname = 1;
|
||||
errstr = "Table Mismatch";
|
||||
tk->SetError(-EC_TABLE_MISMATCH, "API::executed", "AdminTable Mismatch");
|
||||
tk->set_error(-EC_TABLE_MISMATCH, "API::executed", "AdminTable Mismatch");
|
||||
return;
|
||||
}
|
||||
DEC_DELETE(admin_tdef);
|
||||
@ -821,11 +819,11 @@ void NCServer::SaveDefinition(NCResult *tk)
|
||||
else{
|
||||
if(tdef)
|
||||
{
|
||||
if(tdef->IsSameTable(t)) return;
|
||||
if(tdef->is_same_table(t)) return;
|
||||
if(!autoUpdateTable){
|
||||
badname = 1;
|
||||
errstr = "Table Mismatch";
|
||||
tk->SetError(-EC_TABLE_MISMATCH, "API::executed", "Table Mismatch");
|
||||
tk->set_error(-EC_TABLE_MISMATCH, "API::executed", "Table Mismatch");
|
||||
return;
|
||||
}
|
||||
DEC_DELETE(tdef);
|
||||
@ -834,8 +832,8 @@ void NCServer::SaveDefinition(NCResult *tk)
|
||||
tdef->INC();
|
||||
|
||||
FREE(tablename);
|
||||
tablename = STRDUP(tdef->TableName());
|
||||
keytype = tdef->KeyType();
|
||||
tablename = STRDUP(tdef->table_name());
|
||||
keytype = tdef->key_type();
|
||||
|
||||
//bugfix, by ada
|
||||
if(keytype == DField::Unsigned)
|
||||
@ -862,7 +860,7 @@ int NCServer::Ping(void) {
|
||||
return 0;
|
||||
NCRequest r(this, DRequest::Nop);
|
||||
NCResult *t = r.ExecuteNetwork();
|
||||
int ret = t->ResultCode();
|
||||
int ret = t->result_code();
|
||||
delete t;
|
||||
return ret;
|
||||
}
|
||||
@ -871,10 +869,10 @@ NCResult *NCServer::DecodeBuffer(const char *buf, int len)
|
||||
{
|
||||
NCResult *res = new NCResult(tdef);
|
||||
|
||||
switch(len <= (int)sizeof(CPacketHeader) ? DecodeFatalError : res->Decode(buf, len))
|
||||
switch(len <= (int)sizeof(PacketHeader) ? DecodeFatalError : res->Decode(buf, len))
|
||||
{
|
||||
default:
|
||||
res->SetError(-EINVAL, "API::decoding", "invalid packet content");
|
||||
res->set_error(-EINVAL, "API::decoding", "invalid packet content");
|
||||
break;
|
||||
case DecodeDataError:
|
||||
case DecodeDone:
|
||||
@ -885,7 +883,7 @@ NCResult *NCServer::DecodeBuffer(const char *buf, int len)
|
||||
|
||||
int NCServer::CheckPacketSize(const char *buf, int len)
|
||||
{
|
||||
return NCResult::CheckPacketSize(buf, len);
|
||||
return NCResult::check_packet_size(buf, len);
|
||||
}
|
||||
|
||||
/*date:2014/06/04, author:xuxinxin*/
|
||||
@ -965,94 +963,6 @@ DataConnector::~DataConnector()
|
||||
|
||||
int DataConnector::SendData()
|
||||
{
|
||||
int ret = 0;
|
||||
std::map<bidCurve, businessStatistics> mapData;
|
||||
GetReportInfo(mapData);
|
||||
int flag = 0;
|
||||
for(std::map<bidCurve, businessStatistics>::iterator itrflag = mapData.begin(); itrflag != mapData.end(); ++itrflag)
|
||||
{
|
||||
flag += itrflag->second.TotalTime + itrflag->second.TotalRequests;
|
||||
}
|
||||
if(flag == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int HttpServiceTimeOut = 2;
|
||||
std::string strServiceUrl = "http://report.dtc.jd.com:9090";
|
||||
std::string strRsp = "";
|
||||
CurlHttp curlHttp;
|
||||
Json::FastWriter writer;
|
||||
Json::Value statics;
|
||||
|
||||
for(std::map<bidCurve, businessStatistics>::iterator itr = mapData.begin(); itr != mapData.end(); ++itr)
|
||||
{
|
||||
log_info("bid:%d, curve:%u, TotalTime:%lu, TotalRequests:%u", itr->first.bid, itr->first.curve, itr->second.TotalTime, itr->second.TotalRequests);
|
||||
uint32_t bid = 0;
|
||||
uint32_t curve = 0;
|
||||
bid = itr->first.bid;
|
||||
curve = itr->first.curve;
|
||||
|
||||
uint64_t totalTime = itr->second.TotalTime;
|
||||
uint32_t reqNum = itr->second.TotalRequests;
|
||||
Json::Value content;
|
||||
Json::Value inner;
|
||||
Json::Value inArr;
|
||||
|
||||
Json::Value middle;
|
||||
if(0 != totalTime && 0 != reqNum)
|
||||
{
|
||||
inner["curve"] = curve;
|
||||
inner["etype"] = "1";
|
||||
inner["data1"] = static_cast<Json::UInt64>(totalTime);
|
||||
inner["data2"] = reqNum;
|
||||
inner["extra"] = "";
|
||||
inner["cmd"] = "0";
|
||||
inArr.append(inner);
|
||||
|
||||
middle["bid"] = bid;
|
||||
middle["content"] =inArr;
|
||||
|
||||
statics.append(middle);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error("empty data in bid:[%d]!curve:[%d]", bid, curve);
|
||||
}
|
||||
|
||||
}
|
||||
Json::Value body;
|
||||
body["cmd"] = 3;
|
||||
body["statics"]=statics;
|
||||
BuffV buf;
|
||||
std::string strBody = writer.write(body);
|
||||
log_info("HttpBody = [%s]", strBody.c_str());
|
||||
curlHttp.SetHttpParams("%s", strBody.c_str());
|
||||
curlHttp.SetTimeout(HttpServiceTimeOut);
|
||||
ret = curlHttp.HttpRequest(strServiceUrl, &buf, false);
|
||||
if(ret != 0){
|
||||
log_error("report http error! curlHttp.HttpRequest error ret:%d", ret);
|
||||
}
|
||||
strRsp = buf.Ptr();
|
||||
log_info("ret:%d, strRsp:%s", ret, strRsp.c_str());
|
||||
|
||||
Json::Value root;
|
||||
Json::Reader reader;
|
||||
if (!reader.parse(strRsp.c_str(), root))
|
||||
{
|
||||
log_error("parse Json failed, strRsp:%s", strRsp.c_str());
|
||||
}
|
||||
|
||||
std::string strRetCode = root["retCode"].asString();
|
||||
log_info("strRetCode:%s", strRetCode.c_str());
|
||||
|
||||
if(strRetCode == "1")
|
||||
{
|
||||
log_info("call dtchttpd success!");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error("call dtchttpd failed! strRetCode:%s", strRetCode.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1069,7 +979,7 @@ int DataConnector::SetReportInfo(const std::string str, const uint32_t curve, co
|
||||
{
|
||||
do
|
||||
{
|
||||
CScopedLock lock(_lock);
|
||||
ScopedLock lock(_lock);
|
||||
mapBi[bc].TotalTime += t;
|
||||
mapBi[bc].TotalRequests += 1;
|
||||
}while(0);
|
||||
@ -1079,7 +989,7 @@ int DataConnector::SetReportInfo(const std::string str, const uint32_t curve, co
|
||||
|
||||
void DataConnector::GetReportInfo(std::map<bidCurve, businessStatistics> &map)
|
||||
{
|
||||
CScopedLock lock(_lock);
|
||||
ScopedLock lock(_lock);
|
||||
for(std::map<bidCurve, businessStatistics>::iterator it = mapBi.begin(); it != mapBi.end(); ++it)
|
||||
{
|
||||
struct businessStatistics bs;
|
||||
@ -1091,7 +1001,7 @@ void DataConnector::GetReportInfo(std::map<bidCurve, businessStatistics> &map)
|
||||
|
||||
int DataConnector::SetBussinessId(std::string str)
|
||||
{
|
||||
CScopedLock lock(_lock);
|
||||
ScopedLock lock(_lock);
|
||||
if(mapBi.size() == 0)
|
||||
{
|
||||
pthread_mutex_init(&wakeLock, NULL);
|
||||
@ -1123,87 +1033,9 @@ int DataConnector::SetBussinessId(std::string str)
|
||||
|
||||
int DataConnector::SendTopPercentileData()
|
||||
{
|
||||
std::map<uint64_t, top_percentile_statistics> mapStat;
|
||||
GetTopPercentileData(mapStat);
|
||||
|
||||
int HttpServiceTimeOut = 2;
|
||||
std::string strServiceUrl = "http://tp99dtc.m.jd.local/tp99/forSdk";
|
||||
std::string strRsp = "";
|
||||
CurlHttp curlHttp;
|
||||
Json::FastWriter writer;
|
||||
Json::Value statics;
|
||||
|
||||
uint8_t isHaveData = 0;
|
||||
for(std::map<uint64_t, top_percentile_statistics>::iterator it = mapStat.begin(); it != mapStat.end(); ++it)
|
||||
{
|
||||
if(0 == it->second.uiTotalRequests || 0 == it->second.uiTotalTime)
|
||||
continue;
|
||||
|
||||
if(!isHaveData)
|
||||
isHaveData = 1;
|
||||
|
||||
Json::Value sharding;
|
||||
sharding["bid"] = it->second.uiBid;
|
||||
sharding["ip"] = it->second.uiAgentIP;
|
||||
sharding["port"] = it->second.uiAgentPort;
|
||||
sharding["totalCount"] = it->second.uiTotalRequests;
|
||||
sharding["totalTime"] = static_cast<Json::UInt64>(it->second.uiTotalTime);
|
||||
sharding["failCount"] = it->second.uiFailCount;
|
||||
sharding["maxTime"] = static_cast<Json::UInt64>(it->second.uiMaxTime);
|
||||
sharding["minTime"] = static_cast<Json::UInt64>(it->second.uiMinTime);
|
||||
|
||||
for(uint16_t iNum = 0; iNum < (sizeof(it->second.statArr) / sizeof(it->second.statArr[0])); ++ iNum)
|
||||
{
|
||||
sharding["stat"].append(it->second.statArr[iNum]);
|
||||
}
|
||||
|
||||
statics["content"].append(sharding);
|
||||
}
|
||||
|
||||
if(!isHaveData)
|
||||
return 0;
|
||||
struct timeval stTV;
|
||||
gettimeofday(&stTV, NULL);
|
||||
statics["datetime"] = static_cast<Json::UInt64>(stTV.tv_sec);
|
||||
|
||||
BuffV buf;
|
||||
int ret = 0;
|
||||
std::string strStat = writer.write(statics);
|
||||
log_info("HttpBody = [%s]", strStat.c_str());
|
||||
curlHttp.SetHttpParams("%s", strStat.c_str());
|
||||
curlHttp.SetTimeout(HttpServiceTimeOut);
|
||||
ret = curlHttp.HttpRequest(strServiceUrl, &buf, false);
|
||||
if(ret != 0)
|
||||
{
|
||||
log_error("report http error! curlHttp.HttpRequest error ret:%d", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strRsp = buf.Ptr();
|
||||
log_info("ret:%d, strRsp:%s", ret, strRsp.c_str());
|
||||
|
||||
Json::Value root;
|
||||
Json::Reader reader;
|
||||
if (!reader.parse(strRsp.c_str(), root))
|
||||
{
|
||||
log_error("parse Json failed, strRsp:%s", strRsp.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string strRetCode = root["retCode"].asString();
|
||||
log_info("strRetCode:%s", strRetCode.c_str());
|
||||
|
||||
if(strRetCode == "1")
|
||||
log_info("call dtchttpd success!");
|
||||
else
|
||||
log_error("call dtchttpd failed! strRetCode:%s", strRetCode.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*@strAgentAddr:192.168.145.135:20024/tcp
|
||||
*/
|
||||
int DataConnector::SetTopPercentileData(const std::string strAccessKey, const std::string strAgentAddr, const uint64_t elapse, const int status)
|
||||
{
|
||||
if(strAccessKey.empty())
|
||||
@ -1228,7 +1060,7 @@ int DataConnector::SetTopPercentileData(const std::string strAccessKey, const st
|
||||
|
||||
uint64_t uiKey = (uiIP << 32) | (uiPort << 16) | (uint64_t)uiBid;
|
||||
std::map<uint64_t, DataConnector::top_percentile_statistics>::iterator it;
|
||||
CScopedLock lock(m_tp_lock);
|
||||
ScopedLock lock(m_tp_lock);
|
||||
if((it = mapTPStat.find(uiKey)) == mapTPStat.end())
|
||||
{
|
||||
DataConnector::top_percentile_statistics tpStat;
|
||||
@ -1259,7 +1091,7 @@ int DataConnector::SetTopPercentileData(const std::string strAccessKey, const st
|
||||
|
||||
void DataConnector::GetTopPercentileData(std::map<uint64_t, top_percentile_statistics> &mapStat)
|
||||
{
|
||||
CScopedLock lock(m_tp_lock);
|
||||
ScopedLock lock(m_tp_lock);
|
||||
std::swap(mapTPStat, mapStat);
|
||||
}
|
||||
|
||||
|
@ -643,33 +643,33 @@ __EXPORT
|
||||
int Result::FetchRow(void) {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return -EC_NO_MORE_DATA;
|
||||
if(r->ResultCode()<0) return r->ResultCode();
|
||||
if(r->result_code()<0) return r->result_code();
|
||||
if(r->result==NULL) return -EC_NO_MORE_DATA;
|
||||
return r->result->DecodeRow();
|
||||
return r->result->decode_row();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::Rewind(void) {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return -EC_NO_MORE_DATA;
|
||||
if(r->ResultCode()<0) return r->ResultCode();
|
||||
if(r->result_code()<0) return r->result_code();
|
||||
if(r->result==NULL) return -EC_NO_MORE_DATA;
|
||||
return r->result->Rewind();
|
||||
return r->result->rewind();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::ResultCode(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return 0;
|
||||
return r->ResultCode();
|
||||
return r->result_code();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
const char * Result::ErrorMessage(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return NULL;
|
||||
int code = r->ResultCode();
|
||||
const char *msg = r->resultInfo.ErrorMessage();
|
||||
int code = r->result_code();
|
||||
const char *msg = r->resultInfo.error_message();
|
||||
if(msg==NULL && code < 0) {
|
||||
char a[1];
|
||||
msg = strerror_r(-code, a, 1);
|
||||
@ -682,54 +682,54 @@ __EXPORT
|
||||
const char * Result::ErrorFrom(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return NULL;
|
||||
return r->resultInfo.ErrorFrom();
|
||||
return r->resultInfo.error_from();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::HotBackupID() const {
|
||||
CAST(NCResult, r);
|
||||
return r->versionInfo.HotBackupID();
|
||||
return r->versionInfo.hot_backup_id();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::MasterHBTimestamp() const {
|
||||
CAST(NCResult, r);
|
||||
return r->versionInfo.MasterHBTimestamp();
|
||||
return r->versionInfo.master_hb_timestamp();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::SlaveHBTimestamp() const {
|
||||
CAST(NCResult, r);
|
||||
return r->versionInfo.SlaveHBTimestamp();
|
||||
return r->versionInfo.slave_hb_timestamp();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
char* Result::ServerInfo() const {
|
||||
CAST(NCResult, r);
|
||||
return r->resultInfo.ServerInfo();
|
||||
return r->resultInfo.server_info();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::BinlogID() const {
|
||||
CServerInfo *p = (CServerInfo *)ServerInfo();
|
||||
DTCServerInfo *p = (DTCServerInfo *)ServerInfo();
|
||||
return p ? p->binlog_id : 0;
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::BinlogOffset() const {
|
||||
CServerInfo *p = (CServerInfo *)ServerInfo();
|
||||
DTCServerInfo *p = (DTCServerInfo *)ServerInfo();
|
||||
return p ? p->binlog_off : 0;
|
||||
}
|
||||
__EXPORT
|
||||
long long Result::MemSize() const
|
||||
{
|
||||
CServerInfo *p = (CServerInfo *)ServerInfo();
|
||||
DTCServerInfo *p = (DTCServerInfo *)ServerInfo();
|
||||
return p ? p->memsize : 0;
|
||||
}
|
||||
__EXPORT
|
||||
long long Result::DataSize() const
|
||||
{
|
||||
CServerInfo *p = (CServerInfo *)ServerInfo();
|
||||
DTCServerInfo *p = (DTCServerInfo *)ServerInfo();
|
||||
return p ? p->datasize : 0;
|
||||
}
|
||||
|
||||
@ -737,74 +737,74 @@ __EXPORT
|
||||
int Result::NumRows(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL || r->result==NULL) return 0;
|
||||
return r->result->TotalRows();
|
||||
return r->result->total_rows();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::TotalRows(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return 0;
|
||||
return r->resultInfo.TotalRows();
|
||||
return r->resultInfo.total_rows();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::InsertID(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return 0;
|
||||
return r->resultInfo.InsertID();
|
||||
return r->resultInfo.insert_id();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::NumFields(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL || r->result==NULL) return 0;
|
||||
return r->result->NumFields();
|
||||
return r->result->num_fields();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
const char* Result::FieldName(int n) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL || r->result==NULL) return NULL;
|
||||
if(n<0 || n>=r->result->NumFields()) return NULL;
|
||||
return r->FieldName(r->result->FieldId(n));
|
||||
if(n<0 || n>=r->result->num_fields()) return NULL;
|
||||
return r->field_name(r->result->field_id(n));
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::FieldPresent(const char* name) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL || r->result==NULL) return 0;
|
||||
int id = r->FieldId(name);
|
||||
int id = r->field_id(name);
|
||||
if(id < 0) return 0;
|
||||
return r->result->FieldPresent(id);
|
||||
return r->result->field_present(id);
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::FieldType(int n) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL || r->result==NULL) return FieldTypeNone;
|
||||
if(n<0 || n>=r->result->NumFields()) return FieldTypeNone;
|
||||
return r->FieldType(r->result->FieldId(n));
|
||||
if(n<0 || n>=r->result->num_fields()) return FieldTypeNone;
|
||||
return r->field_type(r->result->field_id(n));
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
int Result::AffectedRows(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return 0;
|
||||
return r->resultInfo.AffectedRows();
|
||||
return r->resultInfo.affected_rows();
|
||||
}
|
||||
|
||||
__EXPORT
|
||||
long long Result::IntKey(void) const {
|
||||
CAST(NCResult, r);
|
||||
const DTCValue *v = NULL;
|
||||
if(r && r->FlagMultiKeyResult() && r->result){
|
||||
v = r->result->FieldValue(0);
|
||||
if(r && r->flag_multi_key_result() && r->result){
|
||||
v = r->result->field_value(0);
|
||||
}
|
||||
else if(r && r->ResultKey()){
|
||||
v = r->ResultKey();
|
||||
else if(r && r->result_key()){
|
||||
v = r->result_key();
|
||||
}
|
||||
if(v != NULL){
|
||||
switch(r->FieldType(0)) {
|
||||
switch(r->field_type(0)) {
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
return v->s64;
|
||||
@ -826,14 +826,14 @@ __EXPORT
|
||||
const char *Result::StringKey(void) const {
|
||||
CAST(NCResult, r);
|
||||
const DTCValue *v = NULL;
|
||||
if(r && r->FlagMultiKeyResult() && r->result){
|
||||
v = r->result->FieldValue(0);
|
||||
if(r && r->flag_multi_key_result() && r->result){
|
||||
v = r->result->field_value(0);
|
||||
}
|
||||
else if(r && r->ResultKey()){
|
||||
v = r->ResultKey();
|
||||
else if(r && r->result_key()){
|
||||
v = r->result_key();
|
||||
}
|
||||
if(v != NULL){
|
||||
switch(r->FieldType(0)) {
|
||||
switch(r->field_type(0)) {
|
||||
case DField::Binary:
|
||||
case DField::String:
|
||||
return v->bin.ptr;
|
||||
@ -847,14 +847,14 @@ __EXPORT
|
||||
const char *Result::StringKey(int *lp) const {
|
||||
CAST(NCResult, r);
|
||||
const DTCValue *v = NULL;
|
||||
if(r && r->FlagMultiKeyResult() && r->result){
|
||||
v = r->result->FieldValue(0);
|
||||
if(r && r->flag_multi_key_result() && r->result){
|
||||
v = r->result->field_value(0);
|
||||
}
|
||||
else if(r && r->ResultKey()){
|
||||
v = r->ResultKey();
|
||||
else if(r && r->result_key()){
|
||||
v = r->result_key();
|
||||
}
|
||||
if(v != NULL){
|
||||
switch(r->FieldType(0)) {
|
||||
switch(r->field_type(0)) {
|
||||
case DField::Binary:
|
||||
case DField::String:
|
||||
if(lp) *lp = v->bin.len;
|
||||
@ -868,14 +868,14 @@ const char *Result::StringKey(int *lp) const {
|
||||
const char *Result::StringKey(int &l) const {
|
||||
CAST(NCResult, r);
|
||||
const DTCValue *v = NULL;
|
||||
if(r && r->FlagMultiKeyResult() && r->result){
|
||||
v = r->result->FieldValue(0);
|
||||
if(r && r->flag_multi_key_result() && r->result){
|
||||
v = r->result->field_value(0);
|
||||
}
|
||||
else if(r && r->ResultKey()){
|
||||
v = r->ResultKey();
|
||||
else if(r && r->result_key()){
|
||||
v = r->result_key();
|
||||
}
|
||||
if(v != NULL){
|
||||
switch(r->FieldType(0)) {
|
||||
switch(r->field_type(0)) {
|
||||
case DField::Binary:
|
||||
case DField::String:
|
||||
l = v->bin.len;
|
||||
@ -904,13 +904,13 @@ const char *Result::BinaryKey(int &l) const {
|
||||
static inline int64_t GetIntValue(NCResult *r, int id) {
|
||||
if(id >= 0) {
|
||||
const DTCValue *v;
|
||||
if(id==0 && !(r->result->FieldPresent(0)))
|
||||
v = r->ResultKey();
|
||||
if(id==0 && !(r->result->field_present(0)))
|
||||
v = r->result_key();
|
||||
else
|
||||
v = r->result->FieldValue(id);
|
||||
v = r->result->field_value(id);
|
||||
|
||||
if(v) {
|
||||
switch(r->FieldType(id)) {
|
||||
switch(r->field_type(id)) {
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
return v->s64;
|
||||
@ -929,13 +929,13 @@ static inline int64_t GetIntValue(NCResult *r, int id) {
|
||||
static inline double GetFloatValue(NCResult *r, int id) {
|
||||
if(id >= 0) {
|
||||
const DTCValue *v;
|
||||
if(id==0 && !(r->result->FieldPresent(0)))
|
||||
v = r->ResultKey();
|
||||
if(id==0 && !(r->result->field_present(0)))
|
||||
v = r->result_key();
|
||||
else
|
||||
v = r->result->FieldValue(id);
|
||||
v = r->result->field_value(id);
|
||||
|
||||
if(v) {
|
||||
switch(r->FieldType(id)) {
|
||||
switch(r->field_type(id)) {
|
||||
case DField::Signed:
|
||||
return (double)v->s64;
|
||||
case DField::Unsigned:
|
||||
@ -954,13 +954,13 @@ static inline double GetFloatValue(NCResult *r, int id) {
|
||||
static inline const char *GetStringValue(NCResult *r, int id, int *lenp) {
|
||||
if(id >= 0) {
|
||||
const DTCValue *v;
|
||||
if(id==0 && !(r->result->FieldPresent(0)))
|
||||
v = r->ResultKey();
|
||||
if(id==0 && !(r->result->field_present(0)))
|
||||
v = r->result_key();
|
||||
else
|
||||
v = r->result->FieldValue(id);
|
||||
v = r->result->field_value(id);
|
||||
|
||||
if(v) {
|
||||
switch(r->FieldType(id)) {
|
||||
switch(r->field_type(id)) {
|
||||
case DField::String:
|
||||
if(lenp) *lenp = v->bin.len;
|
||||
return v->str.ptr;
|
||||
@ -973,13 +973,13 @@ static inline const char *GetStringValue(NCResult *r, int id, int *lenp) {
|
||||
static inline const char *GetBinaryValue(NCResult *r, int id, int *lenp) {
|
||||
if(id >= 0) {
|
||||
const DTCValue *v;
|
||||
if(id==0 && !(r->result->FieldPresent(0)))
|
||||
v = r->ResultKey();
|
||||
if(id==0 && !(r->result->field_present(0)))
|
||||
v = r->result_key();
|
||||
else
|
||||
v = r->result->FieldValue(id);
|
||||
v = r->result->field_value(id);
|
||||
|
||||
if(v) {
|
||||
switch(r->FieldType(id)) {
|
||||
switch(r->field_type(id)) {
|
||||
case DField::String:
|
||||
case DField::Binary:
|
||||
if(lenp) *lenp = v->bin.len;
|
||||
@ -994,7 +994,7 @@ __EXPORT
|
||||
long long Result::IntValue(const char *name) const {
|
||||
CAST(NCResult, r);
|
||||
if(r && r->result)
|
||||
return GetIntValue(r, r->FieldId(name));
|
||||
return GetIntValue(r, r->field_id(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1010,7 +1010,7 @@ __EXPORT
|
||||
double Result::FloatValue(const char *name) const {
|
||||
CAST(NCResult, r);
|
||||
if(r && r->result)
|
||||
return GetFloatValue(r, r->FieldId(name));
|
||||
return GetFloatValue(r, r->field_id(name));
|
||||
return NAN;
|
||||
}
|
||||
|
||||
@ -1027,7 +1027,7 @@ const char *Result::StringValue(const char *name, int *lenp) const {
|
||||
if(lenp) *lenp = 0;
|
||||
CAST(NCResult, r);
|
||||
if(r && r->result)
|
||||
return GetStringValue(r, r->FieldId(name), lenp);
|
||||
return GetStringValue(r, r->field_id(name), lenp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1065,7 +1065,7 @@ const char *Result::BinaryValue(const char *name, int *lenp) const {
|
||||
if(lenp) *lenp = 0;
|
||||
CAST(NCResult, r);
|
||||
if(r && r->result)
|
||||
return GetBinaryValue(r, r->FieldId(name), lenp);
|
||||
return GetBinaryValue(r, r->field_id(name), lenp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1091,7 +1091,7 @@ int Result::UnCompressBinaryValue(const char *name,char **buf,int *lenp){
|
||||
snprintf(r->gzip->_errmsg, sizeof(r->gzip->_errmsg), "field name is null");
|
||||
return -EC_UNCOMPRESS_ERROR;
|
||||
}
|
||||
int fieldId = r->FieldId(name);
|
||||
int fieldId = r->field_id(name);
|
||||
if (fieldId >63)//fieldid must less than 64,because compressflag is 8 bytes uint
|
||||
{
|
||||
snprintf(r->gzip->_errmsg, sizeof(r->gzip->_errmsg), "fieldid must less than 64,because compressflag is 8 bytes uint");
|
||||
@ -1154,7 +1154,7 @@ int Result::UnCompressBinaryValueForce(const char *name,char **buf,int *lenp){
|
||||
}
|
||||
iret = r->initCompress();
|
||||
if (iret) return iret;
|
||||
int fieldId = r->FieldId(name);
|
||||
int fieldId = r->field_id(name);
|
||||
buf_dup = GetBinaryValue(r, fieldId, lenp);
|
||||
if (buf_dup==NULL)
|
||||
{
|
||||
@ -1175,7 +1175,7 @@ const char *Result::UnCompressErrorMessage() const
|
||||
{
|
||||
CAST(NCResult, r);
|
||||
if(r && r->gzip)
|
||||
return r->gzip->ErrorMessage();
|
||||
return r->gzip->error_message();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1226,7 +1226,7 @@ __EXPORT
|
||||
long long Result::Magic(void) const {
|
||||
CAST(NCResult, r);
|
||||
if(r==NULL) return 0;
|
||||
return r->versionInfo.SerialNr();
|
||||
return r->versionInfo.serial_nr();
|
||||
};
|
||||
|
||||
__EXPORT
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "memcheck.h"
|
||||
#include "mem_check.h"
|
||||
#include "protocol.h"
|
||||
#include "keylist.h"
|
||||
#include "cache_error.h"
|
||||
#include "key_list.h"
|
||||
#include "buffer_error.h"
|
||||
|
||||
int NCKeyValueList::KeyValueMax = 32;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "listener_pool.h"
|
||||
#include "request_threading.h"
|
||||
#include "task_multiplexer.h"
|
||||
#include "../api/c_api/dtc_int.h"
|
||||
#include "../api/c_api_cc/dtcint.h"
|
||||
#include "proxy_listen_pool.h"
|
||||
#include "table_def_manager.h"
|
||||
|
||||
@ -171,7 +171,7 @@ extern "C" __EXPORT
|
||||
|
||||
void InitTaskExecutor(const char *name, AgentListenPool *listener, TaskDispatcher<TaskRequest> *output)
|
||||
{
|
||||
if (NCResultInternal::verify_class() == 0)
|
||||
if (NCResultInternal::VerifyClass() == 0)
|
||||
{
|
||||
log_error("Inconsistent class NCResultInternal detected, internal API disabled");
|
||||
return;
|
||||
|
@ -1,7 +1,7 @@
|
||||
include ../Make.conf
|
||||
|
||||
target = libcommon.a libcommon_nopic.a
|
||||
CFLAGS+=-I../api/c_api -I. -I../watchdog -I../stat -I../../../3rdlib/attr_api $(ZINC)
|
||||
CFLAGS+=-I../api/c_api_cc -I. -I../watchdog -I../stat -I../../../3rdlib/attr_api $(ZINC)
|
||||
LIBS = $(Z_LIB)
|
||||
VPATH = ../watchdog
|
||||
#SVN_VERSION = $(shell test -d .svn && (svn info ../ | grep "Last Changed Rev" | cut -d " " -f 4))
|
||||
|
@ -84,7 +84,7 @@ int MultiRequest::decode_key_list(void)
|
||||
if (wait->internal_key_val_list())
|
||||
{
|
||||
// embeded API
|
||||
totalReq = wait->internal_key_val_list()->key_count();
|
||||
totalReq = wait->internal_key_val_list()->KeyCount();
|
||||
// Q&D discard const here
|
||||
// this keyList member can't be const,
|
||||
// but actually readonly after init
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "protocol.h"
|
||||
#include "version.h"
|
||||
#include "packet.h"
|
||||
#include "../api/c_api/dtc_int.h"
|
||||
#include "../api/c_api_cc/dtcint.h"
|
||||
#include "table_def.h"
|
||||
#include "decode.h"
|
||||
|
||||
@ -67,8 +67,8 @@ int Templateencode_request(NCRequest &rq, const DTCValue *kptr, T *tgt)
|
||||
vi.set_hot_backup_id(rq.hotBackupID);
|
||||
|
||||
// hot backup timestamp
|
||||
vi.set_master_hb_timestamp(rq.master_hb_timestamp);
|
||||
vi.set_slave_hb_timestamp(rq.slave_hb_timestamp);
|
||||
vi.set_master_hb_timestamp(rq.MasterHBTimestamp);
|
||||
vi.set_slave_hb_timestamp(rq.SlaveHBTimestamp);
|
||||
if (sv->tdef && rq.adminCode != 0)
|
||||
vi.set_data_table_hash(sv->tdef->table_hash());
|
||||
|
||||
@ -81,7 +81,7 @@ int Templateencode_request(NCRequest &rq, const DTCValue *kptr, T *tgt)
|
||||
int isbatch = 0;
|
||||
if (rq.flags & DRequest::Flag::MultiKeyValue)
|
||||
{
|
||||
if (sv->simple_batch_key() && rq.kvl.key_count() == 1)
|
||||
if (sv->SimpleBatchKey() && rq.kvl.KeyCount() == 1)
|
||||
{
|
||||
/* single field single key batch, convert to normal */
|
||||
kptr = rq.kvl.val;
|
||||
@ -95,8 +95,8 @@ int Templateencode_request(NCRequest &rq, const DTCValue *kptr, T *tgt)
|
||||
|
||||
if (isbatch)
|
||||
{
|
||||
int keyFieldCnt = rq.kvl.key_fields();
|
||||
int keyCount = rq.kvl.key_count();
|
||||
int keyFieldCnt = rq.kvl.KeyFields();
|
||||
int keyCount = rq.kvl.KeyCount();
|
||||
int i, j;
|
||||
vi.set_tag(10, keyFieldCnt);
|
||||
vi.set_tag(11, keyCount);
|
||||
@ -105,14 +105,14 @@ int Templateencode_request(NCRequest &rq, const DTCValue *kptr, T *tgt)
|
||||
if (kt.ptr == NULL)
|
||||
throw std::bad_alloc();
|
||||
for (i = 0; i < keyFieldCnt; i++)
|
||||
kt.Add((uint8_t)(rq.kvl.key_type(i)));
|
||||
kt.Add((uint8_t)(rq.kvl.KeyType(i)));
|
||||
vi.set_tag(12, DTCValue::Make(kt.ptr, kt.len));
|
||||
// key name
|
||||
kn.ptr = (char *)MALLOC((256 + sizeof(uint32_t)) * keyFieldCnt);
|
||||
if (kn.ptr == NULL)
|
||||
throw std::bad_alloc();
|
||||
for (i = 0; i < keyFieldCnt; i++)
|
||||
kn.Add(rq.kvl.key_name(i));
|
||||
kn.Add(rq.kvl.KeyName(i));
|
||||
vi.set_tag(13, DTCValue::Make(kn.ptr, kn.len));
|
||||
// key value
|
||||
unsigned int buf_size = 0;
|
||||
@ -121,7 +121,7 @@ int Templateencode_request(NCRequest &rq, const DTCValue *kptr, T *tgt)
|
||||
for (i = 0; i < keyFieldCnt; i++)
|
||||
{
|
||||
DTCValue &v = rq.kvl(j, i);
|
||||
switch (rq.kvl.key_type(i))
|
||||
switch (rq.kvl.KeyType(i))
|
||||
{
|
||||
case DField::Signed:
|
||||
case DField::Unsigned:
|
||||
@ -157,9 +157,9 @@ int Templateencode_request(NCRequest &rq, const DTCValue *kptr, T *tgt)
|
||||
else if (kptr)
|
||||
ri.set_key(*kptr);
|
||||
// cmd
|
||||
if (sv->get_timeout())
|
||||
if (sv->GetTimeout())
|
||||
{
|
||||
ri.set_timeout(sv->get_timeout());
|
||||
ri.set_timeout(sv->GetTimeout());
|
||||
}
|
||||
//limit
|
||||
if (rq.limitCount)
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "log.h"
|
||||
#include "task_request.h"
|
||||
#include "result.h"
|
||||
#include <dtc_int.h>
|
||||
#include <dtcint.h>
|
||||
|
||||
inline int DTCFieldSet::Copy(const FieldSetByName &rq)
|
||||
{
|
||||
@ -159,12 +159,12 @@ int TaskRequest::Copy(NCRequest &rq, const DTCValue *kptr)
|
||||
// inline from prepare_process()
|
||||
if ((requestFlags & DRequest::Flag::MultiKeyValue))
|
||||
{
|
||||
if (rq.kvl.key_fields() != key_fields())
|
||||
if (rq.kvl.KeyFields() != key_fields())
|
||||
{
|
||||
set_error(-EC_KEY_NEEDED, "decoder", "key field count incorrect");
|
||||
return -EC_KEY_NEEDED;
|
||||
}
|
||||
if (rq.kvl.key_count() < 1)
|
||||
if (rq.kvl.KeyCount() < 1)
|
||||
{
|
||||
set_error(-EC_KEY_NEEDED, "decoder", "require key value");
|
||||
return -EC_KEY_NEEDED;
|
||||
@ -224,15 +224,15 @@ int DTCTask::Copy(NCRequest &rq, const DTCValue *kptr)
|
||||
versionInfo.set_hot_backup_id(rq.hotBackupID);
|
||||
|
||||
// hot backup timestamp
|
||||
versionInfo.set_master_hb_timestamp(rq.master_hb_timestamp);
|
||||
versionInfo.set_slave_hb_timestamp(rq.slave_hb_timestamp);
|
||||
versionInfo.set_master_hb_timestamp(rq.MasterHBTimestamp);
|
||||
versionInfo.set_slave_hb_timestamp(rq.SlaveHBTimestamp);
|
||||
if (sv->tdef && rq.adminCode != 0)
|
||||
versionInfo.set_data_table_hash(sv->tdef->table_hash());
|
||||
|
||||
if (rq.flags & DRequest::Flag::MultiKeyValue)
|
||||
{
|
||||
kptr = NULL;
|
||||
if (sv->simple_batch_key() && rq.kvl.key_count() == 1)
|
||||
if (sv->SimpleBatchKey() && rq.kvl.KeyCount() == 1)
|
||||
{
|
||||
/* single field single key batch, convert to normal */
|
||||
kptr = rq.kvl.val;
|
||||
@ -248,9 +248,9 @@ int DTCTask::Copy(NCRequest &rq, const DTCValue *kptr)
|
||||
requestInfo.set_key(*kptr);
|
||||
}
|
||||
// cmd
|
||||
if (sv->get_timeout())
|
||||
if (sv->GetTimeout())
|
||||
{
|
||||
requestInfo.set_timeout(sv->get_timeout());
|
||||
requestInfo.set_timeout(sv->GetTimeout());
|
||||
}
|
||||
//limit
|
||||
if (rq.limitCount)
|
||||
|
Loading…
Reference in New Issue
Block a user