void _flush_list(struct silopit *silopit, struct skipnode *x,struct skipnode *hdr,int flush_count) { int pos = 0; int count = flush_count; struct skipnode *cur = x; struct skipnode *first = hdr; struct jikukan *merge = NULL; struct meta_node *meta_info = NULL; while(cur != first) { meta_info = meta_get(silopit->meta, cur->key); if(!meta_info){ if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(silopit, h, merge->count, NULL); jikukan_free(merge); merge = NULL; } _flush_new_list(silopit, x, count - pos); return; } else { int cmp = strcmp(silopit->name, meta_info->index_name); if(cmp == 0) { if (!merge) merge = _read_mmap(silopit,count); jikukan_insert_node(merge, cur); } else { if (merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(silopit, h, merge->count, meta_info); jikukan_free(merge); merge = NULL; } memset(silopit->name, 0, FILE_NAME_SIZE); memcpy(silopit->name, meta_info->index_name, FILE_NAME_SIZE); merge = _read_mmap(silopit, count); jikukan_insert_node(merge, cur); } } pos++; cur = cur->forward[0]; } if (merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(silopit, h, merge->count, meta_info); jikukan_free(merge); } }
void _flush_list(struct sst *sst, struct skipnode *x, struct skipnode *hdr, int flush_count) { int pos = 0; int count = flush_count; struct skipnode *cur = x; struct skipnode *first = hdr; struct skiplist *merge = NULL; struct meta_node *meta_info = NULL; while(cur != first) { meta_info = meta_get(sst->meta, cur->key); /* If m is NULL, cur->key more larger than meta's largest area * need to create new index-file */ if(!meta_info) { /* If merge is NULL, it has no merge */ if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(sst, h, merge->count, NULL); skiplist_free(merge); merge = NULL; } /* Flush the last nodes to disk */ _flush_new_list(sst, x, count - pos); return ; } else { /* If m is not NULL, means found the index of the cur * We need: * 1) compare the sst->name with meta index name * a)If 0: add the cur to merge, and continue * b)others: * b1)Flush the merge list to disk * b2)Open the meta's mmap, and load all blocks to new merge, add cur to merge */ int cmp = strcmp(sst->name, meta_info->index_name); if(cmp == 0) { if(!merge) merge = _read_mmap(sst, count); skiplist_insert_node(merge, cur); } else { if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(sst, h, merge->count, meta_info); skiplist_free(merge); merge = NULL; } memset(sst->name, 0, FILE_NAME_SIZE); memcpy(sst->name, meta_info->index_name, FILE_NAME_SIZE); merge = _read_mmap(sst, count); /* Add to merge list */ skiplist_insert_node(merge, cur); } } pos++; cur = cur->forward[0]; } if(merge) { struct skipnode *h = merge->hdr->forward[0]; _flush_merge_list(sst, h, merge->count, meta_info); skiplist_free(merge); } }