cetus/src/sharding-config.h

148 lines
4.4 KiB
C
Raw Normal View History

2018-03-14 11:27:27 +08:00
/* $%BEGINLICENSE%$
Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; version 2 of the
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
$%ENDLICENSE%$ */
2018-03-06 14:00:39 +08:00
#ifndef __SHARDING_CONFIG_H__
#define __SHARDING_CONFIG_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "glib-ext.h"
#include "cetus-util.h"
#include "chassis-config.h"
2018-03-06 14:00:39 +08:00
enum shardkey_type_t {
SHARD_DATA_TYPE_UNSUPPORTED=0,
SHARD_DATA_TYPE_INT,
SHARD_DATA_TYPE_STR,
SHARD_DATA_TYPE_DATE,
SHARD_DATA_TYPE_DATETIME,
};
2018-03-06 14:00:39 +08:00
enum sharding_method_t {
SHARD_METHOD_UNKNOWN = -1,
SHARD_METHOD_RANGE = 0,
SHARD_METHOD_HASH = 1,
SHARD_METHOD_LIST = 2
};
typedef struct sharding_vdb_t sharding_vdb_t;
typedef struct sharding_table_t sharding_table_t;
#define MAX_HASH_VALUE_COUNT 1024
typedef struct sharding_partition_t {
2018-03-20 14:19:44 +08:00
char *value; /* high range OR hash value */
char *low_value; /* low range OR null */
2018-03-06 14:00:39 +08:00
int hash_count;
2018-03-20 14:19:44 +08:00
BitArray hash_set[MAX_HASH_VALUE_COUNT / 32]; /* hash values of this partition */
2018-03-06 14:00:39 +08:00
GString *group_name;
enum sharding_method_t method;
enum shardkey_type_t key_type;
2018-03-06 14:00:39 +08:00
} sharding_partition_t;
gboolean sharding_partition_contain_hash(sharding_partition_t *, int);
void sharding_partition_free(sharding_partition_t *);
2018-03-06 14:00:39 +08:00
//gboolean sharding_partition_cover_range(sharding_partition_t *, );
void sharding_partition_to_string(sharding_partition_t *, GString*);
2018-03-06 14:00:39 +08:00
struct sharding_vdb_t {
int id;
enum sharding_method_t method;
int key_type;
int logic_shard_num;
2018-03-20 14:19:44 +08:00
GPtrArray *partitions; /* GPtrArray<sharding_partition_t *> */
2018-03-06 14:00:39 +08:00
};
void sharding_vdb_partitions_to_string(sharding_vdb_t* vdb, GString* repr);
2018-03-06 14:00:39 +08:00
struct sharding_table_t {
GString *schema;
2018-03-06 14:00:39 +08:00
GString *name;
GString *pkey;
int shard_key_type;
int vdb_id;
struct sharding_vdb_t *vdb_ref;
2018-03-06 14:00:39 +08:00
};
2018-07-18 18:26:55 +08:00
struct single_table_t { /* single table only resides on 1 group */
GString *name;
GString *schema;
GString *group;
};
int sharding_key_type(const char *str);
const char* sharding_key_type_str(int type);
GPtrArray *shard_conf_get_any_group(GPtrArray *groups, const char *db, const char *table);
2018-03-06 14:00:39 +08:00
GPtrArray *shard_conf_get_all_groups(GPtrArray *groups);
2018-03-06 14:00:39 +08:00
/* same fixture will get same group */
GPtrArray *shard_conf_get_fixed_group(GPtrArray *groups, guint32 fixture);
2018-03-06 14:00:39 +08:00
GPtrArray *shard_conf_get_table_groups(GPtrArray *visited_groups,
const char *db, const char *table);
2018-03-06 14:00:39 +08:00
gboolean shard_conf_is_shard_table(const char *db, const char *table);
gboolean shard_conf_is_single_table(const char *db, const char *table);
2018-03-20 14:19:44 +08:00
GPtrArray *shard_conf_get_single_table_distinct_group(GPtrArray *groups, const char *db, const char *table);
2018-03-06 14:00:39 +08:00
sharding_table_t *shard_conf_get_info(const char *db, const char *table);
/**
* similar with shard_conf_get_table_groups
* @return array of group_item_t *
*/
2018-03-20 14:19:44 +08:00
GPtrArray *shard_conf_table_partitions(GPtrArray *partitions, const char *db, const char *table);
2018-03-06 14:00:39 +08:00
/**
* find partition by group name
* special name "all" will get all groups
*/
void shard_conf_find_groups(GPtrArray *groups, const char *match);
2018-03-06 14:00:39 +08:00
gboolean shard_conf_load(char *, int);
2018-03-06 14:00:39 +08:00
void shard_conf_destroy(void);
gboolean shard_conf_add_vdb(sharding_vdb_t* vdb);
sharding_vdb_t *sharding_vdb_new();
gboolean sharding_vdb_is_valid(sharding_vdb_t *vdb, int num_groups);
void sharding_vdb_free(sharding_vdb_t *vdb);
gboolean shard_conf_add_sharded_table(sharding_table_t* t);
GList* shard_conf_get_vdb_list();
2018-07-18 18:26:55 +08:00
GList* shard_conf_get_tables(); /* ! g_list_free() after use */
GList* shard_conf_get_single_tables();
gboolean shard_conf_write_json(chassis_config_t* conf_manager);
2018-07-18 18:26:55 +08:00
gboolean shard_conf_add_single_table(const char* schema,
const char* table, const char* group);
2018-03-06 14:00:39 +08:00
#endif /* __SHARDING_CONFIG_H__ */