Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3beef665
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看板
提交
3beef665
编写于
3月 18, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
031d84e7
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
0 addition
and
26153 deletion
+0
-26153
source/libs/tdb/CMakeLists.txt
source/libs/tdb/CMakeLists.txt
+0
-10
source/libs/tdb/src/sqlite/btmutex.c
source/libs/tdb/src/sqlite/btmutex.c
+0
-308
source/libs/tdb/src/sqlite/btree.c
source/libs/tdb/src/sqlite/btree.c
+0
-10869
source/libs/tdb/src/sqlite/pager.c
source/libs/tdb/src/sqlite/pager.c
+0
-6851
source/libs/tdb/src/sqlite/pcache.c
source/libs/tdb/src/sqlite/pcache.c
+0
-851
source/libs/tdb/src/sqlite/pcache1.c
source/libs/tdb/src/sqlite/pcache1.c
+0
-1211
source/libs/tdb/src/sqlite/wal.c
source/libs/tdb/src/sqlite/wal.c
+0
-4153
source/libs/tdb/src/sqliteinc/btree.h
source/libs/tdb/src/sqliteinc/btree.h
+0
-412
source/libs/tdb/src/sqliteinc/btreeInt.h
source/libs/tdb/src/sqliteinc/btreeInt.h
+0
-729
source/libs/tdb/src/sqliteinc/pager.h
source/libs/tdb/src/sqliteinc/pager.h
+0
-241
source/libs/tdb/src/sqliteinc/pcache.h
source/libs/tdb/src/sqliteinc/pcache.h
+0
-210
source/libs/tdb/src/sqliteinc/sqlite3.h
source/libs/tdb/src/sqliteinc/sqlite3.h
+0
-95
source/libs/tdb/src/sqliteinc/sqliteInt.h
source/libs/tdb/src/sqliteinc/sqliteInt.h
+0
-58
source/libs/tdb/src/sqliteinc/wal.h
source/libs/tdb/src/sqliteinc/wal.h
+0
-155
未找到文件。
source/libs/tdb/CMakeLists.txt
浏览文件 @
3beef665
...
...
@@ -22,16 +22,6 @@ target_link_libraries(
PUBLIC util
)
# for tdb_sqlite
add_library
(
tdb_sqlite
""
)
target_sources
(
tdb_sqlite
PRIVATE
"src/sqlite/pcache.c"
"src/sqlite/pcache1.c"
"src/sqlite/pager.c"
)
target_include_directories
(
tdb_sqlite PUBLIC
"src/sqliteinc"
)
# for test
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
...
...
source/libs/tdb/src/sqlite/btmutex.c
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2007 August 27
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement mutexes on Btree objects.
** This code really belongs in btree.c. But btree.c is getting too
** big and we want to break it down some. This packaged seemed like
** a good breakout.
*/
#include "btreeInt.h"
#ifndef SQLITE_OMIT_SHARED_CACHE
#if SQLITE_THREADSAFE
/*
** Obtain the BtShared mutex associated with B-Tree handle p. Also,
** set BtShared.db to the database handle associated with p and the
** p->locked boolean to true.
*/
static
void
lockBtreeMutex
(
Btree
*
p
){
assert
(
p
->
locked
==
0
);
assert
(
sqlite3_mutex_notheld
(
p
->
pBt
->
mutex
)
);
assert
(
sqlite3_mutex_held
(
p
->
db
->
mutex
)
);
sqlite3_mutex_enter
(
p
->
pBt
->
mutex
);
p
->
pBt
->
db
=
p
->
db
;
p
->
locked
=
1
;
}
/*
** Release the BtShared mutex associated with B-Tree handle p and
** clear the p->locked boolean.
*/
static
void
SQLITE_NOINLINE
unlockBtreeMutex
(
Btree
*
p
){
BtShared
*
pBt
=
p
->
pBt
;
assert
(
p
->
locked
==
1
);
assert
(
sqlite3_mutex_held
(
pBt
->
mutex
)
);
assert
(
sqlite3_mutex_held
(
p
->
db
->
mutex
)
);
assert
(
p
->
db
==
pBt
->
db
);
sqlite3_mutex_leave
(
pBt
->
mutex
);
p
->
locked
=
0
;
}
/* Forward reference */
static
void
SQLITE_NOINLINE
btreeLockCarefully
(
Btree
*
p
);
/*
** Enter a mutex on the given BTree object.
**
** If the object is not sharable, then no mutex is ever required
** and this routine is a no-op. The underlying mutex is non-recursive.
** But we keep a reference count in Btree.wantToLock so the behavior
** of this interface is recursive.
**
** To avoid deadlocks, multiple Btrees are locked in the same order
** by all database connections. The p->pNext is a list of other
** Btrees belonging to the same database connection as the p Btree
** which need to be locked after p. If we cannot get a lock on
** p, then first unlock all of the others on p->pNext, then wait
** for the lock to become available on p, then relock all of the
** subsequent Btrees that desire a lock.
*/
void
sqlite3BtreeEnter
(
Btree
*
p
){
/* Some basic sanity checking on the Btree. The list of Btrees
** connected by pNext and pPrev should be in sorted order by
** Btree.pBt value. All elements of the list should belong to
** the same connection. Only shared Btrees are on the list. */
assert
(
p
->
pNext
==
0
||
p
->
pNext
->
pBt
>
p
->
pBt
);
assert
(
p
->
pPrev
==
0
||
p
->
pPrev
->
pBt
<
p
->
pBt
);
assert
(
p
->
pNext
==
0
||
p
->
pNext
->
db
==
p
->
db
);
assert
(
p
->
pPrev
==
0
||
p
->
pPrev
->
db
==
p
->
db
);
assert
(
p
->
sharable
||
(
p
->
pNext
==
0
&&
p
->
pPrev
==
0
)
);
/* Check for locking consistency */
assert
(
!
p
->
locked
||
p
->
wantToLock
>
0
);
assert
(
p
->
sharable
||
p
->
wantToLock
==
0
);
/* We should already hold a lock on the database connection */
assert
(
sqlite3_mutex_held
(
p
->
db
->
mutex
)
);
/* Unless the database is sharable and unlocked, then BtShared.db
** should already be set correctly. */
assert
(
(
p
->
locked
==
0
&&
p
->
sharable
)
||
p
->
pBt
->
db
==
p
->
db
);
if
(
!
p
->
sharable
)
return
;
p
->
wantToLock
++
;
if
(
p
->
locked
)
return
;
btreeLockCarefully
(
p
);
}
/* This is a helper function for sqlite3BtreeLock(). By moving
** complex, but seldom used logic, out of sqlite3BtreeLock() and
** into this routine, we avoid unnecessary stack pointer changes
** and thus help the sqlite3BtreeLock() routine to run much faster
** in the common case.
*/
static
void
SQLITE_NOINLINE
btreeLockCarefully
(
Btree
*
p
){
Btree
*
pLater
;
/* In most cases, we should be able to acquire the lock we
** want without having to go through the ascending lock
** procedure that follows. Just be sure not to block.
*/
if
(
sqlite3_mutex_try
(
p
->
pBt
->
mutex
)
==
SQLITE_OK
){
p
->
pBt
->
db
=
p
->
db
;
p
->
locked
=
1
;
return
;
}
/* To avoid deadlock, first release all locks with a larger
** BtShared address. Then acquire our lock. Then reacquire
** the other BtShared locks that we used to hold in ascending
** order.
*/
for
(
pLater
=
p
->
pNext
;
pLater
;
pLater
=
pLater
->
pNext
){
assert
(
pLater
->
sharable
);
assert
(
pLater
->
pNext
==
0
||
pLater
->
pNext
->
pBt
>
pLater
->
pBt
);
assert
(
!
pLater
->
locked
||
pLater
->
wantToLock
>
0
);
if
(
pLater
->
locked
){
unlockBtreeMutex
(
pLater
);
}
}
lockBtreeMutex
(
p
);
for
(
pLater
=
p
->
pNext
;
pLater
;
pLater
=
pLater
->
pNext
){
if
(
pLater
->
wantToLock
){
lockBtreeMutex
(
pLater
);
}
}
}
/*
** Exit the recursive mutex on a Btree.
*/
void
sqlite3BtreeLeave
(
Btree
*
p
){
assert
(
sqlite3_mutex_held
(
p
->
db
->
mutex
)
);
if
(
p
->
sharable
){
assert
(
p
->
wantToLock
>
0
);
p
->
wantToLock
--
;
if
(
p
->
wantToLock
==
0
){
unlockBtreeMutex
(
p
);
}
}
}
#ifndef NDEBUG
/*
** Return true if the BtShared mutex is held on the btree, or if the
** B-Tree is not marked as sharable.
**
** This routine is used only from within assert() statements.
*/
int
sqlite3BtreeHoldsMutex
(
Btree
*
p
){
assert
(
p
->
sharable
==
0
||
p
->
locked
==
0
||
p
->
wantToLock
>
0
);
assert
(
p
->
sharable
==
0
||
p
->
locked
==
0
||
p
->
db
==
p
->
pBt
->
db
);
assert
(
p
->
sharable
==
0
||
p
->
locked
==
0
||
sqlite3_mutex_held
(
p
->
pBt
->
mutex
)
);
assert
(
p
->
sharable
==
0
||
p
->
locked
==
0
||
sqlite3_mutex_held
(
p
->
db
->
mutex
)
);
return
(
p
->
sharable
==
0
||
p
->
locked
);
}
#endif
/*
** Enter the mutex on every Btree associated with a database
** connection. This is needed (for example) prior to parsing
** a statement since we will be comparing table and column names
** against all schemas and we do not want those schemas being
** reset out from under us.
**
** There is a corresponding leave-all procedures.
**
** Enter the mutexes in accending order by BtShared pointer address
** to avoid the possibility of deadlock when two threads with
** two or more btrees in common both try to lock all their btrees
** at the same instant.
*/
static
void
SQLITE_NOINLINE
btreeEnterAll
(
sqlite3
*
db
){
int
i
;
int
skipOk
=
1
;
Btree
*
p
;
assert
(
sqlite3_mutex_held
(
db
->
mutex
)
);
for
(
i
=
0
;
i
<
db
->
nDb
;
i
++
){
p
=
db
->
aDb
[
i
].
pBt
;
if
(
p
&&
p
->
sharable
){
sqlite3BtreeEnter
(
p
);
skipOk
=
0
;
}
}
db
->
noSharedCache
=
skipOk
;
}
void
sqlite3BtreeEnterAll
(
sqlite3
*
db
){
if
(
db
->
noSharedCache
==
0
)
btreeEnterAll
(
db
);
}
static
void
SQLITE_NOINLINE
btreeLeaveAll
(
sqlite3
*
db
){
int
i
;
Btree
*
p
;
assert
(
sqlite3_mutex_held
(
db
->
mutex
)
);
for
(
i
=
0
;
i
<
db
->
nDb
;
i
++
){
p
=
db
->
aDb
[
i
].
pBt
;
if
(
p
)
sqlite3BtreeLeave
(
p
);
}
}
void
sqlite3BtreeLeaveAll
(
sqlite3
*
db
){
if
(
db
->
noSharedCache
==
0
)
btreeLeaveAll
(
db
);
}
#ifndef NDEBUG
/*
** Return true if the current thread holds the database connection
** mutex and all required BtShared mutexes.
**
** This routine is used inside assert() statements only.
*/
int
sqlite3BtreeHoldsAllMutexes
(
sqlite3
*
db
){
int
i
;
if
(
!
sqlite3_mutex_held
(
db
->
mutex
)
){
return
0
;
}
for
(
i
=
0
;
i
<
db
->
nDb
;
i
++
){
Btree
*
p
;
p
=
db
->
aDb
[
i
].
pBt
;
if
(
p
&&
p
->
sharable
&&
(
p
->
wantToLock
==
0
||
!
sqlite3_mutex_held
(
p
->
pBt
->
mutex
))
){
return
0
;
}
}
return
1
;
}
#endif
/* NDEBUG */
#ifndef NDEBUG
/*
** Return true if the correct mutexes are held for accessing the
** db->aDb[iDb].pSchema structure. The mutexes required for schema
** access are:
**
** (1) The mutex on db
** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
**
** If pSchema is not NULL, then iDb is computed from pSchema and
** db using sqlite3SchemaToIndex().
*/
int
sqlite3SchemaMutexHeld
(
sqlite3
*
db
,
int
iDb
,
Schema
*
pSchema
){
Btree
*
p
;
assert
(
db
!=
0
);
if
(
pSchema
)
iDb
=
sqlite3SchemaToIndex
(
db
,
pSchema
);
assert
(
iDb
>=
0
&&
iDb
<
db
->
nDb
);
if
(
!
sqlite3_mutex_held
(
db
->
mutex
)
)
return
0
;
if
(
iDb
==
1
)
return
1
;
p
=
db
->
aDb
[
iDb
].
pBt
;
assert
(
p
!=
0
);
return
p
->
sharable
==
0
||
p
->
locked
==
1
;
}
#endif
/* NDEBUG */
#else
/* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */
/*
** The following are special cases for mutex enter routines for use
** in single threaded applications that use shared cache. Except for
** these two routines, all mutex operations are no-ops in that case and
** are null #defines in btree.h.
**
** If shared cache is disabled, then all btree mutex routines, including
** the ones below, are no-ops and are null #defines in btree.h.
*/
void
sqlite3BtreeEnter
(
Btree
*
p
){
p
->
pBt
->
db
=
p
->
db
;
}
void
sqlite3BtreeEnterAll
(
sqlite3
*
db
){
int
i
;
for
(
i
=
0
;
i
<
db
->
nDb
;
i
++
){
Btree
*
p
=
db
->
aDb
[
i
].
pBt
;
if
(
p
){
p
->
pBt
->
db
=
p
->
db
;
}
}
}
#endif
/* if SQLITE_THREADSAFE */
#ifndef SQLITE_OMIT_INCRBLOB
/*
** Enter a mutex on a Btree given a cursor owned by that Btree.
**
** These entry points are used by incremental I/O only. Enter() is required
** any time OMIT_SHARED_CACHE is not defined, regardless of whether or not
** the build is threadsafe. Leave() is only required by threadsafe builds.
*/
void
sqlite3BtreeEnterCursor
(
BtCursor
*
pCur
){
sqlite3BtreeEnter
(
pCur
->
pBtree
);
}
# if SQLITE_THREADSAFE
void
sqlite3BtreeLeaveCursor
(
BtCursor
*
pCur
){
sqlite3BtreeLeave
(
pCur
->
pBtree
);
}
# endif
#endif
/* ifndef SQLITE_OMIT_INCRBLOB */
#endif
/* ifndef SQLITE_OMIT_SHARED_CACHE */
source/libs/tdb/src/sqlite/btree.c
已删除
100644 → 0
浏览文件 @
031d84e7
此差异已折叠。
点击以展开。
source/libs/tdb/src/sqlite/pager.c
已删除
100644 → 0
浏览文件 @
031d84e7
此差异已折叠。
点击以展开。
source/libs/tdb/src/sqlite/pcache.c
已删除
100644 → 0
浏览文件 @
031d84e7
此差异已折叠。
点击以展开。
source/libs/tdb/src/sqlite/pcache1.c
已删除
100644 → 0
浏览文件 @
031d84e7
此差异已折叠。
点击以展开。
source/libs/tdb/src/sqlite/wal.c
已删除
100644 → 0
浏览文件 @
031d84e7
此差异已折叠。
点击以展开。
source/libs/tdb/src/sqliteinc/btree.h
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite B-Tree file
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
*/
#ifndef SQLITE_BTREE_H
#define SQLITE_BTREE_H
/* TODO: This definition is just included so other modules compile. It
** needs to be revisited.
*/
#define SQLITE_N_BTREE_META 16
/*
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
*/
#ifndef SQLITE_DEFAULT_AUTOVACUUM
#define SQLITE_DEFAULT_AUTOVACUUM 0
#endif
#define BTREE_AUTOVACUUM_NONE 0
/* Do not do auto-vacuum */
#define BTREE_AUTOVACUUM_FULL 1
/* Do full auto-vacuum */
#define BTREE_AUTOVACUUM_INCR 2
/* Incremental vacuum */
/*
** Forward declarations of structure
*/
typedef
struct
Btree
Btree
;
typedef
struct
BtCursor
BtCursor
;
typedef
struct
BtShared
BtShared
;
typedef
struct
BtreePayload
BtreePayload
;
int
sqlite3BtreeOpen
(
sqlite3_vfs
*
pVfs
,
/* VFS to use with this b-tree */
const
char
*
zFilename
,
/* Name of database file to open */
sqlite3
*
db
,
/* Associated database connection */
Btree
**
ppBtree
,
/* Return open Btree* here */
int
flags
,
/* Flags */
int
vfsFlags
/* Flags passed through to VFS open */
);
/* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
** following values.
**
** NOTE: These values must match the corresponding PAGER_ values in
** pager.h.
*/
#define BTREE_OMIT_JOURNAL 1
/* Do not create or use a rollback journal */
#define BTREE_MEMORY 2
/* This is an in-memory DB */
#define BTREE_SINGLE 4
/* The file contains at most 1 b-tree */
#define BTREE_UNORDERED 8
/* Use of a hash implementation is OK */
int
sqlite3BtreeClose
(
Btree
*
);
int
sqlite3BtreeSetCacheSize
(
Btree
*
,
int
);
int
sqlite3BtreeSetSpillSize
(
Btree
*
,
int
);
#if SQLITE_MAX_MMAP_SIZE>0
int
sqlite3BtreeSetMmapLimit
(
Btree
*
,
sqlite3_int64
);
#endif
int
sqlite3BtreeSetPagerFlags
(
Btree
*
,
unsigned
);
int
sqlite3BtreeSetPageSize
(
Btree
*
p
,
int
nPagesize
,
int
nReserve
,
int
eFix
);
int
sqlite3BtreeGetPageSize
(
Btree
*
);
Pgno
sqlite3BtreeMaxPageCount
(
Btree
*
,
Pgno
);
Pgno
sqlite3BtreeLastPage
(
Btree
*
);
int
sqlite3BtreeSecureDelete
(
Btree
*
,
int
);
int
sqlite3BtreeGetRequestedReserve
(
Btree
*
);
int
sqlite3BtreeGetReserveNoMutex
(
Btree
*
p
);
int
sqlite3BtreeSetAutoVacuum
(
Btree
*
,
int
);
int
sqlite3BtreeGetAutoVacuum
(
Btree
*
);
int
sqlite3BtreeBeginTrans
(
Btree
*
,
int
,
int
*
);
int
sqlite3BtreeCommitPhaseOne
(
Btree
*
,
const
char
*
);
int
sqlite3BtreeCommitPhaseTwo
(
Btree
*
,
int
);
int
sqlite3BtreeCommit
(
Btree
*
);
int
sqlite3BtreeRollback
(
Btree
*
,
int
,
int
);
int
sqlite3BtreeBeginStmt
(
Btree
*
,
int
);
int
sqlite3BtreeCreateTable
(
Btree
*
,
Pgno
*
,
int
flags
);
int
sqlite3BtreeTxnState
(
Btree
*
);
int
sqlite3BtreeIsInBackup
(
Btree
*
);
void
*
sqlite3BtreeSchema
(
Btree
*
,
int
,
void
(
*
)(
void
*
));
int
sqlite3BtreeSchemaLocked
(
Btree
*
pBtree
);
#ifndef SQLITE_OMIT_SHARED_CACHE
int
sqlite3BtreeLockTable
(
Btree
*
pBtree
,
int
iTab
,
u8
isWriteLock
);
#endif
/* Savepoints are named, nestable SQL transactions mostly implemented */
/* in vdbe.c and pager.c See https://sqlite.org/lang_savepoint.html */
int
sqlite3BtreeSavepoint
(
Btree
*
,
int
,
int
);
/* "Checkpoint" only refers to WAL. See https://sqlite.org/wal.html#ckpt */
#ifndef SQLITE_OMIT_WAL
int
sqlite3BtreeCheckpoint
(
Btree
*
,
int
,
int
*
,
int
*
);
#endif
const
char
*
sqlite3BtreeGetFilename
(
Btree
*
);
const
char
*
sqlite3BtreeGetJournalname
(
Btree
*
);
int
sqlite3BtreeCopyFile
(
Btree
*
,
Btree
*
);
int
sqlite3BtreeIncrVacuum
(
Btree
*
);
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
** of the flags shown below.
**
** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
** indices.)
*/
#define BTREE_INTKEY 1
/* Table has only 64-bit signed integer keys */
#define BTREE_BLOBKEY 2
/* Table has keys only - no data */
int
sqlite3BtreeDropTable
(
Btree
*
,
int
,
int
*
);
int
sqlite3BtreeClearTable
(
Btree
*
,
int
,
i64
*
);
int
sqlite3BtreeClearTableOfCursor
(
BtCursor
*
);
int
sqlite3BtreeTripAllCursors
(
Btree
*
,
int
,
int
);
void
sqlite3BtreeGetMeta
(
Btree
*
pBtree
,
int
idx
,
u32
*
pValue
);
int
sqlite3BtreeUpdateMeta
(
Btree
*
,
int
idx
,
u32
value
);
int
sqlite3BtreeNewDb
(
Btree
*
p
);
/*
** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
** should be one of the following values. The integer values are assigned
** to constants so that the offset of the corresponding field in an
** SQLite database header may be found using the following formula:
**
** offset = 36 + (idx * 4)
**
** For example, the free-page-count field is located at byte offset 36 of
** the database file header. The incr-vacuum-flag field is located at
** byte offset 64 (== 36+4*7).
**
** The BTREE_DATA_VERSION value is not really a value stored in the header.
** It is a read-only number computed by the pager. But we merge it with
** the header value access routines since its access pattern is the same.
** Call it a "virtual meta value".
*/
#define BTREE_FREE_PAGE_COUNT 0
#define BTREE_SCHEMA_VERSION 1
#define BTREE_FILE_FORMAT 2
#define BTREE_DEFAULT_CACHE_SIZE 3
#define BTREE_LARGEST_ROOT_PAGE 4
#define BTREE_TEXT_ENCODING 5
#define BTREE_USER_VERSION 6
#define BTREE_INCR_VACUUM 7
#define BTREE_APPLICATION_ID 8
#define BTREE_DATA_VERSION 15
/* A virtual meta-value */
/*
** Kinds of hints that can be passed into the sqlite3BtreeCursorHint()
** interface.
**
** BTREE_HINT_RANGE (arguments: Expr*, Mem*)
**
** The first argument is an Expr* (which is guaranteed to be constant for
** the lifetime of the cursor) that defines constraints on which rows
** might be fetched with this cursor. The Expr* tree may contain
** TK_REGISTER nodes that refer to values stored in the array of registers
** passed as the second parameter. In other words, if Expr.op==TK_REGISTER
** then the value of the node is the value in Mem[pExpr.iTable]. Any
** TK_COLUMN node in the expression tree refers to the Expr.iColumn-th
** column of the b-tree of the cursor. The Expr tree will not contain
** any function calls nor subqueries nor references to b-trees other than
** the cursor being hinted.
**
** The design of the _RANGE hint is aid b-tree implementations that try
** to prefetch content from remote machines - to provide those
** implementations with limits on what needs to be prefetched and thereby
** reduce network bandwidth.
**
** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by
** standard SQLite. The other hints are provided for extentions that use
** the SQLite parser and code generator but substitute their own storage
** engine.
*/
#define BTREE_HINT_RANGE 0
/* Range constraints on queries */
/*
** Values that may be OR'd together to form the argument to the
** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint():
**
** The BTREE_BULKLOAD flag is set on index cursors when the index is going
** to be filled with content that is already in sorted order.
**
** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or
** OP_SeekLE opcodes for a range search, but where the range of entries
** selected will all have the same key. In other words, the cursor will
** be used only for equality key searches.
**
*/
#define BTREE_BULKLOAD 0x00000001
/* Used to full index in sorted order */
#define BTREE_SEEK_EQ 0x00000002
/* EQ seeks only - no range seeks */
/*
** Flags passed as the third argument to sqlite3BtreeCursor().
**
** For read-only cursors the wrFlag argument is always zero. For read-write
** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or just
** (BTREE_WRCSR). If the BTREE_FORDELETE bit is set, then the cursor will
** only be used by SQLite for the following:
**
** * to seek to and then delete specific entries, and/or
**
** * to read values that will be used to create keys that other
** BTREE_FORDELETE cursors will seek to and delete.
**
** The BTREE_FORDELETE flag is an optimization hint. It is not used by
** by this, the native b-tree engine of SQLite, but it is available to
** alternative storage engines that might be substituted in place of this
** b-tree system. For alternative storage engines in which a delete of
** the main table row automatically deletes corresponding index rows,
** the FORDELETE flag hint allows those alternative storage engines to
** skip a lot of work. Namely: FORDELETE cursors may treat all SEEK
** and DELETE operations as no-ops, and any READ operation against a
** FORDELETE cursor may return a null row: 0x01 0x00.
*/
#define BTREE_WRCSR 0x00000004
/* read-write cursor */
#define BTREE_FORDELETE 0x00000008
/* Cursor is for seek/delete only */
int
sqlite3BtreeCursor
(
Btree
*
,
/* BTree containing table to open */
Pgno
iTable
,
/* Index of root page */
int
wrFlag
,
/* 1 for writing. 0 for read-only */
struct
KeyInfo
*
,
/* First argument to compare function */
BtCursor
*
pCursor
/* Space to write cursor structure */
);
BtCursor
*
sqlite3BtreeFakeValidCursor
(
void
);
int
sqlite3BtreeCursorSize
(
void
);
void
sqlite3BtreeCursorZero
(
BtCursor
*
);
void
sqlite3BtreeCursorHintFlags
(
BtCursor
*
,
unsigned
);
#ifdef SQLITE_ENABLE_CURSOR_HINTS
void
sqlite3BtreeCursorHint
(
BtCursor
*
,
int
,
...);
#endif
int
sqlite3BtreeCloseCursor
(
BtCursor
*
);
int
sqlite3BtreeTableMoveto
(
BtCursor
*
,
i64
intKey
,
int
bias
,
int
*
pRes
);
int
sqlite3BtreeIndexMoveto
(
BtCursor
*
,
UnpackedRecord
*
pUnKey
,
int
*
pRes
);
int
sqlite3BtreeCursorHasMoved
(
BtCursor
*
);
int
sqlite3BtreeCursorRestore
(
BtCursor
*
,
int
*
);
int
sqlite3BtreeDelete
(
BtCursor
*
,
u8
flags
);
/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
#define BTREE_SAVEPOSITION 0x02
/* Leave cursor pointing at NEXT or PREV */
#define BTREE_AUXDELETE 0x04
/* not the primary delete operation */
#define BTREE_APPEND 0x08
/* Insert is likely an append */
#define BTREE_PREFORMAT 0x80
/* Inserted data is a preformated cell */
/* An instance of the BtreePayload object describes the content of a single
** entry in either an index or table btree.
**
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
** an arbitrary key and no data. These btrees have pKey,nKey set to the
** key and the pData,nData,nZero fields are uninitialized. The aMem,nMem
** fields give an array of Mem objects that are a decomposition of the key.
** The nMem field might be zero, indicating that no decomposition is available.
**
** Table btrees (used for rowid tables) contain an integer rowid used as
** the key and passed in the nKey field. The pKey field is zero.
** pData,nData hold the content of the new entry. nZero extra zero bytes
** are appended to the end of the content when constructing the entry.
** The aMem,nMem fields are uninitialized for table btrees.
**
** Field usage summary:
**
** Table BTrees Index Btrees
**
** pKey always NULL encoded key
** nKey the ROWID length of pKey
** pData data not used
** aMem not used decomposed key value
** nMem not used entries in aMem
** nData length of pData not used
** nZero extra zeros after pData not used
**
** This object is used to pass information into sqlite3BtreeInsert(). The
** same information used to be passed as five separate parameters. But placing
** the information into this object helps to keep the interface more
** organized and understandable, and it also helps the resulting code to
** run a little faster by using fewer registers for parameter passing.
*/
struct
BtreePayload
{
const
void
*
pKey
;
/* Key content for indexes. NULL for tables */
sqlite3_int64
nKey
;
/* Size of pKey for indexes. PRIMARY KEY for tabs */
const
void
*
pData
;
/* Data for tables. */
sqlite3_value
*
aMem
;
/* First of nMem value in the unpacked pKey */
u16
nMem
;
/* Number of aMem[] value. Might be zero */
int
nData
;
/* Size of pData. 0 if none. */
int
nZero
;
/* Extra zero data appended after pData,nData */
};
int
sqlite3BtreeInsert
(
BtCursor
*
,
const
BtreePayload
*
pPayload
,
int
flags
,
int
seekResult
);
int
sqlite3BtreeFirst
(
BtCursor
*
,
int
*
pRes
);
int
sqlite3BtreeLast
(
BtCursor
*
,
int
*
pRes
);
int
sqlite3BtreeNext
(
BtCursor
*
,
int
flags
);
int
sqlite3BtreeEof
(
BtCursor
*
);
int
sqlite3BtreePrevious
(
BtCursor
*
,
int
flags
);
i64
sqlite3BtreeIntegerKey
(
BtCursor
*
);
void
sqlite3BtreeCursorPin
(
BtCursor
*
);
void
sqlite3BtreeCursorUnpin
(
BtCursor
*
);
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
i64
sqlite3BtreeOffset
(
BtCursor
*
);
#endif
int
sqlite3BtreePayload
(
BtCursor
*
,
u32
offset
,
u32
amt
,
void
*
);
const
void
*
sqlite3BtreePayloadFetch
(
BtCursor
*
,
u32
*
pAmt
);
u32
sqlite3BtreePayloadSize
(
BtCursor
*
);
sqlite3_int64
sqlite3BtreeMaxRecordSize
(
BtCursor
*
);
char
*
sqlite3BtreeIntegrityCheck
(
sqlite3
*
,
Btree
*
,
Pgno
*
aRoot
,
int
nRoot
,
int
,
int
*
);
struct
Pager
*
sqlite3BtreePager
(
Btree
*
);
i64
sqlite3BtreeRowCountEst
(
BtCursor
*
);
#ifndef SQLITE_OMIT_INCRBLOB
int
sqlite3BtreePayloadChecked
(
BtCursor
*
,
u32
offset
,
u32
amt
,
void
*
);
int
sqlite3BtreePutData
(
BtCursor
*
,
u32
offset
,
u32
amt
,
void
*
);
void
sqlite3BtreeIncrblobCursor
(
BtCursor
*
);
#endif
void
sqlite3BtreeClearCursor
(
BtCursor
*
);
int
sqlite3BtreeSetVersion
(
Btree
*
pBt
,
int
iVersion
);
int
sqlite3BtreeCursorHasHint
(
BtCursor
*
,
unsigned
int
mask
);
int
sqlite3BtreeIsReadonly
(
Btree
*
pBt
);
int
sqlite3HeaderSizeBtree
(
void
);
#ifdef SQLITE_DEBUG
sqlite3_uint64
sqlite3BtreeSeekCount
(
Btree
*
);
#else
# define sqlite3BtreeSeekCount(X) 0
#endif
#ifndef NDEBUG
int
sqlite3BtreeCursorIsValid
(
BtCursor
*
);
#endif
int
sqlite3BtreeCursorIsValidNN
(
BtCursor
*
);
int
sqlite3BtreeCount
(
sqlite3
*
,
BtCursor
*
,
i64
*
);
#ifdef SQLITE_TEST
int
sqlite3BtreeCursorInfo
(
BtCursor
*
,
int
*
,
int
);
void
sqlite3BtreeCursorList
(
Btree
*
);
#endif
#ifndef SQLITE_OMIT_WAL
int
sqlite3BtreeCheckpoint
(
Btree
*
,
int
,
int
*
,
int
*
);
#endif
int
sqlite3BtreeTransferRow
(
BtCursor
*
,
BtCursor
*
,
i64
);
/*
** If we are not using shared cache, then there is no need to
** use mutexes to access the BtShared structures. So make the
** Enter and Leave procedures no-ops.
*/
#ifndef SQLITE_OMIT_SHARED_CACHE
void
sqlite3BtreeEnter
(
Btree
*
);
void
sqlite3BtreeEnterAll
(
sqlite3
*
);
int
sqlite3BtreeSharable
(
Btree
*
);
void
sqlite3BtreeEnterCursor
(
BtCursor
*
);
int
sqlite3BtreeConnectionCount
(
Btree
*
);
#else
# define sqlite3BtreeEnter(X)
# define sqlite3BtreeEnterAll(X)
# define sqlite3BtreeSharable(X) 0
# define sqlite3BtreeEnterCursor(X)
# define sqlite3BtreeConnectionCount(X) 1
#endif
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
void
sqlite3BtreeLeave
(
Btree
*
);
void
sqlite3BtreeLeaveCursor
(
BtCursor
*
);
void
sqlite3BtreeLeaveAll
(
sqlite3
*
);
#ifndef NDEBUG
/* These routines are used inside assert() statements only. */
int
sqlite3BtreeHoldsMutex
(
Btree
*
);
int
sqlite3BtreeHoldsAllMutexes
(
sqlite3
*
);
int
sqlite3SchemaMutexHeld
(
sqlite3
*
,
int
,
Schema
*
);
#endif
#else
# define sqlite3BtreeLeave(X)
# define sqlite3BtreeLeaveCursor(X)
# define sqlite3BtreeLeaveAll(X)
# define sqlite3BtreeHoldsMutex(X) 1
# define sqlite3BtreeHoldsAllMutexes(X) 1
# define sqlite3SchemaMutexHeld(X,Y,Z) 1
#endif
#endif
/* SQLITE_BTREE_H */
source/libs/tdb/src/sqliteinc/btreeInt.h
已删除
100644 → 0
浏览文件 @
031d84e7
此差异已折叠。
点击以展开。
source/libs/tdb/src/sqliteinc/pager.h
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
*/
#ifndef SQLITE_PAGER_H
#define SQLITE_PAGER_H
/*
** Default maximum size for persistent journal files. A negative
** value means no limit. This value may be overridden using the
** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
*/
#ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
#define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
#endif
/*
** The type used to represent a page number. The first page in a file
** is called page 1. 0 is used to represent "not a page".
*/
typedef
u32
Pgno
;
/*
** Each open file is managed by a separate instance of the "Pager" structure.
*/
typedef
struct
Pager
Pager
;
/*
** Handle type for pages.
*/
typedef
struct
PgHdr
DbPage
;
// /*
// ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
// ** reserved for working around a windows/posix incompatibility). It is
// ** used in the journal to signify that the remainder of the journal file
// ** is devoted to storing a super-journal name - there are no more pages to
// ** roll back. See comments for function writeSuperJournal() in pager.c
// ** for details.
// */
// #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
/*
** Allowed values for the flags parameter to sqlite3PagerOpen().
**
** NOTE: These values must match the corresponding BTREE_ values in btree.h.
*/
#define PAGER_OMIT_JOURNAL 0x0001
/* Do not use a rollback journal */
#define PAGER_MEMORY 0x0002
/* In-memory database */
/*
** Valid values for the second argument to sqlite3PagerLockingMode().
*/
#define PAGER_LOCKINGMODE_QUERY -1
#define PAGER_LOCKINGMODE_NORMAL 0
#define PAGER_LOCKINGMODE_EXCLUSIVE 1
/*
** Numeric constants that encode the journalmode.
**
** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
** are exposed in the API via the "PRAGMA journal_mode" command and
** therefore cannot be changed without a compatibility break.
*/
#define PAGER_JOURNALMODE_QUERY (-1)
/* Query the value of journalmode */
#define PAGER_JOURNALMODE_DELETE 0
/* Commit by deleting journal file */
#define PAGER_JOURNALMODE_PERSIST 1
/* Commit by zeroing journal header */
#define PAGER_JOURNALMODE_OFF 2
/* Journal omitted. */
#define PAGER_JOURNALMODE_TRUNCATE 3
/* Commit by truncating journal */
#define PAGER_JOURNALMODE_MEMORY 4
/* In-memory journal file */
#define PAGER_JOURNALMODE_WAL 5
/* Use write-ahead logging */
/*
** Flags that make up the mask passed to sqlite3PagerGet().
*/
#define PAGER_GET_NOCONTENT 0x01
/* Do not load data from disk */
#define PAGER_GET_READONLY 0x02
/* Read-only page is acceptable */
/*
** Flags for sqlite3PagerSetFlags()
**
** Value constraints (enforced via assert()):
** PAGER_FULLFSYNC == SQLITE_FullFSync
** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
** PAGER_CACHE_SPILL == SQLITE_CacheSpill
*/
#define PAGER_SYNCHRONOUS_OFF 0x01
/* PRAGMA synchronous=OFF */
#define PAGER_SYNCHRONOUS_NORMAL 0x02
/* PRAGMA synchronous=NORMAL */
#define PAGER_SYNCHRONOUS_FULL 0x03
/* PRAGMA synchronous=FULL */
#define PAGER_SYNCHRONOUS_EXTRA 0x04
/* PRAGMA synchronous=EXTRA */
#define PAGER_SYNCHRONOUS_MASK 0x07
/* Mask for four values above */
#define PAGER_FULLFSYNC 0x08
/* PRAGMA fullfsync=ON */
#define PAGER_CKPT_FULLFSYNC 0x10
/* PRAGMA checkpoint_fullfsync=ON */
#define PAGER_CACHESPILL 0x20
/* PRAGMA cache_spill=ON */
#define PAGER_FLAGS_MASK 0x38
/* All above except SYNCHRONOUS */
/*
** The remainder of this file contains the declarations of the functions
** that make up the Pager sub-system API. See source code comments for
** a detailed description of each routine.
*/
/* Open and close a Pager connection. */
int
sqlite3PagerOpen
(
Pager
**
ppPager
,
const
char
*
,
int
,
int
,
int
,
void
(
*
)(
DbPage
*
)
);
int
sqlite3PagerClose
(
Pager
*
pPager
,
sqlite3
*
);
// int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
// /* Functions used to configure a Pager object. */
// void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *);
// int sqlite3PagerSetPagesize(Pager*, u32*, int);
// Pgno sqlite3PagerMaxPageCount(Pager*, Pgno);
// void sqlite3PagerSetCachesize(Pager*, int);
// int sqlite3PagerSetSpillsize(Pager*, int);
// void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
// void sqlite3PagerShrink(Pager*);
// void sqlite3PagerSetFlags(Pager*,unsigned);
// int sqlite3PagerLockingMode(Pager *, int);
// int sqlite3PagerSetJournalMode(Pager *, int);
// int sqlite3PagerGetJournalMode(Pager*);
// int sqlite3PagerOkToChangeJournalMode(Pager*);
// i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
// sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
// int sqlite3PagerFlush(Pager*);
// /* Functions used to obtain and release page references. */
// int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
// DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
// void sqlite3PagerRef(DbPage*);
// void sqlite3PagerUnref(DbPage*);
// void sqlite3PagerUnrefNotNull(DbPage*);
// void sqlite3PagerUnrefPageOne(DbPage*);
// /* Operations on page references. */
// int sqlite3PagerWrite(DbPage*);
// void sqlite3PagerDontWrite(DbPage*);
// int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
// int sqlite3PagerPageRefcount(DbPage*);
// void *sqlite3PagerGetData(DbPage *);
// void *sqlite3PagerGetExtra(DbPage *);
// /* Functions used to manage pager transactions and savepoints. */
// void sqlite3PagerPagecount(Pager*, int*);
// int sqlite3PagerBegin(Pager*, int exFlag, int);
// int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
// int sqlite3PagerExclusiveLock(Pager*);
// int sqlite3PagerSync(Pager *pPager, const char *zSuper);
// int sqlite3PagerCommitPhaseTwo(Pager*);
// int sqlite3PagerRollback(Pager*);
// int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
// int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
// int sqlite3PagerSharedLock(Pager *pPager);
// #ifndef SQLITE_OMIT_WAL
// int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
// int sqlite3PagerWalSupported(Pager *pPager);
// int sqlite3PagerWalCallback(Pager *pPager);
// int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
// int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
// # ifdef SQLITE_ENABLE_SNAPSHOT
// int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot);
// int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot);
// int sqlite3PagerSnapshotRecover(Pager *pPager);
// int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
// void sqlite3PagerSnapshotUnlock(Pager *pPager);
// # endif
// #endif
// #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT)
// int sqlite3PagerWalWriteLock(Pager*, int);
// void sqlite3PagerWalDb(Pager*, sqlite3*);
// #else
// # define sqlite3PagerWalWriteLock(y,z) SQLITE_OK
// # define sqlite3PagerWalDb(x,y)
// #endif
// #ifdef SQLITE_DIRECT_OVERFLOW_READ
// int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
// #endif
// #ifdef SQLITE_ENABLE_ZIPVFS
// int sqlite3PagerWalFramesize(Pager *pPager);
// #endif
// /* Functions used to query pager state and configuration. */
// u8 sqlite3PagerIsreadonly(Pager*);
// u32 sqlite3PagerDataVersion(Pager*);
// #ifdef SQLITE_DEBUG
// int sqlite3PagerRefcount(Pager*);
// #endif
// int sqlite3PagerMemUsed(Pager*);
// const char *sqlite3PagerFilename(const Pager*, int);
// sqlite3_vfs *sqlite3PagerVfs(Pager*);
// sqlite3_file *sqlite3PagerFile(Pager*);
// sqlite3_file *sqlite3PagerJrnlFile(Pager*);
// const char *sqlite3PagerJournalname(Pager*);
// void *sqlite3PagerTempSpace(Pager*);
// int sqlite3PagerIsMemdb(Pager*);
// void sqlite3PagerCacheStat(Pager *, int, int, int *);
// void sqlite3PagerClearCache(Pager*);
// int sqlite3SectorSize(sqlite3_file *);
// /* Functions used to truncate the database file. */
// void sqlite3PagerTruncateImage(Pager*,Pgno);
// void sqlite3PagerRekey(DbPage*, Pgno, u16);
// /* Functions to support testing and debugging. */
// #if !defined(NDEBUG) || defined(SQLITE_TEST)
// Pgno sqlite3PagerPagenumber(DbPage*);
// int sqlite3PagerIswriteable(DbPage*);
// #endif
// #ifdef SQLITE_TEST
// int *sqlite3PagerStats(Pager*);
// void sqlite3PagerRefdump(Pager*);
// void disable_simulated_io_errors(void);
// void enable_simulated_io_errors(void);
// #else
// # define disable_simulated_io_errors()
// # define enable_simulated_io_errors()
// #endif
#endif
/* SQLITE_PAGER_H */
source/libs/tdb/src/sqliteinc/pcache.h
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2008 August 05
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem.
*/
#ifndef _PCACHE_H_
typedef
struct
PgHdr
PgHdr
;
typedef
struct
PCache
PCache
;
/*
** Every page in the cache is controlled by an instance of the following
** structure.
*/
struct
PgHdr
{
sqlite3_pcache_page
*
pPage
;
/* Pcache object page handle */
void
*
pData
;
/* Page data */
void
*
pExtra
;
/* Extra content */
PCache
*
pCache
;
/* PRIVATE: Cache that owns this page */
PgHdr
*
pDirty
;
/* Transient list of dirty sorted by pgno */
Pager
*
pPager
;
/* The pager this page is part of */
Pgno
pgno
;
/* Page number for this page */
#ifdef SQLITE_CHECK_PAGES
u32
pageHash
;
/* Hash of page content */
#endif
u16
flags
;
/* PGHDR flags defined below */
/**********************************************************************
** Elements above, except pCache, are public. All that follow are
** private to pcache.c and should not be accessed by other modules.
** pCache is grouped with the public elements for efficiency.
*/
i16
nRef
;
/* Number of users of this page */
PgHdr
*
pDirtyNext
;
/* Next element in list of dirty pages */
PgHdr
*
pDirtyPrev
;
/* Previous element in list of dirty pages */
/* NB: pDirtyNext and pDirtyPrev are undefined if the
** PgHdr object is not dirty */
};
/* Bit values for PgHdr.flags */
#define PGHDR_CLEAN 0x001
/* Page not on the PCache.pDirty list */
#define PGHDR_DIRTY 0x002
/* Page is on the PCache.pDirty list */
#define PGHDR_WRITEABLE 0x004
/* Journaled and ready to modify */
#define PGHDR_NEED_SYNC \
0x008
/* Fsync the rollback journal before \
** writing this page to the database */
#define PGHDR_DONT_WRITE 0x010
/* Do not write content to disk */
#define PGHDR_MMAP 0x020
/* This is an mmap page object */
#define PGHDR_WAL_APPEND 0x040
/* Appended to wal file */
/* Initialize and shutdown the page cache subsystem */
int
sqlite3PcacheInitialize
(
void
);
void
sqlite3PcacheShutdown
(
void
);
/* Page cache buffer management:
** These routines implement SQLITE_CONFIG_PAGECACHE.
*/
void
sqlite3PCacheBufferSetup
(
void
*
,
int
sz
,
int
n
);
/* Create a new pager cache.
** Under memory stress, invoke xStress to try to make pages clean.
** Only clean and unpinned pages can be reclaimed.
*/
int
sqlite3PcacheOpen
(
int
szPage
,
/* Size of every page */
int
szExtra
,
/* Extra space associated with each page */
int
bPurgeable
,
/* True if pages are on backing store */
int
(
*
xStress
)(
void
*
,
PgHdr
*
),
/* Call to try to make pages clean */
void
*
pStress
,
/* Argument to xStress */
PCache
*
pToInit
/* Preallocated space for the PCache */
);
/* Modify the page-size after the cache has been created. */
int
sqlite3PcacheSetPageSize
(
PCache
*
,
int
);
/* Return the size in bytes of a PCache object. Used to preallocate
** storage space.
*/
int
sqlite3PcacheSize
(
void
);
/* One release per successful fetch. Page is pinned until released.
** Reference counted.
*/
sqlite3_pcache_page
*
sqlite3PcacheFetch
(
PCache
*
,
Pgno
,
int
createFlag
);
int
sqlite3PcacheFetchStress
(
PCache
*
,
Pgno
,
sqlite3_pcache_page
**
);
PgHdr
*
sqlite3PcacheFetchFinish
(
PCache
*
,
Pgno
,
sqlite3_pcache_page
*
pPage
);
void
sqlite3PcacheRelease
(
PgHdr
*
);
void
sqlite3PcacheDrop
(
PgHdr
*
);
/* Remove page from cache */
void
sqlite3PcacheMakeDirty
(
PgHdr
*
);
/* Make sure page is marked dirty */
void
sqlite3PcacheMakeClean
(
PgHdr
*
);
/* Mark a single page as clean */
void
sqlite3PcacheCleanAll
(
PCache
*
);
/* Mark all dirty list pages as clean */
void
sqlite3PcacheClearWritable
(
PCache
*
);
/* Change a page number. Used by incr-vacuum. */
void
sqlite3PcacheMove
(
PgHdr
*
,
Pgno
);
/* Remove all pages with pgno>x. Reset the cache if x==0 */
void
sqlite3PcacheTruncate
(
PCache
*
,
Pgno
x
);
/* Get a list of all dirty pages in the cache, sorted by page number */
PgHdr
*
sqlite3PcacheDirtyList
(
PCache
*
);
/* Reset and close the cache object */
void
sqlite3PcacheClose
(
PCache
*
);
/* Clear flags from pages of the page cache */
void
sqlite3PcacheClearSyncFlags
(
PCache
*
);
/* Discard the contents of the cache */
void
sqlite3PcacheClear
(
PCache
*
);
/* Return the total number of outstanding page references */
int
sqlite3PcacheRefCount
(
PCache
*
);
/* Increment the reference count of an existing page */
void
sqlite3PcacheRef
(
PgHdr
*
);
int
sqlite3PcachePageRefcount
(
PgHdr
*
);
/* Return the total number of pages stored in the cache */
int
sqlite3PcachePagecount
(
PCache
*
);
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
/* Iterate through all dirty pages currently stored in the cache. This
** interface is only available if SQLITE_CHECK_PAGES is defined when the
** library is built.
*/
void
sqlite3PcacheIterateDirty
(
PCache
*
pCache
,
void
(
*
xIter
)(
PgHdr
*
));
#endif
#if defined(SQLITE_DEBUG)
/* Check invariants on a PgHdr object */
int
sqlite3PcachePageSanity
(
PgHdr
*
);
#endif
/* Set and get the suggested cache-size for the specified pager-cache.
**
** If no global maximum is configured, then the system attempts to limit
** the total number of pages cached by purgeable pager-caches to the sum
** of the suggested cache-sizes.
*/
void
sqlite3PcacheSetCachesize
(
PCache
*
,
int
);
#ifdef SQLITE_TEST
int
sqlite3PcacheGetCachesize
(
PCache
*
);
#endif
/* Set or get the suggested spill-size for the specified pager-cache.
**
** The spill-size is the minimum number of pages in cache before the cache
** will attempt to spill dirty pages by calling xStress.
*/
int
sqlite3PcacheSetSpillsize
(
PCache
*
,
int
);
/* Free up as much memory as possible from the page cache */
void
sqlite3PcacheShrink
(
PCache
*
);
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
/* Try to return memory used by the pcache module to the main memory heap */
int
sqlite3PcacheReleaseMemory
(
int
);
#endif
#ifdef SQLITE_TEST
void
sqlite3PcacheStats
(
int
*
,
int
*
,
int
*
,
int
*
);
#endif
void
sqlite3PCacheSetDefault
(
void
);
/* Return the header size */
int
sqlite3HeaderSizePcache
(
void
);
int
sqlite3HeaderSizePcache1
(
void
);
/* Number of dirty pages as a percentage of the configured cache size */
int
sqlite3PCachePercentDirty
(
PCache
*
);
#ifdef SQLITE_DIRECT_OVERFLOW_READ
int
sqlite3PCacheIsDirty
(
PCache
*
pCache
);
#endif
// For real implementation of sqlite3_pcache ========================================
typedef
struct
sqlite3_pcache
sqlite3_pcache
;
typedef
struct
sqlite3_pcache_methods2
{
int
iVersion
;
void
*
pArg
;
int
(
*
xInit
)(
void
*
);
void
(
*
xShutdown
)(
void
*
);
sqlite3_pcache
*
(
*
xCreate
)(
int
szPage
,
int
szExtra
,
int
bPurgeable
);
void
(
*
xCachesize
)(
sqlite3_pcache
*
,
int
nCachesize
);
int
(
*
xPagecount
)(
sqlite3_pcache
*
);
sqlite3_pcache_page
*
(
*
xFetch
)(
sqlite3_pcache
*
,
unsigned
key
,
int
createFlag
);
void
(
*
xUnpin
)(
sqlite3_pcache
*
,
sqlite3_pcache_page
*
,
int
discard
);
void
(
*
xRekey
)(
sqlite3_pcache
*
,
sqlite3_pcache_page
*
,
unsigned
oldKey
,
unsigned
newKey
);
void
(
*
xTruncate
)(
sqlite3_pcache
*
,
unsigned
iLimit
);
void
(
*
xDestroy
)(
sqlite3_pcache
*
);
void
(
*
xShrink
)(
sqlite3_pcache
*
);
}
sqlite3_pcache_methods2
;
extern
sqlite3_pcache_methods2
pcache2
;
#endif
/* _PCACHE_H_ */
source/libs/tdb/src/sqliteinc/sqlite3.h
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2001-09-15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs. If a C-function, structure, datatype,
** or constant definition does not appear in this file, then it is
** not a published API of SQLite, is subject to change without
** notice, and should not be referenced by programs that use SQLite.
**
** Some of the definitions that are in this file are marked as
** "experimental". Experimental interfaces are normally new
** features recently added to SQLite. We do not anticipate changes
** to experimental interfaces but reserve the right to make minor changes
** if experience from use "in the wild" suggest such changes are prudent.
**
** The official C-language API documentation for SQLite is derived
** from comments in this file. This file is the authoritative source
** on how SQLite interfaces are supposed to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
*/
#ifndef SQLITE3_H
#define SQLITE3_H
#include <stdarg.h>
/* Needed for the definition of va_list */
/*
** Make sure we can call this stuff from C++.
*/
#ifdef __cplusplus
extern
"C"
{
#endif
/*
** CAPI3REF: Result Codes
** KEYWORDS: {result code definitions}
**
** Many SQLite functions return an integer result code from the set shown
** here in order to indicate success or failure.
**
** New error codes may be added in future versions of SQLite.
**
** See also: [extended result code definitions]
*/
#define SQLITE_OK 0
/* Successful result */
/* beginning-of-error-codes */
#define SQLITE_ERROR 1
/* Generic error */
#define SQLITE_INTERNAL 2
/* Internal logic error in SQLite */
#define SQLITE_PERM 3
/* Access permission denied */
#define SQLITE_ABORT 4
/* Callback routine requested an abort */
#define SQLITE_BUSY 5
/* The database file is locked */
#define SQLITE_LOCKED 6
/* A table in the database is locked */
#define SQLITE_NOMEM 7
/* A malloc() failed */
#define SQLITE_READONLY 8
/* Attempt to write a readonly database */
#define SQLITE_INTERRUPT 9
/* Operation terminated by sqlite3_interrupt()*/
#define SQLITE_IOERR 10
/* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT 11
/* The database disk image is malformed */
#define SQLITE_NOTFOUND 12
/* Unknown opcode in sqlite3_file_control() */
#define SQLITE_FULL 13
/* Insertion failed because database is full */
#define SQLITE_CANTOPEN 14
/* Unable to open the database file */
#define SQLITE_PROTOCOL 15
/* Database lock protocol error */
#define SQLITE_EMPTY 16
/* Internal use only */
#define SQLITE_SCHEMA 17
/* The database schema changed */
#define SQLITE_TOOBIG 18
/* String or BLOB exceeds size limit */
#define SQLITE_CONSTRAINT 19
/* Abort due to constraint violation */
#define SQLITE_MISMATCH 20
/* Data type mismatch */
#define SQLITE_MISUSE 21
/* Library used incorrectly */
#define SQLITE_NOLFS 22
/* Uses OS features not supported on host */
#define SQLITE_AUTH 23
/* Authorization denied */
#define SQLITE_FORMAT 24
/* Not used */
#define SQLITE_RANGE 25
/* 2nd parameter to sqlite3_bind out of range */
#define SQLITE_NOTADB 26
/* File opened that is not a database file */
#define SQLITE_NOTICE 27
/* Notifications from sqlite3_log() */
#define SQLITE_WARNING 28
/* Warnings from sqlite3_log() */
#define SQLITE_ROW 100
/* sqlite3_step() has another row ready */
#define SQLITE_DONE 101
/* sqlite3_step() has finished executing */
/* end-of-error-codes */
#ifdef __cplusplus
}
/* end of the 'extern "C"' block */
#endif
#endif
/* _FTS5_H */
/******** End of fts5.h *********/
source/libs/tdb/src/sqliteinc/sqliteInt.h
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
*/
#include <assert.h>
#include <fcntl.h>
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef SQLITEINT_H
#define SQLITEINT_H
#include "sqlite3.h"
typedef
int8_t
i8
;
typedef
int16_t
i16
;
typedef
int32_t
i32
;
typedef
int64_t
i64
;
typedef
uint8_t
u8
;
typedef
uint16_t
u16
;
typedef
uint32_t
u32
;
typedef
uint64_t
u64
;
typedef
struct
sqlite3_pcache_page
{
void
*
pBuf
;
/* The content of the page */
void
*
pExtra
;
/* Extra information associated with the page */
}
sqlite3_pcache_page
;
#define ROUNDDOWN8(x) ((x) & ~7)
#define ROUND8(x) (((x) + 7) & ~7)
typedef
struct
sqlite3_vfs
sqlite3_vfs
;
typedef
struct
sqlite3
sqlite3
;
#define SQLITE_DEFAULT_PAGE_SIZE 4096
#include "pager.h"
#include "pcache.h"
#endif
/* SQLITEINT_H */
source/libs/tdb/src/sqliteinc/wal.h
已删除
100644 → 0
浏览文件 @
031d84e7
/*
** 2010 February 1
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface to the write-ahead logging
** system. Refer to the comments below and the header comment attached to
** the implementation of each function in log.c for further details.
*/
#ifndef SQLITE_WAL_H
#define SQLITE_WAL_H
#include "sqliteInt.h"
/* Macros for extracting appropriate sync flags for either transaction
** commits (WAL_SYNC_FLAGS(X)) or for checkpoint ops (CKPT_SYNC_FLAGS(X)):
*/
#define WAL_SYNC_FLAGS(X) ((X)&0x03)
#define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03)
#ifdef SQLITE_OMIT_WAL
# define sqlite3WalOpen(x,y,z) 0
# define sqlite3WalLimit(x,y)
# define sqlite3WalClose(v,w,x,y,z) 0
# define sqlite3WalBeginReadTransaction(y,z) 0
# define sqlite3WalEndReadTransaction(z)
# define sqlite3WalDbsize(y) 0
# define sqlite3WalBeginWriteTransaction(y) 0
# define sqlite3WalEndWriteTransaction(x) 0
# define sqlite3WalUndo(x,y,z) 0
# define sqlite3WalSavepoint(y,z)
# define sqlite3WalSavepointUndo(y,z) 0
# define sqlite3WalFrames(u,v,w,x,y,z) 0
# define sqlite3WalCheckpoint(q,r,s,t,u,v,w,x,y,z) 0
# define sqlite3WalCallback(z) 0
# define sqlite3WalExclusiveMode(y,z) 0
# define sqlite3WalHeapMemory(z) 0
# define sqlite3WalFramesize(z) 0
# define sqlite3WalFindFrame(x,y,z) 0
# define sqlite3WalFile(x) 0
#else
#define WAL_SAVEPOINT_NDATA 4
/* Connection to a write-ahead log (WAL) file.
** There is one object of this type for each pager.
*/
typedef
struct
Wal
Wal
;
/* Open and close a connection to a write-ahead log. */
int
sqlite3WalOpen
(
sqlite3_vfs
*
,
sqlite3_file
*
,
const
char
*
,
int
,
i64
,
Wal
**
);
int
sqlite3WalClose
(
Wal
*
pWal
,
sqlite3
*
,
int
sync_flags
,
int
,
u8
*
);
/* Set the limiting size of a WAL file. */
void
sqlite3WalLimit
(
Wal
*
,
i64
);
/* Used by readers to open (lock) and close (unlock) a snapshot. A
** snapshot is like a read-transaction. It is the state of the database
** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
** preserves the current state even if the other threads or processes
** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
** transaction and releases the lock.
*/
int
sqlite3WalBeginReadTransaction
(
Wal
*
pWal
,
int
*
);
void
sqlite3WalEndReadTransaction
(
Wal
*
pWal
);
/* Read a page from the write-ahead log, if it is present. */
int
sqlite3WalFindFrame
(
Wal
*
,
Pgno
,
u32
*
);
int
sqlite3WalReadFrame
(
Wal
*
,
u32
,
int
,
u8
*
);
/* If the WAL is not empty, return the size of the database. */
Pgno
sqlite3WalDbsize
(
Wal
*
pWal
);
/* Obtain or release the WRITER lock. */
int
sqlite3WalBeginWriteTransaction
(
Wal
*
pWal
);
int
sqlite3WalEndWriteTransaction
(
Wal
*
pWal
);
/* Undo any frames written (but not committed) to the log */
int
sqlite3WalUndo
(
Wal
*
pWal
,
int
(
*
xUndo
)(
void
*
,
Pgno
),
void
*
pUndoCtx
);
/* Return an integer that records the current (uncommitted) write
** position in the WAL */
void
sqlite3WalSavepoint
(
Wal
*
pWal
,
u32
*
aWalData
);
/* Move the write position of the WAL back to iFrame. Called in
** response to a ROLLBACK TO command. */
int
sqlite3WalSavepointUndo
(
Wal
*
pWal
,
u32
*
aWalData
);
/* Write a frame or frames to the log. */
int
sqlite3WalFrames
(
Wal
*
pWal
,
int
,
PgHdr
*
,
Pgno
,
int
,
int
);
/* Copy pages from the log to the database file */
int
sqlite3WalCheckpoint
(
Wal
*
pWal
,
/* Write-ahead log connection */
sqlite3
*
db
,
/* Check this handle's interrupt flag */
int
eMode
,
/* One of PASSIVE, FULL and RESTART */
int
(
*
xBusy
)(
void
*
),
/* Function to call when busy */
void
*
pBusyArg
,
/* Context argument for xBusyHandler */
int
sync_flags
,
/* Flags to sync db file with (or 0) */
int
nBuf
,
/* Size of buffer nBuf */
u8
*
zBuf
,
/* Temporary buffer to use */
int
*
pnLog
,
/* OUT: Number of frames in WAL */
int
*
pnCkpt
/* OUT: Number of backfilled frames in WAL */
);
/* Return the value to pass to a sqlite3_wal_hook callback, the
** number of frames in the WAL at the point of the last commit since
** sqlite3WalCallback() was called. If no commits have occurred since
** the last call, then return 0.
*/
int
sqlite3WalCallback
(
Wal
*
pWal
);
/* Tell the wal layer that an EXCLUSIVE lock has been obtained (or released)
** by the pager layer on the database file.
*/
int
sqlite3WalExclusiveMode
(
Wal
*
pWal
,
int
op
);
/* Return true if the argument is non-NULL and the WAL module is using
** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
** WAL module is using shared-memory, return false.
*/
int
sqlite3WalHeapMemory
(
Wal
*
pWal
);
#ifdef SQLITE_ENABLE_SNAPSHOT
int
sqlite3WalSnapshotGet
(
Wal
*
pWal
,
sqlite3_snapshot
**
ppSnapshot
);
void
sqlite3WalSnapshotOpen
(
Wal
*
pWal
,
sqlite3_snapshot
*
pSnapshot
);
int
sqlite3WalSnapshotRecover
(
Wal
*
pWal
);
int
sqlite3WalSnapshotCheck
(
Wal
*
pWal
,
sqlite3_snapshot
*
pSnapshot
);
void
sqlite3WalSnapshotUnlock
(
Wal
*
pWal
);
#endif
#ifdef SQLITE_ENABLE_ZIPVFS
/* If the WAL file is not empty, return the number of bytes of content
** stored in each frame (i.e. the db page-size when the WAL was created).
*/
int
sqlite3WalFramesize
(
Wal
*
pWal
);
#endif
/* Return the sqlite3_file object for the WAL file */
sqlite3_file
*
sqlite3WalFile
(
Wal
*
pWal
);
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
int
sqlite3WalWriteLock
(
Wal
*
pWal
,
int
bLock
);
void
sqlite3WalDb
(
Wal
*
pWal
,
sqlite3
*
db
);
#endif
#endif
/* ifndef SQLITE_OMIT_WAL */
#endif
/* SQLITE_WAL_H */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录