item_uthash -> item_rcu && add foreign cont dir API
This commit is contained in:
@@ -24,8 +24,7 @@ enum maat_operation {
|
||||
MAAT_OP_RENEW_TIMEOUT //Rule expire time is changed to now+cmd->expire_after
|
||||
};
|
||||
|
||||
struct maat_cmd_line
|
||||
{
|
||||
struct maat_cmd_line {
|
||||
const char *table_name;
|
||||
const char *table_line;
|
||||
long long rule_id; // for MAAT_OP_DEL, only rule_id and table_name are necessary.
|
||||
@@ -43,6 +42,15 @@ int maat_cmd_set_line(struct maat *maat_instance, const struct maat_cmd_line *li
|
||||
|
||||
long long maat_cmd_incrby(struct maat *maat_instance, const char *key, int increment);
|
||||
|
||||
long long maat_cmd_get_config_version(struct maat *maat_instance);
|
||||
|
||||
/* True(1), False(0) */
|
||||
int maat_cmd_config_is_updating(struct maat *maat_instance);
|
||||
|
||||
char *maat_cmd_str_escape(char *dst, int size, const char *src);
|
||||
|
||||
int maat_cmd_flushDB(struct maat *maat_instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,10 +23,9 @@ extern "C"
|
||||
|
||||
struct maat_options {
|
||||
char instance_name[NAME_MAX];
|
||||
char foreign_cont_dir[NAME_MAX];
|
||||
size_t nr_worker_threads;
|
||||
|
||||
char *accept_tags;
|
||||
|
||||
int rule_effect_interval_ms;
|
||||
int rule_update_checking_interval_ms;
|
||||
int gc_timeout_ms;
|
||||
|
||||
@@ -17,6 +17,7 @@ extern "C"
|
||||
#endif
|
||||
|
||||
#include "cJSON/cJSON.h"
|
||||
#include "rcu_hash.h"
|
||||
#include "maat.h"
|
||||
#include "maat_kv.h"
|
||||
#include "maat_rule.h"
|
||||
@@ -49,6 +50,8 @@ void *compile_runtime_new(void *compile_schema, int max_thread_num,
|
||||
struct log_handle *logger);
|
||||
void compile_runtime_free(void *compile_runtime);
|
||||
|
||||
void compile_runtime_init(void *compile_runtime, struct maat_runtime *maat_rt);
|
||||
|
||||
int compile_runtime_update(void *compile_runtime, void *compile_schema,
|
||||
const char *line, int valid_column);
|
||||
int compile_runtime_commit(void *compile_runtime, const char *table_name);
|
||||
@@ -82,7 +85,7 @@ struct maat_compile_state;
|
||||
struct maat_compile_state *maat_compile_state_new(int thread_id);
|
||||
void maat_compile_state_free(struct maat_compile_state *compile_state);
|
||||
|
||||
int maat_compile_state_update(struct maat_item *item_hash, int vtable_id,
|
||||
int maat_compile_state_update(struct rcu_hash_table *item_htable, int vtable_id,
|
||||
long long *hit_item_ids, size_t hit_item_cnt,
|
||||
size_t *n_hit_group_id, struct maat_state *state);
|
||||
|
||||
|
||||
@@ -18,18 +18,13 @@ extern "C"
|
||||
|
||||
#include "maat.h"
|
||||
#include "rcu_hash.h"
|
||||
#include "maat_garbage_collection.h"
|
||||
|
||||
struct ex_data_container {
|
||||
struct ex_container {
|
||||
void *ex_data;
|
||||
void *custom_data;
|
||||
};
|
||||
|
||||
struct ex_container_ctx {
|
||||
int table_id;
|
||||
void (*custom_data_free)(void *custom_data);
|
||||
struct ex_data_schema *ex_schema;
|
||||
};
|
||||
|
||||
struct ex_data_schema {
|
||||
maat_ex_new_func_t *new_func;
|
||||
maat_ex_free_func_t *free_func;
|
||||
@@ -38,12 +33,18 @@ struct ex_data_schema {
|
||||
void *argp;
|
||||
};
|
||||
|
||||
struct ex_container_schema {
|
||||
int table_id;
|
||||
void (*custom_data_free)(void *custom_data);
|
||||
struct ex_data_schema *ex_schema;
|
||||
};
|
||||
|
||||
struct ex_data_runtime;
|
||||
|
||||
/* ex_data_runtime API */
|
||||
struct ex_data_runtime *
|
||||
ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
|
||||
struct log_handle *logger);
|
||||
struct maat_garbage_bin *garbage_bin, struct log_handle *logger);
|
||||
void ex_data_runtime_free(struct ex_data_runtime *ex_data_rt);
|
||||
void ex_data_runtime_commit(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
@@ -67,42 +68,45 @@ void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *schema);
|
||||
|
||||
/* set user_ctx API */
|
||||
void ex_data_runtime_set_ex_container_ctx(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_ctx *container_ctx);
|
||||
void ex_data_runtime_set_ex_container_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_schema *container_schema);
|
||||
|
||||
struct ex_container_ctx *
|
||||
ex_data_runtime_get_ex_container_ctx(struct ex_data_runtime *ex_data_rt);
|
||||
struct ex_container_schema *
|
||||
ex_data_runtime_get_ex_container_schema(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
struct ex_data_container *ex_data_container_new(void *ex_data, void *custom_data);
|
||||
void ex_data_container_free(void *ctx, void *data);
|
||||
struct ex_container *ex_container_new(void *ex_data, void *custom_data);
|
||||
void ex_container_free(void *ctx, void *data);
|
||||
|
||||
/* ex_data_runtime ex data API */
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, const char *row,
|
||||
const char *key, size_t key_len);
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
|
||||
const char *row, const char *key,
|
||||
size_t key_len);
|
||||
|
||||
int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len,
|
||||
struct ex_data_container *ex_container);
|
||||
struct ex_container *ex_container);
|
||||
|
||||
int ex_data_runtime_del_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len);
|
||||
|
||||
size_t ex_data_runtime_list_updating_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_container ***ex_container);
|
||||
size_t ex_data_runtime_list_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container ***ex_container);
|
||||
|
||||
size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
int ex_data_runtime_is_updating(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len);
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_container *ex_container);
|
||||
struct ex_container *ex_container);
|
||||
|
||||
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len);
|
||||
|
||||
size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,6 @@ int ip_runtime_update(void *ip_runtime, void *ip_schema,
|
||||
const char *line, int valid_column);
|
||||
int ip_runtime_commit(void *ip_runtime, const char *table_name);
|
||||
|
||||
struct ex_data_runtime *ip_runtime_get_ex_data_rt(struct ip_runtime *ip_rt);
|
||||
|
||||
/* ip runtime scan API */
|
||||
int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
uint8_t *ip_addr, int vtable_id, struct maat_state *state);
|
||||
|
||||
@@ -24,11 +24,13 @@ struct maat_kv_store *maat_kv_store_new(void);
|
||||
|
||||
void maat_kv_store_free(struct maat_kv_store *store);
|
||||
|
||||
int maat_kv_register(struct maat_kv_store *store, const char *key, int value);
|
||||
int maat_kv_register(struct maat_kv_store *store, const char *key, long long value);
|
||||
|
||||
int maat_kv_read(struct maat_kv_store *store, const char *key, int *value);
|
||||
int maat_kv_read(struct maat_kv_store *store, const char *key, long long *value);
|
||||
|
||||
int maat_kv_read_unNull(struct maat_kv_store *store, const char *key, size_t key_sz, int *value);
|
||||
int maat_kv_read_unNull(struct maat_kv_store *store, const char *key, size_t key_sz, long long *value);
|
||||
|
||||
int maat_kv_write(struct maat_kv_store *store, const char *key, long long value);
|
||||
|
||||
struct maat_kv_store *maat_kv_store_duplicate(struct maat_kv_store *store);
|
||||
|
||||
|
||||
@@ -37,14 +37,14 @@ extern "C"
|
||||
#define MAX_COMPILE_TABLE_NUM 16
|
||||
#define MAX_PHYSICAL_TABLE_NUM 16
|
||||
|
||||
#define MAAT_UPDATE_TYPE_NONE 0
|
||||
#define MAAT_UPDATE_TYPE_FULL 1
|
||||
#define MAAT_UPDATE_TYPE_INC 2
|
||||
#define DISTRICT_ANY -1
|
||||
#define DISTRICT_UNKNOWN -2
|
||||
|
||||
#define DISTRICT_ANY -1
|
||||
#define DISTRICT_UNKNOWN -2
|
||||
#define MAX_DISTRICT_STR 128
|
||||
#define INVALID_VERSION -1
|
||||
|
||||
#define MAX_DISTRICT_STR 128
|
||||
#define mr_region_id_var "SEQUENCE_REGION"
|
||||
#define mr_group_id_var "SEQUENCE_GROUP"
|
||||
|
||||
enum last_scan_flag {
|
||||
LAST_SCAN_UNSET,
|
||||
@@ -63,7 +63,7 @@ struct maat_item_inner {
|
||||
long long magic_num;
|
||||
long long item_id;
|
||||
long long group_id;
|
||||
int district_id;
|
||||
long long district_id;
|
||||
int expr_id_cnt;
|
||||
int expr_id_lb; //low boundary
|
||||
int expr_id_ub; //up boundary
|
||||
@@ -72,8 +72,9 @@ struct maat_item_inner {
|
||||
struct maat_item {
|
||||
long long item_id;
|
||||
long long group_id;
|
||||
UT_hash_handle hh;
|
||||
|
||||
void *user_data;
|
||||
void (*user_data_free)(void *data);
|
||||
};
|
||||
|
||||
#define COMPILE_RULE_MAGIC 0x1a2b3c4d
|
||||
@@ -105,6 +106,7 @@ struct maat_runtime {
|
||||
size_t max_table_num;
|
||||
|
||||
uint32_t rule_num;
|
||||
struct maat_kv_store *sequence_map;
|
||||
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
struct log_handle *logger;
|
||||
@@ -216,6 +218,9 @@ struct maat {
|
||||
long long load_specific_version; //Default: Load the Latest. Only valid in redis mode, and maybe failed for too old
|
||||
char foreign_cont_dir[NAME_MAX];
|
||||
|
||||
/* internal state */
|
||||
long long new_version;
|
||||
|
||||
/* statistics */
|
||||
long long line_cmd_acc_num;
|
||||
|
||||
@@ -235,7 +240,7 @@ struct maat_state {
|
||||
char compile_tables[MAX_COMPILE_TABLE_NUM][NAME_MAX]; //caller can select compile table to scan
|
||||
unsigned char is_set_district;
|
||||
unsigned char is_last_scan;
|
||||
int district_id; //-1: Any District; -2: Unkonwn District;
|
||||
long long district_id; //-1: Any District; -2: Unkonwn District;
|
||||
int scan_cnt;
|
||||
struct maat_compile_state *compile_state;
|
||||
};
|
||||
@@ -246,11 +251,11 @@ size_t parse_accept_tag(const char *value, struct rule_tag **result, struct log_
|
||||
|
||||
int compare_accept_tag(const char *value, const struct rule_tag *accept_tags, size_t n_accept_tag);
|
||||
|
||||
struct maat_item *maat_item_new(long long item_id, long long group_id, void *user_data);
|
||||
struct maat_item *maat_item_new(long long item_id, long long group_id, void *user_data, void (*user_data_free)(void *));
|
||||
|
||||
void maat_item_free(struct maat_item *item, void (* item_user_data_free)(void *));
|
||||
void maat_item_free(void *user_ctx, void *maat_item);
|
||||
|
||||
struct maat_item_inner *maat_item_inner_new(long long group_id, long long item_id, int district_id);
|
||||
struct maat_item_inner *maat_item_inner_new(long long group_id, long long item_id, long long district_id);
|
||||
|
||||
void maat_item_inner_free(void *item_inner);
|
||||
|
||||
@@ -262,6 +267,8 @@ void maat_finish_cb(void *u_para);
|
||||
|
||||
void *rule_monitor_loop(void *arg);
|
||||
|
||||
long long maat_runtime_get_sequence(struct maat_runtime *maat_rt, const char *key);
|
||||
|
||||
void maat_read_full_config(struct maat *maat_instance);
|
||||
|
||||
/* maat command API for internal */
|
||||
|
||||
@@ -68,8 +68,8 @@ size_t table_manager_accept_tags_count(struct table_manager *tbl_mgr);
|
||||
int table_manager_accept_tags_match(struct table_manager *tbl_mgr, const char *tags);
|
||||
|
||||
int table_manager_set_scan_district(struct table_manager *tbl_mgr, const char *district_str,
|
||||
size_t district_str_len, int *district_id);
|
||||
int table_manager_get_district_id(struct table_manager *tbl_mgr, const char *district);
|
||||
size_t district_str_len, long long *district_id);
|
||||
long long table_manager_get_district_id(struct table_manager *tbl_mgr, const char *district);
|
||||
|
||||
void *table_manager_get_schema(struct table_manager *tbl_mgr, int table_id);
|
||||
void *table_manager_get_runtime(struct table_manager *tbl_mgr, int table_id);
|
||||
|
||||
@@ -50,8 +50,23 @@ void rcu_hash_del(struct rcu_hash_table *htable, const char *key, size_t key_len
|
||||
*/
|
||||
void *rcu_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_len);
|
||||
|
||||
void *rcu_hash_updating_find(struct rcu_hash_table *htable, const char *key, size_t key_len);
|
||||
|
||||
/**
|
||||
* @brief list all effective nodes
|
||||
*
|
||||
* @retval the number of effective nodes
|
||||
*/
|
||||
size_t rcu_hash_list(struct rcu_hash_table *htable, void ***data_array);
|
||||
|
||||
size_t rcu_hash_count(struct rcu_hash_table *htable);
|
||||
size_t rcu_hash_updating_count(struct rcu_hash_table *htable);
|
||||
|
||||
/**
|
||||
* @brief if rcu hash is updating
|
||||
*
|
||||
* @retval True(1) False(0)
|
||||
*/
|
||||
int rcu_hash_is_updating(struct rcu_hash_table *htable);
|
||||
|
||||
/**
|
||||
* @brief make add/del effective
|
||||
@@ -60,8 +75,6 @@ void rcu_hash_commit(struct rcu_hash_table *htable);
|
||||
|
||||
size_t rcu_hash_garbage_queue_len(struct rcu_hash_table *htable);
|
||||
|
||||
size_t rcu_hash_list_updating_data(struct rcu_hash_table *htable, void ***data_array);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user