Compare commits

...

213 Commits

Author SHA1 Message Date
drh dcc3f4b078 Disable compiler intrinsics when using the Intel C Compiler.
FossilOrigin-Name: dbb59f6156625a455057467095e3c6d7ce021b9a447eab1c4ddebe1843796624
2017-07-08 18:27:55 +00:00
drh 12ca0fc259 Basic test cases for PRAGMA secure_delete=FAST.
FossilOrigin-Name: 0c246017b45c5290f3a7932dfce649f1a6d8f9afc00c6c3edf2ef06c17dbca1d
2017-07-07 22:47:32 +00:00
mistachkin 50963c9da8 Fix comment in the Win32 VFS for lsm1.
FossilOrigin-Name: 12a421bcacf72128426eeafed8663accd8f2ac7edb46f620b60b8239065e657e
2017-07-07 21:20:26 +00:00
mistachkin 85bd1cd52b For lsmtest, use a more portable means of setting open() files to binary.
FossilOrigin-Name: aea6e0ffd33f41482f1b53b9f21b77add2865abda4eec1d9ee197177f74f43d0
2017-07-07 21:15:24 +00:00
mistachkin 1d91e9f26a Adjust copy_file() lsmtest function so it works properly for locked database files on Win32.
FossilOrigin-Name: 54a3855583deac93c955ed77fe82be6a6b7aadd3fdb7e6b895888e2a4ff530bd
2017-07-07 20:35:14 +00:00
drh 08f1efeb16 Add the "PRAGMA secure_delete=FAST" option, which overwrites most deleted
content without increasing the amount of I/O.  Deleted content might persist
on the free page list, however.  And extra CPU cycles are used for zeroing,
of course.

FossilOrigin-Name: 38978ce65b280bb7cba3fc08ba91485fb1b84cd9fbba2e950ecf41c021ff452a
2017-07-07 20:06:28 +00:00
drh a690ff360b Change the error message text for SQLITE_ERROR to omit the part about
"missing database" as that meaning is now obsolete (since approx SQLite 2.0).

FossilOrigin-Name: 732f90d6327c5c6368fc8b4cc207bd644ef08e3ae6d2e7295258ab099deaba63
2017-07-07 19:43:23 +00:00
mistachkin b11c650c01 Fix typos in Win32 VFS for lsm1.
FossilOrigin-Name: 0961ec873b78ad2da0ea9cdf2934bc8f08276375a153fe5d9fa8d4280328deef
2017-07-07 19:22:35 +00:00
mistachkin 73518c5876 Fix the memcpy calls in the lsmWin32OsShmMap function for lsm1.
FossilOrigin-Name: aa4890b9f9e9698c61d6ca0e24c26280f5e0a87a8c02865933ad483a1fd44d84
2017-07-07 19:12:55 +00:00
mistachkin a2d85cbbfa Enhance the MSVC makefile 'clean' target to handle lsm1.
FossilOrigin-Name: 2d6faebc319aefeab796c5f2ead4c3c3e2a9dd25c979a16bdb555a109135b13c
2017-07-07 19:02:51 +00:00
mistachkin 9a7a77ad36 Add support for LSM_DEBUG to the MSVC makefile for lsm1.
FossilOrigin-Name: 277a7fedafbe5b43d44086f3cb73e952873913bdc4b51041f45b6571b386d7d9
2017-07-07 18:31:51 +00:00
drh a7a0bfab91 In the command-line shell, when running ".schema" give a sensible error when
the database file is locked.

FossilOrigin-Name: cc329eb8d65171f3f4fcb39b0e55ef85c97a77f3510cf864bbc1537f993d0074
2017-07-07 18:06:49 +00:00
mistachkin 9b8c5f6819 Fix the usleep() macro in the Win32 test code for lsm1.
FossilOrigin-Name: 63599fa524a7c72ffa5362041f2ec394d9af9c43025d8b6d5a34e98eb423d5ff
2017-07-07 17:57:21 +00:00
drh d5eae667f4 Add new PRAGMAs: "function_list", "module_list", and "pragma_list". All are
enclosed within #ifdef SQLITE_INTROSPECTION_PRAGMAS.  The compile-time option
is not on ctime.c yet, since these are still experimental and one can always
test "PRAGMA pragma_list" and see whether or not it returns an empty set.

FossilOrigin-Name: e0b6ae92adfae46f64fc2e2719e22e5467c34d49c1aeaec5cc5faf04258de0f7
2017-07-07 17:43:30 +00:00
drh 8ae11aac93 Add the "Pragma_list" pragma. Put all three pragmas created on this branch
inside of #ifdef SQLITE_INTROSPECTION_PRAGMAS.

FossilOrigin-Name: 2f3c3781ef3d66ecafef083d7144287ff23eea5a6d93b014dfeb2a8ac71f757e
2017-07-07 17:33:07 +00:00
mistachkin e60092b90c Improve clarity in the Win32 VFS for lsm1.
FossilOrigin-Name: 9c7a9e805d95d3d4a3f7e2d608280b7ca0dda01114e32cd366b1deb14e6e6839
2017-07-07 16:46:08 +00:00
mistachkin baebf3cc4b Add support for LSM_DEBUG_MEM to the MSVC makefile for lsm1.
FossilOrigin-Name: 3340de83df8c4fb19f729e6ff0838a9a03a1e701cdb40cb830e76f294198024a
2017-07-07 16:29:37 +00:00
dan 45158fa5d9 Remove a block from the Win32 VFS for lsm1 that is now superfluous.
FossilOrigin-Name: 5f726f2830dcf91f5e5c010b10761757f746d39b9dd2b8c9770452ce65bb1652
2017-07-07 16:27:43 +00:00
dan 3bc909b0af In lsmtest, use an empty string instead of ":memory:" when requesting a
temporary database from SQLite. This prevents other test code from trying to
unlink() ":memory:", which fails on win32.

FossilOrigin-Name: 281ad505d7a112c5524ea9fb195dfc46f819a58f79f42b37b12fbfe46a089ff2
2017-07-07 16:09:24 +00:00
mistachkin 5bd9e61f05 Remove a block from the Win32 VFS for lsm1 that is now superfluous.
FossilOrigin-Name: db4a41408eff450ee429b936847313c2c92ba1f5b1fcbadaacaff3c08bfdd589
2017-07-07 16:07:53 +00:00
mistachkin d429ec222c Memory reallocation fix for the Win32 VFS for lsm1.
FossilOrigin-Name: 5a3140e4dedace6de4366a3c52e41b818b6d19f356fdab738c6605afc1b674fa
2017-07-07 16:06:30 +00:00
drh 40cf27cb63 Enhance the sqlite3VdbeMultiLoad() interface to automatically generate the
OP_ResultRow opcode on PRAGMA implementations, for a small reduction in the
library footprint.

FossilOrigin-Name: c46f0f076c674891e20240bad56693d891aedc43004bcf980a5d199515f23413
2017-07-07 16:00:53 +00:00
drh ab53bb635c Add new pragmas: "function_list" and "module_list"
FossilOrigin-Name: e5f01d7fde05fdb547f35816ff15c31a92c170b31877f4c640b7bc2be3f580b3
2017-07-07 15:43:22 +00:00
drh d10866798d Exploit the fact that Expr.pRight and Expr.x are never used at the same time
for a small performance gain.

FossilOrigin-Name: aacbb9a461fdb34c7f9c8ce348e44c3e96c93334f210d438d92bfac1794dc686
2017-07-07 13:59:34 +00:00
drh c2d14a9a33 More efficient and compact implementation of walkExpr().
FossilOrigin-Name: 115d4b83392d346634866dd959bef30fca50db2e526df17eaeb3d94da7fc895e
2017-07-07 12:58:30 +00:00
drh b98a2e351e More aggressive use of EP_Leaf on expression nodes, to help prune searches.
FossilOrigin-Name: c1a1d68c8219c8072e60af5c46a30849ae9a04fa1a6b2a8b22b82fec069d691d
2017-07-07 12:43:57 +00:00
drh 3da70a6112 Very slightly smaller and faster sqlite3WalkSelect().
FossilOrigin-Name: 9bc65635b29a4991c7821ef0939975d007f9ac23716717699353ef3246e27791
2017-07-07 11:49:48 +00:00
drh 0db5bfe5de Small adjustment to main.mk that facilitates giving non-standard compile-time
options to the shell.

FossilOrigin-Name: 7c7d53a9bbc27fde2dcc028cb7765c76cad0a784e53095b652c90d371968c53d
2017-07-06 22:43:41 +00:00
drh a0c3927510 Change the (machine-generated) keywordhash.h file to increase the scope of the
tables used for keyword matching, so that the tables are accessible to
functions other then keywordCode().

FossilOrigin-Name: c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d
2017-07-06 16:33:14 +00:00
drh 9d8e401c2d More compact implementation of the typeof() SQL function.
FossilOrigin-Name: efb4aab0caa4145732a5438cc2a193bc12c455b4007220564d240e75900ea8ad
2017-07-06 13:51:50 +00:00
drh ebaaa67db2 Avoid unnecessary upper-to-lower case conversion for function names when
registering the built-in functions.

FossilOrigin-Name: 06269257647db51fbc9f8cda88abac5db28b6f917a509768af7686dfa2b94511
2017-07-06 13:23:26 +00:00
drh 3b02e0f615 Small size reduction in findCollSeqEntry().
FossilOrigin-Name: 55ecd30304517acd23f89b3450fd6a5e18ac2f79aa24a4ff693f8d71a49f7837
2017-07-06 03:06:20 +00:00
drh 666e86625c Avoid unnecessary calls to sqlite3GetCollSeq() for a small performance gain.
FossilOrigin-Name: 503ba172e4c32e288abf006fc5cb53fd2b0313c4ee4c526c2d9c4c21b7178f2d
2017-07-06 02:49:26 +00:00
drh 07a3b11a50 Slightly more compact implementation of the byte-code generator for
the COMMIT and ROLLBACK commands.

FossilOrigin-Name: 4da663d9863004d8cef58259a043fdcf4f466f80d3714cf58321a52485be8766
2017-07-06 01:28:02 +00:00
drh 169a689f7b Small performance increase in sqlite3SrcListAppend().
FossilOrigin-Name: 7b2623f1994384484cf31ae9e443ee20f19b278bf2e91898dbc01828822ddf91
2017-07-06 01:02:09 +00:00
drh a35d851892 Make the hash table implementation a little smaller and faster.
FossilOrigin-Name: f762f1effe1ce893d6b67815ad8b585bae2c1621d9199dac9c85d39dad16e774
2017-07-05 23:33:33 +00:00
dan adea0d1c39 Have fts3 virtual table cursors free internal resources when they reach EOF,
instead of waiting until the xClose method is called.

FossilOrigin-Name: b6b14ab6c8f9758a64e5fd29203f8fa610b5c4ef917de9be51ae55e072fad4ed
2017-07-05 18:48:07 +00:00
dan 7181395a4d Fix a problem in lsmtest causing one test to fail for multi-threaded LSM
connections.

FossilOrigin-Name: 2bce64c8864b616f9ab0063f64d0ceb2f83e53e110970c6b3b11003cba5c8804
2017-07-05 14:29:04 +00:00
drh 269ba80469 Add the count-of-view optimization when compiled using
SQLITE_COUNTOFVIEW_OPTIMIZATION.

FossilOrigin-Name: d1ba200234f40b84327c7fc28c2584ed069da80e97578df71114d1a9ba9c559c
2017-07-04 19:34:36 +00:00
dan 431a53fde2 Fix further OOM handling cases in LSM.
FossilOrigin-Name: ca757c8665e27de884086b2aab2bd1db481e2d12f2afe136ec151bf5a0e65b91
2017-07-04 19:23:32 +00:00
dan 038af0bdc6 Fix a couple of problems in handling OOM conditions within LSM.
FossilOrigin-Name: 989a5c1745a7145c14c6d9b713176ecba6b99296de8bdd09f666eeef10da9c2e
2017-07-04 17:25:45 +00:00
drh 92395c59ff Fix a problem in the lempar.c Lemon template for YYSTACKDEPTH<=0 introduced
by check-in [36e54cd8b1fb37]

FossilOrigin-Name: 268a40f44cea6c3f561b7f54c90d631877be44292911424bac24f72c5ee87d60
2017-07-04 12:50:00 +00:00
drh 518ee8f06f Fix compiler warnings in LSM1, especially in the test logic.
FossilOrigin-Name: 9bd3be92b8add7bd0d7bc4b0742b2dd227ebb8d67a839b78f26f2b06b47490f2
2017-07-03 21:09:28 +00:00
dan 45408a108f Fix a bug in lsm queries on levels undergoing incremental an merge that
contain range-delete markers.

FossilOrigin-Name: b2c2487928becbea5a932895d153709c98a057a3c71c2600e165478562e9f7c5
2017-07-03 20:19:28 +00:00
drh cde336e0dc Attempt to improve documentation on sqlite3_column_ and sqlite3_value_
interfaces.

FossilOrigin-Name: 9111ac69bf307997e590bc9459222661fc79f549b3c493168a654a5046e6e4ad
2017-07-03 17:37:04 +00:00
dan 05dda7ba8e Add more tests for LSM log file recovery. Fix a problem in recovering log
files that contain range deletes.

FossilOrigin-Name: e34eafd4c5b2bbf2735e136ad69b67bb4288ad4d01a0128d8e107ac46209a182
2017-07-03 09:00:18 +00:00
dan 24f6904e99 Fix a memory management problem in lsm log recovery code.
FossilOrigin-Name: dd55af30b4440bba1b97c2155b9f499d791cd7d8bae8341972c41439fdc41edc
2017-07-01 20:59:06 +00:00
drh c7b1ee5f6e Enhance the RTree module to detect node truncation early and report an error.
FossilOrigin-Name: 66de6f4a9504ec2670b7273de8fb6955c80e03f7f73414ea6b80fd8a99f75976
2017-07-01 15:21:17 +00:00
drh fd76b71cac Improved documentation for sqlite3_value_type().
FossilOrigin-Name: 0db20efe201736b3ebb177948f6a440ce28e62454536a8496fae64a3b55cb702
2017-06-30 20:11:45 +00:00
mistachkin 04222ce52e Add some assert() statements in the Win32 interface for lsm1.
FossilOrigin-Name: d076d58ff108d286f7ac1f81e1ce945d6f4a4f5f97e3b8d5cee6f8d9a6c48d8f
2017-06-30 19:22:33 +00:00
mistachkin 88f769f967 Fix some minor typos in lsm1.
FossilOrigin-Name: 0ef777d7474383c0211b19baa4a161cf7fce6570f384dfef368cdab45c1a0f01
2017-06-30 18:12:09 +00:00
dan a5b55e370f Avoid constantly freeing and reallocing small internal buffers associated with
LSM cursors. Instead, allow them to persist for the lifetime of the cursor if
they are LSM_SEGMENTPTR_FREE_THRESHOLD (default 1024) bytes or smaller.

FossilOrigin-Name: bacfe8cb3e4d3be736c6789b2ce55ef5603e5c7a289b05b37cae2203cd7f2290
2017-06-30 11:44:11 +00:00
drh a501f7dab4 In the command-line shell, add the -quote option to start up in quote mode.
Enhance the ".mode" command so that it reports the current output mode if
given no arguments.

FossilOrigin-Name: 5e3f9ea5c4fad35fe02a12d59114e94ee00e0a09c1840c88908a4c282e2f4625
2017-06-29 21:33:25 +00:00
drh c31b79d2a4 Remove the ".explain" command from the ".help" output of the command-line
shell, though keep the implementation around for backwards compatibility.

FossilOrigin-Name: 7782c04e9b2c0e95b5ac2a38876c1a233becfd892140bc6844790d62aeaff4f7
2017-06-29 21:11:27 +00:00
drh e755072c3b Some simple tests for the STMT virtual table.
FossilOrigin-Name: a26e17ee56d3c019fc4772fcf95480b4515eea6cfc74c3d494be0d1941e49666
2017-06-29 20:31:01 +00:00
dan d681d3472d Avoid reading or writing the 32 locking bytes at the end of the first meta-page of an LSM database.
FossilOrigin-Name: 3ed6877f89106131fd030c183fac036fed7231cd92dc4715e87a34a045500bdf
2017-06-29 20:23:32 +00:00
dan 28508ddb42 Avoid reading or writing the 32 locking bytes at the end of the first
meta-page of an LSM database.

FossilOrigin-Name: 2b5df3e8a80ae5c0415081dd9b29acaad1464be2e7971399e52c1c98408322d9
2017-06-29 20:13:44 +00:00
mistachkin 97e8b3ea32 Fix issues in the POSIX and Win32 interfaces for lsm1.
FossilOrigin-Name: 38ec41416679e8280d77c8a4913aa6a321784b1237a3fe409b8e256c5f4513de
2017-06-29 19:08:52 +00:00
drh 1d1982c324 Edit comments in sqlite.h.in used for generating documentation, to improve
the description of the new sqlite3_prepare_v3() interfaces, and other
miscellaneous cleanup.  No changes to executable code.

FossilOrigin-Name: 284707a7b3514a55cce24292e45632b7033d6edcff5b27deac5118b27c7b2954
2017-06-29 17:27:04 +00:00
mistachkin de680efbc3 More updates to the Win32 interface for lsm1.
FossilOrigin-Name: cae647696769c9fcdc3beafdfdf74d8384217f4b22820e4545093bea7be58f7c
2017-06-29 16:51:52 +00:00
mistachkin c2586f77ad Correct typo in the Win32 interface for lsm1.
FossilOrigin-Name: 1b4facb1ad0085aa52e63d4d432179467ddc2a69b668d49d86e65ead66a73f57
2017-06-29 15:57:42 +00:00
drh 01e6d540a7 Add interfaces sqlite3_prepare_v3() and sqlite3_prepare16_v3() with the
extra prepFlags argument. Add the SQLITE_PREPARE_PERSISTENT option as 
one bit in that argument.  Use the new option in FTS3, FTS5, and RTREE.

FossilOrigin-Name: 03977248e6fdaa9b35c15e5dd9bb89552f2f0a913cc31609b5af1e2347b67d38
2017-06-29 15:24:57 +00:00
mistachkin 14e61df283 Further corrections to the Win32 interface for lsm1.
FossilOrigin-Name: 4df6e2476ce93b9ca7a6959c8c2d6ef2c30395984b007d74166031dcf09d54b4
2017-06-29 15:13:48 +00:00
drh c6603af755 Rename the "stmts" virtual table to just "stmt" without the final "s".
FossilOrigin-Name: adfdb80105c46ac42b71132c80a91dbd5b1c9ff241fb4fbb5d04641a88898d90
2017-06-29 14:33:51 +00:00
mistachkin 3881d23c72 A couple fixes for the Win32 interface for lsm1.
FossilOrigin-Name: ebbd98e941d8a8ea97b434c29b70095515af0adab1977aa4d37fe74a7401f846
2017-06-29 14:17:48 +00:00
drh c79983312f Add the stmts virtual table to testfixture builds. Add new compile-time
options SQLITE_ENABLE_QPSG and SQLITE_ENABLE_STMTSVTAB to ctime.c

FossilOrigin-Name: 60c628293a1d8a1505e1a36dbd01b1f62bcfd7915e144044c92385423cbf8e07
2017-06-29 13:41:59 +00:00
mistachkin 2ca62cb102 Compilation fix for lsm1 using MSVC.
FossilOrigin-Name: b7794cc5d5abc13c6301c8d5c1b330405432c047f154083430fd15823221e552
2017-06-29 13:35:44 +00:00
drh e4b45f536e Add the LSM1 extension.
FossilOrigin-Name: 824e83274c04d24fd854bc7376c958ea6b05862efc562a3dfed0fc888fd96cc2
2017-06-29 13:19:55 +00:00
drh 366050e89a Add the "stmts" virtual table to the amalgamation, activated when compiled
using -DSQLITE_ENABLE_STMTSVTAB.  Add the SQLITE_STMTSTATUS_REPREPARE and
SQLITE_STMTSTATUS_RUN statistics outputs from sqlite3_stmt_status() and add
corresponding columns to the stmts virtual table.  Change the numeric value
of SQLITE_STMTSTATUS_MEMUSED to get it out of the way of counter values.

FossilOrigin-Name: 88976ae31c2cbc8b75f162140d1356132f69e5b30786e39ad8ca5a1774b03621
2017-06-29 13:13:33 +00:00
drh 3039e3698d The query planner examines the values of bound parameters to help determine
if a partial index is usable.  Reprepares may happen if the bindings change.
This behavior is disabled by the QPSG setting.

FossilOrigin-Name: c322bfa27e88fc9e2c969c1e4ce12a7d541bd2f30e133d267eb2d15fd3477fde
2017-06-29 12:59:40 +00:00
mistachkin d90dbb8c1c Implement xUnlink, xShmMap, and xShmUnmap for lsm1 on Win32.
FossilOrigin-Name: 680cc064c9e809ddc643074b5e65677f484d904b3d52826f6def480ddaa8f0ab
2017-06-29 12:54:58 +00:00
drh 00d11d400b Add the SQLITE_STMTSTATUS_REPREPARE and SQLITE_STMTSTATUS_RUN options to
sqlite3_stmt_status().  Use this for two new columns in the stmts virtual
table.

FossilOrigin-Name: b0b0c8f8d548ef78584ab714ab120b01c1b83fc0d8ae2fd7626b970bab9fca58
2017-06-29 12:49:18 +00:00
drh 5aa307e2a6 Fix the exprCompareVariable() routine so that it works for non-UTF8 text.
FossilOrigin-Name: 25acd9658be792d686b3ebfaa8c3692f9830e043538ed0afecf97110a07758a4
2017-06-29 01:23:12 +00:00
mistachkin cffbd543d3 Implement xRemap for lsm1 on Win32. Also, zero file handle when closing it.
FossilOrigin-Name: 93c9aa7d9aea46b331c53ff579ef704e88ce90f96600b69479a87a4bb4ca2a91
2017-06-29 00:20:42 +00:00
drh c080422642 Alternative implementation of exprCompareVariable(). Need to run tests on
both this branch and the original to see which one to go with.

FossilOrigin-Name: b959c6297c151150ea2dca24aa1f68f3bd76dd6620eb6c03f8dfa59fdd5c13b2
2017-06-28 21:47:16 +00:00
mistachkin 44ab70db7e Implement xLock and xTestLock for lsm1 on Win32.
FossilOrigin-Name: 9112117dad8085c385aa614cd982b307f5822761607ba358f34df7848c549134
2017-06-28 21:36:40 +00:00
drh 3e380a4485 Make the query planners use of partial indexes based on bound variables
responsive to the SQLITE_DBCONFIG_ENABLE_QPSG setting.

FossilOrigin-Name: a934dd14ac55177ac541423f4a077484bb3b461b60c9c2e88d067cca922fa2bc
2017-06-28 18:25:03 +00:00
drh 37f906087b Merge the in the latest enhancements from trunk.
FossilOrigin-Name: 8f63c5863231eba7f853f9587b58a81102c31708402fa9962a6e91aa622fad13
2017-06-28 18:07:29 +00:00
drh d0bbe4e9c2 Incorporate recent trunk changes.
FossilOrigin-Name: 62b8269ba2ff71e2daaa86688698896badd6f6e34ab42fbf92dda7fcda73a230
2017-06-28 15:56:58 +00:00
drh f00f530b7d Build the "stmts" virtual table into the amalgamation. It is active only
when compiled using SQLITE_ENABLE_STMTSVTAB.  That option is supplied to the
command-line shell.

FossilOrigin-Name: 0ff057d86e42e518fda22bfbf5f1977ab6bd0a74a9211ff259ee7e8a7ce98b58
2017-06-28 15:47:29 +00:00
drh 2fb960b545 Fix harmless compiler warnings in the CSV extension.
FossilOrigin-Name: f02a54599de7620438aecd3753199fc52ce8919d7503bb8b2f5592b0e51dbf8c
2017-06-28 15:17:31 +00:00
drh 8b471e7e79 Faster parser stack overflow detection.
FossilOrigin-Name: 36e54cd8b1fb374fd41e3e09b34b86e34327bf07c9e4bfec58382163c5c5d279
2017-06-28 15:01:35 +00:00
drh 6559e2cec7 Minor tweak to the SQL grammar to make the parser tables a few bytes smaller.
FossilOrigin-Name: cc4810b23e683e8c359f7c1a562338ec8501e43cac3475b2be002568fca5e6a4
2017-06-28 14:26:37 +00:00
drh 6be95366c7 In the lemon-generated parser, store the number of symbols on the RHS of each
rule as a negative number and add it to the stack pointer, rather than storing
the value as a positive and subtracting it.  This makes the parser faster.

FossilOrigin-Name: b362f0d8ed34839bf3b29d10ed0853ab94245fba135ccd28e619caa6ee6992d5
2017-06-28 13:47:56 +00:00
drh bd8fcc130a In the lemon-generated parser, automatically promote SHIFTREDUCE actions on
nonterminal systems to pure REDUCE actions, for a performance enhancement.

FossilOrigin-Name: c46d94a8cde816ca383e771721ebd4900de77950cba700e35a26f70fd5b794a4
2017-06-28 11:56:18 +00:00
drh 6e11b16282 Simplify error handling logic in sqlite3_exec() to save about 40 bytes.
FossilOrigin-Name: 6480916c7266437cf8a70e5db2ca5c753ad71c361b68e41cbf8572f77c271920
2017-06-28 01:21:16 +00:00
drh 59a386ea03 Minor code simplification in the ALTER TABLE logic.
FossilOrigin-Name: bfc4e7f30e4654b9603457fb6a4136828e346dcfe4e313fdf56ed62d131b7156
2017-06-28 01:12:53 +00:00
drh 3144df1264 Avoid an unnecessary call to sqlite3XPrintf() in the code generator, for
a performance improvement.

FossilOrigin-Name: 29d6ceb3838394d902e248d1eab627625a857dccb5ed0bb66161a13fafc500c8
2017-06-28 00:55:50 +00:00
drh a5e906f307 Add SQLITE_DBCONFIG_ENABLE_QPSG that forces the query planner stability
guarantee.  This is the fix for ticket [b9f010107724c]

FossilOrigin-Name: b82efd2a24914ace39acf99df75175042471fd73a8d31d66a40b15f63b342e10
2017-06-27 23:36:44 +00:00
mistachkin ec99c0f632 Improve a local variable name.
FossilOrigin-Name: d0f6973d93c36451bf64f47de9a88abec613a624603033bf6717f5071139b6d2
2017-06-27 22:33:06 +00:00
mistachkin b5fdc26c21 Initial work on porting lsmtest to Win32.
FossilOrigin-Name: 7e669d9bfab237ff7ece821cf95cfd3bb753b1882b9a86044b7d4579808aecf4
2017-06-27 22:27:54 +00:00
mistachkin 59b1dd3830 Implement xFullpath for Win32.
FossilOrigin-Name: dbe9c8aa8d70051fafec569054eeda6c02efe9d036ab6beada00da3ed42e52d9
2017-06-27 18:15:38 +00:00
dan 210ec4c855 Fix a virtual table problem that can occur when the vtab is on the RHS of a
LEFT JOIN and there is a MATCH constraint in the ON clause, or when the vtab
is in a sub-query that is the RHS of a LEFT JOIN and there is a MATCH
constraint in the WHERE clause of the sub-query.

FossilOrigin-Name: 87b381663398f029f52cb5598aadd069b03034b6f833ce80ba762b406075a44e
2017-06-27 16:39:01 +00:00
mistachkin 8e1ddde079 Minor corrections to the previous check-in.
FossilOrigin-Name: e1cf8a78a0bbd7b05cefab22a5c9676098887ee9811d37330ce89b3367856f92
2017-06-27 06:28:00 +00:00
mistachkin 02679b0466 Work in progress porting lsm1 to Win32.
FossilOrigin-Name: 2017636e93cf810fe4d1247c18de9f316fca037035a026f77c4588563d7bf0cc
2017-06-27 05:59:47 +00:00
drh af38cdbc08 Add the -withoutnulls option to the "db eval" method in the TCL interface.
FossilOrigin-Name: 18f0616e15684ca327fb10a1d133331af1d3b75f609498982290f6ad69fcaced
2017-06-26 21:08:32 +00:00
drh d5fbde80a2 The ".import" command of the shell, and the csv virtual table extension both
ignore a single UTF-8 BOM at the beginning of their input.

FossilOrigin-Name: 7c15d762d99c2e3e534cd35dfe25ddcd317637eb1f2655fd24c2dd5f9d5a7613
2017-06-26 18:42:23 +00:00
drh 7df7475d0d Make sure sqlite3VdbeSetVarmask() is never invoked when QPSG is enabled.
FossilOrigin-Name: ebcfa73e1c8ebb4fc371a6dcf77f97b6e06e405a299c66182aa4b20423d519ec
2017-06-26 14:46:05 +00:00
drh 169dd928c5 Add the SQLITE_DBCONFIG_ENABLE_QPSG option to activate the query planner
stability guarantee.  This involves refactoring the sqlite3.flags bitvector
to carve out a free bit to use.

FossilOrigin-Name: 7076e8283ebae1b45a5d85d9538b49b6da399d38c3c6935de100f948f814f6a9
2017-06-26 13:57:49 +00:00
dan 4261a4065f Remove an invalid assert() from lsm test code.
FossilOrigin-Name: ca8a7e995c3da10ba05e3b7d4818c633fe5ba6d6f9351b67017a2603b50b903d
2017-06-26 11:46:01 +00:00
dan 3a31c67aae Fix another problem with multi-threaded mode in the LSM test code.
FossilOrigin-Name: 461ced77d93e84f09bfb4291999cd0245506fa9a8369049fd68968bbcf18d41b
2017-06-26 08:24:35 +00:00
dan e6f98bcf09 Update a test case to reflect the fact that the lsm blocksize is configured in
KiB. And defaults to 1024, not 2048.

FossilOrigin-Name: d7015475f121db1f56060716cd8adb73e9b52016890ec9018b620ef9d7d4fbff
2017-06-26 07:31:28 +00:00
dan 07cae6ae74 Fix some compiler warnings in lsm_file.c.
FossilOrigin-Name: 23f16382ed47a90bf5e6c1684d54d28484dca46fea20ca0f131bd477cf222bfb
2017-06-26 06:53:24 +00:00
drh a22dd3860a Disable shell tests for the .schema command if virtual tables are not available.
FossilOrigin-Name: c8186874b3fec737445ad5c4ba3eaecd922af664b387d89dc31eea60476a0294
2017-06-24 19:21:48 +00:00
dan 5aa550cf3b Consider the values bound to SQL variables when determining whether or not a
partial index may be used.

FossilOrigin-Name: 7b59c353b805c64689b4ae9df347705acbb5f116346ad77af8ce087da7893747
2017-06-24 18:10:29 +00:00
drh 7f2d1cd2b0 Make sure the config.h header is included by ctime.c, if that header exists.
FossilOrigin-Name: c2ea62937ec8fabec72d3c7cd38d8e2cabbb5ce48638f8ce7ebefd6cd2716fd3
2017-06-24 16:35:00 +00:00
drh 54ac445d53 Query planner tuning: When deciding between two plans with the same cost,
bias the selection toward the one that does not use the sorter.

FossilOrigin-Name: f0ec36d479ac4efaa0efd0594d032dd7b8ccdf84a4dc3644cd688762186fbcca
2017-06-24 16:03:18 +00:00
drh 45e7d7dd1c Make sure enough memory is allocated for pathological quoting cases when
computing a quoted table name in the command-line shell.

FossilOrigin-Name: 0583b84ab444db3ae3c93db619b67bf84b0305ab989200e77214e02ff2dc923a
2017-06-24 13:31:40 +00:00
dan 65c2a71042 When generating individual loops for each ORed term of an OR scan, move any
constant WHERE expressions outside of the loop, as is done for top-level
loops.

FossilOrigin-Name: 712267c9c08fdcef5d59cedc672657b55fd6a77472711711599f0bd653e6d880
2017-06-23 15:47:05 +00:00
dan c456a76fb3 When generating individual loops for each ORed term of an OR scan, move any
constant WHERE expressions outside of the loop, as is done for top-level
loops.

FossilOrigin-Name: e4a022be4b069b08cfdfda5295461676b99d28e17bbbedfbcb362dec69de59bd
2017-06-22 16:51:16 +00:00
drh c45fdb2a7f Enable pragma virtual tables for the integrity_check, quick_check, and
foreign_key_check pragmas.

FossilOrigin-Name: 118f7bb33a6f78951bbffa957f48015d1bce5aaf9246a99262a90bc8ad52e5a3
2017-06-21 01:36:30 +00:00
drh f383f35e6c Rename the azCompileOpt global constant to avoid a harmless compiler warning
about a name conflict with a local variable.

FossilOrigin-Name: 94e420ecfb4ec047eb7d1d3125ca8487c90d466760b7f7183759ff922bd868d1
2017-06-20 18:19:16 +00:00
dan bd11a2acbb Ensure that the query planner knows that any column of a flattened LEFT JOIN
can be NULL even if that column is labeled with "NOT NULL".
Fix for ticket [892fc34f173e99d8].

FossilOrigin-Name: 483462682d3a57fb9dd85b4772596e9738f1694a454b8ebbc480b9452733e88d
2017-06-20 17:43:26 +00:00
drh a5907a86b8 Experimental "PRAGMA secure_delete=FAST" pragma. The intent is to overwrite
deleted content with zeros without increasing the amount of disk I/O.

FossilOrigin-Name: f1682f0faf1a93ded066464b1ddd5f987e21ee0f6bb5e828ed31c3ad903cf2c3
2017-06-19 11:44:22 +00:00
drh 40db2fd7a3 Fix a missing comma in the previous check-in.
FossilOrigin-Name: f3db02f49073c3f08c3fd7816d85e5472d5e22df20d862fe4886eb2a97efb15f
2017-06-17 18:49:50 +00:00
dan ea03adc6b2 Rework the code in ctime.c a bit to report on more compile time options. And
to only output configuration options passed in to SQLite, not the default
values of #define symbols set automatically. Also generate the large array in
ctime.c using new script tool/mkctime.tcl, instead of entering it manually.

FossilOrigin-Name: 9a443397a6b110f60cae32e1f758914d72931e16ddb423e4d4a119df526bf340
2017-06-17 17:55:33 +00:00
dan 814aad618c Ensure that the value of the THREADSAFE symbol is always included when
reporting compile time options, even if it was not explicitly configured.

FossilOrigin-Name: 95141c642697dc037e57f9e4992ff3460155995d3caef6259235601ee722cb93
2017-06-17 17:29:24 +00:00
dan f417f28bd7 Add extra test cases for sqlite3changeset_apply() and ALTER TABLE ADD COLUMN.
FossilOrigin-Name: 603838fc9a65adda831a6a17b31b2e80f5b56e5946a9f0c1fa2c83d2f2a67f6a
2017-06-17 16:39:10 +00:00
dan da1f49b83f Rework the code in ctime.c a bit to report on more compile time options. And
to only output configuration options passed in to SQLite, not the default
values of #define symbols set automatically. Also generate the large array in
ctime.c using new script tool/mkctime.tcl, instead of entering it manually.

FossilOrigin-Name: bc1951d699e6eeacbe15776a37cd0f5cf3f09eb85d3ae01cff43293cb286fcd7
2017-06-16 19:51:47 +00:00
drh ba87c6c2cd Minor refactoring change to clarify how ATTACH works. No functional changes.
FossilOrigin-Name: 3944a32e1dd90ff903bcbaaa7cb497cebcfcb2ba2a326726ec2268505e524ae3
2017-06-16 18:31:30 +00:00
drh 76cf858d3d Prevent pagesize changes on VACUUM in encrypted databases even when running
the VACUUM on an attached database.

FossilOrigin-Name: 11693849342a308ad929e2d9ead67faabacb523af76128c6973ed6cc8b62c11e
2017-06-16 13:43:37 +00:00
drh 0942559a14 Move the "shell_add_schema()" SQL function used by the ".schema" command
of the command-line shell to a different spot in the shell.c source file
so that it is not in the middle of an unrelated module.

FossilOrigin-Name: 254617a1ccfa1736d4e53d670d80319c79c4d93ebf1de69d89ebdba3949bc270
2017-06-15 16:56:05 +00:00
drh f217f3b68c Fix typo and improve the wording of the description of "Metadata" in the
output of the sqlite3_analyzer tool.

FossilOrigin-Name: ca1ff70780e07e5ee930fe7972db02e887d9b085d8ab78e878d7f966b6d684d4
2017-06-15 16:45:23 +00:00
drh b74013300c Merge the latest changes from trunk.
FossilOrigin-Name: 60105c2253d0b617037e975b0d0b729bcb59b950aa2c33d8891394ad45aabb69
2017-06-15 15:06:26 +00:00
drh 90cdec0672 Fix harmless compiler warnings in the shell.c file
FossilOrigin-Name: 9afd7a2ffd3a39456190ad05e85ff6485298aae262d9e0698a58c1d73507a36f
2017-06-15 13:07:56 +00:00
drh 594ccd09b1 Improvements to the ".tables" command in the command-line shell so that
it shows the name of all schemas if the name is anything other than "main".

FossilOrigin-Name: c7f778b7cee16a1dcebccd256408ee1d08ef2b62e388a9ebba5738a0a89bf3a0
2017-06-15 12:50:47 +00:00
drh 20c9c3f4eb In the command-line shell, enhance the ".schema" command show that it
shows the schema for ATTACH-ed databases in addition to "main".

FossilOrigin-Name: 48e086284a76da10a85315bc992e2294bd4711e35ec5a5abaa16e39a6a69d206
2017-06-15 12:21:09 +00:00
drh c74d962a1f Enhance the sqlite3_analyzer.exe utility so that it computes and shows the
number of bytes of metadata on btree pages and per table and index entry.

FossilOrigin-Name: 43ad41efa9e1fdd79a9804197a227491236495f14ed56c656224d6ce181703c1
2017-06-15 00:52:03 +00:00
dan 2ebf8f474e Fix sqlite3rbu_close() so that the pzErrmsg parameter may be passed NULL.
FossilOrigin-Name: c433672dd8ab625628bde2f4f40a2dc000ed915dbe91833d3f753d8ab51baf25
2017-06-13 16:52:34 +00:00
drh 6e3bccd5c9 Fix the processing of double-negatives in WHERE clause constraints with
STAT4.  Ticket [cfa2c908f2182]

FossilOrigin-Name: 35b34bdf0843b49be39e13ed212e918c2d45afdb8374b5cd02ba6d2d5b16b3b9
2017-06-13 04:31:54 +00:00
drh 56790ea567 Fix an off-by-one error that messes up the display of loop codes in the
".wheretrace" debugging output for queries with more than 62 candidate
loops when SQLITE_ENABLE_WHERETRACE is on.

FossilOrigin-Name: 0bbdaf2801e4102d952db65e53962e534b67b8b72e76fadb4ce404a6249129d9
2017-06-11 20:17:02 +00:00
drh eafc6dfe2b When reusing a materialized view, make sure the estimated number of
output rows is correctly initialized to avoid confusing the query planner.

FossilOrigin-Name: 87aceb417a813a2925b636cffa660fe25f3b7e3b3c84bb2108951bf0af644376
2017-06-11 19:51:36 +00:00
drh e46c63d565 Fix the sessiondiff test module so that it does not run if the session
extension is not enabled.

FossilOrigin-Name: 8f92b7a6223a69304dc8a6ab3b43a49cbb87f572a1e65d8a0c6dc09fca38e1a8
2017-06-11 19:40:34 +00:00
drh c62aab5ba8 Fix a potential null-pointer deference following OOM introduced by
check-in [e39795d7] (unreleased).

FossilOrigin-Name: a2f77285fa44df86863eed576271f1030ec60f15480daf175908c5082c27774b
2017-06-11 18:26:15 +00:00
drh e9acf4b48e Merge enhancements and fixes from trunk.
FossilOrigin-Name: 3fd050c343256c0748256ef183b46df04d9e0da0f81b841dbd336034402b36ab
2017-06-09 15:14:41 +00:00
drh c097b309aa Update the documentation to make it clear that the table name parameter
to sqlite3_table_column_metadata() may not be NULL.

FossilOrigin-Name: 2881ab1ed24ed72760086785bdf224c4e687cf39a02fd349ae13c6e1235e24da
2017-06-09 11:43:53 +00:00
drh c5d353fb33 Adjust the implementation of the ".selftest" feature of the shell to avoid
using the deprecated sqlite3_get_table() interface.

FossilOrigin-Name: 3168e2c92ad0a0dafc78a27ee1d87ac89f426585f506f418a0182141335dc68b
2017-06-09 02:27:49 +00:00
drh d96cc6fbcb Add a testcase() to confirm that an OOM on sqlite3DbStrNDup() is handled
correctly in trigger.c.

FossilOrigin-Name: 343e55992f503efa662e49bb0f3c0d798defd0a11f2ee1c36968902fa7e06823
2017-06-08 14:35:21 +00:00
dan ca66f6c6f4 Ensure pointer map entries are always added when a row that does use overflow
pages replaces one that does not in an auto-vacuum database. Fix for
[fda22108].

FossilOrigin-Name: b30dfba811cb531b09ff2e71a1a18ed53c816cb39155dd52ca3e2701425fe17b
2017-06-08 11:14:08 +00:00
drh cc97ca4c08 In SQLITE_DEBUG mode, attempt to log the page number of the database that
contained the problem when SQLITE_CORRUPT errors are seen.

FossilOrigin-Name: e39795d7d798d5249c7bd2a0f6ff891b455f4300a3d638c39a4668323b367666
2017-06-07 22:32:59 +00:00
dan 41ac439dbe Fix another lsmtest build problem. Add the "-trans BOOLEAN" option to "lsmtest
speed2".

FossilOrigin-Name: 61853bc171e7c3af1db6a33ac8b1ad21e1c08e8d6b317fe061fdcd89c9a42e88
2017-06-07 19:46:18 +00:00
drh 0282c03abc Merge in trunk enhancements.
FossilOrigin-Name: f8bbb608cbf6c245628e3d362e9181fb3dc402b1d8241bcb687caf395f63c916
2017-06-07 16:25:25 +00:00
drh d1417ee1cb Add the SQLITE_DEFAULT_ROWEST compile-time option for changing the estimated
number of rows in tables that lack sqlite_stat1 entries.

FossilOrigin-Name: 234ede26e30f20e6c33002739ed8be35dbfb5c77700bd857ff31072b9b7df347
2017-06-06 18:20:43 +00:00
dan 3b328522f4 Fix a threading problem in lsm test code.
FossilOrigin-Name: 501238b9fbb4eece084b4bfce84a5f37a986f34db8081df517e60ef81f357454
2017-06-06 16:14:49 +00:00
drh cf1393df94 Fix a subtle bug in the remember UDF of the kvtest.exe utility program.
FossilOrigin-Name: 9eea3670e77e2f831b7c00ae2d65a5583f9cad626d9ab286f92582ef29ecd4e3
2017-06-05 19:20:35 +00:00
dan b1d66c5986 Fix a bug in test_fs.c that occurs when the first component of a path contains
a GLOB or LIKE escape character.

FossilOrigin-Name: 73c70590d7689806901378cd2a7e167ec4339f886031369266e07868acd23b93
2017-06-05 16:33:53 +00:00
drh a4327e65bb For the kvtest utility, add the --vacuum option to "kvtest stat" and also
run PRAGMA integrity_check with "kvtest stat".

FossilOrigin-Name: f3c25df4562efda2adeb211a4cc893246354917849a0fa4d95da3d7970e9588e
2017-06-05 13:28:17 +00:00
drh 64bf76d2b2 Fix the column width deduction logic in the command-line shell to account
for multi-byte utf8 characters.

FossilOrigin-Name: ed0842c156ab1a78d5d00d3a55dab5e3f08cd349328d606724688f1528df3f6b
2017-06-05 12:29:26 +00:00
drh 3b77506ba5 Omit some of the fstree tests in vtabH if the PWD contains LIKE wildcards.
FossilOrigin-Name: ead29f9cb757a5f9921086e3bb4998f60e0d6cfcf41ef0f9a230b365b6226947
2017-06-05 10:31:03 +00:00
drh 4c88348729 Initialize a variable to zero to prevent an (incorrect) compiler warning of
it potentially being uninitialized.

FossilOrigin-Name: 65182ce041b30cd0193b958eca975b720fe5200a868baba1e633e49433d86813
2017-06-03 20:09:37 +00:00
drh 5930f663a1 Fix the SQLITE_PTR_TO_INT macro so that works on recent versions of LLVM on
Macs.

FossilOrigin-Name: c4089ffbdb4b3467648c97044b0d3085da7128103079b686f608efde83c7df30
2017-06-03 19:16:29 +00:00
drh 629a75f69a Remove unused header file from kvtest.
FossilOrigin-Name: dd7e043f7c9e16cd98a273b7105fa74bdd14a93db8cd5bde064cc1c40591155c
2017-06-03 18:27:49 +00:00
drh 1346fdad65 In kvtest, add the ability to work with a hierarchy of files on disk,
in addition to having all files in the same directory.

FossilOrigin-Name: f568f666c85ab9b80592927dc033cfd65bd4415576cf5b3beaf300d68a8e074e
2017-06-03 17:24:04 +00:00
drh 16d62901a3 Add the --nocheckpoint and --multitrans options to kvtest.
FossilOrigin-Name: 5828633c2392274b6863b50eaffbb2a176a4d892e83542824a9a3f0d1b62c967
2017-06-03 15:17:21 +00:00
drh 59ce97a013 Merge all recent trunk enhancements.
FossilOrigin-Name: 1d23294d88b1a80fe1f5403ea4fd75e61bb4932d5b714ea450d1b4b84f0896ab
2017-06-02 23:44:38 +00:00
drh f151890791 Add the --fsync flag to kvtest, and document the --nosync flag.
FossilOrigin-Name: 7fdc78a672b2ea6187dcb5fdf32f809bb8e4d501e2434f2233edc3bc2e3acc7c
2017-06-02 23:32:17 +00:00
drh a2e71ced79 Work toward enhancing kvtest to measure write performance.
FossilOrigin-Name: fc73e7d2f16386f96c55c42f9830193f7c178521a7ad90c3117b85ef629b5ce4
2017-06-02 19:31:46 +00:00
drh 170ad68a40 Change the name of the OP_Seek opcode into OP_DeferredSeek for better
clarity of function.  No functional code changes.

FossilOrigin-Name: ab33d299c7dab52703d06f3441c8a98c6c809b2612ec65d71aab2919bd2b1540
2017-06-02 15:44:22 +00:00
drh 6c2d94f928 Fix a typo in the header comment of the "series.c" virtual table extension.
FossilOrigin-Name: d637feb4e3032ee0067c204b56d2af5f7eab228e645f2e77b0b043c2b299724d
2017-06-02 13:16:54 +00:00
dan 38d6985509 Add test code for LSM to the ext/lsm1/lsm-test directory.
FossilOrigin-Name: bb7436e84a315baf05f00e6cab396017e3f287ea404d32e0cc4f389fa1194dec
2017-06-01 16:13:57 +00:00
drh c5e56b3473 Add a comment to the Lemon documentation regarding the security of the
lemon.exe command-line tool.

FossilOrigin-Name: 4c2458c1908181dc2f6bc594395c06d015fcbd78f5d3472f07a6a3909be9673c
2017-06-01 01:53:19 +00:00
drh 2c2f392dca Add interfaces sqlite3_prepare_v3() and sqlite3_prepare16_v3() with the
extra prepFlags argument.  Add the SQLITE_PREPARE_PERSISTENT option as one
bit in that argument.

FossilOrigin-Name: 4a25c5883380fe5990d8180adb58c3bdc7a3d081bc4c69cd4de3cd57074fb251
2017-06-01 00:54:35 +00:00
drh cdbb126be7 Add the SQLITE_STMTSTATUS_MEMUSED opcode to sqlite3_stmt_status()
for finding the heap memory usage by a single prepared statement.

FossilOrigin-Name: c26cf978eead1c9d265eddabaa421e7735b472fcf2792cd2bdeb0901bcf3fb44
2017-05-31 17:30:08 +00:00
drh 3528f6b62b Add the SQLITE_STMTSTATUS_MEMUSED option for sqlite3_stmt_status() that reports
the amount of heap memory used for a single prepared statement.

FossilOrigin-Name: b57d510465458dec5b5fc778fd6e8833392964201f9febebf526e60a543da0c2
2017-05-31 16:21:54 +00:00
drh 6b37e0adc9 Add the experimental "stmts" virtual table for introspection of prepared
statements.

FossilOrigin-Name: cb4c5c66aba757356da3b8ec3c66a5c8c40e180b3360638ac634f7787404a5b1
2017-05-31 16:09:04 +00:00
drh d4ab003d4e Avoid allocating excess memory to the KeyInfo objects.
FossilOrigin-Name: df7859435161f3ecf36635ce574bf73573516a1f2c6e75be320619364e7067d1
2017-05-31 13:45:59 +00:00
drh d5bdd5effb Remove a completely unnecessary memset() from the INSERT code generator.
FossilOrigin-Name: 7d58836b9db1293a3a6581af4358b7c91a588efd5c9b2df384803f3855ff87a8
2017-05-31 13:27:15 +00:00
drh b8a1290a28 Very small performance increase in sqlite3VdbeSetNumCols().
FossilOrigin-Name: 8885b4461044ae8ecdfe1b9aa47f4aad65efabc98e3fcd9e307a06504fab34c6
2017-05-31 11:24:13 +00:00
drh 02f18cc5ac Reorder fields in the PgHdr object for a performance increase.
FossilOrigin-Name: 326e63d71e0e164c5bcd1f74772cb4071b82daf6f04a5d440b985bace5a4c941
2017-05-31 03:20:39 +00:00
drh a8b9793c86 Avoid unnecessary memory zeroing during expression list allocation.
FossilOrigin-Name: de28e6514a42438411e2c9d833ba660108128ca86d0b90f32925fb73195f4862
2017-05-31 02:58:30 +00:00
drh d03257c141 Size and performance optimizations to sqlite3ResolveExprNames().
FossilOrigin-Name: af8c0fed93c830c50641d95691bb507c31947a15529aba2a88bfaa66b3a3287a
2017-05-31 00:49:40 +00:00
drh 2ab792e4c0 Change sqlite3BtreeNext() and sqlite3BtreePrevious() so that they return
SQLITE_DONE if they have already reached the end (or beginning) of the table.
This gives a performance increase and size reduction.

FossilOrigin-Name: e972a3860892022d57b26ec44ce0fbadc61c1ff54b7a10b7e82390db88d323a7
2017-05-30 18:34:07 +00:00
dan d26d2c7de2 Omit a test of codepoint 0x202F (non-break narrow space) from the fts3 ICU
tests. Different versions of ICU apparently handle this obscure codepoint
slightly differently.

FossilOrigin-Name: 69ae688982d6cb9f859f5643c315a1dc5ba76ad35553ecea8329a75ee70a87b1
2017-05-30 18:14:47 +00:00
drh e70d01f143 More efficient error handling and reset in the binding mechanism.
FossilOrigin-Name: 9a3e3b34ba6eafce2f560c13225a3673e18d696b29295b59d958e938fa593baf
2017-05-29 22:44:18 +00:00
drh 1e669f02bc Omit unnecessary fstat() calls for determining the database file size,
resulting in smaller and faster code.

FossilOrigin-Name: dd61c736775c53450821327495276485dced7935d0b4b5ebd17662731afc8adb
2017-05-29 17:59:29 +00:00
drh 8c9ed054b3 Fix an issue with OPT_FEATURE_FLAGS in configure.ac.
FossilOrigin-Name: 43ce3bd3a4b41ea757e308e563d6c1bf7f9c09f10e4766c536d0bf1042c45613
2017-05-29 17:43:06 +00:00
drh 77f6af2b96 Avoid unnecessary fstat() calls to determine the database size when
transitioning into a read transaction on a rollback-mode database.

FossilOrigin-Name: 6c3476b513965df22d648f9a1b99733af753b44d51163cc7d42a69bf562300e1
2017-05-29 16:45:45 +00:00
drh 5f5a2d1c3c Avoid unnecessary calls to fstat() to determine the database file size.
FossilOrigin-Name: c733a1dea37e4678e7bd0d3d0ca9b8eae1fbdc28615f75d8f1e5141aa53567d9
2017-05-29 14:57:23 +00:00
drh 8abc54e2e8 Fix a typo in a comment. No code changes.
FossilOrigin-Name: cb29b838886769afe866b1172e3d5d7e36387149b79c51f91cf59da3f4a5f25b
2017-05-29 14:30:46 +00:00
drh 979dd1be57 Optimizations to the Walker object and its methods to make the code a little
smaller and to help it run a little faster.

FossilOrigin-Name: 6854a34ed708259f2280f7ee56cec09f7fc99810dc739dc2814ddeae286aa2c4
2017-05-29 14:26:07 +00:00
drh d8a295669c Correctly initialize the iSelectId of FROM clause terms that are a self
join of a reused materialized subquery.  Without this, the EXPLAIN QUERY PLAN
output for the query will identify the subquery using the uninitialized
(and arbitrary) iSelectId.

FossilOrigin-Name: 43c9ae371f6250fee98a7c4011726eff8ad37f5a97add4f490ac3a2dd501a0d2
2017-05-29 13:09:24 +00:00
mistachkin e16a350f17 Improve shell help text for the '.open' command.
FossilOrigin-Name: 7cc940a97efc096ff3725710f526c06f52453bd923fb9e825ce6990275df747a
2017-05-29 03:48:13 +00:00
drh ae2ac854b3 Smaller and faster vdbeSorterCompareText().
FossilOrigin-Name: 542dc4c5eb87017fe03b6c181e779993aa84564785e1177ccf937d52f985593b
2017-05-27 22:42:36 +00:00
drh 14e845a9d4 Small performance increase and size decrease in the btreeInitPage() routine.
FossilOrigin-Name: 6f415833e0554706dcf04f68ecba4ca2e54c08f3bbf6a1dba182bb132c912a2e
2017-05-25 21:35:56 +00:00
drh 137c46f8b6 Merge the LEFT JOIN query flattener fixes from 3.19.2.
FossilOrigin-Name: 6513e4a121e32df7e5cd95f47cdf8049b85bdbcb378cf23db29838fb1143d3ce
2017-05-25 17:27:52 +00:00
drh f43ce0b445 The TK_IF_NULL_ROW expression node must be treated as a variable that
references the table Expr.iTable.
Proposed fix for ticket [7fde638e94287d2c].

FossilOrigin-Name: 77fc23013cebc7797985864b91d78db5d0e2469511732044ebfaf02b891c979a
2017-05-25 00:08:48 +00:00
mistachkin 831265f962 Fix harmless compiler warnings in FTS5.
FossilOrigin-Name: 57a60e959c198b87ed29fab14356f89e0ea7cdb1dd99adbea45b40e8d0cb310a
2017-05-24 15:32:44 +00:00
drh 63ad86e70e Fix a problem in STAT4 equality estimation for multi-column indexes
introduced by check-in [3e0590dee0e68cc1599].

FossilOrigin-Name: cfb0d9e0207128b1c2b48689288a849b19dbc00a22cfaca26eec4bfc773629f8
2017-05-24 04:18:00 +00:00
drh ce13b99f99 Remove the msvc.h header file from the autoconf tarball.
FossilOrigin-Name: 84996aef68adeabc8bd97cad269188c67de628f776337a25ec2d63bc956cee78
2017-05-23 20:00:00 +00:00
drh 92b71757f7 Do not use strcpy() in the (obsolete) amatch extension.
In releasetest.tcl, run Apple tests using -Os instead of -O1

FossilOrigin-Name: 4440e42031b9cb0edf9a8621cd4f46f209392940ec5b9eefcf8c1e3fef5f7b76
2017-05-23 19:35:20 +00:00
drh 1d1fc5e385 Disable the LEFT JOIN flattening optimization for aggregate queries, as it
does not currently work.  Further fix for ticket [cad1ab4cb7b0fc344].

FossilOrigin-Name: 44b21e35c92137cc519d0cc87c627cc531d0bd442a7b9a7356fa2c6bc5f70fb6
2017-05-23 15:21:37 +00:00
drh eff0a7b25e Ensure that the expression rewriter inside the query flattener decends into
the substructure of the TK_IF_NULL_ROW operator.  This is a continuation
of the fix for ticket [cad1ab4cb7b0fc344].

FossilOrigin-Name: 941d8142b7c9a96ff143d1add3c86cf42d61fd08e532d400dac555f23eadbcfb
2017-05-23 12:36:13 +00:00
drh 3f1e9e00e6 When flattening a query, make sure iTable attribute of TK_IF_NULL_ROW
operators (that result from a prior flattening of a LEFT JOIN) are updated
correctly.  Fix for ticket [cad1ab4cb7b0fc344].

FossilOrigin-Name: 92c178507df553e4f1110342c8f9b11b3ee37989e1d634fcaccabf657befa22f
2017-05-23 01:21:07 +00:00
drh d4fb196531 Remove a surplus semicolon, which was harmless on gcc and clang but caused
compile-time errors on msvc.  This only comes up using the encryption extension.

FossilOrigin-Name: 987a2b5537254b1fe843eb798d7eb7f04dbe1e32fb827cfb9e1e1ef6c2096759
2017-05-23 00:32:56 +00:00
dan 07d0f15e93 Fix incompatibilities between the "sqldiff --changeset" command and the
sessions module. Specifically, allow sessions to process changesets containing
tables with zero operations on them and have sqldiff output the expected
output for tables with multi-column primary keys.

FossilOrigin-Name: 0bb23c48064cc64134697469f3f4d2d3610b9e6c7a0dc54a3c47a00bd6c2a860
2017-05-22 18:09:00 +00:00
drh 453ca043a2 Add the ".cd" command to the command-line shell.
FossilOrigin-Name: 5fe28e15b1d6d8a588fcaf93c6035c0e0ab7bcad1067c7933cd430d2e04bbbd8
2017-05-22 18:00:34 +00:00
drh ee841262d9 Increase the version number to 3.20 for the next release cycle.
FossilOrigin-Name: ab471f61ef7d9ed1bf937d5e458f720d12209712a015786434edc818a98168c9
2017-05-22 17:39:37 +00:00
drh d758722449 Merge the last-minute 3.19.0 changes into trunk.
FossilOrigin-Name: e6ba2a93a8d28074ff134dd43c142315de291b7c0a38ecc692863c33975c71c7
2017-05-22 14:04:46 +00:00
dan 21766c0c16 Fix a case where NULL was being passed to memcmp() following an OOM. This is
probably not a real problem, as the number-of-bytes parameter was passed 0 in
this case, but it was causing a santizer complaint.

FossilOrigin-Name: 3ea2bad27e516d5dbfa4a9cb0c767d6a8387280a7e4bbf2ae80cd318da670d66
2017-05-22 08:04:09 +00:00
drh 78436d4c66 When planning a query using sorting, resolve ties in the solver by selecting
loop plans with the smaller unsorted cost.

FossilOrigin-Name: f261678c90297f9767040c577796cc1d4db598aa44b0de6906cb73eaef377dee
2017-05-22 00:45:15 +00:00
drh e46515b53f Prevent a possible NULL pointer dereference in the OP_Found opcode that
can follow an OOM error.  Problem found by OSS-Fuzz.

FossilOrigin-Name: c2de178fe7e2e4e0d764e7e6ac637cfc8c053580c43f7246318dafad2974de3c
2017-05-19 22:51:00 +00:00
drh bcbb066534 Improved comments on one routine in the query planner. Improved diagnostic
output for ".wheretrace".  No production code changes.

FossilOrigin-Name: 946b87a5282f00d8c532a51f4390e6de781b9a0d6626cb3c077c5622895dc540
2017-05-19 20:55:04 +00:00
drh 748465b49e Fix a documentation typo. No changes to code.
FossilOrigin-Name: 68942a4feeb83e6e1a32d9bd724ae1d72669949adcfad07fb05b0ac48daf5151
2017-05-19 20:47:54 +00:00
drh 1e1c4226ee Fix a documentation typo. No changes to code.
FossilOrigin-Name: cfa4aa203646f44b303138c25672293bb87d97126fe2030d4709e8ad7814a807
2017-05-18 18:17:55 +00:00
drh 16b7dcc717 LSM1: Fix the integer key encoding so that negative keys are in numeric order.
FossilOrigin-Name: f92dc4187f6046fcb3ab63449efd7f3738594adc
2016-02-24 13:35:22 +00:00
drh 6627fd6126 Merge trunk enhancements.
FossilOrigin-Name: fac4f4ecee21a460e527a0e2ffa24094b74e17dd
2016-02-23 01:41:35 +00:00
drh 078b99f806 Add support for (variable length) integer keys in LSM1.
FossilOrigin-Name: 32f3daec0a8084b258b2513c8025bc4d95a5d757
2016-02-23 01:37:24 +00:00
drh 7dc1918bbf Merge up to trunk.
FossilOrigin-Name: f9e5fb88a5a14b26e9ea6997f449d0913f27a494
2016-02-22 13:01:22 +00:00
drh 99a1ab7ebc Merge the latest enhancements from trunk.
FossilOrigin-Name: 8aede091c4740511d11ea14da253fe39bbfe75a6
2015-11-19 19:31:33 +00:00
drh c83ef77bb9 Work toward more flexible typing for keys and values.
FossilOrigin-Name: 5c79f53131a7ab3c83f49e35a5021a6cdb2518fc
2015-11-19 19:27:07 +00:00
drh a87cc18948 Basic functionality is now working.
FossilOrigin-Name: aa129c51ecf5c917cfac30be330886f8a10f49e1
2015-11-17 02:23:09 +00:00
drh eb8e7adb16 The virtual table compiles but does not work and is missing many features.
This is an incremental check-in.

FossilOrigin-Name: a32849d6bf66462d1f511714a00f24519d7b7079
2015-11-17 00:15:21 +00:00
drh a0b7ffb184 Import the LSM code from SQLite4 for use in an experimental virtual table.
NB: This is a speculative experiment and could easily result in a dead-end
branch.

FossilOrigin-Name: 3d930501a2acb7f20932cfeb4e3fe308b4569cd6
2015-11-16 16:00:22 +00:00
255 changed files with 37069 additions and 1601 deletions
+8 -2
View File
@@ -181,7 +181,7 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \
notify.lo opcodes.lo os.lo os_unix.lo os_win.lo \
pager.lo parse.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \
random.lo resolve.lo rowset.lo rtree.lo \
sqlite3session.lo select.lo sqlite3rbu.lo status.lo \
sqlite3session.lo select.lo sqlite3rbu.lo status.lo stmt.lo \
table.lo threads.lo tokenize.lo treeview.lo trigger.lo \
update.lo util.lo vacuum.lo \
vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \
@@ -350,7 +350,8 @@ SRC += \
$(TOP)/ext/rbu/sqlite3rbu.h \
$(TOP)/ext/rbu/sqlite3rbu.c
SRC += \
$(TOP)/ext/misc/json1.c
$(TOP)/ext/misc/json1.c \
$(TOP)/ext/misc/stmt.c
# Generated source code files
#
@@ -564,6 +565,7 @@ SHELL_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4
# SHELL_OPT += -DSQLITE_ENABLE_FTS5
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
SHELL_OPT += -DSQLITE_ENABLE_STMTVTAB
FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
@@ -1034,6 +1036,9 @@ sqlite3session.lo: $(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
json1.lo: $(TOP)/ext/misc/json1.c
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
stmt.lo: $(TOP)/ext/misc/stmt.c
$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c
# FTS5 things
#
FTS5_SRC = \
@@ -1083,6 +1088,7 @@ TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
TESTFIXTURE_FLAGS += -DBUILD_sqlite
TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024
TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_STMTVTAB
TESTFIXTURE_SRC0 = $(TESTSRC2) libsqlite3.la
TESTFIXTURE_SRC1 = sqlite3.c
+8 -2
View File
@@ -1294,7 +1294,8 @@ SRC07 = \
$(TOP)\ext\rtree\rtree.c \
$(TOP)\ext\session\sqlite3session.c \
$(TOP)\ext\rbu\sqlite3rbu.c \
$(TOP)\ext\misc\json1.c
$(TOP)\ext\misc\json1.c \
$(TOP)\ext\misc\stmt.c
# Extension header files, part 1.
#
@@ -1505,7 +1506,7 @@ FUZZDATA = \
# when the shell is not being dynamically linked.
#
!IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_SHELL_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_STMTVTAB
!ENDIF
# <<mark>>
@@ -2089,6 +2090,7 @@ TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERVER=1 -DSQLITE_PRIVATE=""
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CORE $(NO_WARN)
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
TESTFIXTURE_SRC0 = $(TESTEXT) $(TESTSRC2)
@@ -2242,6 +2244,9 @@ rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H
$(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU \
$(TOP)\ext\rbu\rbu.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
LSMDIR=$(TOP)\ext\lsm1
!INCLUDE $(LSMDIR)\Makefile.msc
moreclean: clean
del /Q $(SQLITE3C) $(SQLITE3H) 2>NUL
# <</mark>>
@@ -2261,6 +2266,7 @@ clean:
-rmdir /Q/S tsrc 2>NUL
del /Q .target_source 2>NUL
del /Q tclsqlite3.exe $(SQLITETCLH) $(SQLITETCLDECLSH) 2>NUL
del /Q lsm.dll lsmtest.exe 2>NUL
del /Q testloadext.dll 2>NUL
del /Q testfixture.exe test.db 2>NUL
del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL
+1 -1
View File
@@ -1 +1 @@
3.19.2
3.20.0
+1 -1
View File
@@ -12,7 +12,7 @@ sqlite3_LDADD = @EXTRA_SHELL_OBJ@ @READLINE_LIBS@
sqlite3_DEPENDENCIES = @EXTRA_SHELL_OBJ@
sqlite3_CFLAGS = $(AM_CFLAGS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS
include_HEADERS = sqlite3.h sqlite3ext.h msvc.h
include_HEADERS = sqlite3.h sqlite3ext.h
EXTRA_DIST = sqlite3.1 tea Makefile.msc sqlite3.rc README.txt Replace.cs
pkgconfigdir = ${libdir}/pkgconfig
Vendored
+19 -19
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for sqlite 3.19.2.
# Generated by GNU Autoconf 2.69 for sqlite 3.20.0.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -726,8 +726,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='sqlite'
PACKAGE_TARNAME='sqlite'
PACKAGE_VERSION='3.19.2'
PACKAGE_STRING='sqlite 3.19.2'
PACKAGE_VERSION='3.20.0'
PACKAGE_STRING='sqlite 3.20.0'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -1463,7 +1463,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures sqlite 3.19.2 to adapt to many kinds of systems.
\`configure' configures sqlite 3.20.0 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1528,7 +1528,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of sqlite 3.19.2:";;
short | recursive ) echo "Configuration of sqlite 3.20.0:";;
esac
cat <<\_ACEOF
@@ -1652,7 +1652,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
sqlite configure 3.19.2
sqlite configure 3.20.0
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2071,7 +2071,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by sqlite $as_me 3.19.2, which was
It was created by sqlite $as_me 3.20.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -11356,7 +11356,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support MEMSYS5" >&5
$as_echo_n "checking whether to support MEMSYS5... " >&6; }
if test "${enable_memsys5}" = "yes"; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MEMSYS5"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS5"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
@@ -11373,7 +11373,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support MEMSYS3" >&5
$as_echo_n "checking whether to support MEMSYS3... " >&6; }
if test "${enable_memsys3}" = "yes" -a "${enable_memsys5}" = "no"; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MEMSYS3"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
@@ -11391,7 +11391,7 @@ else
fi
if test "${enable_fts3}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
fi
# Check whether --enable-fts4 was given.
if test "${enable_fts4+set}" = set; then :
@@ -11401,7 +11401,7 @@ else
fi
if test "${enable_fts4}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
$as_echo_n "checking for library containing log... " >&6; }
if ${ac_cv_search_log+:} false; then :
@@ -11467,7 +11467,7 @@ else
fi
if test "${enable_fts5}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS5"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
$as_echo_n "checking for library containing log... " >&6; }
if ${ac_cv_search_log+:} false; then :
@@ -11536,7 +11536,7 @@ else
fi
if test "${enable_json1}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
fi
#########
@@ -11549,7 +11549,7 @@ else
fi
if test "${enable_rtree}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
fi
#########
@@ -11562,12 +11562,12 @@ else
fi
if test "${enable_session}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_SESSION"
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
fi
#########
# attempt to duplicate any OMITS and ENABLES into the $(OPT_FEATURE_FLAGS) parameter
# attempt to duplicate any OMITS and ENABLES into the ${OPT_FEATURE_FLAGS} parameter
for option in $CFLAGS $CPPFLAGS
do
case $option in
@@ -12151,7 +12151,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by sqlite $as_me 3.19.2, which was
This file was extended by sqlite $as_me 3.20.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -12217,7 +12217,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
sqlite config.status 3.19.2
sqlite config.status 3.20.0
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
+10 -10
View File
@@ -596,7 +596,7 @@ AC_ARG_ENABLE(memsys5,
[enable_memsys5=yes],[enable_memsys5=no])
AC_MSG_CHECKING([whether to support MEMSYS5])
if test "${enable_memsys5}" = "yes"; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MEMSYS5"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS5"
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
@@ -606,7 +606,7 @@ AC_ARG_ENABLE(memsys3,
[enable_memsys3=yes],[enable_memsys3=no])
AC_MSG_CHECKING([whether to support MEMSYS3])
if test "${enable_memsys3}" = "yes" -a "${enable_memsys5}" = "no"; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MEMSYS3"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
@@ -618,20 +618,20 @@ AC_ARG_ENABLE(fts3, AC_HELP_STRING([--enable-fts3],
[Enable the FTS3 extension]),
[enable_fts3=yes],[enable_fts3=no])
if test "${enable_fts3}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
fi
AC_ARG_ENABLE(fts4, AC_HELP_STRING([--enable-fts4],
[Enable the FTS4 extension]),
[enable_fts4=yes],[enable_fts4=no])
if test "${enable_fts4}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
AC_SEARCH_LIBS([log],[m])
fi
AC_ARG_ENABLE(fts5, AC_HELP_STRING([--enable-fts5],
[Enable the FTS5 extension]),
[enable_fts5=yes],[enable_fts5=no])
if test "${enable_fts5}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS5"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
AC_SEARCH_LIBS([log],[m])
fi
@@ -641,7 +641,7 @@ AC_ARG_ENABLE(json1, AC_HELP_STRING([--enable-json1],
[Enable the JSON1 extension]),
[enable_json1=yes],[enable_json1=no])
if test "${enable_json1}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
fi
#########
@@ -650,7 +650,7 @@ AC_ARG_ENABLE(rtree, AC_HELP_STRING([--enable-rtree],
[Enable the RTREE extension]),
[enable_rtree=yes],[enable_rtree=no])
if test "${enable_rtree}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
fi
#########
@@ -659,12 +659,12 @@ AC_ARG_ENABLE(session, AC_HELP_STRING([--enable-session],
[Enable the SESSION extension]),
[enable_session=yes],[enable_session=no])
if test "${enable_session}" = "yes" ; then
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_SESSION"
OPT_FEATURE_FLAGS="$(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
fi
#########
# attempt to duplicate any OMITS and ENABLES into the $(OPT_FEATURE_FLAGS) parameter
# attempt to duplicate any OMITS and ENABLES into the ${OPT_FEATURE_FLAGS} parameter
for option in $CFLAGS $CPPFLAGS
do
case $option in
+20
View File
@@ -23,6 +23,26 @@ or embedded controllers.</p>
<p>This document is an introduction to the Lemon
parser generator.</p>
<h2>Security Note</h2>
<p>The language parser code created by Lemon is very robust and
is well-suited for use in internet-facing applications that need to
safely process maliciously crafted inputs.
<p>The "lemon.exe" command-line tool itself works great when given a valid
input grammar file and almost always gives helpful
error messages for malformed inputs. However, it is possible for
a malicious user to craft a grammar file that will cause
lemon.exe to crash.
We do not see this as a problem, as lemon.exe is not intended to be used
with hostile inputs.
To summarize:</p>
<ul>
<li>Parser code generated by lemon &rarr; Robust and secure
<li>The "lemon.exe" command line tool itself &rarr; Not so much
</ul>
<h2>Theory of Operation</h2>
<p>The main goal of Lemon is to translate a context free grammar (CFG)
+23 -13
View File
@@ -1707,6 +1707,19 @@ static void fts3CursorFinalizeStmt(Fts3Cursor *pCsr){
sqlite3_finalize(pCsr->pStmt);
}
/*
** Free all resources currently held by the cursor passed as the only
** argument.
*/
static void fts3ClearCursor(Fts3Cursor *pCsr){
fts3CursorFinalizeStmt(pCsr);
sqlite3Fts3FreeDeferredTokens(pCsr);
sqlite3_free(pCsr->aDoclist);
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
sqlite3Fts3ExprFree(pCsr->pExpr);
memset(&(&pCsr->base)[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
}
/*
** Close the cursor. For additional information see the documentation
** on the xClose method of the virtual table interface.
@@ -1714,11 +1727,7 @@ static void fts3CursorFinalizeStmt(Fts3Cursor *pCsr){
static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
fts3CursorFinalizeStmt(pCsr);
sqlite3Fts3ExprFree(pCsr->pExpr);
sqlite3Fts3FreeDeferredTokens(pCsr);
sqlite3_free(pCsr->aDoclist);
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
fts3ClearCursor(pCsr);
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
sqlite3_free(pCsr);
return SQLITE_OK;
@@ -1744,7 +1753,7 @@ static int fts3CursorSeekStmt(Fts3Cursor *pCsr){
}else{
zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
if( !zSql ) return SQLITE_NOMEM;
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
rc = sqlite3_prepare_v3(p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
sqlite3_free(zSql);
}
if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
@@ -3219,11 +3228,7 @@ static int fts3FilterMethod(
assert( iIdx==nVal );
/* In case the cursor has been used before, clear it now. */
fts3CursorFinalizeStmt(pCsr);
sqlite3_free(pCsr->aDoclist);
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
sqlite3Fts3ExprFree(pCsr->pExpr);
memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
fts3ClearCursor(pCsr);
/* Set the lower and upper bounds on docids to return */
pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -3281,7 +3286,7 @@ static int fts3FilterMethod(
);
}
if( zSql ){
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
rc = sqlite3_prepare_v3(p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
sqlite3_free(zSql);
}else{
rc = SQLITE_NOMEM;
@@ -3302,7 +3307,12 @@ static int fts3FilterMethod(
** routine to find out if it has reached the end of a result set.
*/
static int fts3EofMethod(sqlite3_vtab_cursor *pCursor){
return ((Fts3Cursor *)pCursor)->isEof;
Fts3Cursor *pCsr = (Fts3Cursor*)pCursor;
if( pCsr->isEof ){
fts3ClearCursor(pCsr);
pCsr->isEof = 1;
}
return pCsr->isEof;
}
/*
+2 -1
View File
@@ -407,7 +407,8 @@ static int fts3SqlStmt(
if( !zSql ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
rc = sqlite3_prepare_v3(p->db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
&pStmt, NULL);
sqlite3_free(zSql);
assert( rc==SQLITE_OK || pStmt==0 );
p->aStmt[eStmt] = pStmt;
+4 -3
View File
@@ -171,10 +171,11 @@ static int fts5HashResize(Fts5Hash *pHash){
for(i=0; i<pHash->nSlot; i++){
while( apOld[i] ){
int iHash;
unsigned int iHash;
Fts5HashEntry *p = apOld[i];
apOld[i] = p->pHashNext;
iHash = fts5HashKey(nNew, (u8*)fts5EntryKey(p), strlen(fts5EntryKey(p)));
iHash = fts5HashKey(nNew, (u8*)fts5EntryKey(p),
(int)strlen(fts5EntryKey(p)));
p->pHashNext = apNew[iHash];
apNew[iHash] = p;
}
@@ -477,7 +478,7 @@ int sqlite3Fts5HashQuery(
int *pnDoclist /* OUT: Size of doclist in bytes */
){
unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
char *zKey;
char *zKey = 0;
Fts5HashEntry *p;
for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
+4 -2
View File
@@ -728,7 +728,8 @@ static int fts5IndexPrepareStmt(
){
if( p->rc==SQLITE_OK ){
if( zSql ){
p->rc = sqlite3_prepare_v2(p->pConfig->db, zSql, -1, ppStmt, 0);
p->rc = sqlite3_prepare_v3(p->pConfig->db, zSql, -1,
SQLITE_PREPARE_PERSISTENT, ppStmt, 0);
}else{
p->rc = SQLITE_NOMEM;
}
@@ -777,7 +778,8 @@ static void fts5DataDelete(Fts5Index *p, i64 iFirst, i64 iLast){
if( zSql==0 ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p->pDeleter, 0);
rc = sqlite3_prepare_v3(pConfig->db, zSql, -1,
SQLITE_PREPARE_PERSISTENT, &p->pDeleter, 0);
sqlite3_free(zSql);
}
if( rc!=SQLITE_OK ){
+4 -2
View File
@@ -883,7 +883,8 @@ static int fts5PrepareStatement(
if( zSql==0 ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0);
rc = sqlite3_prepare_v3(pConfig->db, zSql, -1,
SQLITE_PREPARE_PERSISTENT, &pRet, 0);
if( rc!=SQLITE_OK ){
*pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db));
}
@@ -1019,7 +1020,8 @@ static int fts5FindRankFunction(Fts5Cursor *pCsr){
char *zSql = sqlite3Fts5Mprintf(&rc, "SELECT %s", zRankArgs);
if( zSql ){
sqlite3_stmt *pStmt = 0;
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pStmt, 0);
rc = sqlite3_prepare_v3(pConfig->db, zSql, -1,
SQLITE_PREPARE_PERSISTENT, &pStmt, 0);
sqlite3_free(zSql);
assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
if( rc==SQLITE_OK ){
+2 -1
View File
@@ -136,7 +136,8 @@ static int fts5StorageGetStmt(
if( zSql==0 ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_prepare_v2(pC->db, zSql, -1, &p->aStmt[eStmt], 0);
rc = sqlite3_prepare_v3(pC->db, zSql, -1,
SQLITE_PREPARE_PERSISTENT, &p->aStmt[eStmt], 0);
sqlite3_free(zSql);
if( rc!=SQLITE_OK && pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
+1 -1
View File
@@ -182,7 +182,7 @@ static int fts5tokConnectMethod(
Fts5tokTable *pTab = 0;
int rc;
char **azDequote = 0;
int nDequote;
int nDequote = 0;
rc = sqlite3_declare_vtab(db,
"CREATE TABLE x(input HIDDEN, token, start, end, position)"
+1 -3
View File
@@ -441,7 +441,7 @@ db func funk funk
do_catchsql_test 16.2 {
SELECT funk(), bm25(n1), funk() FROM n1 WHERE n1 MATCH 'a+b+c+d'
} {0 {{} -1e-06 {}}}
# {1 {SQL logic error or missing database}}
# {1 {SQL logic error}}
#-------------------------------------------------------------------------
#
@@ -595,5 +595,3 @@ do_execsql_test 22.1 {
finish_test
-1
View File
@@ -294,4 +294,3 @@ do_execsql_test 7.0 {
finish_test
-1
View File
@@ -276,4 +276,3 @@ foreach {tn expr tclexpr} {
}
finish_test
-1
View File
@@ -242,4 +242,3 @@ foreach {T create} {
}
finish_test
-1
View File
@@ -309,4 +309,3 @@ foreach {tn q cnt} {
}
finish_test
-1
View File
@@ -178,4 +178,3 @@ do_execsql_test 5.1 {
} ;# foreach_detail_mode
finish_test
-1
View File
@@ -142,4 +142,3 @@ if {[detail_is_full]} {
finish_test
-1
View File
@@ -167,4 +167,3 @@ do_execsql_test 1.8.2 {
#db eval {SELECT rowid, fts5_decode(rowid, block) aS r FROM t1_data} {puts $r}
finish_test
-1
View File
@@ -55,4 +55,3 @@ do_execsql_test 1.2 {
finish_test
-1
View File
@@ -66,4 +66,3 @@ do_execsql_test 2.0 { INSERT INTO t1(t1) VALUES('integrity-check') }
finish_test
-1
View File
@@ -147,4 +147,3 @@ do_execsql_test 3.1 {
}
finish_test
+1 -2
View File
@@ -77,7 +77,7 @@ foreach {tn defn} {
} {
do_test 2.2.$tn {
catchsql { INSERT INTO ft1(ft1, rank) VALUES('rank', $defn) }
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
}
#-------------------------------------------------------------------------
@@ -297,4 +297,3 @@ do_catchsql_test 4.4.4 {
finish_test
-1
View File
@@ -100,4 +100,3 @@ do_execsql_test 3.3 {
} {1 2}
finish_test
-1
View File
@@ -342,4 +342,3 @@ foreach {tn expr} {
finish_test
-1
View File
@@ -279,4 +279,3 @@ do_execsql_test 9.3 {
finish_test
-1
View File
@@ -112,4 +112,3 @@ db eval {
}
finish_test
-1
View File
@@ -61,4 +61,3 @@ do_test 2.1...slow {
} {}
finish_test
-2
View File
@@ -64,5 +64,3 @@ foreach_detail_mode $::testprefix {
}
finish_test
-2
View File
@@ -84,5 +84,3 @@ foreach_detail_mode $::testprefix {
finish_test
+14 -15
View File
@@ -66,7 +66,7 @@ foreach {tn val} {
} {
do_catchsql_test 3.$tn {
INSERT INTO t1(t1, rank) VALUES('rank', $val);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
}
#-------------------------------------------------------------------------
@@ -169,33 +169,33 @@ do_execsql_test 9.0 {
} {}
do_catchsql_test 9.1.1 {
INSERT INTO abc(abc, rank) VALUES('pgsz', -5);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.1.2 {
INSERT INTO abc(abc, rank) VALUES('pgsz', 50000000);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.1.3 {
INSERT INTO abc(abc, rank) VALUES('pgsz', 66.67);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.2.1 {
INSERT INTO abc(abc, rank) VALUES('automerge', -5);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.2.2 {
INSERT INTO abc(abc, rank) VALUES('automerge', 50000000);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.2.3 {
INSERT INTO abc(abc, rank) VALUES('automerge', 66.67);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_execsql_test 9.2.4 {
INSERT INTO abc(abc, rank) VALUES('automerge', 1);
} {}
do_catchsql_test 9.3.1 {
INSERT INTO abc(abc, rank) VALUES('crisismerge', -5);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.3.2 {
INSERT INTO abc(abc, rank) VALUES('crisismerge', 66.67);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_execsql_test 9.3.3 {
INSERT INTO abc(abc, rank) VALUES('crisismerge', 1);
} {}
@@ -205,14 +205,14 @@ do_execsql_test 9.3.4 {
do_catchsql_test 9.4.1 {
INSERT INTO abc(abc, rank) VALUES('nosuchoption', 1);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.5.1 {
INSERT INTO abc(abc, rank) VALUES('hashsize', 'not an integer');
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.5.2 {
INSERT INTO abc(abc, rank) VALUES('hashsize', -500000);
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
do_catchsql_test 9.5.3 {
INSERT INTO abc(abc, rank) VALUES('hashsize', 500000);
} {0 {}}
@@ -245,7 +245,7 @@ foreach {tn opt} {
do_catchsql_test 12.1 {
INSERT INTO t1(t1, rank) VALUES('rank', NULL);;
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
#-------------------------------------------------------------------------
# errors in the 'usermerge' option
@@ -260,8 +260,7 @@ foreach {tn val} {
4 1
} {
set sql "INSERT INTO tt(tt, rank) VALUES('usermerge', $val)"
do_catchsql_test 13.$tn $sql {1 {SQL logic error or missing database}}
do_catchsql_test 13.$tn $sql {1 {SQL logic error}}
}
finish_test
-2
View File
@@ -66,5 +66,3 @@ do_execsql_test 2.1 {
}
finish_test
-1
View File
@@ -255,4 +255,3 @@ do_execsql_test 6.2 {
finish_test
-1
View File
@@ -96,4 +96,3 @@ do_catchsql_test 3.1 {
} {1 {database disk image is malformed}}
finish_test
-1
View File
@@ -269,4 +269,3 @@ do_catchsql_test 6.2 {
sqlite3_fts5_may_be_corrupt 0
finish_test
-1
View File
@@ -409,4 +409,3 @@ do_catchsql_test 9.2.2 {
sqlite3_fts5_may_be_corrupt 0
finish_test
-1
View File
@@ -51,4 +51,3 @@ do_test 1.2 {
} {}
finish_test
-1
View File
@@ -241,4 +241,3 @@ do_execsql_test 5.3 {
finish_test
-2
View File
@@ -63,5 +63,3 @@ foreach_detail_mode $::testprefix {
finish_test
-1
View File
@@ -197,4 +197,3 @@ foreach v $vocab {
finish_test
-1
View File
@@ -44,4 +44,3 @@ do_execsql_test 1.2 {
finish_test
-3
View File
@@ -81,6 +81,3 @@ do_execsql_test 3.3 {
finish_test
-1
View File
@@ -351,4 +351,3 @@ do_faultsim_test 9.1 -faults oom-* -prep {
finish_test
-1
View File
@@ -137,4 +137,3 @@ do_faultsim_test 5.0 -faults oom-* -prep {
}
finish_test
-1
View File
@@ -110,4 +110,3 @@ do_faultsim_test 3.2 -faults oom-* -prep {
finish_test
-1
View File
@@ -395,4 +395,3 @@ do_faultsim_test 14.1 -faults oom-t* -prep {
}
finish_test
-1
View File
@@ -130,4 +130,3 @@ do_faultsim_test 3.3 -faults oom-t* -body {
finish_test
-1
View File
@@ -292,4 +292,3 @@ do_faultsim_test 6 -faults oom* -prep {
db close
}
finish_test
-1
View File
@@ -116,4 +116,3 @@ do_faultsim_test 2.2 -faults oom-* -body {
}
finish_test
-1
View File
@@ -82,4 +82,3 @@ do_faultsim_test 4 -faults oom-* -prep {
finish_test
-1
View File
@@ -153,4 +153,3 @@ do_faultsim_test 6 -faults oom-* -body {
} ;# foreach_detail_mode...
finish_test
-1
View File
@@ -61,4 +61,3 @@ do_faultsim_test 2 -faults oom* -prep {
faultsim_test_result {0 {1 2}}
}
finish_test
-1
View File
@@ -132,4 +132,3 @@ do_faultsim_test 4.2 -faults oom* -body {
finish_test
-1
View File
@@ -40,4 +40,3 @@ do_test 1.1 {
finish_test
-1
View File
@@ -90,4 +90,3 @@ do_catchsql_test 4.1 {
} {1 {fts5: syntax error near "`"}}
finish_test
-1
View File
@@ -130,4 +130,3 @@ breakpoint
} ;# foreach_detail_mode
finish_test
-1
View File
@@ -210,4 +210,3 @@ foreach {tn pgsz} {
}
finish_test
-1
View File
@@ -70,4 +70,3 @@ do_execsql_test 1.6 {
finish_test
+43
View File
@@ -0,0 +1,43 @@
# 2014 June 17
#
# 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 implements regression tests for SQLite library. The
# focus of this script is testing the FTS5 module.
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5leftjoin
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE vt USING fts5(x);
INSERT INTO vt VALUES('abc');
INSERT INTO vt VALUES('xyz');
CREATE TABLE t1(a INTEGER PRIMARY KEY);
INSERT INTO t1 VALUES(1), (2);
}
do_execsql_test 1.1 {
SELECT * FROM t1 LEFT JOIN (
SELECT rowid AS rrr, * FROM vt WHERE vt MATCH 'abc'
) ON t1.a = rrr
} {1 1 abc 2 {} {}}
do_execsql_test 1.2 {
SELECT * FROM t1 LEFT JOIN vt ON (vt MATCH 'abc')
} {1 abc 2 abc}
finish_test
-1
View File
@@ -492,4 +492,3 @@ do_catchsql_test 14.2 {
} {1 {unrecognized matchinfo flag: d}}
finish_test
-1
View File
@@ -241,4 +241,3 @@ do_execsql_test 6.3 {
finish_test
-1
View File
@@ -55,4 +55,3 @@ do_execsql_test 1.2 {
}
finish_test
-1
View File
@@ -45,4 +45,3 @@ do_multiclient_test tn {
};# do_multiclient_test
};# foreach_detail_mode
finish_test
-1
View File
@@ -68,4 +68,3 @@ do_near_test 1.25 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 4) } 0
finish_test
-1
View File
@@ -178,4 +178,3 @@ do_execsql_test 4.3.1 {
do_test 4.2.2 { fts5_level_segs ttt } {3}
finish_test
-1
View File
@@ -106,4 +106,3 @@ foreach {tn nStep} {
do_test 2.$tn.6 { fts5_segcount t1 } 1
}
finish_test
-1
View File
@@ -116,4 +116,3 @@ do_execsql_test 2.0 {
}
finish_test
-1
View File
@@ -64,4 +64,3 @@ do_eqp_test 1.5 {
finish_test
-1
View File
@@ -11803,4 +11803,3 @@ foreach {in out} $test_vocab {
finish_test
-1
View File
@@ -67,4 +67,3 @@ foreach {in out} $test_vocab {
finish_test
-2
View File
@@ -341,5 +341,3 @@ foreach {tn create} {
}
finish_test
-2
View File
@@ -79,5 +79,3 @@ for {set tn 1 ; set pgsz 64} {$tn<32} {incr tn; incr pgsz 16} {
finish_test
+1 -1
View File
@@ -90,6 +90,7 @@ do_test 2.7 {
execsql { SELECT rowid FROM tt('a') ORDER BY rank; } db
} {1 3 2}
db2 close
#--------------------------------------------------------------------------
# At one point there was a problem with queries such as:
@@ -151,4 +152,3 @@ do_execsql_test 4.1 {
finish_test
-1
View File
@@ -64,4 +64,3 @@ do_catchsql_test 2.2 {
INSERT INTO nc(nc) VALUES('rebuild');
} {1 {'rebuild' may not be used with a contentless fts5 table}}
finish_test
-1
View File
@@ -149,4 +149,3 @@ do_test 4.3 {
finish_test
-1
View File
@@ -216,4 +216,3 @@ do_execsql_test 6.2 {
finish_test
-1
View File
@@ -370,4 +370,3 @@ do_execsql_test 17.6 {
#db eval {SELECT rowid, fts5_decode_none(rowid, block) aS r FROM t2_data} {puts $r}
finish_test
-1
View File
@@ -116,4 +116,3 @@ do_execsql_test 4.6 {
finish_test
-1
View File
@@ -421,4 +421,3 @@ do_execsql_test 7.1.2 {
} ;# foreach_detail_mode
finish_test
-1
View File
@@ -161,4 +161,3 @@ foreach {tn expr} {
}
finish_test
+1 -1
View File
@@ -109,7 +109,7 @@ do_catchsql_test 2.0 {
do_catchsql_test 2.1 {
CREATE VIRTUAL TABLE t4 USING fts5tokenize;
SELECT * FROM t4;
} {1 {SQL logic error or missing database}}
} {1 {SQL logic error}}
finish_test
-1
View File
@@ -302,4 +302,3 @@ do_test 9.5.2 { set ::flags } {query}
finish_test
-1
View File
@@ -59,4 +59,3 @@ do_execsql_test 2.1 "
finish_test
-1
View File
@@ -126,4 +126,3 @@ do_test 1.5 {
finish_test
-1
View File
@@ -76,4 +76,3 @@ do_execsql_test 3.2 {
finish_test
-2
View File
@@ -117,5 +117,3 @@ do_execsql_test 2.2.integrity {
}
finish_test
-1
View File
@@ -61,4 +61,3 @@ do_test 1.7 {
finish_test
+56
View File
@@ -0,0 +1,56 @@
#
# This Makefile is designed for use with main.mk in the root directory of
# this project. After including main.mk, the users makefile should contain:
#
# LSMDIR=$(TOP)/ext/lsm1/
# include $(LSMDIR)/Makefile
#
# The most useful targets are [lsmtest] and [lsm.so].
#
LSMOBJ = \
lsm_ckpt.o \
lsm_file.o \
lsm_log.o \
lsm_main.o \
lsm_mem.o \
lsm_mutex.o \
lsm_shared.o \
lsm_sorted.o \
lsm_str.o \
lsm_tree.o \
lsm_unix.o \
lsm_win32.o \
lsm_varint.o \
lsm_vtab.o
LSMHDR = \
$(LSMDIR)/lsm.h \
$(LSMDIR)/lsmInt.h
LSMTESTSRC = $(LSMDIR)/lsm-test/lsmtest1.c $(LSMDIR)/lsm-test/lsmtest2.c \
$(LSMDIR)/lsm-test/lsmtest3.c $(LSMDIR)/lsm-test/lsmtest4.c \
$(LSMDIR)/lsm-test/lsmtest5.c $(LSMDIR)/lsm-test/lsmtest6.c \
$(LSMDIR)/lsm-test/lsmtest7.c $(LSMDIR)/lsm-test/lsmtest8.c \
$(LSMDIR)/lsm-test/lsmtest9.c \
$(LSMDIR)/lsm-test/lsmtest_datasource.c \
$(LSMDIR)/lsm-test/lsmtest_func.c $(LSMDIR)/lsm-test/lsmtest_io.c \
$(LSMDIR)/lsm-test/lsmtest_main.c $(LSMDIR)/lsm-test/lsmtest_mem.c \
$(LSMDIR)/lsm-test/lsmtest_tdb.c $(LSMDIR)/lsm-test/lsmtest_tdb3.c \
$(LSMDIR)/lsm-test/lsmtest_util.c $(LSMDIR)/lsm-test/lsmtest_win32.c
# all: lsm.so
LSMOPTS = -DLSM_MUTEX_PTHREADS=1 -I$(LSMDIR)
lsm.so: $(LSMOBJ)
$(TCCX) -shared -o lsm.so $(LSMOBJ)
%.o: $(LSMDIR)/%.c $(LSMHDR) sqlite3.h
$(TCCX) $(LSMOPTS) -c $<
lsmtest$(EXE): $(LSMOBJ) $(LSMTESTSRC) $(LSMTESTHDR) sqlite3.o
# $(TCPPX) -c $(TOP)/lsm-test/lsmtest_tdb2.cc
$(TCCX) $(LSMOPTS) $(LSMTESTSRC) $(LSMOBJ) sqlite3.o -o lsmtest$(EXE) $(THREADLIB)
+100
View File
@@ -0,0 +1,100 @@
#
# This Makefile is designed for use with main.mk in the root directory of
# this project. After including main.mk, the users makefile should contain:
#
# LSMDIR=$(TOP)\ext\lsm1\
# include $(LSMDIR)\Makefile.msc
#
# The most useful targets are [lsmtest.exe] and [lsm.dll].
#
LSMOBJ = \
lsm_ckpt.lo \
lsm_file.lo \
lsm_log.lo \
lsm_main.lo \
lsm_mem.lo \
lsm_mutex.lo \
lsm_shared.lo \
lsm_sorted.lo \
lsm_str.lo \
lsm_tree.lo \
lsm_unix.lo \
lsm_win32.lo \
lsm_varint.lo \
lsm_vtab.lo
LSMHDR = \
$(LSMDIR)\lsm.h \
$(LSMDIR)\lsmInt.h
LSMTESTSRC = $(LSMDIR)\lsm-test\lsmtest1.c $(LSMDIR)\lsm-test\lsmtest2.c \
$(LSMDIR)\lsm-test\lsmtest3.c $(LSMDIR)\lsm-test\lsmtest4.c \
$(LSMDIR)\lsm-test\lsmtest5.c $(LSMDIR)\lsm-test\lsmtest6.c \
$(LSMDIR)\lsm-test\lsmtest7.c $(LSMDIR)\lsm-test\lsmtest8.c \
$(LSMDIR)\lsm-test\lsmtest9.c \
$(LSMDIR)\lsm-test\lsmtest_datasource.c \
$(LSMDIR)\lsm-test\lsmtest_func.c $(LSMDIR)\lsm-test\lsmtest_io.c \
$(LSMDIR)\lsm-test\lsmtest_main.c $(LSMDIR)\lsm-test\lsmtest_mem.c \
$(LSMDIR)\lsm-test\lsmtest_tdb.c $(LSMDIR)\lsm-test\lsmtest_tdb3.c \
$(LSMDIR)\lsm-test\lsmtest_util.c $(LSMDIR)\lsm-test\lsmtest_win32.c
# all: lsm.dll
LSMOPTS = -DLSM_MUTEX_WIN32=1 -I$(LSMDIR)
!IF $(DEBUG)>2
LSMOPTS = $(LSMOPTS) -DLSM_DEBUG=1
!ENDIF
!IF $(MEMDEBUG)!=0
LSMOPTS = $(LSMOPTS) -DLSM_DEBUG_MEM=1
!ENDIF
lsm_ckpt.lo: $(LSMDIR)\lsm_ckpt.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_ckpt.c
lsm_file.lo: $(LSMDIR)\lsm_file.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_file.c
lsm_log.lo: $(LSMDIR)\lsm_log.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_log.c
lsm_main.lo: $(LSMDIR)\lsm_main.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_main.c
lsm_mem.lo: $(LSMDIR)\lsm_mem.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_mem.c
lsm_mutex.lo: $(LSMDIR)\lsm_mutex.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_mutex.c
lsm_shared.lo: $(LSMDIR)\lsm_shared.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_shared.c
lsm_sorted.lo: $(LSMDIR)\lsm_sorted.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_sorted.c
lsm_str.lo: $(LSMDIR)\lsm_str.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_str.c
lsm_tree.lo: $(LSMDIR)\lsm_tree.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_tree.c
lsm_unix.lo: $(LSMDIR)\lsm_unix.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_unix.c
lsm_win32.lo: $(LSMDIR)\lsm_win32.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_win32.c
lsm_varint.lo: $(LSMDIR)\lsm_varint.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_varint.c
lsm_vtab.lo: $(LSMDIR)\lsm_vtab.c $(LSMHDR) $(SQLITE3H)
$(LTCOMPILE) $(LSMOPTS) -c $(LSMDIR)\lsm_vtab.c
lsm.dll: $(LSMOBJ)
$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ $(LSMOBJ)
lsmtest.exe: $(LSMOBJ) $(LSMTESTSRC) $(LSMTESTHDR) $(LIBOBJS1)
$(LTLINK) $(LSMOPTS) $(LSMTESTSRC) /link $(LSMOBJ) $(LIBOBJS1)
+40
View File
@@ -0,0 +1,40 @@
Organization of test case files:
lsmtest1.c: Data tests. Tests that perform many inserts and deletes on a
database file, then verify that the contents of the database can
be queried.
lsmtest2.c: Crash tests. Tests that attempt to verify that the database
recovers correctly following an application or system crash.
lsmtest3.c: Rollback tests. Tests that focus on the explicit rollback of
transactions and sub-transactions.
lsmtest4.c: Multi-client tests.
lsmtest5.c: Multi-client tests with a different thread for each client.
lsmtest6.c: OOM injection tests.
lsmtest7.c: API tests.
lsmtest8.c: Writer crash tests. Tests in this file attempt to verify that
the system recovers and other clients proceed unaffected if
a process fails in the middle of a write transaction.
The difference from lsmtest2.c is that this file tests
live-recovery (recovery from a failure that occurs while other
clients are still running) whereas lsmtest2.c tests recovery
from a system or power failure.
lsmtest9.c: More data tests. These focus on testing that calling
lsm_work(nMerge=1) to compact the database does not corrupt it.
In other words, that databases containing block-redirects
can be read and written.
+292
View File
@@ -0,0 +1,292 @@
#ifndef __WRAPPER_INT_H_
#define __WRAPPER_INT_H_
#include "lsmtest_tdb.h"
#include "sqlite3.h"
#include "lsm.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _O_BINARY
# define _O_BINARY (0)
#endif
#ifdef _WIN32
# include "windows.h"
# define gettimeofday win32GetTimeOfDay
# define F_OK (0)
# define sleep(sec) Sleep(1000 * (sec))
# define usleep(usec) Sleep(((usec) + 999) / 1000)
# ifdef _MSC_VER
# include <io.h>
# define snprintf _snprintf
# define fsync(fd) FlushFileBuffers((HANDLE)_get_osfhandle((fd)))
# define fdatasync(fd) FlushFileBuffers((HANDLE)_get_osfhandle((fd)))
# define __va_copy(dst,src) ((dst) = (src))
# define ftruncate(fd,sz) ((_chsize_s((fd), (sz))==0) ? 0 : -1)
# else
# error Unsupported C compiler for Windows.
# endif
int win32GetTimeOfDay(struct timeval *, void *);
#endif
#ifndef _LSM_INT_H
typedef unsigned int u32;
typedef unsigned char u8;
typedef long long int i64;
typedef unsigned long long int u64;
#endif
#define ArraySize(x) ((int)(sizeof(x) / sizeof((x)[0])))
#define MIN(x,y) ((x)<(y) ? (x) : (y))
#define MAX(x,y) ((x)>(y) ? (x) : (y))
#define unused_parameter(x) (void)(x)
#define TESTDB_DEFAULT_PAGE_SIZE 4096
#define TESTDB_DEFAULT_CACHE_SIZE 2048
/*
** Ideally, these should be in wrapper.c. But they are here instead so that
** they can be used by the C++ database wrappers in wrapper2.cc.
*/
typedef struct DatabaseMethods DatabaseMethods;
struct TestDb {
DatabaseMethods const *pMethods; /* Database methods */
const char *zLibrary; /* Library name for tdb_open() */
};
struct DatabaseMethods {
int (*xClose)(TestDb *);
int (*xWrite)(TestDb *, void *, int , void *, int);
int (*xDelete)(TestDb *, void *, int);
int (*xDeleteRange)(TestDb *, void *, int, void *, int);
int (*xFetch)(TestDb *, void *, int, void **, int *);
int (*xScan)(TestDb *, void *, int, void *, int, void *, int,
void (*)(void *, void *, int , void *, int)
);
int (*xBegin)(TestDb *, int);
int (*xCommit)(TestDb *, int);
int (*xRollback)(TestDb *, int);
};
/*
** Functions in wrapper2.cc (a C++ source file). wrapper2.cc contains the
** wrapper for Kyoto Cabinet. Kyoto cabinet has a C API, but
** the primary interface is the C++ API.
*/
int test_kc_open(const char*, const char *zFilename, int bClear, TestDb **ppDb);
int test_kc_close(TestDb *);
int test_kc_write(TestDb *, void *, int , void *, int);
int test_kc_delete(TestDb *, void *, int);
int test_kc_delete_range(TestDb *, void *, int, void *, int);
int test_kc_fetch(TestDb *, void *, int, void **, int *);
int test_kc_scan(TestDb *, void *, int, void *, int, void *, int,
void (*)(void *, void *, int , void *, int)
);
int test_mdb_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_mdb_close(TestDb *);
int test_mdb_write(TestDb *, void *, int , void *, int);
int test_mdb_delete(TestDb *, void *, int);
int test_mdb_fetch(TestDb *, void *, int, void **, int *);
int test_mdb_scan(TestDb *, void *, int, void *, int, void *, int,
void (*)(void *, void *, int , void *, int)
);
/*
** Functions in wrapper3.c. This file contains the tdb wrapper for lsm.
** The wrapper for lsm is a bit more involved than the others, as it
** includes code for a couple of different lsm configurations, and for
** various types of fault injection and robustness testing.
*/
int test_lsm_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_lsm_lomem_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_zip_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_small_open(const char*, const char*, int bClear, TestDb **ppDb);
int test_lsm_mt2(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_lsm_mt3(const char*, const char *zFile, int bClear, TestDb **ppDb);
int tdb_lsm_configure(lsm_db *, const char *);
/* Functions in lsmtest_tdb4.c */
int test_bt_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_fbt_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
int test_fbts_open(const char*, const char *zFile, int bClear, TestDb **ppDb);
/* Functions in testutil.c. */
int testPrngInit(void);
u32 testPrngValue(u32 iVal);
void testPrngArray(u32 iVal, u32 *aOut, int nOut);
void testPrngString(u32 iVal, char *aOut, int nOut);
void testErrorInit(int argc, char **);
void testPrintError(const char *zFormat, ...);
void testPrintUsage(const char *zArgs);
void testPrintFUsage(const char *zFormat, ...);
void testTimeInit(void);
int testTimeGet(void);
/* Functions in testmem.c. */
void testMallocInstall(lsm_env *pEnv);
void testMallocUninstall(lsm_env *pEnv);
void testMallocCheck(lsm_env *pEnv, int *, int *, FILE *);
void testMallocOom(lsm_env *pEnv, int, int, void(*)(void*), void *);
void testMallocOomEnable(lsm_env *pEnv, int);
/* lsmtest.c */
TestDb *testOpen(const char *zSystem, int, int *pRc);
void testReopen(TestDb **ppDb, int *pRc);
void testClose(TestDb **ppDb);
void testFetch(TestDb *, void *, int, void *, int, int *);
void testWrite(TestDb *, void *, int, void *, int, int *);
void testDelete(TestDb *, void *, int, int *);
void testDeleteRange(TestDb *, void *, int, void *, int, int *);
void testWriteStr(TestDb *, const char *, const char *zVal, int *pRc);
void testFetchStr(TestDb *, const char *, const char *, int *pRc);
void testBegin(TestDb *pDb, int iTrans, int *pRc);
void testCommit(TestDb *pDb, int iTrans, int *pRc);
void test_failed(void);
char *testMallocPrintf(const char *zFormat, ...);
char *testMallocVPrintf(const char *zFormat, va_list ap);
int testGlobMatch(const char *zPattern, const char *zStr);
void testScanCompare(TestDb *, TestDb *, int, void *, int, void *, int, int *);
void testFetchCompare(TestDb *, TestDb *, void *, int, int *);
void *testMalloc(int);
void *testMallocCopy(void *pCopy, int nByte);
void *testRealloc(void *, int);
void testFree(void *);
/* lsmtest_bt.c */
int do_bt(int nArg, char **azArg);
/* testio.c */
int testVfsConfigureDb(TestDb *pDb);
/* testfunc.c */
int do_show(int nArg, char **azArg);
int do_work(int nArg, char **azArg);
/* testio.c */
int do_io(int nArg, char **azArg);
/* lsmtest2.c */
void do_crash_test(const char *zPattern, int *pRc);
int do_rollback_test(int nArg, char **azArg);
/* test3.c */
void test_rollback(const char *zSystem, const char *zPattern, int *pRc);
/* test4.c */
void test_mc(const char *zSystem, const char *zPattern, int *pRc);
/* test5.c */
void test_mt(const char *zSystem, const char *zPattern, int *pRc);
/* lsmtest6.c */
void test_oom(const char *zPattern, int *pRc);
void testDeleteLsmdb(const char *zFile);
void testSaveDb(const char *zFile, const char *zAuxExt);
void testRestoreDb(const char *zFile, const char *zAuxExt);
void testCopyLsmdb(const char *zFrom, const char *zTo);
/* lsmtest7.c */
void test_api(const char *zPattern, int *pRc);
/* lsmtest8.c */
void do_writer_crash_test(const char *zPattern, int *pRc);
/*************************************************************************
** Interface to functionality in test_datasource.c.
*/
typedef struct Datasource Datasource;
typedef struct DatasourceDefn DatasourceDefn;
struct DatasourceDefn {
int eType; /* A TEST_DATASOURCE_* value */
int nMinKey; /* Minimum key size */
int nMaxKey; /* Maximum key size */
int nMinVal; /* Minimum value size */
int nMaxVal; /* Maximum value size */
};
#define TEST_DATASOURCE_RANDOM 1
#define TEST_DATASOURCE_SEQUENCE 2
char *testDatasourceName(const DatasourceDefn *);
Datasource *testDatasourceNew(const DatasourceDefn *);
void testDatasourceFree(Datasource *);
void testDatasourceEntry(Datasource *, int, void **, int *, void **, int *);
/* End of test_datasource.c interface.
*************************************************************************/
void testDatasourceFetch(
TestDb *pDb, /* Database handle */
Datasource *pData,
int iKey,
int *pRc /* IN/OUT: Error code */
);
void testWriteDatasource(TestDb *, Datasource *, int, int *);
void testWriteDatasourceRange(TestDb *, Datasource *, int, int, int *);
void testDeleteDatasource(TestDb *, Datasource *, int, int *);
void testDeleteDatasourceRange(TestDb *, Datasource *, int, int, int *);
/* test1.c */
void test_data_1(const char *, const char *, int *pRc);
void test_data_2(const char *, const char *, int *pRc);
void test_data_3(const char *, const char *, int *pRc);
void testDbContents(TestDb *, Datasource *, int, int, int, int, int, int *);
void testCaseProgress(int, int, int, int *);
int testCaseNDot(void);
void testCompareDb(Datasource *, int, int, TestDb *, TestDb *, int *);
int testControlDb(TestDb **ppDb);
typedef struct CksumDb CksumDb;
CksumDb *testCksumArrayNew(Datasource *, int, int, int);
char *testCksumArrayGet(CksumDb *, int);
void testCksumArrayFree(CksumDb *);
void testCaseStart(int *pRc, char *zFmt, ...);
void testCaseFinish(int rc);
void testCaseSkip(void);
int testCaseBegin(int *, const char *, const char *, ...);
#define TEST_CKSUM_BYTES 29
int testCksumDatabase(TestDb *pDb, char *zOut);
int testCountDatabase(TestDb *pDb);
void testCompareInt(int, int, int *);
void testCompareStr(const char *z1, const char *z2, int *pRc);
/* lsmtest9.c */
void test_data_4(const char *, const char *, int *pRc);
/*
** Similar to the Tcl_GetIndexFromObjStruct() Tcl library function.
*/
#define testArgSelect(w,x,y,z) testArgSelectX(w,x,sizeof(w[0]),y,z)
int testArgSelectX(void *, const char *, int, const char *, int *);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif
+654
View File
@@ -0,0 +1,654 @@
#include "lsmtest.h"
#define DATA_SEQUENTIAL TEST_DATASOURCE_SEQUENCE
#define DATA_RANDOM TEST_DATASOURCE_RANDOM
typedef struct Datatest1 Datatest1;
typedef struct Datatest2 Datatest2;
/*
** An instance of the following structure contains parameters used to
** customize the test function in this file. Test procedure:
**
** 1. Create a data-source based on the "datasource definition" vars.
**
** 2. Insert nRow key value pairs into the database.
**
** 3. Delete all keys from the database. Deletes are done in the same
** order as the inserts.
**
** During steps 2 and 3 above, after each Datatest1.nVerify inserts or
** deletes, the following:
**
** a. Run Datasource.nTest key lookups and check the results are as expected.
**
** b. If Datasource.bTestScan is true, run a handful (8) of range
** queries (scanning forwards and backwards). Check that the results
** are as expected.
**
** c. Close and reopen the database. Then run (a) and (b) again.
*/
struct Datatest1 {
/* Datasource definition */
DatasourceDefn defn;
/* Test procedure parameters */
int nRow; /* Number of rows to insert then delete */
int nVerify; /* How often to verify the db contents */
int nTest; /* Number of keys to test (0==all) */
int bTestScan; /* True to do scan tests */
};
/*
** An instance of the following data structure is used to describe the
** second type of test case in this file. The chief difference between
** these tests and those described by Datatest1 is that these tests also
** experiment with range-delete operations. Tests proceed as follows:
**
** 1. Open the datasource described by Datatest2.defn.
**
** 2. Open a connection on an empty database.
**
** 3. Do this Datatest2.nIter times:
**
** a) Insert Datatest2.nWrite key-value pairs from the datasource.
**
** b) Select two pseudo-random keys and use them as the start
** and end points of a range-delete operation.
**
** c) Verify that the contents of the database are as expected (see
** below for details).
**
** d) Close and then reopen the database handle.
**
** e) Verify that the contents of the database are still as expected.
**
** The inserts and range deletes are run twice - once on the database being
** tested and once using a control system (sqlite3, kc etc. - something that
** works). In order to verify that the contents of the db being tested are
** correct, the test runs a bunch of scans and lookups on both the test and
** control databases. If the results are the same, the test passes.
*/
struct Datatest2 {
DatasourceDefn defn;
int nRange;
int nWrite; /* Number of writes per iteration */
int nIter; /* Total number of iterations to run */
};
/*
** Generate a unique name for the test case pTest with database system
** zSystem.
*/
static char *getName(const char *zSystem, int bRecover, Datatest1 *pTest){
char *zRet;
char *zData;
zData = testDatasourceName(&pTest->defn);
zRet = testMallocPrintf("data.%s.%s.rec=%d.%d.%d",
zSystem, zData, bRecover, pTest->nRow, pTest->nVerify
);
testFree(zData);
return zRet;
}
int testControlDb(TestDb **ppDb){
#ifdef HAVE_KYOTOCABINET
return tdb_open("kyotocabinet", "tmp.db", 1, ppDb);
#else
return tdb_open("sqlite3", "", 1, ppDb);
#endif
}
void testDatasourceFetch(
TestDb *pDb, /* Database handle */
Datasource *pData,
int iKey,
int *pRc /* IN/OUT: Error code */
){
void *pKey; int nKey; /* Database key to query for */
void *pVal; int nVal; /* Expected result of query */
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
testFetch(pDb, pKey, nKey, pVal, nVal, pRc);
}
/*
** This function is called to test that the contents of database pDb
** are as expected. In this case, expected is defined as containing
** key-value pairs iFirst through iLast, inclusive, from data source
** pData. In other words, a loop like the following could be used to
** construct a database with identical contents from scratch.
**
** for(i=iFirst; i<=iLast; i++){
** testDatasourceEntry(pData, i, &pKey, &nKey, &pVal, &nVal);
** // insert (pKey, nKey) -> (pVal, nVal) into database
** }
**
** The key domain consists of keys 0 to (nRow-1), inclusive, from
** data source pData. For both scan and lookup tests, keys are selected
** pseudo-randomly from within this set.
**
** This function runs nLookupTest lookup tests and nScanTest scan tests.
**
** A lookup test consists of selecting a key from the domain and querying
** pDb for it. The test fails if the presence of the key and, if present,
** the associated value do not match the expectations defined above.
**
** A scan test involves selecting a key from the domain and running
** the following queries:
**
** 1. Scan all keys equal to or greater than the key, in ascending order.
** 2. Scan all keys equal to or smaller than the key, in descending order.
**
** Additionally, if nLookupTest is greater than zero, the following are
** run once:
**
** 1. Scan all keys in the db, in ascending order.
** 2. Scan all keys in the db, in descending order.
**
** As you would assume, the test fails if the returned values do not match
** expectations.
*/
void testDbContents(
TestDb *pDb, /* Database handle being tested */
Datasource *pData, /* pDb contains data from here */
int nRow, /* Size of key domain */
int iFirst, /* Index of first key from pData in pDb */
int iLast, /* Index of last key from pData in pDb */
int nLookupTest, /* Number of lookup tests to run */
int nScanTest, /* Number of scan tests to run */
int *pRc /* IN/OUT: Error code */
){
int j;
int rc = *pRc;
if( rc==0 && nScanTest ){
TestDb *pDb2 = 0;
/* Open a control db (i.e. one that we assume works) */
rc = testControlDb(&pDb2);
for(j=iFirst; rc==0 && j<=iLast; j++){
void *pKey; int nKey; /* Database key to insert */
void *pVal; int nVal; /* Database value to insert */
testDatasourceEntry(pData, j, &pKey, &nKey, &pVal, &nVal);
rc = tdb_write(pDb2, pKey, nKey, pVal, nVal);
}
if( rc==0 ){
int iKey1;
int iKey2;
void *pKey1; int nKey1; /* Start key */
void *pKey2; int nKey2; /* Final key */
iKey1 = testPrngValue((iFirst<<8) + (iLast<<16)) % nRow;
iKey2 = testPrngValue((iLast<<8) + (iFirst<<16)) % nRow;
testDatasourceEntry(pData, iKey1, &pKey2, &nKey1, 0, 0);
pKey1 = testMalloc(nKey1+1);
memcpy(pKey1, pKey2, nKey1+1);
testDatasourceEntry(pData, iKey2, &pKey2, &nKey2, 0, 0);
testScanCompare(pDb2, pDb, 0, 0, 0, 0, 0, &rc);
testScanCompare(pDb2, pDb, 0, 0, 0, pKey2, nKey2, &rc);
testScanCompare(pDb2, pDb, 0, pKey1, nKey1, 0, 0, &rc);
testScanCompare(pDb2, pDb, 0, pKey1, nKey1, pKey2, nKey2, &rc);
testScanCompare(pDb2, pDb, 1, 0, 0, 0, 0, &rc);
testScanCompare(pDb2, pDb, 1, 0, 0, pKey2, nKey2, &rc);
testScanCompare(pDb2, pDb, 1, pKey1, nKey1, 0, 0, &rc);
testScanCompare(pDb2, pDb, 1, pKey1, nKey1, pKey2, nKey2, &rc);
testFree(pKey1);
}
tdb_close(pDb2);
}
/* Test some lookups. */
for(j=0; rc==0 && j<nLookupTest; j++){
int iKey; /* Datasource key to test */
void *pKey; int nKey; /* Database key to query for */
void *pVal; int nVal; /* Expected result of query */
if( nLookupTest>=nRow ){
iKey = j;
}else{
iKey = testPrngValue(j + (iFirst<<8) + (iLast<<16)) % nRow;
}
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
if( iFirst>iKey || iKey>iLast ){
pVal = 0;
nVal = -1;
}
testFetch(pDb, pKey, nKey, pVal, nVal, &rc);
}
*pRc = rc;
}
/*
** This function should be called during long running test cases to output
** the progress dots (...) to stdout.
*/
void testCaseProgress(int i, int n, int nDot, int *piDot){
int iDot = *piDot;
while( iDot < ( ((nDot*2+1) * i) / (n*2) ) ){
printf(".");
fflush(stdout);
iDot++;
}
*piDot = iDot;
}
int testCaseNDot(void){ return 20; }
#if 0
static void printScanCb(
void *pCtx, void *pKey, int nKey, void *pVal, int nVal
){
printf("%s\n", (char *)pKey);
fflush(stdout);
}
#endif
void testReopenRecover(TestDb **ppDb, int *pRc){
if( *pRc==0 ){
const char *zLib = tdb_library_name(*ppDb);
const char *zDflt = tdb_default_db(zLib);
testCopyLsmdb(zDflt, "bak.db");
testClose(ppDb);
testCopyLsmdb("bak.db", zDflt);
*pRc = tdb_open(zLib, 0, 0, ppDb);
}
}
static void doDataTest1(
const char *zSystem, /* Database system to test */
int bRecover,
Datatest1 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
int i;
int iDot;
int rc = LSM_OK;
Datasource *pData;
TestDb *pDb;
/* Start the test case, open a database and allocate the datasource. */
pDb = testOpen(zSystem, 1, &rc);
pData = testDatasourceNew(&p->defn);
i = 0;
iDot = 0;
while( rc==LSM_OK && i<p->nRow ){
/* Insert some data */
testWriteDatasourceRange(pDb, pData, i, p->nVerify, &rc);
i += p->nVerify;
/* Check that the db content is correct. */
testDbContents(pDb, pData, p->nRow, 0, i-1, p->nTest, p->bTestScan, &rc);
if( bRecover ){
testReopenRecover(&pDb, &rc);
}else{
testReopen(&pDb, &rc);
}
/* Check that the db content is still correct. */
testDbContents(pDb, pData, p->nRow, 0, i-1, p->nTest, p->bTestScan, &rc);
/* Update the progress dots... */
testCaseProgress(i, p->nRow, testCaseNDot()/2, &iDot);
}
i = 0;
iDot = 0;
while( rc==LSM_OK && i<p->nRow ){
/* Delete some entries */
testDeleteDatasourceRange(pDb, pData, i, p->nVerify, &rc);
i += p->nVerify;
/* Check that the db content is correct. */
testDbContents(pDb, pData, p->nRow, i, p->nRow-1,p->nTest,p->bTestScan,&rc);
/* Close and reopen the database. */
if( bRecover ){
testReopenRecover(&pDb, &rc);
}else{
testReopen(&pDb, &rc);
}
/* Check that the db content is still correct. */
testDbContents(pDb, pData, p->nRow, i, p->nRow-1,p->nTest,p->bTestScan,&rc);
/* Update the progress dots... */
testCaseProgress(i, p->nRow, testCaseNDot()/2, &iDot);
}
/* Free the datasource, close the database and finish the test case. */
testDatasourceFree(pData);
tdb_close(pDb);
testCaseFinish(rc);
*pRc = rc;
}
void test_data_1(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest1 aTest[] = {
{ {DATA_RANDOM, 500,600, 1000,2000}, 1000, 100, 10, 0},
{ {DATA_RANDOM, 20,25, 100,200}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,10, 100,200}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,10, 10,20}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,10, 1000,2000}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 8,100, 10000,20000}, 100, 25, 100, 1},
{ {DATA_RANDOM, 80,100, 10,20}, 1000, 250, 1000, 1},
{ {DATA_RANDOM, 5000,6000, 10,20}, 100, 25, 100, 1},
{ {DATA_SEQUENTIAL, 5,10, 10,20}, 1000, 250, 1000, 1},
{ {DATA_SEQUENTIAL, 5,10, 100,200}, 1000, 250, 1000, 1},
{ {DATA_SEQUENTIAL, 5,10, 1000,2000}, 1000, 250, 1000, 1},
{ {DATA_SEQUENTIAL, 5,100, 10000,20000}, 100, 25, 100, 1},
{ {DATA_RANDOM, 10,10, 100,100}, 100000, 1000, 100, 0},
{ {DATA_SEQUENTIAL, 10,10, 100,100}, 100000, 1000, 100, 0},
};
int i;
int bRecover;
for(bRecover=0; bRecover<2; bRecover++){
if( bRecover==1 && memcmp(zSystem, "lsm", 3) ) break;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName(zSystem, bRecover, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest1(zSystem, bRecover, &aTest[i], pRc);
}
testFree(zName);
}
}
}
void testCompareDb(
Datasource *pData,
int nData,
int iSeed,
TestDb *pControl,
TestDb *pDb,
int *pRc
){
int i;
static int nCall = 0;
nCall++;
testScanCompare(pControl, pDb, 0, 0, 0, 0, 0, pRc);
testScanCompare(pControl, pDb, 1, 0, 0, 0, 0, pRc);
if( *pRc==0 ){
int iKey1;
int iKey2;
void *pKey1; int nKey1; /* Start key */
void *pKey2; int nKey2; /* Final key */
iKey1 = testPrngValue(iSeed) % nData;
iKey2 = testPrngValue(iSeed+1) % nData;
testDatasourceEntry(pData, iKey1, &pKey2, &nKey1, 0, 0);
pKey1 = testMalloc(nKey1+1);
memcpy(pKey1, pKey2, nKey1+1);
testDatasourceEntry(pData, iKey2, &pKey2, &nKey2, 0, 0);
testScanCompare(pControl, pDb, 0, 0, 0, pKey2, nKey2, pRc);
testScanCompare(pControl, pDb, 0, pKey1, nKey1, 0, 0, pRc);
testScanCompare(pControl, pDb, 0, pKey1, nKey1, pKey2, nKey2, pRc);
testScanCompare(pControl, pDb, 1, 0, 0, pKey2, nKey2, pRc);
testScanCompare(pControl, pDb, 1, pKey1, nKey1, 0, 0, pRc);
testScanCompare(pControl, pDb, 1, pKey1, nKey1, pKey2, nKey2, pRc);
testFree(pKey1);
}
for(i=0; i<nData && *pRc==0; i++){
void *pKey; int nKey;
testDatasourceEntry(pData, i, &pKey, &nKey, 0, 0);
testFetchCompare(pControl, pDb, pKey, nKey, pRc);
}
}
static void doDataTest2(
const char *zSystem, /* Database system to test */
int bRecover,
Datatest2 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
TestDb *pDb;
TestDb *pControl;
Datasource *pData;
int i;
int rc = LSM_OK;
int iDot = 0;
/* Start the test case, open a database and allocate the datasource. */
pDb = testOpen(zSystem, 1, &rc);
pData = testDatasourceNew(&p->defn);
rc = testControlDb(&pControl);
if( tdb_lsm(pDb) ){
int nBuf = 32 * 1024 * 1024;
lsm_config(tdb_lsm(pDb), LSM_CONFIG_AUTOFLUSH, &nBuf);
}
for(i=0; rc==0 && i<p->nIter; i++){
void *pKey1; int nKey1;
void *pKey2; int nKey2;
int ii;
int nRange = MIN(p->nIter*p->nWrite, p->nRange);
for(ii=0; rc==0 && ii<p->nWrite; ii++){
int iKey = (i*p->nWrite + ii) % p->nRange;
testWriteDatasource(pControl, pData, iKey, &rc);
testWriteDatasource(pDb, pData, iKey, &rc);
}
testDatasourceEntry(pData, i+1000000, &pKey1, &nKey1, 0, 0);
pKey1 = testMallocCopy(pKey1, nKey1);
testDatasourceEntry(pData, i+2000000, &pKey2, &nKey2, 0, 0);
testDeleteRange(pDb, pKey1, nKey1, pKey2, nKey2, &rc);
testDeleteRange(pControl, pKey1, nKey1, pKey2, nKey2, &rc);
testFree(pKey1);
testCompareDb(pData, nRange, i, pControl, pDb, &rc);
if( bRecover ){
testReopenRecover(&pDb, &rc);
}else{
testReopen(&pDb, &rc);
}
testCompareDb(pData, nRange, i, pControl, pDb, &rc);
/* Update the progress dots... */
testCaseProgress(i, p->nIter, testCaseNDot(), &iDot);
}
testClose(&pDb);
testClose(&pControl);
testDatasourceFree(pData);
testCaseFinish(rc);
*pRc = rc;
}
static char *getName2(const char *zSystem, int bRecover, Datatest2 *pTest){
char *zRet;
char *zData;
zData = testDatasourceName(&pTest->defn);
zRet = testMallocPrintf("data2.%s.%s.rec=%d.%d.%d.%d",
zSystem, zData, bRecover, pTest->nRange, pTest->nWrite, pTest->nIter
);
testFree(zData);
return zRet;
}
void test_data_2(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest2 aTest[] = {
/* defn, nRange, nWrite, nIter */
{ {DATA_RANDOM, 20,25, 100,200}, 10000, 10, 50 },
{ {DATA_RANDOM, 20,25, 100,200}, 10000, 200, 50 },
{ {DATA_RANDOM, 20,25, 100,200}, 100, 10, 1000 },
{ {DATA_RANDOM, 20,25, 100,200}, 100, 200, 50 },
};
int i;
int bRecover;
for(bRecover=0; bRecover<2; bRecover++){
if( bRecover==1 && memcmp(zSystem, "lsm", 3) ) break;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName2(zSystem, bRecover, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest2(zSystem, bRecover, &aTest[i], pRc);
}
testFree(zName);
}
}
}
/*************************************************************************
** Test case data3.*
*/
typedef struct Datatest3 Datatest3;
struct Datatest3 {
int nRange; /* Keys are between 1 and this value, incl. */
int nIter; /* Number of iterations */
int nWrite; /* Number of writes per iteration */
int nDelete; /* Number of deletes per iteration */
int nValMin; /* Minimum value size for writes */
int nValMax; /* Maximum value size for writes */
};
void testPutU32(u8 *aBuf, u32 iVal){
aBuf[0] = (iVal >> 24) & 0xFF;
aBuf[1] = (iVal >> 16) & 0xFF;
aBuf[2] = (iVal >> 8) & 0xFF;
aBuf[3] = (iVal >> 0) & 0xFF;
}
void dt3PutKey(u8 *aBuf, int iKey){
assert( iKey<100000 && iKey>=0 );
sprintf((char *)aBuf, "%.5d", iKey);
}
static void doDataTest3(
const char *zSystem, /* Database system to test */
Datatest3 *p, /* Structure containing test parameters */
int *pRc /* OUT: Error code */
){
int iDot = 0;
int rc = *pRc;
TestDb *pDb;
u8 *abPresent; /* Array of boolean */
char *aVal; /* Buffer to hold values */
int i;
u32 iSeq = 10; /* prng counter */
abPresent = (u8 *)testMalloc(p->nRange+1);
aVal = (char *)testMalloc(p->nValMax+1);
pDb = testOpen(zSystem, 1, &rc);
for(i=0; i<p->nIter && rc==0; i++){
int ii;
testCaseProgress(i, p->nIter, testCaseNDot(), &iDot);
/* Perform nWrite inserts */
for(ii=0; ii<p->nWrite; ii++){
u8 aKey[6];
u32 iKey;
int nVal;
iKey = (testPrngValue(iSeq++) % p->nRange) + 1;
nVal = (testPrngValue(iSeq++) % (p->nValMax - p->nValMin)) + p->nValMin;
testPrngString(testPrngValue(iSeq++), aVal, nVal);
dt3PutKey(aKey, iKey);
testWrite(pDb, aKey, sizeof(aKey)-1, aVal, nVal, &rc);
abPresent[iKey] = 1;
}
/* Perform nDelete deletes */
for(ii=0; ii<p->nDelete; ii++){
u8 aKey1[6];
u8 aKey2[6];
u32 iKey;
iKey = (testPrngValue(iSeq++) % p->nRange) + 1;
dt3PutKey(aKey1, iKey-1);
dt3PutKey(aKey2, iKey+1);
testDeleteRange(pDb, aKey1, sizeof(aKey1)-1, aKey2, sizeof(aKey2)-1, &rc);
abPresent[iKey] = 0;
}
testReopen(&pDb, &rc);
for(ii=1; rc==0 && ii<=p->nRange; ii++){
int nDbVal;
void *pDbVal;
u8 aKey[6];
int dbrc;
dt3PutKey(aKey, ii);
dbrc = tdb_fetch(pDb, aKey, sizeof(aKey)-1, &pDbVal, &nDbVal);
testCompareInt(0, dbrc, &rc);
if( abPresent[ii] ){
testCompareInt(1, (nDbVal>0), &rc);
}else{
testCompareInt(1, (nDbVal<0), &rc);
}
}
}
testClose(&pDb);
testCaseFinish(rc);
*pRc = rc;
}
static char *getName3(const char *zSystem, Datatest3 *p){
return testMallocPrintf("data3.%s.%d.%d.%d.%d.(%d..%d)",
zSystem, p->nRange, p->nIter, p->nWrite, p->nDelete,
p->nValMin, p->nValMax
);
}
void test_data_3(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Datatest3 aTest[] = {
/* nRange, nIter, nWrite, nDelete, nValMin, nValMax */
{ 100, 1000, 5, 5, 50, 100 },
{ 100, 1000, 2, 2, 5, 10 },
};
int i;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName3(zSystem, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest3(zSystem, &aTest[i], pRc);
}
testFree(zName);
}
}
+488
View File
@@ -0,0 +1,488 @@
/*
** This file contains tests related to recovery following application
** and system crashes (power failures) while writing to the database.
*/
#include "lsmtest.h"
/*
** Structure used by testCksumDatabase() to accumulate checksum values in.
*/
typedef struct Cksum Cksum;
struct Cksum {
int nRow;
int cksum1;
int cksum2;
};
/*
** tdb_scan() callback used by testCksumDatabase()
*/
static void scanCksumDb(
void *pCtx,
void *pKey, int nKey,
void *pVal, int nVal
){
Cksum *p = (Cksum *)pCtx;
int i;
p->nRow++;
for(i=0; i<nKey; i++){
p->cksum1 += ((u8 *)pKey)[i];
p->cksum2 += p->cksum1;
}
for(i=0; i<nVal; i++){
p->cksum1 += ((u8 *)pVal)[i];
p->cksum2 += p->cksum1;
}
}
/*
** tdb_scan() callback used by testCountDatabase()
*/
static void scanCountDb(
void *pCtx,
void *pKey, int nKey,
void *pVal, int nVal
){
Cksum *p = (Cksum *)pCtx;
p->nRow++;
unused_parameter(pKey);
unused_parameter(nKey);
unused_parameter(pVal);
unused_parameter(nVal);
}
/*
** Iterate through the entire contents of database pDb. Write a checksum
** string based on the db contents into buffer zOut before returning. A
** checksum string is at most 29 (TEST_CKSUM_BYTES) bytes in size:
**
** * 32-bit integer (10 bytes)
** * 1 space (1 byte)
** * 32-bit hex (8 bytes)
** * 1 space (1 byte)
** * 32-bit hex (8 bytes)
** * nul-terminator (1 byte)
**
** The number of entries in the database is returned.
*/
int testCksumDatabase(
TestDb *pDb, /* Database handle */
char *zOut /* Buffer to write checksum to */
){
Cksum cksum;
memset(&cksum, 0, sizeof(Cksum));
tdb_scan(pDb, (void *)&cksum, 0, 0, 0, 0, 0, scanCksumDb);
sprintf(zOut, "%d %x %x",
cksum.nRow, (u32)cksum.cksum1, (u32)cksum.cksum2
);
assert( strlen(zOut)<TEST_CKSUM_BYTES );
return cksum.nRow;
}
int testCountDatabase(TestDb *pDb){
Cksum cksum;
memset(&cksum, 0, sizeof(Cksum));
tdb_scan(pDb, (void *)&cksum, 0, 0, 0, 0, 0, scanCountDb);
return cksum.nRow;
}
/*
** This function is a no-op if *pRc is not 0 when it is called.
**
** Otherwise, the two nul-terminated strings z1 and z1 are compared. If
** they are the same, the function returns without doing anything. Otherwise,
** an error message is printed, *pRc is set to 1 and the test_failed()
** function called.
*/
void testCompareStr(const char *z1, const char *z2, int *pRc){
if( *pRc==0 ){
if( strcmp(z1, z2) ){
testPrintError("testCompareStr: \"%s\" != \"%s\"\n", z1, z2);
*pRc = 1;
test_failed();
}
}
}
/*
** This function is a no-op if *pRc is not 0 when it is called.
**
** Otherwise, the two integers i1 and i2 are compared. If they are equal,
** the function returns without doing anything. Otherwise, an error message
** is printed, *pRc is set to 1 and the test_failed() function called.
*/
void testCompareInt(int i1, int i2, int *pRc){
if( *pRc==0 && i1!=i2 ){
testPrintError("testCompareInt: %d != %d\n", i1, i2);
*pRc = 1;
test_failed();
}
}
void testCaseStart(int *pRc, char *zFmt, ...){
va_list ap;
va_start(ap, zFmt);
vprintf(zFmt, ap);
printf(" ...");
va_end(ap);
*pRc = 0;
fflush(stdout);
}
/*
** This function is a no-op if *pRc is non-zero when it is called. Zero
** is returned in this case.
**
** Otherwise, the zFmt (a printf style format string) and following arguments
** are used to create a test case name. If zPattern is NULL or a glob pattern
** that matches the test case name, 1 is returned and the test case started.
** Otherwise, zero is returned and the test case does not start.
*/
int testCaseBegin(int *pRc, const char *zPattern, const char *zFmt, ...){
int res = 0;
if( *pRc==0 ){
char *zTest;
va_list ap;
va_start(ap, zFmt);
zTest = testMallocVPrintf(zFmt, ap);
va_end(ap);
if( zPattern==0 || testGlobMatch(zPattern, zTest) ){
printf("%-50s ...", zTest);
res = 1;
}
testFree(zTest);
fflush(stdout);
}
return res;
}
void testCaseFinish(int rc){
if( rc==0 ){
printf("Ok\n");
}else{
printf("FAILED\n");
}
fflush(stdout);
}
void testCaseSkip(){
printf("Skipped\n");
}
void testSetupSavedLsmdb(
const char *zCfg,
const char *zFile,
Datasource *pData,
int nRow,
int *pRc
){
if( *pRc==0 ){
int rc;
TestDb *pDb;
rc = tdb_lsm_open(zCfg, zFile, 1, &pDb);
if( rc==0 ){
testWriteDatasourceRange(pDb, pData, 0, nRow, &rc);
testClose(&pDb);
if( rc==0 ) testSaveDb(zFile, "log");
}
*pRc = rc;
}
}
/*
** This function is a no-op if *pRc is non-zero when it is called.
**
** Open the LSM database identified by zFile and compute its checksum
** (a string, as returned by testCksumDatabase()). If the checksum is
** identical to zExpect1 or, if it is not NULL, zExpect2, the test passes.
** Otherwise, print an error message and set *pRc to 1.
*/
static void testCompareCksumLsmdb(
const char *zFile, /* Path to LSM database */
int bCompress, /* True if db is compressed */
const char *zExpect1, /* Expected checksum 1 */
const char *zExpect2, /* Expected checksum 2 (or NULL) */
int *pRc /* IN/OUT: Test case error code */
){
if( *pRc==0 ){
char zCksum[TEST_CKSUM_BYTES];
TestDb *pDb;
*pRc = tdb_lsm_open((bCompress?"compression=1 mmap=0":""), zFile, 0, &pDb);
testCksumDatabase(pDb, zCksum);
testClose(&pDb);
if( *pRc==0 ){
int r1 = 0;
int r2 = -1;
r1 = strcmp(zCksum, zExpect1);
if( zExpect2 ) r2 = strcmp(zCksum, zExpect2);
if( r1 && r2 ){
if( zExpect2 ){
testPrintError("testCompareCksumLsmdb: \"%s\" != (\"%s\" OR \"%s\")",
zCksum, zExpect1, zExpect2
);
}else{
testPrintError("testCompareCksumLsmdb: \"%s\" != \"%s\"",
zCksum, zExpect1
);
}
*pRc = 1;
test_failed();
}
}
}
}
#if 0 /* not used */
static void testCompareCksumBtdb(
const char *zFile, /* Path to LSM database */
const char *zExpect1, /* Expected checksum 1 */
const char *zExpect2, /* Expected checksum 2 (or NULL) */
int *pRc /* IN/OUT: Test case error code */
){
if( *pRc==0 ){
char zCksum[TEST_CKSUM_BYTES];
TestDb *pDb;
*pRc = tdb_open("bt", zFile, 0, &pDb);
testCksumDatabase(pDb, zCksum);
testClose(&pDb);
if( *pRc==0 ){
int r1 = 0;
int r2 = -1;
r1 = strcmp(zCksum, zExpect1);
if( zExpect2 ) r2 = strcmp(zCksum, zExpect2);
if( r1 && r2 ){
if( zExpect2 ){
testPrintError("testCompareCksumLsmdb: \"%s\" != (\"%s\" OR \"%s\")",
zCksum, zExpect1, zExpect2
);
}else{
testPrintError("testCompareCksumLsmdb: \"%s\" != \"%s\"",
zCksum, zExpect1
);
}
*pRc = 1;
test_failed();
}
}
}
}
#endif /* not used */
/* Above this point are reusable test routines. Not clear that they
** should really be in this file.
*************************************************************************/
/*
** This test verifies that if a system crash occurs while doing merge work
** on the db, no data is lost.
*/
static void crash_test1(int bCompress, int *pRc){
const char *DBNAME = "testdb.lsm";
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 200, 200};
const int nRow = 5000; /* Database size */
const int nIter = 200; /* Number of test iterations */
const int nWork = 20; /* Maximum lsm_work() calls per iteration */
const int nPage = 15; /* Pages per lsm_work call */
int i;
int iDot = 0;
Datasource *pData;
CksumDb *pCksumDb;
TestDb *pDb;
char *zCfg;
const char *azConfig[2] = {
"page_size=1024 block_size=65536 autoflush=16384 safety=2 mmap=0",
"page_size=1024 block_size=65536 autoflush=16384 safety=2 "
" compression=1 mmap=0"
};
assert( bCompress==0 || bCompress==1 );
/* Allocate datasource. And calculate the expected checksums. */
pData = testDatasourceNew(&defn);
pCksumDb = testCksumArrayNew(pData, nRow, nRow, 1);
/* Setup and save the initial database. */
zCfg = testMallocPrintf("%s automerge=7", azConfig[bCompress]);
testSetupSavedLsmdb(zCfg, DBNAME, pData, 5000, pRc);
testFree(zCfg);
for(i=0; i<nIter && *pRc==0; i++){
int iWork;
int testrc = 0;
testCaseProgress(i, nIter, testCaseNDot(), &iDot);
/* Restore and open the database. */
testRestoreDb(DBNAME, "log");
testrc = tdb_lsm_open(azConfig[bCompress], DBNAME, 0, &pDb);
assert( testrc==0 );
/* Call lsm_work() on the db */
tdb_lsm_prepare_sync_crash(pDb, 1 + (i%(nWork*2)));
for(iWork=0; testrc==0 && iWork<nWork; iWork++){
int nWrite = 0;
lsm_db *db = tdb_lsm(pDb);
testrc = lsm_work(db, 0, nPage, &nWrite);
/* assert( testrc!=0 || nWrite>0 ); */
if( testrc==0 ) testrc = lsm_checkpoint(db, 0);
}
tdb_close(pDb);
/* Check that the database content is still correct */
testCompareCksumLsmdb(DBNAME,
bCompress, testCksumArrayGet(pCksumDb, nRow), 0, pRc);
}
testCksumArrayFree(pCksumDb);
testDatasourceFree(pData);
}
/*
** This test verifies that if a system crash occurs while committing a
** transaction to the log file, no earlier transactions are lost or damaged.
*/
static void crash_test2(int bCompress, int *pRc){
const char *DBNAME = "testdb.lsm";
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 1000, 1000};
const int nIter = 200;
const int nInsert = 20;
int i;
int iDot = 0;
Datasource *pData;
CksumDb *pCksumDb;
TestDb *pDb;
/* Allocate datasource. And calculate the expected checksums. */
pData = testDatasourceNew(&defn);
pCksumDb = testCksumArrayNew(pData, 100, 100+nInsert, 1);
/* Setup and save the initial database. */
testSetupSavedLsmdb("", DBNAME, pData, 100, pRc);
for(i=0; i<nIter && *pRc==0; i++){
int iIns;
int testrc = 0;
testCaseProgress(i, nIter, testCaseNDot(), &iDot);
/* Restore and open the database. */
testRestoreDb(DBNAME, "log");
testrc = tdb_lsm_open("safety=2", DBNAME, 0, &pDb);
assert( testrc==0 );
/* Insert nInsert records into the database. Crash midway through. */
tdb_lsm_prepare_sync_crash(pDb, 1 + (i%(nInsert+2)));
for(iIns=0; iIns<nInsert; iIns++){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, 100+iIns, &pKey, &nKey, &pVal, &nVal);
testrc = tdb_write(pDb, pKey, nKey, pVal, nVal);
if( testrc ) break;
}
tdb_close(pDb);
/* Check that no data was lost when the system crashed. */
testCompareCksumLsmdb(DBNAME, bCompress,
testCksumArrayGet(pCksumDb, 100 + iIns),
testCksumArrayGet(pCksumDb, 100 + iIns + 1),
pRc
);
}
testDatasourceFree(pData);
testCksumArrayFree(pCksumDb);
}
/*
** This test verifies that if a system crash occurs when checkpointing
** the database, data is not lost (assuming that any writes not synced
** to the db have been synced into the log file).
*/
static void crash_test3(int bCompress, int *pRc){
const char *DBNAME = "testdb.lsm";
const int nIter = 100;
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 1000, 1000};
int i;
int iDot = 0;
Datasource *pData;
CksumDb *pCksumDb;
TestDb *pDb;
/* Allocate datasource. And calculate the expected checksums. */
pData = testDatasourceNew(&defn);
pCksumDb = testCksumArrayNew(pData, 110, 150, 10);
/* Setup and save the initial database. */
testSetupSavedLsmdb("", DBNAME, pData, 100, pRc);
for(i=0; i<nIter && *pRc==0; i++){
int iOpen;
testCaseProgress(i, nIter, testCaseNDot(), &iDot);
testRestoreDb(DBNAME, "log");
for(iOpen=0; iOpen<5; iOpen++){
/* Open the database. Insert 10 more records. */
pDb = testOpen("lsm", 0, pRc);
testWriteDatasourceRange(pDb, pData, 100+iOpen*10, 10, pRc);
/* Schedule a crash simulation then close the db. */
tdb_lsm_prepare_sync_crash(pDb, 1 + (i%2));
tdb_close(pDb);
/* Open the database and check that the crash did not cause any
** data loss. */
testCompareCksumLsmdb(DBNAME, bCompress,
testCksumArrayGet(pCksumDb, 110 + iOpen*10), 0,
pRc
);
}
}
testDatasourceFree(pData);
testCksumArrayFree(pCksumDb);
}
void do_crash_test(const char *zPattern, int *pRc){
struct Test {
const char *zTest;
void (*x)(int, int *);
int bCompress;
} aTest [] = {
{ "crash.lsm.1", crash_test1, 0 },
#ifdef HAVE_ZLIB
{ "crash.lsm_zip.1", crash_test1, 1 },
#endif
{ "crash.lsm.2", crash_test2, 0 },
{ "crash.lsm.3", crash_test3, 0 },
};
int i;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
struct Test *p = &aTest[i];
if( testCaseBegin(pRc, zPattern, "%s", p->zTest) ){
p->x(p->bCompress, pRc);
testCaseFinish(*pRc);
}
}
}
+238
View File
@@ -0,0 +1,238 @@
/*
** This file contains tests related to the explicit rollback of database
** transactions and sub-transactions.
*/
/*
** Repeat 2000 times (until the db contains 100,000 entries):
**
** 1. Open a transaction and insert 500 rows, opening a nested
** sub-transaction each 100 rows.
**
** 2. Roll back to each sub-transaction savepoint. Check the database
** checksum looks Ok.
**
** 3. Every second iteration, roll back the main transaction. Check the
** db checksum is correct. Every other iteration, commit the main
** transaction (increasing the size of the db by 100 rows).
*/
#include "lsmtest.h"
struct CksumDb {
int nFirst;
int nLast;
int nStep;
char **azCksum;
};
CksumDb *testCksumArrayNew(
Datasource *pData,
int nFirst,
int nLast,
int nStep
){
TestDb *pDb;
CksumDb *pRet;
int i;
int nEntry;
int rc = 0;
assert( nLast>=nFirst && ((nLast-nFirst)%nStep)==0 );
pRet = malloc(sizeof(CksumDb));
memset(pRet, 0, sizeof(CksumDb));
pRet->nFirst = nFirst;
pRet->nLast = nLast;
pRet->nStep = nStep;
nEntry = 1 + ((nLast - nFirst) / nStep);
/* Allocate space so that azCksum is an array of nEntry pointers to
** buffers each TEST_CKSUM_BYTES in size. */
pRet->azCksum = (char **)malloc(nEntry * (sizeof(char *) + TEST_CKSUM_BYTES));
for(i=0; i<nEntry; i++){
char *pStart = (char *)(&pRet->azCksum[nEntry]);
pRet->azCksum[i] = &pStart[i * TEST_CKSUM_BYTES];
}
tdb_open("lsm", "tempdb.lsm", 1, &pDb);
testWriteDatasourceRange(pDb, pData, 0, nFirst, &rc);
for(i=0; i<nEntry; i++){
testCksumDatabase(pDb, pRet->azCksum[i]);
if( i==nEntry ) break;
testWriteDatasourceRange(pDb, pData, nFirst+i*nStep, nStep, &rc);
}
tdb_close(pDb);
return pRet;
}
char *testCksumArrayGet(CksumDb *p, int nRow){
int i;
assert( nRow>=p->nFirst );
assert( nRow<=p->nLast );
assert( ((nRow-p->nFirst) % p->nStep)==0 );
i = (nRow - p->nFirst) / p->nStep;
return p->azCksum[i];
}
void testCksumArrayFree(CksumDb *p){
free(p->azCksum);
memset(p, 0x55, sizeof(*p));
free(p);
}
/* End of CksumDb code.
**************************************************************************/
/*
** Test utility function. Write key-value pair $i from datasource pData
** into database pDb.
*/
void testWriteDatasource(TestDb *pDb, Datasource *pData, int i, int *pRc){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, i, &pKey, &nKey, &pVal, &nVal);
testWrite(pDb, pKey, nKey, pVal, nVal, pRc);
}
/*
** Test utility function. Delete datasource pData key $i from database pDb.
*/
void testDeleteDatasource(TestDb *pDb, Datasource *pData, int i, int *pRc){
void *pKey; int nKey;
testDatasourceEntry(pData, i, &pKey, &nKey, 0, 0);
testDelete(pDb, pKey, nKey, pRc);
}
/*
** This function inserts nWrite key/value pairs into database pDb - the
** nWrite key value pairs starting at iFirst from data source pData.
*/
void testWriteDatasourceRange(
TestDb *pDb, /* Database to write to */
Datasource *pData, /* Data source to read values from */
int iFirst, /* Index of first key/value pair */
int nWrite, /* Number of key/value pairs to write */
int *pRc /* IN/OUT: Error code */
){
int i;
for(i=0; i<nWrite; i++){
testWriteDatasource(pDb, pData, iFirst+i, pRc);
}
}
void testDeleteDatasourceRange(
TestDb *pDb, /* Database to write to */
Datasource *pData, /* Data source to read keys from */
int iFirst, /* Index of first key */
int nWrite, /* Number of keys to delete */
int *pRc /* IN/OUT: Error code */
){
int i;
for(i=0; i<nWrite; i++){
testDeleteDatasource(pDb, pData, iFirst+i, pRc);
}
}
static char *getName(const char *zSystem){
char *zRet;
zRet = testMallocPrintf("rollback.%s", zSystem);
return zRet;
}
static int rollback_test_1(
const char *zSystem,
Datasource *pData
){
const int nRepeat = 100;
TestDb *pDb;
int rc;
int i;
CksumDb *pCksum;
char *zName;
zName = getName(zSystem);
testCaseStart(&rc, zName);
testFree(zName);
pCksum = testCksumArrayNew(pData, 0, nRepeat*100, 100);
pDb = 0;
rc = tdb_open(zSystem, 0, 1, &pDb);
if( pDb && tdb_transaction_support(pDb)==0 ){
testCaseSkip();
goto skip_rollback_test;
}
for(i=0; i<nRepeat && rc==0; i++){
char zCksum[TEST_CKSUM_BYTES];
int nCurrent = (((i+1)/2) * 100);
int nDbRow;
int iTrans;
/* Check that the database is the expected size. */
nDbRow = testCountDatabase(pDb);
testCompareInt(nCurrent, nDbRow, &rc);
for(iTrans=2; iTrans<=6 && rc==0; iTrans++){
tdb_begin(pDb, iTrans);
testWriteDatasourceRange(pDb, pData, nCurrent, 100, &rc);
nCurrent += 100;
}
testCksumDatabase(pDb, zCksum);
testCompareStr(zCksum, testCksumArrayGet(pCksum, nCurrent), &rc);
for(iTrans=6; iTrans>2 && rc==0; iTrans--){
tdb_rollback(pDb, iTrans);
nCurrent -= 100;
testCksumDatabase(pDb, zCksum);
testCompareStr(zCksum, testCksumArrayGet(pCksum, nCurrent), &rc);
}
if( i%2 ){
tdb_rollback(pDb, 0);
nCurrent -= 100;
testCksumDatabase(pDb, zCksum);
testCompareStr(zCksum, testCksumArrayGet(pCksum, nCurrent), &rc);
}else{
tdb_commit(pDb, 0);
}
}
testCaseFinish(rc);
skip_rollback_test:
tdb_close(pDb);
testCksumArrayFree(pCksum);
return rc;
}
void test_rollback(
const char *zSystem,
const char *zPattern,
int *pRc
){
if( *pRc==0 ){
int bRun = 1;
if( zPattern ){
char *zName = getName(zSystem);
bRun = testGlobMatch(zPattern, zName);
testFree(zName);
}
if( bRun ){
DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 50, 100 };
Datasource *pData = testDatasourceNew(&defn);
*pRc = rollback_test_1(zSystem, pData);
testDatasourceFree(pData);
}
}
}
+127
View File
@@ -0,0 +1,127 @@
/*
** This file contains test cases involving multiple database clients.
*/
#include "lsmtest.h"
/*
** The following code implements test cases "mc1.*".
**
** This test case uses one writer and $nReader readers. All connections
** are driven by a single thread. All connections are opened at the start
** of the test and remain open until the test is finished.
**
** The test consists of $nStep steps. Each step the following is performed:
**
** 1. The writer inserts $nWriteStep records into the db.
**
** 2. The writer checks that the contents of the db are as expected.
**
** 3. Each reader that currently has an open read transaction also checks
** that the contents of the db are as expected (according to the snapshot
** the read transaction is reading - see below).
**
** After step 1, reader 1 opens a read transaction. After step 2, reader
** 2 opens a read transaction, and so on. At step ($nReader+1), reader 1
** closes the current read transaction and opens a new one. And so on.
** The result is that at step N (for N > $nReader), there exists a reader
** with an open read transaction reading the snapshot committed following
** steps (N-$nReader-1) to N.
*/
typedef struct Mctest Mctest;
struct Mctest {
DatasourceDefn defn; /* Datasource to use */
int nStep; /* Total number of steps in test */
int nWriteStep; /* Number of rows to insert each step */
int nReader; /* Number of read connections */
};
static void do_mc_test(
const char *zSystem, /* Database system to test */
Mctest *pTest,
int *pRc /* IN/OUT: return code */
){
const int nDomain = pTest->nStep * pTest->nWriteStep;
Datasource *pData; /* Source of data */
TestDb *pDb; /* First database connection (writer) */
int iReader; /* Used to iterate through aReader */
int iStep; /* Current step in test */
int iDot = 0; /* Current step in test */
/* Array of reader connections */
struct Reader {
TestDb *pDb; /* Connection handle */
int iLast; /* Current snapshot contains keys 0..iLast */
} *aReader;
/* Create a data source */
pData = testDatasourceNew(&pTest->defn);
/* Open the writer connection */
pDb = testOpen(zSystem, 1, pRc);
/* Allocate aReader */
aReader = (struct Reader *)testMalloc(sizeof(aReader[0]) * pTest->nReader);
for(iReader=0; iReader<pTest->nReader; iReader++){
aReader[iReader].pDb = testOpen(zSystem, 0, pRc);
}
for(iStep=0; iStep<pTest->nStep; iStep++){
int iLast;
int iBegin; /* Start read trans using aReader[iBegin] */
/* Insert nWriteStep more records into the database */
int iFirst = iStep*pTest->nWriteStep;
testWriteDatasourceRange(pDb, pData, iFirst, pTest->nWriteStep, pRc);
/* Check that the db is Ok according to the writer */
iLast = (iStep+1) * pTest->nWriteStep - 1;
testDbContents(pDb, pData, nDomain, 0, iLast, iLast, 1, pRc);
/* Have reader (iStep % nReader) open a read transaction here. */
iBegin = (iStep % pTest->nReader);
if( iBegin<iStep ) tdb_commit(aReader[iBegin].pDb, 0);
tdb_begin(aReader[iBegin].pDb, 1);
aReader[iBegin].iLast = iLast;
/* Check that the db is Ok for each open reader */
for(iReader=0; iReader<pTest->nReader && aReader[iReader].iLast; iReader++){
iLast = aReader[iReader].iLast;
testDbContents(
aReader[iReader].pDb, pData, nDomain, 0, iLast, iLast, 1, pRc
);
}
/* Report progress */
testCaseProgress(iStep, pTest->nStep, testCaseNDot(), &iDot);
}
/* Close all readers */
for(iReader=0; iReader<pTest->nReader; iReader++){
testClose(&aReader[iReader].pDb);
}
testFree(aReader);
/* Close the writer-connection and free the datasource */
testClose(&pDb);
testDatasourceFree(pData);
}
void test_mc(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
int i;
Mctest aTest[] = {
{ { TEST_DATASOURCE_RANDOM, 10,10, 100,100 }, 100, 10, 5 },
};
for(i=0; i<ArraySize(aTest); i++){
if( testCaseBegin(pRc, zPattern, "mc1.%s.%d", zSystem, i) ){
do_mc_test(zSystem, &aTest[i], pRc);
testCaseFinish(*pRc);
}
}
}
+633
View File
@@ -0,0 +1,633 @@
/*
** This file is broken into three semi-autonomous parts:
**
** 1. The database functions.
** 2. The thread wrappers.
** 3. The implementation of the mt1.* tests.
*/
/*************************************************************************
** DATABASE CONTENTS:
**
** The database contains up to N key/value pairs, where N is some large
** number (say 10,000,000). Keys are integer values between 0 and (N-1).
** The value associated with each key is a pseudo-random blob of data.
**
** Key/value pair keys are encoded as the two bytes "k." followed by a
** 10-digit decimal number. i.e. key 45 -> "k.0000000045".
**
** As well as the key/value pairs, the database also contains checksum
** entries. The checksums form a hierarchy - for every F key/value
** entries there is one level 1 checksum. And for each F level 1 checksums
** there is one level 2 checksum. And so on.
**
** Checksum keys are encoded as the two byte "c." followed by the
** checksum level, followed by a 10 digit decimal number containing
** the value of the first key that contributes to the checksum value.
** For example, assuming F==10, the level 1 checksum that spans keys
** 10 to 19 is "c.1.0000000010".
**
** Clients may perform one of two operations on the database: a read
** or a write.
**
** READ OPERATIONS:
**
** A read operation scans a range of F key/value pairs. It computes
** the expected checksum and then compares the computed value to the
** actual value stored in the level 1 checksum entry. It then scans
** the group of F level 1 checksums, and compares the computed checksum
** to the associated level 2 checksum value, and so on until the
** highest level checksum value has been verified.
**
** If a checksum ever fails to match the expected value, the test
** has failed.
**
** WRITE OPERATIONS:
**
** A write operation involves writing (possibly clobbering) a single
** key/value pair. The associated level 1 checksum is then recalculated
** updated. Then the level 2 checksum, and so on until the highest
** level checksum has been modified.
**
** All updates occur inside a single transaction.
**
** INTERFACE:
**
** The interface used by test cases to read and write the db consists
** of type DbParameters and the following functions:
**
** dbReadOperation()
** dbWriteOperation()
*/
#include "lsmtest.h"
typedef struct DbParameters DbParameters;
struct DbParameters {
int nFanout; /* Checksum fanout (F) */
int nKey; /* Size of key space (N) */
};
#define DB_KEY_BYTES (2+5+10+1)
/*
** Argument aBuf[] must point to a buffer at least DB_KEY_BYTES in size.
** This function populates the buffer with a nul-terminated key string
** corresponding to key iKey.
*/
static void dbFormatKey(
DbParameters *pParam,
int iLevel,
int iKey, /* Key value */
char *aBuf /* Write key string here */
){
if( iLevel==0 ){
snprintf(aBuf, DB_KEY_BYTES, "k.%.10d", iKey);
}else{
int f = 1;
int i;
for(i=0; i<iLevel; i++) f = f * pParam->nFanout;
snprintf(aBuf, DB_KEY_BYTES, "c.%d.%.10d", iLevel, f*(iKey/f));
}
}
/*
** Argument aBuf[] must point to a buffer at least DB_KEY_BYTES in size.
** This function populates the buffer with the string representation of
** checksum value iVal.
*/
static void dbFormatCksumValue(u32 iVal, char *aBuf){
snprintf(aBuf, DB_KEY_BYTES, "%.10u", iVal);
}
/*
** Return the highest level of checksum in the database described
** by *pParam.
*/
static int dbMaxLevel(DbParameters *pParam){
int iMax;
int n = 1;
for(iMax=0; n<pParam->nKey; iMax++){
n = n * pParam->nFanout;
}
return iMax;
}
static void dbCksum(
void *pCtx, /* IN/OUT: Pointer to u32 containing cksum */
void *pKey, int nKey, /* Database key. Unused. */
void *pVal, int nVal /* Database value. Checksum this. */
){
u8 *aVal = (u8 *)pVal;
u32 *pCksum = (u32 *)pCtx;
u32 cksum = *pCksum;
int i;
unused_parameter(pKey);
unused_parameter(nKey);
for(i=0; i<nVal; i++){
cksum += (cksum<<3) + (int)aVal[i];
}
*pCksum = cksum;
}
/*
** Compute the value of the checksum stored on level iLevel that contains
** data from key iKey by scanning the pParam->nFanout entries at level
** iLevel-1.
*/
static u32 dbComputeCksum(
DbParameters *pParam, /* Database parameters */
TestDb *pDb, /* Database connection handle */
int iLevel, /* Level of checksum to compute */
int iKey, /* Compute checksum for this key */
int *pRc /* IN/OUT: Error code */
){
u32 cksum = 0;
if( *pRc==0 ){
int nFirst;
int nLast;
int iFirst = 0;
int iLast = 0;
int i;
int f = 1;
char zFirst[DB_KEY_BYTES];
char zLast[DB_KEY_BYTES];
assert( iLevel>=1 );
for(i=0; i<iLevel; i++) f = f * pParam->nFanout;
iFirst = f*(iKey/f);
iLast = iFirst + f - 1;
dbFormatKey(pParam, iLevel-1, iFirst, zFirst);
dbFormatKey(pParam, iLevel-1, iLast, zLast);
nFirst = strlen(zFirst);
nLast = strlen(zLast);
*pRc = tdb_scan(pDb, (u32*)&cksum, 0, zFirst, nFirst, zLast, nLast,dbCksum);
}
return cksum;
}
static void dbReadOperation(
DbParameters *pParam, /* Database parameters */
TestDb *pDb, /* Database connection handle */
void (*xDelay)(void *),
void *pDelayCtx,
int iKey, /* Key to read */
int *pRc /* IN/OUT: Error code */
){
const int iMax = dbMaxLevel(pParam);
int i;
if( tdb_transaction_support(pDb) ) testBegin(pDb, 1, pRc);
for(i=1; *pRc==0 && i<=iMax; i++){
char zCksum[DB_KEY_BYTES];
char zKey[DB_KEY_BYTES];
u32 iCksum = 0;
iCksum = dbComputeCksum(pParam, pDb, i, iKey, pRc);
if( iCksum ){
if( xDelay && i==1 ) xDelay(pDelayCtx);
dbFormatCksumValue(iCksum, zCksum);
dbFormatKey(pParam, i, iKey, zKey);
testFetchStr(pDb, zKey, zCksum, pRc);
}
}
if( tdb_transaction_support(pDb) ) testCommit(pDb, 0, pRc);
}
static int dbWriteOperation(
DbParameters *pParam, /* Database parameters */
TestDb *pDb, /* Database connection handle */
int iKey, /* Key to write to */
const char *zValue, /* Nul-terminated value to write */
int *pRc /* IN/OUT: Error code */
){
const int iMax = dbMaxLevel(pParam);
char zKey[DB_KEY_BYTES];
int i;
int rc;
assert( iKey>=0 && iKey<pParam->nKey );
dbFormatKey(pParam, 0, iKey, zKey);
/* Open a write transaction. This may fail - SQLITE4_BUSY */
if( *pRc==0 && tdb_transaction_support(pDb) ){
rc = tdb_begin(pDb, 2);
if( rc==5 ) return 0;
*pRc = rc;
}
testWriteStr(pDb, zKey, zValue, pRc);
for(i=1; i<=iMax; i++){
char zCksum[DB_KEY_BYTES];
u32 iCksum = 0;
iCksum = dbComputeCksum(pParam, pDb, i, iKey, pRc);
dbFormatCksumValue(iCksum, zCksum);
dbFormatKey(pParam, i, iKey, zKey);
testWriteStr(pDb, zKey, zCksum, pRc);
}
if( tdb_transaction_support(pDb) ) testCommit(pDb, 0, pRc);
return 1;
}
/*************************************************************************
** The following block contains testXXX() functions that implement a
** wrapper around the systems native multi-thread support. There are no
** synchronization primitives - just functions to launch and join
** threads. Wrapper functions are:
**
** testThreadSupport()
**
** testThreadInit()
** testThreadShutdown()
** testThreadLaunch()
** testThreadWait()
**
** testThreadSetHalt()
** testThreadGetHalt()
** testThreadSetResult()
** testThreadGetResult()
**
** testThreadEnterMutex()
** testThreadLeaveMutex()
*/
typedef struct ThreadSet ThreadSet;
#ifdef LSM_MUTEX_PTHREADS
#include <pthread.h>
#include <unistd.h>
typedef struct Thread Thread;
struct Thread {
int rc;
char *zMsg;
pthread_t id;
void (*xMain)(ThreadSet *, int, void *);
void *pCtx;
ThreadSet *pThreadSet;
};
struct ThreadSet {
int bHalt; /* Halt flag */
int nThread; /* Number of threads */
Thread *aThread; /* Array of Thread structures */
pthread_mutex_t mutex; /* Mutex used for cheating */
};
/*
** Return true if this build supports threads, or false otherwise. If
** this function returns false, no other testThreadXXX() functions should
** be called.
*/
static int testThreadSupport(){ return 1; }
/*
** Allocate and return a thread-set handle with enough space allocated
** to handle up to nMax threads. Each call to this function should be
** matched by a call to testThreadShutdown() to delete the object.
*/
static ThreadSet *testThreadInit(int nMax){
int nByte; /* Total space to allocate */
ThreadSet *p; /* Return value */
nByte = sizeof(ThreadSet) + sizeof(struct Thread) * nMax;
p = (ThreadSet *)testMalloc(nByte);
p->nThread = nMax;
p->aThread = (Thread *)&p[1];
pthread_mutex_init(&p->mutex, 0);
return p;
}
/*
** Delete a thread-set object and release all resources held by it.
*/
static void testThreadShutdown(ThreadSet *p){
int i;
for(i=0; i<p->nThread; i++){
testFree(p->aThread[i].zMsg);
}
pthread_mutex_destroy(&p->mutex);
testFree(p);
}
static void *ttMain(void *pArg){
Thread *pThread = (Thread *)pArg;
int iThread;
iThread = (pThread - pThread->pThreadSet->aThread);
pThread->xMain(pThread->pThreadSet, iThread, pThread->pCtx);
return 0;
}
/*
** Launch a new thread.
*/
static int testThreadLaunch(
ThreadSet *p,
int iThread,
void (*xMain)(ThreadSet *, int, void *),
void *pCtx
){
int rc;
Thread *pThread;
assert( iThread>=0 && iThread<p->nThread );
pThread = &p->aThread[iThread];
assert( pThread->pThreadSet==0 );
pThread->xMain = xMain;
pThread->pCtx = pCtx;
pThread->pThreadSet = p;
rc = pthread_create(&pThread->id, 0, ttMain, (void *)pThread);
return rc;
}
/*
** Set the thread-set "halt" flag.
*/
static void testThreadSetHalt(ThreadSet *pThreadSet){
pThreadSet->bHalt = 1;
}
/*
** Return the current value of the thread-set "halt" flag.
*/
static int testThreadGetHalt(ThreadSet *pThreadSet){
return pThreadSet->bHalt;
}
static void testThreadSleep(ThreadSet *pThreadSet, int nMs){
int nRem = nMs;
while( nRem>0 && testThreadGetHalt(pThreadSet)==0 ){
usleep(50000);
nRem -= 50;
}
}
/*
** Wait for all threads launched to finish before returning. If nMs
** is greater than zero, set the "halt" flag to tell all threads
** to halt after waiting nMs milliseconds.
*/
static void testThreadWait(ThreadSet *pThreadSet, int nMs){
int i;
testThreadSleep(pThreadSet, nMs);
testThreadSetHalt(pThreadSet);
for(i=0; i<pThreadSet->nThread; i++){
Thread *pThread = &pThreadSet->aThread[i];
if( pThread->xMain ){
pthread_join(pThread->id, 0);
}
}
}
/*
** Set the result for thread iThread.
*/
static void testThreadSetResult(
ThreadSet *pThreadSet, /* Thread-set handle */
int iThread, /* Set result for this thread */
int rc, /* Result error code */
char *zFmt, /* Result string format */
... /* Result string formatting args... */
){
va_list ap;
testFree(pThreadSet->aThread[iThread].zMsg);
pThreadSet->aThread[iThread].rc = rc;
pThreadSet->aThread[iThread].zMsg = 0;
if( zFmt ){
va_start(ap, zFmt);
pThreadSet->aThread[iThread].zMsg = testMallocVPrintf(zFmt, ap);
va_end(ap);
}
}
/*
** Retrieve the result for thread iThread.
*/
static int testThreadGetResult(
ThreadSet *pThreadSet, /* Thread-set handle */
int iThread, /* Get result for this thread */
const char **pzRes /* OUT: Pointer to result string */
){
if( pzRes ) *pzRes = pThreadSet->aThread[iThread].zMsg;
return pThreadSet->aThread[iThread].rc;
}
/*
** Enter and leave the test case mutex.
*/
#if 0
static void testThreadEnterMutex(ThreadSet *p){
pthread_mutex_lock(&p->mutex);
}
static void testThreadLeaveMutex(ThreadSet *p){
pthread_mutex_unlock(&p->mutex);
}
#endif
#endif
#if !defined(LSM_MUTEX_PTHREADS)
static int testThreadSupport(){ return 0; }
#define testThreadInit(a) 0
#define testThreadShutdown(a)
#define testThreadLaunch(a,b,c,d) 0
#define testThreadWait(a,b)
#define testThreadSetHalt(a)
#define testThreadGetHalt(a) 0
#define testThreadGetResult(a,b,c) 0
#define testThreadSleep(a,b) 0
static void testThreadSetResult(ThreadSet *a, int b, int c, char *d, ...){
unused_parameter(a);
unused_parameter(b);
unused_parameter(c);
unused_parameter(d);
}
#endif
/* End of threads wrapper.
*************************************************************************/
/*************************************************************************
** Below this point is the third part of this file - the implementation
** of the mt1.* tests.
*/
typedef struct Mt1Test Mt1Test;
struct Mt1Test {
DbParameters param; /* Description of database to read/write */
int nReadwrite; /* Number of read/write threads */
int nFastReader; /* Number of fast reader threads */
int nSlowReader; /* Number of slow reader threads */
int nMs; /* How long to run for */
const char *zSystem; /* Database system to test */
};
typedef struct Mt1DelayCtx Mt1DelayCtx;
struct Mt1DelayCtx {
ThreadSet *pSet; /* Threadset to sleep within */
int nMs; /* Sleep in ms */
};
static void xMt1Delay(void *pCtx){
Mt1DelayCtx *p = (Mt1DelayCtx *)pCtx;
testThreadSleep(p->pSet, p->nMs);
}
#define MT1_THREAD_RDWR 0
#define MT1_THREAD_SLOW 1
#define MT1_THREAD_FAST 2
static void xMt1Work(lsm_db *pDb, void *pCtx){
#if 0
char *z = 0;
lsm_info(pDb, LSM_INFO_DB_STRUCTURE, &z);
printf("%s\n", z);
fflush(stdout);
#endif
}
/*
** This is the main() proc for all threads in test case "mt1".
*/
static void mt1Main(ThreadSet *pThreadSet, int iThread, void *pCtx){
Mt1Test *p = (Mt1Test *)pCtx; /* Test parameters */
Mt1DelayCtx delay;
int nRead = 0; /* Number of calls to dbReadOperation() */
int nWrite = 0; /* Number of completed database writes */
int rc = 0; /* Error code */
int iPrng; /* Prng argument variable */
TestDb *pDb; /* Database handle */
int eType;
delay.pSet = pThreadSet;
delay.nMs = 0;
if( iThread<p->nReadwrite ){
eType = MT1_THREAD_RDWR;
}else if( iThread<(p->nReadwrite+p->nFastReader) ){
eType = MT1_THREAD_FAST;
}else{
eType = MT1_THREAD_SLOW;
delay.nMs = (p->nMs / 20);
}
/* Open a new database connection. Initialize the pseudo-random number
** argument based on the thread number. */
iPrng = testPrngValue(iThread);
pDb = testOpen(p->zSystem, 0, &rc);
if( rc==0 ){
tdb_lsm_config_work_hook(pDb, xMt1Work, 0);
}
/* Loop until either an error occurs or some other thread sets the
** halt flag. */
while( rc==0 && testThreadGetHalt(pThreadSet)==0 ){
int iKey;
/* Perform a read operation on an arbitrarily selected key. */
iKey = (testPrngValue(iPrng++) % p->param.nKey);
dbReadOperation(&p->param, pDb, xMt1Delay, (void *)&delay, iKey, &rc);
if( rc ) continue;
nRead++;
/* Attempt to write an arbitrary key value pair (and update the associated
** checksum entries). dbWriteOperation() returns 1 if the write is
** successful, or 0 if it failed with an LSM_BUSY error. */
if( eType==MT1_THREAD_RDWR ){
char aValue[50];
char aRnd[25];
iKey = (testPrngValue(iPrng++) % p->param.nKey);
testPrngString(iPrng, aRnd, sizeof(aRnd));
iPrng += sizeof(aRnd);
snprintf(aValue, sizeof(aValue), "%d.%s", iThread, aRnd);
nWrite += dbWriteOperation(&p->param, pDb, iKey, aValue, &rc);
}
}
testClose(&pDb);
/* If an error has occured, set the thread error code and the threadset
** halt flag to tell the other test threads to halt. Otherwise, set the
** thread error code to 0 and post a message with the number of read
** and write operations completed. */
if( rc ){
testThreadSetResult(pThreadSet, iThread, rc, 0);
testThreadSetHalt(pThreadSet);
}else{
testThreadSetResult(pThreadSet, iThread, 0, "r/w: %d/%d", nRead, nWrite);
}
}
static void do_test_mt1(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
Mt1Test aTest[] = {
/* param, nReadwrite, nFastReader, nSlowReader, nMs, zSystem */
{ {10, 1000}, 4, 0, 0, 10000, 0 },
{ {10, 1000}, 4, 4, 2, 100000, 0 },
{ {10, 100000}, 4, 0, 0, 10000, 0 },
{ {10, 100000}, 4, 4, 2, 100000, 0 },
};
int i;
for(i=0; *pRc==0 && i<ArraySize(aTest); i++){
Mt1Test *p = &aTest[i];
int bRun = testCaseBegin(pRc, zPattern,
"mt1.%s.db=%d,%d.ms=%d.rdwr=%d.fast=%d.slow=%d",
zSystem, p->param.nFanout, p->param.nKey,
p->nMs, p->nReadwrite, p->nFastReader, p->nSlowReader
);
if( bRun ){
TestDb *pDb;
ThreadSet *pSet;
int iThread;
int nThread;
p->zSystem = zSystem;
pDb = testOpen(zSystem, 1, pRc);
nThread = p->nReadwrite + p->nFastReader + p->nSlowReader;
pSet = testThreadInit(nThread);
for(iThread=0; *pRc==0 && iThread<nThread; iThread++){
testThreadLaunch(pSet, iThread, mt1Main, (void *)p);
}
testThreadWait(pSet, p->nMs);
for(iThread=0; *pRc==0 && iThread<nThread; iThread++){
*pRc = testThreadGetResult(pSet, iThread, 0);
}
testCaseFinish(*pRc);
for(iThread=0; *pRc==0 && iThread<nThread; iThread++){
const char *zMsg = 0;
*pRc = testThreadGetResult(pSet, iThread, &zMsg);
printf(" Info: thread %d (%d): %s\n", iThread, *pRc, zMsg);
}
testThreadShutdown(pSet);
testClose(&pDb);
}
}
}
void test_mt(
const char *zSystem, /* Database system name */
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
if( testThreadSupport()==0 ) return;
do_test_mt1(zSystem, zPattern, pRc);
}
+668
View File
@@ -0,0 +1,668 @@
#include "lsmtest.h"
typedef struct OomTest OomTest;
struct OomTest {
lsm_env *pEnv;
int iNext; /* Next value to pass to testMallocOom() */
int nFail; /* Number of OOM events injected */
int bEnable;
int rc; /* Test case error code */
};
static void testOomStart(OomTest *p){
memset(p, 0, sizeof(OomTest));
p->iNext = 1;
p->bEnable = 1;
p->nFail = 1;
p->pEnv = tdb_lsm_env();
}
static void xOomHook(OomTest *p){
p->nFail++;
}
static int testOomContinue(OomTest *p){
if( p->rc!=0 || (p->iNext>1 && p->nFail==0) ){
return 0;
}
p->nFail = 0;
testMallocOom(p->pEnv, p->iNext, 0, (void (*)(void*))xOomHook, (void *)p);
return 1;
}
static void testOomEnable(OomTest *p, int bEnable){
p->bEnable = bEnable;
testMallocOomEnable(p->pEnv, bEnable);
}
static void testOomNext(OomTest *p){
p->iNext++;
}
static int testOomHit(OomTest *p){
return (p->nFail>0);
}
static int testOomFinish(OomTest *p){
return p->rc;
}
static void testOomAssert(OomTest *p, int bVal){
if( bVal==0 ){
test_failed();
p->rc = 1;
}
}
/*
** Test that the error code matches the state of the OomTest object passed
** as the first argument. Specifically, check that rc is LSM_NOMEM if an
** OOM error has already been injected, or LSM_OK if not.
*/
static void testOomAssertRc(OomTest *p, int rc){
testOomAssert(p, rc==LSM_OK || rc==LSM_NOMEM);
testOomAssert(p, testOomHit(p)==(rc==LSM_NOMEM) || p->bEnable==0 );
}
static void testOomOpen(
OomTest *pOom,
const char *zName,
lsm_db **ppDb,
int *pRc
){
if( *pRc==LSM_OK ){
int rc;
rc = lsm_new(tdb_lsm_env(), ppDb);
if( rc==LSM_OK ) rc = lsm_open(*ppDb, zName);
testOomAssertRc(pOom, rc);
*pRc = rc;
}
}
static void testOomFetch(
OomTest *pOom,
lsm_db *pDb,
void *pKey, int nKey,
void *pVal, int nVal,
int *pRc
){
testOomAssertRc(pOom, *pRc);
if( *pRc==LSM_OK ){
lsm_cursor *pCsr;
int rc;
rc = lsm_csr_open(pDb, &pCsr);
if( rc==LSM_OK ) rc = lsm_csr_seek(pCsr, pKey, nKey, 0);
testOomAssertRc(pOom, rc);
if( rc==LSM_OK ){
const void *p; int n;
testOomAssert(pOom, lsm_csr_valid(pCsr));
rc = lsm_csr_key(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
testOomAssert(pOom, rc!=LSM_OK || (n==nKey && memcmp(pKey, p, nKey)==0) );
}
if( rc==LSM_OK ){
const void *p; int n;
testOomAssert(pOom, lsm_csr_valid(pCsr));
rc = lsm_csr_value(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
testOomAssert(pOom, rc!=LSM_OK || (n==nVal && memcmp(pVal, p, nVal)==0) );
}
lsm_csr_close(pCsr);
*pRc = rc;
}
}
static void testOomWrite(
OomTest *pOom,
lsm_db *pDb,
void *pKey, int nKey,
void *pVal, int nVal,
int *pRc
){
testOomAssertRc(pOom, *pRc);
if( *pRc==LSM_OK ){
int rc;
rc = lsm_insert(pDb, pKey, nKey, pVal, nVal);
testOomAssertRc(pOom, rc);
*pRc = rc;
}
}
static void testOomFetchStr(
OomTest *pOom,
lsm_db *pDb,
const char *zKey,
const char *zVal,
int *pRc
){
int nKey = strlen(zKey);
int nVal = strlen(zVal);
testOomFetch(pOom, pDb, (void *)zKey, nKey, (void *)zVal, nVal, pRc);
}
static void testOomFetchData(
OomTest *pOom,
lsm_db *pDb,
Datasource *pData,
int iKey,
int *pRc
){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
testOomFetch(pOom, pDb, pKey, nKey, pVal, nVal, pRc);
}
static void testOomWriteStr(
OomTest *pOom,
lsm_db *pDb,
const char *zKey,
const char *zVal,
int *pRc
){
int nKey = strlen(zKey);
int nVal = strlen(zVal);
testOomWrite(pOom, pDb, (void *)zKey, nKey, (void *)zVal, nVal, pRc);
}
static void testOomWriteData(
OomTest *pOom,
lsm_db *pDb,
Datasource *pData,
int iKey,
int *pRc
){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, iKey, &pKey, &nKey, &pVal, &nVal);
testOomWrite(pOom, pDb, pKey, nKey, pVal, nVal, pRc);
}
static void testOomScan(
OomTest *pOom,
lsm_db *pDb,
int bReverse,
const void *pKey, int nKey,
int nScan,
int *pRc
){
if( *pRc==0 ){
int rc;
int iScan = 0;
lsm_cursor *pCsr;
int (*xAdvance)(lsm_cursor *);
rc = lsm_csr_open(pDb, &pCsr);
testOomAssertRc(pOom, rc);
if( rc==LSM_OK ){
if( bReverse ){
rc = lsm_csr_seek(pCsr, pKey, nKey, LSM_SEEK_LE);
xAdvance = lsm_csr_prev;
}else{
rc = lsm_csr_seek(pCsr, pKey, nKey, LSM_SEEK_GE);
xAdvance = lsm_csr_next;
}
}
testOomAssertRc(pOom, rc);
while( rc==LSM_OK && lsm_csr_valid(pCsr) && iScan<nScan ){
const void *p; int n;
rc = lsm_csr_key(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
if( rc==LSM_OK ){
rc = lsm_csr_value(pCsr, &p, &n);
testOomAssertRc(pOom, rc);
}
if( rc==LSM_OK ){
rc = xAdvance(pCsr);
testOomAssertRc(pOom, rc);
}
iScan++;
}
lsm_csr_close(pCsr);
*pRc = rc;
}
}
#define LSMTEST6_TESTDB "testdb.lsm"
#ifndef _WIN32
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
void testDeleteLsmdb(const char *zFile){
char *zLog = testMallocPrintf("%s-log", zFile);
char *zShm = testMallocPrintf("%s-shm", zFile);
unlink(zFile);
unlink(zLog);
unlink(zShm);
testFree(zLog);
testFree(zShm);
}
static void copy_file(const char *zFrom, const char *zTo, int isDatabase){
if( access(zFrom, F_OK) ){
unlink(zTo);
}else{
int fd1;
int fd2;
off_t sz;
off_t i;
struct stat buf;
u8 *aBuf;
fd1 = open(zFrom, O_RDONLY | _O_BINARY, 0644);
fd2 = open(zTo, O_RDWR | O_CREAT | _O_BINARY, 0644);
fstat(fd1, &buf);
sz = buf.st_size;
ftruncate(fd2, sz);
aBuf = testMalloc(4096);
for(i=0; i<sz; i+=4096){
int bLockPage = isDatabase && i == 0;
int nByte = MIN((bLockPage ? 4066 : 4096), sz - i);
memset(aBuf, 0, 4096);
read(fd1, aBuf, nByte);
write(fd2, aBuf, nByte);
if( bLockPage ){
lseek(fd1, 4096, SEEK_SET);
lseek(fd2, 4096, SEEK_SET);
}
}
testFree(aBuf);
close(fd1);
close(fd2);
}
}
void testCopyLsmdb(const char *zFrom, const char *zTo){
char *zLog1 = testMallocPrintf("%s-log", zFrom);
char *zLog2 = testMallocPrintf("%s-log", zTo);
char *zShm1 = testMallocPrintf("%s-shm", zFrom);
char *zShm2 = testMallocPrintf("%s-shm", zTo);
unlink(zShm2);
unlink(zLog2);
unlink(zTo);
copy_file(zFrom, zTo, 1);
copy_file(zLog1, zLog2, 0);
copy_file(zShm1, zShm2, 0);
testFree(zLog1); testFree(zLog2); testFree(zShm1); testFree(zShm2);
}
/*
** File zFile is the path to a database. This function makes backups
** of the database file and its log as follows:
**
** cp $(zFile) $(zFile)-save
** cp $(zFile)-$(zAux) $(zFile)-save-$(zAux)
**
** Function testRestoreDb() can be used to copy the files back in the
** other direction.
*/
void testSaveDb(const char *zFile, const char *zAux){
char *zLog = testMallocPrintf("%s-%s", zFile, zAux);
char *zFileSave = testMallocPrintf("%s-save", zFile);
char *zLogSave = testMallocPrintf("%s-%s-save", zFile, zAux);
unlink(zFileSave);
unlink(zLogSave);
copy_file(zFile, zFileSave, 1);
copy_file(zLog, zLogSave, 0);
testFree(zLog); testFree(zFileSave); testFree(zLogSave);
}
/*
** File zFile is the path to a database. This function restores
** a backup of the database made by a previous call to testSaveDb().
** Specifically, it does the equivalent of:
**
** cp $(zFile)-save $(zFile)
** cp $(zFile)-save-$(zAux) $(zFile)-$(zAux)
*/
void testRestoreDb(const char *zFile, const char *zAux){
char *zLog = testMallocPrintf("%s-%s", zFile, zAux);
char *zFileSave = testMallocPrintf("%s-save", zFile);
char *zLogSave = testMallocPrintf("%s-%s-save", zFile, zAux);
copy_file(zFileSave, zFile, 1);
copy_file(zLogSave, zLog, 0);
testFree(zLog); testFree(zFileSave); testFree(zLogSave);
}
static int lsmWriteStr(lsm_db *pDb, const char *zKey, const char *zVal){
int nKey = strlen(zKey);
int nVal = strlen(zVal);
return lsm_insert(pDb, (void *)zKey, nKey, (void *)zVal, nVal);
}
static void setup_delete_db(){
testDeleteLsmdb(LSMTEST6_TESTDB);
}
/*
** Create a small database. With the following content:
**
** "one" -> "one"
** "two" -> "four"
** "three" -> "nine"
** "four" -> "sixteen"
** "five" -> "twentyfive"
** "six" -> "thirtysix"
** "seven" -> "fourtynine"
** "eight" -> "sixtyfour"
*/
static void setup_populate_db(){
const char *azStr[] = {
"one", "one",
"two", "four",
"three", "nine",
"four", "sixteen",
"five", "twentyfive",
"six", "thirtysix",
"seven", "fourtynine",
"eight", "sixtyfour",
};
int rc;
int ii;
lsm_db *pDb;
testDeleteLsmdb(LSMTEST6_TESTDB);
rc = lsm_new(tdb_lsm_env(), &pDb);
if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB);
for(ii=0; rc==LSM_OK && ii<ArraySize(azStr); ii+=2){
rc = lsmWriteStr(pDb, azStr[ii], azStr[ii+1]);
}
lsm_close(pDb);
testSaveDb(LSMTEST6_TESTDB, "log");
assert( rc==LSM_OK );
}
static Datasource *getDatasource(void){
const DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 200, 250 };
return testDatasourceNew(&defn);
}
/*
** Set up a database file with the following properties:
**
** * Page size is 1024 bytes.
** * Block size is 64 KB.
** * Contains 5000 key-value pairs starting at 0 from the
** datasource returned getDatasource().
*/
static void setup_populate_db2(){
Datasource *pData;
int ii;
int rc;
int nBlocksize = 64*1024;
int nPagesize = 1024;
int nWritebuffer = 4*1024;
lsm_db *pDb;
testDeleteLsmdb(LSMTEST6_TESTDB);
rc = lsm_new(tdb_lsm_env(), &pDb);
if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB);
lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &nBlocksize);
lsm_config(pDb, LSM_CONFIG_PAGE_SIZE, &nPagesize);
lsm_config(pDb, LSM_CONFIG_AUTOFLUSH, &nWritebuffer);
pData = getDatasource();
for(ii=0; rc==LSM_OK && ii<5000; ii++){
void *pKey; int nKey;
void *pVal; int nVal;
testDatasourceEntry(pData, ii, &pKey, &nKey, &pVal, &nVal);
lsm_insert(pDb, pKey, nKey, pVal, nVal);
}
testDatasourceFree(pData);
lsm_close(pDb);
testSaveDb(LSMTEST6_TESTDB, "log");
assert( rc==LSM_OK );
}
/*
** Test the results of OOM conditions in lsm_new().
*/
static void simple_oom_1(OomTest *pOom){
int rc;
lsm_db *pDb;
rc = lsm_new(tdb_lsm_env(), &pDb);
testOomAssertRc(pOom, rc);
lsm_close(pDb);
}
/*
** Test the results of OOM conditions in lsm_open().
*/
static void simple_oom_2(OomTest *pOom){
int rc;
lsm_db *pDb;
rc = lsm_new(tdb_lsm_env(), &pDb);
if( rc==LSM_OK ){
rc = lsm_open(pDb, "testdb.lsm");
}
testOomAssertRc(pOom, rc);
lsm_close(pDb);
}
/*
** Test the results of OOM conditions in simple fetch operations.
*/
static void simple_oom_3(OomTest *pOom){
int rc = LSM_OK;
lsm_db *pDb;
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomFetchStr(pOom, pDb, "four", "sixteen", &rc);
testOomFetchStr(pOom, pDb, "seven", "fourtynine", &rc);
testOomFetchStr(pOom, pDb, "one", "one", &rc);
testOomFetchStr(pOom, pDb, "eight", "sixtyfour", &rc);
lsm_close(pDb);
}
/*
** Test the results of OOM conditions in simple write operations.
*/
static void simple_oom_4(OomTest *pOom){
int rc = LSM_OK;
lsm_db *pDb;
testDeleteLsmdb(LSMTEST6_TESTDB);
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomWriteStr(pOom, pDb, "123", "onetwothree", &rc);
testOomWriteStr(pOom, pDb, "456", "fourfivesix", &rc);
testOomWriteStr(pOom, pDb, "789", "seveneightnine", &rc);
testOomWriteStr(pOom, pDb, "123", "teneleventwelve", &rc);
testOomWriteStr(pOom, pDb, "456", "fourteenfifteensixteen", &rc);
lsm_close(pDb);
}
static void simple_oom_5(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomFetchData(pOom, pDb, pData, 3333, &rc);
testOomFetchData(pOom, pDb, pData, 0, &rc);
testOomFetchData(pOom, pDb, pData, 4999, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
static void simple_oom_6(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomWriteData(pOom, pDb, pData, 5000, &rc);
testOomWriteData(pOom, pDb, pData, 5001, &rc);
testOomWriteData(pOom, pDb, pData, 5002, &rc);
testOomFetchData(pOom, pDb, pData, 5001, &rc);
testOomFetchData(pOom, pDb, pData, 1234, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
static void simple_oom_7(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomScan(pOom, pDb, 0, "abc", 3, 20, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
static void simple_oom_8(OomTest *pOom){
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb;
testRestoreDb(LSMTEST6_TESTDB, "log");
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb, &rc);
testOomScan(pOom, pDb, 1, "xyz", 3, 20, &rc);
lsm_close(pDb);
testDatasourceFree(pData);
}
/*
** This test case has two clients connected to a database. The first client
** hits an OOM while writing to the database. Check that the second
** connection is still able to query the db following the OOM.
*/
static void simple_oom2_1(OomTest *pOom){
const int nRecord = 100; /* Number of records initially in db */
const int nIns = 10; /* Number of records inserted with OOM */
Datasource *pData = getDatasource();
int rc = LSM_OK;
lsm_db *pDb1;
lsm_db *pDb2;
int i;
testDeleteLsmdb(LSMTEST6_TESTDB);
/* Open the two connections. Initialize the in-memory tree so that it
** contains 100 records. Do all this with OOM injection disabled. */
testOomEnable(pOom, 0);
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb1, &rc);
testOomOpen(pOom, LSMTEST6_TESTDB, &pDb2, &rc);
for(i=0; i<nRecord; i++){
testOomWriteData(pOom, pDb1, pData, i, &rc);
}
testOomEnable(pOom, 1);
assert( rc==0 );
/* Insert 10 more records using pDb1. Stop when an OOM is encountered. */
for(i=nRecord; i<nRecord+nIns; i++){
testOomWriteData(pOom, pDb1, pData, i, &rc);
if( rc ) break;
}
testOomAssertRc(pOom, rc);
/* Switch off OOM injection. Write a few rows using pDb2. Then check
** that the database may be successfully queried. */
testOomEnable(pOom, 0);
rc = 0;
for(; i<nRecord+nIns && rc==0; i++){
testOomWriteData(pOom, pDb2, pData, i, &rc);
}
for(i=0; i<nRecord+nIns; i++) testOomFetchData(pOom, pDb2, pData, i, &rc);
testOomEnable(pOom, 1);
lsm_close(pDb1);
lsm_close(pDb2);
testDatasourceFree(pData);
}
static void do_test_oom1(const char *zPattern, int *pRc){
struct SimpleOom {
const char *zName;
void (*xSetup)(void);
void (*xFunc)(OomTest *);
} aSimple[] = {
{ "oom1.lsm.1", setup_delete_db, simple_oom_1 },
{ "oom1.lsm.2", setup_delete_db, simple_oom_2 },
{ "oom1.lsm.3", setup_populate_db, simple_oom_3 },
{ "oom1.lsm.4", setup_delete_db, simple_oom_4 },
{ "oom1.lsm.5", setup_populate_db2, simple_oom_5 },
{ "oom1.lsm.6", setup_populate_db2, simple_oom_6 },
{ "oom1.lsm.7", setup_populate_db2, simple_oom_7 },
{ "oom1.lsm.8", setup_populate_db2, simple_oom_8 },
{ "oom2.lsm.1", setup_delete_db, simple_oom2_1 },
};
int i;
for(i=0; i<ArraySize(aSimple); i++){
if( *pRc==0 && testCaseBegin(pRc, zPattern, "%s", aSimple[i].zName) ){
OomTest t;
if( aSimple[i].xSetup ){
aSimple[i].xSetup();
}
for(testOomStart(&t); testOomContinue(&t); testOomNext(&t)){
aSimple[i].xFunc(&t);
}
printf("(%d injections).", t.iNext-2);
testCaseFinish( (*pRc = testOomFinish(&t)) );
testMallocOom(tdb_lsm_env(), 0, 0, 0, 0);
}
}
}
void test_oom(
const char *zPattern, /* Run test cases that match this pattern */
int *pRc /* IN/OUT: Error code */
){
do_test_oom1(zPattern, pRc);
}

Some files were not shown because too many files have changed in this diff Show More