more progress
This commit is contained in:
parent
eef8f49af0
commit
36c20ec617
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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_INT_H_
|
||||
#define _TD_META_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct {
|
||||
tkv_db_t db;
|
||||
} SMeta;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_META_INT_H_*/
|
|
@ -22,10 +22,22 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint64_t tb_uid_t;
|
||||
tb_uid_t metaGenerateUid();
|
||||
/* ------------------------ APIS EXPOSED ------------------------ */
|
||||
typedef uint64_t tb_uid_t;
|
||||
typedef struct STableUidGenerator STableUidGenerator;
|
||||
|
||||
// tb_uid_t
|
||||
#define IVLD_TB_UID 0
|
||||
tb_uid_t generateUid(STableUidGenerator *);
|
||||
|
||||
// STableUidGenerator
|
||||
void tableUidGeneratorInit(STableUidGenerator *, tb_uid_t suid);
|
||||
#define tableUidGeneratorClear(ug)
|
||||
|
||||
/* ------------------------ FOR TEST AND COMPILE ONLY ------------------------ */
|
||||
struct STableUidGenerator {
|
||||
tb_uid_t nextUid;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tkv.h"
|
||||
#include "thash.h"
|
||||
#include "tkv.h"
|
||||
#include "tlist.h"
|
||||
#include "tlockfree.h"
|
||||
#include "ttypes.h"
|
||||
|
@ -43,13 +43,14 @@ typedef struct STableObj {
|
|||
struct SMeta {
|
||||
pthread_rwlock_t rwLock;
|
||||
|
||||
SHashObj *pTableObjHash; // uid --> STableObj
|
||||
SList * stbList; // super table list
|
||||
STkvDb * tbnameDb; // tbname --> uid
|
||||
STkvDb * tagDb; // uid --> tag
|
||||
STkvDb * schemaDb;
|
||||
STkvDb * tagIdx;
|
||||
size_t totalUsed;
|
||||
STableUidGenerator uidGenerator;
|
||||
SHashObj * pTableObjHash; // uid --> STableObj
|
||||
SList * stbList; // super table list
|
||||
STkvDb * tbnameDb; // tbname --> uid
|
||||
STkvDb * tagDb; // uid --> tag
|
||||
STkvDb * schemaDb;
|
||||
STkvDb * tagIdx;
|
||||
size_t totalUsed;
|
||||
};
|
||||
|
||||
static STable * metaTableNew(tb_uid_t uid, const char *name, int32_t sver);
|
||||
|
@ -68,6 +69,7 @@ SMeta *metaOpen(SMetaOpts *options) {
|
|||
|
||||
pthread_rwlock_init(&(pMeta->rwLock), NULL);
|
||||
|
||||
tableUidGeneratorInit(&(pMeta->uidGenerator), IVLD_TB_UID);
|
||||
pMeta->pTableObjHash = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
|
||||
pMeta->stbList = tdListNew(sizeof(STableObj *));
|
||||
|
@ -109,9 +111,9 @@ void metaClose(SMeta *pMeta) {
|
|||
}
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
|
||||
size_t vallen;
|
||||
STkvReadOpts *ropt;
|
||||
STableObj * pTableObj = NULL;
|
||||
size_t vallen;
|
||||
STkvReadOpts * ropt;
|
||||
STableObj * pTableObj = NULL;
|
||||
STkvWriteOpts *wopt;
|
||||
|
||||
// Check if table already exists
|
||||
|
@ -133,7 +135,8 @@ int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
|
|||
}
|
||||
|
||||
// Create table object
|
||||
pTableObj->pTable = metaTableNew(metaGenerateUid(), pTableOpts->name, schemaVersion(pTableOpts->pSchema));
|
||||
pTableObj->pTable =
|
||||
metaTableNew(generateUid(&(pMeta->uidGenerator)), pTableOpts->name, schemaVersion(pTableOpts->pSchema));
|
||||
if (pTableObj->pTable == NULL) {
|
||||
// TODO
|
||||
}
|
||||
|
@ -147,7 +150,7 @@ int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
|
|||
|
||||
// Add to tbname db
|
||||
tkvPut(pMeta->tbnameDb, wopt, pTableOpts->name, strlen(pTableOpts->name), (char *)&pTableObj->pTable->uid,
|
||||
sizeof(tb_uid_t));
|
||||
sizeof(tb_uid_t));
|
||||
|
||||
// Add to schema db
|
||||
char id[12];
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
|
||||
#include "metaUid.h"
|
||||
|
||||
static tb_uid_t nuid = IVLD_TB_UID;
|
||||
tb_uid_t generateUid(STableUidGenerator *pGen) {
|
||||
// Generate a new table UID
|
||||
return ++(pGen->nextUid);
|
||||
}
|
||||
|
||||
tb_uid_t metaGenerateUid() {
|
||||
// TODO: need a more complex UID generator
|
||||
return ++nuid;
|
||||
void tableUidGeneratorInit(STableUidGenerator *pGen, tb_uid_t suid) {
|
||||
// Init a generator
|
||||
pGen->nextUid = suid;
|
||||
}
|
Loading…
Reference in New Issue