Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f316cc12
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看板
未验证
提交
f316cc12
编写于
12月 20, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
12月 20, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19010 from taosdata/fix/TD-21344-main
fix(tdb): rollback in-memory pages
上级
27370baa
0b56b4af
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
63 addition
and
15 deletion
+63
-15
source/dnode/vnode/src/meta/metaSnapshot.c
source/dnode/vnode/src/meta/metaSnapshot.c
+3
-0
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+3
-0
source/libs/tdb/src/db/tdbPCache.c
source/libs/tdb/src/db/tdbPCache.c
+27
-1
source/libs/tdb/src/db/tdbPage.c
source/libs/tdb/src/db/tdbPage.c
+3
-0
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+16
-5
source/libs/tdb/src/db/tdbTable.c
source/libs/tdb/src/db/tdbTable.c
+8
-8
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+3
-1
未找到文件。
source/dnode/vnode/src/meta/metaSnapshot.c
浏览文件 @
f316cc12
...
@@ -161,7 +161,10 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback) {
...
@@ -161,7 +161,10 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback) {
SMetaSnapWriter
*
pWriter
=
*
ppWriter
;
SMetaSnapWriter
*
pWriter
=
*
ppWriter
;
if
(
rollback
)
{
if
(
rollback
)
{
metaInfo
(
"vgId:%d, meta snapshot writer close and rollback start "
,
TD_VID
(
pWriter
->
pMeta
->
pVnode
));
code
=
metaAbort
(
pWriter
->
pMeta
);
code
=
metaAbort
(
pWriter
->
pMeta
);
metaInfo
(
"vgId:%d, meta snapshot writer close and rollback finished, code:0x%x"
,
TD_VID
(
pWriter
->
pMeta
->
pVnode
),
code
);
if
(
code
)
goto
_err
;
if
(
code
)
goto
_err
;
}
else
{
}
else
{
code
=
metaCommit
(
pWriter
->
pMeta
,
pWriter
->
pMeta
->
txn
);
code
=
metaCommit
(
pWriter
->
pMeta
,
pWriter
->
pMeta
->
txn
);
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
f316cc12
...
@@ -710,6 +710,9 @@ int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
...
@@ -710,6 +710,9 @@ int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
if
(
metaBuildCtimeIdxKey
(
&
ctimeKey
,
pME
)
<
0
)
{
if
(
metaBuildCtimeIdxKey
(
&
ctimeKey
,
pME
)
<
0
)
{
return
0
;
return
0
;
}
}
metaDebug
(
"vgId:%d, start to save ctime:%"
PRId64
" uid:%"
PRId64
" ct:%"
PRId64
,
TD_VID
(
pMeta
->
pVnode
),
pME
->
version
,
pME
->
uid
,
ctimeKey
.
ctime
);
return
tdbTbInsert
(
pMeta
->
pCtimeIdx
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
NULL
,
0
,
pMeta
->
txn
);
return
tdbTbInsert
(
pMeta
->
pCtimeIdx
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
NULL
,
0
,
pMeta
->
txn
);
}
}
...
...
source/libs/tdb/src/db/tdbPCache.c
浏览文件 @
f316cc12
...
@@ -192,6 +192,28 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) {
...
@@ -192,6 +192,28 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) {
return
pPage
;
return
pPage
;
}
}
void
tdbPCacheMarkFree
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
tdbPCacheLock
(
pCache
);
tdbPCacheRemovePageFromHash
(
pCache
,
pPage
);
pPage
->
isFree
=
1
;
tdbPCacheUnlock
(
pCache
);
}
static
void
tdbPCacheFreePage
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
if
(
pPage
->
id
<
pCache
->
nPages
)
{
pPage
->
pFreeNext
=
pCache
->
pFree
;
pCache
->
pFree
=
pPage
;
pPage
->
isFree
=
0
;
++
pCache
->
nFree
;
tdbTrace
(
"pcache/free page %p/%d/%d"
,
pPage
,
TDB_PAGE_PGNO
(
pPage
),
pPage
->
id
);
}
else
{
tdbTrace
(
"pcache destroy page: %p/%d/%d"
,
pPage
,
TDB_PAGE_PGNO
(
pPage
),
pPage
->
id
);
tdbPCacheRemovePageFromHash
(
pCache
,
pPage
);
tdbPageDestroy
(
pPage
,
tdbDefaultFree
,
NULL
);
}
}
void
tdbPCacheRelease
(
SPCache
*
pCache
,
SPage
*
pPage
,
TXN
*
pTxn
)
{
void
tdbPCacheRelease
(
SPCache
*
pCache
,
SPage
*
pPage
,
TXN
*
pTxn
)
{
i32
nRef
;
i32
nRef
;
...
@@ -209,7 +231,11 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) {
...
@@ -209,7 +231,11 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) {
// nRef = tdbGetPageRef(pPage);
// nRef = tdbGetPageRef(pPage);
// if (nRef == 0) {
// if (nRef == 0) {
if
(
pPage
->
isLocal
)
{
if
(
pPage
->
isLocal
)
{
tdbPCacheUnpinPage
(
pCache
,
pPage
);
if
(
!
pPage
->
isFree
)
{
tdbPCacheUnpinPage
(
pCache
,
pPage
);
}
else
{
tdbPCacheFreePage
(
pCache
,
pPage
);
}
}
else
{
}
else
{
if
(
TDB_TXN_IS_WRITE
(
pTxn
))
{
if
(
TDB_TXN_IS_WRITE
(
pTxn
))
{
// remove from hash
// remove from hash
...
...
source/libs/tdb/src/db/tdbPage.c
浏览文件 @
f316cc12
...
@@ -111,6 +111,9 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell
...
@@ -111,6 +111,9 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell
void
tdbPageInit
(
SPage
*
pPage
,
u8
szAmHdr
,
int
(
*
xCellSize
)(
const
SPage
*
,
SCell
*
,
int
,
TXN
*
,
SBTree
*
pBt
))
{
void
tdbPageInit
(
SPage
*
pPage
,
u8
szAmHdr
,
int
(
*
xCellSize
)(
const
SPage
*
,
SCell
*
,
int
,
TXN
*
,
SBTree
*
pBt
))
{
tdbTrace
(
"page/init: %p %"
PRIu8
" %p"
,
pPage
,
szAmHdr
,
xCellSize
);
tdbTrace
(
"page/init: %p %"
PRIu8
" %p"
,
pPage
,
szAmHdr
,
xCellSize
);
pPage
->
pPageHdr
=
pPage
->
pData
+
szAmHdr
;
pPage
->
pPageHdr
=
pPage
->
pData
+
szAmHdr
;
if
(
TDB_PAGE_NCELLS
(
pPage
)
==
0
)
{
return
tdbPageZero
(
pPage
,
szAmHdr
,
xCellSize
);
}
pPage
->
pCellIdx
=
pPage
->
pPageHdr
+
TDB_PAGE_HDR_SIZE
(
pPage
);
pPage
->
pCellIdx
=
pPage
->
pPageHdr
+
TDB_PAGE_HDR_SIZE
(
pPage
);
pPage
->
pFreeStart
=
pPage
->
pCellIdx
+
TDB_PAGE_OFFSET_SIZE
(
pPage
)
*
TDB_PAGE_NCELLS
(
pPage
);
pPage
->
pFreeStart
=
pPage
->
pCellIdx
+
TDB_PAGE_OFFSET_SIZE
(
pPage
)
*
TDB_PAGE_NCELLS
(
pPage
);
pPage
->
pFreeEnd
=
pPage
->
pData
+
TDB_PAGE_CCELLS
(
pPage
);
pPage
->
pFreeEnd
=
pPage
->
pData
+
TDB_PAGE_CCELLS
(
pPage
);
...
...
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
f316cc12
...
@@ -466,11 +466,19 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
...
@@ -466,11 +466,19 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
return
-
1
;
return
-
1
;
}
}
if
(
tdbOsLSeek
(
jfd
,
0L
,
SEEK_SET
)
<
0
)
{
tdbError
(
"failed to lseek jfd due to %s. file:%s, offset:0"
,
strerror
(
errno
),
pPager
->
dbFileName
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
u8
*
pageBuf
=
tdbOsCalloc
(
1
,
pPager
->
pageSize
);
u8
*
pageBuf
=
tdbOsCalloc
(
1
,
pPager
->
pageSize
);
if
(
pageBuf
==
NULL
)
{
if
(
pageBuf
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
tdbDebug
(
"tdb/abort: pager:%p,"
,
pPager
);
for
(
int
pgIndex
=
0
;
pgIndex
<
journalSize
;
++
pgIndex
)
{
for
(
int
pgIndex
=
0
;
pgIndex
<
journalSize
;
++
pgIndex
)
{
// read pgno & the page from journal
// read pgno & the page from journal
SPgno
pgno
;
SPgno
pgno
;
...
@@ -481,6 +489,8 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
...
@@ -481,6 +489,8 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
return
-
1
;
return
-
1
;
}
}
tdbTrace
(
"tdb/abort: pgno:%d,"
,
pgno
);
ret
=
tdbOsRead
(
jfd
,
pageBuf
,
pPager
->
pageSize
);
ret
=
tdbOsRead
(
jfd
,
pageBuf
,
pPager
->
pageSize
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
tdbOsFree
(
pageBuf
);
tdbOsFree
(
pageBuf
);
...
@@ -524,6 +534,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
...
@@ -524,6 +534,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
tRBTreeDrop
(
&
pPager
->
rbt
,
(
SRBTreeNode
*
)
pPage
);
tRBTreeDrop
(
&
pPager
->
rbt
,
(
SRBTreeNode
*
)
pPage
);
hashset_remove
(
pTxn
->
jPageSet
,
(
void
*
)((
long
)
TDB_PAGE_PGNO
(
pPage
)));
hashset_remove
(
pTxn
->
jPageSet
,
(
void
*
)((
long
)
TDB_PAGE_PGNO
(
pPage
)));
tdbPCacheMarkFree
(
pPager
->
pCache
,
pPage
);
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
,
pTxn
);
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
,
pTxn
);
}
}
...
@@ -577,12 +588,12 @@ int tdbPagerFlushPage(SPager *pPager, TXN *pTxn) {
...
@@ -577,12 +588,12 @@ int tdbPagerFlushPage(SPager *pPager, TXN *pTxn) {
return
-
1
;
return
-
1
;
}
}
tdbTrace
(
"tdb/flush:%p,
%d/%d/%d"
,
pPager
,
pPager
->
dbOrigSize
,
pPager
->
dbFileSize
,
maxPgno
);
tdbTrace
(
"tdb/flush:%p,
pgno:%d, %d/%d/%d"
,
pPager
,
pgno
,
pPager
->
dbOrigSize
,
pPager
->
dbFileSize
,
maxPgno
);
pPager
->
dbOrigSize
=
maxPgno
;
pPager
->
dbOrigSize
=
maxPgno
;
pPage
->
isDirty
=
0
;
pPage
->
isDirty
=
0
;
tdbTrace
(
"pager/flush drop page: %p
%d
from dirty tree: %p"
,
pPage
,
TDB_PAGE_PGNO
(
pPage
),
&
pPager
->
rbt
);
tdbTrace
(
"pager/flush drop page: %p
, pgno:%d,
from dirty tree: %p"
,
pPage
,
TDB_PAGE_PGNO
(
pPage
),
&
pPager
->
rbt
);
tRBTreeDrop
(
&
pPager
->
rbt
,
(
SRBTreeNode
*
)
pPage
);
tRBTreeDrop
(
&
pPager
->
rbt
,
(
SRBTreeNode
*
)
pPage
);
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
,
pTxn
);
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
,
pTxn
);
...
@@ -829,7 +840,7 @@ static int tdbPagerPWritePageToDB(SPager *pPager, SPage *pPage) {
...
@@ -829,7 +840,7 @@ static int tdbPagerPWritePageToDB(SPager *pPager, SPage *pPage) {
return
0
;
return
0
;
}
}
static
int
tdbPagerRestore
(
SPager
*
pPager
,
SBTree
*
pBt
,
const
char
*
jFileName
)
{
static
int
tdbPagerRestore
(
SPager
*
pPager
,
const
char
*
jFileName
)
{
int
ret
=
0
;
int
ret
=
0
;
SPgno
journalSize
=
0
;
SPgno
journalSize
=
0
;
u8
*
pageBuf
=
NULL
;
u8
*
pageBuf
=
NULL
;
...
@@ -907,7 +918,7 @@ static int tdbPagerRestore(SPager *pPager, SBTree *pBt, const char *jFileName) {
...
@@ -907,7 +918,7 @@ static int tdbPagerRestore(SPager *pPager, SBTree *pBt, const char *jFileName) {
return
0
;
return
0
;
}
}
int
tdbPagerRestoreJournals
(
SPager
*
pPager
,
SBTree
*
pBt
)
{
int
tdbPagerRestoreJournals
(
SPager
*
pPager
)
{
tdbDirEntryPtr
pDirEntry
;
tdbDirEntryPtr
pDirEntry
;
tdbDirPtr
pDir
=
taosOpenDir
(
pPager
->
pEnv
->
dbName
);
tdbDirPtr
pDir
=
taosOpenDir
(
pPager
->
pEnv
->
dbName
);
if
(
pDir
==
NULL
)
{
if
(
pDir
==
NULL
)
{
...
@@ -918,7 +929,7 @@ int tdbPagerRestoreJournals(SPager *pPager, SBTree *pBt) {
...
@@ -918,7 +929,7 @@ int tdbPagerRestoreJournals(SPager *pPager, SBTree *pBt) {
while
((
pDirEntry
=
tdbReadDir
(
pDir
))
!=
NULL
)
{
while
((
pDirEntry
=
tdbReadDir
(
pDir
))
!=
NULL
)
{
char
*
name
=
tdbDirEntryBaseName
(
tdbGetDirEntryName
(
pDirEntry
));
char
*
name
=
tdbDirEntryBaseName
(
tdbGetDirEntryName
(
pDirEntry
));
if
(
strncmp
(
TDB_MAINDB_NAME
"-journal"
,
name
,
16
)
==
0
)
{
if
(
strncmp
(
TDB_MAINDB_NAME
"-journal"
,
name
,
16
)
==
0
)
{
if
(
tdbPagerRestore
(
pPager
,
pBt
,
name
)
<
0
)
{
if
(
tdbPagerRestore
(
pPager
,
name
)
<
0
)
{
tdbCloseDir
(
&
pDir
);
tdbCloseDir
(
&
pDir
);
tdbError
(
"failed to restore file due to %s. jFileName:%s"
,
strerror
(
errno
),
name
);
tdbError
(
"failed to restore file due to %s. jFileName:%s"
,
strerror
(
errno
),
name
);
...
...
source/libs/tdb/src/db/tdbTable.c
浏览文件 @
f316cc12
...
@@ -107,23 +107,23 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
...
@@ -107,23 +107,23 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
ASSERT
(
pPager
!=
NULL
);
ASSERT
(
pPager
!=
NULL
);
// pTb->pBt
ret
=
tdbBtreeOpen
(
keyLen
,
valLen
,
pPager
,
tbname
,
pgno
,
keyCmprFn
,
pEnv
,
&
(
pTb
->
pBt
));
if
(
ret
<
0
)
{
tdbOsFree
(
pTb
);
return
-
1
;
}
if
(
rollback
)
{
if
(
rollback
)
{
tdbPagerRollback
(
pPager
);
tdbPagerRollback
(
pPager
);
}
else
{
}
else
{
ret
=
tdbPagerRestoreJournals
(
pPager
,
pTb
->
pBt
);
ret
=
tdbPagerRestoreJournals
(
pPager
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
tdbOsFree
(
pTb
);
tdbOsFree
(
pTb
);
return
-
1
;
return
-
1
;
}
}
}
}
// pTb->pBt
ret
=
tdbBtreeOpen
(
keyLen
,
valLen
,
pPager
,
tbname
,
pgno
,
keyCmprFn
,
pEnv
,
&
(
pTb
->
pBt
));
if
(
ret
<
0
)
{
tdbOsFree
(
pTb
);
return
-
1
;
}
*
ppTb
=
pTb
;
*
ppTb
=
pTb
;
return
0
;
return
0
;
}
}
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
f316cc12
...
@@ -197,7 +197,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initP
...
@@ -197,7 +197,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initP
TXN
*
pTxn
);
TXN
*
pTxn
);
void
tdbPagerReturnPage
(
SPager
*
pPager
,
SPage
*
pPage
,
TXN
*
pTxn
);
void
tdbPagerReturnPage
(
SPager
*
pPager
,
SPage
*
pPage
,
TXN
*
pTxn
);
int
tdbPagerAllocPage
(
SPager
*
pPager
,
SPgno
*
ppgno
);
int
tdbPagerAllocPage
(
SPager
*
pPager
,
SPgno
*
ppgno
);
int
tdbPagerRestoreJournals
(
SPager
*
pPager
,
SBTree
*
pBt
);
int
tdbPagerRestoreJournals
(
SPager
*
pPager
);
int
tdbPagerRollback
(
SPager
*
pPager
);
int
tdbPagerRollback
(
SPager
*
pPager
);
// tdbPCache.c ====================================
// tdbPCache.c ====================================
...
@@ -205,6 +205,7 @@ int tdbPagerRollback(SPager *pPager);
...
@@ -205,6 +205,7 @@ int tdbPagerRollback(SPager *pPager);
u8 isAnchor; \
u8 isAnchor; \
u8 isLocal; \
u8 isLocal; \
u8 isDirty; \
u8 isDirty; \
u8 isFree; \
volatile i32 nRef; \
volatile i32 nRef; \
i32 id; \
i32 id; \
SPage *pFreeNext; \
SPage *pFreeNext; \
...
@@ -222,6 +223,7 @@ int tdbPCacheClose(SPCache *pCache);
...
@@ -222,6 +223,7 @@ int tdbPCacheClose(SPCache *pCache);
int
tdbPCacheAlter
(
SPCache
*
pCache
,
int32_t
nPage
);
int
tdbPCacheAlter
(
SPCache
*
pCache
,
int32_t
nPage
);
SPage
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
TXN
*
pTxn
);
SPage
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
TXN
*
pTxn
);
void
tdbPCacheRelease
(
SPCache
*
pCache
,
SPage
*
pPage
,
TXN
*
pTxn
);
void
tdbPCacheRelease
(
SPCache
*
pCache
,
SPage
*
pPage
,
TXN
*
pTxn
);
void
tdbPCacheMarkFree
(
SPCache
*
pCache
,
SPage
*
pPage
);
int
tdbPCacheGetPageSize
(
SPCache
*
pCache
);
int
tdbPCacheGetPageSize
(
SPCache
*
pCache
);
// tdbPage.c ====================================
// tdbPage.c ====================================
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录