void init_caches(uint32_t count) { if (count == 0) count = MAX_LINE_COUNT; assert(count > 0); assert(key_cache == NULL); assert(value_cache == NULL); key_cache = mem_cache_create(sizeof(uint32_t), count); value_cache = mem_cache_create(sizeof(logrecord_t), count); ipseg_cache = mem_cache_create(sizeof(ip_seg), MAX_A_LIST_LINES); assert(wb_list_map == NULL); wb_list_map = hash_table_new(int32_hash, int32_compare_func, NULL, NULL, NULL); assert(a_list == NULL); a_list = list_new(MAX_A_LIST_LINES, NULL); assert(regular_map == NULL); assert(tcp80_map == NULL); assert(tcp443_map == NULL); assert(tcp8080_map == NULL); regular_map = hash_table_new(int32_hash, int32_compare_func, NULL, NULL, NULL); tcp80_map = hash_table_new(int32_hash, int32_compare_func, NULL, NULL, NULL); tcp443_map = hash_table_new(int32_hash, int32_compare_func, NULL, NULL, NULL); tcp8080_map = hash_table_new(int32_hash, int32_compare_func, NULL, NULL, NULL); }
static void cache_index_read(int fd) { assert(fd != -1); int size = sizeof(struct cache_index); int res; struct cache_index ci; char buf[MAX_FILE]; char *temp; struct cache_dir *dentry; for(; ;) { struct stat sbuf; char content[size * 1024]; int used = 0; res = read(fd, content, size * 1024); if(-1 == res) { error("cache_index_read %s\n", strerror(errno)); break; } else if(0 == res) break; while(used < res) { if(memcpy(&ci, content + used, size)) used += size; else { fprintf(stderr, "cache_index_read memcpy failed\n"); abort(); } if(ci.operate == CACHE_INDEX_DEL) continue; struct cache_file *cache = calloc(1, sizeof(*cache)); assert(cache); cache->header_size = ci.header_size; cache->body_size = ci.body_size; cache->key = string_init(ci.key); cache->dir_no = ci.dirno; cache->time = ci.time; cache->statu = CACHE_DISK; /* get file path */ dentry = config->cache_dir->items[cache->dir_no]; snprintf(buf, MAX_FILE - 1, "%s/%s", dentry->path, cache->key->buf); cache->file = string_init(buf); if(-1 == stat(cache->file->buf, &sbuf)) { debug("cache_index_read %s not exist\n", cache->file->buf); safe_free(cache); continue; } cache_index_log(&ci, dentry->new_fd); /*preload header */ if(-1 == cache_header_preload(cache)) { safe_free(cache); continue; } INIT_LIST_HEAD(&cache->list); cache->shm_cache = shm_cache_create(-1, 0, 0); cache->mem_cache = mem_cache_create(0, 0); if(!cache_file_insert(cache)) cache_num ++; } } close(fd); }