带全量的业务,支持持久化的旧配置淘汰删除;
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <MESA/MESA_handle_logger.h>
|
||||
|
||||
@@ -95,6 +96,127 @@ int filter_fn(const struct dirent * ent)
|
||||
strncmp(ent->d_name,"inc_config_index",strlen("inc_config_index")) == 0);
|
||||
}
|
||||
|
||||
void remove_configs_of_index_file(const char *filename)
|
||||
{
|
||||
FILE* fp=NULL;
|
||||
int ret=0;
|
||||
char line[MAX_CONFIG_LINE];
|
||||
struct cfg_table_info idx;
|
||||
|
||||
fp=fopen(filename, "r");
|
||||
while(!feof(fp))
|
||||
{
|
||||
memset(line, 0, sizeof(line));
|
||||
fgets(line, sizeof(line), fp);
|
||||
ret=sscanf(line,"%[^ \t]%*[ \t]%d%*[ \t]%s", idx.table_name, &idx.cfg_num, idx.cfg_path);
|
||||
if(ret != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(!access(idx.cfg_path, F_OK))
|
||||
{
|
||||
remove(idx.cfg_path);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void remove_configs_version_smaller(const char *file_dir, int64_t version_higher, int recursively, void *logger)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
int64_t config_seq;
|
||||
int32_t i, n=0;
|
||||
char update_str[32], index_path[256];
|
||||
|
||||
if(version_higher <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
n = my_scandir(file_dir, &namelist, filter_fn, (int (*)(const void*, const void*))alphasort);
|
||||
if(n <= 0)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
if((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0) || (namelist[i]->d_type==DT_DIR))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(strlen(namelist[i]->d_name) > 42)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(sscanf(namelist[i]->d_name,"%[a-zA-Z]_config_index.%ld", update_str, &config_seq) != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(version_higher <= config_seq)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
snprintf(index_path, 256, "%s/%s", file_dir, namelist[i]->d_name);
|
||||
if(recursively)
|
||||
{
|
||||
remove_configs_of_index_file(index_path);
|
||||
}
|
||||
remove(index_path);
|
||||
MESA_RUNTIME_LOGV4(logger, RLOG_LV_INFO, "config file %s removed initiatively.", index_path);
|
||||
}
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2A3ACB7><EFBFBD>ֵ:<3A><><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6>ٸ<EFBFBD>*/
|
||||
u_int32_t get_full_topN_max_versions(const char *file_dir, int64_t *ver_array, int32_t maxsize)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
int64_t config_seq, tmpval;
|
||||
int32_t curnum=0, i, j, n=0;
|
||||
char update_str[32];
|
||||
|
||||
n = my_scandir(file_dir, &namelist, filter_fn, (int (*)(const void*, const void*))alphasort);
|
||||
if(maxsize<=0 || n <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for(i=0; i<maxsize; i++)
|
||||
{
|
||||
ver_array[i] = 0;
|
||||
}
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
if((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0) || (namelist[i]->d_type==DT_DIR))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(strlen(namelist[i]->d_name) > 42)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(sscanf(namelist[i]->d_name,"%[a-zA-Z]_config_index.%ld", update_str, &config_seq) != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(strncasecmp(update_str, "full", strlen(update_str)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ver_array[0] < config_seq)
|
||||
{
|
||||
ver_array[0] = config_seq;
|
||||
for(j=1; j<maxsize && (ver_array[j-1] > ver_array[j]); j++)
|
||||
{
|
||||
tmpval = ver_array[j-1];
|
||||
ver_array[j-1] = ver_array[j];
|
||||
ver_array[j] = tmpval;
|
||||
}
|
||||
if(curnum < maxsize) curnum++;
|
||||
}
|
||||
}
|
||||
return curnum;
|
||||
}
|
||||
|
||||
enum DORIS_UPDATE_TYPE get_new_idx_path(long long current_version, const char *file_dir, void *logger, struct index_path_array **idx_path, int *idx_num)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
@@ -116,7 +238,7 @@ enum DORIS_UPDATE_TYPE get_new_idx_path(long long current_version, const char *f
|
||||
inc_idx_num=0;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0))
|
||||
if((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0) || (namelist[i]->d_type==DT_DIR))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user