Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7a37edce
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7a37edce
编写于
11月 12, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix sdb errors
上级
f26cf444
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
192 addition
and
118 deletion
+192
-118
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+11
-8
include/util/taoserror.h
include/util/taoserror.h
+9
-7
source/dnode/mnode/impl/src/mnodeAcct.c
source/dnode/mnode/impl/src/mnodeAcct.c
+1
-0
source/dnode/mnode/impl/src/mnodeUser.c
source/dnode/mnode/impl/src/mnodeUser.c
+2
-4
source/dnode/mnode/sdb/inc/sdbInt.h
source/dnode/mnode/sdb/inc/sdbInt.h
+2
-2
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+1
-1
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+44
-34
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+120
-52
source/dnode/mnode/sdb/src/sdbRaw.c
source/dnode/mnode/sdb/src/sdbRaw.c
+0
-10
source/util/src/terror.c
source/util/src/terror.c
+2
-0
未找到文件。
include/dnode/mnode/sdb/sdb.h
浏览文件 @
7a37edce
...
...
@@ -95,11 +95,21 @@ extern "C" {
#define SDB_SET_DATALEN(pRaw, dataLen) \
{ \
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
sdbFreeRaw(pRaw);
\
sdbFreeRaw(pRaw); \
return NULL; \
}; \
}
typedef
struct
SSdbRaw
SSdbRaw
;
typedef
struct
SSdbRow
SSdbRow
;
typedef
enum
{
SDB_KEY_BINARY
=
1
,
SDB_KEY_INT32
=
2
,
SDB_KEY_INT64
=
3
}
EKeyType
;
typedef
enum
{
SDB_STATUS_CREATING
=
1
,
SDB_STATUS_READY
=
2
,
SDB_STATUS_DROPPING
=
3
,
SDB_STATUS_DROPPED
=
4
}
ESdbStatus
;
typedef
enum
{
SDB_START
=
0
,
SDB_TRANS
=
1
,
...
...
@@ -116,12 +126,6 @@ typedef enum {
SDB_MAX
=
12
}
ESdbType
;
typedef
enum
{
SDB_ACTION_INSERT
=
1
,
SDB_ACTION_UPDATE
=
2
,
SDB_ACTION_DELETE
=
3
}
ESdbAction
;
typedef
enum
{
SDB_KEY_BINARY
=
1
,
SDB_KEY_INT32
=
2
,
SDB_KEY_INT64
=
3
}
EKeyType
;
typedef
enum
{
SDB_STATUS_CREATING
=
1
,
SDB_STATUS_READY
=
2
,
SDB_STATUS_DROPPING
=
3
}
ESdbStatus
;
typedef
struct
SSdbRaw
SSdbRaw
;
typedef
struct
SSdbRow
SSdbRow
;
typedef
int32_t
(
*
SdbInsertFp
)(
void
*
pObj
);
typedef
int32_t
(
*
SdbUpdateFp
)(
void
*
pSrcObj
,
void
*
pDstObj
);
typedef
int32_t
(
*
SdbDeleteFp
)(
void
*
pObj
);
...
...
@@ -165,7 +169,6 @@ int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val);
int32_t
sdbSetRawBinary
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
const
char
*
pVal
,
int32_t
valLen
);
int32_t
sdbSetRawDataLen
(
SSdbRaw
*
pRaw
,
int32_t
dataLen
);
int32_t
sdbSetRawStatus
(
SSdbRaw
*
pRaw
,
ESdbStatus
status
);
int32_t
sdbSetRawAction
(
SSdbRaw
*
pRaw
,
ESdbAction
action
);
int32_t
sdbGetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
*
val
);
int32_t
sdbGetRawInt32
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int32_t
*
val
);
int32_t
sdbGetRawInt64
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int64_t
*
val
);
...
...
include/util/taoserror.h
浏览文件 @
7a37edce
...
...
@@ -136,13 +136,15 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0320)
#define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0321)
#define TSDB_CODE_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0322)
#define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0323)
#define TSDB_CODE_SDB_INVALID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0324)
#define TSDB_CODE_SDB_INVALID_ACTION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325)
#define TSDB_CODE_SDB_INVALID_STATUS_TYPE TAOS_DEF_ERROR_CODE(0, 0x0326)
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0327)
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x0328)
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x0329)
#define TSDB_CODE_SDB_OBJ_CREATING TAOS_DEF_ERROR_CODE(0, 0x0323)
#define TSDB_CODE_SDB_OBJ_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0324)
#define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325)
#define TSDB_CODE_SDB_INVALID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0326)
#define TSDB_CODE_SDB_INVALID_ACTION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0327)
#define TSDB_CODE_SDB_INVALID_STATUS_TYPE TAOS_DEF_ERROR_CODE(0, 0x0328)
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0329)
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x032A)
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x032B)
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0330) //"DNode already exists")
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0331) //"DNode does not exist")
...
...
source/dnode/mnode/impl/src/mnodeAcct.c
浏览文件 @
7a37edce
...
...
@@ -94,6 +94,7 @@ static int32_t mnodeCreateDefaultAcct() {
SSdbRaw
*
pRaw
=
mnodeAcctActionEncode
(
&
acctObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
return
sdbWrite
(
pRaw
);
}
...
...
source/dnode/mnode/impl/src/mnodeUser.c
浏览文件 @
7a37edce
...
...
@@ -110,6 +110,7 @@ static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
SSdbRaw
*
pRaw
=
mnodeUserActionEncode
(
&
userObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
return
sdbWrite
(
pRaw
);
}
...
...
@@ -149,15 +150,13 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
sdbSetRawAction
(
pRedoRaw
,
SDB_ACTION_INSERT
);
SSdbRaw
*
pUndoRaw
=
mnodeUserActionEncode
(
&
userObj
);
if
(
pUndoRaw
==
NULL
||
trnAppendUndoLog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
trnDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPING
);
sdbSetRawAction
(
pUndoRaw
,
SDB_ACTION_DELETE
);
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
SSdbRaw
*
pCommitRaw
=
mnodeUserActionEncode
(
&
userObj
);
if
(
pCommitRaw
==
NULL
||
trnAppendCommitLog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
...
...
@@ -165,7 +164,6 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
sdbSetRawAction
(
pCommitRaw
,
SDB_ACTION_UPDATE
);
if
(
trnPrepare
(
pTrans
,
mnodeSyncPropose
)
!=
0
)
{
trnDrop
(
pTrans
);
...
...
source/dnode/mnode/sdb/inc/sdbInt.h
浏览文件 @
7a37edce
...
...
@@ -40,14 +40,14 @@ typedef struct SSdbRaw {
int8_t
sdb
;
int8_t
sver
;
int8_t
status
;
int8_t
action
;
int8_t
reserved
[
4
];
int8_t
reserved
;
int32_t
cksum
;
int32_t
dataLen
;
char
pData
[];
}
SSdbRaw
;
typedef
struct
SSdbRow
{
ESdbType
sdb
;
ESdbStatus
status
;
int32_t
refCount
;
char
pObj
[];
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
7a37edce
...
...
@@ -45,7 +45,7 @@ int32_t sdbInit() {
type
=
TSDB_DATA_TYPE_BINARY
;
}
SHashObj
*
hash
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
type
),
true
,
HASH_NO_LOCK
);
SHashObj
*
hash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
type
),
true
,
HASH_NO_LOCK
);
if
(
hash
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
7a37edce
...
...
@@ -17,8 +17,9 @@
#include "sdbInt.h"
#include "tglobal.h"
static
int32_t
sdbCreateDir
()
{
mDebug
(
"start to create mnode at %s"
,
tsMnodeDir
);
if
(
!
taosMkDir
(
tsSdb
.
currDir
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to create dir:%s since %s"
,
tsSdb
.
currDir
,
terrstr
());
...
...
@@ -41,6 +42,8 @@ static int32_t sdbCreateDir() {
}
static
int32_t
sdbRunDeployFp
()
{
mDebug
(
"start to run deploy functions"
);
for
(
int32_t
i
=
SDB_START
;
i
<
SDB_MAX
;
++
i
)
{
SdbDeployFp
fp
=
tsSdb
.
deployFps
[
i
];
if
(
fp
==
NULL
)
continue
;
...
...
@@ -58,25 +61,26 @@ static int32_t sdbWriteVersion(FileFd fd) { return 0; }
static
int32_t
sdbReadVersion
(
FileFd
fd
)
{
return
0
;
}
static
int32_t
sdbReadDataFile
()
{
int32_t
code
=
0
;
SSdbRaw
*
pRaw
=
malloc
(
SDB_MAX_SIZE
);
if
(
pRaw
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
char
file
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%ssdb.data"
,
tsSdb
.
currDir
);
FileFd
fd
=
taosOpenFileCreateWrite
(
file
);
if
(
fd
<=
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to open file:%s for read since %s"
,
file
,
t
strerror
(
code
));
return
code
;
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to open file:%s for read since %s"
,
file
,
t
errstr
(
));
return
-
1
;
}
int64_t
offset
=
0
;
int32_t
code
=
0
;
while
(
1
)
{
int
32_t
ret
=
(
int32_t
)
taosReadFile
(
fd
,
pRaw
,
sizeof
(
SSdbRaw
));
int
64_t
ret
=
taosReadFile
(
fd
,
pRaw
,
sizeof
(
SSdbRaw
));
if
(
ret
==
0
)
break
;
if
(
ret
<
0
)
{
...
...
@@ -93,7 +97,7 @@ static int32_t sdbReadDataFile() {
code
=
sdbWrite
(
pRaw
);
if
(
code
!=
0
)
{
mError
(
"failed to read file:%s since %s"
,
file
,
t
strerror
(
code
));
mError
(
"failed to read file:%s since %s"
,
file
,
t
errstr
(
));
goto
PARSE_SDB_DATA_ERROR
;
}
}
...
...
@@ -102,32 +106,35 @@ static int32_t sdbReadDataFile() {
PARSE_SDB_DATA_ERROR:
taosCloseFile
(
fd
);
terrno
=
code
;
return
code
;
}
static
int32_t
sdbWriteDataFile
()
{
int32_t
code
=
0
;
char
tmpfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
tmpfile
,
sizeof
(
tmpfile
),
"%ssdb.data"
,
tsSdb
.
tmpDir
);
FileFd
fd
=
taosOpenFileCreateWrite
(
tmpfile
);
if
(
fd
<=
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to open file:%s for write since %s"
,
tmpfile
,
t
strerror
(
code
));
return
code
;
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to open file:%s for write since %s"
,
tmpfile
,
t
errstr
(
));
return
-
1
;
}
for
(
int32_t
i
=
SDB_MAX
-
1
;
i
>
SDB_START
;
--
i
)
{
SHashObj
*
hash
=
tsSdb
.
hashObjs
[
i
];
if
(
!
hash
)
continue
;
int32_t
code
=
0
;
for
(
int32_t
i
=
SDB_MAX
-
1
;
i
>
SDB_START
;
--
i
)
{
SdbEncodeFp
encodeFp
=
tsSdb
.
encodeFps
[
i
];
if
(
!
encodeFp
)
continue
;
if
(
encodeFp
==
NULL
)
continue
;
SHashObj
*
hash
=
tsSdb
.
hashObjs
[
i
];
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
i
];
taosWLockLatch
(
pLock
);
SSdbRow
*
pRow
=
taosHashIterate
(
hash
,
NULL
);
while
(
pRow
!=
NULL
)
{
if
(
pRow
->
status
==
SDB_STATUS_READY
)
continue
;
if
(
pRow
->
status
!=
SDB_STATUS_READY
)
continue
;
SSdbRaw
*
pRaw
=
(
*
encodeFp
)(
pRow
->
pObj
);
if
(
pRaw
!=
NULL
)
{
taosWriteFile
(
fd
,
pRaw
,
sizeof
(
SSdbRaw
)
+
pRaw
->
dataLen
);
...
...
@@ -139,6 +146,7 @@ static int32_t sdbWriteDataFile() {
pRow
=
taosHashIterate
(
hash
,
pRow
);
}
taosWUnLockLatch
(
pLock
);
}
if
(
code
==
0
)
{
...
...
@@ -151,41 +159,40 @@ static int32_t sdbWriteDataFile() {
code
=
taosFsyncFile
(
fd
);
}
if
(
code
!
=
0
)
{
if
(
code
=
=
0
)
{
char
curfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
curfile
,
sizeof
(
curfile
),
"%ssdb.data"
,
tsSdb
.
currDir
);
code
=
taosRenameFile
(
tmpfile
,
curfile
);
}
if
(
code
!=
0
)
{
mError
(
"failed to write sdb file since %s"
,
tstrerror
(
code
));
terrno
=
code
;
mError
(
"failed to write sdb file since %s"
,
terrstr
());
}
else
{
m
Info
(
"write sdb file successfully"
);
m
Debug
(
"write sdb file successfully"
);
}
return
code
;
}
int32_t
sdbRead
()
{
int32_t
code
=
sdbReadDataFile
();
if
(
code
!=
0
)
{
return
code
;
mDebug
(
"start to read mnode file"
);
if
(
sdbReadDataFile
()
!=
0
)
{
return
-
1
;
}
mInfo
(
"read sdb file successfully"
);
return
-
1
;
return
0
;
}
int32_t
sdbCommit
()
{
int32_t
code
=
sdbWriteDataFile
();
if
(
code
!=
0
)
{
return
code
;
}
return
0
;
mDebug
(
"start to commit mnode file"
);
return
sdbWriteDataFile
();
}
int32_t
sdbDeploy
()
{
mDebug
(
"start to deploy mnode"
);
if
(
sdbCreateDir
()
!=
0
)
{
return
-
1
;
}
...
...
@@ -201,4 +208,7 @@ int32_t sdbDeploy() {
return
0
;
}
void
sdbUnDeploy
()
{}
void
sdbUnDeploy
()
{
mDebug
(
"start to undeploy mnode"
);
taosRemoveDir
(
tsMnodeDir
);
}
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
7a37edce
...
...
@@ -32,25 +32,49 @@ static SHashObj *sdbGetHash(int32_t sdb) {
return
hash
;
}
static
int32_t
sdbGetkeySize
(
ESdbType
sdb
,
void
*
pKey
)
{
int32_t
keySize
;
EKeyType
keyType
=
tsSdb
.
keyTypes
[
sdb
];
if
(
keyType
==
SDB_KEY_INT32
)
{
keySize
=
sizeof
(
int32_t
);
}
else
if
(
keyType
==
SDB_KEY_BINARY
)
{
keySize
=
strlen
(
pKey
)
+
1
;
}
else
{
keySize
=
sizeof
(
int64_t
);
}
return
keySize
;
}
static
int32_t
sdbInsertRow
(
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
SSdbRow
*
pDstRow
=
NULL
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
taosWLockLatch
(
pLock
);
SSdbRow
*
pDstRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
pDstRow
!=
NULL
)
{
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
taosWUnLockLatch
(
pLock
);
return
-
1
;
}
pRow
->
refCount
=
0
;
pRow
->
refCount
=
1
;
pRow
->
status
=
pRaw
->
status
;
if
(
taosHashPut
(
hash
,
pRow
->
pObj
,
keySize
,
&
pRow
,
sizeof
(
void
*
))
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
taosWUnLockLatch
(
pLock
);
return
-
1
;
}
SdbInsertFp
insertFp
=
tsSdb
.
insertFps
[
pRaw
->
sdb
];
taosWUnLockLatch
(
pLock
);
SdbInsertFp
insertFp
=
tsSdb
.
insertFps
[
pRow
->
sdb
];
if
(
insertFp
!=
NULL
)
{
if
((
*
insertFp
)(
pRow
->
pObj
)
!=
0
)
{
taosWLockLatch
(
pLock
);
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
return
-
1
;
}
}
...
...
@@ -59,13 +83,20 @@ static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
}
static
int32_t
sdbUpdateRow
(
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
SSdbRow
*
pDstRow
=
NULL
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
taosRLockLatch
(
pLock
);
SSdbRow
*
pDstRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
pDstRow
==
NULL
)
{
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
taosRUnLockLatch
(
pLock
);
return
-
1
;
}
SdbUpdateFp
updateFp
=
tsSdb
.
updateFps
[
pRaw
->
sdb
];
pRow
->
status
=
pRaw
->
status
;
taosRUnLockLatch
(
pLock
);
SdbUpdateFp
updateFp
=
tsSdb
.
updateFps
[
pRow
->
sdb
];
if
(
updateFp
!=
NULL
)
{
if
((
*
updateFp
)(
pRow
->
pObj
,
pDstRow
->
pObj
)
!=
0
)
{
return
-
1
;
...
...
@@ -76,20 +107,28 @@ static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
}
static
int32_t
sdbDeleteRow
(
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
SSdbRow
*
pDstRow
=
NULL
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
taosWLockLatch
(
pLock
);
SSdbRow
*
pDstRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
pDstRow
==
NULL
)
{
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
taosWUnLockLatch
(
pLock
);
return
-
1
;
}
SdbDeleteFp
deleteFp
=
tsSdb
.
deleteFps
[
pRaw
->
sdb
];
pRow
->
status
=
pRaw
->
status
;
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
SdbDeleteFp
deleteFp
=
tsSdb
.
deleteFps
[
pRow
->
sdb
];
if
(
deleteFp
!=
NULL
)
{
if
((
*
deleteFp
)(
pRow
->
pObj
)
!=
0
)
{
return
-
1
;
}
}
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
sdbRelease
(
pRow
->
pObj
);
return
0
;
}
...
...
@@ -104,73 +143,87 @@ int32_t sdbWrite(SSdbRaw *pRaw) {
return
-
1
;
}
int32_t
keySize
;
EKeyType
keyType
=
tsSdb
.
keyTypes
[
pRaw
->
sdb
];
if
(
keyType
==
SDB_KEY_INT32
)
{
keySize
=
sizeof
(
int32_t
);
}
else
if
(
keyType
==
SDB_KEY_BINARY
)
{
keySize
=
strlen
(
pRow
->
pObj
)
+
1
;
}
else
{
keySize
=
sizeof
(
int64_t
);
}
pRow
->
sdb
=
pRaw
->
sdb
;
int32_t
keySize
=
sdbGetkeySize
(
pRow
->
sdb
,
pRow
->
pObj
);
int32_t
code
=
-
1
;
if
(
pRaw
->
action
==
SDB_ACTION_INSERT
)
{
code
=
sdbInsertRow
(
hash
,
pRaw
,
pRow
,
keySize
);
}
else
if
(
pRaw
->
action
==
SDB_ACTION_UPDATE
)
{
code
=
sdbUpdateRow
(
hash
,
pRaw
,
pRow
,
keySize
);
}
else
if
(
pRaw
->
action
==
SDB_ACTION_DELETE
)
{
code
=
sdbDeleteRow
(
hash
,
pRaw
,
pRow
,
keySize
);
}
else
{
terrno
=
TSDB_CODE_SDB_INVALID_ACTION_TYPE
;
switch
(
pRaw
->
status
)
{
case
SDB_STATUS_CREATING
:
code
=
sdbInsertRow
(
hash
,
pRaw
,
pRow
,
keySize
);
break
;
case
SDB_STATUS_READY
:
case
SDB_STATUS_DROPPING
:
code
=
sdbUpdateRow
(
hash
,
pRaw
,
pRow
,
keySize
);
break
;
case
SDB_STATUS_DROPPED
:
code
=
sdbDeleteRow
(
hash
,
pRaw
,
pRow
,
keySize
);
break
;
default:
terrno
=
TSDB_CODE_SDB_INVALID_ACTION_TYPE
;
break
;
}
if
(
code
!=
0
)
{
sdbFreeRow
(
pRow
);
}
return
0
;
}
void
*
sdbAcquire
(
ESdbType
sdb
,
void
*
pKey
)
{
terrno
=
0
;
SHashObj
*
hash
=
sdbGetHash
(
sdb
);
if
(
hash
==
NULL
)
{
if
(
hash
==
NULL
)
return
NULL
;
void
*
pRet
=
NULL
;
int32_t
keySize
=
sdbGetkeySize
(
sdb
,
pKey
);
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
taosRLockLatch
(
pLock
);
SSdbRow
**
ppRow
=
taosHashGet
(
hash
,
pKey
,
keySize
);
if
(
ppRow
==
NULL
||
*
ppRow
)
{
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
taosRUnLockLatch
(
pLock
);
return
NULL
;
}
int32_t
keySize
;
EKeyType
keyType
=
tsSdb
.
keyTypes
[
sdb
];
switch
(
keyType
)
{
case
SDB_KEY_INT32
:
keySize
=
sizeof
(
int32_t
);
SSdbRow
*
pRow
=
*
ppRow
;
switch
(
pRow
->
status
)
{
case
SDB_STATUS_READY
:
atomic_add_fetch_32
(
&
pRow
->
refCount
,
1
);
pRet
=
pRow
->
pObj
;
break
;
case
SDB_
KEY_INT64
:
keySize
=
sizeof
(
int64_t
)
;
case
SDB_
STATUS_CREATING
:
terrno
=
TSDB_CODE_SDB_OBJ_CREATING
;
break
;
case
SDB_
KEY_BINARY
:
keySize
=
strlen
(
pKey
)
+
1
;
case
SDB_
STATUS_DROPPING
:
terrno
=
TSDB_CODE_SDB_OBJ_DROPPING
;
break
;
default:
keySize
=
sizeof
(
int32_t
);
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
break
;
}
SSdbRow
*
pRow
=
taosHashGet
(
hash
,
pKey
,
keySize
);
if
(
pRow
==
NULL
)
return
NULL
;
if
(
pRow
->
status
==
SDB_STATUS_READY
)
{
atomic_add_fetch_32
(
&
pRow
->
refCount
,
1
);
return
pRow
->
pObj
;
}
else
{
terrno
=
-
1
;
// todo
return
NULL
;
}
taosRUnLockLatch
(
pLock
);
return
pRet
;
}
void
sdbRelease
(
void
*
pObj
)
{
if
(
pObj
==
NULL
)
return
;
SSdbRow
*
pRow
=
(
SSdbRow
*
)((
char
*
)
pObj
-
sizeof
(
SSdbRow
));
atomic_sub_fetch_32
(
&
pRow
->
refCount
,
1
);
if
(
pRow
->
sdb
>=
SDB_MAX
||
pRow
->
sdb
<=
SDB_START
)
return
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
taosRLockLatch
(
pLock
);
int32_t
ref
=
atomic_sub_fetch_32
(
&
pRow
->
refCount
,
1
);
if
(
ref
<=
0
&&
pRow
->
status
==
SDB_STATUS_DROPPED
)
{
sdbFreeRow
(
pRow
);
}
taosRUnLockLatch
(
pLock
);
}
void
*
sdbFetchRow
(
ESdbType
sdb
,
void
*
pIter
)
{
...
...
@@ -179,7 +232,12 @@ void *sdbFetchRow(ESdbType sdb, void *pIter) {
return
NULL
;
}
return
taosHashIterate
(
hash
,
pIter
);
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
taosRLockLatch
(
pLock
);
void
*
pRet
=
taosHashIterate
(
hash
,
pIter
);
taosRUnLockLatch
(
pLock
);
return
pRet
;
}
void
sdbCancelFetch
(
ESdbType
sdb
,
void
*
pIter
)
{
...
...
@@ -187,7 +245,11 @@ void sdbCancelFetch(ESdbType sdb, void *pIter) {
if
(
hash
==
NULL
)
{
return
;
}
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
taosRLockLatch
(
pLock
);
taosHashCancelIterate
(
hash
,
pIter
);
taosRUnLockLatch
(
pLock
);
}
int32_t
sdbGetSize
(
ESdbType
sdb
)
{
...
...
@@ -195,5 +257,11 @@ int32_t sdbGetSize(ESdbType sdb) {
if
(
hash
==
NULL
)
{
return
0
;
}
return
taosHashGetSize
(
hash
);
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
taosRLockLatch
(
pLock
);
int32_t
size
=
taosHashGetSize
(
hash
);
taosRUnLockLatch
(
pLock
);
return
size
;
}
source/dnode/mnode/sdb/src/sdbRaw.c
浏览文件 @
7a37edce
...
...
@@ -116,16 +116,6 @@ int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
return
0
;
}
int32_t
sdbSetRawAction
(
SSdbRaw
*
pRaw
,
ESdbAction
action
)
{
if
(
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
return
-
1
;
}
pRaw
->
action
=
action
;
return
0
;
}
int32_t
sdbGetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
*
val
)
{
if
(
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
...
...
source/util/src/terror.c
浏览文件 @
7a37edce
...
...
@@ -147,6 +147,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_FAILED_TO_INIT_STEP, "failed to init compon
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_APP_ERROR
,
"Unexpected generic error in sdb"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_OBJ_ALREADY_THERE
,
"Object already there"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_OBJ_NOT_THERE
,
"Object not there"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_OBJ_CREATING
,
"Object is creating"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_OBJ_DROPPING
,
"Object is dropping"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_TABLE_TYPE
,
"Invalid table type"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_KEY_TYPE
,
"Invalid key type"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_ACTION_TYPE
,
"Invalid action type"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录