代码适配Maat command、maat json。

This commit is contained in:
zhengchao
2020-06-13 21:05:42 +08:00
parent 7e1cb56d4f
commit 2c80ba4c0a
22 changed files with 935 additions and 1513 deletions

View File

@@ -1,8 +1,8 @@
#pragma once
struct Maat_garbage_bin{};
struct Maat_garbage_bin* Maat_garbage_bin_new(void);
struct Maat_garbage_bin* Maat_garbage_bin_new(int default_timeout);
void Maat_garbage_bin_free(struct Maat_garbage_bin* bin);
void Maat_garbage_bag(struct Maat_garbage_bin* bin, void* garbage, int timeout, void (* func)(void *));
void Maat_garbage_bagging(struct Maat_garbage_bin* bin, void* garbage, void (* func)(void *));
void Maat_garbage_collect_routine(struct Maat_garbage_bin* bin);

View File

@@ -1,6 +1,52 @@
#pragma once
#include "Maat_rule.h"
#include <sys/queue.h>
struct Maat_hierarchy;
struct Maat_hierarchy* Maat_hierarchy_new(int thread_num, void* mesa_handle_logger);
void Maat_hierarchy_free(struct Maat_hierarchy* hier);
void Maat_hierarchy_set_compile_user_data_free_func(struct Maat_hierarchy* hier, void (* func)(void *));
void Maat_hierarchy_set_region_user_data_free_func(struct Maat_hierarchy* hier, void (* func)(void *));
struct Maat_hierarchy_compile_mid;
struct Maat_hierarchy_compile_mid* Maat_hierarchy_compile_mid_new(struct Maat_hierarchy* hier, int thread_num);
void Maat_hierarchy_compile_mid_free(struct Maat_hierarchy_compile_mid* mid);
void Maat_hierarchy_compile_mid_udpate(struct Maat_hierarchy_compile_mid* mid, int region_id, int virtual_table_id, int Nth_scan, int Nth_region_result);
void Maat_hierarchy_compile_user_data_iterate(struct Maat_hierarchy* hier, void (*callback)(void *user_data, void* apram), void* param);
int Maat_hierarchy_compile_mid_has_NOT_clause(struct Maat_hierarchy_compile_mid* mid);
struct Maat_hierarchy_hit_path
{
int Nth_hit_region;
struct Maat_hit_path_t path;
TAILQ_ENTRY(Maat_hierarchy_hit_path) entries;
};
void Maat_hit_path_init(struct Maat_hit_path_t* hit_path);
size_t Maat_hierarchy_hit_path_select0(const struct Maat_hierarchy_compile_mid* mid, struct Maat_hit_path_t* condition,
struct Maat_hierarchy_hit_path** hit_paths, size_t n_path);
int Maat_hierarchy_compile_add(struct Maat_hierarchy* hier, int compile_id, int declared_clause_num, void* user_data);
int Maat_hierarchy_compile_remove(struct Maat_hierarchy * hier, int compile_id);
void* Maat_hierarchy_compile_dettach_user_data(struct Maat_hierarchy* hier, int compile_id);
void* Maat_hierarchy_compile_read_user_data(struct Maat_hierarchy* hier, int compile_id);
void* Maat_hierarchy_region_dettach_user_data(struct Maat_hierarchy* hier, int region_id);
int Maat_hierarchy_add_group_to_compile(struct Maat_hierarchy* hier, int group_id, int vt_id, int not_flag, int Nth_clause, int compile_id);
int Maat_hierarchy_remove_group_from_compile(struct Maat_hierarchy* hier, int group_id, int vt_id, int not_flag, int Nth_clause, int compile_id);
int Maat_hierarchy_add_group_to_group(struct Maat_hierarchy* hier, int group_id, int superior_group_id);
int Maat_hierarchy_remove_group_from_group(struct Maat_hierarchy* hier, int group_id, int superior_group_id);
int Maat_hierarchy_add_region_to_group(struct Maat_hierarchy* hier, int group_id, int region_id, int table_id, void* user_data);
int Maat_hierarchy_remove_region_from_group(struct Maat_hierarchy* hier, int group_id, int region_id);
int Maat_hierarchy_rebuild(struct Maat_hierarchy* hier);
int Maat_hierarchy_region_compile(struct Maat_hierarchy_compile_mid* mid, int is_last_compile, void** user_data_array, size_t ud_array_sz);

View File

@@ -11,10 +11,8 @@
#include <MESA/field_stat2.h>
#include <MESA/rulescan.h>
#include "dynamic_array.h"
#include "bool_matcher.h"
#include "hiredis.h"
#include "IPMatcher.h"
#include "igraph/igraph.h"
#include "stream_fuzzy_hash.h"
#include "gram_index_engine.h"
#include "alignment_int64.h"
@@ -139,13 +137,6 @@ struct op_expr_t
int rule_type;
};
struct region_group_relation
{
int region_id;
int group_id;
int array_idx;
};
struct Maat_region_inner
{
int region_id;
@@ -159,51 +150,6 @@ struct Maat_region_inner
};
struct Maat_group_inner
{
int group_id;
int table_id;
int region_boundary;
int region_cnt;
int ref_by_parent_cnt;
int ref_by_children_cnt;
char* group_name;
int ref_by_compile_cnt;
int vertex_id;
size_t top_group_cnt;
long long* top_groups;
dynamic_array_t *regions;
pthread_mutex_t mutex;
};
struct _compile_result_t
{
int compile_id;
struct bool_expr group_set;
};
struct Maat_hit_path_inner
{
int Nth_hit_region;
struct Maat_hit_path_t path;
TAILQ_ENTRY(Maat_hit_path_inner) entries;
};
TAILQ_HEAD(hit_path_q, Maat_hit_path_inner);
struct scan_hit_status
{
size_t hit_path_cnt;
struct hit_path_q hit_path_qhead;
size_t all_hit_group_cnt;
size_t all_hit_group_array_sz;
unsigned long long *all_hit_group_array;
char not_grp_compile_hitted_flag;
};
struct _OUTER_scan_status_t
{
struct _Maat_feather_t* feather;
@@ -213,18 +159,8 @@ struct _OUTER_scan_status_t
int district_id;
int scan_cnt;
struct Maat_hierarchy_compile_mid* compile_mid;
struct scan_hit_status* inner;
};
enum maat_garbage_type
{
GARBAGE_SCANNER=0,
GARBAGE_GROUP_RULE,
GARBAGE_COMPILE_RULE,
GARBAGE_COMPILE_INNER,
GARBAGE_BOOL_MATCHER,
GARBAGE_MAP_STR2INT,
GARBAGE_IP_MATCHER
};
struct iconv_handle_t
{
int is_initialized;
@@ -356,6 +292,8 @@ struct _Maat_feather_t
char instance_name[MAX_TABLE_NAME_LEN];
char table_info_fn[MAX_TABLE_NAME_LEN];
char compile_tn[MAX_TABLE_NAME_LEN];
char group2compile_tn[MAX_TABLE_NAME_LEN];
char group2group_tn[MAX_TABLE_NAME_LEN];
char group_tn[MAX_TABLE_NAME_LEN];
pthread_mutex_t background_update_mutex;
char decrypt_key[MAX_TABLE_NAME_LEN];
@@ -386,7 +324,7 @@ struct _Maat_feather_t
int fs_status_id[MAX_MAAT_STAT_NUM];
int fs_column_id[MAX_MAAT_STAT_NUM];
mcore_long_t outer_mid_cnt;
mcore_long_t inner_mid_cnt;
mcore_long_t compile_mid_cnt;
mcore_long_t hit_cnt;
mcore_long_t thread_call_cnt;//size indicate by scan_thread_num,
mcore_long_t not_grp_hit_cnt;
@@ -401,25 +339,7 @@ struct _Maat_feather_t
long long cmd_acc_num;
long long line_cmd_acc_num;
};
struct _maat_garbage_t
{
enum maat_garbage_type type;
time_t create_time;
int expire_after;
int ok_times;
union
{
struct Maat_scanner* scanner;
struct Maat_group_inner* group_rule;
struct Maat_compile_rule* compile_rule;
struct Maat_compile_inner * compile_group_relation;
struct bool_matcher* bool_matcher;
struct ip_matcher* a_ip_matcher;
void * raw;
MESA_htable_handle str2int_map;
char* filename;
};
};
struct foreign_key
{
int column;
@@ -439,10 +359,7 @@ struct serial_rule_t //rm= Redis Maat
struct foreign_key* f_keys;
};
int parse_accept_tag(const char* value, struct rule_tag** result, void* logger);
void garbage_bagging(enum maat_garbage_type type,void *p,MESA_lqueue_head garbage_q);
void garbage_bagging_with_timeout(enum maat_garbage_type type,void *p, int timeout, MESA_lqueue_head garbage_q);
void garbage_bury(MESA_lqueue_head garbage_q,void *logger);
void make_group_set(struct Maat_compile_inner* compile_rule, struct bool_expr* a_set, unsigned char *has_not);
void maat_start_cb(long long new_version,int update_type,void*u_para);
int maat_update_cb(const char* table_name,const char* line,void *u_para);
void maat_finish_cb(void* u_para);

View File

@@ -154,7 +154,9 @@ int Maat_table_add_callback_func(struct Maat_table_manager* table_mgr,
Maat_finish_callback_t *finish,//u_para
void* u_para);
int Maat_table_get_compile_table_name(struct Maat_table_manager* table_mgr, char* buff, size_t sz);
int Maat_table_get_group_table_name(struct Maat_table_manager* table_mgr, char* buff, size_t sz);
int Maat_table_get_group2compile_table_name(struct Maat_table_manager* table_mgr, char* buff, size_t sz);
int Maat_table_get_group2group_table_name(struct Maat_table_manager* table_mgr, char* buff, size_t sz);
const char* Maat_table_get_name_by_id(struct Maat_table_manager* table_mgr, int table_id);
enum MAAT_TABLE_TYPE Maat_table_get_type_by_id(struct Maat_table_manager* table_mgr, int table_id);

View File

@@ -1,6 +1,6 @@
#ifndef H_MAAT_JSON2IRIS_H_INCLUDE
#define H_MAAT_JSON2IRIS_H_INCLUDE
int json2iris(const char* json_buff, const char* json_filename, const char*compile_tn, const char* group_tn, redisContext *redis_write_ctx, char* iris_dir_buf, int buf_len, char* encrypt_key, char* encrypt_algo, void* logger);
int json2iris(const char* json_buff, const char* json_filename, const char*compile_tn, const char* group2compile_tn, const char* group2group_tn, redisContext *redis_write_ctx, char* iris_dir_buf, int buf_len, char* encrypt_key, char* encrypt_algo, void* logger);
int set_file_rulenum(const char* path, int rulenum, void* logger);
#endif