failed to open rocksdb cf
This commit is contained in:
parent
d7e86aca05
commit
8be29dc98e
|
@ -44,6 +44,7 @@ typedef struct {
|
||||||
SList* list;
|
SList* list;
|
||||||
TdThreadMutex cfMutex;
|
TdThreadMutex cfMutex;
|
||||||
SHashObj* cfInst;
|
SHashObj* cfInst;
|
||||||
|
int64_t defaultCfInit;
|
||||||
} SBackendHandle;
|
} SBackendHandle;
|
||||||
|
|
||||||
void* streamBackendInit(const char* path);
|
void* streamBackendInit(const char* path);
|
||||||
|
|
|
@ -33,7 +33,9 @@ typedef struct {
|
||||||
SListNode* pCompareNode;
|
SListNode* pCompareNode;
|
||||||
} RocksdbCfInst;
|
} RocksdbCfInst;
|
||||||
|
|
||||||
RocksdbCfInst* streamStateOpenBackendCf(void* backend, char* name, char* idstr);
|
int32_t streamStateOpenBackendCf(void* backend, char* name, SHashObj* ids);
|
||||||
|
|
||||||
|
void destroyRocksdbCfInst(RocksdbCfInst* inst);
|
||||||
|
|
||||||
void destroyCompactFilteFactory(void* arg);
|
void destroyCompactFilteFactory(void* arg);
|
||||||
void destroyCompactFilte(void* arg);
|
void destroyCompactFilte(void* arg);
|
||||||
|
@ -100,7 +102,7 @@ void* streamBackendInit(const char* path) {
|
||||||
size_t nCf = 0;
|
size_t nCf = 0;
|
||||||
|
|
||||||
char** cfs = rocksdb_list_column_families(opts, path, &nCf, &err);
|
char** cfs = rocksdb_list_column_families(opts, path, &nCf, &err);
|
||||||
if (nCf == 0 || err != NULL) {
|
if (nCf == 0 || nCf == 1 || err != NULL) {
|
||||||
taosMemoryFreeClear(err);
|
taosMemoryFreeClear(err);
|
||||||
pHandle->db = rocksdb_open(opts, path, &err);
|
pHandle->db = rocksdb_open(opts, path, &err);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
|
@ -117,24 +119,18 @@ void* streamBackendInit(const char* path) {
|
||||||
if (3 == sscanf(cf, "0x%" PRIx64 "-%d_%s", &streamId, &taskId, suffix)) {
|
if (3 == sscanf(cf, "0x%" PRIx64 "-%d_%s", &streamId, &taskId, suffix)) {
|
||||||
char idstr[128] = {0};
|
char idstr[128] = {0};
|
||||||
sprintf(idstr, "0x%" PRIx64 "-%d", streamId, taskId);
|
sprintf(idstr, "0x%" PRIx64 "-%d", streamId, taskId);
|
||||||
if (taosHashGet(tbl, idstr, strlen(idstr)) != NULL) {
|
// qError("make cf name %s", idstr);
|
||||||
taosHashPut(tbl, idstr, strlen(idstr), &dummpy, sizeof(dummpy));
|
if (taosHashGet(tbl, idstr, strlen(idstr) + 1) == NULL) {
|
||||||
|
taosHashPut(tbl, idstr, strlen(idstr) + 1, &dummpy, sizeof(dummpy));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void* pIter = taosHashIterate(tbl, NULL);
|
streamStateOpenBackendCf(pHandle, (char*)path, tbl);
|
||||||
while (pIter != NULL) {
|
|
||||||
size_t keyLen = 0;
|
|
||||||
char* key = taosHashGetKey(pIter, &keyLen);
|
|
||||||
RocksdbCfInst* inst = streamStateOpenBackendCf(pHandle, (char*)path, key);
|
|
||||||
taosHashPut(pHandle->cfInst, key, keyLen, &inst, sizeof(void*));
|
|
||||||
|
|
||||||
taosHashIterate(tbl, pIter);
|
|
||||||
}
|
|
||||||
taosHashCleanup(tbl);
|
taosHashCleanup(tbl);
|
||||||
}
|
}
|
||||||
|
rocksdb_list_column_families_destroy(cfs, nCf);
|
||||||
|
|
||||||
return (void*)pHandle;
|
return (void*)pHandle;
|
||||||
_EXIT:
|
_EXIT:
|
||||||
|
@ -151,6 +147,13 @@ _EXIT:
|
||||||
}
|
}
|
||||||
void streamBackendCleanup(void* arg) {
|
void streamBackendCleanup(void* arg) {
|
||||||
SBackendHandle* pHandle = (SBackendHandle*)arg;
|
SBackendHandle* pHandle = (SBackendHandle*)arg;
|
||||||
|
RocksdbCfInst** pIter = (RocksdbCfInst**)taosHashIterate(pHandle->cfInst, NULL);
|
||||||
|
while (pIter != NULL) {
|
||||||
|
RocksdbCfInst* inst = *pIter;
|
||||||
|
destroyRocksdbCfInst(inst);
|
||||||
|
taosHashIterate(pHandle->cfInst, pIter);
|
||||||
|
}
|
||||||
|
taosHashCleanup(pHandle->cfInst);
|
||||||
|
|
||||||
rocksdb_flushoptions_t* flushOpt = rocksdb_flushoptions_create();
|
rocksdb_flushoptions_t* flushOpt = rocksdb_flushoptions_create();
|
||||||
char* err = NULL;
|
char* err = NULL;
|
||||||
|
@ -176,7 +179,6 @@ void streamBackendCleanup(void* arg) {
|
||||||
// rocksdb_compactionfilterfactory_destroy(pHandle->filterFactory);
|
// rocksdb_compactionfilterfactory_destroy(pHandle->filterFactory);
|
||||||
tdListFree(pHandle->list);
|
tdListFree(pHandle->list);
|
||||||
taosThreadMutexDestroy(&pHandle->cfMutex);
|
taosThreadMutexDestroy(&pHandle->cfMutex);
|
||||||
taosHashCleanup(pHandle->cfInst);
|
|
||||||
|
|
||||||
taosMemoryFree(pHandle);
|
taosMemoryFree(pHandle);
|
||||||
|
|
||||||
|
@ -669,22 +671,56 @@ rocksdb_compactionfilter_t* compactFilteFactoryCreateFilter(void* arg, rocksdb_c
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
RocksdbCfInst* streamStateOpenBackendCf(void* backend, char* name, char* idstr) {
|
void destroyRocksdbCfInst(RocksdbCfInst* inst) {
|
||||||
// qInfo("start to open backend cf, %p 0x%" PRIx64 "-%d", pState, pState->streamId, pState->taskId);
|
int cfLen = sizeof(ginitDict) / sizeof(ginitDict[0]);
|
||||||
SBackendHandle* handle = backend;
|
|
||||||
|
|
||||||
char* err = NULL;
|
|
||||||
int cfLen = sizeof(ginitDict) / sizeof(ginitDict[0]);
|
|
||||||
char** cfNames = taosMemoryCalloc(cfLen, sizeof(char*));
|
|
||||||
for (int i = 0; i < cfLen; i++) {
|
for (int i = 0; i < cfLen; i++) {
|
||||||
cfNames[i] = taosMemoryCalloc(1, 128);
|
rocksdb_column_family_handle_destroy(inst->pHandle[i]);
|
||||||
GEN_COLUMN_FAMILY_NAME(cfNames[i], idstr, ginitDict[i].key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RocksdbCfParam* param = taosMemoryCalloc(cfLen, sizeof(RocksdbCfParam));
|
rocksdb_writeoptions_destroy(inst->wOpt);
|
||||||
const rocksdb_options_t** cfOpt = taosMemoryCalloc(cfLen, sizeof(rocksdb_options_t*));
|
inst->wOpt = NULL;
|
||||||
for (int i = 0; i < cfLen; i++) {
|
|
||||||
cfOpt[i] = rocksdb_options_create_copy(handle->dbOpt);
|
rocksdb_readoptions_destroy(inst->rOpt);
|
||||||
|
taosMemoryFree(inst->cfOpt);
|
||||||
|
taosMemoryFree(inst->param);
|
||||||
|
taosMemoryFreeClear(inst->param);
|
||||||
|
taosMemoryFree(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t streamStateOpenBackendCf(void* backend, char* name, SHashObj* ids) {
|
||||||
|
SBackendHandle* handle = backend;
|
||||||
|
char* err = NULL;
|
||||||
|
size_t nSize = taosHashGetSize(ids);
|
||||||
|
int cfLen = sizeof(ginitDict) / sizeof(ginitDict[0]);
|
||||||
|
|
||||||
|
char** cfNames = taosMemoryCalloc(nSize * cfLen + 1, sizeof(char*));
|
||||||
|
void* pIter = taosHashIterate(ids, NULL);
|
||||||
|
size_t keyLen = 0;
|
||||||
|
char* idstr = taosHashGetKey(pIter, &keyLen);
|
||||||
|
for (int i = 0; i < nSize * cfLen + 1; i++) {
|
||||||
|
cfNames[i] = (char*)taosMemoryCalloc(1, 128);
|
||||||
|
if (i == 0) {
|
||||||
|
memcpy(cfNames[0], "default", strlen("default"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
qError("cf name %s", idstr);
|
||||||
|
|
||||||
|
GEN_COLUMN_FAMILY_NAME(cfNames[i], idstr, ginitDict[(i - 1) % (cfLen)].key);
|
||||||
|
if (i % cfLen == 0) {
|
||||||
|
pIter = taosHashIterate(ids, pIter);
|
||||||
|
if (pIter != NULL) idstr = taosHashGetKey(pIter, &keyLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < nSize * cfLen + 1; i++) {
|
||||||
|
qError("cf name %s", cfNames[i]);
|
||||||
|
}
|
||||||
|
rocksdb_options_t** cfOpts = taosMemoryCalloc(nSize * cfLen + 1, sizeof(rocksdb_options_t*));
|
||||||
|
RocksdbCfParam* params = taosMemoryCalloc(nSize * cfLen + 1, sizeof(RocksdbCfParam*));
|
||||||
|
for (int i = 0; i < nSize * cfLen + 1; i++) {
|
||||||
|
cfOpts[i] = rocksdb_options_create_copy(handle->dbOpt);
|
||||||
|
if (i == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// refactor later
|
// refactor later
|
||||||
rocksdb_block_based_table_options_t* tableOpt = rocksdb_block_based_options_create();
|
rocksdb_block_based_table_options_t* tableOpt = rocksdb_block_based_options_create();
|
||||||
rocksdb_block_based_options_set_block_cache(tableOpt, handle->cache);
|
rocksdb_block_based_options_set_block_cache(tableOpt, handle->cache);
|
||||||
|
@ -692,45 +728,77 @@ RocksdbCfInst* streamStateOpenBackendCf(void* backend, char* name, char* idstr)
|
||||||
rocksdb_filterpolicy_t* filter = rocksdb_filterpolicy_create_bloom(15);
|
rocksdb_filterpolicy_t* filter = rocksdb_filterpolicy_create_bloom(15);
|
||||||
rocksdb_block_based_options_set_filter_policy(tableOpt, filter);
|
rocksdb_block_based_options_set_filter_policy(tableOpt, filter);
|
||||||
|
|
||||||
rocksdb_options_set_block_based_table_factory((rocksdb_options_t*)cfOpt[i], tableOpt);
|
rocksdb_options_set_block_based_table_factory((rocksdb_options_t*)cfOpts[i], tableOpt);
|
||||||
|
params[i].tableOpt = tableOpt;
|
||||||
param[i].tableOpt = tableOpt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
rocksdb_comparator_t** pCompare = taosMemoryCalloc(cfLen, sizeof(rocksdb_comparator_t**));
|
rocksdb_comparator_t** pCompare = taosMemoryCalloc(nSize * cfLen + 1, sizeof(rocksdb_comparator_t**));
|
||||||
for (int i = 0; i < cfLen; i++) {
|
for (int i = 0; i < nSize * cfLen + 1; i++) {
|
||||||
SCfInit* cf = &ginitDict[i];
|
if (i == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
SCfInit* cf = &ginitDict[(i - 1) % cfLen];
|
||||||
|
|
||||||
rocksdb_comparator_t* compare = rocksdb_comparator_create(NULL, cf->detroyFunc, cf->cmpFunc, cf->cmpName);
|
rocksdb_comparator_t* compare = rocksdb_comparator_create(NULL, cf->detroyFunc, cf->cmpFunc, cf->cmpName);
|
||||||
rocksdb_options_set_comparator((rocksdb_options_t*)cfOpt[i], compare);
|
rocksdb_options_set_comparator((rocksdb_options_t*)cfOpts[i], compare);
|
||||||
pCompare[i] = compare;
|
pCompare[i] = compare;
|
||||||
}
|
}
|
||||||
rocksdb_column_family_handle_t** cfHandle = taosMemoryCalloc(cfLen, sizeof(rocksdb_column_family_handle_t*));
|
rocksdb_column_family_handle_t** cfHandle =
|
||||||
rocksdb_t* db = rocksdb_open_column_families(handle->dbOpt, name, cfLen, (const char* const*)cfNames,
|
taosMemoryCalloc(nSize * cfLen + 1, sizeof(rocksdb_column_family_handle_t*));
|
||||||
(const rocksdb_options_t* const*)cfOpt, cfHandle, &err);
|
rocksdb_t* db = rocksdb_open_column_families(handle->dbOpt, name, nSize * cfLen + 1, (const char* const*)cfNames,
|
||||||
|
(const rocksdb_options_t* const*)cfOpts, cfHandle, &err);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
qError("failed to open rocksdb cf, reason:%s", err);
|
qError("failed to open rocksdb cf, reason:%s", err);
|
||||||
taosMemoryFree(err);
|
taosMemoryFree(err);
|
||||||
} else {
|
} else {
|
||||||
qDebug("succ to open rocksdb cf, reason:%s", err);
|
qDebug("succ to open rocksdb cf, reason:%s", err);
|
||||||
}
|
}
|
||||||
RocksdbCfInst* inst = taosMemoryCalloc(1, sizeof(RocksdbCfInst));
|
|
||||||
|
|
||||||
inst->db = db;
|
pIter = taosHashIterate(ids, NULL);
|
||||||
inst->pHandle = cfHandle;
|
idstr = taosHashGetKey(pIter, &keyLen);
|
||||||
inst->wOpt = rocksdb_writeoptions_create();
|
for (int i = 0; i < nSize; i++) {
|
||||||
inst->rOpt = rocksdb_readoptions_create();
|
RocksdbCfInst* inst = taosMemoryCalloc(1, sizeof(RocksdbCfInst));
|
||||||
inst->cfOpt = (rocksdb_options_t**)cfOpt;
|
rocksdb_column_family_handle_t** subCf = taosMemoryCalloc(cfLen, sizeof(rocksdb_column_family_handle_t*));
|
||||||
inst->dbOpt = handle->dbOpt;
|
rocksdb_comparator_t** subCompare = taosMemoryCalloc(cfLen, sizeof(rocksdb_comparator_t*));
|
||||||
inst->param = param;
|
RocksdbCfParam* subParam = taosMemoryCalloc(cfLen, sizeof(RocksdbCfParam));
|
||||||
inst->pBackendHandle = handle;
|
rocksdb_options_t** subOpt = taosMemoryCalloc(cfLen, sizeof(rocksdb_options_t*));
|
||||||
|
for (int j = 0; j < cfLen; j++) {
|
||||||
|
subCf[j] = cfHandle[i * cfLen + j + 1];
|
||||||
|
subCompare[j] = pCompare[i * cfLen + j + 1];
|
||||||
|
subParam[j] = params[i * cfLen + j + 1];
|
||||||
|
subOpt[j] = cfOpts[i * cfLen + j + 1];
|
||||||
|
}
|
||||||
|
inst->db = db;
|
||||||
|
inst->pHandle = subCf;
|
||||||
|
inst->wOpt = rocksdb_writeoptions_create();
|
||||||
|
inst->rOpt = rocksdb_readoptions_create();
|
||||||
|
inst->cfOpt = (rocksdb_options_t**)subOpt;
|
||||||
|
inst->dbOpt = handle->dbOpt;
|
||||||
|
inst->param = subParam;
|
||||||
|
inst->pBackendHandle = handle;
|
||||||
|
handle->db = db;
|
||||||
|
SCfComparator compare = {.comp = subCompare, .numOfComp = cfLen};
|
||||||
|
inst->pCompareNode = streamBackendAddCompare(handle, &compare);
|
||||||
|
rocksdb_writeoptions_disable_WAL(inst->wOpt, 1);
|
||||||
|
|
||||||
handle->db = db;
|
taosHashPut(handle->cfInst, idstr, keyLen, &inst, sizeof(void*));
|
||||||
|
|
||||||
SCfComparator compare = {.comp = pCompare, .numOfComp = cfLen};
|
pIter = taosHashIterate(ids, pIter);
|
||||||
inst->pCompareNode = streamBackendAddCompare(handle, &compare);
|
if (pIter != NULL) idstr = taosHashGetKey(pIter, &keyLen);
|
||||||
rocksdb_writeoptions_disable_WAL(inst->wOpt, 1);
|
}
|
||||||
return inst;
|
rocksdb_column_family_handle_destroy(cfHandle[0]);
|
||||||
|
rocksdb_options_destroy(cfOpts[0]);
|
||||||
|
|
||||||
|
for (int i = 0; i < nSize * cfLen + 1; i++) {
|
||||||
|
taosMemoryFree(cfNames[i]);
|
||||||
|
}
|
||||||
|
taosMemoryFree(cfNames);
|
||||||
|
taosMemoryFree(cfHandle);
|
||||||
|
taosMemoryFree(pCompare);
|
||||||
|
taosMemoryFree(params);
|
||||||
|
taosMemoryFree(cfOpts);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
int streamStateOpenBackend(void* backend, SStreamState* pState) {
|
int streamStateOpenBackend(void* backend, SStreamState* pState) {
|
||||||
qInfo("start to open backend, %p 0x%" PRIx64 "-%d", pState, pState->streamId, pState->taskId);
|
qInfo("start to open backend, %p 0x%" PRIx64 "-%d", pState, pState->streamId, pState->taskId);
|
||||||
|
@ -738,7 +806,7 @@ int streamStateOpenBackend(void* backend, SStreamState* pState) {
|
||||||
|
|
||||||
sprintf(pState->pTdbState->idstr, "0x%" PRIx64 "-%d", pState->streamId, pState->taskId);
|
sprintf(pState->pTdbState->idstr, "0x%" PRIx64 "-%d", pState->streamId, pState->taskId);
|
||||||
taosThreadMutexLock(&handle->cfMutex);
|
taosThreadMutexLock(&handle->cfMutex);
|
||||||
RocksdbCfInst** ppInst = taosHashGet(handle->cfInst, pState->pTdbState->idstr, strlen(pState->pTdbState->idstr));
|
RocksdbCfInst** ppInst = taosHashGet(handle->cfInst, pState->pTdbState->idstr, strlen(pState->pTdbState->idstr) + 1);
|
||||||
if (ppInst != NULL && *ppInst != NULL) {
|
if (ppInst != NULL && *ppInst != NULL) {
|
||||||
RocksdbCfInst* inst = *ppInst;
|
RocksdbCfInst* inst = *ppInst;
|
||||||
pState->pTdbState->rocksdb = inst->db;
|
pState->pTdbState->rocksdb = inst->db;
|
||||||
|
@ -812,13 +880,14 @@ int streamStateOpenBackend(void* backend, SStreamState* pState) {
|
||||||
void streamStateCloseBackend(SStreamState* pState, bool remove) {
|
void streamStateCloseBackend(SStreamState* pState, bool remove) {
|
||||||
SBackendHandle* pHandle = pState->pTdbState->pBackendHandle;
|
SBackendHandle* pHandle = pState->pTdbState->pBackendHandle;
|
||||||
taosThreadMutexLock(&pHandle->cfMutex);
|
taosThreadMutexLock(&pHandle->cfMutex);
|
||||||
RocksdbCfInst** ppInst = taosHashGet(pHandle->cfInst, pState->pTdbState->idstr, strlen(pState->pTdbState->idstr));
|
RocksdbCfInst** ppInst = taosHashGet(pHandle->cfInst, pState->pTdbState->idstr, strlen(pState->pTdbState->idstr) + 1);
|
||||||
if (ppInst != NULL && *ppInst != NULL) {
|
if (ppInst != NULL && *ppInst != NULL) {
|
||||||
RocksdbCfInst* inst = *ppInst;
|
RocksdbCfInst* inst = *ppInst;
|
||||||
taosMemoryFree(inst);
|
taosMemoryFree(inst);
|
||||||
taosHashRemove(pHandle->cfInst, pState->pTdbState->idstr, strlen(pState->pTdbState->idstr));
|
taosHashRemove(pHandle->cfInst, pState->pTdbState->idstr, strlen(pState->pTdbState->idstr) + 1);
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&pHandle->cfMutex);
|
taosThreadMutexUnlock(&pHandle->cfMutex);
|
||||||
|
|
||||||
char* status[] = {"close", "drop"};
|
char* status[] = {"close", "drop"};
|
||||||
qInfo("start to %s backend, %p, 0x%" PRIx64 "-%d", status[remove == false ? 0 : 1], pState, pState->streamId,
|
qInfo("start to %s backend, %p, 0x%" PRIx64 "-%d", status[remove == false ? 0 : 1], pState, pState->streamId,
|
||||||
pState->taskId);
|
pState->taskId);
|
||||||
|
|
|
@ -94,6 +94,7 @@ _err:
|
||||||
if (pMeta->db) tdbClose(pMeta->db);
|
if (pMeta->db) tdbClose(pMeta->db);
|
||||||
// if (pMeta->streamBackend) streamBackendCleanup(pMeta->streamBackend);
|
// if (pMeta->streamBackend) streamBackendCleanup(pMeta->streamBackend);
|
||||||
taosMemoryFree(pMeta);
|
taosMemoryFree(pMeta);
|
||||||
|
qError("failed to open stream meta");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue