Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
708fef9a
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
708fef9a
编写于
2月 23, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
dac6531b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
82 addition
and
46 deletion
+82
-46
source/libs/tdb/src/db/tdb.c
source/libs/tdb/src/db/tdb.c
+1
-1
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+7
-7
source/libs/tdb/src/db/tdbPgCache.c
source/libs/tdb/src/db/tdbPgCache.c
+42
-14
source/libs/tdb/src/db/tdbPgFile.c
source/libs/tdb/src/db/tdbPgFile.c
+9
-9
source/libs/tdb/src/db/tdbUtil.c
source/libs/tdb/src/db/tdbUtil.c
+1
-1
source/libs/tdb/src/inc/tdbBtree.h
source/libs/tdb/src/inc/tdbBtree.h
+1
-1
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+3
-3
source/libs/tdb/src/inc/tdbPgCache.h
source/libs/tdb/src/inc/tdbPgCache.h
+12
-4
source/libs/tdb/src/inc/tdbPgFile.h
source/libs/tdb/src/inc/tdbPgFile.h
+5
-5
source/libs/tdb/src/inc/tdbUtil.h
source/libs/tdb/src/inc/tdbUtil.h
+1
-1
未找到文件。
source/libs/tdb/src/db/tdb.c
浏览文件 @
708fef9a
...
...
@@ -65,7 +65,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
SBTree
*
pBt
;
bool
fileExist
;
size_t
dbNameLen
;
pgno_t
dbRootPgno
;
SPgno
dbRootPgno
;
char
dbfname
[
128
];
// TODO: make this as a macro or malloc on the heap
ASSERT
(
pDb
!=
NULL
);
...
...
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
708fef9a
...
...
@@ -17,12 +17,12 @@
struct
SBtCursor
{
SBTree
*
pBtree
;
pgno_t
pgno
;
SPgno
pgno
;
SPage
*
pPage
;
// current page traversing
};
typedef
struct
{
pgno_t
pgno
;
SPgno
pgno
;
pgsz_t
offset
;
}
SBtIdx
;
...
...
@@ -34,7 +34,7 @@ typedef struct __attribute__((__packed__)) {
pgoff_t
freeOff
;
// free payload offset
pgsz_t
fragSize
;
// total fragment size
pgoff_t
offPayload
;
// payload offset
pgno_t
rChildPgno
;
// right most child page number
SPgno
rChildPgno
;
// right most child page number
}
SBtPgHdr
;
typedef
int
(
*
BtreeCmprFn
)(
const
void
*
,
const
void
*
);
...
...
@@ -45,7 +45,7 @@ typedef int (*BtreeCmprFn)(const void *, const void *);
static
int
btreeCreate
(
SBTree
**
ppBt
);
static
int
btreeDestroy
(
SBTree
*
pBt
);
static
int
btreeCursorMoveToChild
(
SBtCursor
*
pBtCur
,
pgno_t
pgno
);
static
int
btreeCursorMoveToChild
(
SBtCursor
*
pBtCur
,
SPgno
pgno
);
int
btreeOpen
(
SBTree
**
ppBt
,
SPgFile
*
pPgFile
)
{
SBTree
*
pBt
;
...
...
@@ -98,8 +98,8 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) {
SPage
*
pPage
;
SBtPgHdr
*
pBtPgHdr
;
SPgFile
*
pPgFile
;
pgno_t
childPgno
;
pgno_t
rootPgno
;
SPgno
childPgno
;
SPgno
rootPgno
;
int
nPayloads
;
void
*
pPayload
;
BtreeCmprFn
cmpFn
;
...
...
@@ -157,7 +157,7 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) {
return
0
;
}
static
int
btreeCursorMoveToChild
(
SBtCursor
*
pBtCur
,
pgno_t
pgno
)
{
static
int
btreeCursorMoveToChild
(
SBtCursor
*
pBtCur
,
SPgno
pgno
)
{
SPgFile
*
pPgFile
;
// TODO
return
0
;
...
...
source/libs/tdb/src/db/tdbPgCache.c
浏览文件 @
708fef9a
...
...
@@ -24,20 +24,19 @@ struct SPCache {
SPgHdr
*
lru
;
int
nRecyclable
;
int
nHash
;
SPgHdr
*
pgHash
;
SPgHdr
*
*
pgHash
;
int
nFree
;
SPgHdr
*
pFree
;
};
struct
SPgHdr
{
void
*
pData
;
SPgid
pgid
;
SPgHdr
*
pFreeNext
;
};
#define PCACHE_PAGE_HASH(pgid) 0 // TODO
static
void
tdbPCacheLock
(
SPCache
*
pCache
);
static
void
tdbPCacheUnlock
(
SPCache
*
pCache
);
static
bool
tdbPCacheLocked
(
SPCache
*
pCache
);
static
void
tdbPCacheInitLock
(
SPCache
*
pCache
);
static
void
tdbPCacheClearLock
(
SPCache
*
pCache
);
static
void
tdbPCacheLock
(
SPCache
*
pCache
);
static
void
tdbPCacheUnlock
(
SPCache
*
pCache
);
static
bool
tdbPCacheLocked
(
SPCache
*
pCache
);
static
SPgHdr
*
tdbPCacheFetchImpl
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
bool
alcNewPage
);
int
tdbOpenPCache
(
int
pageSize
,
int
cacheSize
,
int
extraSize
,
SPCache
**
ppCache
)
{
SPCache
*
pCache
;
...
...
@@ -53,7 +52,7 @@ int tdbOpenPCache(int pageSize, int cacheSize, int extraSize, SPCache **ppCache)
pCache
->
cacheSize
=
cacheSize
;
pCache
->
extraSize
=
extraSize
;
pthread_mutex_init
(
&
pCache
->
mutex
,
NULL
);
tdbPCacheInitLock
(
pCache
);
for
(
int
i
=
0
;
i
<
cacheSize
;
i
++
)
{
pPtr
=
calloc
(
1
,
pageSize
+
extraSize
+
sizeof
(
SPgHdr
));
...
...
@@ -76,17 +75,24 @@ int tdbClosePCache(SPCache *pCache) {
return
0
;
}
void
*
tdbPCacheFetch
(
SPCache
*
pCache
,
SPgid
*
pPgid
)
{
SPgHdr
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
bool
alcNewPage
)
{
SPgHdr
*
pPage
;
tdbPCacheLock
(
pCache
);
// 1. search the hash table
pPage
=
tdbPCacheFetchImpl
(
pCache
,
pPgid
,
alcNewPage
);
tdbPCacheUnlock
(
pCache
);
return
NULL
;
return
pPage
;
}
void
tdbPCacheRelease
(
void
*
pHdr
)
{
void
tdbPCacheRelease
(
SPgHdr
*
pHdr
)
{
// TODO
}
static
void
tdbPCacheInitLock
(
SPCache
*
pCache
)
{
pthread_mutex_init
(
&
(
pCache
->
mutex
),
NULL
);
}
static
void
tdbPCacheClearLock
(
SPCache
*
pCache
)
{
pthread_mutex_destroy
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheLock
(
SPCache
*
pCache
)
{
pthread_mutex_lock
(
&
(
pCache
->
mutex
));
}
static
void
tdbPCacheUnlock
(
SPCache
*
pCache
)
{
pthread_mutex_unlock
(
&
(
pCache
->
mutex
));
}
...
...
@@ -95,4 +101,26 @@ static bool tdbPCacheLocked(SPCache *pCache) {
assert
(
0
);
// TODO
return
true
;
}
static
SPgHdr
*
tdbPCacheFetchImpl
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
bool
alcNewPage
)
{
SPgHdr
*
pPage
;
// 1. Search the hash table
pPage
=
pCache
->
pgHash
[
PCACHE_PAGE_HASH
(
pPgid
)
%
pCache
->
nHash
];
while
(
pPage
)
{
if
(
memcmp
(
pPgid
,
&
(
pPage
->
pgid
),
sizeof
(
*
pPgid
))
==
0
)
break
;
pPage
=
pPage
->
pHashNext
;
}
if
(
pPage
)
{
// TODO: pin the page and return the page
return
pPage
;
}
else
if
(
!
alcNewPage
)
{
return
pPage
;
}
// Try other methods
return
pPage
;
}
\ No newline at end of file
source/libs/tdb/src/db/tdbPgFile.c
浏览文件 @
708fef9a
...
...
@@ -17,8 +17,8 @@
typedef
struct
SPage1
{
char
magic
[
64
];
pgno_t
mdbRootPgno
;
// master DB root page number
pgno_t
freePgno
;
// free list page number
SPgno
mdbRootPgno
;
// master DB root page number
SPgno
freePgno
;
// free list page number
uint32_t
nFree
;
// number of free pages
}
SPage1
;
...
...
@@ -28,13 +28,13 @@ typedef struct SFreePage {
TDB_STATIC_ASSERT
(
sizeof
(
SPage1
)
<=
TDB_MIN_PGSIZE
,
"TDB Page1 definition too large"
);
static
int
pgFileRead
(
SPgFile
*
pPgFile
,
pgno_t
pgno
,
uint8_t
*
pData
);
static
int
pgFileRead
(
SPgFile
*
pPgFile
,
SPgno
pgno
,
uint8_t
*
pData
);
int
pgFileOpen
(
SPgFile
**
ppPgFile
,
const
char
*
fname
,
TENV
*
pEnv
)
{
SPgFile
*
pPgFile
;
SPgCache
*
pPgCache
;
size_t
fnameLen
;
pgno_t
fsize
;
SPgno
fsize
;
*
ppPgFile
=
NULL
;
...
...
@@ -67,7 +67,7 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
if
(
pPgFile
->
fsize
==
0
)
{
// A created file
pgno_t
pgno
;
SPgno
pgno
;
pgid_t
pgid
;
pgFileAllocatePage
(
pPgFile
,
&
pgno
);
...
...
@@ -106,7 +106,7 @@ int pgFileClose(SPgFile *pPgFile) {
return
0
;
}
SPage
*
pgFileFetch
(
SPgFile
*
pPgFile
,
pgno_t
pgno
)
{
SPage
*
pgFileFetch
(
SPgFile
*
pPgFile
,
SPgno
pgno
)
{
SPgCache
*
pPgCache
;
SPage
*
pPage
;
pgid_t
pgid
;
...
...
@@ -161,8 +161,8 @@ int pgFileWrite(SPage *pPage) {
return
0
;
}
int
pgFileAllocatePage
(
SPgFile
*
pPgFile
,
pgno_t
*
pPgno
)
{
pgno_t
pgno
;
int
pgFileAllocatePage
(
SPgFile
*
pPgFile
,
SPgno
*
pPgno
)
{
SPgno
pgno
;
SPage1
*
pPage1
;
SPgCache
*
pPgCache
;
pgid_t
pgid
;
...
...
@@ -189,7 +189,7 @@ int pgFileAllocatePage(SPgFile *pPgFile, pgno_t *pPgno) {
return
0
;
}
static
int
pgFileRead
(
SPgFile
*
pPgFile
,
pgno_t
pgno
,
uint8_t
*
pData
)
{
static
int
pgFileRead
(
SPgFile
*
pPgFile
,
SPgno
pgno
,
uint8_t
*
pData
)
{
pgsz_t
pgSize
;
ssize_t
rsize
;
uint8_t
*
pTData
;
...
...
source/libs/tdb/src/db/tdbUtil.c
浏览文件 @
708fef9a
...
...
@@ -51,7 +51,7 @@ int tdbCheckFileAccess(const char *pathname, int mode) {
return
access
(
pathname
,
flags
);
}
int
tdbGetFileSize
(
const
char
*
fname
,
pgsz_t
pgSize
,
pgno_t
*
pSize
)
{
int
tdbGetFileSize
(
const
char
*
fname
,
pgsz_t
pgSize
,
SPgno
*
pSize
)
{
struct
stat
st
;
int
ret
;
...
...
source/libs/tdb/src/inc/tdbBtree.h
浏览文件 @
708fef9a
...
...
@@ -34,7 +34,7 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey);
int
btreeCursorNext
(
SBtCursor
*
pBtCur
);
struct
SBTree
{
pgno_t
root
;
SPgno
root
;
};
#ifdef __cplusplus
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
708fef9a
...
...
@@ -27,8 +27,8 @@ extern "C" {
typedef
struct
SPgFile
SPgFile
;
//
pgno_t
typedef
int32_t
pgno_t
;
//
SPgno
typedef
int32_t
SPgno
;
#define TDB_IVLD_PGNO ((pgno_t)0)
// fileid
...
...
@@ -37,7 +37,7 @@ typedef int32_t pgno_t;
// pgid_t
typedef
struct
{
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
pgno_t
pgno
;
SPgno
pgno
;
}
pgid_t
,
SPgid
;
#define TDB_IVLD_PGID (pgid_t){0, TDB_IVLD_PGNO};
...
...
source/libs/tdb/src/inc/tdbPgCache.h
浏览文件 @
708fef9a
...
...
@@ -23,10 +23,18 @@ extern "C" {
typedef
struct
SPCache
SPCache
;
typedef
struct
SPgHdr
SPgHdr
;
int
tdbOpenPCache
(
int
pageSize
,
int
cacheSize
,
int
extraSize
,
SPCache
**
ppCache
);
int
tdbPCacheClose
(
SPCache
*
pCache
);
void
*
tdbPCacheFetch
(
SPCache
*
pCache
,
SPgid
*
pPgid
);
void
tdbPCacheRelease
(
void
*
pHdr
);
struct
SPgHdr
{
void
*
pData
;
void
*
pExtra
;
SPgid
pgid
;
SPgHdr
*
pFreeNext
;
SPgHdr
*
pHashNext
;
};
int
tdbOpenPCache
(
int
pageSize
,
int
cacheSize
,
int
extraSize
,
SPCache
**
ppCache
);
int
tdbPCacheClose
(
SPCache
*
pCache
);
SPgHdr
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
bool
alcNewPage
);
void
tdbPCacheRelease
(
SPgHdr
*
pHdr
);
#ifdef __cplusplus
}
...
...
source/libs/tdb/src/inc/tdbPgFile.h
浏览文件 @
708fef9a
...
...
@@ -24,7 +24,7 @@ typedef struct __attribute__((__packed__)) {
char
hdrInfo
[
16
];
// info string
pgsz_t
szPage
;
// page size of current file
int32_t
cno
;
// commit number counter
pgno_t
freePgno
;
// freelist page number
SPgno
freePgno
;
// freelist page number
uint8_t
resv
[
100
];
// reserved space
}
SPgFileHdr
;
...
...
@@ -36,8 +36,8 @@ struct SPgFile {
TENV
*
pEnv
;
// env containing this page file
char
*
fname
;
// backend file name
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
// file id
pgno_t
lsize
;
// page file logical size (for count)
pgno_t
fsize
;
// real file size on disk (for rollback)
SPgno
lsize
;
// page file logical size (for count)
SPgno
fsize
;
// real file size on disk (for rollback)
int
fd
;
SPgFileListNode
envHash
;
SPgFileListNode
envPgfList
;
...
...
@@ -46,11 +46,11 @@ struct SPgFile {
int
pgFileOpen
(
SPgFile
**
ppPgFile
,
const
char
*
fname
,
TENV
*
pEnv
);
int
pgFileClose
(
SPgFile
*
pPgFile
);
SPage
*
pgFileFetch
(
SPgFile
*
pPgFile
,
pgno_t
pgno
);
SPage
*
pgFileFetch
(
SPgFile
*
pPgFile
,
SPgno
pgno
);
int
pgFileRelease
(
SPage
*
pPage
);
int
pgFileWrite
(
SPage
*
pPage
);
int
pgFileAllocatePage
(
SPgFile
*
pPgFile
,
pgno_t
*
pPgno
);
int
pgFileAllocatePage
(
SPgFile
*
pPgFile
,
SPgno
*
pPgno
);
#ifdef __cplusplus
}
...
...
source/libs/tdb/src/inc/tdbUtil.h
浏览文件 @
708fef9a
...
...
@@ -35,7 +35,7 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);
#define TDB_W_OK 0x4
int
tdbCheckFileAccess
(
const
char
*
pathname
,
int
mode
);
int
tdbGetFileSize
(
const
char
*
fname
,
pgsz_t
pgSize
,
pgno_t
*
pSize
);
int
tdbGetFileSize
(
const
char
*
fname
,
pgsz_t
pgSize
,
SPgno
*
pSize
);
#ifdef __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录