Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9f6f7449
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
9f6f7449
编写于
2月 21, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make pcache compilable
上级
2434e711
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
57 deletion
+51
-57
source/libs/tdb/src/sqlite/pcache1.c
source/libs/tdb/src/sqlite/pcache1.c
+51
-57
未找到文件。
source/libs/tdb/src/sqlite/pcache1.c
浏览文件 @
9f6f7449
...
...
@@ -290,7 +290,7 @@ static int pcache1InitBulk(PCache1 *pCache) {
if
(
zBulk
)
{
int
nBulk
=
szBulk
/
pCache
->
szAlloc
;
do
{
PgHdr1
*
pX
=
(
PgHdr1
*
)
&
zBulk
[
pCache
->
szPage
]
;
PgHdr1
*
pX
=
(
PgHdr1
*
)
(
&
zBulk
[
pCache
->
szPage
])
;
pX
->
page
.
pBuf
=
zBulk
;
pX
->
page
.
pExtra
=
&
pX
[
1
];
pX
->
isBulkLocal
=
1
;
...
...
@@ -315,35 +315,35 @@ static int pcache1InitBulk(PCache1 *pCache) {
*/
static
void
*
pcache1Alloc
(
int
nByte
)
{
void
*
p
=
0
;
assert
(
sqlite3_mutex_notheld
(
pcache1
.
grp
.
mutex
));
//
assert(sqlite3_mutex_notheld(pcache1.grp.mutex));
if
(
nByte
<=
pcache1
.
szSlot
)
{
sqlite3_mutex_enter
(
pcache1
.
mutex
);
pthread_mutex_lock
(
&
(
pcache1
.
mutex
)
);
p
=
(
PgHdr1
*
)
pcache1
.
pFree
;
if
(
p
)
{
pcache1
.
pFree
=
pcache1
.
pFree
->
pNext
;
pcache1
.
nFreeSlot
--
;
pcache1
.
bUnderPressure
=
pcache1
.
nFreeSlot
<
pcache1
.
nReserve
;
assert
(
pcache1
.
nFreeSlot
>=
0
);
sqlite3StatusHighwater
(
SQLITE_STATUS_PAGECACHE_SIZE
,
nByte
);
sqlite3StatusUp
(
SQLITE_STATUS_PAGECACHE_USED
,
1
);
//
sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
//
sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1);
}
sqlite3_mutex_leave
(
pcache1
.
mutex
);
pthread_mutex_unlock
(
&
pcache1
.
mutex
);
}
if
(
p
==
0
)
{
/* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
** it from sqlite3Malloc instead.
*/
p
=
sqlite3M
alloc
(
nByte
);
p
=
m
alloc
(
nByte
);
#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
if
(
p
)
{
int
sz
=
sqlite3MallocSize
(
p
)
;
sqlite3_mutex_enter
(
pcache1
.
mutex
);
sqlite3StatusHighwater
(
SQLITE_STATUS_PAGECACHE_SIZE
,
nByte
);
sqlite3StatusUp
(
SQLITE_STATUS_PAGECACHE_OVERFLOW
,
sz
);
sqlite3_mutex_leave
(
pcache1
.
mutex
);
int
sz
=
nByte
;
pthread_mutex_lock
(
&
pcache1
.
mutex
);
//
sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
//
sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
pthread_mutex_unlock
(
&
pcache1
.
mutex
);
}
#endif
sqlite3MemdebugSetType
(
p
,
MEMTYPE_PCACHE
);
//
sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
}
return
p
;
}
...
...
@@ -353,30 +353,31 @@ static void *pcache1Alloc(int nByte) {
*/
static
void
pcache1Free
(
void
*
p
)
{
if
(
p
==
0
)
return
;
if
(
SQLITE_WITHIN
(
p
,
pcache1
.
pStart
,
pcache1
.
pEnd
))
{
// if (SQLITE_WITHIN(p, pcache1.pStart, pcache1.pEnd)) {
if
(
p
>=
pcache1
.
pStart
&&
p
<
pcache1
.
pEnd
)
{
PgFreeslot
*
pSlot
;
sqlite3_mutex_enter
(
pcache1
.
mutex
);
sqlite3StatusDown
(
SQLITE_STATUS_PAGECACHE_USED
,
1
);
pthread_mutex_lock
(
&
pcache1
.
mutex
);
//
sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
pSlot
=
(
PgFreeslot
*
)
p
;
pSlot
->
pNext
=
pcache1
.
pFree
;
pcache1
.
pFree
=
pSlot
;
pcache1
.
nFreeSlot
++
;
pcache1
.
bUnderPressure
=
pcache1
.
nFreeSlot
<
pcache1
.
nReserve
;
assert
(
pcache1
.
nFreeSlot
<=
pcache1
.
nSlot
);
sqlite3_mutex_leave
(
pcache1
.
mutex
);
pthread_mutex_unlock
(
&
pcache1
.
mutex
);
}
else
{
assert
(
sqlite3MemdebugHasType
(
p
,
MEMTYPE_PCACHE
));
sqlite3MemdebugSetType
(
p
,
MEMTYPE_HEAP
);
//
assert(sqlite3MemdebugHasType(p, MEMTYPE_PCACHE));
//
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
{
int
nFreed
=
0
;
nFreed
=
sqlite3MallocSize
(
p
);
sqlite3_mutex_enter
(
pcache1
.
mutex
);
sqlite3StatusDown
(
SQLITE_STATUS_PAGECACHE_OVERFLOW
,
nFreed
);
sqlite3_mutex_leave
(
pcache1
.
mutex
);
//
nFreed = sqlite3MallocSize(p);
pthread_mutex_lock
(
&
pcache1
.
mutex
);
//
sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed);
pthread_mutex_unlock
(
&
pcache1
.
mutex
);
}
#endif
sqlite3_
free
(
p
);
free
(
p
);
}
}
...
...
@@ -421,7 +422,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc) {
pcache1LeaveMutex
(
pCache
->
pGroup
);
#endif
if
(
benignMalloc
)
{
sqlite3BeginBenignMalloc
();
//
sqlite3BeginBenignMalloc();
}
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
pPg
=
pcache1Alloc
(
pCache
->
szPage
);
...
...
@@ -435,7 +436,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc) {
pPg
=
pcache1Alloc
(
pCache
->
szAlloc
);
#endif
if
(
benignMalloc
)
{
sqlite3EndBenignMalloc
();
//
sqlite3EndBenignMalloc();
}
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
pcache1EnterMutex
(
pCache
->
pGroup
);
...
...
@@ -506,11 +507,11 @@ void sqlite3PageFree(void *p) { pcache1Free(p); }
** the heap even further.
*/
static
int
pcache1UnderMemoryPressure
(
PCache1
*
pCache
)
{
if
(
pcache1
.
nSlot
&&
(
pCache
->
szPage
+
pCache
->
szExtra
)
<=
pcache1
.
szSlot
)
{
return
pcache1
.
bUnderPressure
;
}
else
{
return
sqlite3HeapNearlyFull
();
}
//
if (pcache1.nSlot && (pCache->szPage + pCache->szExtra) <= pcache1.szSlot) {
return
pcache1
.
bUnderPressure
;
//
} else {
//
return sqlite3HeapNearlyFull();
//
}
}
/******************************************************************************/
...
...
@@ -536,11 +537,11 @@ static void pcache1ResizeHash(PCache1 *p) {
pcache1LeaveMutex
(
p
->
pGroup
);
if
(
p
->
nHash
)
{
sqlite3BeginBenignMalloc
();
//
sqlite3BeginBenignMalloc();
}
apNew
=
(
PgHdr1
**
)
calloc
(
nNew
,
sizeof
(
PgHdr1
*
));
if
(
p
->
nHash
)
{
sqlite3EndBenignMalloc
();
//
sqlite3EndBenignMalloc();
}
pcache1EnterMutex
(
p
->
pGroup
);
if
(
apNew
)
{
...
...
@@ -554,7 +555,7 @@ static void pcache1ResizeHash(PCache1 *p) {
apNew
[
h
]
=
pPage
;
}
}
sqlite3_
free
(
p
->
apHash
);
free
(
p
->
apHash
);
p
->
apHash
=
apNew
;
p
->
nHash
=
nNew
;
}
...
...
@@ -621,7 +622,7 @@ static void pcache1EnforceMaxPage(PCache1 *pCache) {
pcache1RemoveFromHash
(
p
,
1
);
}
if
(
pCache
->
nPage
==
0
&&
pCache
->
pBulk
)
{
sqlite3_
free
(
pCache
->
pBulk
);
free
(
pCache
->
pBulk
);
pCache
->
pBulk
=
pCache
->
pFree
=
0
;
}
}
...
...
@@ -636,7 +637,7 @@ static void pcache1EnforceMaxPage(PCache1 *pCache) {
static
void
pcache1TruncateUnsafe
(
PCache1
*
pCache
,
/* The cache to truncate */
unsigned
int
iLimit
/* Drop pages with this pgno or larger */
)
{
TESTONLY
(
int
nPage
=
0
;)
/* To assert pCache->nPage is correct */
int
nPage
=
0
;
/* To assert pCache->nPage is correct */
unsigned
int
h
,
iStop
;
// assert(sqlite3_mutex_held(pCache->pGroup->mutex));
assert
(
pCache
->
iMaxKey
>=
iLimit
);
...
...
@@ -648,7 +649,7 @@ static void pcache1TruncateUnsafe(PCache1 * pCache, /* The cache to truncate
** be removed. */
h
=
iLimit
%
pCache
->
nHash
;
iStop
=
pCache
->
iMaxKey
%
pCache
->
nHash
;
TESTONLY
(
nPage
=
-
10
;)
/* Disable the pCache->nPage validity check */
nPage
=
-
10
;
/* Disable the pCache->nPage validity check */
}
else
{
/* This is the general case where many pages are being removed.
** It is necessary to scan the entire hash table */
...
...
@@ -668,7 +669,7 @@ static void pcache1TruncateUnsafe(PCache1 * pCache, /* The cache to truncate
pcache1FreePage
(
pPage
);
}
else
{
pp
=
&
pPage
->
pNext
;
TESTONLY
(
if
(
nPage
>=
0
)
nPage
++
;)
if
(
nPage
>=
0
)
nPage
++
;
}
}
if
(
h
==
iStop
)
break
;
...
...
@@ -851,7 +852,7 @@ static int pcache1Pagecount(sqlite3_pcache *p) {
** usually not needed, and by avoiding the stack initialization required
** for these steps, the main pcache1Fetch() procedure can run faster.
*/
static
SQLITE_NOINLINE
PgHdr1
*
pcache1FetchStage2
(
PCache1
*
pCache
,
unsigned
int
iKey
,
int
createFlag
)
{
static
PgHdr1
*
pcache1FetchStage2
(
PCache1
*
pCache
,
unsigned
int
iKey
,
int
createFlag
)
{
unsigned
int
nPinned
;
PGroup
*
pGroup
=
pCache
->
pGroup
;
PgHdr1
*
pPage
=
0
;
...
...
@@ -1020,14 +1021,7 @@ static sqlite3_pcache_page *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, i
assert
(
pCache
->
bPurgeable
==
0
||
pCache
->
nMin
==
10
);
assert
(
pCache
->
nMin
==
0
||
pCache
->
bPurgeable
);
assert
(
pCache
->
nHash
>
0
);
#if PCACHE1_MIGHT_USE_GROUP_MUTEX
if
(
pCache
->
pGroup
->
mutex
)
{
return
(
sqlite3_pcache_page
*
)
pcache1FetchWithMutex
(
p
,
iKey
,
createFlag
);
}
else
#endif
{
return
(
sqlite3_pcache_page
*
)
pcache1FetchNoMutex
(
p
,
iKey
,
createFlag
);
}
return
(
sqlite3_pcache_page
*
)
pcache1FetchWithMutex
(
p
,
iKey
,
createFlag
);
}
/*
...
...
@@ -1129,9 +1123,9 @@ static void pcache1Destroy(sqlite3_pcache *p) {
pGroup
->
mxPinned
=
pGroup
->
nMaxPage
+
10
-
pGroup
->
nMinPage
;
pcache1EnforceMaxPage
(
pCache
);
pcache1LeaveMutex
(
pGroup
);
sqlite3_
free
(
pCache
->
pBulk
);
sqlite3_
free
(
pCache
->
apHash
);
sqlite3_
free
(
pCache
);
free
(
pCache
->
pBulk
);
free
(
pCache
->
apHash
);
free
(
pCache
);
}
/*
...
...
@@ -1139,11 +1133,11 @@ static void pcache1Destroy(sqlite3_pcache *p) {
*/
int
sqlite3HeaderSizePcache1
(
void
)
{
return
ROUND8
(
sizeof
(
PgHdr1
));
}
/*
** Return the global mutex used by this PCACHE implementation. The
** sqlite3_status() routine needs access to this mutex.
*/
sqlite3_mutex
*
sqlite3Pcache1Mutex
(
void
)
{
return
pcache1
.
mutex
;
}
/
/ /
*
//
** Return the global mutex used by this PCACHE implementation. The
//
** sqlite3_status() routine needs access to this mutex.
//
*/
//
sqlite3_mutex *sqlite3Pcache1Mutex(void) { return pcache1.mutex; }
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
/*
...
...
@@ -1157,8 +1151,8 @@ sqlite3_mutex *sqlite3Pcache1Mutex(void) { return pcache1.mutex; }
*/
int
sqlite3PcacheReleaseMemory
(
int
nReq
)
{
int
nFree
=
0
;
assert
(
sqlite3_mutex_notheld
(
pcache1
.
grp
.
mutex
));
assert
(
sqlite3_mutex_notheld
(
pcache1
.
mutex
));
//
assert(sqlite3_mutex_notheld(pcache1.grp.mutex));
//
assert(sqlite3_mutex_notheld(pcache1.mutex));
if
(
sqlite3GlobalConfig
.
pPage
==
0
)
{
PgHdr1
*
p
;
pcache1EnterMutex
(
&
pcache1
.
grp
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录