mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-11-30 02:47:35 +08:00
Remove typedef in c files
This commit is contained in:
parent
5cf749ef0a
commit
cc43dc719e
@ -383,9 +383,9 @@ static void g_table_free_all(gpointer q) {
|
||||
g_hash_table_destroy(table);
|
||||
}
|
||||
|
||||
typedef struct used_conns {
|
||||
struct used_conns_t {
|
||||
int num;
|
||||
} used_conns_t;
|
||||
};
|
||||
|
||||
static int admin_send_backend_detail_info(network_mysqld_con *admin_con, const char *sql)
|
||||
{
|
||||
@ -437,10 +437,10 @@ static int admin_send_backend_detail_info(network_mysqld_con *admin_con, const c
|
||||
continue;
|
||||
}
|
||||
|
||||
used_conns_t *total_used = g_hash_table_lookup(table,
|
||||
struct used_conns_t *total_used = g_hash_table_lookup(table,
|
||||
con->client->response->username->str);
|
||||
if (total_used == NULL) {
|
||||
total_used = g_new0(used_conns_t, 1);
|
||||
total_used = g_new0(struct used_conns_t, 1);
|
||||
g_hash_table_insert(table,
|
||||
g_strdup(con->client->response->username->str), total_used);
|
||||
}
|
||||
@ -459,10 +459,10 @@ static int admin_send_backend_detail_info(network_mysqld_con *admin_con, const c
|
||||
continue;
|
||||
}
|
||||
|
||||
used_conns_t *total_used = g_hash_table_lookup(table,
|
||||
struct used_conns_t *total_used = g_hash_table_lookup(table,
|
||||
con->client->response->username->str);
|
||||
if (total_used == NULL) {
|
||||
total_used = g_new0(used_conns_t, 1);
|
||||
total_used = g_new0(struct used_conns_t, 1);
|
||||
g_hash_table_insert(table,
|
||||
g_strdup(con->client->response->username->str), total_used);
|
||||
}
|
||||
@ -480,10 +480,10 @@ static int admin_send_backend_detail_info(network_mysqld_con *admin_con, const c
|
||||
con->server->dst->name->str);
|
||||
continue;
|
||||
}
|
||||
used_conns_t *total_used = g_hash_table_lookup(table,
|
||||
struct used_conns_t *total_used = g_hash_table_lookup(table,
|
||||
con->client->response->username->str);
|
||||
if (total_used == NULL) {
|
||||
total_used = g_new0(used_conns_t, 1);
|
||||
total_used = g_new0(struct used_conns_t, 1);
|
||||
g_hash_table_insert(table,
|
||||
g_strdup(con->client->response->username->str), total_used);
|
||||
}
|
||||
@ -551,7 +551,7 @@ static int admin_send_backend_detail_info(network_mysqld_con *admin_con, const c
|
||||
snprintf(buffer, sizeof(buffer), "%d", queue->length);
|
||||
g_ptr_array_add(row, g_strdup(buffer));
|
||||
|
||||
used_conns_t *total_used = g_hash_table_lookup(table, key->str);
|
||||
struct used_conns_t *total_used = g_hash_table_lookup(table, key->str);
|
||||
if (total_used) {
|
||||
snprintf(buffer, sizeof(buffer), "%d", total_used->num);
|
||||
} else {
|
||||
@ -2355,28 +2355,28 @@ network_mysqld_admin_plugin_get_options(chassis_plugin_config *config)
|
||||
/* ring buffer from: https://github.com/AndersKaloer/Ring-Buffer */
|
||||
#define RING_BUFFER_SIZE 128 /* must be power of 2, !! index [0, 126] !!*/
|
||||
#define RING_BUFFER_MASK (RING_BUFFER_SIZE-1)
|
||||
typedef struct ring_buffer_t {
|
||||
struct ring_buffer_t {
|
||||
int head;
|
||||
int tail;
|
||||
guint64 buffer[RING_BUFFER_SIZE];
|
||||
} ring_buffer_t;
|
||||
};
|
||||
|
||||
static void ring_buffer_add(ring_buffer_t *buffer, guint64 data) {
|
||||
static void ring_buffer_add(struct ring_buffer_t *buffer, guint64 data) {
|
||||
if (((buffer->head - buffer->tail) & RING_BUFFER_MASK) == RING_BUFFER_MASK)
|
||||
buffer->tail = ((buffer->tail + 1) & RING_BUFFER_MASK);
|
||||
buffer->buffer[buffer->head] = data;
|
||||
buffer->head = ((buffer->head + 1) & RING_BUFFER_MASK);
|
||||
}
|
||||
|
||||
static guint64 ring_buffer_get(ring_buffer_t *buffer, int index) {
|
||||
static guint64 ring_buffer_get(struct ring_buffer_t *buffer, int index) {
|
||||
if (index >= ((buffer->head - buffer->tail) & RING_BUFFER_MASK))
|
||||
return 0;
|
||||
int data_index = ((buffer->tail + index) & RING_BUFFER_MASK);
|
||||
return buffer->buffer[data_index];
|
||||
}
|
||||
|
||||
static ring_buffer_t g_sql_count = {126, 0};
|
||||
static ring_buffer_t g_trx_count = {126, 0};
|
||||
static struct ring_buffer_t g_sql_count = {126, 0};
|
||||
static struct ring_buffer_t g_trx_count = {126, 0};
|
||||
|
||||
static void calc_qps_average(char *buf, int len)
|
||||
{
|
||||
|
@ -280,13 +280,13 @@ static gboolean sql_select_contains_sharding_table(sql_select_t *select,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef struct condition_t {
|
||||
struct condition_t {
|
||||
int op;
|
||||
union {
|
||||
gint64 num;
|
||||
const char *str;
|
||||
}v;
|
||||
} condition_t;
|
||||
};
|
||||
|
||||
/**
|
||||
* check if the group satisfies an inequation
|
||||
@ -294,7 +294,7 @@ typedef struct condition_t {
|
||||
* if exists X -> (low, high] that satifies X > 42, return true
|
||||
* if it doesn't exist such an X, return false;
|
||||
*/
|
||||
static gboolean partition_satisfies(sharding_partition_t *partition, condition_t cond)
|
||||
static gboolean partition_satisfies(sharding_partition_t *partition, struct condition_t cond)
|
||||
{
|
||||
/* partition value -> (low, high] */
|
||||
const sharding_vdb_t *conf = partition->vdb;
|
||||
@ -363,7 +363,7 @@ static gboolean partition_satisfies(sharding_partition_t *partition, condition_t
|
||||
}
|
||||
|
||||
/* filter out those which not satisfy cond */
|
||||
static void partitions_filter(GPtrArray *partitions, condition_t cond)
|
||||
static void partitions_filter(GPtrArray *partitions, struct condition_t cond)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < partitions->len; ++i) {
|
||||
@ -376,7 +376,7 @@ static void partitions_filter(GPtrArray *partitions, condition_t cond)
|
||||
}
|
||||
|
||||
/* collect those which satisfy cond */
|
||||
static void partitions_collect(GPtrArray *from_partitions, condition_t cond,
|
||||
static void partitions_collect(GPtrArray *from_partitions, struct condition_t cond,
|
||||
GPtrArray *to_partitions)
|
||||
{
|
||||
int i = 0;
|
||||
@ -389,7 +389,7 @@ static void partitions_collect(GPtrArray *from_partitions, condition_t cond,
|
||||
}
|
||||
|
||||
/* get first group that satisfies cond */
|
||||
sharding_partition_t *partitions_get(GPtrArray *from_partitions, condition_t cond)
|
||||
sharding_partition_t *partitions_get(GPtrArray *from_partitions, struct condition_t cond)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < from_partitions->len; ++i) {
|
||||
@ -425,7 +425,7 @@ static GPtrArray *partitions_dup(GPtrArray *partitions)
|
||||
/**
|
||||
* parse cond.v from a string
|
||||
*/
|
||||
static int string_to_sharding_value(const char *str, int expected, condition_t *cond)
|
||||
static int string_to_sharding_value(const char *str, int expected, struct condition_t *cond)
|
||||
{
|
||||
assert(cond);
|
||||
if (expected == SHARD_DATA_TYPE_STR) {
|
||||
@ -455,7 +455,7 @@ static int string_to_sharding_value(const char *str, int expected, condition_t *
|
||||
/**
|
||||
* parse cond.v from sql expression
|
||||
*/
|
||||
static int expr_parse_sharding_value(sql_expr_t *p, int expected, condition_t *cond)
|
||||
static int expr_parse_sharding_value(sql_expr_t *p, int expected, struct condition_t *cond)
|
||||
{
|
||||
assert(p);
|
||||
assert(cond);
|
||||
@ -485,7 +485,7 @@ static int partitions_filter_inequation_expr(GPtrArray *partitions, sql_expr_t *
|
||||
return PARSE_OK;
|
||||
}
|
||||
|
||||
condition_t cond = {0};
|
||||
struct condition_t cond = {0};
|
||||
cond.op = expr->op;
|
||||
int rc = expr_parse_sharding_value(expr->right, conf->key_type, &cond);
|
||||
if (rc != PARSE_OK)
|
||||
@ -505,7 +505,7 @@ static int partitions_filter_BETWEEN_expr(GPtrArray *partitions, sql_expr_t *exp
|
||||
return PARSE_OK;
|
||||
}
|
||||
|
||||
condition_t cond = {0};
|
||||
struct condition_t cond = {0};
|
||||
sql_expr_list_t *btlist = expr->list;
|
||||
if (btlist && btlist->len == 2) {
|
||||
sql_expr_t *low = g_ptr_array_index(btlist, 0);
|
||||
@ -536,7 +536,7 @@ static int partitions_collect_IN_expr(GPtrArray *partitions, sql_expr_t *expr)
|
||||
return PARSE_OK;
|
||||
}
|
||||
|
||||
condition_t cond = {0};
|
||||
struct condition_t cond = {0};
|
||||
if (expr->list && expr->list->len > 0) {
|
||||
GPtrArray *partitions = g_ptr_array_new();
|
||||
|
||||
@ -1120,7 +1120,7 @@ static int insert_multi_value(sql_context_t *context, sql_insert_t *insert,
|
||||
rc = ERROR_UNPARSABLE;
|
||||
goto out;
|
||||
}
|
||||
condition_t cond = {TK_EQ, {0}};
|
||||
struct condition_t cond = {TK_EQ, {0}};
|
||||
sql_expr_t *val = g_ptr_array_index(values->columns, shard_key_index);
|
||||
int rc = expr_parse_sharding_value(val, shard_info->shard_key_type, &cond);
|
||||
if (rc != PARSE_OK) {
|
||||
@ -1234,7 +1234,7 @@ static int routing_insert(sql_context_t *context, sql_insert_t *insert,
|
||||
return ERROR_UNPARSABLE;
|
||||
}
|
||||
|
||||
condition_t cond = {TK_EQ, {0}};
|
||||
struct condition_t cond = {TK_EQ, {0}};
|
||||
sql_expr_t *val = g_ptr_array_index(values, shard_key_index);
|
||||
int rc = expr_parse_sharding_value(val, shard_info->shard_key_type, &cond);
|
||||
if (rc != PARSE_OK) {
|
||||
@ -1358,7 +1358,7 @@ int routing_by_property(sql_context_t *context, sql_property_t *property,
|
||||
GPtrArray *partitions = g_ptr_array_new();
|
||||
shard_conf_table_partitions(partitions, db, table);
|
||||
if (property->key) {
|
||||
condition_t cond = {TK_EQ, {0}};
|
||||
struct condition_t cond = {TK_EQ, {0}};
|
||||
sharding_table_t *info = shard_conf_get_info(db, table);
|
||||
if (!info) {
|
||||
g_ptr_array_free(partitions, TRUE);
|
||||
|
@ -25,12 +25,12 @@ static char tc_error_log_time[TC_ERR_LOG_TIME_STR_LEN];
|
||||
|
||||
static int update_time();
|
||||
|
||||
typedef struct {
|
||||
struct tc_log_level_t {
|
||||
char *level;
|
||||
int len;
|
||||
} tc_log_level_t;
|
||||
};
|
||||
|
||||
static tc_log_level_t tc_log_levels[] = {
|
||||
static struct tc_log_level_t tc_log_levels[] = {
|
||||
{ "[unknown]", 9 },
|
||||
{ "[emerg]", 7 },
|
||||
{ "[alert]", 7 },
|
||||
@ -211,7 +211,7 @@ tc_log_info(int level, int err, const char *fmt, ...)
|
||||
int n, len;
|
||||
char buffer[LOG_MAX_LEN], *p;
|
||||
va_list args;
|
||||
tc_log_level_t *ll;
|
||||
struct tc_log_level_t *ll;
|
||||
|
||||
if (log_fd == -1) {
|
||||
return;
|
||||
|
@ -38,15 +38,15 @@ enum chassis_config_type_t {
|
||||
};
|
||||
|
||||
#define RF_MAX_NAME_LEN 128
|
||||
typedef struct chassis_config_object_t {
|
||||
struct config_object_t {
|
||||
char name[RF_MAX_NAME_LEN];
|
||||
|
||||
/* TODO: cache lock */
|
||||
char *cache;
|
||||
time_t mtime;
|
||||
} config_object_t;
|
||||
};
|
||||
|
||||
static void config_object_free(config_object_t *ob)
|
||||
static void config_object_free(struct config_object_t *ob)
|
||||
{
|
||||
if (ob->cache) g_free(ob->cache);
|
||||
g_free(ob);
|
||||
@ -323,7 +323,7 @@ GHashTable *chassis_config_get_options(chassis_config_t *conf)
|
||||
}
|
||||
|
||||
|
||||
static void chassis_config_object_set_cache(config_object_t *ob,
|
||||
static void chassis_config_object_set_cache(struct config_object_t *ob,
|
||||
const char *str, time_t mt)
|
||||
{
|
||||
if (ob->cache) {
|
||||
@ -333,12 +333,12 @@ static void chassis_config_object_set_cache(config_object_t *ob,
|
||||
ob->mtime = mt;
|
||||
}
|
||||
|
||||
static config_object_t *chassis_config_get_object(chassis_config_t *conf,
|
||||
static struct config_object_t *chassis_config_get_object(chassis_config_t *conf,
|
||||
const char *name)
|
||||
{
|
||||
GList *l = NULL;
|
||||
for (l = conf->objects; l; l = l->next) {
|
||||
config_object_t *ob = l->data;
|
||||
struct config_object_t *ob = l->data;
|
||||
if (strcmp(ob->name, name) == 0)
|
||||
return ob;
|
||||
}
|
||||
@ -346,7 +346,7 @@ static config_object_t *chassis_config_get_object(chassis_config_t *conf,
|
||||
}
|
||||
|
||||
static gboolean chassis_config_mysql_query_object(chassis_config_t *conf,
|
||||
config_object_t *object, const char *name, char **json_res)
|
||||
struct config_object_t *object, const char *name, char **json_res)
|
||||
{
|
||||
g_assert(conf->type == CHASSIS_CONF_MYSQL);
|
||||
if (object->cache) {
|
||||
@ -391,7 +391,7 @@ mysql_error:
|
||||
}
|
||||
|
||||
static gboolean chassis_config_local_query_object(chassis_config_t *conf,
|
||||
config_object_t *object, const char *name, char **json_res)
|
||||
struct config_object_t *object, const char *name, char **json_res)
|
||||
{
|
||||
if (object->cache) {
|
||||
*json_res = g_strdup(object->cache);
|
||||
@ -425,9 +425,9 @@ static gboolean chassis_config_local_query_object(chassis_config_t *conf,
|
||||
gboolean chassis_config_query_object(chassis_config_t *conf,
|
||||
const char *name, char **json_res)
|
||||
{
|
||||
config_object_t *object = chassis_config_get_object(conf, name);
|
||||
struct config_object_t *object = chassis_config_get_object(conf, name);
|
||||
if (!object) {
|
||||
object = g_new0(config_object_t, 1);
|
||||
object = g_new0(struct config_object_t, 1);
|
||||
strncpy(object->name, name, RF_MAX_NAME_LEN - 1);
|
||||
conf->objects = g_list_append(conf->objects, object);
|
||||
}
|
||||
@ -443,7 +443,7 @@ gboolean chassis_config_query_object(chassis_config_t *conf,
|
||||
}
|
||||
|
||||
static gboolean chassis_config_mysql_write_object(chassis_config_t *conf,
|
||||
config_object_t *object, const char *name, const char *json)
|
||||
struct config_object_t *object, const char *name, const char *json)
|
||||
{
|
||||
g_assert(conf->type == CHASSIS_CONF_MYSQL);
|
||||
time_t now = time(0);
|
||||
@ -467,7 +467,7 @@ static gboolean chassis_config_mysql_write_object(chassis_config_t *conf,
|
||||
}
|
||||
|
||||
static gboolean chassis_config_local_write_object(chassis_config_t *conf,
|
||||
config_object_t *object, const char *name, const char *json_str)
|
||||
struct config_object_t *object, const char *name, const char *json_str)
|
||||
{
|
||||
/* conf->schema is an absolute path for local config */
|
||||
char basename[128] = {0};
|
||||
@ -493,9 +493,9 @@ static gboolean chassis_config_local_write_object(chassis_config_t *conf,
|
||||
gboolean chassis_config_write_object(chassis_config_t *conf,
|
||||
const char *name, const char *json)
|
||||
{
|
||||
config_object_t *object = chassis_config_get_object(conf, name);
|
||||
struct config_object_t *object = chassis_config_get_object(conf, name);
|
||||
if (!object) {
|
||||
object = g_new0(config_object_t, 1);
|
||||
object = g_new0(struct config_object_t, 1);
|
||||
strncpy(object->name, name, RF_MAX_NAME_LEN - 1);
|
||||
conf->objects = g_list_append(conf->objects, object);
|
||||
}
|
||||
@ -556,7 +556,7 @@ gboolean chassis_config_parse_options(chassis_config_t *conf, GList *entries)
|
||||
}
|
||||
|
||||
gboolean chassis_config_mysql_is_object_outdated(chassis_config_t *conf,
|
||||
config_object_t *object,
|
||||
struct config_object_t *object,
|
||||
const char *name)
|
||||
{
|
||||
MYSQL *conn = chassis_config_get_mysql_connection(conf);
|
||||
@ -582,7 +582,7 @@ gboolean chassis_config_mysql_is_object_outdated(chassis_config_t *conf,
|
||||
}
|
||||
|
||||
gboolean chassis_config_local_is_object_outdated(chassis_config_t *conf,
|
||||
config_object_t *object,
|
||||
struct config_object_t *object,
|
||||
const char *name)
|
||||
{
|
||||
GStatBuf sta;
|
||||
@ -599,7 +599,7 @@ gboolean chassis_config_local_is_object_outdated(chassis_config_t *conf,
|
||||
|
||||
gboolean chassis_config_is_object_outdated(chassis_config_t *conf, const char *name)
|
||||
{
|
||||
config_object_t *object = chassis_config_get_object(conf, name);
|
||||
struct config_object_t *object = chassis_config_get_object(conf, name);
|
||||
if (!object) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -615,7 +615,7 @@ gboolean chassis_config_is_object_outdated(chassis_config_t *conf, const char *n
|
||||
|
||||
void chassis_config_update_object_cache(chassis_config_t *conf, const char *name)
|
||||
{
|
||||
config_object_t *object = chassis_config_get_object(conf, name);
|
||||
struct config_object_t *object = chassis_config_get_object(conf, name);
|
||||
if (!object)
|
||||
return;
|
||||
if (object->cache) {
|
||||
|
@ -212,7 +212,7 @@ chassis_option_t *chassis_options_get(GList *opts, const char *long_name)
|
||||
|
||||
#define OPTIONAL_ARG(entry) FALSE
|
||||
|
||||
typedef struct
|
||||
struct opt_change
|
||||
{
|
||||
enum option_type arg_type;
|
||||
gpointer arg_data;
|
||||
@ -234,13 +234,13 @@ typedef struct
|
||||
gchar **data;
|
||||
} array;
|
||||
} allocated;
|
||||
} Change;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct pending_null
|
||||
{
|
||||
gchar **ptr;
|
||||
gchar *value;
|
||||
} PendingNull;
|
||||
};
|
||||
|
||||
static gboolean context_has_h_entry(chassis_options_t *context)
|
||||
{
|
||||
@ -371,13 +371,13 @@ parse_int64(const gchar *arg_name,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Change *
|
||||
static struct opt_change *
|
||||
get_change(chassis_options_t *context,
|
||||
enum option_type arg_type,
|
||||
gpointer arg_data)
|
||||
{
|
||||
GList *list;
|
||||
Change *change = NULL;
|
||||
struct opt_change *change = NULL;
|
||||
|
||||
for(list = context->changes; list != NULL; list = list->next) {
|
||||
change = list->data;
|
||||
@ -386,7 +386,7 @@ get_change(chassis_options_t *context,
|
||||
goto found;
|
||||
}
|
||||
|
||||
change = g_new0(Change, 1);
|
||||
change = g_new0(struct opt_change, 1);
|
||||
change->arg_type = arg_type;
|
||||
change->arg_data = arg_data;
|
||||
|
||||
@ -401,9 +401,9 @@ add_pending_null(chassis_options_t *context,
|
||||
gchar **ptr,
|
||||
gchar *value)
|
||||
{
|
||||
PendingNull *n;
|
||||
struct pending_null *n;
|
||||
|
||||
n = g_new0(PendingNull, 1);
|
||||
n = g_new0(struct pending_null, 1);
|
||||
n->ptr = ptr;
|
||||
n->value = value;
|
||||
|
||||
@ -418,7 +418,7 @@ parse_arg(chassis_options_t *context,
|
||||
GError **error)
|
||||
|
||||
{
|
||||
Change *change;
|
||||
struct opt_change *change;
|
||||
|
||||
g_assert(value || OPTIONAL_ARG(entry) || NO_ARG(entry));
|
||||
|
||||
@ -680,7 +680,7 @@ static void free_changes_list(chassis_options_t *context, gboolean revert)
|
||||
{
|
||||
GList *list;
|
||||
for (list = context->changes; list != NULL; list = list->next) {
|
||||
Change *change = list->data;
|
||||
struct opt_change *change = list->data;
|
||||
|
||||
if (revert) {
|
||||
switch (change->arg_type) {
|
||||
@ -718,7 +718,7 @@ static void free_pending_nulls(chassis_options_t *context, gboolean perform_null
|
||||
{
|
||||
GList *list;
|
||||
for (list = context->pending_nulls; list != NULL; list = list->next) {
|
||||
PendingNull *n = list->data;
|
||||
struct pending_null *n = list->data;
|
||||
|
||||
if (perform_nulls) {
|
||||
if (n->value) {
|
||||
|
@ -82,7 +82,7 @@
|
||||
/**
|
||||
* options of the cetus frontend
|
||||
*/
|
||||
typedef struct {
|
||||
struct chassis_frontend_t{
|
||||
int print_version;
|
||||
int verbose_shutdown;
|
||||
|
||||
@ -140,15 +140,15 @@ typedef struct {
|
||||
char *default_db;
|
||||
|
||||
char *remote_config_url;
|
||||
} chassis_frontend_t;
|
||||
};
|
||||
|
||||
/**
|
||||
* create a new the frontend for the chassis
|
||||
*/
|
||||
chassis_frontend_t *chassis_frontend_new(void) {
|
||||
chassis_frontend_t *frontend;
|
||||
struct chassis_frontend_t *chassis_frontend_new(void) {
|
||||
struct chassis_frontend_t *frontend;
|
||||
|
||||
frontend = g_slice_new0(chassis_frontend_t);
|
||||
frontend = g_slice_new0(struct chassis_frontend_t);
|
||||
frontend->max_files_number = 0;
|
||||
frontend->disable_threads = 0;
|
||||
frontend->is_back_compressed = 0;
|
||||
@ -172,7 +172,7 @@ chassis_frontend_t *chassis_frontend_new(void) {
|
||||
/**
|
||||
* free the frontend of the chassis
|
||||
*/
|
||||
void chassis_frontend_free(chassis_frontend_t *frontend) {
|
||||
void chassis_frontend_free(struct chassis_frontend_t *frontend) {
|
||||
if (!frontend) return;
|
||||
|
||||
if (frontend->keyfile) g_key_file_free(frontend->keyfile);
|
||||
@ -196,14 +196,14 @@ void chassis_frontend_free(chassis_frontend_t *frontend) {
|
||||
|
||||
g_free(frontend->remote_config_url);
|
||||
|
||||
g_slice_free(chassis_frontend_t, frontend);
|
||||
g_slice_free(struct chassis_frontend_t, frontend);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setup the options of the chassis
|
||||
*/
|
||||
int chassis_frontend_set_chassis_options(chassis_frontend_t *frontend, chassis_options_t *opts) {
|
||||
int chassis_frontend_set_chassis_options(struct chassis_frontend_t *frontend, chassis_options_t *opts) {
|
||||
chassis_options_add(opts,
|
||||
"verbose-shutdown",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->verbose_shutdown),
|
||||
@ -436,7 +436,7 @@ static void sigsegv_handler(int G_GNUC_UNUSED signum) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static gboolean check_plugin_mode_valid(chassis_frontend_t *frontend, chassis *srv)
|
||||
static gboolean check_plugin_mode_valid(struct chassis_frontend_t *frontend, chassis *srv)
|
||||
{
|
||||
int i, proxy_mode = 0, sharding_mode = 0;
|
||||
|
||||
@ -469,7 +469,7 @@ static void g_query_cache_item_free(gpointer q) {
|
||||
#define DUP_STRING(STR, DEFAULT) \
|
||||
(STR) ? g_strdup(STR) : ((DEFAULT) ? g_strdup(DEFAULT) : NULL)
|
||||
|
||||
static void init_parameters(chassis_frontend_t *frontend, chassis *srv)
|
||||
static void init_parameters(struct chassis_frontend_t *frontend, chassis *srv)
|
||||
{
|
||||
srv->default_username = DUP_STRING(frontend->default_username, NULL);
|
||||
srv->default_charset = DUP_STRING(frontend->default_charset, NULL);
|
||||
@ -546,7 +546,7 @@ static void init_parameters(chassis_frontend_t *frontend, chassis *srv)
|
||||
|
||||
|
||||
static void
|
||||
release_resouces_when_exit(chassis_frontend_t *frontend, chassis *srv, GError *gerr,
|
||||
release_resouces_when_exit(struct chassis_frontend_t *frontend, chassis *srv, GError *gerr,
|
||||
chassis_options_t *opts, chassis_log *log)
|
||||
{
|
||||
if (gerr) g_error_free(gerr);
|
||||
@ -562,7 +562,7 @@ release_resouces_when_exit(chassis_frontend_t *frontend, chassis *srv, GError *g
|
||||
}
|
||||
|
||||
static void
|
||||
resolve_path(chassis *srv, chassis_frontend_t *frontend)
|
||||
resolve_path(chassis *srv, struct chassis_frontend_t *frontend)
|
||||
{
|
||||
/*
|
||||
* these are used before we gathered all the options
|
||||
@ -635,7 +635,7 @@ int main_cmdline(int argc, char **argv) {
|
||||
static struct sigaction sigsegv_sa;
|
||||
#endif
|
||||
/* read the command-line options */
|
||||
chassis_frontend_t *frontend = NULL;
|
||||
struct chassis_frontend_t *frontend = NULL;
|
||||
chassis_options_t *opts = NULL;
|
||||
|
||||
GError *gerr = NULL;
|
||||
|
@ -36,32 +36,32 @@ static GHashTable *shard_conf_vdb_map = NULL;
|
||||
static GList *shard_conf_single_tables = NULL;
|
||||
|
||||
|
||||
typedef struct sharding_database_t {
|
||||
struct sharding_database_t {
|
||||
char *name;
|
||||
GHashTable *tables; /* <char *, const sharding_table_t *> */
|
||||
} sharding_database_t;
|
||||
};
|
||||
|
||||
static sharding_database_t *sharding_database_new(const char *name)
|
||||
static struct sharding_database_t *sharding_database_new(const char *name)
|
||||
{
|
||||
sharding_database_t *db = g_new0(sharding_database_t, 1);
|
||||
struct sharding_database_t *db = g_new0(struct sharding_database_t, 1);
|
||||
db->tables = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
db->name = g_strdup(name);
|
||||
return db;
|
||||
}
|
||||
|
||||
static void sharding_database_free(sharding_database_t *db)
|
||||
static void sharding_database_free(struct sharding_database_t *db)
|
||||
{
|
||||
g_free(db->name);
|
||||
g_hash_table_destroy(db->tables);
|
||||
g_free(db);
|
||||
}
|
||||
|
||||
static void sharding_database_add_table(sharding_database_t *db, sharding_table_t *table)
|
||||
static void sharding_database_add_table(struct sharding_database_t *db, sharding_table_t *table)
|
||||
{
|
||||
g_hash_table_insert(db->tables, table->name->str, table);
|
||||
}
|
||||
|
||||
static sharding_table_t *sharding_database_get_table(sharding_database_t *db,
|
||||
static sharding_table_t *sharding_database_get_table(struct sharding_database_t *db,
|
||||
const char *table)
|
||||
{
|
||||
if (!table)
|
||||
@ -165,12 +165,12 @@ static gboolean sharding_vdb_is_valid(sharding_vdb_t *vdb)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static sharding_database_t *sharding_vdb_get_database(sharding_vdb_t *vdb,
|
||||
static struct sharding_database_t *sharding_vdb_get_database(sharding_vdb_t *vdb,
|
||||
const char *db_name)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < vdb->databases->len; ++i) {
|
||||
sharding_database_t *db = g_ptr_array_index(vdb->databases, i);
|
||||
struct sharding_database_t *db = g_ptr_array_index(vdb->databases, i);
|
||||
if (strcasecmp(db_name, db->name) == 0) {
|
||||
return db;
|
||||
}
|
||||
@ -178,10 +178,10 @@ static sharding_database_t *sharding_vdb_get_database(sharding_vdb_t *vdb,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static sharding_database_t *sharding_vdb_add_database(sharding_vdb_t *vdb,
|
||||
static struct sharding_database_t *sharding_vdb_add_database(sharding_vdb_t *vdb,
|
||||
const char *name)
|
||||
{
|
||||
sharding_database_t *db = sharding_database_new(name);
|
||||
struct sharding_database_t *db = sharding_database_new(name);
|
||||
g_ptr_array_add(vdb->databases, db);
|
||||
return db;
|
||||
}
|
||||
@ -311,7 +311,7 @@ sharding_table_t *shard_conf_get_info(const char *db_name, const char *table)
|
||||
if (!vdb) {
|
||||
return NULL;
|
||||
}
|
||||
sharding_database_t *db = sharding_vdb_get_database(vdb, db_name);
|
||||
struct sharding_database_t *db = sharding_vdb_get_database(vdb, db_name);
|
||||
if (!db) {
|
||||
return NULL;
|
||||
}
|
||||
@ -342,13 +342,13 @@ GPtrArray *shard_conf_get_fixed_group(GPtrArray *groups, const char *db, guint32
|
||||
return groups;
|
||||
}
|
||||
|
||||
typedef struct single_table_t { /* single table only resides on 1 group */
|
||||
struct single_table_t { /* single table only resides on 1 group */
|
||||
GString *name;
|
||||
GString *db;
|
||||
GString *group;
|
||||
} single_table_t;
|
||||
};
|
||||
|
||||
void single_table_free(single_table_t *t)
|
||||
void single_table_free(struct single_table_t *t)
|
||||
{
|
||||
if (t) {
|
||||
g_string_free(t->name, TRUE);
|
||||
@ -422,7 +422,7 @@ gboolean shard_conf_try_setup(GList *vdbs, GList *tables, GList *single_tables)
|
||||
}
|
||||
|
||||
/* collect database into vdb */
|
||||
sharding_database_t *database = sharding_vdb_get_database(vdb, table->db->str);
|
||||
struct sharding_database_t *database = sharding_vdb_get_database(vdb, table->db->str);
|
||||
if (!database) {
|
||||
database = sharding_vdb_add_database(vdb, table->db->str);
|
||||
}
|
||||
@ -483,11 +483,11 @@ gboolean shard_conf_load(char *json_str)
|
||||
return success;
|
||||
}
|
||||
|
||||
static single_table_t *shard_conf_get_single_table(const char *db, const char *name)
|
||||
static struct single_table_t *shard_conf_get_single_table(const char *db, const char *name)
|
||||
{
|
||||
GList *l = shard_conf_single_tables;
|
||||
for (; l; l = l->next) {
|
||||
single_table_t *t = l->data;
|
||||
struct single_table_t *t = l->data;
|
||||
if (strcasecmp(t->name->str, name) == 0
|
||||
&& strcasecmp(t->db->str, db) == 0) {
|
||||
return t;
|
||||
@ -498,7 +498,7 @@ static single_table_t *shard_conf_get_single_table(const char *db, const char *n
|
||||
|
||||
gboolean shard_conf_is_single_table(const char *db, const char *name)
|
||||
{
|
||||
single_table_t *t = shard_conf_get_single_table(db, name);
|
||||
struct single_table_t *t = shard_conf_get_single_table(db, name);
|
||||
return t != NULL;
|
||||
}
|
||||
|
||||
@ -517,7 +517,7 @@ static gboolean shard_conf_group_contains(GPtrArray *groups, GString *match)
|
||||
GPtrArray *shard_conf_get_single_table_distinct_group(GPtrArray *groups,
|
||||
const char *db, const char *name)
|
||||
{
|
||||
single_table_t *t = shard_conf_get_single_table(db, name);
|
||||
struct single_table_t *t = shard_conf_get_single_table(db, name);
|
||||
if (t && !shard_conf_group_contains(groups, t->group)) {
|
||||
g_ptr_array_add(groups, t->group);
|
||||
}
|
||||
@ -783,7 +783,7 @@ static GList *parse_single_tables(cJSON *root)
|
||||
cJSON *db = cJSON_GetObjectItem(p, "db");
|
||||
cJSON *group = cJSON_GetObjectItem(p, "group");
|
||||
if (name && db && group) {
|
||||
single_table_t *table = g_new0(single_table_t, 1);
|
||||
struct single_table_t *table = g_new0(struct single_table_t, 1);
|
||||
table->group = g_string_new(group->valuestring);
|
||||
table->db = g_string_new(db->valuestring);
|
||||
table->name = g_string_new(name->valuestring);
|
||||
|
Loading…
Reference in New Issue
Block a user