refact
This commit is contained in:
parent
d78480998f
commit
d5af05860e
|
@ -25,6 +25,7 @@ extern "C" {
|
||||||
extern const SVnodeOptions defaultVnodeOptions;
|
extern const SVnodeOptions defaultVnodeOptions;
|
||||||
|
|
||||||
int vnodeValidateOptions(const SVnodeOptions *);
|
int vnodeValidateOptions(const SVnodeOptions *);
|
||||||
|
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions);
|
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions);
|
||||||
static void vnodeFree(SVnode *pVnode);
|
static void vnodeFree(SVnode *pVnode);
|
||||||
|
static int vnodeOpenImpl(SVnode *pVnode);
|
||||||
|
static void vnodeCloseImpl(SVnode *pVnode);
|
||||||
|
|
||||||
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) {
|
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) {
|
||||||
SVnode *pVnode = NULL;
|
SVnode *pVnode = NULL;
|
||||||
|
@ -32,6 +34,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the handle
|
||||||
pVnode = vnodeNew(path, pVnodeOptions);
|
pVnode = vnodeNew(path, pVnodeOptions);
|
||||||
if (pVnode == NULL) {
|
if (pVnode == NULL) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
|
@ -40,22 +43,52 @@ SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) {
|
||||||
|
|
||||||
taosMkDir(path);
|
taosMkDir(path);
|
||||||
|
|
||||||
|
// Open the vnode
|
||||||
|
if (vnodeOpenImpl(pVnode) < 0) {
|
||||||
|
// TODO: handle error
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return pVnode;
|
return pVnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeClose(SVnode *pVnode) { /* TODO */
|
void vnodeClose(SVnode *pVnode) {
|
||||||
|
if (pVnode) {
|
||||||
|
vnodeCloseImpl(pVnode);
|
||||||
|
vnodeFree(pVnode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeDestroy(const char *path) { taosRemoveDir(path); }
|
void vnodeDestroy(const char *path) { taosRemoveDir(path); }
|
||||||
|
|
||||||
/* ------------------------ STATIC METHODS ------------------------ */
|
/* ------------------------ STATIC METHODS ------------------------ */
|
||||||
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) {
|
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) {
|
||||||
|
SVnode *pVnode = NULL;
|
||||||
|
|
||||||
|
pVnode = (SVnode *)calloc(1, sizeof(*pVnode));
|
||||||
|
if (pVnode == NULL) {
|
||||||
// TODO
|
// TODO
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pVnode->path = strdup(path);
|
||||||
|
vnodeOptionsCopy(&(pVnode->options), pVnodeOptions);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void vnodeFree(SVnode *pVnode) {
|
static void vnodeFree(SVnode *pVnode) {
|
||||||
if (pVnode) {
|
if (pVnode) {
|
||||||
|
tfree(pVnode->path);
|
||||||
|
free(pVnode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vnodeOpenImpl(SVnode *pVnode) {
|
||||||
|
// TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vnodeCloseImpl(SVnode *pVnode) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -27,3 +27,7 @@ int vnodeValidateOptions(const SVnodeOptions *pVnodeOptions) {
|
||||||
// TODO
|
// TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc) {
|
||||||
|
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeOptions));
|
||||||
|
}
|
Loading…
Reference in New Issue