void __exit destroyDM() { destroyCFSThread(); dictRelease(g_dataModel.cfsHashTable); dictRelease(g_cfmDict); return ; }
int initDbEngine(void) { objectIndexLength = 256; objectIndexFreeId = 0; objectIndexCount = 0; if (NULL == (objectIndex = (const dbObject **) calloc(objectIndexLength, (sizeof(const dbObject *))))) return -1; if (NULL == (sets = dictCreate(&dictSetType, NULL))) { free((void *) objectIndex); return -1; } if (0 != registerSyncObject(sets)) { free((void *) objectIndex); dictRelease(sets); return -1; } if (0 != registerSyncObject(objectIndex)) { unregisterSyncObject(sets); free((void *) objectIndex); dictRelease(sets); return -1; } return 0; }
/* release memory allocated for copy on write during background save */ void cowBkgdSaveReset() { int j; listNode *ln; if (server.cowDictCopied != NULL) { for (j = 0; j < server.dbnum; j++) { if (server.cowSaveDb[j].dict != NULL) { /* restore normal dictionary destructors */ restore_dictobj(server.db[j].dict, &server.cowSaveDbExt[j]); server.cowSaveDb[j].dict = NULL; } if (server.cowSaveDbExt[j].dictArray != NULL) { cowReleaseDictArray(server.cowSaveDbExt[j].dictArray); server.cowSaveDbExt[j].dictArray = NULL; } if (server.cowSaveDb[j].expires != NULL && server.cowSaveDb[j].expires != server.db[j].expires) { dictRelease(server.cowSaveDb[j].expires); server.cowSaveDb[j].expires = NULL; } } } server.cowCurIters.curDbDictIter = NULL; server.cowCurIters.curObjDictIter = NULL; server.cowCurIters.curObjZDictIter = NULL; server.cowCurIters.curObjListIter = NULL; /* cleanup table of copied items */ if (server.cowDictCopied != NULL) { dictRelease(server.cowDictCopied); server.cowDictCopied = NULL; } if (server.cowDictConverted != NULL) { dictRelease(server.cowDictConverted); server.cowDictConverted = NULL; } /* delete all deferred items */ redisLog(REDIS_NOTICE, "cowBkgdSaveReset deleting %d SDS and %d obj items", listLength(deferSdsDelete), listLength(deferObjDelete)); while ( (ln = listFirst(deferSdsDelete)) != NULL) { sdsfree((sds)(ln->value)); listDelNode(deferSdsDelete, ln); } while ( (ln = listFirst(deferObjDelete)) != NULL) { if (ln->value != NULL) { decrRefCount(ln->value); } listDelNode(deferObjDelete, ln); } }
/* Helper function to free the context. */ static void __redisAsyncFree(redisAsyncContext *ac) { redisContext *c = &(ac->c); redisCallback cb; dictIterator *it; dictEntry *de; // 执行所有等待队列中回调函数,将空回复传进去 /* Execute pending callbacks with NULL reply. */ while (__redisShiftCallback(&ac->replies,&cb) == REDIS_OK) __redisRunCallback(ac,&cb,NULL); // 执行所有等待队列中回调函数,将空回复传进去 // 这里是无效命令的回调函数 /* Execute callbacks for invalid commands */ while (__redisShiftCallback(&ac->sub.invalid,&cb) == REDIS_OK) __redisRunCallback(ac,&cb,NULL); // 执行所有等待队列中回调函数,将空回复传进去 // 这里是订阅发布的回调函数 /* Run subscription callbacks callbacks with NULL reply */ it = dictGetIterator(ac->sub.channels); while ((de = dictNext(it)) != NULL) __redisRunCallback(ac,dictGetEntryVal(de),NULL); dictReleaseIterator(it); dictRelease(ac->sub.channels); // 执行所有等待队列中回调函数,将空回复传进去 // 这里是订阅发布的回调函数 it = dictGetIterator(ac->sub.patterns); while ((de = dictNext(it)) != NULL) __redisRunCallback(ac,dictGetEntryVal(de),NULL); dictReleaseIterator(it); dictRelease(ac->sub.patterns); // 注销连接上的读写事件 /* Signal event lib to clean up */ _EL_CLEANUP(ac); // 执行连接关闭回调函数,可做一些清理工作 /* Execute disconnect callback. When redisAsyncFree() initiated destroying * this context, the status will always be REDIS_OK. */ if (ac->onDisconnect && (c->flags & REDIS_CONNECTED)) { if (c->flags & REDIS_FREEING) { ac->onDisconnect(ac,REDIS_OK); } else { ac->onDisconnect(ac,(ac->err == 0) ? REDIS_OK : REDIS_ERR); } } // 释放 redisContext 中的内存 /* Cleanup self */ redisFree(c); }
/* Release resources related to Lua scripting. * 释放 Lua 脚本的相关资源 * This function is used in order to reset the scripting environment. * 用于初始化脚本环境 */ void scriptingRelease(void) { // 释放记录脚本的字典 dictRelease(server.lua_scripts); // 关闭 Lua 环境 lua_close(server.lua); }
void dictCounterDestructor(void *privdata, void *val) { DICT_NOTUSED(privdata); listNode *ln; listIter li; counter *cntr = val; pubsub *p; /* Unsubscribe everyone */ if (cntr->subscribers != NULL) { while (listLength(cntr->subscribers)) { ln = listFirst(cntr->subscribers); p = listNodeValue(ln); pubsubUnsubscribeCounter(p->c,cntr->name,1); } } /* Free all shards */ listRewind(cntr->shards,&li); while ((ln = listNext(&li)) != NULL) { shard *shrd = listNodeValue(ln); zfree(shrd); } listRelease(cntr->shards); if (cntr->want_acks) dictRelease(cntr->want_acks); /* cntr->name will be freed by the dict code. */ zfree(cntr); }
int main(int argc, char *argv[]) { int ret; dict *d = dictCreate(&testDictType, NULL); assert(d); Key_t *k = (Key_t*)malloc(sizeof(*k)); k->laddr = 112; k->raddr = 112; k->lport = 1123; k->rport = 3306; Val_t *v = (Val_t*)malloc(sizeof(*v)); v->v = malloc(100); snprintf(v->v, 100, "%s", "abcdefg"); ret = dictAdd(d, k, v); assert(ret == DICT_OK); Val_t *v2 = dictFetchValue(d, k); assert(0 == strcmp(v2->v, v->v)); printf("%d-%s-%s\n", ret, v->v, v2->v); dictPrintStats(d); dictDelete(d, k); dictPrintStats(d); dictRelease(d); return 0; }
void freeZsetObject(robj *o) { zset *zs = o->ptr; dictRelease(zs->dict); zslFree(zs->zsl); zfree(zs); }
void engine_free(Engine *engine) { dictRelease(engine->queries); if(engine->data_dir) { pstring_free(engine->data_dir); } parser_free(engine->parser); ring_buffer_free(engine->stream); if(engine->auth) pstring_free(engine->auth); lrw_dict_free(engine->term_dictionary); plist_pool_free(engine->postings); if(engine->docs->on_evict)callback_free(engine->docs->on_evict); ring_buffer_free(engine->docs); dictRelease(engine->ints); if(engine->doc_set) dictRelease(engine->doc_set); free(engine); }
void cmd_mgr_destroy (command_manager * mgr) { aeDeleteTimeEvent (mgr->el, mgr->cron_teid); dictRelease (mgr->commands); index_helper_destroy (mgr->idx_helper); mempool_destroy (mgr->mp_cmdctx); zfree (mgr); }
void deallocStaticFile() { if (AllowExtensions) dictRelease(AllowExtensions); if (DirectoryIndex) freeList(DirectoryIndex); MaxFileSize = 0; wstrFree(IfModifiedSince); }
int main(int argc, const char *argv[]) { struct timeval start, end; double elapsed; dict *d; struct bftree *tree; const int times = 500; struct bftree_opts opt = { NULL, NULL, bftreeSdsKeyCompare, (void (*)(void*))sdsfree, (void (*)(void*))sdsfree }; tree = bftree_create(&opt); d = dictCreate(&sdsdict_type, NULL); gettimeofday(&start, NULL); redis_add(d, times); gettimeofday(&end, NULL); elapsed = get_seconds(start, end); printf("redis add %d elements seconds: %f\n", times, elapsed); gettimeofday(&start, NULL); tree = bftree_add(tree, times); gettimeofday(&end, NULL); elapsed = get_seconds(start, end); printf("bftree add %d elements seconds: %f\n", times, elapsed); gettimeofday(&start, NULL); redis_fetch(d, times); gettimeofday(&end, NULL); elapsed = get_seconds(start, end); printf("redis get %d elements seconds: %f\n", times, elapsed); gettimeofday(&start, NULL); bftree_fetch(tree, times); gettimeofday(&end, NULL); elapsed = get_seconds(start, end); printf("bftree get %d elements seconds: %f\n", times, elapsed); gettimeofday(&start, NULL); redis_del(d, times); gettimeofday(&end, NULL); elapsed = get_seconds(start, end); printf("redis delete %d elements seconds: %f\n", times, elapsed); gettimeofday(&start, NULL); bftree_delele(tree, times); gettimeofday(&end, NULL); elapsed = get_seconds(start, end); printf("bftree delete %d elements seconds: %f\n", times, elapsed); bftree_free(tree); dictRelease(d); return 0; }
void aeDeleteEventLoop(aeEventLoop *eventLoop) { aeApiFree(eventLoop); #ifdef _WIN32 dictRelease(eventLoop->fdiMap->map); listRelease(eventLoop->fdiMap->recycle_pool); zfree(eventLoop->fdiMap); #endif zfree(eventLoop->events); zfree(eventLoop->fired); zfree(eventLoop); }
void result_iterator_free(ResultIterator *iter) { dictRelease(iter->cursors); for(int i = 0; i < iter->count; i++) { free(iter->subs[i]->cursors); free(iter->subs[i]->negateds); free(iter->subs[i]->state); free(iter->subs[i]); } free(iter->subs); free(iter); }
void freeSetObject(robj *o) { switch (o->encoding) { case OBJ_ENCODING_HT: dictRelease((dict*) o->ptr); break; case OBJ_ENCODING_INTSET: zfree(o->ptr); break; default: serverPanic("Unknown set encoding type"); } }
void execShutdownCommand(dict *db) { writeLog(1, "start to clear db..."); dictRelease(db); writeLog(1, "db cleared..."); /* * TODO * Implement all connections free here. */ sleep(5); writeLog(1, "start to shutdown..."); exit(1); }
static void freeHashObject(robj *o) { switch (o->encoding) { case REDIS_ENCODING_HT: dictRelease((dict*) o->ptr); break; case REDIS_ENCODING_ZIPMAP: zfree(o->ptr); break; default: redisAssert(0); break; } }
void destroyTaskMap(dict* p) { if (p) { dictIterator* di = dictGetIterator(p); dictEntry* de; while ((de = dictNext(di)) != NULL) { ugTaskType* ptask = dictGetEntryVal(de); luaworkUnrefFunction(server.ls, ptask->handle, NULL); } dictReleaseIterator(di); dictRelease(p); } }
static void init_DXDB_PersistentStorageItems(uint32 ntbl, uint32 nindx) { if (Tbl) free(Tbl); Num_tbls = 0; Tbl = malloc(sizeof(r_tbl_t) * ntbl); bzero(Tbl, sizeof(r_tbl_t) * ntbl); Tbl_HW = ntbl; if (TblD) dictRelease(TblD); TblD = dictCreate(&sdsDictType, NULL); if (DropT) { listRelease(DropT); DropT = NULL; } if (Index) free(Index); Num_indx = 0; Index = malloc(sizeof(r_ind_t) * nindx); bzero(Index, sizeof(r_ind_t) * nindx); Ind_HW = nindx; if (IndD) dictRelease(IndD); IndD = dictCreate(&sdsDictType, NULL); if (DropI) { listRelease(DropI); DropI = NULL; } if (StmtD) dictRelease(StmtD); StmtD = dictCreate(&dbDictType, NULL); }
void freeHashObject(robj *o) { switch (o->encoding) { case REDIS_ENCODING_HT: dictRelease((dict*) o->ptr); break; case REDIS_ENCODING_ZIPMAP: zfree(o->ptr); break; default: redisPanic("Unknown hash encoding type"); break; } }
void freeHashObject(robj *o) { switch (o->encoding) { case OBJ_ENCODING_HT: dictRelease((dict*) o->ptr); break; case OBJ_ENCODING_ZIPLIST: zfree(o->ptr); break; default: serverPanic("Unknown hash encoding type"); break; } }
static void _conn_destroy(void * ptr) { http_connection_t * conn = (http_connection_t *) ptr; zfree(conn->timeout); if (conn->request->data) { conn->request->free_data(conn); } if (conn->request) { dictRelease(conn->request->headers); zfree(conn->request->url); zfree(conn->request->uri); dictRelease(conn->request->args); zfree(conn->request); } if (conn->response) { dictRelease(conn->response->headers); zfree(conn->response->ptr); zfree(conn->response); } zfree(conn); }
static int conf_post_validate(rmt_conf *cf) { if(cf == NULL){ return RMT_ERROR; } if(cf->organizations != NULL){ dictRelease(cf->organizations); cf->organizations = NULL; } return RMT_OK; }
void query_node_free(QueryNode *node) { if(node->children) { dictRelease(node->children); } Callback *cb = node->callback; while(cb) { Callback *tmp = cb; cb = cb->next; callback_free(tmp); } free(node); }
/* Change job state as acknowledged. If it is already in that state, the * function does nothing. */ void acknowledgeJob(job *job) { if (job->state == JOB_STATE_ACKED) return; dequeueJob(job); job->state = JOB_STATE_ACKED; /* Remove the nodes_confirmed hash table if it exists. * tryJobGC() will take care to create a new one used for the GC * process. */ if (job->nodes_confirmed) { dictRelease(job->nodes_confirmed); job->nodes_confirmed = NULL; } updateJobAwakeTime(job,0); /* Make sure we'll schedule a job GC. */ AOFAckJob(job); /* Change job state in AOF. */ }
void freeZsetObject(robj *o) { zset *zs; switch (o->encoding) { case OBJ_ENCODING_SKIPLIST: zs = o->ptr; dictRelease(zs->dict); zslFree(zs->zsl); zfree(zs); break; case OBJ_ENCODING_ZIPLIST: zfree(o->ptr); break; default: serverPanic("Unknown sorted set encoding"); } }
int main(int argc, char *argv[]) { int ret; dict *d = dictCreate(&testDictType, NULL); assert(d); create(d, 123); create(d, 124); create(d, 125); create(d, 126); dictPrintStats(d); dictRelease(d); return 0; }
aeEventLoop *aeCreateEventLoop(int setsize) { aeEventLoop *eventLoop; int i; if ((eventLoop = zmalloc(sizeof(*eventLoop))) == NULL) goto err; eventLoop->events = zmalloc(sizeof(aeFileEvent)*setsize); eventLoop->fired = zmalloc(sizeof(aeFiredEvent)*setsize); if (eventLoop->events == NULL || eventLoop->fired == NULL) goto err; eventLoop->setsize = setsize; eventLoop->lastTime = time(NULL); eventLoop->timeEventHead = NULL; eventLoop->timeEventNextId = 0; eventLoop->stop = 0; eventLoop->maxfd = EVENTLOOP_MAXFD_INITIAL_VALUE; eventLoop->beforesleep = NULL; if (aeApiCreate(eventLoop) == -1) goto err; /* Events with mask == AE_NONE are not set. So let's initialize the * vector with it. */ for (i = 0; i < setsize; i++) eventLoop->events[i].mask = AE_NONE; #ifdef _WIN32 if ((eventLoop->fdiMap = zmalloc(sizeof(fd_index_map_t))) == NULL) goto err; eventLoop->fdiMap->map = dictCreate(&fdiDictType, NULL); eventLoop->fdiMap->recycle_pool = listCreate(); if (eventLoop->fdiMap->map == NULL || eventLoop->fdiMap->recycle_pool == NULL) goto err; eventLoop->fdiMap->next_available = 3; // stdin(0), stdout(1) and stderr(2) #endif return eventLoop; err: #ifdef _WIN32 if (eventLoop->fdiMap) { if (eventLoop->fdiMap->map != NULL) dictRelease(eventLoop->fdiMap->map); if (eventLoop->fdiMap->recycle_pool != NULL) listRelease(eventLoop->fdiMap->recycle_pool); zfree(eventLoop->fdiMap); } #endif if (eventLoop) { zfree(eventLoop->events); zfree(eventLoop->fired); zfree(eventLoop); } return NULL; }
static void client_unref_internal_try_put(struct conn *conn) { ASSERT(conn->waiting_to_unref); unsigned long msgs = dictSize(conn->outstanding_msgs_dict); if (msgs != 0) { log_warn("conn %p Waiting for %lu outstanding messages", conn, msgs); return; } struct server_pool *pool; ASSERT(conn->owner != NULL); pool = conn->owner; conn->owner = NULL; dictRelease(conn->outstanding_msgs_dict); conn->waiting_to_unref = 0; log_warn("unref conn %p owner %p from pool '%.*s'", conn, pool, pool->name.len, pool->name.data); conn_put(conn); }
static void conf_deinit(rmt_conf *cf) { if(cf == NULL){ return; } if (cf->fname != NULL) { sdsfree(cf->fname); cf->fname = NULL; } if(cf->fh != NULL){ fclose(cf->fh); cf->fh = NULL; } if(cf->organizations != NULL){ dictRelease(cf->organizations); cf->organizations = NULL; } conf_pool_deinit(&cf->source_pool); conf_pool_deinit(&cf->target_pool); if(cf->listen != NULL){ sdsfree(cf->listen); cf->listen = CONF_UNSET_PTR; } if(cf->dir != NULL){ sdsfree(cf->dir); cf->dir = CONF_UNSET_PTR; } cf->maxmemory = CONF_UNSET_NUM; cf->threads = CONF_UNSET_NUM; cf->step = CONF_UNSET_NUM; cf->mbuf_size = CONF_UNSET_NUM; cf->noreply = CONF_UNSET_NUM; cf->rdb_diskless = CONF_UNSET_NUM; cf->source_safe = CONF_UNSET_NUM; }