more
This commit is contained in:
parent
512ad36e62
commit
b45884c151
|
@ -56,6 +56,16 @@ void metaQueryHandleDestroy(SMetaQueryHandle *);
|
|||
SMetaQueryOpts *metaQueryOptionsCreate();
|
||||
void metaQueryOptionsDestroy(SMetaQueryOpts *);
|
||||
|
||||
// STableOpts
|
||||
void metaTableOptsInit(int8_t type, const char *name, const STSchema *pSchema);
|
||||
|
||||
/* -------------------------------- Hided implementations -------------------------------- */
|
||||
struct STableOpts {
|
||||
int8_t type;
|
||||
char * name;
|
||||
STSchema *pSchema;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_META_UID_H_
|
||||
#define _TD_META_UID_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint64_t tb_uid_t;
|
||||
tb_uid_t metaGenerateUid();
|
||||
|
||||
#define IVLD_TB_UID 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_META_UID_H_*/
|
|
@ -21,12 +21,14 @@
|
|||
#include "ttypes.h"
|
||||
|
||||
#include "meta.h"
|
||||
#include "metaUid.h"
|
||||
|
||||
/* -------------------- Structures -------------------- */
|
||||
|
||||
typedef struct STable {
|
||||
uint64_t uid;
|
||||
tstr * name;
|
||||
uint64_t suid;
|
||||
tb_uid_t uid;
|
||||
char * name;
|
||||
tb_uid_t suid;
|
||||
SArray * schema;
|
||||
} STable;
|
||||
|
||||
|
@ -51,11 +53,8 @@ struct SMeta {
|
|||
size_t totalUsed;
|
||||
};
|
||||
|
||||
struct STableOpts {
|
||||
int8_t type;
|
||||
char * name;
|
||||
STSchema *pSchema;
|
||||
};
|
||||
static STable * metaTableNew(tb_uid_t uid, const char *name, int32_t sver);
|
||||
static STableObj *metaTableObjNew();
|
||||
|
||||
/* -------------------- Methods -------------------- */
|
||||
|
||||
|
@ -111,10 +110,97 @@ void metaClose(SMeta *pMeta) {
|
|||
}
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
|
||||
// TODO
|
||||
size_t vallen;
|
||||
char * err = NULL;
|
||||
rocksdb_readoptions_t * ropt;
|
||||
STableObj * pTableObj = NULL;
|
||||
rocksdb_writeoptions_t *wopt;
|
||||
|
||||
// Check if table already exists
|
||||
ropt = rocksdb_readoptions_create();
|
||||
|
||||
char *uidStr = rocksdb_get(pMeta->tbnameDb, ropt, pTableOpts->name, strlen(pTableOpts->name), &vallen, &err);
|
||||
if (uidStr != NULL) {
|
||||
// Has duplicate named table
|
||||
return -1;
|
||||
}
|
||||
|
||||
rocksdb_readoptions_destroy(ropt);
|
||||
|
||||
// Create table obj
|
||||
pTableObj = metaTableObjNew();
|
||||
if (pTableObj == NULL) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create table object
|
||||
pTableObj->pTable = metaTableNew(metaGenerateUid(), pTableOpts->name, schemaVersion(pTableOpts->pSchema));
|
||||
if (pTableObj->pTable == NULL) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
pthread_rwlock_rdlock(&pMeta->rwLock);
|
||||
|
||||
taosHashPut(pMeta->pTableObjHash, &(pTableObj->pTable->uid), sizeof(tb_uid_t), &pTableObj, sizeof(pTableObj));
|
||||
|
||||
wopt = rocksdb_writeoptions_create();
|
||||
|
||||
rocksdb_put(pMeta->tbnameDb, wopt, pTableOpts->name, strlen(pTableOpts->name), &pTableObj->pTable->uid,
|
||||
sizeof(tb_uid_t), &err);
|
||||
rocksdb_put(pMeta->schemaDb, wopt, pTableOpts->name, strlen(pTableOpts->name), &pTableObj->pTable->uid,
|
||||
sizeof(tb_uid_t), &err);
|
||||
|
||||
rocksdb_writeoptions_destroy(wopt);
|
||||
|
||||
pthread_rwlock_unlock(&pMeta->rwLock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaDestroy(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
int metaCommit(SMeta *meta) { return 0; }
|
||||
|
||||
/* -------------------- Static Methods -------------------- */
|
||||
|
||||
static STable *metaTableNew(tb_uid_t uid, const char *name, int32_t sver) {
|
||||
STable *pTable = NULL;
|
||||
|
||||
pTable = (STable *)malloc(sizeof(*pTable));
|
||||
if (pTable == NULL) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTable->schema = taosArrayInit(0, sizeof(int32_t));
|
||||
if (pTable->schema == NULL) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTable->uid = uid;
|
||||
pTable->name = strdup(name);
|
||||
pTable->suid = IVLD_TB_UID;
|
||||
taosArrayPush(pTable->schema, &sver);
|
||||
|
||||
return pTable;
|
||||
}
|
||||
|
||||
static STableObj *metaTableObjNew() {
|
||||
STableObj *pTableObj = NULL;
|
||||
|
||||
pTableObj = (STableObj *)malloc(sizeof(*pTableObj));
|
||||
if (pTableObj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTableObj->pin = true;
|
||||
pTableObj->ref = 1;
|
||||
taosInitRWLatch(&(pTableObj->latch));
|
||||
pTableObj->offset = UINT64_MAX;
|
||||
pTableObj->ctbList = NULL;
|
||||
pTableObj->pTable = NULL;
|
||||
|
||||
return pTableObj;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "metaUid.h"
|
||||
|
||||
static tb_uid_t nuid = IVLD_TB_UID;
|
||||
|
||||
tb_uid_t metaGenerateUid() {
|
||||
// TODO: need a more complex UID generator
|
||||
return ++nuid;
|
||||
}
|
|
@ -2,6 +2,7 @@ add_executable(metaTest "")
|
|||
target_sources(metaTest
|
||||
PRIVATE
|
||||
"../src/meta.c"
|
||||
"../src/metaUid.c"
|
||||
"metaTests.cpp"
|
||||
)
|
||||
target_include_directories(metaTest
|
||||
|
|
Loading…
Reference in New Issue