Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c1ffbb5c
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看板
提交
c1ffbb5c
编写于
1月 23, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor:do some internal refactor.
上级
21d57a36
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
34 deletion
+43
-34
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+0
-4
source/libs/function/src/tpercentile.c
source/libs/function/src/tpercentile.c
+7
-6
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+36
-24
未找到文件。
source/libs/function/src/builtinsimpl.c
浏览文件 @
c1ffbb5c
...
...
@@ -3061,14 +3061,12 @@ static int32_t doSaveTupleData(SSerializeDataHandle* pHandle, const void* pBuf,
if
(
pHandle
->
currentPage
==
-
1
)
{
pPage
=
getNewBufPage
(
pHandle
->
pBuf
,
&
pHandle
->
currentPage
);
if
(
pPage
==
NULL
)
{
terrno
=
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
pPage
->
num
=
sizeof
(
SFilePage
);
}
else
{
pPage
=
getBufPage
(
pHandle
->
pBuf
,
pHandle
->
currentPage
);
if
(
pPage
==
NULL
)
{
terrno
=
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
if
(
pPage
->
num
+
length
>
getBufPageSize
(
pHandle
->
pBuf
))
{
...
...
@@ -3076,7 +3074,6 @@ static int32_t doSaveTupleData(SSerializeDataHandle* pHandle, const void* pBuf,
releaseBufPage
(
pHandle
->
pBuf
,
pPage
);
pPage
=
getNewBufPage
(
pHandle
->
pBuf
,
&
pHandle
->
currentPage
);
if
(
pPage
==
NULL
)
{
terrno
=
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
pPage
->
num
=
sizeof
(
SFilePage
);
...
...
@@ -3123,7 +3120,6 @@ static int32_t doUpdateTupleData(SSerializeDataHandle* pHandle, const void* pBuf
if
(
pHandle
->
pBuf
!=
NULL
)
{
SFilePage
*
pPage
=
getBufPage
(
pHandle
->
pBuf
,
pPos
->
pageId
);
if
(
pPage
==
NULL
)
{
terrno
=
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
memcpy
(
pPage
->
data
+
pPos
->
offset
,
pBuf
,
length
);
...
...
source/libs/function/src/tpercentile.c
浏览文件 @
c1ffbb5c
...
...
@@ -43,8 +43,8 @@ static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx)
if
(
pg
==
NULL
)
{
return
NULL
;
}
memcpy
(
buffer
->
data
+
offset
,
pg
->
data
,
(
size_t
)(
pg
->
num
*
pMemBucket
->
bytes
));
memcpy
(
buffer
->
data
+
offset
,
pg
->
data
,
(
size_t
)(
pg
->
num
*
pMemBucket
->
bytes
));
offset
+=
(
int32_t
)(
pg
->
num
*
pMemBucket
->
bytes
);
}
...
...
@@ -109,7 +109,7 @@ int32_t findOnlyResult(tMemBucket *pMemBucket, double *result) {
int32_t
*
pageId
=
taosArrayGet
(
list
,
0
);
SFilePage
*
pPage
=
getBufPage
(
pMemBucket
->
pBuffer
,
*
pageId
);
if
(
pPage
==
NULL
)
{
return
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
ASSERT
(
pPage
->
num
==
1
);
...
...
@@ -276,7 +276,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
return
NULL
;
}
int32_t
ret
=
createDiskbasedBuf
(
&
pBucket
->
pBuffer
,
pBucket
->
bufPageSize
,
pBucket
->
bufPageSize
*
512
,
"1"
,
tsTempDir
);
int32_t
ret
=
createDiskbasedBuf
(
&
pBucket
->
pBuffer
,
pBucket
->
bufPageSize
,
pBucket
->
bufPageSize
*
1024
,
"1"
,
tsTempDir
);
if
(
ret
!=
0
)
{
tMemBucketDestroy
(
pBucket
);
return
NULL
;
...
...
@@ -388,7 +388,7 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
pSlot
->
info
.
data
=
getNewBufPage
(
pBucket
->
pBuffer
,
&
pageId
);
if
(
pSlot
->
info
.
data
==
NULL
)
{
return
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
pSlot
->
info
.
pageId
=
pageId
;
taosArrayPush
(
pPageIdList
,
&
pageId
);
...
...
@@ -482,8 +482,9 @@ int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction
// data in buffer and file are merged together to be processed.
SFilePage
*
buffer
=
loadDataFromFilePage
(
pMemBucket
,
i
);
if
(
buffer
==
NULL
)
{
return
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
int32_t
currentIdx
=
count
-
num
;
char
*
thisVal
=
buffer
->
data
+
pMemBucket
->
bytes
*
currentIdx
;
...
...
@@ -520,7 +521,7 @@ int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction
int32_t
*
pageId
=
taosArrayGet
(
list
,
f
);
SFilePage
*
pg
=
getBufPage
(
pMemBucket
->
pBuffer
,
*
pageId
);
if
(
pg
==
NULL
)
{
return
TSDB_CODE_NO_AVAIL_DISK
;
return
terrno
;
}
int32_t
code
=
tMemBucketPut
(
pMemBucket
,
pg
->
data
,
(
int32_t
)
pg
->
num
);
...
...
source/util/src/tpagedbuf.c
浏览文件 @
c1ffbb5c
...
...
@@ -5,7 +5,7 @@
#include "thash.h"
#include "tlog.h"
#define GET_
DATA_PAYLOAD
(_p) ((char*)(_p)->pData + POINTER_BYTES)
#define GET_
PAYLOAD_DATA
(_p) ((char*)(_p)->pData + POINTER_BYTES)
#define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages)
typedef
struct
SPageDiskInfo
{
...
...
@@ -89,7 +89,7 @@ static char* doDecompressData(void* data, int32_t srcSize, int32_t* dst, SDiskba
return
data
;
}
static
uint64_t
allocatePositionInFile
(
SDiskbasedBuf
*
pBuf
,
size_t
size
)
{
static
uint64_t
allocate
New
PositionInFile
(
SDiskbasedBuf
*
pBuf
,
size_t
size
)
{
if
(
pBuf
->
pFree
==
NULL
)
{
return
pBuf
->
nextPos
;
}
else
{
...
...
@@ -114,8 +114,6 @@ static uint64_t allocatePositionInFile(SDiskbasedBuf* pBuf, size_t size) {
static
void
setPageNotInBuf
(
SPageInfo
*
pPageInfo
)
{
pPageInfo
->
pData
=
NULL
;
}
static
FORCE_INLINE
size_t
getAllocPageSize
(
int32_t
pageSize
)
{
return
pageSize
+
POINTER_BYTES
+
sizeof
(
SFilePage
);
}
/**
* +--------------------------+-------------------+--------------+
* | PTR to SPageInfo (8bytes)| Payload (PageSize)| 2 Extra Bytes|
...
...
@@ -124,13 +122,16 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize
* @param pg
* @return
*/
static
char
*
doFlushPageToDisk
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pg
)
{
static
FORCE_INLINE
size_t
getAllocPageSize
(
int32_t
pageSize
)
{
return
pageSize
+
POINTER_BYTES
+
sizeof
(
SFilePage
);
}
static
char
*
doFlushBufPage
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pg
)
{
ASSERT
(
!
pg
->
used
&&
pg
->
pData
!=
NULL
);
int32_t
size
=
pBuf
->
pageSize
;
char
*
t
=
NULL
;
if
(
pg
->
offset
==
-
1
||
pg
->
dirty
)
{
void
*
payload
=
GET_
DATA_PAYLOAD
(
pg
);
void
*
payload
=
GET_
PAYLOAD_DATA
(
pg
);
t
=
doCompressData
(
payload
,
pBuf
->
pageSize
,
&
size
,
pBuf
);
ASSERTS
(
size
>=
0
,
"size is negative"
);
}
...
...
@@ -140,7 +141,7 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
if
(
pg
->
offset
==
-
1
)
{
ASSERTS
(
pg
->
dirty
==
true
,
"pg->dirty is false"
);
pg
->
offset
=
allocatePositionInFile
(
pBuf
,
size
);
pg
->
offset
=
allocate
New
PositionInFile
(
pBuf
,
size
);
pBuf
->
nextPos
+=
size
;
int32_t
ret
=
taosLSeekFile
(
pBuf
->
pFile
,
pg
->
offset
,
SEEK_SET
);
...
...
@@ -169,7 +170,7 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
taosArrayPush
(
pBuf
->
pFree
,
&
dinfo
);
// 2. allocate new position, and update the info
pg
->
offset
=
allocatePositionInFile
(
pBuf
,
size
);
pg
->
offset
=
allocate
New
PositionInFile
(
pBuf
,
size
);
pBuf
->
nextPos
+=
size
;
}
...
...
@@ -208,9 +209,8 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
return
pDataBuf
;
}
static
char
*
flush
PageToDisk
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pg
)
{
static
char
*
flush
BufPage
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pg
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
ASSERT
(((
int64_t
)
pBuf
->
numOfPages
*
pBuf
->
pageSize
)
==
pBuf
->
totalBufSize
&&
pBuf
->
numOfPages
>=
pBuf
->
inMemPages
);
if
(
pBuf
->
pFile
==
NULL
)
{
if
((
ret
=
createDiskFile
(
pBuf
))
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -219,7 +219,7 @@ static char* flushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
}
}
char
*
p
=
doFlush
PageToDisk
(
pBuf
,
pg
);
char
*
p
=
doFlush
BufPage
(
pBuf
,
pg
);
setPageNotInBuf
(
pg
);
pg
->
dirty
=
false
;
return
p
;
...
...
@@ -233,7 +233,7 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
return
ret
;
}
void
*
pPage
=
(
void
*
)
GET_
DATA_PAYLOAD
(
pg
);
void
*
pPage
=
(
void
*
)
GET_
PAYLOAD_DATA
(
pg
);
ret
=
(
int32_t
)
taosReadFile
(
pBuf
->
pFile
,
pPage
,
pg
->
length
);
if
(
ret
!=
pg
->
length
)
{
ret
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -252,6 +252,10 @@ static SPageInfo* registerPage(SDiskbasedBuf* pBuf, int32_t pageId) {
pBuf
->
numOfPages
+=
1
;
SPageInfo
*
ppi
=
taosMemoryMalloc
(
sizeof
(
SPageInfo
));
if
(
ppi
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
ppi
->
pageId
=
pageId
;
ppi
->
pData
=
NULL
;
...
...
@@ -274,17 +278,14 @@ static SListNode* getEldestUnrefedPage(SDiskbasedBuf* pBuf) {
ASSERT
(
pageInfo
->
pageId
>=
0
&&
pageInfo
->
pn
==
pn
);
if
(
!
pageInfo
->
used
)
{
// printf("%d is chosen\n", pageInfo->pageId);
break
;
}
else
{
// printf("page %d is used, dirty:%d\n", pageInfo->pageId, pageInfo->dirty);
}
}
return
pn
;
}
static
char
*
ev
acOneData
Page
(
SDiskbasedBuf
*
pBuf
)
{
static
char
*
ev
ictBuf
Page
(
SDiskbasedBuf
*
pBuf
)
{
SListNode
*
pn
=
getEldestUnrefedPage
(
pBuf
);
if
(
pn
==
NULL
)
{
// no available buffer pages now, return.
return
NULL
;
...
...
@@ -299,7 +300,7 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) {
d
->
pn
=
NULL
;
taosMemoryFreeClear
(
pn
);
return
flush
PageToDisk
(
pBuf
,
d
);
return
flush
BufPage
(
pBuf
,
d
);
}
static
void
lruListPushFront
(
SList
*
pList
,
SPageInfo
*
pi
)
{
...
...
@@ -374,8 +375,9 @@ int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMem
static
char
*
doExtractPage
(
SDiskbasedBuf
*
pBuf
)
{
char
*
availablePage
=
NULL
;
if
(
NO_IN_MEM_AVAILABLE_PAGES
(
pBuf
))
{
availablePage
=
ev
acOneData
Page
(
pBuf
);
availablePage
=
ev
ictBuf
Page
(
pBuf
);
if
(
availablePage
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
uWarn
(
"no available buf pages, current:%d, max:%d"
,
listNEles
(
pBuf
->
lruList
),
pBuf
->
inMemPages
)
}
}
else
{
...
...
@@ -409,6 +411,9 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
// register page id info
pi
=
registerPage
(
pBuf
,
*
pageId
);
if
(
pi
==
NULL
)
{
return
NULL
;
}
// add to hash map
taosHashPut
(
pBuf
->
all
,
pageId
,
sizeof
(
int32_t
),
&
pi
,
POINTER_BYTES
);
...
...
@@ -423,11 +428,15 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_getNewBufPage , pi->pData:%p, pageId:%d, offset:%"
PRId64
,
pi
->
pData
,
pi
->
pageId
,
pi
->
offset
);
#endif
return
(
void
*
)(
GET_DATA_PAYLOAD
(
pi
));
return
(
void
*
)(
GET_PAYLOAD_DATA
(
pi
));
}
void
*
getBufPage
(
SDiskbasedBuf
*
pBuf
,
int32_t
id
)
{
ASSERT
(
pBuf
!=
NULL
&&
id
>=
0
);
if
(
id
<
0
)
{
return
NULL
;
}
pBuf
->
statis
.
getPages
+=
1
;
SPageInfo
**
pi
=
taosHashGet
(
pBuf
->
all
,
&
id
,
sizeof
(
int32_t
));
...
...
@@ -437,7 +446,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
// no need to update the LRU list if only one page exists
if
(
pBuf
->
numOfPages
==
1
)
{
(
*
pi
)
->
used
=
true
;
return
(
void
*
)(
GET_
DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_
PAYLOAD_DATA
(
*
pi
));
}
SPageInfo
**
pInfo
=
(
SPageInfo
**
)((
*
pi
)
->
pn
->
data
);
...
...
@@ -445,10 +454,11 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
lruListMoveToFront
(
pBuf
->
lruList
,
(
*
pi
));
(
*
pi
)
->
used
=
true
;
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_getBufPage1 pageId:%d, offset:%"
PRId64
,
(
*
pi
)
->
pageId
,
(
*
pi
)
->
offset
);
#endif
return
(
void
*
)(
GET_
DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_
PAYLOAD_DATA
(
*
pi
));
}
else
{
// not in memory
ASSERT
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(((
*
pi
)
->
length
>=
0
&&
(
*
pi
)
->
offset
>=
0
)
||
((
*
pi
)
->
length
==
-
1
&&
(
*
pi
)
->
offset
==
-
1
)));
...
...
@@ -475,14 +485,15 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_getBufPage2 pageId:%d, offset:%"
PRId64
,
(
*
pi
)
->
pageId
,
(
*
pi
)
->
offset
);
#endif
return
(
void
*
)(
GET_
DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_
PAYLOAD_DATA
(
*
pi
));
}
}
void
releaseBufPage
(
SDiskbasedBuf
*
pBuf
,
void
*
page
)
{
if
(
ASSERTS
(
pBuf
!=
NULL
&&
page
!=
NULL
,
"pBuf or page is NULL"
)
)
{
if
(
page
==
NULL
)
{
return
;
}
SPageInfo
*
ppi
=
getPageInfoFromPayload
(
page
);
releaseBufPageInfo
(
pBuf
,
ppi
);
}
...
...
@@ -491,6 +502,7 @@ void releaseBufPageInfo(SDiskbasedBuf* pBuf, SPageInfo* pi) {
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_releaseBufPageInfo pageId:%d, used:%d, offset:%"
PRId64
,
pi
->
pageId
,
pi
->
used
,
pi
->
offset
);
#endif
if
(
ASSERTS
(
pi
->
pData
!=
NULL
,
"pi->pData is NULL"
))
{
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录