Compare commits
590 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba76c160c7 | |||
| f3e0993b9d | |||
| c51f318f6a | |||
| 3a621d8a58 | |||
| b8c49d6f62 | |||
| a303f7914d | |||
| 632632ced3 | |||
| f8cae0b149 | |||
| bc9cebcd1d | |||
| 2b0579b06b | |||
| 323199b57e | |||
| 67767084b6 | |||
| 55385fb79c | |||
| fced18af1a | |||
| 334fa0eb5a | |||
| e20e6f59c2 | |||
| a1de06a4c6 | |||
| 158436f53d | |||
| d261437615 | |||
| 8c7f142470 | |||
| 525d297450 | |||
| 2605119d14 | |||
| de223ffbbd | |||
| ea0cda00d6 | |||
| c2aa8e3875 | |||
| 1bf7eb3d49 | |||
| f1c37a357e | |||
| d95fffc9af | |||
| 4733884eae | |||
| 0dfa31d279 | |||
| 15c6d88381 | |||
| eaacb4ac37 | |||
| 0c747e1653 | |||
| e5c8467a8e | |||
| b2b8ab6bc8 | |||
| 7f70085071 | |||
| a183595edd | |||
| 63ab7c625c | |||
| 1c19c06246 | |||
| da17de532f | |||
| 1ed6441bb1 | |||
| 139ec38ac8 | |||
| 41fda52f3c | |||
| 7fb2545905 | |||
| 3a61466a2f | |||
| 916fc1129c | |||
| a8a99becb5 | |||
| f3b396494f | |||
| 4ebf49168a | |||
| c6b86ba2ab | |||
| c5ff2aa7cf | |||
| cb36dc3f3e | |||
| 7c86a0321e | |||
| d443f0a95f | |||
| 34b1bf16ec | |||
| 74cd3c53f9 | |||
| ffbfc27fab | |||
| 5a9ada593f | |||
| 9c0770537f | |||
| 6cc222c3be | |||
| db0d47b749 | |||
| e34f35c833 | |||
| 626351d444 | |||
| 6e27846323 | |||
| 8ce786f173 | |||
| 6b9230d2a1 | |||
| d4ead9b9e4 | |||
| f57d368078 | |||
| 3fceae3b95 | |||
| 38113d392d | |||
| a105989856 | |||
| ecbeefecd0 | |||
| 2b24d8957e | |||
| 726e836108 | |||
| 7be565f0cc | |||
| c053b57716 | |||
| 0d859b4828 | |||
| ab29c24dc3 | |||
| dcc07d3ca6 | |||
| 234c6c4bf0 | |||
| 86319b841a | |||
| f4e66056ac | |||
| 76db3a6e66 | |||
| 003737d1dc | |||
| be4d0c2e2f | |||
| aeb886bc53 | |||
| 2f9311c5cb | |||
| 093b26e8e0 | |||
| 63ee854264 | |||
| 3ba506d9cc | |||
| 67fa337744 | |||
| 033dbac510 | |||
| 9af334f54a | |||
| 4bb53ab2e4 | |||
| 7adc9a5978 | |||
| acdda1075d | |||
| bc2691d5c1 | |||
| 95c188d557 | |||
| 4043096408 | |||
| d06a0be514 | |||
| 984e446891 | |||
| 774ce0ba43 | |||
| d41f5ef7e6 | |||
| efe8ae567c | |||
| 21c57abc53 | |||
| 31c86ca0a8 | |||
| 9f36870a77 | |||
| 9c3fcd932d | |||
| 0a585a64d2 | |||
| 6eaeea0a3b | |||
| e826aa8e00 | |||
| ff5d4c348c | |||
| f66a0600d8 | |||
| 34c1e04cbf | |||
| f83df5b150 | |||
| d6cb2ccee6 | |||
| e7cf3fe4c8 | |||
| efde2f6059 | |||
| 53a6b7d138 | |||
| 4472c967a6 | |||
| abe709be8d | |||
| 5dbbe50758 | |||
| 9f136fc5ed | |||
| 898ac77f55 | |||
| 264bcad69a | |||
| a8bb50ce95 | |||
| c93270ebc7 | |||
| 94356039d0 | |||
| ee4676b3f7 | |||
| e4eaf174a5 | |||
| 59e1ab5576 | |||
| 11878165f6 | |||
| 5013fd1f81 | |||
| eeb2e03b7b | |||
| 80f0fcd31d | |||
| 8c1670642d | |||
| e33786f09a | |||
| f9d511319b | |||
| ea0d2cebd9 | |||
| 7b34ca9cc1 | |||
| 8080411752 | |||
| 97fa2fe414 | |||
| b4fdfc2f9a | |||
| 40d299ae32 | |||
| 0f5a3f16f3 | |||
| 3be9a9b984 | |||
| 8f2f5e4963 | |||
| 0df9db4921 | |||
| 01f5e6e757 | |||
| ba5cce9f08 | |||
| cdaff852bf | |||
| e15ef5b756 | |||
| d3973778a1 | |||
| 55085a2cc2 | |||
| b8d2ca1513 | |||
| 6147a0f6a1 | |||
| 308831d1c7 | |||
| 9b6bc61dbd | |||
| 7aa5271c72 | |||
| 9804ed7021 | |||
| 75ef68e385 | |||
| 35299c9076 | |||
| 87f53152ed | |||
| 6f7c977ed9 | |||
| ad7118fa68 | |||
| 0ab87fc9a7 | |||
| 0611aeeed4 | |||
| 566348f68b | |||
| d357d9d1cd | |||
| 833fb1ef59 | |||
| 34775b696b | |||
| d310393158 | |||
| 275d08ad62 | |||
| 1d574d3d71 | |||
| e2ebc364cd | |||
| 0d9ec8b2ee | |||
| 4defad2f29 | |||
| 7d973ac52f | |||
| b9c23fa541 | |||
| cbc3cd47f0 | |||
| fa563eff1d | |||
| 65ee59bb26 | |||
| a9af4102f1 | |||
| 4af7048aeb | |||
| 0f76b0a4d6 | |||
| c8e6f627b8 | |||
| d05bf5aedf | |||
| 5b15123fba | |||
| 974b8d7df0 | |||
| 8f6b797a1b | |||
| 3eccaa7915 | |||
| c49ff175ef | |||
| e6197c0d1d | |||
| 7e38287da4 | |||
| 381df874f0 | |||
| b7f5885b3e | |||
| 36ba76010c | |||
| 436c8e5026 | |||
| 1bf80f2dce | |||
| 39bffbcd32 | |||
| d3cd2a25b4 | |||
| 9ffb344ed9 | |||
| 5b047a8ec6 | |||
| c2f7be11bb | |||
| 1d592e0d62 | |||
| 0b0c8734f3 | |||
| 54f296389c | |||
| 41549103ac | |||
| c090488133 | |||
| 943324c80d | |||
| 18af487597 | |||
| 15e4074084 | |||
| 4ac2118c5d | |||
| 4bdfae9d40 | |||
| 5d0d30ae2d | |||
| 836e895f9e | |||
| 879066a0a2 | |||
| e309de27f9 | |||
| a34f87d25a | |||
| 42f9273da2 | |||
| 96c753ec56 | |||
| b62c26d999 | |||
| 80d74f0934 | |||
| 3a94a00768 | |||
| 8d2f3a1f82 | |||
| c839ea5d94 | |||
| 6553a5d6a6 | |||
| c9f1759c94 | |||
| a7a8d7fa87 | |||
| e040128ecd | |||
| 92f93556e5 | |||
| 5ace5e0a38 | |||
| c1254430d8 | |||
| 3574ec40a6 | |||
| 51e3a140c9 | |||
| ae48a2463b | |||
| 3e7fe489e2 | |||
| a4476ea1fa | |||
| 5ad6e7b0e0 | |||
| 5dbbbf4923 | |||
| 96d39ce7d2 | |||
| 653e32e9a1 | |||
| 31efe5a0f2 | |||
| dc868ef879 | |||
| 4d488bd341 | |||
| 3ed76ca35b | |||
| 99cb0049ee | |||
| ef565295f5 | |||
| 9daf58ee8d | |||
| 3675a69f1d | |||
| 9444c29094 | |||
| 6d3ae03f1e | |||
| b8a62d9da7 | |||
| 1ecc36a2b0 | |||
| 2c88a2ffb5 | |||
| 96bb92e70c | |||
| 892109542b | |||
| 68353d0531 | |||
| 2abc502ebc | |||
| dc90d7055c | |||
| 2364fe3b38 | |||
| 1f030eac9f | |||
| 36baed3e2e | |||
| ca574fa1d5 | |||
| feeacfb897 | |||
| b927708437 | |||
| 8d93e83461 | |||
| 205257791c | |||
| 4500a87c95 | |||
| 5c01f3fb83 | |||
| e779baa099 | |||
| 3b56f296e9 | |||
| 0dee14a559 | |||
| 9300c4a13c | |||
| ac37661a16 | |||
| cac1ef709f | |||
| 611ffbc981 | |||
| cfce9b6a11 | |||
| a07871d332 | |||
| 5c0850f8b8 | |||
| ebb99967c2 | |||
| aa5b8f9d47 | |||
| 91b1b0de2b | |||
| 12f17d41f9 | |||
| a8bddde325 | |||
| b19c14742d | |||
| e55a29f5fd | |||
| cfa48c17f7 | |||
| 1ab3d7eafd | |||
| 6ba22a75f3 | |||
| 2ea861a245 | |||
| 34d92f4ac6 | |||
| 8eefa2725b | |||
| 65551b5456 | |||
| 5a2e3c4af2 | |||
| 1d49644650 | |||
| 1e01174ac3 | |||
| 60633a852d | |||
| 589855f40e | |||
| e6db55f0e2 | |||
| 50815f8ba4 | |||
| b10548a7b0 | |||
| cf0f11ac18 | |||
| 334b15d8fc | |||
| 5b71447e8e | |||
| 128ae8ea3f | |||
| 1e2156e926 | |||
| d97c59e2bc | |||
| 72d81265ab | |||
| 23203a407e | |||
| ba6527af04 | |||
| f568a2f1bf | |||
| 51127416a4 | |||
| d1b64404b3 | |||
| 2674a4fdcb | |||
| 3e205eff8e | |||
| 25e416dc3a | |||
| 7462b3749a | |||
| 043136276a | |||
| 93cd069fdf | |||
| 832dfd97d1 | |||
| a8756afdbc | |||
| a2daecfc8c | |||
| cbefdaad9e | |||
| 65a445d750 | |||
| bd5d297fec | |||
| 22f9ca64db | |||
| 6a03f2029b | |||
| d6403a2d2e | |||
| 78202b9a3b | |||
| a09a8ffa62 | |||
| 723e8c88fa | |||
| d4cc844a2b | |||
| 49a37f333a | |||
| 194d6edeb6 | |||
| e7fe1d3b3e | |||
| f5dc671a57 | |||
| e7efe1e201 | |||
| 8f5503861f | |||
| 7cbfa5b0d1 | |||
| 3312564540 | |||
| 16eedfbdda | |||
| 9290d70466 | |||
| 3e17953beb | |||
| ac28cc30c0 | |||
| 12ed2fea03 | |||
| a12c1dcca6 | |||
| 48790b48a7 | |||
| e924087d30 | |||
| c35f07ec2f | |||
| 36595d0630 | |||
| 6b8d7ac599 | |||
| 0247e15f69 | |||
| c7cb05813c | |||
| 419b93adbf | |||
| 96455af950 | |||
| a248d84fbe | |||
| 2c4008fe26 | |||
| 195956af94 | |||
| 28a7f01f90 | |||
| d968525382 | |||
| eb8089ef46 | |||
| 9455a6e8b8 | |||
| 56d831e064 | |||
| 7754f53045 | |||
| 4619855103 | |||
| be4cf645a8 | |||
| 065daf24b4 | |||
| 0b8e4294d5 | |||
| d61dbf7072 | |||
| 586361fa7c | |||
| e7f190b8e1 | |||
| 130a2f52b1 | |||
| 92f91ca37d | |||
| 4edee00ee0 | |||
| 91020438c0 | |||
| b4af09c80e | |||
| 75ca99ab99 | |||
| cf0ba94657 | |||
| d7d632d581 | |||
| 4cefe53a33 | |||
| afd432f86e | |||
| 7aadad63e9 | |||
| b9bf2d9382 | |||
| d8d88d9390 | |||
| c0e3a8ca19 | |||
| f28c0f37f2 | |||
| 2af776ff59 | |||
| 8fb8782e2a | |||
| 7fa9e45746 | |||
| 6f341f499a | |||
| f91151bfa1 | |||
| 20bfeccb65 | |||
| f942995fd2 | |||
| 62ed0b79da | |||
| a00b9b99ba | |||
| 9976684d26 | |||
| 8200750eb1 | |||
| dca1f04f07 | |||
| 1df00568b3 | |||
| f8b5cc695c | |||
| 3c2b02d919 | |||
| 08a256958f | |||
| 7af1d61886 | |||
| c6925d5922 | |||
| 4bace197e1 | |||
| 81b8ad0830 | |||
| b33477c5b4 | |||
| d271627f96 | |||
| fbb07ff67f | |||
| db97d2ef81 | |||
| 6f15549f91 | |||
| 90916e5ba0 | |||
| 8376b87ae3 | |||
| 1702244d2e | |||
| bb4743c278 | |||
| 5e972ddd9f | |||
| 51d3e6d51c | |||
| 1be5689087 | |||
| c30e1a10ef | |||
| 4a27581f14 | |||
| 697d29ea49 | |||
| 7f84ce0ea9 | |||
| a6c95406c1 | |||
| e3fc1fc8dd | |||
| 6f097125cd | |||
| 0e77c3fa4d | |||
| 527062ac5e | |||
| 656563cce9 | |||
| 6cebfa56cc | |||
| 8e875fa3bd | |||
| c5c9c6093b | |||
| 16478dbfdd | |||
| a939a635a2 | |||
| 3f85939bf0 | |||
| b1406a6550 | |||
| 1ecc135cc5 | |||
| 9081b89720 | |||
| 88f7807fa6 | |||
| 11ba513fe5 | |||
| e7440380c2 | |||
| e6061cba7f | |||
| 5d06c6b3f1 | |||
| de048aeda9 | |||
| 7270a56fdf | |||
| aa86b2a373 | |||
| ff1d5e5bb8 | |||
| cd70a44d45 | |||
| 332eb8e63c | |||
| f9c2cff2fe | |||
| eff534e1a5 | |||
| a37bf61539 | |||
| d7d77eb56d | |||
| 82b08cc8ef | |||
| e318c4573b | |||
| 8725bf916d | |||
| 1f4c281b0b | |||
| 1cf61ce636 | |||
| cd552cf99f | |||
| 8c30f16a2e | |||
| f681a9a7d8 | |||
| 380ef6006b | |||
| a0e569d5ba | |||
| 46c7568db5 | |||
| 210b182b79 | |||
| 1e687a4187 | |||
| 67695a30ea | |||
| 3e616d3445 | |||
| d38777134b | |||
| df23b518da | |||
| 7957c70947 | |||
| b79848edd4 | |||
| 1560d52f82 | |||
| f402509b62 | |||
| bac6793a8a | |||
| 7423ecb0a9 | |||
| 7bcb650f57 | |||
| 6d7be8293e | |||
| 5a6f651397 | |||
| d649d7b90c | |||
| 095d399e7c | |||
| fdd37e9637 | |||
| 2445ee0e37 | |||
| ea8f9708c5 | |||
| bcd14a0a3e | |||
| c585e03a4b | |||
| 1f436ad563 | |||
| daa4cdf84a | |||
| bae748a76e | |||
| 74cc109780 | |||
| 01a2953350 | |||
| cf05295a85 | |||
| 91db1c413b | |||
| 10687e283a | |||
| 074b1aa42d | |||
| 522ce56734 | |||
| 68b74e2c42 | |||
| e5a7b815af | |||
| f98148be9c | |||
| 27e13f4f3a | |||
| 81e9bbf8da | |||
| 7d20c2e8a3 | |||
| 192d0ff8cc | |||
| 97e6368abc | |||
| 1c11aa3da2 | |||
| bf5f1f5172 | |||
| 194f0bada7 | |||
| 08f8111bd8 | |||
| f8addcf937 | |||
| bcfe38b96a | |||
| 1b8f6558f8 | |||
| 1f68085849 | |||
| c493e4516a | |||
| 69b5674b40 | |||
| 0eca9db776 | |||
| c066f2af9c | |||
| 625d0b70fe | |||
| 45bff0ea64 | |||
| 07b483c48e | |||
| 6fd9469a32 | |||
| 33c2e37f98 | |||
| 2ba5a93e8f | |||
| 6276637075 | |||
| 8663a78ec9 | |||
| aa12f0027b | |||
| 9a13a21223 | |||
| 9b91aac83b | |||
| acd1d93497 | |||
| 449b34571e | |||
| 9615cf93c8 | |||
| 925b79039c | |||
| 7fc6e6a272 | |||
| 8c8443a38a | |||
| 44a03671c4 | |||
| 0a5508aeb4 | |||
| 4fe1ac8fe1 | |||
| 24d290e7b0 | |||
| 8504d37b99 | |||
| 4aacd1ef8e | |||
| 0840460689 | |||
| 240319decd | |||
| 787f4c3f09 | |||
| 4d453cc2ed | |||
| c701d17366 | |||
| 8bc112e3e4 | |||
| 27408ab9c9 | |||
| d9eae6b75a | |||
| 45bc9b9f97 | |||
| e33ea17d24 | |||
| a12e92d2f7 | |||
| 478dfc7e74 | |||
| 1b62720fa8 | |||
| 1e3a862b79 | |||
| bd05edd98f | |||
| a24a397b8b | |||
| 0e6e05d4d5 | |||
| c525e6e817 | |||
| 1ff6f19d8b | |||
| bfb4993364 | |||
| debc8f7bb7 | |||
| aa54d7a0ca | |||
| eb27359e5e | |||
| 33f3273705 | |||
| 216676664d | |||
| 6245e5a46b | |||
| caf0473652 | |||
| 2427ce16d9 | |||
| 46bfcc1a21 | |||
| 5e71497404 | |||
| 526399b0fd | |||
| e1910ed1d2 | |||
| d82c6a2cf7 | |||
| 3d21dcc924 | |||
| ba56f7020d | |||
| 99f1aa03fb | |||
| 280559b446 | |||
| e2e81e6983 | |||
| e24f20a4f5 | |||
| 311d73efc2 | |||
| a3ee3860a2 | |||
| c96e47c80e | |||
| 620a00ee32 | |||
| 62b954d545 | |||
| 0d92e66dfc | |||
| ddc62664bf | |||
| b4f41b801a | |||
| df77e56cde | |||
| dc9a262319 | |||
| b111f1cb2a | |||
| 5525ac1049 |
+10
-16
@@ -30,14 +30,12 @@ The public domain source files usually contain a header comment
|
||||
similar to the following to make it clear that the software is
|
||||
public domain.
|
||||
|
||||
> ~~~
|
||||
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.
|
||||
~~~
|
||||
> 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.
|
||||
|
||||
Almost every file you find in this source repository will be
|
||||
public domain. But there are a small number of exceptions:
|
||||
@@ -49,9 +47,7 @@ This repository contains a (relatively) small amount of non-public-domain
|
||||
code used to help implement the configuration and build logic. In other
|
||||
words, there are some non-public-domain files used to implement:
|
||||
|
||||
> ~~~
|
||||
./configure && make
|
||||
~~~
|
||||
> ./configure && make
|
||||
|
||||
In all cases, the non-public-domain files included with this
|
||||
repository have generous BSD-style licenses. So anyone is free to
|
||||
@@ -69,7 +65,7 @@ third-party build scripts in order to compile SQLite.
|
||||
Non-public-domain code included in this respository includes:
|
||||
|
||||
* The ["autosetup"](http://msteveb.github.io/autosetup/) configuration
|
||||
system that is contained (mostly) the autosetup/ directory, but also
|
||||
system that is contained (mostly) in the autosetup/ directory, but also
|
||||
includes the "./configure" script at the top-level of this archive.
|
||||
Autosetup has a separate BSD-style license. See the
|
||||
[autosetup/LICENSE](http://msteveb.github.io/autosetup/license/)
|
||||
@@ -79,13 +75,11 @@ Non-public-domain code included in this respository includes:
|
||||
software found in the legacy autoconf/ directory and its
|
||||
subdirectories.
|
||||
|
||||
The following unix shell command is can be run from the top-level
|
||||
The following unix shell command can be run from the top-level
|
||||
of this source repository in order to remove all non-public-domain
|
||||
code:
|
||||
|
||||
> ~~~
|
||||
rm -rf configure autosetup autoconf
|
||||
~~~
|
||||
> rm -rf configure autosetup autoconf
|
||||
|
||||
If you unpack this source repository and then run the command above, what
|
||||
is left will be 100% public domain.
|
||||
|
||||
+5
-15
@@ -11,17 +11,6 @@
|
||||
#
|
||||
all:
|
||||
########################################################################
|
||||
#
|
||||
# Known TODOs/FIXMEs/TOIMPROVEs for the autosetup port, in no
|
||||
# particular order...
|
||||
#
|
||||
# - TEA pieces.
|
||||
#
|
||||
# - Replace the autotools-specific distribution deliverable(s).
|
||||
#
|
||||
# - Confirm whether cross-compilation works and patch it
|
||||
# appropriately.
|
||||
#
|
||||
# Maintenance reminders:
|
||||
#
|
||||
# - This makefile should remain as POSIX-make-compatible as possible:
|
||||
@@ -264,7 +253,9 @@ AS_AUTO_DEF = $(TOP)/auto.def
|
||||
# invoked with to produce this makefile.
|
||||
#
|
||||
AS_AUTORECONFIG = @SQLITE_AUTORECONFIG@
|
||||
|
||||
.PHONY: config reconfigure
|
||||
config reconfigure:
|
||||
$(AS_AUTORECONFIG)
|
||||
USE_AMALGAMATION ?= @USE_AMALGAMATION@
|
||||
LINK_TOOLS_DYNAMICALLY ?= @LINK_TOOLS_DYNAMICALLY@
|
||||
AMALGAMATION_GEN_FLAGS ?= --linemacros=@AMALGAMATION_LINE_MACROS@
|
||||
@@ -322,9 +313,8 @@ fiddle: sqlite3.c shell.c
|
||||
./custom.rws: ./tool/custom.txt
|
||||
@echo 'Updating custom dictionary from tool/custom.txt'
|
||||
aspell --lang=en create master ./custom.rws < ./tool/custom.txt
|
||||
# Note that jimsh does not work here:
|
||||
# https://github.com/msteveb/jimtcl/issues/319
|
||||
misspell: ./custom.rws has_tclsh84
|
||||
# $(JIMSH) does not work with spellsift.tcl
|
||||
$(TCLSH_CMD) ./tool/spellsift.tcl ./src/*.c ./src/*.h ./src/*.in
|
||||
|
||||
#
|
||||
@@ -341,7 +331,7 @@ distclean: distclean-autosetup
|
||||
|
||||
#
|
||||
# tool/version-info: a utility for emitting sqlite3 version info
|
||||
# in various forms.
|
||||
# in various forms. It's used by ext/wasm/.
|
||||
#
|
||||
version-info$(T.exe): $(TOP)/tool/version-info.c Makefile sqlite3.h
|
||||
$(T.link) $(ST_OPT) -o $@ $(TOP)/tool/version-info.c
|
||||
|
||||
+148
-33
@@ -405,6 +405,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_CARRAY=1
|
||||
!ENDIF
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
|
||||
!ENDIF
|
||||
@@ -427,6 +428,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
|
||||
|
||||
# Always enable math functions on Windows
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MATH_FUNCTIONS
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PERCENTILE
|
||||
|
||||
# Should the rbu extension be enabled? If so, add compilation options
|
||||
# to enable it.
|
||||
@@ -803,17 +805,21 @@ BCC = $(BCC) /d2guard4 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
|
||||
!IF $(DEBUG)>1
|
||||
TCC = $(TCC) -MDd
|
||||
BCC = $(BCC) -MDd
|
||||
ZLIBCFLAGS = -nologo -MDd -W3 -O2 -Oy- -Zi
|
||||
!ELSE
|
||||
TCC = $(TCC) -MD
|
||||
BCC = $(BCC) -MD
|
||||
ZLIBCFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi
|
||||
!ENDIF
|
||||
!ELSE
|
||||
!IF $(DEBUG)>1
|
||||
TCC = $(TCC) -MTd
|
||||
BCC = $(BCC) -MTd
|
||||
ZLIBCFLAGS = -nologo -MTd -W3 -O2 -Oy- -Zi
|
||||
!ELSE
|
||||
TCC = $(TCC) -MT
|
||||
BCC = $(BCC) -MT
|
||||
ZLIBCFLAGS = -nologo -MT -W3 -O2 -Oy- -Zi
|
||||
!ENDIF
|
||||
!ENDIF
|
||||
|
||||
@@ -1343,7 +1349,7 @@ LTLIBS = $(LTLIBS) $(LIBICU)
|
||||
#
|
||||
LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \
|
||||
backup.lo bitvec.lo btmutex.lo btree.lo build.lo \
|
||||
callback.lo complete.lo ctime.lo \
|
||||
callback.lo carray.lo complete.lo ctime.lo \
|
||||
date.lo dbpage.lo dbstat.lo delete.lo \
|
||||
expr.lo fault.lo fkey.lo \
|
||||
fts3.lo fts3_aux.lo fts3_expr.lo fts3_hash.lo fts3_icu.lo \
|
||||
@@ -1405,6 +1411,7 @@ SRC00 = \
|
||||
$(TOP)\src\btree.c \
|
||||
$(TOP)\src\build.c \
|
||||
$(TOP)\src\callback.c \
|
||||
$(TOP)\src\carray.c \
|
||||
$(TOP)\src\complete.c \
|
||||
ctime.c \
|
||||
$(TOP)\src\date.c \
|
||||
@@ -1638,7 +1645,6 @@ TESTEXT = \
|
||||
$(TOP)\ext\misc\amatch.c \
|
||||
$(TOP)\ext\misc\appendvfs.c \
|
||||
$(TOP)\ext\misc\basexx.c \
|
||||
$(TOP)\ext\misc\carray.c \
|
||||
$(TOP)\ext\misc\cksumvfs.c \
|
||||
$(TOP)\ext\misc\closure.c \
|
||||
$(TOP)\ext\misc\csv.c \
|
||||
@@ -1654,7 +1660,6 @@ TESTEXT = \
|
||||
$(TOP)\ext\misc\mmapwarm.c \
|
||||
$(TOP)\ext\misc\nextchar.c \
|
||||
$(TOP)\ext\misc\normalize.c \
|
||||
$(TOP)\ext\misc\percentile.c \
|
||||
$(TOP)\ext\misc\prefixes.c \
|
||||
$(TOP)\ext\misc\qpvtab.c \
|
||||
$(TOP)\ext\misc\randomjson.c \
|
||||
@@ -1766,6 +1771,7 @@ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_DQS=0
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_PERCENTILE=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_STMT_SCANSTATUS=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_STRICT_SUBTYPE=1
|
||||
@@ -1780,6 +1786,7 @@ FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -I$(TOP)\test -I$(TOP)\ext\recover
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_OSS_FUZZ
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_CARRAY
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
@@ -1793,6 +1800,7 @@ FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MATH_FUNCTIONS
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_NORMALIZE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_PERCENTILE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_PREUPDATE_HOOK
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_SESSION
|
||||
@@ -1823,7 +1831,6 @@ FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\test\fuzzinvariants.c
|
||||
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\test\vt02.c
|
||||
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\recover\dbdata.c
|
||||
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\recover\sqlite3recover.c
|
||||
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\percentile.c
|
||||
FUZZCHECK_SRC = $(FUZZCHECK_SRC) $(TOP)\ext\misc\randomjson.c
|
||||
|
||||
OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
|
||||
@@ -2101,6 +2108,9 @@ build.lo: $(TOP)\src\build.c $(HDR)
|
||||
callback.lo: $(TOP)\src\callback.c $(HDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\callback.c
|
||||
|
||||
carray.lo: $(TOP)\src\carray.c $(HDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\carray.c
|
||||
|
||||
complete.lo: $(TOP)\src\complete.c $(HDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\complete.c
|
||||
|
||||
@@ -2384,7 +2394,6 @@ SHELL_DEP = \
|
||||
$(TOP)\ext\misc\ieee754.c \
|
||||
$(TOP)\ext\misc\memtrace.c \
|
||||
$(TOP)\ext\misc\pcachetrace.c \
|
||||
$(TOP)\ext\misc\percentile.c \
|
||||
$(TOP)\ext\misc\regexp.c \
|
||||
$(TOP)\ext\misc\series.c \
|
||||
$(TOP)\ext\misc\sha1.c \
|
||||
@@ -2411,7 +2420,7 @@ shell.c: $(SHELL_DEP) $(TOP)\tool\mkshellc.tcl $(JIM_TCLSH)
|
||||
$(JIM_TCLSH) $(TOP)\tool\mkshellc.tcl shell.c
|
||||
|
||||
zlib:
|
||||
pushd $(ZLIBDIR) && $(MAKE) /f win32\Makefile.msc clean $(ZLIBLIB) && popd
|
||||
pushd $(ZLIBDIR) && $(MAKE) /f win32\Makefile.msc clean $(ZLIBLIB) CFLAGS="$(ZLIBCFLAGS)" && popd
|
||||
|
||||
# Rules to build the extension objects.
|
||||
#
|
||||
@@ -2485,24 +2494,6 @@ FTS5_SRC = \
|
||||
$(TOP)\ext\fts5\fts5_varint.c \
|
||||
$(TOP)\ext\fts5\fts5_vocab.c
|
||||
|
||||
LSM1_SRC = \
|
||||
$(TOP)\ext\lsm1\lsm.h \
|
||||
$(TOP)\ext\lsm1\lsmInt.h \
|
||||
$(TOP)\ext\lsm1\lsm_ckpt.c \
|
||||
$(TOP)\ext\lsm1\lsm_file.c \
|
||||
$(TOP)\ext\lsm1\lsm_log.c \
|
||||
$(TOP)\ext\lsm1\lsm_main.c \
|
||||
$(TOP)\ext\lsm1\lsm_mem.c \
|
||||
$(TOP)\ext\lsm1\lsm_mutex.c \
|
||||
$(TOP)\ext\lsm1\lsm_shared.c \
|
||||
$(TOP)\ext\lsm1\lsm_sorted.c \
|
||||
$(TOP)\ext\lsm1\lsm_str.c \
|
||||
$(TOP)\ext\lsm1\lsm_tree.c \
|
||||
$(TOP)\ext\lsm1\lsm_unix.c \
|
||||
$(TOP)\ext\lsm1\lsm_varint.c \
|
||||
$(TOP)\ext\lsm1\lsm_vtab.c \
|
||||
$(TOP)\ext\lsm1\lsm_win32.c
|
||||
|
||||
fts5parse.c: $(TOP)\ext\fts5\fts5parse.y lemon.exe
|
||||
copy /Y $(TOP)\ext\fts5\fts5parse.y .
|
||||
copy /B fts5parse.y +,,
|
||||
@@ -2516,11 +2507,6 @@ fts5.c: $(FTS5_SRC) $(JIM_TCLSH)
|
||||
copy /Y $(TOP)\ext\fts5\fts5.h .
|
||||
copy /B fts5.h +,,
|
||||
|
||||
lsm1.c: $(LSM1_SRC) $(JIM_TCLSH)
|
||||
$(JIM_TCLSH) $(TOP)\ext\lsm1\tool\mklsm1c.tcl
|
||||
copy /Y $(TOP)\ext\lsm1\lsm.h .
|
||||
copy /B lsm.h +,,
|
||||
|
||||
fts5.lo: fts5.c $(HDR) $(EXTHDR)
|
||||
$(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c fts5.c
|
||||
|
||||
@@ -2548,6 +2534,8 @@ TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_CARRAY=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_PERCENTILE=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CKSUMVFS_STATIC=1
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
|
||||
TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_STATIC_RANDOMJSON
|
||||
@@ -2596,9 +2584,12 @@ extensiontest: testfixture.exe testloadext.dll
|
||||
@set PATH=$(LIBTCLPATH);$(PATH)
|
||||
.\testfixture.exe $(TOP)\test\loadext.test $(TESTOPTS)
|
||||
|
||||
tool-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe sqlite3_rsync.exe $(TOP)\tool\mktoolzip.tcl
|
||||
tool-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe sqlite3_rsync.exe sqlite3.dll $(TOP)\tool\mktoolzip.tcl
|
||||
.\testfixture.exe $(TOP)\tool\mktoolzip.tcl
|
||||
|
||||
snapshot-zip: testfixture.exe sqlite3.exe sqldiff.exe sqlite3_analyzer.exe sqlite3_rsync.exe sqlite3.dll $(TOP)\tool\mktoolzip.tcl
|
||||
.\testfixture.exe $(TOP)\tool\mktoolzip.tcl --snapshot
|
||||
|
||||
coretestprogs: testfixture.exe sqlite3.exe
|
||||
|
||||
testprogs: $(TESTPROGS) srcck1.exe fuzzcheck.exe sessionfuzz.exe
|
||||
@@ -2824,8 +2815,133 @@ tcl-env:
|
||||
@echo JIM_TCLSH = $(JIM_TCLSH)
|
||||
@echo VISUALSTUDIOVERSION = $(VISUALSTUDIOVERSION)
|
||||
|
||||
LSMDIR=$(TOP)\ext\lsm1
|
||||
!INCLUDE $(LSMDIR)\Makefile.msc
|
||||
env:
|
||||
@echo ALL_TCL_TARGETS = $(ALL_TCL_TARGETS)
|
||||
@echo API_ARMOR = $(API_ARMOR)
|
||||
@echo ASAN = $(ASAN)
|
||||
@echo BCC = $(BCC)
|
||||
@echo BUILD_ZLIB = $(BUILD_ZLIB)
|
||||
@echo CC = $(CC)
|
||||
@echo CCOPTS = $(CCOPTS)
|
||||
@echo CHECKER_DEPS = $(CHECKER_DEPS)
|
||||
@echo CORE_CCONV_OPTS = $(CORE_CCONV_OPTS)
|
||||
@echo CORE_COMPILE_OPTS = $(CORE_COMPILE_OPTS)
|
||||
@echo CORE_LINK_DEP = $(CORE_LINK_DEP)
|
||||
@echo CORE_LINK_OPTS = $(CORE_LINK_OPTS)
|
||||
@echo CRTLIBPATH = $(CRTLIBPATH)
|
||||
@echo CSC = $(CSC)
|
||||
@echo DBFUZZ_COMPILE_OPTS = $(DBFUZZ_COMPILE_OPTS)
|
||||
@echo DEBUG = $(DEBUG)
|
||||
@echo DYNAMIC_SHELL = $(DYNAMIC_SHELL)
|
||||
@echo EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS)
|
||||
@echo EXTHDR = $(EXTHDR)
|
||||
@echo EXTRA_SRC = $(EXTRA_SRC)
|
||||
@echo FOR_UWP = $(FOR_UWP)
|
||||
@echo FUZZCHECK_OPTS = $(FUZZCHECK_OPTS)
|
||||
@echo FUZZCHECK_SRC = $(FUZZCHECK_SRC)
|
||||
@echo FUZZDATA = $(FUZZDATA)
|
||||
@echo FUZZERSHELL_COMPILE_OPTS = $(FUZZERSHELL_COMPILE_OPTS)
|
||||
@echo HDR = $(HDR)
|
||||
@echo ICUDIR = $(ICUDIR)
|
||||
@echo ICUINCDIR = $(ICUINCDIR)
|
||||
@echo ICULIBDIR = $(ICULIBDIR)
|
||||
@echo JIM_TCLSH = $(JIM_TCLSH)
|
||||
@echo KV_COMPILE_OPTS = $(KV_COMPILE_OPTS)
|
||||
@echo LDFLAGS = $(LDFLAGS)
|
||||
@echo LD = $(LD)
|
||||
@echo LIBICU = $(LIBICU)
|
||||
@echo LIBOBJ = $(LIBOBJ)
|
||||
@echo LIBREADLINE = $(LIBREADLINE)
|
||||
@echo LIBRESOBJS = $(LIBRESOBJS)
|
||||
@echo LIBTCLPATH = $(LIBTCLPATH)
|
||||
@echo LIBTCLSTUB = $(LIBTCLSTUB)
|
||||
@echo LIBTCL = $(LIBTCL)
|
||||
@echo LTCOMPILE = $(LTCOMPILE)
|
||||
@echo LTLIB = $(LTLIB)
|
||||
@echo LTLIBOPTS = $(LTLIBOPTS)
|
||||
@echo LTLIBPATHS = $(LTLIBPATHS)
|
||||
@echo LTLIBS = $(LTLIBS)
|
||||
@echo LTLINK = $(LTLINK)
|
||||
@echo LTLINKOPTS = $(LTLINKOPTS)
|
||||
@echo LTRCOMPILE = $(LTRCOMPILE)
|
||||
@echo MEMDEBUG = $(MEMDEBUG)
|
||||
@echo MINIMAL_AMALGAMATION = $(MINIMAL_AMALGAMATION)
|
||||
@echo MPTESTER_COMPILE_OPTS = $(MPTESTER_COMPILE_OPTS)
|
||||
@echo NCC = $(NCC)
|
||||
@echo NCRTLIBPATH = $(NCRTLIBPATH)
|
||||
@echo NLTLIBPATHS = $(NLTLIBPATHS)
|
||||
@echo NO_LINEMACROS = $(NO_LINEMACROS)
|
||||
@echo NO_TCL = $(NO_TCL)
|
||||
@echo NO_WARN = $(NO_WARN)
|
||||
@echo NSDKLIBPATH = $(NSDKLIBPATH)
|
||||
@echo NUCRTLIBPATH = $(NUCRTLIBPATH)
|
||||
@echo OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS)
|
||||
@echo OPTIMIZATIONS = $(OPTIMIZATIONS)
|
||||
@echo OSSSHELL_SRC = $(OSSSHELL_SRC)
|
||||
@echo OSTRACE = $(OSTRACE)
|
||||
@echo RBU = $(RBU)
|
||||
@echo RCC = $(RCC)
|
||||
@echo RC = $(RC)
|
||||
@echo READLINE_FLAGS = $(READLINE_FLAGS)
|
||||
@echo REQ_FEATURE_FLAGS = $(REQ_FEATURE_FLAGS)
|
||||
@echo RSYNC_OPT = $(RSYNC_OPT)
|
||||
@echo RSYNC_SRC = $(RSYNC_SRC)
|
||||
@echo SESSION = $(SESSION)
|
||||
@echo SETLK_TIMEOUT = $(SETLK_TIMEOUT)
|
||||
@echo SHELL_CCONV_OPTS = $(SHELL_CCONV_OPTS)
|
||||
@echo SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS)
|
||||
@echo SHELL_CORE_DEP = $(SHELL_CORE_DEP)
|
||||
@echo SHELL_CORE_LIB = $(SHELL_CORE_LIB)
|
||||
@echo SHELL_CORE_SRC = $(SHELL_CORE_SRC)
|
||||
@echo SHELL_DEP = $(SHELL_DEP)
|
||||
@echo SHELL_LINK_OPTS = $(SHELL_LINK_OPTS)
|
||||
@echo SPLIT_AMALGAMATION = $(SPLIT_AMALGAMATION)
|
||||
@echo SQLITETCLDECLSH = $(SQLITETCLDECLSH)
|
||||
@echo SQLITE_TCL_DEP = $(SQLITE_TCL_DEP)
|
||||
@echo SQLITETCLH = $(SQLITETCLH)
|
||||
@echo SRC = $(SRC)
|
||||
@echo STATICALLY_LINK_TCL = $(STATICALLY_LINK_TCL)
|
||||
@echo ST_COMPILE_OPTS = $(ST_COMPILE_OPTS)
|
||||
@echo STORELIBPATH = $(STORELIBPATH)
|
||||
@echo SYMBOLS = $(SYMBOLS)
|
||||
@echo TCC = $(TCC)
|
||||
@echo TCLDIR = $(TCLDIR)
|
||||
@echo TCLINCDIR = $(TCLINCDIR)
|
||||
@echo TCLLIBDIR = $(TCLLIBDIR)
|
||||
@echo TCLLIBPATHS = $(TCLLIBPATHS)
|
||||
@echo TCLLIBS = $(TCLLIBS)
|
||||
@echo TCLSH_CMD = $(TCLSH_CMD)
|
||||
@echo TCLSQLITEEX = $(TCLSQLITEEX)
|
||||
@echo TCLSUFFIX = $(TCLSUFFIX)
|
||||
@echo TCLVERSION = $(TCLVERSION)
|
||||
@echo TEST_CCONV_OPTS = $(TEST_CCONV_OPTS)
|
||||
@echo TESTEXT = $(TESTEXT)
|
||||
@echo TESTFIXTURE_DEP = $(TESTFIXTURE_DEP)
|
||||
@echo TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS)
|
||||
@echo TESTFIXTURE_SRC = $(TESTFIXTURE_SRC)
|
||||
@echo TESTOPTS = $(TESTOPTS)
|
||||
@echo TESTPROGS = $(TESTPROGS)
|
||||
@echo TESTSRC = $(TESTSRC)
|
||||
@echo TLIBS = $(TLIBS)
|
||||
@echo TOP = $(TOP)
|
||||
@echo UCRTLIBPATH = $(UCRTLIBPATH)
|
||||
@echo USE_AMALGAMATION = $(USE_AMALGAMATION)
|
||||
@echo USE_CRT_DLL = $(USE_CRT_DLL)
|
||||
@echo USE_FATAL_WARN = $(USE_FATAL_WARN)
|
||||
@echo USE_FULLWARN = $(USE_FULLWARN)
|
||||
@echo USE_ICU = $(USE_ICU)
|
||||
@echo USE_LISTINGS = $(USE_LISTINGS)
|
||||
@echo USE_NATIVE_LIBPATHS = $(USE_NATIVE_LIBPATHS)
|
||||
@echo USE_RC = $(USE_RC)
|
||||
@echo USE_RUNTIME_CHECKS = $(USE_RUNTIME_CHECKS)
|
||||
@echo USE_SEH = $(USE_SEH)
|
||||
@echo USE_STDCALL = $(USE_STDCALL)
|
||||
@echo USE_ZLIB = $(USE_ZLIB)
|
||||
@echo XCOMPILE = $(XCOMPILE)
|
||||
@echo ZLIBDIR = $(ZLIBDIR)
|
||||
@echo ZLIBINCDIR = $(ZLIBINCDIR)
|
||||
@echo ZLIBLIBDIR = $(ZLIBLIBDIR)
|
||||
@echo ZLIBLIB = $(ZLIBLIB)
|
||||
|
||||
moreclean: clean
|
||||
del /Q $(SQLITE3C) $(SQLITE3H) 2>NUL
|
||||
@@ -2868,7 +2984,6 @@ clean:
|
||||
del /Q kvtest.exe ossshell.exe scrub.exe 2>NUL
|
||||
del /Q showshm.exe sqlite3_checker.* sqlite3_expert.exe 2>NUL
|
||||
del /Q fts5.* fts5parse.* 2>NUL
|
||||
del /Q lsm.h lsm1.c 2>NUL
|
||||
del /q src-verify.exe 2>NUL
|
||||
del /q jimsh.exe jimsh0.exe 2>NUL
|
||||
# <</mark>>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This repository contains the complete source code for the
|
||||
[SQLite database engine](https://sqlite.org/), including
|
||||
many test scripts. However, other test scripts
|
||||
and most of the documentation are managed separately.
|
||||
many tests. Additional tests and most documentation
|
||||
are managed separately.
|
||||
|
||||
See the [on-line documentation](https://sqlite.org/) for more information
|
||||
about what SQLite is and how it works from a user's perspective. This
|
||||
@@ -53,39 +53,32 @@ then no longer be fully in the public domain.
|
||||
|
||||
## Obtaining The SQLite Source Code
|
||||
|
||||
If you do not want to use Fossil, you can download tarballs or ZIP
|
||||
archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
|
||||
Source code tarballs or ZIP archives are available at:
|
||||
|
||||
* Latest trunk check-in as
|
||||
[Tarball](https://sqlite.org/src/tarball/sqlite.tar.gz),
|
||||
[ZIP-archive](https://sqlite.org/src/zip/sqlite.zip), or
|
||||
[SQLite-archive](https://sqlite.org/src/sqlar/sqlite.sqlar).
|
||||
* [Latest trunk check-in](https://sqlite.org/src/rchvdwnld/trunk).
|
||||
|
||||
* Latest release as
|
||||
[Tarball](https://sqlite.org/src/tarball/sqlite.tar.gz?r=release),
|
||||
[ZIP-archive](https://sqlite.org/src/zip/sqlite.zip?r=release), or
|
||||
[SQLite-archive](https://sqlite.org/src/sqlar/sqlite.sqlar?r=release).
|
||||
* [Latest release](https://sqlite.org/src/rchvdwnld/release)
|
||||
|
||||
* For other check-ins, substitute an appropriate branch name or
|
||||
tag or hash prefix in place of "release" in the URLs of the previous
|
||||
bullet. Or browse the [timeline](https://sqlite.org/src/timeline)
|
||||
to locate the check-in desired, click on its information page link,
|
||||
then click on the "Tarball" or "ZIP Archive" links on the information
|
||||
page.
|
||||
* For other check-ins, browse the
|
||||
[project timeline](https://sqlite.org/src/timeline?y=ci) and
|
||||
click on the check-in hash of the check-in you want to download.
|
||||
On the resulting "info" page, click one of the options to the
|
||||
right of the "**Downloads:**" label in the "**Overview**" section
|
||||
near the top.
|
||||
|
||||
To access sources directly using [Fossil](https://fossil-scm.org/home),
|
||||
first install Fossil version 2.0 or later.
|
||||
Source tarballs and precompiled binaries available at
|
||||
Source tarballs and precompiled binaries for Fossil are available at
|
||||
<https://fossil-scm.org/home/uv/download.html>. Fossil is
|
||||
a stand-alone program. To install, simply download or build the single
|
||||
executable file and put that file someplace on your $PATH.
|
||||
executable file and put that file someplace on your $PATH or %PATH%.
|
||||
Then run commands like this:
|
||||
|
||||
mkdir -p ~/sqlite
|
||||
cd ~/sqlite
|
||||
fossil open https://sqlite.org/src
|
||||
|
||||
The "fossil open" command will take two or three minutes. Afterwards,
|
||||
The initial "fossil open" command will take two or three minutes. Afterwards,
|
||||
you can do fast, bandwidth-efficient updates to the whatever versions
|
||||
of SQLite you like. Some examples:
|
||||
|
||||
@@ -152,7 +145,8 @@ show what changes are needed.
|
||||
## Compiling for Windows Using MSVC
|
||||
|
||||
On Windows, everything can be compiled with MSVC.
|
||||
You will also need a working installation of TCL.
|
||||
You will also need a working installation of TCL if you want to run tests.
|
||||
TCL is not required if you just want to build SQLite itself.
|
||||
See the [compile-for-windows.md](doc/compile-for-windows.md) document for
|
||||
additional information about how to install MSVC and TCL and configure your
|
||||
build environment.
|
||||
@@ -164,8 +158,8 @@ TCL library, using a command like this:
|
||||
|
||||
SQLite uses "tclsh.exe" as part of the build process, and so that
|
||||
program will need to be somewhere on your %PATH%. SQLite itself
|
||||
does not contain any TCL code, but it does use TCL to help with the
|
||||
build process and to run tests. You may need to install TCL development
|
||||
does not contain any TCL code, but it does use TCL to run tests.
|
||||
You may need to install TCL development
|
||||
libraries in order to successfully complete some makefile targets.
|
||||
It is helpful, but is not required, to install the SQLite TCL extension
|
||||
(the "tclextension-install" target) prior to running tests.
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
#
|
||||
# JimTCL: https://jim.tcl.tk
|
||||
#
|
||||
# Code-diver notes: APIs names starting with "sqlite-" are specific to
|
||||
# this project and can be found in autosetup/sqlite-config.tcl. Names
|
||||
# starting with "proj-" are project-agnostic and found in
|
||||
# autosetup/proj.tcl.
|
||||
#
|
||||
use sqlite-config
|
||||
sqlite-configure canonical {
|
||||
proj-if-opt-truthy dev {
|
||||
|
||||
+19
-3
@@ -117,6 +117,19 @@ sqlite_cfg.h: $(AS_AUTO_DEF)
|
||||
# CFLAGS for sqlite3$(T.exe)
|
||||
#
|
||||
SHELL_OPT ?= @OPT_SHELL@
|
||||
SHELL_OPT += -DSQLITE_DQS=0
|
||||
SHELL_OPT += -DSQLITE_ENABLE_FTS4
|
||||
#SHELL_OPT += -DSQLITE_ENABLE_FTS5
|
||||
SHELL_OPT += -DSQLITE_ENABLE_RTREE
|
||||
SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
SHELL_OPT += -DSQLITE_ENABLE_STMTVTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
SHELL_OPT += -DSQLITE_ENABLE_PERCENTILE
|
||||
SHELL_OPT += -DSQLITE_STRICT_SUBTYPE=1
|
||||
|
||||
#
|
||||
# Library-level feature flags
|
||||
@@ -222,9 +235,12 @@ install: install-lib
|
||||
# Flags to link the shell app either directly against sqlite3.c
|
||||
# (ENABLE_STATIC_SHELL==1) or libsqlite3.so (ENABLE_STATIC_SHELL==0).
|
||||
#
|
||||
# Maintenance reminder: placement of $(LDFLAGS) is more relevant for
|
||||
# some platforms than others:
|
||||
# https://sqlite.org/forum/forumpost/d80ecdaddd
|
||||
ENABLE_STATIC_SHELL = @ENABLE_STATIC_SHELL@
|
||||
sqlite3-shell-link-flags.1 = $(TOP)/sqlite3.c $(LDFLAGS.libsqlite3)
|
||||
sqlite3-shell-link-flags.0 = -L. -lsqlite3 $(LDFLAGS.zlib) $(LDFLAGS.math)
|
||||
sqlite3-shell-link-flags.1 = $(TOP)/sqlite3.c $(LDFLAGS) $(LDFLAGS.libsqlite3)
|
||||
sqlite3-shell-link-flags.0 = $(LDFLAGS) -L. -lsqlite3 $(LDFLAGS.zlib) $(LDFLAGS.math)
|
||||
sqlite3-shell-deps.1 = $(TOP)/sqlite3.c
|
||||
sqlite3-shell-deps.0 = $(libsqlite3.DLL)
|
||||
#
|
||||
@@ -245,7 +261,7 @@ sqlite3$(T.exe): $(TOP)/shell.c $(sqlite3-shell-deps.$(ENABLE_STATIC_SHELL))
|
||||
$(sqlite3-shell-static.flags.$(STATIC_CLI_SHELL)) \
|
||||
-I. $(OPT_FEATURE_FLAGS) $(SHELL_OPT) \
|
||||
$(CFLAGS) $(CFLAGS.readline) $(CFLAGS.icu) \
|
||||
$(LDFLAGS) $(LDFLAGS.readline)
|
||||
$(LDFLAGS.readline)
|
||||
|
||||
sqlite3$(T.exe)-1:
|
||||
sqlite3$(T.exe)-0: sqlite3$(T.exe)
|
||||
|
||||
@@ -327,6 +327,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_CARRAY=1
|
||||
!ENDIF
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
|
||||
!ENDIF
|
||||
@@ -349,6 +350,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
|
||||
|
||||
# Always enable math functions on Windows
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_MATH_FUNCTIONS
|
||||
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PERCENTILE
|
||||
|
||||
# Should the rbu extension be enabled? If so, add compilation options
|
||||
# to enable it.
|
||||
@@ -693,17 +695,21 @@ BCC = $(BCC) /d2guard4 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
|
||||
!IF $(DEBUG)>1
|
||||
TCC = $(TCC) -MDd
|
||||
BCC = $(BCC) -MDd
|
||||
ZLIBCFLAGS = -nologo -MDd -W3 -O2 -Oy- -Zi
|
||||
!ELSE
|
||||
TCC = $(TCC) -MD
|
||||
BCC = $(BCC) -MD
|
||||
ZLIBCFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi
|
||||
!ENDIF
|
||||
!ELSE
|
||||
!IF $(DEBUG)>1
|
||||
TCC = $(TCC) -MTd
|
||||
BCC = $(BCC) -MTd
|
||||
ZLIBCFLAGS = -nologo -MTd -W3 -O2 -Oy- -Zi
|
||||
!ELSE
|
||||
TCC = $(TCC) -MT
|
||||
BCC = $(BCC) -MT
|
||||
ZLIBCFLAGS = -nologo -MT -W3 -O2 -Oy- -Zi
|
||||
!ENDIF
|
||||
!ENDIF
|
||||
|
||||
@@ -1015,6 +1021,7 @@ SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_DQS=0
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_PERCENTILE=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_STMT_SCANSTATUS=1
|
||||
SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_STRICT_SUBTYPE=1
|
||||
|
||||
@@ -119,7 +119,7 @@ TCLLIBDIR = @TCLLIBDIR@
|
||||
# typically come from the ./configure command-line invocation).
|
||||
#
|
||||
CFLAGS.configure = @SH_CFLAGS@ @TEAISH_CFLAGS@ @CFLAGS@ @CPPFLAGS@ $(TCL_INCLUDE_SPEC)
|
||||
#CFLAGS.configure += -DUSE_TCL_STUBS=1
|
||||
CFLAGS.configure += -DUSE_TCL_STUBS=@TEAISH_USE_STUBS@
|
||||
|
||||
#
|
||||
# LDFLAGS.configure = LDFLAGS as known at configure-time.
|
||||
@@ -153,6 +153,7 @@ tx.src = @TEAISH_EXT_SRC@
|
||||
# gets set up via the configure script.
|
||||
#
|
||||
tx.CFLAGS =
|
||||
tx.CPPFLAGS =
|
||||
|
||||
#
|
||||
# tx.LDFLAGS is typically set by teaish.make, whereas TEAISH_LDFLAGS
|
||||
@@ -218,7 +219,7 @@ config.log: @TEAISH_TEST_TCL_IN@
|
||||
# CC variant for compiling Tcl-using sources.
|
||||
#
|
||||
CC.tcl = \
|
||||
$(CC) -o $@ $(CFLAGS.configure) $(CFLAGS) $(tx.CFLAGS)
|
||||
$(CC) -o $@ $(CFLAGS.configure) $(CFLAGS) $(tx.CFLAGS) $(tx.CPPFLAGS)
|
||||
|
||||
#
|
||||
# CC variant for linking $(tx.src) into an extension DLL. Note that
|
||||
|
||||
Vendored
+15
-2
@@ -1,7 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Look for and run autosetup...
|
||||
dir0="`dirname "$0"`"
|
||||
dirA="$dir0/../autosetup"
|
||||
# This is the case ^^^^^^^^^^^^ in the SQLite "autoconf" bundle.
|
||||
dirA="$dir0"
|
||||
if [ -d $dirA/autosetup ]; then
|
||||
# A local copy of autosetup
|
||||
dirA=$dirA/autosetup
|
||||
elif [ -d $dirA/../autosetup ]; then
|
||||
# SQLite "autoconf" bundle
|
||||
dirA=$dirA/../autosetup
|
||||
elif [ -d $dirA/../../autosetup ]; then
|
||||
# SQLite canonical source tree
|
||||
dirA=$dirA/../../autosetup
|
||||
else
|
||||
echo "$0: Cannot find autosetup" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
WRAPPER="$0"; export WRAPPER; exec "`"$dirA/autosetup-find-tclsh"`" \
|
||||
"$dirA/autosetup" --teaish-extension-dir="$dir0" \
|
||||
"$@"
|
||||
|
||||
+4
-3
@@ -380,8 +380,9 @@ and its own special handling of `--enable-...` flags makes `--debug`
|
||||
an alias for `--enable-debug`. As this project has a long history of
|
||||
using `--enable-debug`, we patch autosetup to use the name
|
||||
`--autosetup-debug` in place of `--debug`. That requires (as of this
|
||||
writing) four small edits in [](/file/autosetup/autosetup), as
|
||||
demonstrated in [check-in 3296c8d3](/info/3296c8d3).
|
||||
writing) four small edits in
|
||||
[/autosetup/autosetup](/file/autosetup/autosetup), as demonstrated in
|
||||
[check-in 3296c8d3](/info/3296c8d3).
|
||||
|
||||
If autosetup is upgraded and this patch is _not_ applied the invoking
|
||||
`./configure` will fail loudly because of the declaration of the
|
||||
@@ -426,7 +427,7 @@ proc sqlite-custom-flags {} {
|
||||
```
|
||||
|
||||
That function must return either an empty string or a list in the form
|
||||
used internally by `sqlite-config.tcl:sqlite-configure`.
|
||||
used internally by [sqlite-config.tcl][]'s `sqlite-configure`.
|
||||
|
||||
Next, define:
|
||||
|
||||
|
||||
+11
-7
@@ -406,8 +406,8 @@ proc options-add {opts} {
|
||||
# Find the corresponding value in the user options
|
||||
# and set the default if necessary
|
||||
if {[string match "-*" $opt]} {
|
||||
# This is a documentation-only option, like "-C <dir>"
|
||||
set opthelp $opt
|
||||
# We no longer support documentation-only options, like "-C <dir>"
|
||||
autosetup-error "Option $opt is not supported"
|
||||
} elseif {$colon eq ""} {
|
||||
# Boolean option
|
||||
lappend autosetup(options) $name
|
||||
@@ -1611,7 +1611,7 @@ proc autosetup_output_block {type lines} {
|
||||
# Generate a command reference from inline documentation
|
||||
proc automf_command_reference {} {
|
||||
lappend files $::autosetup(prog)
|
||||
lappend files {*}[lsort [glob -nocomplain $::autosetup(libdir)/*.tcl]]
|
||||
lappend files {*}[lsort [glob -nocomplain $::autosetup(libdir)/{*/*.tcl,*.tcl}]]
|
||||
|
||||
# We want to process all non-module files before module files
|
||||
# and then modules in alphabetical order.
|
||||
@@ -2124,7 +2124,7 @@ if {$autosetup(istcl)} {
|
||||
set frame [info frame -$i]
|
||||
if {[dict exists $frame file]} {
|
||||
# We don't need proc, so use ""
|
||||
lappend stacktrace "" [dict get $frame file] [dict get $frame line]
|
||||
lappend stacktrace "" [dict get $frame file] [dict get $frame line] ""
|
||||
}
|
||||
}
|
||||
return $stacktrace
|
||||
@@ -2181,8 +2181,12 @@ proc error-location {msg} {
|
||||
if {$::autosetup(debug)} {
|
||||
return -code error $msg
|
||||
}
|
||||
# Search back through the stack trace for the first error in a .def file
|
||||
foreach {p f l} [stacktrace] {
|
||||
set vars {p f l cmd}
|
||||
if {!$::autosetup(istcl) && ![dict exists $::tcl_platform stackFormat]} {
|
||||
# Older versions of Jim had a 3 element stacktrace
|
||||
set vars {p f l}
|
||||
}
|
||||
foreach $vars [stacktrace] {
|
||||
if {[string match *.def $f]} {
|
||||
return "[relative-path $f]:$l: Error: $msg"
|
||||
}
|
||||
@@ -2534,7 +2538,7 @@ if {[catch {main $argv} msg opts] == 1} {
|
||||
show-notices
|
||||
autosetup-full-error [error-dump $msg $opts $autosetup(debug)]
|
||||
if {!$autosetup(debug)} {
|
||||
puts stderr "Try: '[file tail $autosetup(exe)] --autosetup-debug' for a full stack trace"
|
||||
puts stderr "Try: '[file tail $autosetup(exe)] --debug' for a full stack trace"
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -89,13 +89,15 @@ switch -glob -- [get-define host] {
|
||||
define SH_SOPREFIX -Wl,-h,
|
||||
}
|
||||
}
|
||||
*-*-hpux {
|
||||
# XXX: These haven't been tested
|
||||
define SHOBJ_CFLAGS "+O3 +z"
|
||||
*-*-hpux* {
|
||||
define SHOBJ_CFLAGS +z
|
||||
define SHOBJ_LDFLAGS -b
|
||||
define SH_CFLAGS +z
|
||||
define SH_LDFLAGS -b
|
||||
define SH_LINKFLAGS -Wl,+s
|
||||
define LD_LIBRARY_PATH SHLIB_PATH
|
||||
define SH_LINKRPATH "-Wl,+b -Wl,%s"
|
||||
define SH_SOPREFIX -Wl,+h,
|
||||
define STRIPLIBFLAGS -Wl,-s
|
||||
}
|
||||
*-*-haiku {
|
||||
define SHOBJ_CFLAGS ""
|
||||
|
||||
+12
-25
@@ -9132,7 +9132,7 @@ int Jim_StringEqObj(Jim_Obj *aObjPtr, Jim_Obj *bObjPtr)
|
||||
const char *sA = Jim_GetString(aObjPtr, &Alen);
|
||||
const char *sB = Jim_GetString(bObjPtr, &Blen);
|
||||
|
||||
return Alen == Blen && *sA == *sB && memcmp(sA, sB, Alen) == 0;
|
||||
return Alen == Blen && memcmp(sA, sB, Alen) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10242,7 +10242,7 @@ static int JimCommandsHT_KeyCompare(void *privdata, const void *key1, const void
|
||||
int len1, len2;
|
||||
const char *str1 = Jim_GetStringNoQualifier((Jim_Obj *)key1, &len1);
|
||||
const char *str2 = Jim_GetStringNoQualifier((Jim_Obj *)key2, &len2);
|
||||
return len1 == len2 && *str1 == *str2 && memcmp(str1, str2, len1) == 0;
|
||||
return len1 == len2 && memcmp(str1, str2, len1) == 0;
|
||||
}
|
||||
|
||||
static void JimCommandsHT_ValDestructor(void *interp, void *val)
|
||||
@@ -13864,13 +13864,6 @@ static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
|
||||
case JIM_EXPROP_NOT:
|
||||
wC = !bA;
|
||||
break;
|
||||
case JIM_EXPROP_UNARYPLUS:
|
||||
case JIM_EXPROP_UNARYMINUS:
|
||||
rc = JIM_ERR;
|
||||
Jim_SetResultFormatted(interp,
|
||||
"can't use non-numeric string as operand of \"%s\"",
|
||||
node->type == JIM_EXPROP_UNARYPLUS ? "+" : "-");
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
@@ -19875,22 +19868,16 @@ wrongargs:
|
||||
}
|
||||
else if (errorCodeObj) {
|
||||
int len = Jim_ListLength(interp, argv[idx + 1]);
|
||||
int i;
|
||||
|
||||
if (len > Jim_ListLength(interp, errorCodeObj)) {
|
||||
ret = JIM_OK;
|
||||
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
ret = JIM_OK;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
|
||||
Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
|
||||
if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
|
||||
Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
|
||||
if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20266,7 +20253,7 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
|
||||
}
|
||||
|
||||
case OPT_SET:
|
||||
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG | JIM_UNSHARED);
|
||||
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
|
||||
|
||||
case OPT_EXISTS:{
|
||||
int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_NONE);
|
||||
@@ -20278,7 +20265,7 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
|
||||
}
|
||||
|
||||
case OPT_UNSET:
|
||||
if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_UNSHARED) != JIM_OK) {
|
||||
if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) {
|
||||
return JIM_ERR;
|
||||
}
|
||||
return JIM_OK;
|
||||
|
||||
+65
-16
@@ -378,8 +378,8 @@ proc proj-bin-define {binName {defName {}}} {
|
||||
#
|
||||
# Despite using cc-path-progs to do the search, this function clears
|
||||
# any define'd name that function stores for the result (because the
|
||||
# caller has no sensible way of knowing which result it was unless
|
||||
# they pass only a single argument).
|
||||
# caller has no sensible way of knowing which [define] name it has
|
||||
# unless they pass only a single argument).
|
||||
#
|
||||
proc proj-first-bin-of {args} {
|
||||
set rc ""
|
||||
@@ -451,7 +451,9 @@ proc proj-opt-set {flag {val 1}} {
|
||||
# @proj-opt-exists flag
|
||||
#
|
||||
# Returns 1 if the given flag has been defined as a legal configure
|
||||
# option, else returns 0.
|
||||
# option, else returns 0. Options set via proj-opt-set "exist" for
|
||||
# this purpose even if they were not defined via autosetup's
|
||||
# [options] function.
|
||||
#
|
||||
proc proj-opt-exists {flag} {
|
||||
expr {$flag in $::autosetup(options)};
|
||||
@@ -555,7 +557,7 @@ proc proj-opt-define-bool {args} {
|
||||
if {$invert} {
|
||||
set rc [expr {!$rc}]
|
||||
}
|
||||
msg-result $rc
|
||||
msg-result [string map {0 no 1 yes} $rc]
|
||||
define $defName $rc
|
||||
return $rc
|
||||
}
|
||||
@@ -704,11 +706,20 @@ proc proj-file-write {args} {
|
||||
}
|
||||
|
||||
#
|
||||
# @proj-check-compile-commands ?configFlag?
|
||||
# @proj-check-compile-commands ?-assume-for-clang? ?configFlag?
|
||||
#
|
||||
# Checks the compiler for compile_commands.json support. If passed an
|
||||
# argument it is assumed to be the name of an autosetup boolean config
|
||||
# which controls whether to run/skip this check.
|
||||
# Checks the compiler for compile_commands.json support. If
|
||||
# $configFlag is not empty then it is assumed to be the name of an
|
||||
# autosetup boolean config which controls whether to run/skip this
|
||||
# check.
|
||||
#
|
||||
# If -assume-for-clang is provided and $configFlag is not empty and CC
|
||||
# matches *clang* and no --$configFlag was explicitly provided to the
|
||||
# configure script then behave as if --$configFlag had been provided.
|
||||
# To disable that assumption, either don't pass -assume-for-clang or
|
||||
# pass --$configFlag=0 to the configure script. (The reason for this
|
||||
# behavior is that clang supports compile-commands but some other
|
||||
# compilers report false positives with these tests.)
|
||||
#
|
||||
# Returns 1 if supported, else 0, and defines HAVE_COMPILE_COMMANDS to
|
||||
# that value. Defines MAKE_COMPILATION_DB to "yes" if supported, "no"
|
||||
@@ -716,12 +727,38 @@ proc proj-file-write {args} {
|
||||
# HAVE_COMPILE_COMMANDS is preferred.
|
||||
#
|
||||
# ACHTUNG: this test has a long history of false positive results
|
||||
# because of compilers reacting differently to the -MJ flag.
|
||||
# because of compilers reacting differently to the -MJ flag. Because
|
||||
# of this, it is recommended that this support be an opt-in feature,
|
||||
# rather than an on-by-default default one. That is: in the
|
||||
# configure script define the option as
|
||||
# {--the-flag-name=0 => {Enable ....}}
|
||||
#
|
||||
proc proj-check-compile-commands {{configFlag {}}} {
|
||||
proc proj-check-compile-commands {args} {
|
||||
set i 0
|
||||
set configFlag {}
|
||||
set fAssumeForClang 0
|
||||
set doAssume 0
|
||||
msg-checking "compile_commands.json support... "
|
||||
if {"" ne $configFlag && ![proj-opt-truthy $configFlag]} {
|
||||
msg-result "explicitly disabled"
|
||||
if {"-assume-for-clang" eq [lindex $args 0]} {
|
||||
lassign $args - configFlag
|
||||
incr fAssumeForClang
|
||||
} elseif {1 == [llength $args]} {
|
||||
lassign $args configFlag
|
||||
} else {
|
||||
proj-error "Invalid arguments"
|
||||
}
|
||||
if {1 == $fAssumeForClang && "" ne $configFlag} {
|
||||
if {[string match *clang* [get-define CC]]
|
||||
&& ![proj-opt-was-provided $configFlag]
|
||||
&& ![proj-opt-truthy $configFlag]} {
|
||||
proj-indented-notice [subst -nocommands -nobackslashes {
|
||||
CC appears to be clang, so assuming that --$configFlag is likely
|
||||
to work. To disable this assumption use --$configFlag=0.}]
|
||||
incr doAssume
|
||||
}
|
||||
}
|
||||
if {!$doAssume && "" ne $configFlag && ![proj-opt-truthy $configFlag]} {
|
||||
msg-result "check disabled. Use --${configFlag} to enable it."
|
||||
define HAVE_COMPILE_COMMANDS 0
|
||||
define MAKE_COMPILATION_DB no
|
||||
return 0
|
||||
@@ -730,7 +767,7 @@ proc proj-check-compile-commands {{configFlag {}}} {
|
||||
# This test reportedly incorrectly succeeds on one of
|
||||
# Martin G.'s older systems. drh also reports a false
|
||||
# positive on an unspecified older Mac system.
|
||||
msg-result "compiler supports compile_commands.json"
|
||||
msg-result "compiler supports -MJ. Assuming it's useful for compile_commands.json"
|
||||
define MAKE_COMPILATION_DB yes; # deprecated
|
||||
define HAVE_COMPILE_COMMANDS 1
|
||||
return 1
|
||||
@@ -1133,6 +1170,10 @@ proc proj-check-rpath {} {
|
||||
if {"" eq $wl} {
|
||||
set wl [proj-cc-check-Wl-flag -R$lp]
|
||||
}
|
||||
if {"" eq $wl} {
|
||||
# HP-UX: https://sqlite.org/forum/forumpost/d80ecdaddd
|
||||
set wl [proj-cc-check-Wl-flag +b $lp]
|
||||
}
|
||||
define LDFLAGS_RPATH $wl
|
||||
}
|
||||
}
|
||||
@@ -1142,7 +1183,7 @@ proc proj-check-rpath {} {
|
||||
#
|
||||
# @proj-check-soname ?libname?
|
||||
#
|
||||
# Checks whether CC supports the -Wl,soname,lib... flag. If so, it
|
||||
# Checks whether CC supports the -Wl,-soname,lib... flag. If so, it
|
||||
# returns 1 and defines LDFLAGS_SONAME_PREFIX to the flag's prefix, to
|
||||
# which the client would need to append "libwhatever.N". If not, it
|
||||
# returns 0 and defines LDFLAGS_SONAME_PREFIX to an empty string.
|
||||
@@ -1158,6 +1199,10 @@ proc proj-check-soname {{libname "libfoo.so.0"}} {
|
||||
if {[cc-check-flags "-Wl,-soname,${libname}"]} {
|
||||
define LDFLAGS_SONAME_PREFIX "-Wl,-soname,"
|
||||
return 1
|
||||
} elseif {[cc-check-flags "-Wl,+h,${libname}"]} {
|
||||
# HP-UX: https://sqlite.org/forum/forumpost/d80ecdaddd
|
||||
define LDFLAGS_SONAME_PREFIX "-Wl,+h,"
|
||||
return 1
|
||||
} else {
|
||||
define LDFLAGS_SONAME_PREFIX ""
|
||||
return 0
|
||||
@@ -1604,7 +1649,7 @@ proc proj-tclConfig-sh-to-autosetup {tclConfigSh} {
|
||||
#
|
||||
# Similar modifications may be made for --mandir.
|
||||
#
|
||||
# Returns 1 if it modifies the environment, else 0.
|
||||
# Returns >0 if it modifies the environment, else 0.
|
||||
#
|
||||
proc proj-tweak-default-env-dirs {} {
|
||||
set rc 0
|
||||
@@ -1643,7 +1688,11 @@ proc proj-tweak-default-env-dirs {} {
|
||||
# processing the file. In the context of that script, the vars
|
||||
# $dotInsIn and $dotInsOut will be set to the input and output file
|
||||
# names. This can be used, for example, to make the output file
|
||||
# executable or perform validation on its contents.
|
||||
# executable or perform validation on its contents:
|
||||
#
|
||||
## proj-dot-ins-append my.sh.in my.sh {
|
||||
## catch {exec chmod u+x $dotInsOut}
|
||||
## }
|
||||
#
|
||||
# See [proj-dot-ins-process], [proj-dot-ins-list]
|
||||
#
|
||||
|
||||
+96
-54
@@ -1,7 +1,7 @@
|
||||
# This file holds functions for autosetup which are specific to the
|
||||
# sqlite build tree. They are in this file, instead of auto.def, so
|
||||
# that they can be reused in the autoconf sub-tree. This file requires
|
||||
# functions from proj.tcl.
|
||||
# functions from the project-agnostic proj.tcl.
|
||||
|
||||
if {[string first " " $autosetup(srcdir)] != -1} {
|
||||
user-error "The pathname of the source tree\
|
||||
@@ -11,7 +11,7 @@ if {[string first " " $autosetup(builddir)] != -1} {
|
||||
user-error "The pathname of the build directory\
|
||||
may not contain space characters"
|
||||
}
|
||||
#parray ::autosetup; exit 0
|
||||
|
||||
use proj
|
||||
#
|
||||
# We want the package version info to be emitted early on, but doing
|
||||
@@ -65,11 +65,12 @@ array set sqliteConfig [subst [proj-strip-hash-comments {
|
||||
# The list of feature --flags which the --all flag implies. This
|
||||
# requires special handling in a few places.
|
||||
#
|
||||
all-flag-enables {fts4 fts5 rtree geopoly session}
|
||||
all-flag-enables {fts4 fts5 rtree geopoly session dbpage dbstat carray}
|
||||
|
||||
#
|
||||
# Default value for the --all flag. Can hypothetically be modified
|
||||
# by non-canonical builds.
|
||||
# by non-canonical builds (it was added for a Tcl extension build
|
||||
# mode which was eventually removed).
|
||||
#
|
||||
all-flag-default 0
|
||||
}]]
|
||||
@@ -92,7 +93,7 @@ array set sqliteConfig [subst [proj-strip-hash-comments {
|
||||
# sqlite-configure BUILD_NAME { build-specific configure script }
|
||||
#
|
||||
# There are snippets of build-mode-specific decision-making in
|
||||
# [sqlite-configure-finalize]
|
||||
# [sqlite-configure-finalize], which gets run after $configScript.
|
||||
proc sqlite-configure {buildMode configScript} {
|
||||
proj-assert {$::sqliteConfig(build-mode) eq "unknown"} \
|
||||
"sqlite-configure must not be called more than once"
|
||||
@@ -112,8 +113,10 @@ proc sqlite-configure {buildMode configScript} {
|
||||
#
|
||||
# Reference: https://msteveb.github.io/autosetup/developer/
|
||||
#
|
||||
# All configure flags must be described in an 'options' call. The
|
||||
# general syntax is:
|
||||
# All configure flags must be described in one or more calls to
|
||||
# autosetup's [options] and [options-add] functions. The general
|
||||
# syntax of the single argument to those functions is a list contain
|
||||
# a mapping of flags to help text:
|
||||
#
|
||||
# FLAG => {Help text}
|
||||
#
|
||||
@@ -164,13 +167,18 @@ proc sqlite-configure {buildMode configScript} {
|
||||
########################################################################
|
||||
set allFlags {
|
||||
# Structure: a list of M {Z} pairs, where M is a descriptive
|
||||
# option group name and Z is a list of X Y pairs. X is a list of
|
||||
# option group name and Z is a list of X Y pairs. X is a list of
|
||||
# $buildMode name(s) to which the Y flags apply, or {*} to apply
|
||||
# to all builds. Y is a {block} in the form expected by
|
||||
# autosetup's [options] command. Each block which is applicable
|
||||
# to $buildMode is appended to a new list before that list is
|
||||
# passed on to [options]. The order of each Y and sub-Y is
|
||||
# retained, which is significant for rendering of --help.
|
||||
# autosetup's [options] and [options-add] command. Each block
|
||||
# which is applicable to $buildMode is passed on to
|
||||
# [options-add]. The order of each Y and sub-Y is retained, which
|
||||
# is significant for rendering of --help.
|
||||
#
|
||||
# Maintenance note: [options] does not support comments in
|
||||
# options, but we filter this object through
|
||||
# [proj-strip-hash-comments] to remove them before passing them on
|
||||
# to [options].
|
||||
|
||||
# When writing {help text blocks}, be aware that:
|
||||
#
|
||||
@@ -180,7 +188,7 @@ proc sqlite-configure {buildMode configScript} {
|
||||
# pretty-printed.
|
||||
#
|
||||
# B) Vars and commands are NOT expanded, but we use a [subst] call
|
||||
# below which will replace (only) var refs.
|
||||
# below which will replace (only) $var refs.
|
||||
|
||||
# Options for how to build the library
|
||||
build-modes {
|
||||
@@ -212,6 +220,9 @@ proc sqlite-configure {buildMode configScript} {
|
||||
geopoly => {Enable the GEOPOLY extension}
|
||||
rtree => {Enable the RTREE extension}
|
||||
session => {Enable the SESSION extension}
|
||||
dbpage => {Enable the sqlite3_dbpage extension}
|
||||
dbstat => {Enable the sqlite3_dbstat extension}
|
||||
carray=1 => {Disable the CARRAY extension}
|
||||
all=$::sqliteConfig(all-flag-default) => {$allFlagHelp}
|
||||
largefile=1
|
||||
=> {This legacy flag has no effect on the library but may influence
|
||||
@@ -321,7 +332,7 @@ proc sqlite-configure {buildMode configScript} {
|
||||
Needed only by ext/wasm. Default=EMSDK env var.}
|
||||
|
||||
amalgamation-extra-src:FILES
|
||||
=> {Space-separated list of soure files to append as-is to the resulting
|
||||
=> {Space-separated list of source files to append as-is to the resulting
|
||||
sqlite3.c amalgamation file. May be provided multiple times.}
|
||||
}
|
||||
}
|
||||
@@ -337,7 +348,6 @@ proc sqlite-configure {buildMode configScript} {
|
||||
}
|
||||
{canonical autoconf} {
|
||||
rpath=1 => {Disable use of the rpath linker flag}
|
||||
|
||||
# soname: https://sqlite.org/src/forumpost/5a3b44f510df8ded
|
||||
soname:=legacy
|
||||
=> {SONAME for libsqlite3.so. "none", or not using this flag, sets no
|
||||
@@ -408,7 +418,6 @@ proc sqlite-configure {buildMode configScript} {
|
||||
# ^^^ lappend of [sqlite-custom-flags] introduces weirdness if
|
||||
# we delay [proj-strip-hash-comments] until after that.
|
||||
|
||||
|
||||
########################################################################
|
||||
# sqlite-custom.tcl is intended only for vendor-branch-specific
|
||||
# customization. See autosetup/README.md#branch-customization for
|
||||
@@ -426,6 +435,8 @@ proc sqlite-configure {buildMode configScript} {
|
||||
}
|
||||
}
|
||||
|
||||
#lappend allFlags just-testing {{*} {soname:=duplicateEntry => {x}}}
|
||||
|
||||
# Filter allFlags to create the set of [options] legal for this build
|
||||
foreach {group XY} [subst -nobackslashes -nocommands $allFlags] {
|
||||
foreach {X Y} $XY {
|
||||
@@ -434,7 +445,7 @@ proc sqlite-configure {buildMode configScript} {
|
||||
}
|
||||
}
|
||||
}
|
||||
#lappend opts "soname:=duplicateEntry => {x}"; #just testing
|
||||
|
||||
if {[catch {options {}} msg xopts]} {
|
||||
# Workaround for <https://github.com/msteveb/autosetup/issues/73>
|
||||
# where [options] behaves oddly on _some_ TCL builds when it's
|
||||
@@ -449,8 +460,9 @@ proc sqlite-configure {buildMode configScript} {
|
||||
|
||||
########################################################################
|
||||
# Runs "phase 1" of the configure process: after initial --flags
|
||||
# handling but before the build-specific parts are run. $buildMode
|
||||
# must be the mode which was passed to [sqlite-configure].
|
||||
# handling but before sqlite-configure's $configScript argument is
|
||||
# run. $buildMode must be the mode which was passed to
|
||||
# [sqlite-configure].
|
||||
proc sqlite-configure-phase1 {buildMode} {
|
||||
define PACKAGE_NAME sqlite
|
||||
define PACKAGE_URL {https://sqlite.org}
|
||||
@@ -492,6 +504,7 @@ proc sqlite-configure-phase1 {buildMode} {
|
||||
if {[file exists $srcdir/sqlite3.pc.in]} {
|
||||
proj-dot-ins-append $srcdir/sqlite3.pc.in
|
||||
}
|
||||
sqlite-handle-hpux; # must be relatively early so that other config tests can work
|
||||
}; # sqlite-configure-phase1
|
||||
|
||||
########################################################################
|
||||
@@ -618,7 +631,7 @@ proc sqlite-check-common-system-deps {} {
|
||||
|
||||
# Check for needed/wanted functions
|
||||
cc-check-functions gmtime_r isnan localtime_r localtime_s \
|
||||
strchrnul usleep utime pread pread64 pwrite pwrite64
|
||||
usleep utime pread pread64 pwrite pwrite64
|
||||
|
||||
apply {{} {
|
||||
set ldrt ""
|
||||
@@ -776,6 +789,9 @@ proc sqlite-handle-common-feature-flags {} {
|
||||
}
|
||||
scanstatus -DSQLITE_ENABLE_STMT_SCANSTATUS {}
|
||||
column-metadata -DSQLITE_ENABLE_COLUMN_METADATA {}
|
||||
dbpage -DSQLITE_ENABLE_DBPAGE_VTAB {}
|
||||
dbstat -DSQLITE_ENABLE_DBSTAT_VTAB {}
|
||||
carray -DSQLITE_ENABLE_CARRAY {}
|
||||
}] {
|
||||
if {$boolFlag ni $::autosetup(options)} {
|
||||
# Skip flags which are in the canonical build but not
|
||||
@@ -1017,7 +1033,7 @@ proc sqlite-handle-emsdk {} {
|
||||
proc sqlite-get-readline-dir-list {} {
|
||||
# Historical note: the dirs list, except for the inclusion of
|
||||
# $prefix and some platform-specific dirs, originates from the
|
||||
# legacy configure script
|
||||
# legacy configure script.
|
||||
set dirs [list [get-define prefix]]
|
||||
switch -glob -- [get-define host] {
|
||||
*-linux-android {
|
||||
@@ -1035,7 +1051,7 @@ proc sqlite-get-readline-dir-list {} {
|
||||
if {[opt-val with-readline-ldflags] in {auto ""}} {
|
||||
# If the user did not supply their own --with-readline-ldflags
|
||||
# value, hijack that flag to inject options which are known to
|
||||
# work on a default Haiku installation.
|
||||
# work on Haiku OS installations.
|
||||
if {"" ne [glob -nocomplain /boot/system/lib/libreadline*]} {
|
||||
proj-opt-set with-readline-ldflags {-L/boot/system/lib -lreadline}
|
||||
}
|
||||
@@ -1085,8 +1101,8 @@ proc sqlite-get-readline-dir-list {} {
|
||||
# 4) Default to automatic search for optional readline
|
||||
#
|
||||
# 5) Try to find readline or editline. If it's not found AND the
|
||||
# corresponding --FEATURE flag was explicitly given, fail fatally,
|
||||
# else fail silently.
|
||||
# corresponding --FEATURE flag was explicitly given then fail
|
||||
# fatally, else fail non-fatally.
|
||||
proc sqlite-check-line-editing {} {
|
||||
msg-result "Checking for line-editing capability..."
|
||||
define HAVE_READLINE 0
|
||||
@@ -1099,7 +1115,7 @@ proc sqlite-check-line-editing {} {
|
||||
# if the library is not found.
|
||||
set libsForReadline {readline edit} ; # -l<LIB> names to check for readline().
|
||||
# The libedit check changes this.
|
||||
set editLibName "readline" ; # "readline" or "editline"
|
||||
set editLibName "readline" ; # "readline" or "editline"
|
||||
set editLibDef "HAVE_READLINE" ; # "HAVE_READLINE" or "HAVE_EDITLINE"
|
||||
set dirLn [opt-val with-linenoise]
|
||||
if {"" ne $dirLn} {
|
||||
@@ -1116,7 +1132,7 @@ proc sqlite-check-line-editing {} {
|
||||
foreach f $lnCOpts {
|
||||
if {[file exists $dirLn/$f]} {
|
||||
set lnC $dirLn/$f
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
if {"" eq $lnC} {
|
||||
@@ -1226,16 +1242,18 @@ proc sqlite-check-line-editing {} {
|
||||
set rlLib [opt-val with-readline-ldflags]
|
||||
#proc-debug "rlLib=$rlLib"
|
||||
if {$rlLib in {auto ""}} {
|
||||
set rlLib ""
|
||||
set libTerm ""
|
||||
if {[proj-check-function-in-lib tgetent "$editLibName ncurses curses termcap"]} {
|
||||
set rlLib "" ; # make sure it's not "auto", as we may append to it below
|
||||
set libTerm ""; # lib with tgetent(3)
|
||||
if {[proj-check-function-in-lib tgetent [list $editLibName ncurses curses termcap]]} {
|
||||
# ^^^ that libs list comes from the legacy configure script ^^^
|
||||
set libTerm [get-define lib_tgetent]
|
||||
undefine lib_tgetent
|
||||
}
|
||||
if {$editLibName eq $libTerm} {
|
||||
# tgetent(3) was found in the editing library
|
||||
set rlLib $libTerm
|
||||
} elseif {[proj-check-function-in-lib readline $libsForReadline $libTerm]} {
|
||||
# tgetent(3) was found in an external lib
|
||||
set rlLib [get-define lib_readline]
|
||||
lappend rlLib $libTerm
|
||||
undefine lib_readline
|
||||
@@ -1265,8 +1283,8 @@ proc sqlite-check-line-editing {} {
|
||||
msg-result "Using $editLibName flags: $rlInc $rlLib"
|
||||
# Check whether rl_completion_matches() has a signature we can use
|
||||
# and disable that sub-feature if it doesn't.
|
||||
if {![cctest \
|
||||
-cflags "$rlInc -D${editLibDef}" -libs $rlLib -nooutput 1 -source {
|
||||
if {![cctest -cflags "$rlInc -D${editLibDef}" -libs $rlLib -nooutput 1 \
|
||||
-source {
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_EDITLINE
|
||||
#include <editline/readline.h>
|
||||
@@ -1319,7 +1337,7 @@ proc sqlite-handle-line-editing {} {
|
||||
# - pkg-config: use only pkg-config to determine flags
|
||||
# - /path/to/icu-config: use that to determine flags
|
||||
#
|
||||
# If --with-icu-config is used as neither pkg-config nor icu-config
|
||||
# If --with-icu-config is used and neither pkg-config nor icu-config
|
||||
# are found, fail fatally.
|
||||
#
|
||||
# If both --with-icu-ldflags and --with-icu-config are provided, they
|
||||
@@ -1412,39 +1430,50 @@ proc sqlite-handle-icu {} {
|
||||
# Makes the following environment changes:
|
||||
#
|
||||
# - defines LDFLAGS_DLOPEN to any linker flags needed for this
|
||||
# feature. It may legally be empty on some systems where dlopen()
|
||||
# is in libc.
|
||||
# feature. It may legally be empty on (A) some systems where
|
||||
# dlopen() is in libc and (B) certain Unix-esque Windows
|
||||
# environments which identify as Windows for SQLite's purposes so
|
||||
# use LoadLibrary().
|
||||
#
|
||||
# - If the feature is not available, adds
|
||||
# -DSQLITE_OMIT_LOAD_EXTENSION=1 to the feature flags list.
|
||||
proc sqlite-handle-load-extension {} {
|
||||
define LDFLAGS_DLOPEN ""
|
||||
set found 0
|
||||
set suffix ""
|
||||
proj-if-opt-truthy load-extension {
|
||||
set found [proj-check-function-in-lib dlopen dl]
|
||||
if {$found} {
|
||||
define LDFLAGS_DLOPEN [get-define lib_dlopen]
|
||||
undefine lib_dlopen
|
||||
} else {
|
||||
if {[proj-opt-was-provided load-extension]} {
|
||||
# Explicit --enable-load-extension: fail if not found
|
||||
proj-indented-notice -error {
|
||||
--enable-load-extension was provided but dlopen()
|
||||
not found. Use --disable-load-extension to bypass this
|
||||
check.
|
||||
}
|
||||
} else {
|
||||
# It was implicitly enabled: warn if not found
|
||||
proj-indented-notice {
|
||||
WARNING: dlopen() not found, so loadable module support will
|
||||
be disabled. Use --disable-load-extension to bypass this
|
||||
check.
|
||||
switch -glob -- [get-define host] {
|
||||
*-*-mingw* - *windows* {
|
||||
incr found
|
||||
set suffix "Using LoadLibrary()"
|
||||
}
|
||||
default {
|
||||
set found [proj-check-function-in-lib dlopen dl]
|
||||
if {$found} {
|
||||
set suffix [define LDFLAGS_DLOPEN [get-define lib_dlopen]]
|
||||
undefine lib_dlopen
|
||||
} else {
|
||||
if {[proj-opt-was-provided load-extension]} {
|
||||
# Explicit --enable-load-extension: fail if not found
|
||||
proj-indented-notice -error {
|
||||
--enable-load-extension was provided but dlopen()
|
||||
not found. Use --disable-load-extension to bypass this
|
||||
check.
|
||||
}
|
||||
} else {
|
||||
# It was implicitly enabled: warn if not found
|
||||
proj-indented-notice {
|
||||
WARNING: dlopen() not found, so loadable module support will
|
||||
be disabled. Use --disable-load-extension to bypass this
|
||||
check.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if {$found} {
|
||||
msg-result "Loadable extension support enabled."
|
||||
msg-result "Loadable extension support enabled. $suffix"
|
||||
} else {
|
||||
msg-result "Disabling loadable extension support. Use --enable-load-extension to enable them."
|
||||
sqlite-add-feature-flag -DSQLITE_OMIT_LOAD_EXTENSION=1
|
||||
@@ -1461,7 +1490,7 @@ proc sqlite-handle-math {} {
|
||||
}
|
||||
define LDFLAGS_MATH [get-define lib_ceil]
|
||||
undefine lib_ceil
|
||||
sqlite-add-feature-flag -DSQLITE_ENABLE_MATH_FUNCTIONS
|
||||
sqlite-add-feature-flag -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_PERCENTILE
|
||||
msg-result "Enabling math SQL functions"
|
||||
} {
|
||||
define LDFLAGS_MATH ""
|
||||
@@ -1523,6 +1552,19 @@ proc sqlite-handle-mac-install-name {} {
|
||||
return $rc
|
||||
}
|
||||
|
||||
#
|
||||
# Checks specific to HP-UX.
|
||||
#
|
||||
proc sqlite-handle-hpux {} {
|
||||
switch -glob -- [get-define host] {
|
||||
*hpux* {
|
||||
if {[cc-check-flags "-Ae"]} {
|
||||
define-append CFLAGS -Ae
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# Handles the --dll-basename configure flag. [define]'s
|
||||
# SQLITE_DLL_BASENAME to the DLL's preferred base name (minus
|
||||
|
||||
@@ -220,7 +220,9 @@ proc teaish-configure-core {} {
|
||||
=> {Full pathname of tclsh to use. It is used for trying to find
|
||||
tclConfig.sh. Warning: if its containing dir has multiple tclsh
|
||||
versions, it may select the wrong tclConfig.sh!
|
||||
Defaults to the $TCLSH environment variable.}
|
||||
Defaults to the $TCLSH environment variable.}
|
||||
|
||||
tcl-stubs=0 => {Enable use of Tcl stubs library.}
|
||||
|
||||
# TEA has --with-tclinclude but it appears to only be useful for
|
||||
# building an extension against an uninstalled copy of TCL's own
|
||||
@@ -498,6 +500,8 @@ proc teaish__configure_phase1 {} {
|
||||
}
|
||||
teaish-checks-run -post
|
||||
|
||||
define TEAISH_USE_STUBS [opt-bool tcl-stubs]
|
||||
|
||||
apply {{} {
|
||||
# Set up "vsatisfies" code for pkgIndex.tcl.in,
|
||||
# _teaish.tester.tcl.in, and for a configure-time check. We would
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Notes On Compiling SQLite On Windows 11
|
||||
|
||||
Below are step-by-step instructions on how to build SQLite from
|
||||
canonical source on a new Windows 11 PC, as of 2024-10-09.
|
||||
canonical source on a new Windows 11 PC, as of 2025-10-31.
|
||||
See [](./compile-for-unix.md) for a similar guide for unix-like
|
||||
systems, including MacOS.
|
||||
|
||||
@@ -24,7 +24,8 @@ systems, including MacOS.
|
||||
application to your task bar, as you will use it a lot. Bring up
|
||||
an instance of this command prompt and do all of the subsequent steps
|
||||
in that "x64 Native Tools" command prompt. (Or use "x86" if you want
|
||||
a 32-bit build.) The subsequent steps will not work in a vanilla
|
||||
a 32-bit build. Or use "ARM64" if you want to do a build for Windows
|
||||
on ARM.) The subsequent steps will not work in a vanilla
|
||||
DOS prompt. Nor will they work in PowerShell.
|
||||
|
||||
3. *(Optional):* Install TCL development libraries.
|
||||
@@ -133,9 +134,7 @@ following minor changes:
|
||||
The command the developers use for building the deliverable DLL on the
|
||||
[download page](https://sqlite.org/download.html) is as follows:
|
||||
|
||||
> ~~~~
|
||||
nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1"
|
||||
~~~~
|
||||
> nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1"
|
||||
|
||||
That command generates both the sqlite3.dll and sqlite3.def files. The same
|
||||
command works for both 32-bit and 64-bit builds.
|
||||
@@ -147,9 +146,7 @@ with TCL in order to function. The [sqlite3_analyzer.exe program](https://sqlit
|
||||
is an example. You can build as described above, and then
|
||||
enter:
|
||||
|
||||
> ~~~~
|
||||
nmake /f Makefile.msc sqlite3_analyzer.exe
|
||||
~~~~
|
||||
> nmake /f Makefile.msc sqlite3_analyzer.exe
|
||||
|
||||
And you will end up with a working executable. However, that executable
|
||||
will depend on having the "tcl98.dll" library somewhere on your %PATH%.
|
||||
@@ -175,17 +172,11 @@ statically linked so that it does not depend on separate DLL:
|
||||
5. CD into your SQLite source code directory and build the desired
|
||||
utility program, but add the following extra argument to the
|
||||
nmake command line:
|
||||
<blockquote><pre>
|
||||
STATICALLY_LINK_TCL=1
|
||||
</pre></blockquote>
|
||||
<blockquote><pre>STATICALLY_LINK_TCL=1</pre></blockquote>
|
||||
<p>So, for example, to build a statically linked version of
|
||||
sqlite3_analyzer.exe, you might type:
|
||||
<blockquote><pre>
|
||||
nmake /f Makefile.msc STATICALLY_LINK_TCL=1 sqlite3_analyzer.exe
|
||||
</pre></blockquote>
|
||||
<blockquote><pre>nmake /f Makefile.msc STATICALLY_LINK_TCL=1 sqlite3_analyzer.exe</pre></blockquote>
|
||||
|
||||
6. After your executable is built, you can verify that it does not
|
||||
depend on the TCL DLL by running:
|
||||
<blockquote><pre>
|
||||
dumpbin /dependents sqlite3_analyzer.exe
|
||||
</pre></blockquote>
|
||||
<blockquote><pre>dumpbin /dependents sqlite3_analyzer.exe</pre></blockquote>
|
||||
|
||||
+8
-9
@@ -149,11 +149,10 @@ RFC 8259 format, without extensions. The payload is the ASCII
|
||||
text representation of that numeric value.
|
||||
|
||||
<li value="4"><p><b>INT5</b> →
|
||||
The element is a JSON integer value that is not in the
|
||||
canonical format. The payload is the ASCII
|
||||
text representation of that numeric value. Because the payload is in a
|
||||
non-standard format, it will need to be translated when the JSONB is
|
||||
converted into RFC 8259 text JSON.
|
||||
The element is a JSON integer literal in hexadecimal notation.
|
||||
The payload is the ASCII text representation of the literal.
|
||||
Because the payload is in a non-standard format, it will need
|
||||
to be translated when the JSONB is converted into RFC 8259 text JSON.
|
||||
|
||||
<li value="5"><p><b>FLOAT</b> →
|
||||
The element is a JSON floating-point value in the canonical
|
||||
@@ -162,10 +161,10 @@ text representation of that numeric value.
|
||||
|
||||
<li value="6"><p><b>FLOAT5</b> →
|
||||
The element is a JSON floating-point value that is not in the
|
||||
canonical format. The payload is the ASCII
|
||||
text representation of that numeric value. Because the payload is in a
|
||||
non-standard format, it will need to be translated when the JSONB is
|
||||
converted into RFC 8259 text JSON.
|
||||
canonical JSON format but rather the extended JSON5 format.
|
||||
The payload is the ASCII text representation of that numeric value.
|
||||
Because the payload is in a non-standard format, it will need to
|
||||
be translated when the JSONB is converted into RFC 8259 text JSON.
|
||||
|
||||
<li value="7"><p><b>TEXT</b> →
|
||||
The element is a JSON string value that does not contain
|
||||
|
||||
+27
-25
@@ -172,11 +172,11 @@ struct sqlite3expert {
|
||||
** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
|
||||
** If the allocation fails, set *pRc to SQLITE_NOMEM and return NULL.
|
||||
*/
|
||||
static void *idxMalloc(int *pRc, int nByte){
|
||||
static void *idxMalloc(int *pRc, i64 nByte){
|
||||
void *pRet;
|
||||
assert( *pRc==SQLITE_OK );
|
||||
assert( nByte>0 );
|
||||
pRet = sqlite3_malloc(nByte);
|
||||
pRet = sqlite3_malloc64(nByte);
|
||||
if( pRet ){
|
||||
memset(pRet, 0, nByte);
|
||||
}else{
|
||||
@@ -243,7 +243,7 @@ static int idxHashAdd(
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + nKey+1 + nVal+1);
|
||||
pEntry = idxMalloc(pRc, sizeof(IdxHashEntry) + (i64)nKey+1 + (i64)nVal+1);
|
||||
if( pEntry ){
|
||||
pEntry->zKey = (char*)&pEntry[1];
|
||||
memcpy(pEntry->zKey, zKey, nKey);
|
||||
@@ -378,15 +378,15 @@ struct ExpertCsr {
|
||||
};
|
||||
|
||||
static char *expertDequote(const char *zIn){
|
||||
int n = STRLEN(zIn);
|
||||
char *zRet = sqlite3_malloc(n);
|
||||
i64 n = STRLEN(zIn);
|
||||
char *zRet = sqlite3_malloc64(n);
|
||||
|
||||
assert( zIn[0]=='\'' );
|
||||
assert( zIn[n-1]=='\'' );
|
||||
|
||||
if( zRet ){
|
||||
int iOut = 0;
|
||||
int iIn = 0;
|
||||
i64 iOut = 0;
|
||||
i64 iIn = 0;
|
||||
for(iIn=1; iIn<(n-1); iIn++){
|
||||
if( zIn[iIn]=='\'' ){
|
||||
assert( zIn[iIn+1]=='\'' );
|
||||
@@ -699,7 +699,7 @@ static int idxGetTableInfo(
|
||||
sqlite3_stmt *p1 = 0;
|
||||
int nCol = 0;
|
||||
int nTab;
|
||||
int nByte;
|
||||
i64 nByte;
|
||||
IdxTable *pNew = 0;
|
||||
int rc, rc2;
|
||||
char *pCsr = 0;
|
||||
@@ -791,14 +791,14 @@ static char *idxAppendText(int *pRc, char *zIn, const char *zFmt, ...){
|
||||
va_list ap;
|
||||
char *zAppend = 0;
|
||||
char *zRet = 0;
|
||||
int nIn = zIn ? STRLEN(zIn) : 0;
|
||||
int nAppend = 0;
|
||||
i64 nIn = zIn ? STRLEN(zIn) : 0;
|
||||
i64 nAppend = 0;
|
||||
va_start(ap, zFmt);
|
||||
if( *pRc==SQLITE_OK ){
|
||||
zAppend = sqlite3_vmprintf(zFmt, ap);
|
||||
if( zAppend ){
|
||||
nAppend = STRLEN(zAppend);
|
||||
zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
|
||||
zRet = (char*)sqlite3_malloc64(nIn + nAppend + 1);
|
||||
}
|
||||
if( zAppend && zRet ){
|
||||
if( nIn ) memcpy(zRet, zIn, nIn);
|
||||
@@ -1562,8 +1562,8 @@ struct IdxRemCtx {
|
||||
int eType; /* SQLITE_NULL, INTEGER, REAL, TEXT, BLOB */
|
||||
i64 iVal; /* SQLITE_INTEGER value */
|
||||
double rVal; /* SQLITE_FLOAT value */
|
||||
int nByte; /* Bytes of space allocated at z */
|
||||
int n; /* Size of buffer z */
|
||||
i64 nByte; /* Bytes of space allocated at z */
|
||||
i64 n; /* Size of buffer z */
|
||||
char *z; /* SQLITE_TEXT/BLOB value */
|
||||
} aSlot[1];
|
||||
};
|
||||
@@ -1599,11 +1599,13 @@ static void idxRemFunc(
|
||||
break;
|
||||
|
||||
case SQLITE_BLOB:
|
||||
sqlite3_result_blob(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
|
||||
assert( pSlot->n <= 0x7fffffff );
|
||||
sqlite3_result_blob(pCtx, pSlot->z, (int)pSlot->n, SQLITE_TRANSIENT);
|
||||
break;
|
||||
|
||||
case SQLITE_TEXT:
|
||||
sqlite3_result_text(pCtx, pSlot->z, pSlot->n, SQLITE_TRANSIENT);
|
||||
assert( pSlot->n <= 0x7fffffff );
|
||||
sqlite3_result_text(pCtx, pSlot->z, (int)pSlot->n, SQLITE_TRANSIENT);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1623,10 +1625,10 @@ static void idxRemFunc(
|
||||
|
||||
case SQLITE_BLOB:
|
||||
case SQLITE_TEXT: {
|
||||
int nByte = sqlite3_value_bytes(argv[1]);
|
||||
i64 nByte = sqlite3_value_bytes(argv[1]);
|
||||
const void *pData = 0;
|
||||
if( nByte>pSlot->nByte ){
|
||||
char *zNew = (char*)sqlite3_realloc(pSlot->z, nByte*2);
|
||||
char *zNew = (char*)sqlite3_realloc64(pSlot->z, nByte*2);
|
||||
if( zNew==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return;
|
||||
@@ -1681,7 +1683,7 @@ static int idxPopulateOneStat1(
|
||||
int nCol = 0;
|
||||
int i;
|
||||
sqlite3_stmt *pQuery = 0;
|
||||
int *aStat = 0;
|
||||
i64 *aStat = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
assert( p->iSample>0 );
|
||||
@@ -1727,7 +1729,7 @@ static int idxPopulateOneStat1(
|
||||
sqlite3_free(zQuery);
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1));
|
||||
aStat = (i64*)idxMalloc(&rc, sizeof(i64)*(nCol+1));
|
||||
}
|
||||
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){
|
||||
IdxHashEntry *pEntry;
|
||||
@@ -1744,11 +1746,11 @@ static int idxPopulateOneStat1(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
int s0 = aStat[0];
|
||||
zStat = sqlite3_mprintf("%d", s0);
|
||||
i64 s0 = aStat[0];
|
||||
zStat = sqlite3_mprintf("%lld", s0);
|
||||
if( zStat==0 ) rc = SQLITE_NOMEM;
|
||||
for(i=1; rc==SQLITE_OK && i<=nCol; i++){
|
||||
zStat = idxAppendText(&rc, zStat, " %d", (s0+aStat[i]/2) / aStat[i]);
|
||||
zStat = idxAppendText(&rc, zStat, " %lld", (s0+aStat[i]/2) / aStat[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1827,7 +1829,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
|
||||
rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
int nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
|
||||
i64 nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
|
||||
pCtx = (struct IdxRemCtx*)idxMalloc(&rc, nByte);
|
||||
}
|
||||
|
||||
@@ -1844,7 +1846,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
pCtx->nSlot = nMax+1;
|
||||
pCtx->nSlot = (i64)nMax+1;
|
||||
rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -2111,7 +2113,7 @@ int sqlite3_expert_sql(
|
||||
if( pStmt ){
|
||||
IdxStatement *pNew;
|
||||
const char *z = sqlite3_sql(pStmt);
|
||||
int n = STRLEN(z);
|
||||
i64 n = STRLEN(z);
|
||||
pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1);
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew->zSql = (char*)&pNew[1];
|
||||
|
||||
+8
-12
@@ -14,6 +14,13 @@
|
||||
#ifndef _FTSINT_H
|
||||
#define _FTSINT_H
|
||||
|
||||
/*
|
||||
** Activate assert() only if SQLITE_TEST is enabled.
|
||||
*/
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
# define NDEBUG 1
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
@@ -21,10 +28,6 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
# define NDEBUG 1
|
||||
#endif
|
||||
|
||||
/* FTS3/FTS4 require virtual tables */
|
||||
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
||||
# undef SQLITE_ENABLE_FTS3
|
||||
@@ -44,7 +47,7 @@
|
||||
|
||||
/* If not building as part of the core, include sqlite3ext.h. */
|
||||
#ifndef SQLITE_CORE
|
||||
# include "sqlite3ext.h"
|
||||
# include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT3
|
||||
#endif
|
||||
|
||||
@@ -186,13 +189,6 @@ typedef sqlite3_int64 i64; /* 8-byte signed integer */
|
||||
*/
|
||||
#define UNUSED_PARAMETER(x) (void)(x)
|
||||
|
||||
/*
|
||||
** Activate assert() only if SQLITE_TEST is enabled.
|
||||
*/
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
# define NDEBUG 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The TESTONLY macro is used to enclose variable declarations or
|
||||
** other bits of code that are needed to support the arguments
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
typedef sqlite3_int64 i64;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Characters that may appear in the second argument to matchinfo().
|
||||
*/
|
||||
|
||||
@@ -3714,8 +3714,8 @@ struct NodeWriter {
|
||||
** to an appendable b-tree segment.
|
||||
*/
|
||||
struct IncrmergeWriter {
|
||||
int nLeafEst; /* Space allocated for leaf blocks */
|
||||
int nWork; /* Number of leaf pages flushed */
|
||||
i64 nLeafEst; /* Space allocated for leaf blocks */
|
||||
i64 nWork; /* Number of leaf pages flushed */
|
||||
sqlite3_int64 iAbsLevel; /* Absolute level of input segments */
|
||||
int iIdx; /* Index of *output* segment in iAbsLevel+1 */
|
||||
sqlite3_int64 iStart; /* Block number of first allocated block */
|
||||
@@ -4461,7 +4461,7 @@ static int fts3IncrmergeWriter(
|
||||
){
|
||||
int rc; /* Return Code */
|
||||
int i; /* Iterator variable */
|
||||
int nLeafEst = 0; /* Blocks allocated for leaf nodes */
|
||||
i64 nLeafEst = 0; /* Blocks allocated for leaf nodes */
|
||||
sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */
|
||||
sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */
|
||||
|
||||
@@ -4471,7 +4471,7 @@ static int fts3IncrmergeWriter(
|
||||
sqlite3_bind_int64(pLeafEst, 1, iAbsLevel);
|
||||
sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment);
|
||||
if( SQLITE_ROW==sqlite3_step(pLeafEst) ){
|
||||
nLeafEst = sqlite3_column_int(pLeafEst, 0);
|
||||
nLeafEst = sqlite3_column_int64(pLeafEst, 0);
|
||||
}
|
||||
rc = sqlite3_reset(pLeafEst);
|
||||
}
|
||||
|
||||
+15
-16
@@ -60,21 +60,14 @@ typedef sqlite3_uint64 u64;
|
||||
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
|
||||
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
|
||||
|
||||
/* The uptr type is an unsigned integer large enough to hold a pointer
|
||||
/*
|
||||
** This macro is used in a single assert() within fts5 to check that an
|
||||
** allocation is aligned to an 8-byte boundary. But it is a complicated
|
||||
** macro to get right for multiple platforms without generating warnings.
|
||||
** So instead of reproducing the entire definition from sqliteInt.h, we
|
||||
** just do without this assert() for the rare non-amalgamation builds.
|
||||
*/
|
||||
#if defined(HAVE_STDINT_H)
|
||||
typedef uintptr_t uptr;
|
||||
#elif SQLITE_PTRSIZE==4
|
||||
typedef u32 uptr;
|
||||
#else
|
||||
typedef u64 uptr;
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
|
||||
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
|
||||
#else
|
||||
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
|
||||
#endif
|
||||
#define EIGHT_BYTE_ALIGNMENT(x) 1
|
||||
|
||||
/*
|
||||
** Macros needed to provide flexible arrays in a portable way
|
||||
@@ -88,7 +81,13 @@ typedef sqlite3_uint64 u64;
|
||||
# define FLEXARRAY 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* SQLITE_AMALGAMATION */
|
||||
|
||||
/*
|
||||
** Constants for the largest and smallest possible 32-bit signed integers.
|
||||
*/
|
||||
# define LARGEST_INT32 ((int)(0x7fffffff))
|
||||
# define SMALLEST_INT32 ((int)((-1) - LARGEST_INT32))
|
||||
|
||||
/* Truncate very long tokens to this many bytes. Hard limit is
|
||||
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
|
||||
@@ -822,7 +821,7 @@ int sqlite3Fts5ExprPattern(
|
||||
** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
|
||||
** }
|
||||
*/
|
||||
int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc);
|
||||
int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, i64, int bDesc);
|
||||
int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax);
|
||||
int sqlite3Fts5ExprEof(Fts5Expr*);
|
||||
i64 sqlite3Fts5ExprRowid(Fts5Expr*);
|
||||
|
||||
+10
-1
@@ -1549,7 +1549,13 @@ static int fts5ExprNodeFirst(Fts5Expr *pExpr, Fts5ExprNode *pNode){
|
||||
** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
|
||||
** is not considered an error if the query does not match any documents.
|
||||
*/
|
||||
int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
|
||||
int sqlite3Fts5ExprFirst(
|
||||
Fts5Expr *p,
|
||||
Fts5Index *pIdx,
|
||||
i64 iFirst,
|
||||
i64 iLast,
|
||||
int bDesc
|
||||
){
|
||||
Fts5ExprNode *pRoot = p->pRoot;
|
||||
int rc; /* Return code */
|
||||
|
||||
@@ -1571,6 +1577,9 @@ int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
|
||||
assert( pRoot->bEof==0 );
|
||||
rc = fts5ExprNodeNext(p, pRoot, 0, 0);
|
||||
}
|
||||
if( fts5RowidCmp(p, pRoot->iRowid, iLast)>0 ){
|
||||
pRoot->bEof = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+50
-29
@@ -877,9 +877,9 @@ static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
u8 *aOut = 0; /* Read blob data into this buffer */
|
||||
int nByte = sqlite3_blob_bytes(p->pReader);
|
||||
int szData = (sizeof(Fts5Data) + 7) & ~7;
|
||||
sqlite3_int64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
|
||||
i64 nByte = sqlite3_blob_bytes(p->pReader);
|
||||
i64 szData = (sizeof(Fts5Data) + 7) & ~7;
|
||||
i64 nAlloc = szData + nByte + FTS5_DATA_PADDING;
|
||||
pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
|
||||
if( pRet ){
|
||||
pRet->nn = nByte;
|
||||
@@ -1986,9 +1986,9 @@ static void fts5SegIterSetNext(Fts5Index *p, Fts5SegIter *pIter){
|
||||
** leave an error in the Fts5Index object.
|
||||
*/
|
||||
static void fts5SegIterAllocTombstone(Fts5Index *p, Fts5SegIter *pIter){
|
||||
const int nTomb = pIter->pSeg->nPgTombstone;
|
||||
const i64 nTomb = (i64)pIter->pSeg->nPgTombstone;
|
||||
if( nTomb>0 ){
|
||||
int nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
|
||||
i64 nByte = SZ_FTS5TOMBSTONEARRAY(nTomb+1);
|
||||
Fts5TombstoneArray *pNew;
|
||||
pNew = (Fts5TombstoneArray*)sqlite3Fts5MallocZero(&p->rc, nByte);
|
||||
if( pNew ){
|
||||
@@ -2074,6 +2074,7 @@ static void fts5SegIterReverseInitPage(Fts5Index *p, Fts5SegIter *pIter){
|
||||
while( 1 ){
|
||||
u64 iDelta = 0;
|
||||
|
||||
if( i>=n ) break;
|
||||
if( eDetail==FTS5_DETAIL_NONE ){
|
||||
/* todo */
|
||||
if( i<n && a[i]==0 ){
|
||||
@@ -2481,18 +2482,20 @@ static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
|
||||
fts5DataRelease(pIter->pLeaf);
|
||||
pIter->pLeaf = pLast;
|
||||
pIter->iLeafPgno = pgnoLast;
|
||||
iOff = fts5LeafFirstRowidOff(pLast);
|
||||
if( iOff>pLast->szLeaf ){
|
||||
FTS5_CORRUPT_ITER(p, pIter);
|
||||
return;
|
||||
}
|
||||
iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
|
||||
pIter->iLeafOffset = iOff;
|
||||
if( p->rc==SQLITE_OK ){
|
||||
iOff = fts5LeafFirstRowidOff(pLast);
|
||||
if( iOff>pLast->szLeaf ){
|
||||
FTS5_CORRUPT_ITER(p, pIter);
|
||||
return;
|
||||
}
|
||||
iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
|
||||
pIter->iLeafOffset = iOff;
|
||||
|
||||
if( fts5LeafIsTermless(pLast) ){
|
||||
pIter->iEndofDoclist = pLast->nn+1;
|
||||
}else{
|
||||
pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
|
||||
if( fts5LeafIsTermless(pLast) ){
|
||||
pIter->iEndofDoclist = pLast->nn+1;
|
||||
}else{
|
||||
pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5845,7 +5848,7 @@ static Fts5Structure *fts5IndexOptimizeStruct(
|
||||
}
|
||||
|
||||
nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
|
||||
assert( nByte==SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
|
||||
assert( nByte==(i64)SZ_FTS5STRUCTURE(pStruct->nLevel+2) );
|
||||
pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
|
||||
|
||||
if( pNew ){
|
||||
@@ -5928,7 +5931,7 @@ int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge){
|
||||
fts5StructureRelease(pStruct);
|
||||
pStruct = pNew;
|
||||
nMin = 1;
|
||||
nMerge = nMerge*-1;
|
||||
nMerge = (nMerge==SMALLEST_INT32 ? LARGEST_INT32 : (nMerge*-1));
|
||||
}
|
||||
if( pStruct && pStruct->nLevel ){
|
||||
if( fts5IndexMerge(p, &pStruct, nMerge, nMin) ){
|
||||
@@ -6820,11 +6823,14 @@ int sqlite3Fts5IndexRollback(Fts5Index *p){
|
||||
*/
|
||||
int sqlite3Fts5IndexReinit(Fts5Index *p){
|
||||
Fts5Structure *pTmp;
|
||||
u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
|
||||
union {
|
||||
Fts5Structure sFts;
|
||||
u8 tmpSpace[SZ_FTS5STRUCTURE(1)];
|
||||
} uFts;
|
||||
fts5StructureInvalidate(p);
|
||||
fts5IndexDiscardData(p);
|
||||
pTmp = (Fts5Structure*)tmpSpace;
|
||||
memset(pTmp, 0, SZ_FTS5STRUCTURE(1));
|
||||
pTmp = &uFts.sFts;
|
||||
memset(uFts.tmpSpace, 0, sizeof(uFts.tmpSpace));
|
||||
if( p->pConfig->bContentlessDelete ){
|
||||
pTmp->nOriginCntr = 1;
|
||||
}
|
||||
@@ -8284,19 +8290,27 @@ static int fts5TestUtf8(const char *z, int n){
|
||||
/*
|
||||
** This function is also purely an internal test. It does not contribute to
|
||||
** FTS functionality, or even the integrity-check, in any way.
|
||||
**
|
||||
** This function sets output variable (*pbFail) to true if the test fails. Or
|
||||
** leaves it unchanged if the test succeeds.
|
||||
*/
|
||||
static void fts5TestTerm(
|
||||
Fts5Index *p,
|
||||
Fts5Buffer *pPrev, /* Previous term */
|
||||
const char *z, int n, /* Possibly new term to test */
|
||||
u64 expected,
|
||||
u64 *pCksum
|
||||
u64 *pCksum,
|
||||
int *pbFail
|
||||
){
|
||||
int rc = p->rc;
|
||||
if( pPrev->n==0 ){
|
||||
fts5BufferSet(&rc, pPrev, n, (const u8*)z);
|
||||
}else
|
||||
if( rc==SQLITE_OK && (pPrev->n!=n || memcmp(pPrev->p, z, n)) ){
|
||||
if( *pbFail==0
|
||||
&& rc==SQLITE_OK
|
||||
&& (pPrev->n!=n || memcmp(pPrev->p, z, n))
|
||||
&& (p->pHash==0 || p->pHash->nEntry==0)
|
||||
){
|
||||
u64 cksum3 = *pCksum;
|
||||
const char *zTerm = (const char*)&pPrev->p[1]; /* term sans prefix-byte */
|
||||
int nTerm = pPrev->n-1; /* Size of zTerm in bytes */
|
||||
@@ -8346,7 +8360,7 @@ static void fts5TestTerm(
|
||||
fts5BufferSet(&rc, pPrev, n, (const u8*)z);
|
||||
|
||||
if( rc==SQLITE_OK && cksum3!=expected ){
|
||||
rc = FTS5_CORRUPT;
|
||||
*pbFail = 1;
|
||||
}
|
||||
*pCksum = cksum3;
|
||||
}
|
||||
@@ -8355,7 +8369,7 @@ static void fts5TestTerm(
|
||||
|
||||
#else
|
||||
# define fts5TestDlidxReverse(x,y,z)
|
||||
# define fts5TestTerm(u,v,w,x,y,z)
|
||||
# define fts5TestTerm(t,u,v,w,x,y,z)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -8613,6 +8627,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
/* Used by extra internal tests only run if NDEBUG is not defined */
|
||||
u64 cksum3 = 0; /* Checksum based on contents of indexes */
|
||||
Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */
|
||||
int bTestFail = 0;
|
||||
#endif
|
||||
const int flags = FTS5INDEX_QUERY_NOOUTPUT;
|
||||
|
||||
@@ -8655,7 +8670,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
char *z = (char*)fts5MultiIterTerm(pIter, &n);
|
||||
|
||||
/* If this is a new term, query for it. Update cksum3 with the results. */
|
||||
fts5TestTerm(p, &term, z, n, cksum2, &cksum3);
|
||||
fts5TestTerm(p, &term, z, n, cksum2, &cksum3, &bTestFail);
|
||||
if( p->rc ) break;
|
||||
|
||||
if( eDetail==FTS5_DETAIL_NONE ){
|
||||
@@ -8673,7 +8688,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
}
|
||||
}
|
||||
}
|
||||
fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
|
||||
fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3, &bTestFail);
|
||||
|
||||
fts5MultiIterFree(pIter);
|
||||
if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
|
||||
@@ -8682,11 +8697,17 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
|
||||
"fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
|
||||
);
|
||||
}
|
||||
|
||||
fts5StructureRelease(pStruct);
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* In SQLITE_DEBUG builds, expensive extra checks were run as part of
|
||||
** the integrity-check above. If no other errors were detected, but one
|
||||
** of these tests failed, set the result to SQLITE_CORRUPT_VTAB here. */
|
||||
if( p->rc==SQLITE_OK && bTestFail ){
|
||||
p->rc = FTS5_CORRUPT;
|
||||
}
|
||||
fts5BufferFree(&term);
|
||||
#endif
|
||||
|
||||
fts5StructureRelease(pStruct);
|
||||
fts5BufferFree(&poslist);
|
||||
return fts5IndexReturn(p);
|
||||
}
|
||||
|
||||
+37
-17
@@ -511,6 +511,17 @@ static void fts5SetUniqueFlag(sqlite3_index_info *pIdxInfo){
|
||||
#endif
|
||||
}
|
||||
|
||||
static void fts5SetEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
|
||||
#if SQLITE_VERSION_NUMBER>=3008002
|
||||
#ifndef SQLITE_CORE
|
||||
if( sqlite3_libversion_number()>=3008002 )
|
||||
#endif
|
||||
{
|
||||
pIdxInfo->estimatedRows = nRow;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int fts5UsePatternMatch(
|
||||
Fts5Config *pConfig,
|
||||
struct sqlite3_index_constraint *p
|
||||
@@ -646,7 +657,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
nSeenMatch++;
|
||||
idxStr[iIdxStr++] = 'M';
|
||||
sqlite3_snprintf(6, &idxStr[iIdxStr], "%d", iCol);
|
||||
idxStr += strlen(&idxStr[iIdxStr]);
|
||||
iIdxStr += (int)strlen(&idxStr[iIdxStr]);
|
||||
assert( idxStr[iIdxStr]=='\0' );
|
||||
}
|
||||
pInfo->aConstraintUsage[i].argvIndex = ++iCons;
|
||||
@@ -665,6 +676,7 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
idxStr[iIdxStr++] = '=';
|
||||
bSeenEq = 1;
|
||||
pInfo->aConstraintUsage[i].argvIndex = ++iCons;
|
||||
pInfo->aConstraintUsage[i].omit = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -712,17 +724,21 @@ static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
|
||||
/* Calculate the estimated cost based on the flags set in idxFlags. */
|
||||
if( bSeenEq ){
|
||||
pInfo->estimatedCost = nSeenMatch ? 1000.0 : 10.0;
|
||||
if( nSeenMatch==0 ) fts5SetUniqueFlag(pInfo);
|
||||
}else if( bSeenLt && bSeenGt ){
|
||||
pInfo->estimatedCost = nSeenMatch ? 5000.0 : 250000.0;
|
||||
}else if( bSeenLt || bSeenGt ){
|
||||
pInfo->estimatedCost = nSeenMatch ? 7500.0 : 750000.0;
|
||||
pInfo->estimatedCost = nSeenMatch ? 1000.0 : 25.0;
|
||||
fts5SetUniqueFlag(pInfo);
|
||||
fts5SetEstimatedRows(pInfo, 1);
|
||||
}else{
|
||||
pInfo->estimatedCost = nSeenMatch ? 10000.0 : 1000000.0;
|
||||
}
|
||||
for(i=1; i<nSeenMatch; i++){
|
||||
pInfo->estimatedCost *= 0.4;
|
||||
if( bSeenLt && bSeenGt ){
|
||||
pInfo->estimatedCost = nSeenMatch ? 5000.0 : 750000.0;
|
||||
}else if( bSeenLt || bSeenGt ){
|
||||
pInfo->estimatedCost = nSeenMatch ? 7500.0 : 2250000.0;
|
||||
}else{
|
||||
pInfo->estimatedCost = nSeenMatch ? 10000.0 : 3000000.0;
|
||||
}
|
||||
for(i=1; i<nSeenMatch; i++){
|
||||
pInfo->estimatedCost *= 0.4;
|
||||
}
|
||||
fts5SetEstimatedRows(pInfo, (i64)(pInfo->estimatedCost / 4.0));
|
||||
}
|
||||
|
||||
pInfo->idxNum = idxFlags;
|
||||
@@ -921,7 +937,9 @@ static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){
|
||||
int bDesc = pCsr->bDesc;
|
||||
i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
|
||||
|
||||
rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->p.pIndex, iRowid, bDesc);
|
||||
rc = sqlite3Fts5ExprFirst(
|
||||
pCsr->pExpr, pTab->p.pIndex, iRowid, pCsr->iLastRowid, bDesc
|
||||
);
|
||||
if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
|
||||
*pbSkip = 1;
|
||||
}
|
||||
@@ -1093,7 +1111,9 @@ static int fts5CursorFirstSorted(
|
||||
static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
|
||||
int rc;
|
||||
Fts5Expr *pExpr = pCsr->pExpr;
|
||||
rc = sqlite3Fts5ExprFirst(pExpr, pTab->p.pIndex, pCsr->iFirstRowid, bDesc);
|
||||
rc = sqlite3Fts5ExprFirst(
|
||||
pExpr, pTab->p.pIndex, pCsr->iFirstRowid, pCsr->iLastRowid, bDesc
|
||||
);
|
||||
if( sqlite3Fts5ExprEof(pExpr) ){
|
||||
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
||||
}
|
||||
@@ -3601,9 +3621,9 @@ static void fts5LocaleFunc(
|
||||
sqlite3_value **apArg /* Function arguments */
|
||||
){
|
||||
const char *zLocale = 0;
|
||||
int nLocale = 0;
|
||||
i64 nLocale = 0;
|
||||
const char *zText = 0;
|
||||
int nText = 0;
|
||||
i64 nText = 0;
|
||||
|
||||
assert( nArg==2 );
|
||||
UNUSED_PARAM(nArg);
|
||||
@@ -3620,10 +3640,10 @@ static void fts5LocaleFunc(
|
||||
Fts5Global *p = (Fts5Global*)sqlite3_user_data(pCtx);
|
||||
u8 *pBlob = 0;
|
||||
u8 *pCsr = 0;
|
||||
int nBlob = 0;
|
||||
i64 nBlob = 0;
|
||||
|
||||
nBlob = FTS5_LOCALE_HDR_SIZE + nLocale + 1 + nText;
|
||||
pBlob = (u8*)sqlite3_malloc(nBlob);
|
||||
pBlob = (u8*)sqlite3_malloc64(nBlob);
|
||||
if( pBlob==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return;
|
||||
|
||||
@@ -396,7 +396,12 @@ static int fts5VocabOpenMethod(
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Restore cursor pCsr to the state it was in immediately after being
|
||||
** created by the xOpen() method.
|
||||
*/
|
||||
static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
|
||||
int nCol = pCsr->pFts5->pConfig->nCol;
|
||||
pCsr->rowid = 0;
|
||||
sqlite3Fts5IterClose(pCsr->pIter);
|
||||
sqlite3Fts5StructureRelease(pCsr->pStruct);
|
||||
@@ -406,6 +411,12 @@ static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
|
||||
pCsr->nLeTerm = -1;
|
||||
pCsr->zLeTerm = 0;
|
||||
pCsr->bEof = 0;
|
||||
pCsr->iCol = 0;
|
||||
pCsr->iInstPos = 0;
|
||||
pCsr->iInstOff = 0;
|
||||
pCsr->colUsed = 0;
|
||||
memset(pCsr->aCnt, 0, sizeof(i64)*nCol);
|
||||
memset(pCsr->aDoc, 0, sizeof(i64)*nCol);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -294,6 +294,39 @@ do_execsql_test 7.0 {
|
||||
INSERT INTO x1 VALUES($doc);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Forum post: https://sqlite.org/forum/forumpost/ea4d8c9acb
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 8.0 {
|
||||
PRAGMA encoding = 'UTF-16le';
|
||||
CREATE VIRTUAL TABLE vt0 USING fts5(c0);
|
||||
}
|
||||
set v [db one {SELECT x'2a12'}]
|
||||
do_execsql_test 8.1 {
|
||||
INSERT INTO vt0 VALUES ($v);
|
||||
}
|
||||
do_execsql_test 8.2 {
|
||||
SELECT quote(c0) FROM vt0
|
||||
} {X'2A12'}
|
||||
do_execsql_test 8.3 {
|
||||
INSERT INTO vt0(vt0) VALUES('integrity-check');
|
||||
} {}
|
||||
reset_db
|
||||
do_execsql_test 8.4 {
|
||||
PRAGMA encoding = 'UTF-16le';
|
||||
CREATE VIRTUAL TABLE vt0 USING fts5(c0);
|
||||
}
|
||||
do_execsql_test 8.5 {
|
||||
INSERT INTO vt0 VALUES (x'2a12');
|
||||
}
|
||||
do_execsql_test 8.6 {
|
||||
SELECT quote(c0) FROM vt0
|
||||
} {X'2A12'}
|
||||
do_execsql_test 8.7 {
|
||||
INSERT INTO vt0(vt0) VALUES('integrity-check');
|
||||
} {}
|
||||
|
||||
} ;# foreach_detail_mode...
|
||||
|
||||
|
||||
|
||||
@@ -6644,7 +6644,7 @@ do_test 48.0 {
|
||||
|
||||
do_catchsql_test 48.1 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
} {1 {database disk image is malformed}}
|
||||
} {1 {fts5: corruption on page 1, segment 1, table "t1"}}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
reset_db
|
||||
@@ -10106,7 +10106,7 @@ do_test 68.0 {
|
||||
do_catchsql_test 68.1 {
|
||||
PRAGMA reverse_unordered_selects=ON;
|
||||
INSERT INTO t1(t1) SELECT x FROM t2;
|
||||
} {1 {database disk image is malformed}}
|
||||
} {1 {fts5: corruption on page 1, segment 1, table "t1"}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
@@ -15909,8 +15909,582 @@ do_catchsql_test 82.4 {
|
||||
SAVEPOINT b;
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_test 83.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 24576 pagesize 4096 filename crash-c4a4c5492615bd.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06 .....@ ........
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 ................
|
||||
| 96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53 ...............S
|
||||
| 112: 0e e8 0e 8b 0e 33 0e 0f 00 01 00 00 00 00 00 00 .....3..........
|
||||
| 3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................
|
||||
| 3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62 ......1tablebbbb
|
||||
| 3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62 .CREATE TABLE bb
|
||||
| 3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65 (a)V.......table
|
||||
| 3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66 t1_configt1_conf
|
||||
| 3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 ig.CREATE TABLE
|
||||
| 3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52 't1_config'(k PR
|
||||
| 3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49 IMARY KEY, v) WI
|
||||
| 3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21 THOUT ROWID[...!
|
||||
| 3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73 !...tablet1_docs
|
||||
| 3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52 izet1_docsize.CR
|
||||
| 3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64 EATE TABLE 't1_d
|
||||
| 3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47 ocsize'(id INTEG
|
||||
| 3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
|
||||
| 3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81 sz BLOB)i.......
|
||||
| 3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69 -tablet1_idxt1_i
|
||||
| 3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 dx.CREATE TABLE
|
||||
| 3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20 't1_idx'(segid,
|
||||
| 3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d term, pgno, PRIM
|
||||
| 3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74 ARY KEY(segid, t
|
||||
| 3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f erm)) WITHOUT RO
|
||||
| 3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c WIDU........tabl
|
||||
| 3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02 et1_datat1_data.
|
||||
| 3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 CREATE TABLE 't1
|
||||
| 3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45 _data'(id INTEGE
|
||||
| 3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 R PRIMARY KEY, b
|
||||
| 4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11 lock BLOB)T.....
|
||||
| 4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41 ...tablet1t1CREA
|
||||
| 4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
|
||||
| 4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61 t1 USING fts5(a
|
||||
| 4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 ,b,prefix=.1,2,3
|
||||
| 4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29 ,4., content=..)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4 ..j.7.L....L....
|
||||
| 16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad ...m.K.,........
|
||||
| 32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5 ...l.K.)........
|
||||
| 48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5 ...v.T.1........
|
||||
| 64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0 ...s.T.2........
|
||||
| 80: 0b 8d 0b 7e 0b 48 0b 2e 0b 00 4a ef fa cc 0a ad ...~.H....J.....
|
||||
| 96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 00 00 00 00 00 ...m.M.+........
|
||||
| 2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00 ................
|
||||
| 2384: 30 00 00 00 01 01 03 35 00 03 01 01 12 02 01 12 0......5........
|
||||
| 2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00 ............>...
|
||||
| 2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68 ....4tabl.....wh
|
||||
| 2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c er.............<
|
||||
| 2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e .....4fts4.....n
|
||||
| 2464: 75 6d 62 03 07 01 04 09 1b 8c 80 80 80 80 0e 03 umb.............
|
||||
| 2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04 .<.....3the.....
|
||||
| 2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80 ..whe...........
|
||||
| 2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01 ...<.....3num...
|
||||
| 2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80 ....tab.........
|
||||
| 2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02 .....8.....2wh..
|
||||
| 2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80 ...3fts.........
|
||||
| 2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02 .....6.....2ta..
|
||||
| 2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80 ...h............
|
||||
| 2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01 ....<.....2nu...
|
||||
| 2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80 ....of..........
|
||||
| 2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03 ......8.....2ft.
|
||||
| 2656: 02 02 01 02 69 73 02 06 01 01 03 04 07 18 8c 80 ....is..........
|
||||
| 2672: 80 80 22 08 03 00 36 00 00 00 13 02 31 74 03 08 ......6.....1t..
|
||||
| 2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80 ......w.........
|
||||
| 2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01 .....:.....1n...
|
||||
| 2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80 .....o..........
|
||||
| 2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03 ......6......1f.
|
||||
| 2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80 ....i...........
|
||||
| 2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03 .....>.....0the.
|
||||
| 2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15 ......where.....
|
||||
| 2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06 ........0.......
|
||||
| 2816: 06 30 74 61 62 6c 65 03 01 f3 07 1c 8c 80 80 80 .0table.........
|
||||
| 2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65 ....>.....0numbe
|
||||
| 2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c r.......of......
|
||||
| 2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02 .......,........
|
||||
| 2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03 0n..............
|
||||
| 2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03 .<.....0fts4aux.
|
||||
| 2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00 ....is........*.
|
||||
| 2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88 .....$..........
|
||||
| 2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80 ................
|
||||
| 2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77 ......>.....4row
|
||||
| 2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b s.......ther....
|
||||
| 2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01 .........0......
|
||||
| 3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80 ...4betw........
|
||||
| 3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77 .....<......3row
|
||||
| 3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88 .......the......
|
||||
| 3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04 .......<........
|
||||
| 3072: 33 61 72 65 02 02 b3 01 03 62 65 74 02 02 07 08 3are.....bet....
|
||||
| 3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32 .........<.....2
|
||||
| 3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06 th........3and..
|
||||
| 3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16 ...........<....
|
||||
| 3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01 .2in.......ro...
|
||||
| 3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 0f .............6..
|
||||
| 3168: f0 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02 ....2ar.....be..
|
||||
| 3184: 03 05 07 1b 88 80 80 80 80 0a 03 00 3c dd 00 00 ............<...
|
||||
| 3200: 18 c2 31 74 02 08 02 01 01 07 00 03 32 61 6e 02 ..1t........2an.
|
||||
| 3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00 ..............8.
|
||||
| 3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06 ....1n.......r..
|
||||
| 3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00 ..............4.
|
||||
| 3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01 ....1b.....i....
|
||||
| 3280: 06 04 06 19 88 80 90 80 80 07 03 00 38 00 00 00 ............8...
|
||||
| 3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01 ...12.....a.....
|
||||
| 3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00 ............<...
|
||||
| 3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02 ..0there.....11.
|
||||
| 3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00 ..............0.
|
||||
| 3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07 .......0the.....
|
||||
| 3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01 ..........>.....
|
||||
| 3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73 ...0n.......rows
|
||||
| 3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00 .............<..
|
||||
| 3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02 ...0between.....
|
||||
| 3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a in.............:
|
||||
| 3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02 .....0and.......
|
||||
| 3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00 re..............
|
||||
| 3488: 34 00 00 0c 52 02 30 31 02 06 01 01 04 01 01 32 4...R.01.......2
|
||||
| 3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00 ................
|
||||
| 3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00 .............<..
|
||||
| 3536: 00 16 05 34 74 61 62 6c 01 06 00 f1 05 02 03 65 ...4tabl.......e
|
||||
| 3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c rm.............<
|
||||
| 3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70 .....4each.....p
|
||||
| 3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03 res.............
|
||||
| 3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02 .:.....3ter.....
|
||||
| 3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e he..............
|
||||
| 3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01 ..<.....3pre....
|
||||
| 3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80 .tab............
|
||||
| 3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02 ....:.....3for..
|
||||
| 3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80 ...ts...........
|
||||
| 3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06 .....<.....2th..
|
||||
| 3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 74 .....3eac......t
|
||||
| 3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 .......6.....2ta
|
||||
| 3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80 .......e........
|
||||
| 3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01 ......8.....2in.
|
||||
| 3776: 06 01 01 02 11 02 70 62 01 02 05 04 09 18 84 80 ......pb........
|
||||
| 3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01 ......6.....2fo.
|
||||
| 3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80 ....t...........
|
||||
| 3824: 80 80 08 03 00 3c 0d c0 00 16 12 31 74 01 0a 04 .....<.....1t...
|
||||
| 3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84 ......2ea.......
|
||||
| 3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01 .......4.....1i.
|
||||
| 3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80 ......p.........
|
||||
| 3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03 .....6.....1e...
|
||||
| 3904: 01 01 66 01 08 02 5b 01 04 04 06 1b 84 80 80 80 ..f...[.........
|
||||
| 3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01 ....<.....0term.
|
||||
| 3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80 ....he..........
|
||||
| 3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62 ............0tab
|
||||
| 3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03 le..............
|
||||
| 3984: 00 30 00 00 00 11 01 f8 30 70 72 65 73 65 6e 74 .0......0present
|
||||
| 4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00 .............<..
|
||||
| 4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e ...0fts.......in
|
||||
| 4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a ...............:
|
||||
| 4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66 .....0each.....f
|
||||
| 4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00 or..............
|
||||
| 4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04 ................
|
||||
| page 3 offset 8192
|
||||
| 0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1 ....2.O.........
|
||||
| 16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0 ................
|
||||
| 32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f .........x.q.h._
|
||||
| 48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13 .V.M.A.8./.&....
|
||||
| 64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd ................
|
||||
| 80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 00 00 00 ................
|
||||
| 3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................
|
||||
| 3664: 04 01 10 01 03 34 74 20 07 04 02 4e 01 03 34 1e .....4t ...N..4.
|
||||
| 3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03 ......3th.......
|
||||
| 3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10 3n.......2w.....
|
||||
| 3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04 ..2t.......2n...
|
||||
| 3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08 ....2.......1t..
|
||||
| 3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c .....1n.......1.
|
||||
| 3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03 ......0th.......
|
||||
| 3776: 30 74 08 19 04 01 12 01 03 30 6e 75 06 08 04 01 0t.......0nu....
|
||||
| 3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01 ...0n...........
|
||||
| 3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04 ...4r.......4 ..
|
||||
| 3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72 ....3r.......3ar
|
||||
| 3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 01 02 .......2t.......
|
||||
| 3856: 32 69 18 09 04 01 12 01 02 32 60 82 16 08 04 01 2i.......2`.....
|
||||
| 3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08 ...1t.......1n..
|
||||
| 3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32 .....1b.......12
|
||||
| 3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01 .......0ther....
|
||||
| 3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08 ...0t.......0n..
|
||||
| 3936: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61 .....0b.......0a
|
||||
| 3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22 .............4t.
|
||||
| 3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e .....4 .....3te.
|
||||
| 3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a .....3p......3f.
|
||||
| 4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74 .....2th......2t
|
||||
| 4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66 ......2i......2f
|
||||
| 4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69 ......1t......1i
|
||||
| 4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65 ......1......0te
|
||||
| 4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70 ......0t......0p
|
||||
| 4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02 ......0ft.......
|
||||
| page 4 offset 12288
|
||||
| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10 ................
|
||||
| 4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04 ................
|
||||
| page 5 offset 16384
|
||||
| 0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70 ...............p
|
||||
| 4080: 67 83 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04 g.z.....version.
|
||||
| page 6 offset 20480
|
||||
| 0: 0d 00 00 00 03 0f f2 00 0f fc 0f 00 00 00 00 00 ................
|
||||
| 4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 02 09 ................
|
||||
| end crash-c4a4c5492615bd.db
|
||||
}]} {}
|
||||
|
||||
|
||||
do_catchsql_test 83.1 {
|
||||
SELECT * FROM t1('R*R*R*R*R*R*R*R*') WHERE (a,b)<=(current_date,0 BETWEEN 'a'<>11 AND '') ORDER BY rowid DESC;
|
||||
} {/.*fts5: corruption found/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_test 84.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 53248 pagesize 4096 filename c1a.txt.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 0d .....@ ........
|
||||
| 32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04 ................
|
||||
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
|
||||
| 96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36 ...............6
|
||||
| 112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00 ...k............
|
||||
| 3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74 .........1tablet
|
||||
| 3488: 32 74 32 0d 43 52 45 41 54 45 20 54 41 42 4c 45 2t2.CREATE TABLE
|
||||
| 3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61 t2(x)V.......ta
|
||||
| 3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 blet1_configt1_c
|
||||
| 3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42 onfig.CREATE TAB
|
||||
| 3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b LE 't1_config'(k
|
||||
| 3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 PRIMARY KEY, v)
|
||||
| 3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06 WITHOUT ROWID[.
|
||||
| 3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64 ..!!...tablet1_d
|
||||
| 3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 ocsizet1_docsize
|
||||
| 3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 .CREATE TABLE 't
|
||||
| 3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 1_docsize'(id IN
|
||||
| 3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
|
||||
| 3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21 Y, sz BLOB)^...!
|
||||
| 3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74 !...tablet1_cont
|
||||
| 3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52 entt1_content.CR
|
||||
| 3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 EATE TABLE 't1_c
|
||||
| 3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 ontent'(id INTEG
|
||||
| 3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
|
||||
| 3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19 c0, c1, c2)i....
|
||||
| 3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 ...-tablet1_idxt
|
||||
| 3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42 1_idx.CREATE TAB
|
||||
| 3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69 LE 't1_idx'(segi
|
||||
| 3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 d, term, pgno, P
|
||||
| 3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64 RIMARY KEY(segid
|
||||
| 3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54 , term)) WITHOUT
|
||||
| 3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74 ROWIDU........t
|
||||
| 3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61 ablet1_datat1_da
|
||||
| 3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 ta.CREATE TABLE
|
||||
| 3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54 't1_data'(id INT
|
||||
| 3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
||||
| 3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06 , block BLOB)8..
|
||||
| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
|
||||
| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
|
||||
| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 LE t1 USING fts5
|
||||
| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9.....
|
||||
| page 3 offset 8192
|
||||
| 0: 05 00 00 00 02 0f f1 00 00 00 00 0c 0f fb 0f f1 ................
|
||||
| 4064: 00 00 0b 01 03 00 1c 81 3a 84 5e 81 3a 81 3a 0a ........:.^.:.:.
|
||||
| 4080: 0a 00 00 00 0b 84 80 80 80 80 01 00 00 00 0a 0a ................
|
||||
| page 4 offset 12288
|
||||
| 0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02 ................
|
||||
| page 7 offset 24576
|
||||
| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version.
|
||||
| page 10 offset 36864
|
||||
| 0: 0d 00 00 00 02 0f e2 00 0f e2 0f ef 00 00 00 00 ................
|
||||
| 4064: 00 00 0b 01 03 00 1c 81 3a 84 5e 81 3a 81 3a 0f ........:.^.:.:.
|
||||
| 4080: 0a 03 00 24 00 00 00 00 01 01 02 00 01 01 01 09 ...$............
|
||||
| page 11 offset 40960
|
||||
| 0: 0d 00 00 00 01 00 22 00 00 22 00 00 00 00 00 00 ................
|
||||
| 32: 00 00 9f 56 84 80 80 80 80 01 04 00 bf 30 00 00 ...V.........0..
|
||||
| 48: 0f 58 02 30 30 19 02 05 01 02 05 01 02 05 16 02 .X.00...........
|
||||
| 64: 05 01 02 05 01 02 05 61 02 05 01 02 05 01 02 05 .......a........
|
||||
| 80: 13 02 05 01 02 05 01 02 05 0d 02 03 01 02 03 01 ................
|
||||
| 96: 02 03 02 09 78 66 66 66 66 66 66 66 65 81 17 02 ....xfffffffe...
|
||||
| 112: 05 01 02 05 01 02 05 01 01 31 04 02 04 01 02 04 .........1......
|
||||
| 128: 01 02 04 01 02 05 01 02 05 01 02 05 0d 02 06 01 ................
|
||||
| 144: 02 06 01 02 06 02 01 30 79 02 04 01 02 04 01 02 .......0y.......
|
||||
| 160: 04 03 02 30 30 2b 02 05 01 02 05 01 02 05 58 02 ...00+........X.
|
||||
| 176: 05 01 02 05 01 02 05 01 02 05 01 02 05 01 02 05 ................
|
||||
| 192: 16 02 05 01 02 05 01 02 05 05 06 30 30 30 30 30 ...........00000
|
||||
| 208: 30 81 0b 02 04 01 02 04 01 02 04 10 02 05 01 02 0...............
|
||||
| 224: 05 01 02 05 03 02 32 34 76 02 05 01 02 05 01 02 ......24v.......
|
||||
| 240: 05 02 01 38 07 02 04 01 02 04 01 02 04 01 01 32 ...8...........2
|
||||
| 256: 28 02 04 01 02 04 01 02 04 04 02 05 01 02 05 01 (...............
|
||||
| 272: 02 05 02 01 30 1f 02 05 01 02 05 01 02 05 03 02 ....0...........
|
||||
| 288: 30 30 10 02 05 01 02 05 01 02 05 6a 02 04 01 02 00.........j....
|
||||
| 304: 04 01 02 04 02 08 35 30 30 30 30 30 30 30 81 26 ......50000000.&
|
||||
| 320: 02 05 01 02 05 01 02 05 01 01 33 07 02 06 01 02 ..........3.....
|
||||
| 336: 06 01 02 06 81 2c 02 04 01 02 04 01 02 04 02 04 .....,..........
|
||||
| 352: 32 37 36 36 81 23 02 05 01 02 05 01 02 05 01 01 2766.#..........
|
||||
| 368: 34 13 02 05 01 02 05 01 02 05 02 03 30 39 36 1c 4...........096.
|
||||
| 384: 02 05 01 02 05 01 02 05 07 02 05 01 02 05 01 02 ................
|
||||
| 400: 05 01 03 35 30 30 7f 02 05 01 02 05 01 02 05 04 ...500..........
|
||||
| 416: 02 30 30 81 0e 02 06 01 02 06 01 02 06 06 03 30 .00............0
|
||||
| 432: 30 30 81 11 02 04 01 02 04 01 02 04 01 05 36 35 00............65
|
||||
| 448: 35 33 36 81 1a 02 05 01 02 05 01 02 05 01 04 38 536............8
|
||||
| 464: 31 39 32 81 02 02 06 01 02 06 01 02 06 01 05 61 192............a
|
||||
| 480: 6c 6c 6f 77 01 02 02 01 02 02 01 02 02 02 02 72 llow...........r
|
||||
| 496: 67 81 08 02 04 01 02 04 01 02 04 02 05 74 6f 6d g............tom
|
||||
| 512: 69 63 04 02 02 01 02 02 01 02 02 03 06 74 61 63 ic...........tac
|
||||
| 528: 68 65 64 79 02 03 01 02 03 01 02 03 02 0d 75 74 hedy..........ut
|
||||
| 544: 6f 63 68 65 63 6b 70 6f 69 6e 74 2b 02 04 01 02 ocheckpoint+....
|
||||
| 560: 04 01 02 04 05 06 76 61 63 75 75 6d 0d 02 03 01 ......vacuum....
|
||||
| 576: 02 03 01 02 03 01 06 62 69 6e 61 72 79 03 06 01 .......binary...
|
||||
| 592: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 608: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 624: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 640: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 656: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 672: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 688: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 704: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 720: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 736: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 752: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 768: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 784: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 800: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 816: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 832: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 848: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 864: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 880: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 896: 01 02 02 02 07 79 74 65 63 6f 64 65 37 02 03 01 .....ytecode7...
|
||||
| 912: 02 03 01 02 03 01 05 63 61 63 68 65 10 02 03 01 .......cache....
|
||||
| 928: 02 03 01 01 03 02 04 6c 61 6e 67 07 02 03 01 02 .......lang.....
|
||||
| 944: 03 01 02 03 02 05 6f 6c 75 6d 6e 7c 02 03 01 02 ......olumn|....
|
||||
| 960: 03 01 02 03 03 06 6d 6d 65 6e 74 73 43 02 04 01 ......mmentsC...
|
||||
| 976: 02 04 01 02 04 04 05 70 69 6c 65 72 07 02 02 01 .......piler....
|
||||
| 992: 02 02 01 02 02 05 04 6f 75 6e 64 7f 02 03 01 02 .......ound.....
|
||||
| 1008: 03 01 02 03 03 03 75 6e 74 81 17 02 04 01 02 04 ......unt.......
|
||||
| 1024: 01 02 04 02 05 75 72 73 6f 72 3a 02 03 01 02 03 .....ursor:.....
|
||||
| 1040: 01 02 03 01 06 64 62 70 61 67 65 3d 02 03 01 02 .....dbpage=....
|
||||
| 1056: 03 01 02 03 03 04 73 74 61 74 40 02 03 01 02 03 ......stat@.....
|
||||
| 1072: 01 02 03 02 04 65 62 75 67 0a 02 02 01 02 02 01 .....ebug.......
|
||||
| 1088: 02 02 03 05 66 61 75 6c 74 0d 02 02 01 02 02 01 ....fault.......
|
||||
| 1104: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1120: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1136: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1152: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1168: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1184: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1200: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 4f 02 ..............O.
|
||||
| 1216: 03 01 02 03 01 02 03 03 03 70 74 68 81 05 02 04 .........pth....
|
||||
| 1232: 01 02 04 01 02 04 19 02 04 01 02 04 01 02 04 02 ................
|
||||
| 1248: 05 69 72 65 63 74 34 02 02 01 02 02 01 02 02 01 .irect4.........
|
||||
| 1264: 06 65 6e 61 62 6c 65 37 02 02 01 02 02 01 02 02 .enable7........
|
||||
| 1280: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1296: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1312: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1328: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1344: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1360: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1376: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1392: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1408: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1424: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1440: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1456: 02 01 02 02 02 06 78 70 6c 61 69 6e 43 02 03 01 ......xplainC...
|
||||
| 1472: 02 03 01 02 03 04 01 72 81 05 02 03 01 02 03 01 .......r........
|
||||
| 1488: 02 03 03 07 74 65 6e 73 69 6f 6e 81 2f 02 04 01 ....tension./...
|
||||
| 1504: 02 04 01 02 04 01 04 66 69 6c 65 13 02 03 01 02 .......file.....
|
||||
| 1520: 03 01 02 03 02 05 6f 72 6d 61 74 13 02 04 01 02 ......ormat.....
|
||||
| 1536: 04 01 02 04 02 03 74 73 33 46 02 03 01 02 03 01 ......ts3F......
|
||||
| 1552: 02 03 01 02 03 01 02 03 01 02 03 04 01 34 4c 02 .............4L.
|
||||
| 1568: 03 01 02 03 01 02 03 04 01 35 4f 02 03 01 02 03 .........5O.....
|
||||
| 1584: 01 02 03 02 03 75 6e 63 5e 02 05 01 02 05 01 02 .....unc^.......
|
||||
| 1600: 05 05 04 74 69 6f 6e 73 02 05 01 02 05 01 02 05 ...tions........
|
||||
| 1616: 13 02 03 01 02 03 01 02 03 09 01 73 55 02 04 01 ...........sU...
|
||||
| 1632: 02 04 01 02 04 01 07 67 65 6f 70 6f 6c 79 52 02 .......geopolyR.
|
||||
| 1648: 03 01 02 03 01 02 03 01 05 68 69 6e 74 73 3a 02 .........hints:.
|
||||
| 1664: 04 01 02 04 01 02 04 02 03 6f 6f 6b 61 02 04 01 .........ooka...
|
||||
| 1680: 02 04 01 02 04 01 02 69 6e 01 02 04 01 02 04 01 .......in.......
|
||||
| 1696: 02 04 03 04 69 74 73 7a 1f 02 04 01 02 04 01 02 ....itsz........
|
||||
| 1712: 04 03 08 74 72 69 6e 73 69 63 73 04 02 03 01 02 ...trinsics.....
|
||||
| 1728: 03 01 02 03 01 07 6a 6f 75 72 6e 61 6c 16 02 03 ......journal...
|
||||
| 1744: 01 02 03 01 02 03 01 06 6c 65 6e 67 74 68 81 0b ........length..
|
||||
| 1760: 02 03 01 02 03 01 02 03 01 02 05 01 02 05 01 02 ................
|
||||
| 1776: 05 0d 02 04 01 02 04 01 02 04 02 03 69 6b 65 81 ............ike.
|
||||
| 1792: 0e 02 03 01 02 03 01 02 03 03 03 6d 69 74 16 02 ...........mit..
|
||||
| 1808: 05 01 02 05 01 02 05 5e 02 04 01 02 04 01 02 04 .......^........
|
||||
| 1824: 02 03 6f 61 64 81 2f 02 03 01 02 03 01 02 03 01 ..oad./.........
|
||||
| 1840: 06 6d 61 6c 6c 6f 63 76 02 02 01 02 02 01 02 02 .mallocv........
|
||||
| 1856: 3a 02 03 01 02 03 01 02 03 03 02 74 68 55 02 03 :..........thU..
|
||||
| 1872: 01 02 03 01 02 03 03 01 78 79 02 02 01 02 02 01 ........xy......
|
||||
| 1888: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1904: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1920: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1936: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 1952: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 1968: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 1984: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 ................
|
||||
| 2000: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 ................
|
||||
| 2016: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 ................
|
||||
| 2032: 02 02 02 05 65 6d 6f 72 79 81 11 02 03 01 02 03 ....emory.......
|
||||
| 2048: 01 02 03 04 04 73 79 73 35 58 02 03 01 02 03 01 .....sys5X......
|
||||
| 2064: 02 03 02 03 6d 61 70 19 02 03 01 02 03 01 02 03 ....map.........
|
||||
| 2080: 79 02 03 01 02 03 01 02 03 02 04 75 74 65 78 81 y..........utex.
|
||||
| 2096: 2c 02 02 01 02 02 01 02 02 01 06 6e 6f 63 61 73 ,..........nocas
|
||||
| 2112: 65 02 06 01 02 02 03 06 01 02 02 03 06 01 02 02 e...............
|
||||
| 2128: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2144: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2160: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2176: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 2192: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2208: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2224: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2240: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2256: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 2272: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2288: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2304: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2320: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2336: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 2352: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2368: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2384: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2400: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2416: 02 02 03 06 01 02 02 03 07 72 6d 61 6c 69 7a 65 .........rmalize
|
||||
| 2432: 5b 02 03 01 02 03 01 02 03 02 05 75 6d 62 65 72 [..........umber
|
||||
| 2448: 81 23 02 04 01 02 04 01 02 04 01 06 6f 66 66 73 .#..........offs
|
||||
| 2464: 65 74 5e 02 03 01 02 03 01 02 03 02 03 6d 69 74 et^..........mit
|
||||
| 2480: 81 2c 02 03 01 02 03 01 02 03 01 02 02 01 02 02 .,..............
|
||||
| 2496: 01 02 02 02 01 70 81 26 02 04 01 02 04 01 02 04 .....p.&........
|
||||
| 2512: 02 07 76 65 72 66 6c 6f 77 34 02 03 01 02 03 01 ..verflow4......
|
||||
| 2528: 02 03 01 04 70 61 67 65 1c 02 03 01 02 03 01 02 ....page........
|
||||
| 2544: 03 64 02 04 01 02 04 01 02 04 13 02 03 01 02 03 .d..............
|
||||
| 2560: 01 02 03 01 02 03 01 02 03 01 02 03 03 09 72 65 ..............re
|
||||
| 2576: 6e 74 68 65 73 69 73 49 02 04 01 02 04 01 02 04 nthesisI........
|
||||
| 2592: 03 05 74 74 65 72 6e 81 0e 02 04 01 02 04 01 02 ..ttern.........
|
||||
| 2608: 04 02 05 63 61 63 68 65 1f 02 03 01 02 03 01 02 ...cache........
|
||||
| 2624: 03 02 08 72 65 75 70 64 61 74 65 61 02 03 01 02 ...reupdatea....
|
||||
| 2640: 03 01 02 03 01 04 72 65 61 64 34 02 04 01 02 04 ......read4.....
|
||||
| 2656: 01 02 04 03 07 63 75 72 73 69 76 65 22 02 03 01 .....cursive....
|
||||
| 2672: 02 03 01 02 03 02 04 6f 77 69 64 01 02 03 01 02 .......owid.....
|
||||
| 2688: 03 01 02 03 02 04 74 72 65 65 64 02 03 01 02 03 ......treed.....
|
||||
| 2704: 01 02 03 04 02 69 6d 01 06 01 02 02 03 06 01 02 .....im.........
|
||||
| 2720: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2736: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2752: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2768: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2784: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 2800: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2816: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2832: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2848: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2864: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 2880: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2896: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2912: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 2928: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 ................
|
||||
| 2944: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 ................
|
||||
| 2960: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 ................
|
||||
| 2976: 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 ................
|
||||
| 2992: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 ................
|
||||
| 3008: 01 02 02 03 06 01 02 02 03 06 01 02 02 01 0a 73 ...............s
|
||||
| 3024: 63 61 6e 73 74 61 74 75 73 70 02 04 01 02 04 01 canstatusp......
|
||||
| 3040: 02 04 02 05 65 63 74 6f 72 25 02 03 01 02 03 01 ....ector%......
|
||||
| 3056: 02 03 03 04 6c 65 63 74 7f 02 04 01 02 04 01 02 ....lect........
|
||||
| 3072: 04 03 05 73 73 69 6f 6e 67 02 03 01 02 03 01 02 ...ssiong.......
|
||||
| 3088: 03 02 03 69 7a 65 10 02 04 01 02 04 01 02 04 04 ...ize..........
|
||||
| 3104: 02 04 01 02 04 01 02 04 01 02 04 01 02 04 01 02 ................
|
||||
| 3120: 04 01 02 04 01 02 04 01 02 04 07 02 04 01 02 04 ................
|
||||
| 3136: 01 02 04 5b 02 05 01 02 05 01 02 05 10 02 04 01 ...[............
|
||||
| 3152: 02 04 01 02 04 04 02 04 01 02 04 01 02 04 02 03 ................
|
||||
| 3168: 6f 66 74 76 02 03 01 02 03 01 02 03 02 02 71 6c oftv..........ql
|
||||
| 3184: 5e 02 04 01 02 04 01 02 04 13 02 04 01 02 04 01 ^...............
|
||||
| 3200: 02 04 28 02 03 01 02 03 01 02 03 02 04 74 61 74 ..(..........tat
|
||||
| 3216: 34 6a 02 03 01 02 03 01 02 03 03 02 6d 74 70 02 4j..........mtp.
|
||||
| 3232: 03 01 02 03 01 02 03 05 04 76 74 61 62 6d 02 03 .........vtabm..
|
||||
| 3248: 01 02 03 01 02 03 03 03 6f 72 65 81 35 02 03 01 ........ore.5...
|
||||
| 3264: 02 03 01 02 03 02 0a 79 6e 63 68 72 6f 6e 6f 75 .......ynchronou
|
||||
| 3280: 73 28 02 03 01 02 03 01 02 03 04 02 04 01 02 04 s(..............
|
||||
| 3296: 01 02 04 03 04 73 74 65 6d 81 32 02 02 01 02 02 .....stem.2.....
|
||||
| 3312: 01 02 02 01 04 74 65 6d 70 81 35 02 02 01 02 02 .....temp.5.....
|
||||
| 3328: 01 02 02 02 06 68 72 65 61 64 73 31 02 04 01 02 .....hreads1....
|
||||
| 3344: 04 01 02 04 76 02 04 01 02 04 01 02 04 08 03 61 ....v..........a
|
||||
| 3360: 66 65 81 38 02 02 01 02 02 01 02 02 02 06 72 69 fe.8..........ri
|
||||
| 3376: 67 67 65 72 81 20 02 03 01 02 03 01 02 03 08 01 gger. ..........
|
||||
| 3392: 73 22 02 04 01 02 04 01 02 04 01 07 75 6e 6b 6e s...........unkn
|
||||
| 3408: 6f 77 6e 73 02 03 01 02 03 01 02 03 01 08 76 61 owns..........va
|
||||
| 3424: 72 69 61 62 6c 65 81 23 02 03 01 02 03 01 02 03 riable.#........
|
||||
| 3440: 02 03 64 62 65 81 26 02 03 01 02 03 01 02 03 02 ..dbe.&.........
|
||||
| 3456: 03 69 65 77 01 02 05 01 02 05 01 02 05 02 03 74 .iew...........t
|
||||
| 3472: 61 62 37 02 04 01 02 04 01 02 04 04 02 04 01 02 ab7.............
|
||||
| 3488: 04 01 02 04 01 02 04 01 02 04 01 02 04 01 03 77 ...............w
|
||||
| 3504: 61 6c 2b 02 03 01 02 03 01 02 03 01 02 03 01 02 al+.............
|
||||
| 3520: 03 01 02 03 02 05 6f 72 6b 65 72 31 02 03 01 02 ......orker1....
|
||||
| 3536: 03 01 02 03 76 02 03 01 02 03 01 02 03 01 01 78 ....v..........x
|
||||
| 3552: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3568: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3584: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3600: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3616: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3632: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3648: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3664: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3680: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3696: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3712: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3728: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3744: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3760: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3776: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3792: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3808: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3824: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3840: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3856: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3872: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3888: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3904: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3920: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3936: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3952: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3968: 06 01 01 02 01 06 04 30 15 1e 0c 28 1b 0d 0c 15 .......0...(....
|
||||
| 3984: 0c 16 14 16 10 0c 17 0e 0e 0f 11 10 10 0e 10 11 ................
|
||||
| 4000: 18 11 82 3e 12 10 0f 10 11 10 0f 0f 10 11 0f 0f ...>............
|
||||
| 4016: 81 05 18 10 81 45 11 0d 13 0f 10 17 0c 0c 0e 18 .....E..........
|
||||
| 4032: 0c 12 10 0e 0d 0f 13 12 24 0f 17 0f 1a 0d 81 1c ........$.......
|
||||
| 4048: 11 0f 17 10 82 3e 12 11 11 18 0d 12 2a 14 11 10 .....>......*...
|
||||
| 4064: 13 0f 12 0f 0f 82 3a 15 10 0f 10 4d 0e 1f 0f 0d ......:....M....
|
||||
| 4080: 0f 0f 1e 10 10 1a 0f 12 0c 12 14 0f 0e 20 17 19 ............. ..
|
||||
| page 12 offset 45056
|
||||
| 0: 0d 00 00 00 01 0d f4 00 0d f4 00 00 00 00 00 00 ................
|
||||
| 3568: 00 00 00 00 84 04 84 80 80 80 80 02 04 00 88 0c ................
|
||||
| 3584: 00 07 02 00 01 01 02 56 06 01 01 02 01 06 01 01 .......V........
|
||||
| 3600: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3616: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3632: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3648: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3664: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3680: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3696: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3712: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3728: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3744: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3760: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3776: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3792: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3808: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3824: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3840: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3856: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3872: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3888: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3904: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 3920: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 3936: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 3952: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 3968: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 ................
|
||||
| 3984: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 4000: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| 4016: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 ................
|
||||
| 4032: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 ................
|
||||
| 4048: 52 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 R...............
|
||||
| 4064: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 ................
|
||||
| 4080: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 ................
|
||||
| end c1a.txt.db
|
||||
}]} {}
|
||||
|
||||
do_catchsql_test 84.1 {
|
||||
SELECT * FROM t1('R*R*x') ORDER BY rowid DESC;
|
||||
} {1 {fts5: corruption found reading blob 137438953475 from table "t1"}}
|
||||
|
||||
sqlite3_fts5_may_be_corrupt 0
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -90,5 +90,58 @@ do_execsql_test 3.7 {
|
||||
SELECT * FROM sqlite_schema
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
proc hex_to_blob {hex} {
|
||||
binary encode hex $hex
|
||||
}
|
||||
db func hex_to_blob hex_to_blob
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(x, content='', contentless_delete=1);
|
||||
BEGIN;
|
||||
INSERT INTO x1(rowid, x) VALUES(1, 'a b c d e f g h');
|
||||
INSERT INTO x1(rowid, x) VALUES(2, 'a b c d e f g h');
|
||||
COMMIT;
|
||||
DELETE FROM x1 WHERE rowid=1;
|
||||
}
|
||||
|
||||
do_execsql_test 4.1 {
|
||||
SELECT hex(block) FROM x1_data WHERE id=10
|
||||
} {
|
||||
00000000FF00000101010200010101010101010102
|
||||
}
|
||||
|
||||
do_execsql_test 4.2.1 {
|
||||
UPDATE x1_data SET block=
|
||||
X'00000000FF00000101010200010101010101819C9B95A8000102'
|
||||
WHERE id=10;
|
||||
}
|
||||
|
||||
do_catchsql_test 4.2.2 {
|
||||
SELECT * FROM x1('c d e');
|
||||
} {1 {out of memory}}
|
||||
|
||||
do_execsql_test 4.3.1 {
|
||||
UPDATE x1_data SET block=
|
||||
X'00000000FF000001010102000101010101019282AFF9A0000102'
|
||||
WHERE id=10;
|
||||
}
|
||||
|
||||
do_catchsql_test 4.3.2 {
|
||||
SELECT * FROM x1('c d e');
|
||||
} {1 {out of memory}}
|
||||
|
||||
do_execsql_test 4.4.1 {
|
||||
UPDATE x1_data SET block=
|
||||
X'00000000FF000001010102000101010101018181808080130102'
|
||||
WHERE id=10;
|
||||
}
|
||||
|
||||
do_catchsql_test 4.3.2 {
|
||||
SELECT * FROM x1('c d e');
|
||||
} {1 {out of memory}}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# 2025 October 13
|
||||
#
|
||||
# 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 test is focused on really large position lists. Those that require
|
||||
# 4 or 5 byte position-list size varints. Because of the amount of memory
|
||||
# required, these tests only run on 64-bit platforms.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5corruptbig
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
if { $tcl_platform(wordSize)<8 } {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
if { $SQLITE_MAX_LENGTH!=0x7FFFFFFF } {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
UPDATE t1_data SET block = zeroblob(2147483640) WHERE id=10;
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT id, length(block) FROM t1_data
|
||||
} {1 0 10 2147483640}
|
||||
|
||||
do_catchsql_test 1.3 {
|
||||
SELECT * FROM t1('abc')
|
||||
} {1 {out of memory}}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -37,6 +37,12 @@ do_execsql_test 2.1 {
|
||||
INSERT INTO yy(yy) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 2.1 {
|
||||
INSERT INTO yy(yy) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
do_execsql_test 3.0 {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# 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 fts5join
|
||||
|
||||
# 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, b TIMESTAMP);
|
||||
INSERT INTO t1 VALUES(1, 1), (2, 2);
|
||||
CREATE INDEX i1 ON t1(b);
|
||||
}
|
||||
|
||||
# set sqlite_where_trace [expr 0xFFF]
|
||||
|
||||
do_eqp_test 1.1 {
|
||||
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid ORDER BY t1.rowid;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN t1
|
||||
`--SCAN vt VIRTUAL TABLE INDEX 0:=
|
||||
}
|
||||
|
||||
do_eqp_test 1.2 {
|
||||
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid AND b>? ORDER BY b LIMIT 10
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SEARCH t1 USING COVERING INDEX i1 (b>?)
|
||||
`--SCAN vt VIRTUAL TABLE INDEX 0:=
|
||||
}
|
||||
|
||||
do_eqp_test 1.3 {
|
||||
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid AND b>?
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SEARCH t1 USING COVERING INDEX i1 (b>?)
|
||||
`--SCAN vt VIRTUAL TABLE INDEX 0:=
|
||||
}
|
||||
|
||||
do_eqp_test 1.4 {
|
||||
SELECT * FROM vt, t1 WHERE vt.rowid = t1.rowid ORDER BY b
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN t1 USING COVERING INDEX i1
|
||||
`--SCAN vt VIRTUAL TABLE INDEX 0:=
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -40,4 +40,53 @@ do_execsql_test 1.2 {
|
||||
SELECT * FROM t1 LEFT JOIN vt ON (vt MATCH 'abc')
|
||||
} {1 abc 2 abc}
|
||||
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
DELETE FROM t1;
|
||||
INSERT INTO t1 VALUES(14);
|
||||
}
|
||||
|
||||
do_execsql_test 1.4 {
|
||||
SELECT * FROM vt LEFT JOIN t1 ON vt.rowid = 1;
|
||||
} {
|
||||
abc 14
|
||||
xyz {}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE t0 USING fts5(a,b);
|
||||
INSERT INTO t0(a,b)VALUES(1,0);
|
||||
CREATE TABLE t1(x);
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
SELECT * FROM t0 LEFT JOIN t1;
|
||||
} {1 0 {}}
|
||||
|
||||
breakpoint
|
||||
do_catchsql_test 2.2 {
|
||||
SELECT * FROM t0 LEFT JOIN t1 ON t0.b MATCH '1';
|
||||
} {1 {no query solution}}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
SELECT * FROM t0 LEFT JOIN t1 ON +b MATCH '1';
|
||||
} {1 0 {}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE t0 USING fts5(c0, c1);
|
||||
INSERT INTO t0(c0,c1) VALUES (1,0);
|
||||
}
|
||||
|
||||
do_catchsql_test 3.1 {
|
||||
SELECT * FROM t0
|
||||
LEFT JOIN ( SELECT 0 AS col_0 )
|
||||
ON ((((t0.c1 MATCH '1')AND(CASE WHEN t0.c0 THEN CAST(t0.c1 AS INTEGER) ELSE 1 END))));
|
||||
} {1 {no query solution}}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -238,6 +238,22 @@ do_execsql_test 6.3 {
|
||||
INSERT INTO g1(g1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Check that passing -2147483648 as the parameter to a merge command
|
||||
# does not cause a signed integer overflow error.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 7.0 {
|
||||
CREATE VIRTUAL TABLE f1 USING fts5(a);
|
||||
}
|
||||
do_execsql_test 7.1 {
|
||||
INSERT INTO f1 VALUES('one two three');
|
||||
INSERT INTO f1 VALUES('four five six');
|
||||
INSERT INTO f1 VALUES('seven eight nine');
|
||||
}
|
||||
do_execsql_test 7.2 {
|
||||
INSERT INTO f1(f1, rank) VALUES('merge', -2147483648);
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -685,5 +685,17 @@ do_execsql_test 26.1 {
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
do_execsql_test 27.0 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts5(a, b);
|
||||
INSERT INTO ft1(rowid, a, b) VALUES(3, '3', '3');
|
||||
}
|
||||
|
||||
do_execsql_test 27.1 {
|
||||
SELECT * FROM ft1 WHERE rowid=3 AND b MATCH 'hello';
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -38,15 +38,15 @@ foreach {tn sql uses} {
|
||||
1.2 { DELETE FROM ft WHERE rowid=? } 0
|
||||
1.3 { DELETE FROM ft WHERE rowid=? } 0
|
||||
1.4 { DELETE FROM ft WHERE ft MATCH '1' } 1
|
||||
1.5 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 1
|
||||
1.6 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 1
|
||||
1.5 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 0
|
||||
1.6 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 0
|
||||
|
||||
2.1 { UPDATE ft SET content='a b c' } 1
|
||||
2.2 { UPDATE ft SET content='a b c' WHERE rowid=? } 0
|
||||
2.3 { UPDATE ft SET content='a b c' WHERE rowid=? } 0
|
||||
2.4 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' } 1
|
||||
2.5 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 1
|
||||
2.6 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 1
|
||||
2.5 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 0
|
||||
2.6 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 0
|
||||
} {
|
||||
do_test 1.$tn { sql_uses_stmt db $sql } $uses
|
||||
}
|
||||
|
||||
@@ -305,6 +305,28 @@ do_catchsql_test 6.2 {
|
||||
|
||||
sqlite3_fts5_may_be_corrupt 0
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 7.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(a, b);
|
||||
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, col);
|
||||
|
||||
INSERT INTO t1 VALUES('xx', 'xx');
|
||||
|
||||
CREATE TABLE x1(t);
|
||||
INSERT INTO x1 VALUES('xx');
|
||||
INSERT INTO x1 VALUES('xx');
|
||||
|
||||
SELECT term, col FROM v1;
|
||||
} {
|
||||
xx a xx b
|
||||
}
|
||||
|
||||
do_execsql_test 7.1 {
|
||||
SELECT * FROM x1 WHERE 'a'=(SELECT col FROM v1 WHERE term=t)
|
||||
} {xx xx}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ do_test 2.3 {
|
||||
sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
|
||||
|
||||
db eval {
|
||||
PRAGMA writable_schema=on;
|
||||
DELETE FROM imp1 WHERE rowid=1;
|
||||
DELETE FROM imp2 WHERE rowid=2;
|
||||
}
|
||||
@@ -174,6 +175,7 @@ do_test 3.2 {
|
||||
sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
|
||||
|
||||
db eval {
|
||||
PRAGMA writable_schema=on;
|
||||
DELETE FROM imp1 WHERE a=5;
|
||||
}
|
||||
execsql_pp {
|
||||
|
||||
@@ -29,6 +29,7 @@ do_execsql_test 1.0 {
|
||||
proc imposter_edit {obj create sql} {
|
||||
sqlite3 xdb test.db
|
||||
set pgno [xdb one {SELECT rootpage FROM sqlite_schema WHERE name=$obj}]
|
||||
xdb eval {PRAGMA Writable_schema=ON}
|
||||
|
||||
sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER xdb main 1 $pgno
|
||||
xdb eval $create
|
||||
|
||||
@@ -160,6 +160,7 @@ static char *intckMprintf(sqlite3_intck *p, const char *zFmt, ...){
|
||||
sqlite3_free(zRet);
|
||||
zRet = 0;
|
||||
}
|
||||
va_end(ap);
|
||||
return zRet;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,10 @@
|
||||
** Creates a verbose JNI function name. Suffix must be
|
||||
** the JNI-mangled form of the function's name, minus the
|
||||
** prefix seen in this macro.
|
||||
**
|
||||
** If you get java.lang.UnsatisfiedLinkError when calling newly-added
|
||||
** native bindings, be sure that the mangled name is correct. It can
|
||||
** be found in the generated sqlite3-jni.h.
|
||||
*/
|
||||
#define JniFuncName(Suffix) \
|
||||
Java_org_sqlite_jni_capi_CApi_sqlite3_ ## Suffix
|
||||
@@ -177,10 +181,10 @@
|
||||
JNIEXPORT ReturnType JNICALL JniFuncName(Suffix)
|
||||
|
||||
/*
|
||||
** S3JniApi's intent is that CFunc be the C API func(s) the
|
||||
** being-declared JNI function is wrapping, making it easier to find
|
||||
** that function's JNI-side entry point. The other args are for JniDecl.
|
||||
** See the many examples in this file.
|
||||
** S3JniApi's intent is that CFunc be the name(s) of the C API func(s)
|
||||
** the being-declared JNI function is wrapping, making it easier to
|
||||
** find those bindings' JNI-side entry points. The other args are for
|
||||
** JniDecl. See the many examples in this file.
|
||||
*/
|
||||
#define S3JniApi(CFunc,ReturnType,Suffix) JniDecl(ReturnType,Suffix)
|
||||
|
||||
@@ -3856,6 +3860,19 @@ S3JniApi(sqlite3_errmsg(),jstring,1errmsg)(
|
||||
effect should be identical to using errmsg16(), however. */;
|
||||
}
|
||||
|
||||
S3JniApi(sqlite3_set_errmsg(),jint,1set_1errmsg)(
|
||||
JniArgsEnvClass, jobject jpDb, jint errCode, jstring msg
|
||||
){
|
||||
sqlite3 * const pDb = PtrGet_sqlite3(jpDb);
|
||||
const char *zUtf8;
|
||||
jint rc;
|
||||
if( !pDb ) return SQLITE_MISUSE;
|
||||
zUtf8 = msg ? s3jni_jstring_to_mutf8(msg) : NULL;
|
||||
rc = sqlite3_set_errmsg(pDb, (int)errCode, zUtf8);
|
||||
s3jni_mutf8_release(msg, zUtf8);
|
||||
return rc;
|
||||
}
|
||||
|
||||
S3JniApi(sqlite3_errstr(),jstring,1errstr)(
|
||||
JniArgsEnvClass, jint rcCode
|
||||
){
|
||||
|
||||
@@ -1342,7 +1342,7 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1data_1count
|
||||
* Method: sqlite3_db_config
|
||||
* Signature: (Lorg/sqlite/jni/capi/sqlite3;IILorg/sqlite/jni/capi/OutputPointer/Int32;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1db_1config__Lorg_sqlite_jni_capi_sqlite3_2IILorg_sqlite_jni_capi_OutputPointer_00024Int32_2
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1db_1config__Lorg_sqlite_jni_capi_sqlite3_2IILorg_sqlite_jni_capi_OutputPointer_Int32_2
|
||||
(JNIEnv *, jclass, jobject, jint, jint, jobject);
|
||||
|
||||
/*
|
||||
@@ -1417,6 +1417,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1errcode
|
||||
JNIEXPORT jstring JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1errmsg
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_capi_CApi
|
||||
* Method: sqlite3_set_errmsg
|
||||
* Signature: (Lorg/sqlite/jni/capi/sqlite3;ILjava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_capi_CApi_sqlite3_1set_1errmsg
|
||||
(JNIEnv *, jclass, jobject, jint, jstring);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_capi_CApi
|
||||
* Method: sqlite3_error_offset
|
||||
|
||||
@@ -1197,10 +1197,15 @@ public final class CApi {
|
||||
|
||||
public static native String sqlite3_errmsg(@NotNull sqlite3 db);
|
||||
|
||||
/** Added in 3.51.0. */
|
||||
public static native int sqlite3_set_errmsg(@NotNull sqlite3 db,
|
||||
int resultCode,
|
||||
String msg);
|
||||
|
||||
private static native int sqlite3_error_offset(@NotNull long ptrToDb);
|
||||
|
||||
/**
|
||||
Note that the returned byte offset values assume UTF-8-encoded
|
||||
Caveat: the returned byte offset values assume UTF-8-encoded
|
||||
inputs, so won't always match character offsets in Java Strings.
|
||||
*/
|
||||
public static int sqlite3_error_offset(@NotNull sqlite3 db){
|
||||
|
||||
@@ -1874,6 +1874,20 @@ public class Tester1 implements Runnable {
|
||||
sqlite3_close_v2(db);
|
||||
}
|
||||
|
||||
private void testSetErrmsg(){
|
||||
final sqlite3 db = createNewDb();
|
||||
|
||||
int rc = sqlite3_set_errmsg(db, SQLITE_RANGE, "nope");
|
||||
affirm( 0==rc );
|
||||
affirm( SQLITE_MISUSE == sqlite3_set_errmsg(null, 0, null) );
|
||||
affirm( "nope".equals(sqlite3_errmsg(db)) );
|
||||
affirm( SQLITE_RANGE == sqlite3_errcode(db) );
|
||||
rc = sqlite3_set_errmsg(db, 0, null);
|
||||
affirm( "not an error".equals(sqlite3_errmsg(db)) );
|
||||
affirm( 0 == sqlite3_errcode(db) );
|
||||
sqlite3_close_v2(db);
|
||||
}
|
||||
|
||||
/* Copy/paste/rename this to add new tests. */
|
||||
private void _testTemplate(){
|
||||
final sqlite3 db = createNewDb();
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#
|
||||
# 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/
|
||||
# LSMOPTS=-fPIC
|
||||
# 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 += -fPIC -DLSM_MUTEX_PTHREADS=1 -I$(LSMDIR) -DHAVE_ZLIB
|
||||
|
||||
lsm.so: $(LSMOBJ)
|
||||
$(T.link) -shared -fPIC -o lsm.so $(LSMOBJ)
|
||||
|
||||
%.o: $(LSMDIR)/%.c $(LSMHDR) sqlite3.h
|
||||
$(T.link) $(LSMOPTS) -c $<
|
||||
|
||||
lsmtest$(EXE): $(LSMOBJ) $(LSMTESTSRC) $(LSMTESTHDR) sqlite3.o
|
||||
# $(T.link) -c $(TOP)/lsm-test/lsmtest_tdb2.cc
|
||||
$(T.link) $(LSMOPTS) $(LSMTESTSRC) $(LSMOBJ) sqlite3.o -o lsmtest$(EXE) $(THREADLIB) -lz
|
||||
@@ -1,102 +0,0 @@
|
||||
#
|
||||
# This Makefile is designed for use with Makefile.msc in the root directory
|
||||
# of this project. The Makefile.msc 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 lsmtest.exe
|
||||
|
||||
LSMOPTS = $(NO_WARN) -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)
|
||||
copy /Y $@ $(LSMDIR)\$@
|
||||
|
||||
lsmtest.exe: $(LSMOBJ) $(LSMTESTSRC) $(LSMTESTHDR) $(LIBOBJ)
|
||||
$(LTLINK) $(LSMOPTS) $(LSMTESTSRC) /link $(LSMOBJ) $(LIBOBJ)
|
||||
copy /Y $@ $(LSMDIR)\$@
|
||||
@@ -1,40 +0,0 @@
|
||||
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,303 +0,0 @@
|
||||
|
||||
#ifndef __WRAPPER_INT_H_
|
||||
#define __WRAPPER_INT_H_
|
||||
|
||||
#include "lsmtest_tdb.h"
|
||||
#include "sqlite3.h"
|
||||
#include "lsm.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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
|
||||
|
||||
#ifndef _O_BINARY
|
||||
# define _O_BINARY (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** 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_lomem2_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
|
||||
@@ -1,656 +0,0 @@
|
||||
|
||||
#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;
|
||||
int iToggle = 0;
|
||||
|
||||
/* 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;
|
||||
|
||||
if( iToggle ) testBegin(pDb, 1, &rc);
|
||||
/* Check that the db content is correct. */
|
||||
testDbContents(pDb, pData, p->nRow, 0, i-1, p->nTest, p->bTestScan, &rc);
|
||||
if( iToggle ) testCommit(pDb, 0, &rc);
|
||||
iToggle = (iToggle+1)%2;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,488 +0,0 @@
|
||||
|
||||
/*
|
||||
** 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
|
||||
|
||||
/*
|
||||
** 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
|
||||
/*
|
||||
** 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,633 +0,0 @@
|
||||
|
||||
/*
|
||||
** 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);
|
||||
}
|
||||
@@ -1,661 +0,0 @@
|
||||
|
||||
#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 *) = 0;
|
||||
|
||||
|
||||
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"
|
||||
|
||||
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(void){
|
||||
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(void){
|
||||
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(void){
|
||||
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);
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
|
||||
/*
|
||||
** Test that the rules for when lsm_csr_next() and lsm_csr_prev() are
|
||||
** enforced. Specifically:
|
||||
**
|
||||
** * Both functions always return LSM_MISUSE if the cursor is at EOF
|
||||
** when they are called.
|
||||
**
|
||||
** * lsm_csr_next() may only be used after lsm_csr_seek(LSM_SEEK_GE) or
|
||||
** lsm_csr_first().
|
||||
**
|
||||
** * lsm_csr_prev() may only be used after lsm_csr_seek(LSM_SEEK_LE) or
|
||||
** lsm_csr_last().
|
||||
*/
|
||||
static void do_test_api1_lsm(lsm_db *pDb, int *pRc){
|
||||
int ret;
|
||||
lsm_cursor *pCsr;
|
||||
lsm_cursor *pCsr2;
|
||||
int nKey;
|
||||
const void *pKey;
|
||||
|
||||
ret = lsm_csr_open(pDb, &pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
ret = lsm_csr_seek(pCsr, "jjj", 3, LSM_SEEK_GE);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
ret = lsm_csr_seek(pCsr, "jjj", 3, LSM_SEEK_LE);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
|
||||
ret = lsm_csr_seek(pCsr, "jjj", 3, LSM_SEEK_LEFAST);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
ret = lsm_csr_key(pCsr, &pKey, &nKey);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
|
||||
ret = lsm_csr_open(pDb, &pCsr2);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
|
||||
ret = lsm_csr_seek(pCsr2, pKey, nKey, LSM_SEEK_EQ);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
testCompareInt(1, lsm_csr_valid(pCsr2), pRc);
|
||||
ret = lsm_csr_next(pCsr2);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr2);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
lsm_csr_close(pCsr2);
|
||||
|
||||
ret = lsm_csr_first(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
ret = lsm_csr_last(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
ret = lsm_csr_first(pCsr);
|
||||
while( lsm_csr_valid(pCsr) ){
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
}
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
ret = lsm_csr_last(pCsr);
|
||||
while( lsm_csr_valid(pCsr) ){
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
}
|
||||
ret = lsm_csr_prev(pCsr);
|
||||
testCompareInt(LSM_OK, ret, pRc);
|
||||
ret = lsm_csr_next(pCsr);
|
||||
testCompareInt(LSM_MISUSE, ret, pRc);
|
||||
|
||||
lsm_csr_close(pCsr);
|
||||
}
|
||||
|
||||
static void do_test_api1(const char *zPattern, int *pRc){
|
||||
if( testCaseBegin(pRc, zPattern, "api1.lsm") ){
|
||||
const DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 200, 250 };
|
||||
Datasource *pData;
|
||||
TestDb *pDb;
|
||||
int rc = 0;
|
||||
|
||||
pDb = testOpen("lsm_lomem", 1, &rc);
|
||||
pData = testDatasourceNew(&defn);
|
||||
testWriteDatasourceRange(pDb, pData, 0, 1000, pRc);
|
||||
|
||||
do_test_api1_lsm(tdb_lsm(pDb), pRc);
|
||||
|
||||
testDatasourceFree(pData);
|
||||
testClose(&pDb);
|
||||
|
||||
testCaseFinish(*pRc);
|
||||
}
|
||||
}
|
||||
|
||||
static lsm_db *newLsmConnection(
|
||||
const char *zDb,
|
||||
int nPgsz,
|
||||
int nBlksz,
|
||||
int *pRc
|
||||
){
|
||||
lsm_db *db = 0;
|
||||
if( *pRc==0 ){
|
||||
int n1 = nPgsz;
|
||||
int n2 = nBlksz;
|
||||
*pRc = lsm_new(tdb_lsm_env(), &db);
|
||||
if( *pRc==0 ){
|
||||
if( n1 ) lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1);
|
||||
if( n2 ) lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2);
|
||||
*pRc = lsm_open(db, "testdb.lsm");
|
||||
}
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
static void testPagesize(lsm_db *db, int nPgsz, int nBlksz, int *pRc){
|
||||
if( *pRc==0 ){
|
||||
int n1 = 0;
|
||||
int n2 = 0;
|
||||
|
||||
lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1);
|
||||
lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2);
|
||||
|
||||
testCompareInt(n1, nPgsz, pRc);
|
||||
testCompareInt(n2, nBlksz, pRc);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Test case "api2" tests that the default page and block sizes of a
|
||||
** database may only be modified before lsm_open() is called. And that
|
||||
** after lsm_open() is called lsm_config() may be used to read the
|
||||
** actual page and block size of the db.
|
||||
*/
|
||||
static void do_test_api2(const char *zPattern, int *pRc){
|
||||
if( *pRc==0 && testCaseBegin(pRc, zPattern, "api2.lsm") ){
|
||||
lsm_db *db1 = 0;
|
||||
lsm_db *db2 = 0;
|
||||
|
||||
testDeleteLsmdb("testdb.lsm");
|
||||
db1 = newLsmConnection("testdb.lsm", 0, 0, pRc);
|
||||
testPagesize(db1, 4096, 1024, pRc);
|
||||
db2 = newLsmConnection("testdb.lsm", 1024, 64*1024, pRc);
|
||||
testPagesize(db2, 4096, 1024, pRc);
|
||||
lsm_close(db1);
|
||||
lsm_close(db2);
|
||||
|
||||
testDeleteLsmdb("testdb.lsm");
|
||||
db1 = newLsmConnection("testdb.lsm", 1024, 64*1024, pRc);
|
||||
testPagesize(db1, 1024, 64*1024, pRc);
|
||||
db2 = newLsmConnection("testdb.lsm", 0, 0, pRc);
|
||||
testPagesize(db2, 1024, 64*1024, pRc);
|
||||
lsm_close(db1);
|
||||
lsm_close(db2);
|
||||
|
||||
testDeleteLsmdb("testdb.lsm");
|
||||
db1 = newLsmConnection("testdb.lsm", 8192, 2*1024, pRc);
|
||||
testPagesize(db1, 8192, 2*1024, pRc);
|
||||
db2 = newLsmConnection("testdb.lsm", 1024, 64*1024, pRc);
|
||||
testPagesize(db2, 8192, 2*1024, pRc);
|
||||
lsm_close(db1);
|
||||
lsm_close(db2);
|
||||
|
||||
testCaseFinish(*pRc);
|
||||
}
|
||||
}
|
||||
|
||||
void test_api(
|
||||
const char *zPattern, /* Run test cases that match this pattern */
|
||||
int *pRc /* IN/OUT: Error code */
|
||||
){
|
||||
do_test_api1(zPattern, pRc);
|
||||
do_test_api2(zPattern, pRc);
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
|
||||
/*
|
||||
** This file contains test cases to verify that "live-recovery" following
|
||||
** a mid-transaction failure of a writer process.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** This test file includes lsmInt.h to get access to the definition of the
|
||||
** ShmHeader structure. This is required to cause strategic damage to the
|
||||
** shared memory header as part of recovery testing.
|
||||
*/
|
||||
#include "lsmInt.h"
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
typedef struct SetupStep SetupStep;
|
||||
struct SetupStep {
|
||||
int bFlush; /* Flush to disk and checkpoint */
|
||||
int iInsStart; /* First key-value from ds to insert */
|
||||
int nIns; /* Number of rows to insert */
|
||||
int iDelStart; /* First key from ds to delete */
|
||||
int nDel; /* Number of rows to delete */
|
||||
};
|
||||
|
||||
static void doSetupStep(
|
||||
TestDb *pDb,
|
||||
Datasource *pData,
|
||||
const SetupStep *pStep,
|
||||
int *pRc
|
||||
){
|
||||
testWriteDatasourceRange(pDb, pData, pStep->iInsStart, pStep->nIns, pRc);
|
||||
testDeleteDatasourceRange(pDb, pData, pStep->iDelStart, pStep->nDel, pRc);
|
||||
if( *pRc==0 ){
|
||||
int nSave = -1;
|
||||
int nBuf = 64;
|
||||
lsm_db *db = tdb_lsm(pDb);
|
||||
|
||||
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nSave);
|
||||
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nBuf);
|
||||
lsm_begin(db, 1);
|
||||
lsm_commit(db, 0);
|
||||
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nSave);
|
||||
|
||||
*pRc = lsm_work(db, 0, 0, 0);
|
||||
if( *pRc==0 ){
|
||||
*pRc = lsm_checkpoint(db, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void doSetupStepArray(
|
||||
TestDb *pDb,
|
||||
Datasource *pData,
|
||||
const SetupStep *aStep,
|
||||
int nStep
|
||||
){
|
||||
int i;
|
||||
for(i=0; i<nStep; i++){
|
||||
int rc = 0;
|
||||
doSetupStep(pDb, pData, &aStep[i], &rc);
|
||||
assert( rc==0 );
|
||||
}
|
||||
}
|
||||
|
||||
static void setupDatabase1(TestDb *pDb, Datasource **ppData){
|
||||
const SetupStep aStep[] = {
|
||||
{ 0, 1, 2000, 0, 0 },
|
||||
{ 1, 0, 0, 0, 0 },
|
||||
{ 0, 10001, 1000, 0, 0 },
|
||||
};
|
||||
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 12, 16, 100, 500};
|
||||
Datasource *pData;
|
||||
|
||||
pData = testDatasourceNew(&defn);
|
||||
doSetupStepArray(pDb, pData, aStep, ArraySize(aStep));
|
||||
if( ppData ){
|
||||
*ppData = pData;
|
||||
}else{
|
||||
testDatasourceFree(pData);
|
||||
}
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
void testReadFile(const char *zFile, int iOff, void *pOut, int nByte, int *pRc){
|
||||
if( *pRc==0 ){
|
||||
FILE *fd;
|
||||
fd = fopen(zFile, "rb");
|
||||
if( fd==0 ){
|
||||
*pRc = 1;
|
||||
}else{
|
||||
if( 0!=fseek(fd, iOff, SEEK_SET) ){
|
||||
*pRc = 1;
|
||||
}else{
|
||||
assert( nByte>=0 );
|
||||
if( (size_t)nByte!=fread(pOut, 1, nByte, fd) ){
|
||||
*pRc = 1;
|
||||
}
|
||||
}
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testWriteFile(
|
||||
const char *zFile,
|
||||
int iOff,
|
||||
void *pOut,
|
||||
int nByte,
|
||||
int *pRc
|
||||
){
|
||||
if( *pRc==0 ){
|
||||
FILE *fd;
|
||||
fd = fopen(zFile, "r+b");
|
||||
if( fd==0 ){
|
||||
*pRc = 1;
|
||||
}else{
|
||||
if( 0!=fseek(fd, iOff, SEEK_SET) ){
|
||||
*pRc = 1;
|
||||
}else{
|
||||
assert( nByte>=0 );
|
||||
if( (size_t)nByte!=fwrite(pOut, 1, nByte, fd) ){
|
||||
*pRc = 1;
|
||||
}
|
||||
}
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ShmHeader *getShmHeader(const char *zDb){
|
||||
int rc = 0;
|
||||
char *zShm = testMallocPrintf("%s-shm", zDb);
|
||||
ShmHeader *pHdr;
|
||||
|
||||
pHdr = testMalloc(sizeof(ShmHeader));
|
||||
testReadFile(zShm, 0, (void *)pHdr, sizeof(ShmHeader), &rc);
|
||||
assert( rc==0 );
|
||||
|
||||
return pHdr;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function makes a copy of the three files associated with LSM
|
||||
** database zDb (i.e. if zDb is "test.db", it makes copies of "test.db",
|
||||
** "test.db-log" and "test.db-shm").
|
||||
**
|
||||
** It then opens a new database connection to the copy with the xLock() call
|
||||
** instrumented so that it appears that some other process already connected
|
||||
** to the db (holding a shared lock on DMS2). This prevents recovery from
|
||||
** running. Then:
|
||||
**
|
||||
** 1) Check that the checksum of the database is zCksum.
|
||||
** 2) Write a few keys to the database. Then delete the same keys.
|
||||
** 3) Check that the checksum is zCksum.
|
||||
** 4) Flush the db to disk and run a checkpoint.
|
||||
** 5) Check once more that the checksum is still zCksum.
|
||||
*/
|
||||
static void doLiveRecovery(const char *zDb, const char *zCksum, int *pRc){
|
||||
if( *pRc==LSM_OK ){
|
||||
const DatasourceDefn defn = {TEST_DATASOURCE_RANDOM, 20, 25, 100, 500};
|
||||
Datasource *pData;
|
||||
const char *zCopy = "testcopy.lsm";
|
||||
char zCksum2[TEST_CKSUM_BYTES];
|
||||
TestDb *pDb = 0;
|
||||
int rc;
|
||||
|
||||
pData = testDatasourceNew(&defn);
|
||||
|
||||
testCopyLsmdb(zDb, zCopy);
|
||||
rc = tdb_lsm_open("test_no_recovery=1", zCopy, 0, &pDb);
|
||||
if( rc==0 ){
|
||||
ShmHeader *pHdr;
|
||||
lsm_db *db;
|
||||
testCksumDatabase(pDb, zCksum2);
|
||||
testCompareStr(zCksum, zCksum2, &rc);
|
||||
|
||||
testWriteDatasourceRange(pDb, pData, 1, 10, &rc);
|
||||
testDeleteDatasourceRange(pDb, pData, 1, 10, &rc);
|
||||
|
||||
/* Test that the two tree-headers are now consistent. */
|
||||
pHdr = getShmHeader(zCopy);
|
||||
if( rc==0 && memcmp(&pHdr->hdr1, &pHdr->hdr2, sizeof(pHdr->hdr1)) ){
|
||||
rc = 1;
|
||||
}
|
||||
testFree(pHdr);
|
||||
|
||||
if( rc==0 ){
|
||||
int nBuf = 64;
|
||||
db = tdb_lsm(pDb);
|
||||
lsm_config(db, LSM_CONFIG_AUTOFLUSH, &nBuf);
|
||||
lsm_begin(db, 1);
|
||||
lsm_commit(db, 0);
|
||||
rc = lsm_work(db, 0, 0, 0);
|
||||
}
|
||||
|
||||
testCksumDatabase(pDb, zCksum2);
|
||||
testCompareStr(zCksum, zCksum2, &rc);
|
||||
}
|
||||
|
||||
testDatasourceFree(pData);
|
||||
testClose(&pDb);
|
||||
testDeleteLsmdb(zCopy);
|
||||
*pRc = rc;
|
||||
}
|
||||
}
|
||||
|
||||
static void doWriterCrash1(int *pRc){
|
||||
const int nWrite = 2000;
|
||||
const int nStep = 10;
|
||||
const int iWriteStart = 20000;
|
||||
int rc = 0;
|
||||
TestDb *pDb = 0;
|
||||
Datasource *pData = 0;
|
||||
|
||||
rc = tdb_lsm_open("autowork=0", "testdb.lsm", 1, &pDb);
|
||||
if( rc==0 ){
|
||||
int iDot = 0;
|
||||
char zCksum[TEST_CKSUM_BYTES];
|
||||
int i;
|
||||
setupDatabase1(pDb, &pData);
|
||||
testCksumDatabase(pDb, zCksum);
|
||||
testBegin(pDb, 2, &rc);
|
||||
for(i=0; rc==0 && i<nWrite; i+=nStep){
|
||||
testCaseProgress(i, nWrite, testCaseNDot(), &iDot);
|
||||
testWriteDatasourceRange(pDb, pData, iWriteStart+i, nStep, &rc);
|
||||
doLiveRecovery("testdb.lsm", zCksum, &rc);
|
||||
}
|
||||
}
|
||||
testCommit(pDb, 0, &rc);
|
||||
testClose(&pDb);
|
||||
testDatasourceFree(pData);
|
||||
*pRc = rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This test case verifies that inconsistent tree-headers in shared-memory
|
||||
** are resolved correctly.
|
||||
*/
|
||||
static void doWriterCrash2(int *pRc){
|
||||
int rc = 0;
|
||||
TestDb *pDb = 0;
|
||||
Datasource *pData = 0;
|
||||
|
||||
rc = tdb_lsm_open("autowork=0", "testdb.lsm", 1, &pDb);
|
||||
if( rc==0 ){
|
||||
ShmHeader *pHdr1;
|
||||
ShmHeader *pHdr2;
|
||||
char zCksum1[TEST_CKSUM_BYTES];
|
||||
char zCksum2[TEST_CKSUM_BYTES];
|
||||
|
||||
pHdr1 = testMalloc(sizeof(ShmHeader));
|
||||
pHdr2 = testMalloc(sizeof(ShmHeader));
|
||||
setupDatabase1(pDb, &pData);
|
||||
|
||||
/* Grab a copy of the shared-memory header. And the db checksum */
|
||||
testReadFile("testdb.lsm-shm", 0, (void *)pHdr1, sizeof(ShmHeader), &rc);
|
||||
testCksumDatabase(pDb, zCksum1);
|
||||
|
||||
/* Modify the database */
|
||||
testBegin(pDb, 2, &rc);
|
||||
testWriteDatasourceRange(pDb, pData, 30000, 200, &rc);
|
||||
testCommit(pDb, 0, &rc);
|
||||
|
||||
/* Grab a second copy of the shared-memory header. And the db checksum */
|
||||
testReadFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
|
||||
testCksumDatabase(pDb, zCksum2);
|
||||
doLiveRecovery("testdb.lsm", zCksum2, &rc);
|
||||
|
||||
/* If both tree-headers are valid, tree-header-1 is used. */
|
||||
memcpy(&pHdr2->hdr1, &pHdr1->hdr1, sizeof(pHdr1->hdr1));
|
||||
pHdr2->bWriter = 1;
|
||||
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
|
||||
doLiveRecovery("testdb.lsm", zCksum1, &rc);
|
||||
|
||||
/* If both tree-headers are valid, tree-header-1 is used. */
|
||||
memcpy(&pHdr2->hdr1, &pHdr2->hdr2, sizeof(pHdr1->hdr1));
|
||||
memcpy(&pHdr2->hdr2, &pHdr1->hdr1, sizeof(pHdr1->hdr1));
|
||||
pHdr2->bWriter = 1;
|
||||
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
|
||||
doLiveRecovery("testdb.lsm", zCksum2, &rc);
|
||||
|
||||
/* If tree-header 1 is invalid, tree-header-2 is used */
|
||||
memcpy(&pHdr2->hdr2, &pHdr2->hdr1, sizeof(pHdr1->hdr1));
|
||||
pHdr2->hdr1.aCksum[0] = 5;
|
||||
pHdr2->hdr1.aCksum[0] = 6;
|
||||
pHdr2->bWriter = 1;
|
||||
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
|
||||
doLiveRecovery("testdb.lsm", zCksum2, &rc);
|
||||
|
||||
/* If tree-header 2 is invalid, tree-header-1 is used */
|
||||
memcpy(&pHdr2->hdr1, &pHdr2->hdr2, sizeof(pHdr1->hdr1));
|
||||
pHdr2->hdr2.aCksum[0] = 5;
|
||||
pHdr2->hdr2.aCksum[0] = 6;
|
||||
pHdr2->bWriter = 1;
|
||||
testWriteFile("testdb.lsm-shm", 0, (void *)pHdr2, sizeof(ShmHeader), &rc);
|
||||
doLiveRecovery("testdb.lsm", zCksum2, &rc);
|
||||
|
||||
testFree(pHdr1);
|
||||
testFree(pHdr2);
|
||||
testClose(&pDb);
|
||||
}
|
||||
|
||||
*pRc = rc;
|
||||
}
|
||||
|
||||
void do_writer_crash_test(const char *zPattern, int *pRc){
|
||||
struct Test {
|
||||
const char *zName;
|
||||
void (*xFunc)(int *);
|
||||
} aTest[] = {
|
||||
{ "writercrash1.lsm", doWriterCrash1 },
|
||||
{ "writercrash2.lsm", doWriterCrash2 },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<ArraySize(aTest); i++){
|
||||
struct Test *p = &aTest[i];
|
||||
if( testCaseBegin(pRc, zPattern, p->zName) ){
|
||||
p->xFunc(pRc);
|
||||
testCaseFinish(*pRc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
#define DATA_SEQUENTIAL TEST_DATASOURCE_SEQUENCE
|
||||
#define DATA_RANDOM TEST_DATASOURCE_RANDOM
|
||||
|
||||
typedef struct Datatest4 Datatest4;
|
||||
|
||||
/*
|
||||
** Test overview:
|
||||
**
|
||||
** 1. Insert (Datatest4.nRec) records into a database.
|
||||
**
|
||||
** 2. Repeat (Datatest4.nRepeat) times:
|
||||
**
|
||||
** 2a. Delete 2/3 of the records in the database.
|
||||
**
|
||||
** 2b. Run lsm_work(nMerge=1).
|
||||
**
|
||||
** 2c. Insert as many records as were deleted in 2a.
|
||||
**
|
||||
** 2d. Check database content is as expected.
|
||||
**
|
||||
** 2e. If (Datatest4.bReopen) is true, close and reopen the database.
|
||||
*/
|
||||
struct Datatest4 {
|
||||
/* Datasource definition */
|
||||
DatasourceDefn defn;
|
||||
|
||||
int nRec;
|
||||
int nRepeat;
|
||||
int bReopen;
|
||||
};
|
||||
|
||||
static void doDataTest4(
|
||||
const char *zSystem, /* Database system to test */
|
||||
Datatest4 *p, /* Structure containing test parameters */
|
||||
int *pRc /* OUT: Error code */
|
||||
){
|
||||
lsm_db *db = 0;
|
||||
TestDb *pDb;
|
||||
TestDb *pControl;
|
||||
Datasource *pData;
|
||||
int i;
|
||||
int rc = 0;
|
||||
int iDot = 0;
|
||||
int bMultiThreaded = 0; /* True for MT LSM database */
|
||||
|
||||
int nRecOn3 = (p->nRec / 3);
|
||||
int iData = 0;
|
||||
|
||||
/* Start the test case, open a database and allocate the datasource. */
|
||||
rc = testControlDb(&pControl);
|
||||
pDb = testOpen(zSystem, 1, &rc);
|
||||
pData = testDatasourceNew(&p->defn);
|
||||
if( rc==0 ){
|
||||
db = tdb_lsm(pDb);
|
||||
bMultiThreaded = tdb_lsm_multithread(pDb);
|
||||
}
|
||||
|
||||
testWriteDatasourceRange(pControl, pData, iData, nRecOn3*3, &rc);
|
||||
testWriteDatasourceRange(pDb, pData, iData, nRecOn3*3, &rc);
|
||||
|
||||
for(i=0; rc==0 && i<p->nRepeat; i++){
|
||||
|
||||
testDeleteDatasourceRange(pControl, pData, iData, nRecOn3*2, &rc);
|
||||
testDeleteDatasourceRange(pDb, pData, iData, nRecOn3*2, &rc);
|
||||
|
||||
if( db ){
|
||||
int nDone;
|
||||
#if 0
|
||||
fprintf(stderr, "lsm_work() start...\n"); fflush(stderr);
|
||||
#endif
|
||||
do {
|
||||
nDone = 0;
|
||||
rc = lsm_work(db, 1, (1<<30), &nDone);
|
||||
}while( rc==0 && nDone>0 );
|
||||
if( bMultiThreaded && rc==LSM_BUSY ) rc = LSM_OK;
|
||||
#if 0
|
||||
fprintf(stderr, "lsm_work() done...\n"); fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
|
||||
if( i+1<p->nRepeat ){
|
||||
iData += (nRecOn3*2);
|
||||
testWriteDatasourceRange(pControl, pData, iData+nRecOn3, nRecOn3*2, &rc);
|
||||
testWriteDatasourceRange(pDb, pData, iData+nRecOn3, nRecOn3*2, &rc);
|
||||
|
||||
testCompareDb(pData, nRecOn3*3, iData, pControl, pDb, &rc);
|
||||
|
||||
/* If Datatest4.bReopen is true, close and reopen the database */
|
||||
if( p->bReopen ){
|
||||
testReopen(&pDb, &rc);
|
||||
if( rc==0 ) db = tdb_lsm(pDb);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the progress dots... */
|
||||
testCaseProgress(i, p->nRepeat, testCaseNDot(), &iDot);
|
||||
}
|
||||
|
||||
testClose(&pDb);
|
||||
testClose(&pControl);
|
||||
testDatasourceFree(pData);
|
||||
testCaseFinish(rc);
|
||||
*pRc = rc;
|
||||
}
|
||||
|
||||
static char *getName4(const char *zSystem, Datatest4 *pTest){
|
||||
char *zRet;
|
||||
char *zData;
|
||||
zData = testDatasourceName(&pTest->defn);
|
||||
zRet = testMallocPrintf("data4.%s.%s.%d.%d.%d",
|
||||
zSystem, zData, pTest->nRec, pTest->nRepeat, pTest->bReopen
|
||||
);
|
||||
testFree(zData);
|
||||
return zRet;
|
||||
}
|
||||
|
||||
void test_data_4(
|
||||
const char *zSystem, /* Database system name */
|
||||
const char *zPattern, /* Run test cases that match this pattern */
|
||||
int *pRc /* IN/OUT: Error code */
|
||||
){
|
||||
Datatest4 aTest[] = {
|
||||
/* defn, nRec, nRepeat, bReopen */
|
||||
{ {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 0 },
|
||||
{ {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 1 },
|
||||
};
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
|
||||
char *zName = getName4(zSystem, &aTest[i]);
|
||||
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
|
||||
doDataTest4(zSystem, &aTest[i], pRc);
|
||||
}
|
||||
testFree(zName);
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
|
||||
#include "lsmtest.h"
|
||||
#include "bt.h"
|
||||
|
||||
int do_bt(int nArg, char **azArg){
|
||||
struct Option {
|
||||
const char *zName;
|
||||
int bPgno;
|
||||
int eOpt;
|
||||
} aOpt [] = {
|
||||
{ "dbhdr", 0, BT_INFO_HDRDUMP },
|
||||
{ "filename", 0, BT_INFO_FILENAME },
|
||||
{ "block_freelist", 0, BT_INFO_BLOCK_FREELIST },
|
||||
{ "page_freelist", 0, BT_INFO_PAGE_FREELIST },
|
||||
{ "filename", 0, BT_INFO_FILENAME },
|
||||
{ "page", 1, BT_INFO_PAGEDUMP },
|
||||
{ "page_ascii", 1, BT_INFO_PAGEDUMP_ASCII },
|
||||
{ "leaks", 0, BT_INFO_PAGE_LEAKS },
|
||||
{ 0, 0 }
|
||||
};
|
||||
int iOpt;
|
||||
int rc;
|
||||
bt_info buf;
|
||||
char *zOpt;
|
||||
char *zFile;
|
||||
|
||||
bt_db *db = 0;
|
||||
|
||||
if( nArg<2 ){
|
||||
testPrintUsage("FILENAME OPTION ...");
|
||||
return -1;
|
||||
}
|
||||
zFile = azArg[0];
|
||||
zOpt = azArg[1];
|
||||
|
||||
rc = testArgSelect(aOpt, "option", zOpt, &iOpt);
|
||||
if( rc!=0 ) return rc;
|
||||
if( nArg!=2+aOpt[iOpt].bPgno ){
|
||||
testPrintFUsage("FILENAME %s %s", zOpt, aOpt[iOpt].bPgno ? "PGNO" : "");
|
||||
return -4;
|
||||
}
|
||||
|
||||
rc = sqlite4BtNew(sqlite4_env_default(), 0, &db);
|
||||
if( rc!=SQLITE4_OK ){
|
||||
testPrintError("sqlite4BtNew() failed: %d", rc);
|
||||
return -2;
|
||||
}
|
||||
rc = sqlite4BtOpen(db, zFile);
|
||||
if( rc!=SQLITE4_OK ){
|
||||
testPrintError("sqlite4BtOpen() failed: %d", rc);
|
||||
return -3;
|
||||
}
|
||||
|
||||
buf.eType = aOpt[iOpt].eOpt;
|
||||
buf.pgno = 0;
|
||||
sqlite4_buffer_init(&buf.output, 0);
|
||||
|
||||
if( aOpt[iOpt].bPgno ){
|
||||
buf.pgno = (u32)atoi(azArg[2]);
|
||||
}
|
||||
|
||||
rc = sqlite4BtControl(db, BT_CONTROL_INFO, &buf);
|
||||
if( rc!=SQLITE4_OK ){
|
||||
testPrintError("sqlite4BtControl() failed: %d\n", rc);
|
||||
return -4;
|
||||
}
|
||||
|
||||
printf("%s\n", (char*)buf.output.p);
|
||||
sqlite4_buffer_clear(&buf.output);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
struct Datasource {
|
||||
int eType;
|
||||
|
||||
int nMinKey;
|
||||
int nMaxKey;
|
||||
int nMinVal;
|
||||
int nMaxVal;
|
||||
|
||||
char *aKey;
|
||||
char *aVal;
|
||||
};
|
||||
|
||||
void testDatasourceEntry(
|
||||
Datasource *p,
|
||||
int iData,
|
||||
void **ppKey, int *pnKey,
|
||||
void **ppVal, int *pnVal
|
||||
){
|
||||
assert( (ppKey==0)==(pnKey==0) );
|
||||
assert( (ppVal==0)==(pnVal==0) );
|
||||
|
||||
if( ppKey ){
|
||||
int nKey = 0;
|
||||
switch( p->eType ){
|
||||
case TEST_DATASOURCE_RANDOM: {
|
||||
int nRange = (1 + p->nMaxKey - p->nMinKey);
|
||||
nKey = (int)( testPrngValue((u32)iData) % nRange ) + p->nMinKey;
|
||||
testPrngString((u32)iData, p->aKey, nKey);
|
||||
break;
|
||||
}
|
||||
case TEST_DATASOURCE_SEQUENCE:
|
||||
nKey = sprintf(p->aKey, "%012d", iData);
|
||||
break;
|
||||
}
|
||||
*ppKey = p->aKey;
|
||||
*pnKey = nKey;
|
||||
}
|
||||
if( ppVal ){
|
||||
u32 nVal = testPrngValue((u32)iData)%(1+p->nMaxVal-p->nMinVal)+p->nMinVal;
|
||||
testPrngString((u32)~iData, p->aVal, (int)nVal);
|
||||
*ppVal = p->aVal;
|
||||
*pnVal = (int)nVal;
|
||||
}
|
||||
}
|
||||
|
||||
void testDatasourceFree(Datasource *p){
|
||||
testFree(p);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a pointer to a nul-terminated string that corresponds to the
|
||||
** contents of the datasource-definition passed as the first argument.
|
||||
** The caller should eventually free the returned pointer using testFree().
|
||||
*/
|
||||
char *testDatasourceName(const DatasourceDefn *p){
|
||||
char *zRet;
|
||||
zRet = testMallocPrintf("%s.(%d-%d).(%d-%d)",
|
||||
(p->eType==TEST_DATASOURCE_SEQUENCE ? "seq" : "rnd"),
|
||||
p->nMinKey, p->nMaxKey,
|
||||
p->nMinVal, p->nMaxVal
|
||||
);
|
||||
return zRet;
|
||||
}
|
||||
|
||||
Datasource *testDatasourceNew(const DatasourceDefn *pDefn){
|
||||
Datasource *p;
|
||||
int nMinKey;
|
||||
int nMaxKey;
|
||||
int nMinVal;
|
||||
int nMaxVal;
|
||||
|
||||
if( pDefn->eType==TEST_DATASOURCE_SEQUENCE ){
|
||||
nMinKey = 128;
|
||||
nMaxKey = 128;
|
||||
}else{
|
||||
nMinKey = MAX(0, pDefn->nMinKey);
|
||||
nMaxKey = MAX(nMinKey, pDefn->nMaxKey);
|
||||
}
|
||||
nMinVal = MAX(0, pDefn->nMinVal);
|
||||
nMaxVal = MAX(nMinVal, pDefn->nMaxVal);
|
||||
|
||||
p = (Datasource *)testMalloc(sizeof(Datasource) + nMaxKey + nMaxVal + 1);
|
||||
p->eType = pDefn->eType;
|
||||
p->nMinKey = nMinKey;
|
||||
p->nMinVal = nMinVal;
|
||||
p->nMaxKey = nMaxKey;
|
||||
p->nMaxVal = nMaxVal;
|
||||
|
||||
p->aKey = (char *)&p[1];
|
||||
p->aVal = &p->aKey[nMaxKey];
|
||||
return p;
|
||||
};
|
||||
@@ -1,177 +0,0 @@
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
|
||||
int do_work(int nArg, char **azArg){
|
||||
struct Option {
|
||||
const char *zName;
|
||||
} aOpt [] = {
|
||||
{ "-nmerge" },
|
||||
{ "-nkb" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
lsm_db *pDb;
|
||||
int rc;
|
||||
int i;
|
||||
const char *zDb;
|
||||
int nMerge = 1;
|
||||
int nKB = (1<<30);
|
||||
|
||||
if( nArg==0 ) goto usage;
|
||||
zDb = azArg[nArg-1];
|
||||
for(i=0; i<(nArg-1); i++){
|
||||
int iSel;
|
||||
rc = testArgSelect(aOpt, "option", azArg[i], &iSel);
|
||||
if( rc ) return rc;
|
||||
switch( iSel ){
|
||||
case 0:
|
||||
i++;
|
||||
if( i==(nArg-1) ) goto usage;
|
||||
nMerge = atoi(azArg[i]);
|
||||
break;
|
||||
case 1:
|
||||
i++;
|
||||
if( i==(nArg-1) ) goto usage;
|
||||
nKB = atoi(azArg[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = lsm_new(0, &pDb);
|
||||
if( rc!=LSM_OK ){
|
||||
testPrintError("lsm_open(): rc=%d\n", rc);
|
||||
}else{
|
||||
rc = lsm_open(pDb, zDb);
|
||||
if( rc!=LSM_OK ){
|
||||
testPrintError("lsm_open(): rc=%d\n", rc);
|
||||
}else{
|
||||
int n = -1;
|
||||
lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &n);
|
||||
n = n*2;
|
||||
lsm_config(pDb, LSM_CONFIG_AUTOCHECKPOINT, &n);
|
||||
|
||||
rc = lsm_work(pDb, nMerge, nKB, 0);
|
||||
if( rc!=LSM_OK ){
|
||||
testPrintError("lsm_work(): rc=%d\n", rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( rc==LSM_OK ){
|
||||
rc = lsm_checkpoint(pDb, 0);
|
||||
}
|
||||
|
||||
lsm_close(pDb);
|
||||
return rc;
|
||||
|
||||
usage:
|
||||
testPrintUsage("?-optimize? ?-n N? DATABASE");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** lsmtest show ?-config LSM-CONFIG? DATABASE ?COMMAND ?PGNO??
|
||||
*/
|
||||
int do_show(int nArg, char **azArg){
|
||||
lsm_db *pDb;
|
||||
int rc;
|
||||
const char *zDb;
|
||||
|
||||
int eOpt = LSM_INFO_DB_STRUCTURE;
|
||||
unsigned int iPg = 0;
|
||||
int bConfig = 0;
|
||||
const char *zConfig = "";
|
||||
|
||||
struct Option {
|
||||
const char *zName;
|
||||
int bConfig;
|
||||
int eOpt;
|
||||
} aOpt [] = {
|
||||
{ "array", 0, LSM_INFO_ARRAY_STRUCTURE },
|
||||
{ "array-pages", 0, LSM_INFO_ARRAY_PAGES },
|
||||
{ "blocksize", 1, LSM_CONFIG_BLOCK_SIZE },
|
||||
{ "pagesize", 1, LSM_CONFIG_PAGE_SIZE },
|
||||
{ "freelist", 0, LSM_INFO_FREELIST },
|
||||
{ "page-ascii", 0, LSM_INFO_PAGE_ASCII_DUMP },
|
||||
{ "page-hex", 0, LSM_INFO_PAGE_HEX_DUMP },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
char *z = 0;
|
||||
int iDb = 0; /* Index of DATABASE in azArg[] */
|
||||
|
||||
/* Check if there is a "-config" option: */
|
||||
if( nArg>2 && strlen(azArg[0])>1
|
||||
&& memcmp(azArg[0], "-config", strlen(azArg[0]))==0
|
||||
){
|
||||
zConfig = azArg[1];
|
||||
iDb = 2;
|
||||
}
|
||||
if( nArg<(iDb+1) ) goto usage;
|
||||
|
||||
if( nArg>(iDb+1) ){
|
||||
rc = testArgSelect(aOpt, "option", azArg[iDb+1], &eOpt);
|
||||
if( rc!=0 ) return rc;
|
||||
bConfig = aOpt[eOpt].bConfig;
|
||||
eOpt = aOpt[eOpt].eOpt;
|
||||
if( (bConfig==0 && eOpt==LSM_INFO_FREELIST)
|
||||
|| (bConfig==1 && eOpt==LSM_CONFIG_BLOCK_SIZE)
|
||||
|| (bConfig==1 && eOpt==LSM_CONFIG_PAGE_SIZE)
|
||||
){
|
||||
if( nArg!=(iDb+2) ) goto usage;
|
||||
}else{
|
||||
if( nArg!=(iDb+3) ) goto usage;
|
||||
iPg = atoi(azArg[iDb+2]);
|
||||
}
|
||||
}
|
||||
zDb = azArg[iDb];
|
||||
|
||||
rc = lsm_new(0, &pDb);
|
||||
tdb_lsm_configure(pDb, zConfig);
|
||||
if( rc!=LSM_OK ){
|
||||
testPrintError("lsm_new(): rc=%d\n", rc);
|
||||
}else{
|
||||
rc = lsm_open(pDb, zDb);
|
||||
if( rc!=LSM_OK ){
|
||||
testPrintError("lsm_open(): rc=%d\n", rc);
|
||||
}
|
||||
}
|
||||
|
||||
if( rc==LSM_OK ){
|
||||
if( bConfig==0 ){
|
||||
switch( eOpt ){
|
||||
case LSM_INFO_DB_STRUCTURE:
|
||||
case LSM_INFO_FREELIST:
|
||||
rc = lsm_info(pDb, eOpt, &z);
|
||||
break;
|
||||
case LSM_INFO_ARRAY_STRUCTURE:
|
||||
case LSM_INFO_ARRAY_PAGES:
|
||||
case LSM_INFO_PAGE_ASCII_DUMP:
|
||||
case LSM_INFO_PAGE_HEX_DUMP:
|
||||
rc = lsm_info(pDb, eOpt, iPg, &z);
|
||||
break;
|
||||
default:
|
||||
assert( !"no chance" );
|
||||
}
|
||||
|
||||
if( rc==LSM_OK ){
|
||||
printf("%s\n", z ? z : "");
|
||||
fflush(stdout);
|
||||
}
|
||||
lsm_free(lsm_get_env(pDb), z);
|
||||
}else{
|
||||
int iRes = -1;
|
||||
lsm_config(pDb, eOpt, &iRes);
|
||||
printf("%d\n", iRes);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
lsm_close(pDb);
|
||||
return rc;
|
||||
|
||||
usage:
|
||||
testPrintUsage("DATABASE ?array|page-ascii|page-hex PGNO?");
|
||||
return -1;
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
|
||||
/*
|
||||
** SUMMARY
|
||||
**
|
||||
** This file implements the 'io' subcommand of the test program. It is used
|
||||
** for testing the performance of various combinations of write() and fsync()
|
||||
** system calls. All operations occur on a single file, which may or may not
|
||||
** exist when a test is started.
|
||||
**
|
||||
** A test consists of a series of commands. Each command is either a write
|
||||
** or an fsync. A write is specified as "<amount>@<offset>", where <amount>
|
||||
** is the amount of data written, and <offset> is the offset of the file
|
||||
** to write to. An <amount> or an <offset> is specified as an integer number
|
||||
** of bytes. Or, if postfixed with a "K", "M" or "G", an integer number of
|
||||
** KB, MB or GB, respectively. An fsync is simply "S". All commands are
|
||||
** case-insensitive.
|
||||
**
|
||||
** Example test program:
|
||||
**
|
||||
** 2M@6M 1492K@4M S 4096@4K S
|
||||
**
|
||||
** This program writes 2 MB of data starting at the offset 6MB offset of
|
||||
** the file, followed by 1492 KB of data written at the 4MB offset of the
|
||||
** file, followed by a call to fsync(), a write of 4KB of data at byte
|
||||
** offset 4096, and finally another call to fsync().
|
||||
**
|
||||
** Commands may either be specified on the command line (one command per
|
||||
** command line argument) or read from stdin. Commands read from stdin
|
||||
** must be separated by white-space.
|
||||
**
|
||||
** COMMAND LINE INVOCATION
|
||||
**
|
||||
** The sub-command implemented in this file must be invoked with at least
|
||||
** two arguments - the path to the file to write to and the page-size to
|
||||
** use for writing. If there are more than two arguments, then each
|
||||
** subsequent argument is assumed to be a test command. If there are exactly
|
||||
** two arguments, the test commands are read from stdin.
|
||||
**
|
||||
** A write command does not result in a single call to system call write().
|
||||
** Instead, the specified region is written sequentially using one or
|
||||
** more calls to write(), each of which writes not more than one page of
|
||||
** data. For example, if the page-size is 4KB, the command "2M@6M" results
|
||||
** in 512 calls to write(), each of which writes 4KB of data.
|
||||
**
|
||||
** EXAMPLES
|
||||
**
|
||||
** Two equivalent examples:
|
||||
**
|
||||
** $ lsmtest io testfile.db 4KB 2M@6M 1492K@4M S 4096@4K S
|
||||
** 3544K written in 129 ms
|
||||
** $ echo "2M@6M 1492K@4M S 4096@4K S" | lsmtest io testfile.db 4096
|
||||
** 3544K written in 127 ms
|
||||
**
|
||||
*/
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
typedef struct IoContext IoContext;
|
||||
|
||||
struct IoContext {
|
||||
int fd;
|
||||
int nWrite;
|
||||
};
|
||||
|
||||
/*
|
||||
** As isspace(3)
|
||||
*/
|
||||
static int safe_isspace(char c){
|
||||
if( c&0x80) return 0;
|
||||
return isspace(c);
|
||||
}
|
||||
|
||||
/*
|
||||
** As isdigit(3)
|
||||
*/
|
||||
static int safe_isdigit(char c){
|
||||
if( c&0x80) return 0;
|
||||
return isdigit(c);
|
||||
}
|
||||
|
||||
static i64 getNextSize(char *zIn, char **pzOut, int *pRc){
|
||||
i64 iRet = 0;
|
||||
if( *pRc==0 ){
|
||||
char *z = zIn;
|
||||
|
||||
if( !safe_isdigit(*z) ){
|
||||
*pRc = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Process digits */
|
||||
while( safe_isdigit(*z) ){
|
||||
iRet = iRet*10 + (*z - '0');
|
||||
z++;
|
||||
}
|
||||
|
||||
/* Process suffix */
|
||||
switch( *z ){
|
||||
case 'k': case 'K':
|
||||
iRet = iRet * 1024;
|
||||
z++;
|
||||
break;
|
||||
|
||||
case 'm': case 'M':
|
||||
iRet = iRet * 1024 * 1024;
|
||||
z++;
|
||||
break;
|
||||
|
||||
case 'g': case 'G':
|
||||
iRet = iRet * 1024 * 1024 * 1024;
|
||||
z++;
|
||||
break;
|
||||
}
|
||||
|
||||
if( pzOut ) *pzOut = z;
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
static int doOneCmd(
|
||||
IoContext *pCtx,
|
||||
u8 *aData,
|
||||
int pgsz,
|
||||
char *zCmd,
|
||||
char **pzOut
|
||||
){
|
||||
char c;
|
||||
char *z = zCmd;
|
||||
|
||||
while( safe_isspace(*z) ) z++;
|
||||
c = *z;
|
||||
|
||||
if( c==0 ){
|
||||
if( pzOut ) *pzOut = z;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( c=='s' || c=='S' ){
|
||||
if( pzOut ) *pzOut = &z[1];
|
||||
return fdatasync(pCtx->fd);
|
||||
}
|
||||
|
||||
if( safe_isdigit(c) ){
|
||||
i64 iOff = 0;
|
||||
int nByte = 0;
|
||||
int rc = 0;
|
||||
int nPg;
|
||||
int iPg;
|
||||
|
||||
nByte = (int)getNextSize(z, &z, &rc);
|
||||
if( rc || *z!='@' ) goto bad_command;
|
||||
z++;
|
||||
iOff = getNextSize(z, &z, &rc);
|
||||
if( rc || (safe_isspace(*z)==0 && *z!='\0') ) goto bad_command;
|
||||
if( pzOut ) *pzOut = z;
|
||||
|
||||
nPg = (nByte+pgsz-1) / pgsz;
|
||||
lseek(pCtx->fd, (off_t)iOff, SEEK_SET);
|
||||
for(iPg=0; iPg<nPg; iPg++){
|
||||
write(pCtx->fd, aData, pgsz);
|
||||
}
|
||||
pCtx->nWrite += nByte/1024;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bad_command:
|
||||
testPrintError("unrecognized command: %s", zCmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int readStdin(char **pzOut){
|
||||
int nAlloc = 128;
|
||||
char *zOut = 0;
|
||||
int nOut = 0;
|
||||
|
||||
while( !feof(stdin) ){
|
||||
int nRead;
|
||||
|
||||
nAlloc = nAlloc*2;
|
||||
zOut = realloc(zOut, nAlloc);
|
||||
nRead = fread(&zOut[nOut], 1, nAlloc-nOut-1, stdin);
|
||||
|
||||
if( nRead==0 ) break;
|
||||
nOut += nRead;
|
||||
zOut[nOut] = '\0';
|
||||
}
|
||||
|
||||
*pzOut = zOut;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_io(int nArg, char **azArg){
|
||||
IoContext ctx;
|
||||
int pgsz;
|
||||
char *zFile;
|
||||
char *zPgsz;
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
char *zStdin = 0;
|
||||
char *z;
|
||||
|
||||
u8 *aData;
|
||||
|
||||
memset(&ctx, 0, sizeof(IoContext));
|
||||
if( nArg<2 ){
|
||||
testPrintUsage("FILE PGSZ ?CMD-1 ...?");
|
||||
return -1;
|
||||
}
|
||||
zFile = azArg[0];
|
||||
zPgsz = azArg[1];
|
||||
|
||||
pgsz = (int)getNextSize(zPgsz, 0, &rc);
|
||||
if( pgsz<=0 ){
|
||||
testPrintError("Ridiculous page size: %d", pgsz);
|
||||
return -1;
|
||||
}
|
||||
aData = malloc(pgsz);
|
||||
memset(aData, 0x77, pgsz);
|
||||
|
||||
ctx.fd = open(zFile, O_RDWR|O_CREAT|_O_BINARY, 0644);
|
||||
if( ctx.fd<0 ){
|
||||
perror("open: ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( nArg==2 ){
|
||||
readStdin(&zStdin);
|
||||
testTimeInit();
|
||||
z = zStdin;
|
||||
while( *z && rc==0 ){
|
||||
rc = doOneCmd(&ctx, aData, pgsz, z, &z);
|
||||
}
|
||||
}else{
|
||||
testTimeInit();
|
||||
for(i=2; i<nArg; i++){
|
||||
rc = doOneCmd(&ctx, aData, pgsz, azArg[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%dK written in %d ms\n", ctx.nWrite, testTimeGet());
|
||||
|
||||
free(zStdin);
|
||||
close(ctx.fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,409 +0,0 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ArraySize(x) ((int)(sizeof(x) / sizeof((x)[0])))
|
||||
|
||||
#define MIN(x,y) ((x)<(y) ? (x) : (y))
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned char u8;
|
||||
typedef long long int i64;
|
||||
typedef unsigned long long int u64;
|
||||
|
||||
#if defined(__GLIBC__) && defined(LSM_DEBUG_MEM)
|
||||
extern int backtrace(void**,int);
|
||||
extern void backtrace_symbols_fd(void*const*,int,int);
|
||||
# define TM_BACKTRACE 12
|
||||
#else
|
||||
# define backtrace(A,B) 1
|
||||
# define backtrace_symbols_fd(A,B,C)
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct TmBlockHdr TmBlockHdr;
|
||||
typedef struct TmAgg TmAgg;
|
||||
typedef struct TmGlobal TmGlobal;
|
||||
|
||||
struct TmGlobal {
|
||||
/* Linked list of all currently outstanding allocations. And a table of
|
||||
** all allocations, past and present, indexed by backtrace() info. */
|
||||
TmBlockHdr *pFirst;
|
||||
#ifdef TM_BACKTRACE
|
||||
TmAgg *aHash[10000];
|
||||
#endif
|
||||
|
||||
/* Underlying malloc/realloc/free functions */
|
||||
void *(*xMalloc)(int); /* underlying malloc(3) function */
|
||||
void *(*xRealloc)(void *, int); /* underlying realloc(3) function */
|
||||
void (*xFree)(void *); /* underlying free(3) function */
|
||||
|
||||
/* Mutex to protect pFirst and aHash */
|
||||
void (*xEnterMutex)(TmGlobal*); /* Call this to enter the mutex */
|
||||
void (*xLeaveMutex)(TmGlobal*); /* Call this to leave mutex */
|
||||
void (*xDelMutex)(TmGlobal*); /* Call this to delete mutex */
|
||||
void *pMutex; /* Mutex handle */
|
||||
|
||||
void *(*xSaveMalloc)(void *, size_t);
|
||||
void *(*xSaveRealloc)(void *, void *, size_t);
|
||||
void (*xSaveFree)(void *, void *);
|
||||
|
||||
/* OOM injection scheduling. If nCountdown is greater than zero when a
|
||||
** malloc attempt is made, it is decremented. If this means nCountdown
|
||||
** transitions from 1 to 0, then the allocation fails. If bPersist is true
|
||||
** when this happens, nCountdown is then incremented back to 1 (so that the
|
||||
** next attempt fails too).
|
||||
*/
|
||||
int nCountdown;
|
||||
int bPersist;
|
||||
int bEnable;
|
||||
void (*xHook)(void *);
|
||||
void *pHookCtx;
|
||||
};
|
||||
|
||||
struct TmBlockHdr {
|
||||
TmBlockHdr *pNext;
|
||||
TmBlockHdr *pPrev;
|
||||
int nByte;
|
||||
#ifdef TM_BACKTRACE
|
||||
TmAgg *pAgg;
|
||||
#endif
|
||||
u32 iForeGuard;
|
||||
};
|
||||
|
||||
#ifdef TM_BACKTRACE
|
||||
struct TmAgg {
|
||||
int nAlloc; /* Number of allocations at this path */
|
||||
int nByte; /* Total number of bytes allocated */
|
||||
int nOutAlloc; /* Number of outstanding allocations */
|
||||
int nOutByte; /* Number of outstanding bytes */
|
||||
void *aFrame[TM_BACKTRACE]; /* backtrace() output */
|
||||
TmAgg *pNext; /* Next object in hash-table collision */
|
||||
};
|
||||
#endif
|
||||
|
||||
#define FOREGUARD 0x80F5E153
|
||||
#define REARGUARD 0xE4676B53
|
||||
static const u32 rearguard = REARGUARD;
|
||||
|
||||
#define ROUND8(x) (((x)+7)&~7)
|
||||
|
||||
#define BLOCK_HDR_SIZE (ROUND8( sizeof(TmBlockHdr) ))
|
||||
|
||||
static void lsmtest_oom_error(void){
|
||||
static int nErr = 0;
|
||||
nErr++;
|
||||
}
|
||||
|
||||
static void tmEnterMutex(TmGlobal *pTm){
|
||||
pTm->xEnterMutex(pTm);
|
||||
}
|
||||
static void tmLeaveMutex(TmGlobal *pTm){
|
||||
pTm->xLeaveMutex(pTm);
|
||||
}
|
||||
|
||||
static void *tmMalloc(TmGlobal *pTm, int nByte){
|
||||
TmBlockHdr *pNew; /* New allocation header block */
|
||||
u8 *pUser; /* Return value */
|
||||
int nReq; /* Total number of bytes requested */
|
||||
|
||||
assert( sizeof(rearguard)==4 );
|
||||
nReq = BLOCK_HDR_SIZE + nByte + 4;
|
||||
pNew = (TmBlockHdr *)pTm->xMalloc(nReq);
|
||||
memset(pNew, 0, sizeof(TmBlockHdr));
|
||||
|
||||
tmEnterMutex(pTm);
|
||||
assert( pTm->nCountdown>=0 );
|
||||
assert( pTm->bPersist==0 || pTm->bPersist==1 );
|
||||
|
||||
if( pTm->bEnable && pTm->nCountdown==1 ){
|
||||
/* Simulate an OOM error. */
|
||||
lsmtest_oom_error();
|
||||
pTm->xFree(pNew);
|
||||
pTm->nCountdown = pTm->bPersist;
|
||||
if( pTm->xHook ) pTm->xHook(pTm->pHookCtx);
|
||||
pUser = 0;
|
||||
}else{
|
||||
if( pTm->bEnable && pTm->nCountdown ) pTm->nCountdown--;
|
||||
|
||||
pNew->iForeGuard = FOREGUARD;
|
||||
pNew->nByte = nByte;
|
||||
pNew->pNext = pTm->pFirst;
|
||||
|
||||
if( pTm->pFirst ){
|
||||
pTm->pFirst->pPrev = pNew;
|
||||
}
|
||||
pTm->pFirst = pNew;
|
||||
|
||||
pUser = &((u8 *)pNew)[BLOCK_HDR_SIZE];
|
||||
memset(pUser, 0x56, nByte);
|
||||
memcpy(&pUser[nByte], &rearguard, 4);
|
||||
|
||||
#ifdef TM_BACKTRACE
|
||||
{
|
||||
TmAgg *pAgg;
|
||||
int i;
|
||||
u32 iHash = 0;
|
||||
void *aFrame[TM_BACKTRACE];
|
||||
memset(aFrame, 0, sizeof(aFrame));
|
||||
backtrace(aFrame, TM_BACKTRACE);
|
||||
|
||||
for(i=0; i<ArraySize(aFrame); i++){
|
||||
iHash += (u64)(aFrame[i]) + (iHash<<3);
|
||||
}
|
||||
iHash = iHash % ArraySize(pTm->aHash);
|
||||
|
||||
for(pAgg=pTm->aHash[iHash]; pAgg; pAgg=pAgg->pNext){
|
||||
if( memcmp(pAgg->aFrame, aFrame, sizeof(aFrame))==0 ) break;
|
||||
}
|
||||
if( !pAgg ){
|
||||
pAgg = (TmAgg *)pTm->xMalloc(sizeof(TmAgg));
|
||||
memset(pAgg, 0, sizeof(TmAgg));
|
||||
memcpy(pAgg->aFrame, aFrame, sizeof(aFrame));
|
||||
pAgg->pNext = pTm->aHash[iHash];
|
||||
pTm->aHash[iHash] = pAgg;
|
||||
}
|
||||
pAgg->nAlloc++;
|
||||
pAgg->nByte += nByte;
|
||||
pAgg->nOutAlloc++;
|
||||
pAgg->nOutByte += nByte;
|
||||
pNew->pAgg = pAgg;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
tmLeaveMutex(pTm);
|
||||
return pUser;
|
||||
}
|
||||
|
||||
static void tmFree(TmGlobal *pTm, void *p){
|
||||
if( p ){
|
||||
TmBlockHdr *pHdr;
|
||||
u8 *pUser = (u8 *)p;
|
||||
|
||||
tmEnterMutex(pTm);
|
||||
pHdr = (TmBlockHdr *)(pUser - BLOCK_HDR_SIZE);
|
||||
assert( pHdr->iForeGuard==FOREGUARD );
|
||||
assert( 0==memcmp(&pUser[pHdr->nByte], &rearguard, 4) );
|
||||
|
||||
if( pHdr->pPrev ){
|
||||
assert( pHdr->pPrev->pNext==pHdr );
|
||||
pHdr->pPrev->pNext = pHdr->pNext;
|
||||
}else{
|
||||
assert( pHdr==pTm->pFirst );
|
||||
pTm->pFirst = pHdr->pNext;
|
||||
}
|
||||
if( pHdr->pNext ){
|
||||
assert( pHdr->pNext->pPrev==pHdr );
|
||||
pHdr->pNext->pPrev = pHdr->pPrev;
|
||||
}
|
||||
|
||||
#ifdef TM_BACKTRACE
|
||||
pHdr->pAgg->nOutAlloc--;
|
||||
pHdr->pAgg->nOutByte -= pHdr->nByte;
|
||||
#endif
|
||||
|
||||
tmLeaveMutex(pTm);
|
||||
memset(pUser, 0x58, pHdr->nByte);
|
||||
memset(pHdr, 0x57, sizeof(TmBlockHdr));
|
||||
pTm->xFree(pHdr);
|
||||
}
|
||||
}
|
||||
|
||||
static void *tmRealloc(TmGlobal *pTm, void *p, int nByte){
|
||||
void *pNew;
|
||||
|
||||
pNew = tmMalloc(pTm, nByte);
|
||||
if( pNew && p ){
|
||||
TmBlockHdr *pHdr;
|
||||
u8 *pUser = (u8 *)p;
|
||||
pHdr = (TmBlockHdr *)(pUser - BLOCK_HDR_SIZE);
|
||||
memcpy(pNew, p, MIN(nByte, pHdr->nByte));
|
||||
tmFree(pTm, p);
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
||||
static void tmMallocOom(
|
||||
TmGlobal *pTm,
|
||||
int nCountdown,
|
||||
int bPersist,
|
||||
void (*xHook)(void *),
|
||||
void *pHookCtx
|
||||
){
|
||||
assert( nCountdown>=0 );
|
||||
assert( bPersist==0 || bPersist==1 );
|
||||
pTm->nCountdown = nCountdown;
|
||||
pTm->bPersist = bPersist;
|
||||
pTm->xHook = xHook;
|
||||
pTm->pHookCtx = pHookCtx;
|
||||
pTm->bEnable = 1;
|
||||
}
|
||||
|
||||
static void tmMallocOomEnable(
|
||||
TmGlobal *pTm,
|
||||
int bEnable
|
||||
){
|
||||
pTm->bEnable = bEnable;
|
||||
}
|
||||
|
||||
static void tmMallocCheck(
|
||||
TmGlobal *pTm,
|
||||
int *pnLeakAlloc,
|
||||
int *pnLeakByte,
|
||||
FILE *pFile
|
||||
){
|
||||
TmBlockHdr *pHdr;
|
||||
int nLeak = 0;
|
||||
int nByte = 0;
|
||||
|
||||
if( pTm==0 ) return;
|
||||
|
||||
for(pHdr=pTm->pFirst; pHdr; pHdr=pHdr->pNext){
|
||||
nLeak++;
|
||||
nByte += pHdr->nByte;
|
||||
}
|
||||
if( pnLeakAlloc ) *pnLeakAlloc = nLeak;
|
||||
if( pnLeakByte ) *pnLeakByte = nByte;
|
||||
|
||||
#ifdef TM_BACKTRACE
|
||||
if( pFile ){
|
||||
int i;
|
||||
fprintf(pFile, "LEAKS\n");
|
||||
for(i=0; i<ArraySize(pTm->aHash); i++){
|
||||
TmAgg *pAgg;
|
||||
for(pAgg=pTm->aHash[i]; pAgg; pAgg=pAgg->pNext){
|
||||
if( pAgg->nOutAlloc ){
|
||||
int j;
|
||||
fprintf(pFile, "%d %d ", pAgg->nOutByte, pAgg->nOutAlloc);
|
||||
for(j=0; j<TM_BACKTRACE; j++){
|
||||
fprintf(pFile, "%p ", pAgg->aFrame[j]);
|
||||
}
|
||||
fprintf(pFile, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(pFile, "\nALLOCATIONS\n");
|
||||
for(i=0; i<ArraySize(pTm->aHash); i++){
|
||||
TmAgg *pAgg;
|
||||
for(pAgg=pTm->aHash[i]; pAgg; pAgg=pAgg->pNext){
|
||||
int j;
|
||||
fprintf(pFile, "%d %d ", pAgg->nByte, pAgg->nAlloc);
|
||||
for(j=0; j<TM_BACKTRACE; j++) fprintf(pFile, "%p ", pAgg->aFrame[j]);
|
||||
fprintf(pFile, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void)pFile;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#include "lsm.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
typedef struct LsmMutex LsmMutex;
|
||||
struct LsmMutex {
|
||||
lsm_env *pEnv;
|
||||
lsm_mutex *pMutex;
|
||||
};
|
||||
|
||||
static void tmLsmMutexEnter(TmGlobal *pTm){
|
||||
LsmMutex *p = (LsmMutex *)pTm->pMutex;
|
||||
p->pEnv->xMutexEnter(p->pMutex);
|
||||
}
|
||||
static void tmLsmMutexLeave(TmGlobal *pTm){
|
||||
LsmMutex *p = (LsmMutex *)(pTm->pMutex);
|
||||
p->pEnv->xMutexLeave(p->pMutex);
|
||||
}
|
||||
static void tmLsmMutexDel(TmGlobal *pTm){
|
||||
LsmMutex *p = (LsmMutex *)pTm->pMutex;
|
||||
pTm->xFree(p);
|
||||
}
|
||||
static void *tmLsmMalloc(int n){ return malloc(n); }
|
||||
static void tmLsmFree(void *ptr){ free(ptr); }
|
||||
static void *tmLsmRealloc(void *ptr, int n){ return realloc(ptr, n); }
|
||||
|
||||
static void *tmLsmEnvMalloc(lsm_env *p, size_t n){
|
||||
return tmMalloc((TmGlobal *)(p->pMemCtx), n);
|
||||
}
|
||||
static void tmLsmEnvFree(lsm_env *p, void *ptr){
|
||||
tmFree((TmGlobal *)(p->pMemCtx), ptr);
|
||||
}
|
||||
static void *tmLsmEnvRealloc(lsm_env *p, void *ptr, size_t n){
|
||||
return tmRealloc((TmGlobal *)(p->pMemCtx), ptr, n);
|
||||
}
|
||||
|
||||
void testMallocInstall(lsm_env *pEnv){
|
||||
TmGlobal *pGlobal;
|
||||
LsmMutex *pMutex;
|
||||
assert( pEnv->pMemCtx==0 );
|
||||
|
||||
/* Allocate and populate a TmGlobal structure. */
|
||||
pGlobal = (TmGlobal *)tmLsmMalloc(sizeof(TmGlobal));
|
||||
memset(pGlobal, 0, sizeof(TmGlobal));
|
||||
pGlobal->xMalloc = tmLsmMalloc;
|
||||
pGlobal->xRealloc = tmLsmRealloc;
|
||||
pGlobal->xFree = tmLsmFree;
|
||||
pMutex = (LsmMutex *)pGlobal->xMalloc(sizeof(LsmMutex));
|
||||
pMutex->pEnv = pEnv;
|
||||
pEnv->xMutexStatic(pEnv, LSM_MUTEX_HEAP, &pMutex->pMutex);
|
||||
pGlobal->xEnterMutex = tmLsmMutexEnter;
|
||||
pGlobal->xLeaveMutex = tmLsmMutexLeave;
|
||||
pGlobal->xDelMutex = tmLsmMutexDel;
|
||||
pGlobal->pMutex = (void *)pMutex;
|
||||
|
||||
pGlobal->xSaveMalloc = pEnv->xMalloc;
|
||||
pGlobal->xSaveRealloc = pEnv->xRealloc;
|
||||
pGlobal->xSaveFree = pEnv->xFree;
|
||||
|
||||
/* Set up pEnv to the use the new TmGlobal */
|
||||
pEnv->pMemCtx = (void *)pGlobal;
|
||||
pEnv->xMalloc = tmLsmEnvMalloc;
|
||||
pEnv->xRealloc = tmLsmEnvRealloc;
|
||||
pEnv->xFree = tmLsmEnvFree;
|
||||
}
|
||||
|
||||
void testMallocUninstall(lsm_env *pEnv){
|
||||
TmGlobal *p = (TmGlobal *)pEnv->pMemCtx;
|
||||
pEnv->pMemCtx = 0;
|
||||
if( p ){
|
||||
pEnv->xMalloc = p->xSaveMalloc;
|
||||
pEnv->xRealloc = p->xSaveRealloc;
|
||||
pEnv->xFree = p->xSaveFree;
|
||||
p->xDelMutex(p);
|
||||
tmLsmFree(p);
|
||||
}
|
||||
}
|
||||
|
||||
void testMallocCheck(
|
||||
lsm_env *pEnv,
|
||||
int *pnLeakAlloc,
|
||||
int *pnLeakByte,
|
||||
FILE *pFile
|
||||
){
|
||||
if( pEnv->pMemCtx==0 ){
|
||||
*pnLeakAlloc = 0;
|
||||
*pnLeakByte = 0;
|
||||
}else{
|
||||
tmMallocCheck((TmGlobal *)(pEnv->pMemCtx), pnLeakAlloc, pnLeakByte, pFile);
|
||||
}
|
||||
}
|
||||
|
||||
void testMallocOom(
|
||||
lsm_env *pEnv,
|
||||
int nCountdown,
|
||||
int bPersist,
|
||||
void (*xHook)(void *),
|
||||
void *pHookCtx
|
||||
){
|
||||
TmGlobal *pTm = (TmGlobal *)(pEnv->pMemCtx);
|
||||
tmMallocOom(pTm, nCountdown, bPersist, xHook, pHookCtx);
|
||||
}
|
||||
|
||||
void testMallocOomEnable(lsm_env *pEnv, int bEnable){
|
||||
TmGlobal *pTm = (TmGlobal *)(pEnv->pMemCtx);
|
||||
tmMallocOomEnable(pTm, bEnable);
|
||||
}
|
||||
@@ -1,846 +0,0 @@
|
||||
|
||||
/*
|
||||
** This program attempts to test the correctness of some facets of the
|
||||
** LSM database library. Specifically, that the contents of the database
|
||||
** are maintained correctly during a series of inserts and deletes.
|
||||
*/
|
||||
|
||||
|
||||
#include "lsmtest_tdb.h"
|
||||
#include "lsm.h"
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
typedef struct SqlDb SqlDb;
|
||||
|
||||
static int error_transaction_function(TestDb *p, int iLevel){
|
||||
unused_parameter(p);
|
||||
unused_parameter(iLevel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
** Begin wrapper for LevelDB.
|
||||
*/
|
||||
#ifdef HAVE_LEVELDB
|
||||
|
||||
#include <leveldb/c.h>
|
||||
|
||||
typedef struct LevelDb LevelDb;
|
||||
struct LevelDb {
|
||||
TestDb base;
|
||||
leveldb_t *db;
|
||||
leveldb_options_t *pOpt;
|
||||
leveldb_writeoptions_t *pWriteOpt;
|
||||
leveldb_readoptions_t *pReadOpt;
|
||||
|
||||
char *pVal;
|
||||
};
|
||||
|
||||
static int test_leveldb_close(TestDb *pTestDb){
|
||||
LevelDb *pDb = (LevelDb *)pTestDb;
|
||||
|
||||
leveldb_close(pDb->db);
|
||||
leveldb_writeoptions_destroy(pDb->pWriteOpt);
|
||||
leveldb_readoptions_destroy(pDb->pReadOpt);
|
||||
leveldb_options_destroy(pDb->pOpt);
|
||||
free(pDb->pVal);
|
||||
free(pDb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_leveldb_write(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void *pVal,
|
||||
int nVal
|
||||
){
|
||||
LevelDb *pDb = (LevelDb *)pTestDb;
|
||||
char *zErr = 0;
|
||||
leveldb_put(pDb->db, pDb->pWriteOpt, pKey, nKey, pVal, nVal, &zErr);
|
||||
return (zErr!=0);
|
||||
}
|
||||
|
||||
static int test_leveldb_delete(TestDb *pTestDb, void *pKey, int nKey){
|
||||
LevelDb *pDb = (LevelDb *)pTestDb;
|
||||
char *zErr = 0;
|
||||
leveldb_delete(pDb->db, pDb->pWriteOpt, pKey, nKey, &zErr);
|
||||
return (zErr!=0);
|
||||
}
|
||||
|
||||
static int test_leveldb_fetch(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void **ppVal,
|
||||
int *pnVal
|
||||
){
|
||||
LevelDb *pDb = (LevelDb *)pTestDb;
|
||||
char *zErr = 0;
|
||||
size_t nVal = 0;
|
||||
|
||||
if( pKey==0 ) return 0;
|
||||
free(pDb->pVal);
|
||||
pDb->pVal = leveldb_get(pDb->db, pDb->pReadOpt, pKey, nKey, &nVal, &zErr);
|
||||
*ppVal = (void *)(pDb->pVal);
|
||||
if( pDb->pVal==0 ){
|
||||
*pnVal = -1;
|
||||
}else{
|
||||
*pnVal = (int)nVal;
|
||||
}
|
||||
|
||||
return (zErr!=0);
|
||||
}
|
||||
|
||||
static int test_leveldb_scan(
|
||||
TestDb *pTestDb,
|
||||
void *pCtx,
|
||||
int bReverse,
|
||||
void *pKey1, int nKey1, /* Start of search */
|
||||
void *pKey2, int nKey2, /* End of search */
|
||||
void (*xCallback)(void *, void *, int , void *, int)
|
||||
){
|
||||
LevelDb *pDb = (LevelDb *)pTestDb;
|
||||
leveldb_iterator_t *iter;
|
||||
|
||||
iter = leveldb_create_iterator(pDb->db, pDb->pReadOpt);
|
||||
|
||||
if( bReverse==0 ){
|
||||
if( pKey1 ){
|
||||
leveldb_iter_seek(iter, pKey1, nKey1);
|
||||
}else{
|
||||
leveldb_iter_seek_to_first(iter);
|
||||
}
|
||||
}else{
|
||||
if( pKey2 ){
|
||||
leveldb_iter_seek(iter, pKey2, nKey2);
|
||||
|
||||
if( leveldb_iter_valid(iter)==0 ){
|
||||
leveldb_iter_seek_to_last(iter);
|
||||
}else{
|
||||
const char *k; size_t n;
|
||||
int res;
|
||||
k = leveldb_iter_key(iter, &n);
|
||||
res = memcmp(k, pKey2, MIN(n, nKey2));
|
||||
if( res==0 ) res = n - nKey2;
|
||||
assert( res>=0 );
|
||||
if( res>0 ){
|
||||
leveldb_iter_prev(iter);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
leveldb_iter_seek_to_last(iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while( leveldb_iter_valid(iter) ){
|
||||
const char *k; size_t n;
|
||||
const char *v; size_t n2;
|
||||
int res;
|
||||
|
||||
k = leveldb_iter_key(iter, &n);
|
||||
if( bReverse==0 && pKey2 ){
|
||||
res = memcmp(k, pKey2, MIN(n, nKey2));
|
||||
if( res==0 ) res = n - nKey2;
|
||||
if( res>0 ) break;
|
||||
}
|
||||
if( bReverse!=0 && pKey1 ){
|
||||
res = memcmp(k, pKey1, MIN(n, nKey1));
|
||||
if( res==0 ) res = n - nKey1;
|
||||
if( res<0 ) break;
|
||||
}
|
||||
|
||||
v = leveldb_iter_value(iter, &n2);
|
||||
|
||||
xCallback(pCtx, (void *)k, n, (void *)v, n2);
|
||||
|
||||
if( bReverse==0 ){
|
||||
leveldb_iter_next(iter);
|
||||
}else{
|
||||
leveldb_iter_prev(iter);
|
||||
}
|
||||
}
|
||||
|
||||
leveldb_iter_destroy(iter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_leveldb_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
static const DatabaseMethods LeveldbMethods = {
|
||||
test_leveldb_close,
|
||||
test_leveldb_write,
|
||||
test_leveldb_delete,
|
||||
0,
|
||||
test_leveldb_fetch,
|
||||
test_leveldb_scan,
|
||||
error_transaction_function,
|
||||
error_transaction_function,
|
||||
error_transaction_function
|
||||
};
|
||||
|
||||
LevelDb *pLevelDb;
|
||||
char *zErr = 0;
|
||||
|
||||
if( bClear ){
|
||||
char *zCmd = sqlite3_mprintf("rm -rf %s\n", zFilename);
|
||||
system(zCmd);
|
||||
sqlite3_free(zCmd);
|
||||
}
|
||||
|
||||
pLevelDb = (LevelDb *)malloc(sizeof(LevelDb));
|
||||
memset(pLevelDb, 0, sizeof(LevelDb));
|
||||
|
||||
pLevelDb->pOpt = leveldb_options_create();
|
||||
leveldb_options_set_create_if_missing(pLevelDb->pOpt, 1);
|
||||
pLevelDb->pWriteOpt = leveldb_writeoptions_create();
|
||||
pLevelDb->pReadOpt = leveldb_readoptions_create();
|
||||
|
||||
pLevelDb->db = leveldb_open(pLevelDb->pOpt, zFilename, &zErr);
|
||||
|
||||
if( zErr ){
|
||||
test_leveldb_close((TestDb *)pLevelDb);
|
||||
*ppDb = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*ppDb = (TestDb *)pLevelDb;
|
||||
pLevelDb->base.pMethods = &LeveldbMethods;
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_LEVELDB */
|
||||
/*
|
||||
** End wrapper for LevelDB.
|
||||
*************************************************************************/
|
||||
|
||||
#ifdef HAVE_KYOTOCABINET
|
||||
static int kc_close(TestDb *pTestDb){
|
||||
return test_kc_close(pTestDb);
|
||||
}
|
||||
|
||||
static int kc_write(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void *pVal,
|
||||
int nVal
|
||||
){
|
||||
return test_kc_write(pTestDb, pKey, nKey, pVal, nVal);
|
||||
}
|
||||
|
||||
static int kc_delete(TestDb *pTestDb, void *pKey, int nKey){
|
||||
return test_kc_delete(pTestDb, pKey, nKey);
|
||||
}
|
||||
|
||||
static int kc_delete_range(
|
||||
TestDb *pTestDb,
|
||||
void *pKey1, int nKey1,
|
||||
void *pKey2, int nKey2
|
||||
){
|
||||
return test_kc_delete_range(pTestDb, pKey1, nKey1, pKey2, nKey2);
|
||||
}
|
||||
|
||||
static int kc_fetch(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void **ppVal,
|
||||
int *pnVal
|
||||
){
|
||||
if( pKey==0 ) return LSM_OK;
|
||||
return test_kc_fetch(pTestDb, pKey, nKey, ppVal, pnVal);
|
||||
}
|
||||
|
||||
static int kc_scan(
|
||||
TestDb *pTestDb,
|
||||
void *pCtx,
|
||||
int bReverse,
|
||||
void *pFirst, int nFirst,
|
||||
void *pLast, int nLast,
|
||||
void (*xCallback)(void *, void *, int , void *, int)
|
||||
){
|
||||
return test_kc_scan(
|
||||
pTestDb, pCtx, bReverse, pFirst, nFirst, pLast, nLast, xCallback
|
||||
);
|
||||
}
|
||||
|
||||
static int kc_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
static const DatabaseMethods KcdbMethods = {
|
||||
kc_close,
|
||||
kc_write,
|
||||
kc_delete,
|
||||
kc_delete_range,
|
||||
kc_fetch,
|
||||
kc_scan,
|
||||
error_transaction_function,
|
||||
error_transaction_function,
|
||||
error_transaction_function
|
||||
};
|
||||
|
||||
int rc;
|
||||
TestDb *pTestDb = 0;
|
||||
|
||||
rc = test_kc_open(zFilename, bClear, &pTestDb);
|
||||
if( rc!=0 ){
|
||||
*ppDb = 0;
|
||||
return rc;
|
||||
}
|
||||
pTestDb->pMethods = &KcdbMethods;
|
||||
*ppDb = pTestDb;
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_KYOTOCABINET */
|
||||
/*
|
||||
** End wrapper for Kyoto cabinet.
|
||||
*************************************************************************/
|
||||
|
||||
#ifdef HAVE_MDB
|
||||
static int mdb_close(TestDb *pTestDb){
|
||||
return test_mdb_close(pTestDb);
|
||||
}
|
||||
|
||||
static int mdb_write(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void *pVal,
|
||||
int nVal
|
||||
){
|
||||
return test_mdb_write(pTestDb, pKey, nKey, pVal, nVal);
|
||||
}
|
||||
|
||||
static int mdb_delete(TestDb *pTestDb, void *pKey, int nKey){
|
||||
return test_mdb_delete(pTestDb, pKey, nKey);
|
||||
}
|
||||
|
||||
static int mdb_fetch(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void **ppVal,
|
||||
int *pnVal
|
||||
){
|
||||
if( pKey==0 ) return LSM_OK;
|
||||
return test_mdb_fetch(pTestDb, pKey, nKey, ppVal, pnVal);
|
||||
}
|
||||
|
||||
static int mdb_scan(
|
||||
TestDb *pTestDb,
|
||||
void *pCtx,
|
||||
int bReverse,
|
||||
void *pFirst, int nFirst,
|
||||
void *pLast, int nLast,
|
||||
void (*xCallback)(void *, void *, int , void *, int)
|
||||
){
|
||||
return test_mdb_scan(
|
||||
pTestDb, pCtx, bReverse, pFirst, nFirst, pLast, nLast, xCallback
|
||||
);
|
||||
}
|
||||
|
||||
static int mdb_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
static const DatabaseMethods KcdbMethods = {
|
||||
mdb_close,
|
||||
mdb_write,
|
||||
mdb_delete,
|
||||
0,
|
||||
mdb_fetch,
|
||||
mdb_scan,
|
||||
error_transaction_function,
|
||||
error_transaction_function,
|
||||
error_transaction_function
|
||||
};
|
||||
|
||||
int rc;
|
||||
TestDb *pTestDb = 0;
|
||||
|
||||
rc = test_mdb_open(zSpec, zFilename, bClear, &pTestDb);
|
||||
if( rc!=0 ){
|
||||
*ppDb = 0;
|
||||
return rc;
|
||||
}
|
||||
pTestDb->pMethods = &KcdbMethods;
|
||||
*ppDb = pTestDb;
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_MDB */
|
||||
|
||||
/*************************************************************************
|
||||
** Begin wrapper for SQLite.
|
||||
*/
|
||||
|
||||
/*
|
||||
** nOpenTrans:
|
||||
** The number of open nested transactions, in the same sense as used
|
||||
** by the tdb_begin/commit/rollback and SQLite 4 KV interfaces. If this
|
||||
** value is 0, there are no transactions open at all. If it is 1, then
|
||||
** there is a read transaction. If it is 2 or greater, then there are
|
||||
** (nOpenTrans-1) nested write transactions open.
|
||||
*/
|
||||
struct SqlDb {
|
||||
TestDb base;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *pInsert;
|
||||
sqlite3_stmt *pDelete;
|
||||
sqlite3_stmt *pDeleteRange;
|
||||
sqlite3_stmt *pFetch;
|
||||
sqlite3_stmt *apScan[8];
|
||||
|
||||
int nOpenTrans;
|
||||
|
||||
/* Used by sql_fetch() to allocate space for results */
|
||||
int nAlloc;
|
||||
u8 *aAlloc;
|
||||
};
|
||||
|
||||
static int sql_close(TestDb *pTestDb){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
sqlite3_finalize(pDb->pInsert);
|
||||
sqlite3_finalize(pDb->pDelete);
|
||||
sqlite3_finalize(pDb->pDeleteRange);
|
||||
sqlite3_finalize(pDb->pFetch);
|
||||
sqlite3_finalize(pDb->apScan[0]);
|
||||
sqlite3_finalize(pDb->apScan[1]);
|
||||
sqlite3_finalize(pDb->apScan[2]);
|
||||
sqlite3_finalize(pDb->apScan[3]);
|
||||
sqlite3_finalize(pDb->apScan[4]);
|
||||
sqlite3_finalize(pDb->apScan[5]);
|
||||
sqlite3_finalize(pDb->apScan[6]);
|
||||
sqlite3_finalize(pDb->apScan[7]);
|
||||
sqlite3_close(pDb->db);
|
||||
free((char *)pDb->aAlloc);
|
||||
free((char *)pDb);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int sql_write(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void *pVal,
|
||||
int nVal
|
||||
){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
sqlite3_bind_blob(pDb->pInsert, 1, pKey, nKey, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(pDb->pInsert, 2, pVal, nVal, SQLITE_STATIC);
|
||||
sqlite3_step(pDb->pInsert);
|
||||
return sqlite3_reset(pDb->pInsert);
|
||||
}
|
||||
|
||||
static int sql_delete(TestDb *pTestDb, void *pKey, int nKey){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
sqlite3_bind_blob(pDb->pDelete, 1, pKey, nKey, SQLITE_STATIC);
|
||||
sqlite3_step(pDb->pDelete);
|
||||
return sqlite3_reset(pDb->pDelete);
|
||||
}
|
||||
|
||||
static int sql_delete_range(
|
||||
TestDb *pTestDb,
|
||||
void *pKey1, int nKey1,
|
||||
void *pKey2, int nKey2
|
||||
){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
sqlite3_bind_blob(pDb->pDeleteRange, 1, pKey1, nKey1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(pDb->pDeleteRange, 2, pKey2, nKey2, SQLITE_STATIC);
|
||||
sqlite3_step(pDb->pDeleteRange);
|
||||
return sqlite3_reset(pDb->pDeleteRange);
|
||||
}
|
||||
|
||||
static int sql_fetch(
|
||||
TestDb *pTestDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void **ppVal,
|
||||
int *pnVal
|
||||
){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
int rc;
|
||||
|
||||
sqlite3_reset(pDb->pFetch);
|
||||
if( pKey==0 ){
|
||||
assert( ppVal==0 );
|
||||
assert( pnVal==0 );
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
sqlite3_bind_blob(pDb->pFetch, 1, pKey, nKey, SQLITE_STATIC);
|
||||
rc = sqlite3_step(pDb->pFetch);
|
||||
if( rc==SQLITE_ROW ){
|
||||
int nVal = sqlite3_column_bytes(pDb->pFetch, 0);
|
||||
u8 *aVal = (void *)sqlite3_column_blob(pDb->pFetch, 0);
|
||||
|
||||
if( nVal>pDb->nAlloc ){
|
||||
free(pDb->aAlloc);
|
||||
pDb->aAlloc = (u8 *)malloc(nVal*2);
|
||||
pDb->nAlloc = nVal*2;
|
||||
}
|
||||
memcpy(pDb->aAlloc, aVal, nVal);
|
||||
*pnVal = nVal;
|
||||
*ppVal = (void *)pDb->aAlloc;
|
||||
}else{
|
||||
*pnVal = -1;
|
||||
*ppVal = 0;
|
||||
}
|
||||
|
||||
rc = sqlite3_reset(pDb->pFetch);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int sql_scan(
|
||||
TestDb *pTestDb,
|
||||
void *pCtx,
|
||||
int bReverse,
|
||||
void *pFirst, int nFirst,
|
||||
void *pLast, int nLast,
|
||||
void (*xCallback)(void *, void *, int , void *, int)
|
||||
){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
sqlite3_stmt *pScan;
|
||||
|
||||
assert( bReverse==1 || bReverse==0 );
|
||||
pScan = pDb->apScan[(pFirst==0) + (pLast==0)*2 + bReverse*4];
|
||||
|
||||
if( pFirst ) sqlite3_bind_blob(pScan, 1, pFirst, nFirst, SQLITE_STATIC);
|
||||
if( pLast ) sqlite3_bind_blob(pScan, 2, pLast, nLast, SQLITE_STATIC);
|
||||
|
||||
while( SQLITE_ROW==sqlite3_step(pScan) ){
|
||||
void *pKey; int nKey;
|
||||
void *pVal; int nVal;
|
||||
|
||||
nKey = sqlite3_column_bytes(pScan, 0);
|
||||
pKey = (void *)sqlite3_column_blob(pScan, 0);
|
||||
nVal = sqlite3_column_bytes(pScan, 1);
|
||||
pVal = (void *)sqlite3_column_blob(pScan, 1);
|
||||
|
||||
xCallback(pCtx, pKey, nKey, pVal, nVal);
|
||||
}
|
||||
return sqlite3_reset(pScan);
|
||||
}
|
||||
|
||||
static int sql_begin(TestDb *pTestDb, int iLevel){
|
||||
int i;
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
|
||||
/* iLevel==0 is a no-op */
|
||||
if( iLevel==0 ) return 0;
|
||||
|
||||
/* If there are no transactions at all open, open a read transaction. */
|
||||
if( pDb->nOpenTrans==0 ){
|
||||
int rc = sqlite3_exec(pDb->db,
|
||||
"BEGIN; SELECT * FROM sqlite_schema LIMIT 1;" , 0, 0, 0
|
||||
);
|
||||
if( rc!=0 ) return rc;
|
||||
pDb->nOpenTrans = 1;
|
||||
}
|
||||
|
||||
/* Open any required write transactions */
|
||||
for(i=pDb->nOpenTrans; i<iLevel; i++){
|
||||
char *zSql = sqlite3_mprintf("SAVEPOINT x%d", i);
|
||||
int rc = sqlite3_exec(pDb->db, zSql, 0, 0, 0);
|
||||
sqlite3_free(zSql);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
pDb->nOpenTrans = iLevel;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sql_commit(TestDb *pTestDb, int iLevel){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
assert( iLevel>=0 );
|
||||
|
||||
/* Close the read transaction if requested. */
|
||||
if( pDb->nOpenTrans>=1 && iLevel==0 ){
|
||||
int rc = sqlite3_exec(pDb->db, "COMMIT", 0, 0, 0);
|
||||
if( rc!=0 ) return rc;
|
||||
pDb->nOpenTrans = 0;
|
||||
}
|
||||
|
||||
/* Close write transactions as required */
|
||||
if( pDb->nOpenTrans>iLevel ){
|
||||
char *zSql = sqlite3_mprintf("RELEASE x%d", iLevel);
|
||||
int rc = sqlite3_exec(pDb->db, zSql, 0, 0, 0);
|
||||
sqlite3_free(zSql);
|
||||
if( rc!=0 ) return rc;
|
||||
}
|
||||
|
||||
pDb->nOpenTrans = iLevel;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sql_rollback(TestDb *pTestDb, int iLevel){
|
||||
SqlDb *pDb = (SqlDb *)pTestDb;
|
||||
assert( iLevel>=0 );
|
||||
|
||||
if( pDb->nOpenTrans>=1 && iLevel==0 ){
|
||||
/* Close the read transaction if requested. */
|
||||
int rc = sqlite3_exec(pDb->db, "ROLLBACK", 0, 0, 0);
|
||||
if( rc!=0 ) return rc;
|
||||
}else if( pDb->nOpenTrans>1 && iLevel==1 ){
|
||||
/* Or, rollback and close the top-level write transaction */
|
||||
int rc = sqlite3_exec(pDb->db, "ROLLBACK TO x1; RELEASE x1;", 0, 0, 0);
|
||||
if( rc!=0 ) return rc;
|
||||
}else{
|
||||
/* Or, just roll back some nested transactions */
|
||||
char *zSql = sqlite3_mprintf("ROLLBACK TO x%d", iLevel-1);
|
||||
int rc = sqlite3_exec(pDb->db, zSql, 0, 0, 0);
|
||||
sqlite3_free(zSql);
|
||||
if( rc!=0 ) return rc;
|
||||
}
|
||||
|
||||
pDb->nOpenTrans = iLevel;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sql_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
static const DatabaseMethods SqlMethods = {
|
||||
sql_close,
|
||||
sql_write,
|
||||
sql_delete,
|
||||
sql_delete_range,
|
||||
sql_fetch,
|
||||
sql_scan,
|
||||
sql_begin,
|
||||
sql_commit,
|
||||
sql_rollback
|
||||
};
|
||||
const char *zCreate = "CREATE TABLE IF NOT EXISTS t1(k PRIMARY KEY, v)";
|
||||
const char *zInsert = "REPLACE INTO t1 VALUES(?, ?)";
|
||||
const char *zDelete = "DELETE FROM t1 WHERE k = ?";
|
||||
const char *zRange = "DELETE FROM t1 WHERE k>? AND k<?";
|
||||
const char *zFetch = "SELECT v FROM t1 WHERE k = ?";
|
||||
|
||||
const char *zScan0 = "SELECT * FROM t1 WHERE k BETWEEN ?1 AND ?2 ORDER BY k";
|
||||
const char *zScan1 = "SELECT * FROM t1 WHERE k <= ?2 ORDER BY k";
|
||||
const char *zScan2 = "SELECT * FROM t1 WHERE k >= ?1 ORDER BY k";
|
||||
const char *zScan3 = "SELECT * FROM t1 ORDER BY k";
|
||||
|
||||
const char *zScan4 =
|
||||
"SELECT * FROM t1 WHERE k BETWEEN ?1 AND ?2 ORDER BY k DESC";
|
||||
const char *zScan5 = "SELECT * FROM t1 WHERE k <= ?2 ORDER BY k DESC";
|
||||
const char *zScan6 = "SELECT * FROM t1 WHERE k >= ?1 ORDER BY k DESC";
|
||||
const char *zScan7 = "SELECT * FROM t1 ORDER BY k DESC";
|
||||
|
||||
int rc;
|
||||
SqlDb *pDb;
|
||||
char *zPragma;
|
||||
|
||||
if( bClear && zFilename && zFilename[0] ){
|
||||
unlink(zFilename);
|
||||
}
|
||||
|
||||
pDb = (SqlDb *)malloc(sizeof(SqlDb));
|
||||
memset(pDb, 0, sizeof(SqlDb));
|
||||
pDb->base.pMethods = &SqlMethods;
|
||||
|
||||
if( 0!=(rc = sqlite3_open(zFilename, &pDb->db))
|
||||
|| 0!=(rc = sqlite3_exec(pDb->db, zCreate, 0, 0, 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zInsert, -1, &pDb->pInsert, 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zDelete, -1, &pDb->pDelete, 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zRange, -1, &pDb->pDeleteRange, 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zFetch, -1, &pDb->pFetch, 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan0, -1, &pDb->apScan[0], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan1, -1, &pDb->apScan[1], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan2, -1, &pDb->apScan[2], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan3, -1, &pDb->apScan[3], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan4, -1, &pDb->apScan[4], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan5, -1, &pDb->apScan[5], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan6, -1, &pDb->apScan[6], 0))
|
||||
|| 0!=(rc = sqlite3_prepare_v2(pDb->db, zScan7, -1, &pDb->apScan[7], 0))
|
||||
){
|
||||
*ppDb = 0;
|
||||
sql_close((TestDb *)pDb);
|
||||
return rc;
|
||||
}
|
||||
|
||||
zPragma = sqlite3_mprintf("PRAGMA page_size=%d", TESTDB_DEFAULT_PAGE_SIZE);
|
||||
sqlite3_exec(pDb->db, zPragma, 0, 0, 0);
|
||||
sqlite3_free(zPragma);
|
||||
zPragma = sqlite3_mprintf("PRAGMA cache_size=%d", TESTDB_DEFAULT_CACHE_SIZE);
|
||||
sqlite3_exec(pDb->db, zPragma, 0, 0, 0);
|
||||
sqlite3_free(zPragma);
|
||||
|
||||
/* sqlite3_exec(pDb->db, "PRAGMA locking_mode=EXCLUSIVE", 0, 0, 0); */
|
||||
sqlite3_exec(pDb->db, "PRAGMA synchronous=OFF", 0, 0, 0);
|
||||
sqlite3_exec(pDb->db, "PRAGMA journal_mode=WAL", 0, 0, 0);
|
||||
sqlite3_exec(pDb->db, "PRAGMA wal_autocheckpoint=4096", 0, 0, 0);
|
||||
if( zSpec ){
|
||||
rc = sqlite3_exec(pDb->db, zSpec, 0, 0, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sql_close((TestDb *)pDb);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
*ppDb = (TestDb *)pDb;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
** End wrapper for SQLite.
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
** Begin exported functions.
|
||||
*/
|
||||
static struct Lib {
|
||||
const char *zName;
|
||||
const char *zDefaultDb;
|
||||
int (*xOpen)(const char *, const char *zFilename, int bClear, TestDb **ppDb);
|
||||
} aLib[] = {
|
||||
{ "sqlite3", "testdb.sqlite", sql_open },
|
||||
{ "lsm_small", "testdb.lsm_small", test_lsm_small_open },
|
||||
{ "lsm_lomem", "testdb.lsm_lomem", test_lsm_lomem_open },
|
||||
{ "lsm_lomem2", "testdb.lsm_lomem2", test_lsm_lomem2_open },
|
||||
#ifdef HAVE_ZLIB
|
||||
{ "lsm_zip", "testdb.lsm_zip", test_lsm_zip_open },
|
||||
#endif
|
||||
{ "lsm", "testdb.lsm", test_lsm_open },
|
||||
#ifdef LSM_MUTEX_PTHREADS
|
||||
{ "lsm_mt2", "testdb.lsm_mt2", test_lsm_mt2 },
|
||||
{ "lsm_mt3", "testdb.lsm_mt3", test_lsm_mt3 },
|
||||
#endif
|
||||
#ifdef HAVE_LEVELDB
|
||||
{ "leveldb", "testdb.leveldb", test_leveldb_open },
|
||||
#endif
|
||||
#ifdef HAVE_KYOTOCABINET
|
||||
{ "kyotocabinet", "testdb.kc", kc_open },
|
||||
#endif
|
||||
#ifdef HAVE_MDB
|
||||
{ "mdb", "./testdb.mdb", mdb_open }
|
||||
#endif
|
||||
};
|
||||
|
||||
const char *tdb_system_name(int i){
|
||||
if( i<0 || i>=ArraySize(aLib) ) return 0;
|
||||
return aLib[i].zName;
|
||||
}
|
||||
|
||||
const char *tdb_default_db(const char *zSys){
|
||||
int i;
|
||||
for(i=0; i<ArraySize(aLib); i++){
|
||||
if( strcmp(aLib[i].zName, zSys)==0 ) return aLib[i].zDefaultDb;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdb_open(const char *zLib, const char *zDb, int bClear, TestDb **ppDb){
|
||||
int i;
|
||||
int rc = 1;
|
||||
const char *zSpec = 0;
|
||||
|
||||
int nLib = 0;
|
||||
while( zLib[nLib] && zLib[nLib]!=' ' ){
|
||||
nLib++;
|
||||
}
|
||||
zSpec = &zLib[nLib];
|
||||
while( *zSpec==' ' ) zSpec++;
|
||||
if( *zSpec=='\0' ) zSpec = 0;
|
||||
|
||||
for(i=0; i<ArraySize(aLib); i++){
|
||||
if( (int)strlen(aLib[i].zName)==nLib
|
||||
&& 0==memcmp(zLib, aLib[i].zName, nLib) ){
|
||||
rc = aLib[i].xOpen(zSpec, (zDb ? zDb : aLib[i].zDefaultDb), bClear, ppDb);
|
||||
if( rc==0 ){
|
||||
(*ppDb)->zLibrary = aLib[i].zName;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( rc ){
|
||||
/* Failed to find the requested database library. Return an error. */
|
||||
*ppDb = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int tdb_close(TestDb *pDb){
|
||||
if( pDb ){
|
||||
return pDb->pMethods->xClose(pDb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdb_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal){
|
||||
return pDb->pMethods->xWrite(pDb, pKey, nKey, pVal, nVal);
|
||||
}
|
||||
|
||||
int tdb_delete(TestDb *pDb, void *pKey, int nKey){
|
||||
return pDb->pMethods->xDelete(pDb, pKey, nKey);
|
||||
}
|
||||
|
||||
int tdb_delete_range(
|
||||
TestDb *pDb, void *pKey1, int nKey1, void *pKey2, int nKey2
|
||||
){
|
||||
return pDb->pMethods->xDeleteRange(pDb, pKey1, nKey1, pKey2, nKey2);
|
||||
}
|
||||
|
||||
int tdb_fetch(TestDb *pDb, void *pKey, int nKey, void **ppVal, int *pnVal){
|
||||
return pDb->pMethods->xFetch(pDb, pKey, nKey, ppVal, pnVal);
|
||||
}
|
||||
|
||||
int tdb_scan(
|
||||
TestDb *pDb, /* Database handle */
|
||||
void *pCtx, /* Context pointer to pass to xCallback */
|
||||
int bReverse, /* True to scan in reverse order */
|
||||
void *pKey1, int nKey1, /* Start of search */
|
||||
void *pKey2, int nKey2, /* End of search */
|
||||
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
|
||||
){
|
||||
return pDb->pMethods->xScan(
|
||||
pDb, pCtx, bReverse, pKey1, nKey1, pKey2, nKey2, xCallback
|
||||
);
|
||||
}
|
||||
|
||||
int tdb_begin(TestDb *pDb, int iLevel){
|
||||
return pDb->pMethods->xBegin(pDb, iLevel);
|
||||
}
|
||||
int tdb_commit(TestDb *pDb, int iLevel){
|
||||
return pDb->pMethods->xCommit(pDb, iLevel);
|
||||
}
|
||||
int tdb_rollback(TestDb *pDb, int iLevel){
|
||||
return pDb->pMethods->xRollback(pDb, iLevel);
|
||||
}
|
||||
|
||||
int tdb_transaction_support(TestDb *pDb){
|
||||
return (pDb->pMethods->xBegin != error_transaction_function);
|
||||
}
|
||||
|
||||
const char *tdb_library_name(TestDb *pDb){
|
||||
return pDb->zLibrary;
|
||||
}
|
||||
|
||||
/*
|
||||
** End exported functions.
|
||||
*************************************************************************/
|
||||
@@ -1,174 +0,0 @@
|
||||
|
||||
/*
|
||||
** This file is the interface to a very simple database library used for
|
||||
** testing. The interface is similar to that of the LSM. The main virtue
|
||||
** of this library is that the same API may be used to access a key-value
|
||||
** store implemented by LSM, SQLite or another database system. Which
|
||||
** makes it easy to use for correctness and performance tests.
|
||||
*/
|
||||
|
||||
#ifndef __WRAPPER_H_
|
||||
#define __WRAPPER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lsm.h"
|
||||
|
||||
typedef struct TestDb TestDb;
|
||||
|
||||
/*
|
||||
** Open a new database connection. The first argument is the name of the
|
||||
** database library to use. e.g. something like:
|
||||
**
|
||||
** "sqlite3"
|
||||
** "lsm"
|
||||
**
|
||||
** See function tdb_system_name() for a list of available database systems.
|
||||
**
|
||||
** The second argument is the name of the database to open (e.g. a filename).
|
||||
**
|
||||
** If the third parameter is non-zero, then any existing database by the
|
||||
** name of zDb is removed before opening a new one. If it is zero, then an
|
||||
** existing database may be opened.
|
||||
*/
|
||||
int tdb_open(const char *zLibrary, const char *zDb, int bClear, TestDb **ppDb);
|
||||
|
||||
/*
|
||||
** Close a database handle.
|
||||
*/
|
||||
int tdb_close(TestDb *pDb);
|
||||
|
||||
/*
|
||||
** Write a new key/value into the database.
|
||||
*/
|
||||
int tdb_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal);
|
||||
|
||||
/*
|
||||
** Delete a key from the database.
|
||||
*/
|
||||
int tdb_delete(TestDb *pDb, void *pKey, int nKey);
|
||||
|
||||
/*
|
||||
** Delete a range of keys from the database.
|
||||
*/
|
||||
int tdb_delete_range(TestDb *, void *pKey1, int nKey1, void *pKey2, int nKey2);
|
||||
|
||||
/*
|
||||
** Query the database for key (pKey/nKey). If no entry is found, set *ppVal
|
||||
** to 0 and *pnVal to -1 before returning. Otherwise, set *ppVal and *pnVal
|
||||
** to a pointer to and size of the value associated with (pKey/nKey).
|
||||
*/
|
||||
int tdb_fetch(TestDb *pDb, void *pKey, int nKey, void **ppVal, int *pnVal);
|
||||
|
||||
/*
|
||||
** Open and close nested transactions. Currently, these functions only
|
||||
** work for SQLite3 and LSM systems. Use the tdb_transaction_support()
|
||||
** function to determine if a given TestDb handle supports these methods.
|
||||
**
|
||||
** These functions and the iLevel parameter follow the same conventions as
|
||||
** the SQLite 4 transaction interface. Note that this is slightly different
|
||||
** from the way LSM does things. As follows:
|
||||
**
|
||||
** tdb_begin():
|
||||
** A successful call to tdb_begin() with (iLevel>1) guarantees that
|
||||
** there are at least (iLevel-1) write transactions open. If iLevel==1,
|
||||
** then it guarantees that at least a read-transaction is open. Calling
|
||||
** tdb_begin() with iLevel==0 is a no-op.
|
||||
**
|
||||
** tdb_commit():
|
||||
** A successful call to tdb_commit() with (iLevel>1) guarantees that
|
||||
** there are at most (iLevel-1) write transactions open. If iLevel==1,
|
||||
** then it guarantees that there are no write transactions open (although
|
||||
** a read-transaction may remain open). Calling tdb_commit() with
|
||||
** iLevel==0 ensures that all transactions, read or write, have been
|
||||
** closed and committed.
|
||||
**
|
||||
** tdb_rollback():
|
||||
** This call is similar to tdb_commit(), except that instead of committing
|
||||
** transactions, it reverts them. For example, calling tdb_rollback() with
|
||||
** iLevel==2 ensures that there is at most one write transaction open, and
|
||||
** restores the database to the state that it was in when that transaction
|
||||
** was opened.
|
||||
**
|
||||
** In other words, tdb_commit() just closes transactions - tdb_rollback()
|
||||
** closes transactions and then restores the database to the state it
|
||||
** was in before those transactions were even opened.
|
||||
*/
|
||||
int tdb_begin(TestDb *pDb, int iLevel);
|
||||
int tdb_commit(TestDb *pDb, int iLevel);
|
||||
int tdb_rollback(TestDb *pDb, int iLevel);
|
||||
|
||||
/*
|
||||
** Return true if transactions are supported, or false otherwise.
|
||||
*/
|
||||
int tdb_transaction_support(TestDb *pDb);
|
||||
|
||||
/*
|
||||
** Return the name of the database library (as passed to tdb_open()) used
|
||||
** by the handled passed as the first argument.
|
||||
*/
|
||||
const char *tdb_library_name(TestDb *pDb);
|
||||
|
||||
/*
|
||||
** Scan a range of database keys. Invoke the callback function for each
|
||||
** key visited.
|
||||
*/
|
||||
int tdb_scan(
|
||||
TestDb *pDb, /* Database handle */
|
||||
void *pCtx, /* Context pointer to pass to xCallback */
|
||||
int bReverse, /* True to scan in reverse order */
|
||||
void *pKey1, int nKey1, /* Start of search */
|
||||
void *pKey2, int nKey2, /* End of search */
|
||||
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
|
||||
);
|
||||
|
||||
const char *tdb_system_name(int i);
|
||||
const char *tdb_default_db(const char *zSys);
|
||||
|
||||
int tdb_lsm_open(const char *zCfg, const char *zDb, int bClear, TestDb **ppDb);
|
||||
|
||||
/*
|
||||
** If the TestDb handle passed as an argument is a wrapper around an LSM
|
||||
** database, return the LSM handle. Otherwise, if the argument is some other
|
||||
** database system, return NULL.
|
||||
*/
|
||||
lsm_db *tdb_lsm(TestDb *pDb);
|
||||
|
||||
/*
|
||||
** Return true if the db passed as an argument is a multi-threaded LSM
|
||||
** connection.
|
||||
*/
|
||||
int tdb_lsm_multithread(TestDb *pDb);
|
||||
|
||||
/*
|
||||
** Return a pointer to the lsm_env object used by all lsm database
|
||||
** connections initialized as a copy of the object returned by
|
||||
** lsm_default_env(). It may be modified (e.g. to override functions)
|
||||
** if the caller can guarantee that it is not already in use.
|
||||
*/
|
||||
lsm_env *tdb_lsm_env(void);
|
||||
|
||||
/*
|
||||
** The following functions only work with LSM database handles. It is
|
||||
** illegal to call them with any other type of database handle specified
|
||||
** as an argument.
|
||||
*/
|
||||
void tdb_lsm_enable_log(TestDb *pDb, int bEnable);
|
||||
void tdb_lsm_application_crash(TestDb *pDb);
|
||||
void tdb_lsm_prepare_system_crash(TestDb *pDb);
|
||||
void tdb_lsm_system_crash(TestDb *pDb);
|
||||
void tdb_lsm_prepare_sync_crash(TestDb *pDb, int iSync);
|
||||
|
||||
|
||||
void tdb_lsm_safety(TestDb *pDb, int eMode);
|
||||
void tdb_lsm_config_work_hook(TestDb *pDb, void (*)(lsm_db *, void *), void *);
|
||||
void tdb_lsm_write_hook(TestDb *, void(*)(void*,int,lsm_i64,int,int), void*);
|
||||
int tdb_lsm_config_str(TestDb *pDb, const char *zStr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* End of the 'extern "C"' block */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,369 +0,0 @@
|
||||
|
||||
|
||||
#include "lsmtest.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_KYOTOCABINET
|
||||
#include "kcpolydb.h"
|
||||
extern "C" {
|
||||
struct KcDb {
|
||||
TestDb base;
|
||||
kyotocabinet::TreeDB* db;
|
||||
char *pVal;
|
||||
};
|
||||
}
|
||||
|
||||
int test_kc_open(const char *zFilename, int bClear, TestDb **ppDb){
|
||||
KcDb *pKcDb;
|
||||
int ok;
|
||||
int rc = 0;
|
||||
|
||||
if( bClear ){
|
||||
char *zCmd = sqlite3_mprintf("rm -rf %s\n", zFilename);
|
||||
system(zCmd);
|
||||
sqlite3_free(zCmd);
|
||||
}
|
||||
|
||||
pKcDb = (KcDb *)malloc(sizeof(KcDb));
|
||||
memset(pKcDb, 0, sizeof(KcDb));
|
||||
|
||||
|
||||
pKcDb->db = new kyotocabinet::TreeDB();
|
||||
pKcDb->db->tune_page(TESTDB_DEFAULT_PAGE_SIZE);
|
||||
pKcDb->db->tune_page_cache(
|
||||
TESTDB_DEFAULT_PAGE_SIZE * TESTDB_DEFAULT_CACHE_SIZE
|
||||
);
|
||||
ok = pKcDb->db->open(zFilename,
|
||||
kyotocabinet::PolyDB::OWRITER | kyotocabinet::PolyDB::OCREATE
|
||||
);
|
||||
if( ok==0 ){
|
||||
free(pKcDb);
|
||||
pKcDb = 0;
|
||||
rc = 1;
|
||||
}
|
||||
|
||||
*ppDb = (TestDb *)pKcDb;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int test_kc_close(TestDb *pDb){
|
||||
KcDb *pKcDb = (KcDb *)pDb;
|
||||
if( pKcDb->pVal ){
|
||||
delete [] pKcDb->pVal;
|
||||
}
|
||||
pKcDb->db->close();
|
||||
delete pKcDb->db;
|
||||
free(pKcDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_kc_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal){
|
||||
KcDb *pKcDb = (KcDb *)pDb;
|
||||
int ok;
|
||||
|
||||
ok = pKcDb->db->set((const char *)pKey, nKey, (const char *)pVal, nVal);
|
||||
return (ok ? 0 : 1);
|
||||
}
|
||||
|
||||
int test_kc_delete(TestDb *pDb, void *pKey, int nKey){
|
||||
KcDb *pKcDb = (KcDb *)pDb;
|
||||
int ok;
|
||||
|
||||
ok = pKcDb->db->remove((const char *)pKey, nKey);
|
||||
return (ok ? 0 : 1);
|
||||
}
|
||||
|
||||
int test_kc_delete_range(
|
||||
TestDb *pDb,
|
||||
void *pKey1, int nKey1,
|
||||
void *pKey2, int nKey2
|
||||
){
|
||||
int res;
|
||||
KcDb *pKcDb = (KcDb *)pDb;
|
||||
kyotocabinet::DB::Cursor* pCur = pKcDb->db->cursor();
|
||||
|
||||
if( pKey1 ){
|
||||
res = pCur->jump((const char *)pKey1, nKey1);
|
||||
}else{
|
||||
res = pCur->jump();
|
||||
}
|
||||
|
||||
while( 1 ){
|
||||
const char *pKey; size_t nKey;
|
||||
const char *pVal; size_t nVal;
|
||||
|
||||
pKey = pCur->get(&nKey, &pVal, &nVal);
|
||||
if( pKey==0 ) break;
|
||||
|
||||
#ifndef NDEBUG
|
||||
if( pKey1 ){
|
||||
res = memcmp(pKey, pKey1, MIN((size_t)nKey1, nKey));
|
||||
assert( res>0 || (res==0 && nKey>nKey1) );
|
||||
}
|
||||
#endif
|
||||
|
||||
if( pKey2 ){
|
||||
res = memcmp(pKey, pKey2, MIN((size_t)nKey2, nKey));
|
||||
if( res>0 || (res==0 && (size_t)nKey2<nKey) ){
|
||||
delete [] pKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pCur->remove();
|
||||
delete [] pKey;
|
||||
}
|
||||
|
||||
delete pCur;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_kc_fetch(
|
||||
TestDb *pDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void **ppVal,
|
||||
int *pnVal
|
||||
){
|
||||
KcDb *pKcDb = (KcDb *)pDb;
|
||||
size_t nVal;
|
||||
|
||||
if( pKcDb->pVal ){
|
||||
delete [] pKcDb->pVal;
|
||||
pKcDb->pVal = 0;
|
||||
}
|
||||
|
||||
pKcDb->pVal = pKcDb->db->get((const char *)pKey, nKey, &nVal);
|
||||
if( pKcDb->pVal ){
|
||||
*ppVal = pKcDb->pVal;
|
||||
*pnVal = nVal;
|
||||
}else{
|
||||
*ppVal = 0;
|
||||
*pnVal = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_kc_scan(
|
||||
TestDb *pDb, /* Database handle */
|
||||
void *pCtx, /* Context pointer to pass to xCallback */
|
||||
int bReverse, /* True for a reverse order scan */
|
||||
void *pKey1, int nKey1, /* Start of search */
|
||||
void *pKey2, int nKey2, /* End of search */
|
||||
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
|
||||
){
|
||||
KcDb *pKcDb = (KcDb *)pDb;
|
||||
kyotocabinet::DB::Cursor* pCur = pKcDb->db->cursor();
|
||||
int res;
|
||||
|
||||
if( bReverse==0 ){
|
||||
if( pKey1 ){
|
||||
res = pCur->jump((const char *)pKey1, nKey1);
|
||||
}else{
|
||||
res = pCur->jump();
|
||||
}
|
||||
}else{
|
||||
if( pKey2 ){
|
||||
res = pCur->jump_back((const char *)pKey2, nKey2);
|
||||
}else{
|
||||
res = pCur->jump_back();
|
||||
}
|
||||
}
|
||||
|
||||
while( res ){
|
||||
const char *pKey; size_t nKey;
|
||||
const char *pVal; size_t nVal;
|
||||
pKey = pCur->get(&nKey, &pVal, &nVal);
|
||||
|
||||
if( bReverse==0 && pKey2 ){
|
||||
res = memcmp(pKey, pKey2, MIN((size_t)nKey2, nKey));
|
||||
if( res>0 || (res==0 && (size_t)nKey2<nKey) ){
|
||||
delete [] pKey;
|
||||
break;
|
||||
}
|
||||
}else if( bReverse!=0 && pKey1 ){
|
||||
res = memcmp(pKey, pKey1, MIN((size_t)nKey1, nKey));
|
||||
if( res<0 || (res==0 && (size_t)nKey1>nKey) ){
|
||||
delete [] pKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
xCallback(pCtx, (void *)pKey, (int)nKey, (void *)pVal, (int)nVal);
|
||||
delete [] pKey;
|
||||
|
||||
if( bReverse ){
|
||||
res = pCur->step_back();
|
||||
}else{
|
||||
res = pCur->step();
|
||||
}
|
||||
}
|
||||
|
||||
delete pCur;
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_KYOTOCABINET */
|
||||
|
||||
#ifdef HAVE_MDB
|
||||
#include "lmdb.h"
|
||||
|
||||
extern "C" {
|
||||
struct MdbDb {
|
||||
TestDb base;
|
||||
MDB_env *env;
|
||||
MDB_dbi dbi;
|
||||
};
|
||||
}
|
||||
|
||||
int test_mdb_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
MDB_txn *txn;
|
||||
MdbDb *pMdb;
|
||||
int rc;
|
||||
|
||||
if( bClear ){
|
||||
char *zCmd = sqlite3_mprintf("rm -rf %s\n", zFilename);
|
||||
system(zCmd);
|
||||
sqlite3_free(zCmd);
|
||||
}
|
||||
|
||||
pMdb = (MdbDb *)malloc(sizeof(MdbDb));
|
||||
memset(pMdb, 0, sizeof(MdbDb));
|
||||
|
||||
rc = mdb_env_create(&pMdb->env);
|
||||
if( rc==0 ) rc = mdb_env_set_mapsize(pMdb->env, 1*1024*1024*1024);
|
||||
if( rc==0 ) rc = mdb_env_open(pMdb->env, zFilename, MDB_NOSYNC|MDB_NOSUBDIR, 0600);
|
||||
if( rc==0 ) rc = mdb_txn_begin(pMdb->env, NULL, 0, &txn);
|
||||
if( rc==0 ){
|
||||
rc = mdb_open(txn, NULL, 0, &pMdb->dbi);
|
||||
mdb_txn_commit(txn);
|
||||
}
|
||||
|
||||
*ppDb = (TestDb *)pMdb;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int test_mdb_close(TestDb *pDb){
|
||||
MdbDb *pMdb = (MdbDb *)pDb;
|
||||
|
||||
mdb_close(pMdb->env, pMdb->dbi);
|
||||
mdb_env_close(pMdb->env);
|
||||
free(pMdb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_mdb_write(TestDb *pDb, void *pKey, int nKey, void *pVal, int nVal){
|
||||
int rc;
|
||||
MdbDb *pMdb = (MdbDb *)pDb;
|
||||
MDB_val val;
|
||||
MDB_val key;
|
||||
MDB_txn *txn;
|
||||
|
||||
val.mv_size = nVal;
|
||||
val.mv_data = pVal;
|
||||
key.mv_size = nKey;
|
||||
key.mv_data = pKey;
|
||||
|
||||
rc = mdb_txn_begin(pMdb->env, NULL, 0, &txn);
|
||||
if( rc==0 ){
|
||||
rc = mdb_put(txn, pMdb->dbi, &key, &val, 0);
|
||||
if( rc==0 ){
|
||||
rc = mdb_txn_commit(txn);
|
||||
}else{
|
||||
mdb_txn_abort(txn);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int test_mdb_delete(TestDb *pDb, void *pKey, int nKey){
|
||||
int rc;
|
||||
MdbDb *pMdb = (MdbDb *)pDb;
|
||||
MDB_val key;
|
||||
MDB_txn *txn;
|
||||
|
||||
key.mv_size = nKey;
|
||||
key.mv_data = pKey;
|
||||
rc = mdb_txn_begin(pMdb->env, NULL, 0, &txn);
|
||||
if( rc==0 ){
|
||||
rc = mdb_del(txn, pMdb->dbi, &key, 0);
|
||||
if( rc==0 ){
|
||||
rc = mdb_txn_commit(txn);
|
||||
}else{
|
||||
mdb_txn_abort(txn);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int test_mdb_fetch(
|
||||
TestDb *pDb,
|
||||
void *pKey,
|
||||
int nKey,
|
||||
void **ppVal,
|
||||
int *pnVal
|
||||
){
|
||||
int rc;
|
||||
MdbDb *pMdb = (MdbDb *)pDb;
|
||||
MDB_val key;
|
||||
MDB_txn *txn;
|
||||
|
||||
key.mv_size = nKey;
|
||||
key.mv_data = pKey;
|
||||
|
||||
rc = mdb_txn_begin(pMdb->env, NULL, MDB_RDONLY, &txn);
|
||||
if( rc==0 ){
|
||||
MDB_val val = {0, 0};
|
||||
rc = mdb_get(txn, pMdb->dbi, &key, &val);
|
||||
if( rc==MDB_NOTFOUND ){
|
||||
rc = 0;
|
||||
*ppVal = 0;
|
||||
*pnVal = -1;
|
||||
}else{
|
||||
*ppVal = val.mv_data;
|
||||
*pnVal = val.mv_size;
|
||||
}
|
||||
mdb_txn_commit(txn);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int test_mdb_scan(
|
||||
TestDb *pDb, /* Database handle */
|
||||
void *pCtx, /* Context pointer to pass to xCallback */
|
||||
int bReverse, /* True for a reverse order scan */
|
||||
void *pKey1, int nKey1, /* Start of search */
|
||||
void *pKey2, int nKey2, /* End of search */
|
||||
void (*xCallback)(void *pCtx, void *pKey, int nKey, void *pVal, int nVal)
|
||||
){
|
||||
MdbDb *pMdb = (MdbDb *)pDb;
|
||||
int rc;
|
||||
MDB_cursor_op op = bReverse ? MDB_PREV : MDB_NEXT;
|
||||
MDB_txn *txn;
|
||||
|
||||
rc = mdb_txn_begin(pMdb->env, NULL, MDB_RDONLY, &txn);
|
||||
if( rc==0 ){
|
||||
MDB_cursor *csr;
|
||||
MDB_val key = {0, 0};
|
||||
MDB_val val = {0, 0};
|
||||
|
||||
rc = mdb_cursor_open(txn, pMdb->dbi, &csr);
|
||||
if( rc==0 ){
|
||||
while( mdb_cursor_get(csr, &key, &val, op)==0 ){
|
||||
xCallback(pCtx, key.mv_data, key.mv_size, val.mv_data, val.mv_size);
|
||||
}
|
||||
mdb_cursor_close(csr);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* HAVE_MDB */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,980 +0,0 @@
|
||||
|
||||
/*
|
||||
** This file contains the TestDb bt wrapper.
|
||||
*/
|
||||
|
||||
#include "lsmtest_tdb.h"
|
||||
#include "lsmtest.h"
|
||||
#include <unistd.h>
|
||||
#include "bt.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct BtDb BtDb;
|
||||
typedef struct BtFile BtFile;
|
||||
|
||||
/* Background checkpointer interface (see implementations below). */
|
||||
typedef struct bt_ckpter bt_ckpter;
|
||||
static int bgc_attach(BtDb *pDb, const char*);
|
||||
static int bgc_detach(BtDb *pDb);
|
||||
|
||||
/*
|
||||
** Each database or log file opened by a database handle is wrapped by
|
||||
** an object of the following type.
|
||||
*/
|
||||
struct BtFile {
|
||||
BtDb *pBt; /* Database handle that opened this file */
|
||||
bt_env *pVfs; /* Underlying VFS */
|
||||
bt_file *pFile; /* File handle belonging to underlying VFS */
|
||||
int nSectorSize; /* Size of sectors in bytes */
|
||||
int nSector; /* Allocated size of nSector array */
|
||||
u8 **apSector; /* Original sector data */
|
||||
};
|
||||
|
||||
/*
|
||||
** nCrashSync:
|
||||
** If this value is non-zero, then a "crash-test" is running. If
|
||||
** nCrashSync==1, then the crash is simulated during the very next
|
||||
** call to the xSync() VFS method (on either the db or log file).
|
||||
** If nCrashSync==2, the following call to xSync(), and so on.
|
||||
**
|
||||
** bCrash:
|
||||
** After a crash is simulated, this variable is set. Any subsequent
|
||||
** attempts to write to a file or modify the file system in any way
|
||||
** fail once this is set. All the caller can do is close the connection.
|
||||
**
|
||||
** bFastInsert:
|
||||
** If this variable is set to true, then a BT_CONTROL_FAST_INSERT_OP
|
||||
** control is issued before each callto BtReplace() or BtCsrOpen().
|
||||
*/
|
||||
struct BtDb {
|
||||
TestDb base; /* Base class */
|
||||
bt_db *pBt; /* bt database handle */
|
||||
sqlite4_env *pEnv; /* SQLite environment (for malloc/free) */
|
||||
bt_env *pVfs; /* Underlying VFS */
|
||||
int bFastInsert; /* True to use fast-insert */
|
||||
|
||||
/* Space for bt_fetch() results */
|
||||
u8 *aBuffer; /* Space to store results */
|
||||
int nBuffer; /* Allocated size of aBuffer[] in bytes */
|
||||
int nRef;
|
||||
|
||||
/* Background checkpointer used by mt connections */
|
||||
bt_ckpter *pCkpter;
|
||||
|
||||
/* Stuff used for crash test simulation */
|
||||
BtFile *apFile[2]; /* Database and log files used by pBt */
|
||||
bt_env env; /* Private VFS for this object */
|
||||
int nCrashSync; /* Number of syncs until crash (see above) */
|
||||
int bCrash; /* True once a crash has been simulated */
|
||||
};
|
||||
|
||||
static int btVfsFullpath(
|
||||
sqlite4_env *pEnv,
|
||||
bt_env *pVfs,
|
||||
const char *z,
|
||||
char **pzOut
|
||||
){
|
||||
BtDb *pBt = (BtDb*)pVfs->pVfsCtx;
|
||||
if( pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return pBt->pVfs->xFullpath(pEnv, pBt->pVfs, z, pzOut);
|
||||
}
|
||||
|
||||
static int btVfsOpen(
|
||||
sqlite4_env *pEnv,
|
||||
bt_env *pVfs,
|
||||
const char *zFile,
|
||||
int flags, bt_file **ppFile
|
||||
){
|
||||
BtFile *p;
|
||||
BtDb *pBt = (BtDb*)pVfs->pVfsCtx;
|
||||
int rc;
|
||||
|
||||
if( pBt->bCrash ) return SQLITE4_IOERR;
|
||||
|
||||
p = (BtFile*)testMalloc(sizeof(BtFile));
|
||||
if( !p ) return SQLITE4_NOMEM;
|
||||
if( flags & BT_OPEN_DATABASE ){
|
||||
pBt->apFile[0] = p;
|
||||
}else if( flags & BT_OPEN_LOG ){
|
||||
pBt->apFile[1] = p;
|
||||
}
|
||||
if( (flags & BT_OPEN_SHARED)==0 ){
|
||||
p->pBt = pBt;
|
||||
}
|
||||
p->pVfs = pBt->pVfs;
|
||||
|
||||
rc = pBt->pVfs->xOpen(pEnv, pVfs, zFile, flags, &p->pFile);
|
||||
if( rc!=SQLITE4_OK ){
|
||||
testFree(p);
|
||||
p = 0;
|
||||
}else{
|
||||
pBt->nRef++;
|
||||
}
|
||||
|
||||
*ppFile = (bt_file*)p;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int btVfsSize(bt_file *pFile, sqlite4_int64 *piRes){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xSize(p->pFile, piRes);
|
||||
}
|
||||
|
||||
static int btVfsRead(bt_file *pFile, sqlite4_int64 iOff, void *pBuf, int nBuf){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xRead(p->pFile, iOff, pBuf, nBuf);
|
||||
}
|
||||
|
||||
static int btFlushSectors(BtFile *p, int iFile){
|
||||
sqlite4_int64 iSz;
|
||||
int rc;
|
||||
int i;
|
||||
u8 *aTmp = 0;
|
||||
|
||||
rc = p->pBt->pVfs->xSize(p->pFile, &iSz);
|
||||
for(i=0; rc==SQLITE4_OK && i<p->nSector; i++){
|
||||
if( p->pBt->bCrash && p->apSector[i] ){
|
||||
|
||||
/* The system is simulating a crash. There are three choices for
|
||||
** this sector:
|
||||
**
|
||||
** 1) Leave it as it is (simulating a successful write),
|
||||
** 2) Restore the original data (simulating a lost write),
|
||||
** 3) Populate the disk sector with garbage data.
|
||||
*/
|
||||
sqlite4_int64 iSOff = p->nSectorSize*i;
|
||||
int nWrite = MIN(p->nSectorSize, iSz - iSOff);
|
||||
|
||||
if( nWrite ){
|
||||
u8 *aWrite = 0;
|
||||
int iOpt = (testPrngValue(i) % 3) + 1;
|
||||
if( iOpt==1 ){
|
||||
aWrite = p->apSector[i];
|
||||
}else if( iOpt==3 ){
|
||||
if( aTmp==0 ) aTmp = testMalloc(p->nSectorSize);
|
||||
aWrite = aTmp;
|
||||
testPrngArray(i*13, (u32*)aWrite, nWrite/sizeof(u32));
|
||||
}
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "handle sector %d of %s with %s\n", i,
|
||||
iFile==0 ? "db" : "log",
|
||||
iOpt==1 ? "rollback" : iOpt==2 ? "write" : "omit"
|
||||
);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
if( aWrite ){
|
||||
rc = p->pBt->pVfs->xWrite(p->pFile, iSOff, aWrite, nWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
testFree(p->apSector[i]);
|
||||
p->apSector[i] = 0;
|
||||
}
|
||||
|
||||
testFree(aTmp);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int btSaveSectors(BtFile *p, sqlite4_int64 iOff, int nBuf){
|
||||
int rc;
|
||||
sqlite4_int64 iSz; /* Size of file on disk */
|
||||
int iFirst; /* First sector affected */
|
||||
int iSector; /* Current sector */
|
||||
int iLast; /* Last sector affected */
|
||||
|
||||
if( p->nSectorSize==0 ){
|
||||
p->nSectorSize = p->pBt->pVfs->xSectorSize(p->pFile);
|
||||
if( p->nSectorSize<512 ) p->nSectorSize = 512;
|
||||
}
|
||||
iLast = (iOff+nBuf-1) / p->nSectorSize;
|
||||
iFirst = iOff / p->nSectorSize;
|
||||
|
||||
rc = p->pBt->pVfs->xSize(p->pFile, &iSz);
|
||||
for(iSector=iFirst; rc==SQLITE4_OK && iSector<=iLast; iSector++){
|
||||
int nRead;
|
||||
sqlite4_int64 iSOff = iSector * p->nSectorSize;
|
||||
u8 *aBuf = testMalloc(p->nSectorSize);
|
||||
nRead = MIN(p->nSectorSize, (iSz - iSOff));
|
||||
if( nRead>0 ){
|
||||
rc = p->pBt->pVfs->xRead(p->pFile, iSOff, aBuf, nRead);
|
||||
}
|
||||
|
||||
while( rc==SQLITE4_OK && iSector>=p->nSector ){
|
||||
int nNew = p->nSector + 32;
|
||||
u8 **apNew = (u8**)testMalloc(nNew * sizeof(u8*));
|
||||
memcpy(apNew, p->apSector, p->nSector*sizeof(u8*));
|
||||
testFree(p->apSector);
|
||||
p->apSector = apNew;
|
||||
p->nSector = nNew;
|
||||
}
|
||||
|
||||
p->apSector[iSector] = aBuf;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int btVfsWrite(bt_file *pFile, sqlite4_int64 iOff, void *pBuf, int nBuf){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
if( p->pBt && p->pBt->nCrashSync ){
|
||||
btSaveSectors(p, iOff, nBuf);
|
||||
}
|
||||
return p->pVfs->xWrite(p->pFile, iOff, pBuf, nBuf);
|
||||
}
|
||||
|
||||
static int btVfsTruncate(bt_file *pFile, sqlite4_int64 iOff){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xTruncate(p->pFile, iOff);
|
||||
}
|
||||
|
||||
static int btVfsSync(bt_file *pFile){
|
||||
int rc = SQLITE4_OK;
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
BtDb *pBt = p->pBt;
|
||||
|
||||
if( pBt ){
|
||||
if( pBt->bCrash ) return SQLITE4_IOERR;
|
||||
if( pBt->nCrashSync ){
|
||||
pBt->nCrashSync--;
|
||||
pBt->bCrash = (pBt->nCrashSync==0);
|
||||
if( pBt->bCrash ){
|
||||
btFlushSectors(pBt->apFile[0], 0);
|
||||
btFlushSectors(pBt->apFile[1], 1);
|
||||
rc = SQLITE4_IOERR;
|
||||
}else{
|
||||
btFlushSectors(p, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rc==SQLITE4_OK ){
|
||||
rc = p->pVfs->xSync(p->pFile);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int btVfsSectorSize(bt_file *pFile){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
return p->pVfs->xSectorSize(p->pFile);
|
||||
}
|
||||
|
||||
static void btDeref(BtDb *p){
|
||||
p->nRef--;
|
||||
assert( p->nRef>=0 );
|
||||
if( p->nRef<=0 ) testFree(p);
|
||||
}
|
||||
|
||||
static int btVfsClose(bt_file *pFile){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
BtDb *pBt = p->pBt;
|
||||
int rc;
|
||||
if( pBt ){
|
||||
btFlushSectors(p, 0);
|
||||
if( p==pBt->apFile[0] ) pBt->apFile[0] = 0;
|
||||
if( p==pBt->apFile[1] ) pBt->apFile[1] = 0;
|
||||
}
|
||||
testFree(p->apSector);
|
||||
rc = p->pVfs->xClose(p->pFile);
|
||||
#if 0
|
||||
btDeref(p->pBt);
|
||||
#endif
|
||||
testFree(p);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int btVfsUnlink(sqlite4_env *pEnv, bt_env *pVfs, const char *zFile){
|
||||
BtDb *pBt = (BtDb*)pVfs->pVfsCtx;
|
||||
if( pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return pBt->pVfs->xUnlink(pEnv, pBt->pVfs, zFile);
|
||||
}
|
||||
|
||||
static int btVfsLock(bt_file *pFile, int iLock, int eType){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xLock(p->pFile, iLock, eType);
|
||||
}
|
||||
|
||||
static int btVfsTestLock(bt_file *pFile, int iLock, int nLock, int eType){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xTestLock(p->pFile, iLock, nLock, eType);
|
||||
}
|
||||
|
||||
static int btVfsShmMap(bt_file *pFile, int iChunk, int sz, void **ppOut){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xShmMap(p->pFile, iChunk, sz, ppOut);
|
||||
}
|
||||
|
||||
static void btVfsShmBarrier(bt_file *pFile){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
return p->pVfs->xShmBarrier(p->pFile);
|
||||
}
|
||||
|
||||
static int btVfsShmUnmap(bt_file *pFile, int bDelete){
|
||||
BtFile *p = (BtFile*)pFile;
|
||||
if( p->pBt && p->pBt->bCrash ) return SQLITE4_IOERR;
|
||||
return p->pVfs->xShmUnmap(p->pFile, bDelete);
|
||||
}
|
||||
|
||||
static int bt_close(TestDb *pTestDb){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
int rc = sqlite4BtClose(p->pBt);
|
||||
free(p->aBuffer);
|
||||
if( p->apFile[0] ) p->apFile[0]->pBt = 0;
|
||||
if( p->apFile[1] ) p->apFile[1]->pBt = 0;
|
||||
bgc_detach(p);
|
||||
testFree(p);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int btMinTransaction(BtDb *p, int iMin, int *piLevel){
|
||||
int iLevel;
|
||||
int rc = SQLITE4_OK;
|
||||
|
||||
iLevel = sqlite4BtTransactionLevel(p->pBt);
|
||||
if( iLevel<iMin ){
|
||||
rc = sqlite4BtBegin(p->pBt, iMin);
|
||||
*piLevel = iLevel;
|
||||
}else{
|
||||
*piLevel = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
static int btRestoreTransaction(BtDb *p, int iLevel, int rcin){
|
||||
int rc = rcin;
|
||||
if( iLevel>=0 ){
|
||||
if( rc==SQLITE4_OK ){
|
||||
rc = sqlite4BtCommit(p->pBt, iLevel);
|
||||
}else{
|
||||
sqlite4BtRollback(p->pBt, iLevel);
|
||||
}
|
||||
assert( iLevel==sqlite4BtTransactionLevel(p->pBt) );
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_write(TestDb *pTestDb, void *pK, int nK, void *pV, int nV){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
int iLevel;
|
||||
int rc;
|
||||
|
||||
rc = btMinTransaction(p, 2, &iLevel);
|
||||
if( rc==SQLITE4_OK ){
|
||||
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
|
||||
rc = sqlite4BtReplace(p->pBt, pK, nK, pV, nV);
|
||||
rc = btRestoreTransaction(p, iLevel, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_delete(TestDb *pTestDb, void *pK, int nK){
|
||||
return bt_write(pTestDb, pK, nK, 0, -1);
|
||||
}
|
||||
|
||||
static int bt_delete_range(
|
||||
TestDb *pTestDb,
|
||||
void *pKey1, int nKey1,
|
||||
void *pKey2, int nKey2
|
||||
){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
bt_cursor *pCsr = 0;
|
||||
int rc = SQLITE4_OK;
|
||||
int iLevel;
|
||||
|
||||
rc = btMinTransaction(p, 2, &iLevel);
|
||||
if( rc==SQLITE4_OK ){
|
||||
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
|
||||
rc = sqlite4BtCsrOpen(p->pBt, 0, &pCsr);
|
||||
}
|
||||
while( rc==SQLITE4_OK ){
|
||||
const void *pK;
|
||||
int n;
|
||||
int nCmp;
|
||||
int res;
|
||||
|
||||
rc = sqlite4BtCsrSeek(pCsr, pKey1, nKey1, BT_SEEK_GE);
|
||||
if( rc==SQLITE4_INEXACT ) rc = SQLITE4_OK;
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
|
||||
rc = sqlite4BtCsrKey(pCsr, &pK, &n);
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
|
||||
nCmp = MIN(n, nKey1);
|
||||
res = memcmp(pKey1, pK, nCmp);
|
||||
assert( res<0 || (res==0 && nKey1<=n) );
|
||||
if( res==0 && nKey1==n ){
|
||||
rc = sqlite4BtCsrNext(pCsr);
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
rc = sqlite4BtCsrKey(pCsr, &pK, &n);
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
}
|
||||
|
||||
nCmp = MIN(n, nKey2);
|
||||
res = memcmp(pKey2, pK, nCmp);
|
||||
if( res<0 || (res==0 && nKey2<=n) ) break;
|
||||
|
||||
rc = sqlite4BtDelete(pCsr);
|
||||
}
|
||||
if( rc==SQLITE4_NOTFOUND ) rc = SQLITE4_OK;
|
||||
|
||||
sqlite4BtCsrClose(pCsr);
|
||||
|
||||
rc = btRestoreTransaction(p, iLevel, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_fetch(
|
||||
TestDb *pTestDb,
|
||||
void *pK, int nK,
|
||||
void **ppVal, int *pnVal
|
||||
){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
bt_cursor *pCsr = 0;
|
||||
int iLevel;
|
||||
int rc = SQLITE4_OK;
|
||||
|
||||
iLevel = sqlite4BtTransactionLevel(p->pBt);
|
||||
if( iLevel==0 ){
|
||||
rc = sqlite4BtBegin(p->pBt, 1);
|
||||
if( rc!=SQLITE4_OK ) return rc;
|
||||
}
|
||||
|
||||
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
|
||||
rc = sqlite4BtCsrOpen(p->pBt, 0, &pCsr);
|
||||
if( rc==SQLITE4_OK ){
|
||||
rc = sqlite4BtCsrSeek(pCsr, pK, nK, BT_SEEK_EQ);
|
||||
if( rc==SQLITE4_OK ){
|
||||
const void *pV = 0;
|
||||
int nV = 0;
|
||||
rc = sqlite4BtCsrData(pCsr, 0, -1, &pV, &nV);
|
||||
if( rc==SQLITE4_OK ){
|
||||
if( nV>p->nBuffer ){
|
||||
free(p->aBuffer);
|
||||
p->aBuffer = (u8*)malloc(nV*2);
|
||||
p->nBuffer = nV*2;
|
||||
}
|
||||
memcpy(p->aBuffer, pV, nV);
|
||||
*pnVal = nV;
|
||||
*ppVal = (void*)(p->aBuffer);
|
||||
}
|
||||
|
||||
}else if( rc==SQLITE4_INEXACT || rc==SQLITE4_NOTFOUND ){
|
||||
*ppVal = 0;
|
||||
*pnVal = -1;
|
||||
rc = SQLITE4_OK;
|
||||
}
|
||||
sqlite4BtCsrClose(pCsr);
|
||||
}
|
||||
|
||||
if( iLevel==0 ) sqlite4BtCommit(p->pBt, 0);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_scan(
|
||||
TestDb *pTestDb,
|
||||
void *pCtx,
|
||||
int bReverse,
|
||||
void *pFirst, int nFirst,
|
||||
void *pLast, int nLast,
|
||||
void (*xCallback)(void *, void *, int , void *, int)
|
||||
){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
bt_cursor *pCsr = 0;
|
||||
int rc;
|
||||
int iLevel;
|
||||
|
||||
rc = btMinTransaction(p, 1, &iLevel);
|
||||
|
||||
if( rc==SQLITE4_OK ){
|
||||
if( p->bFastInsert ) sqlite4BtControl(p->pBt, BT_CONTROL_FAST_INSERT_OP, 0);
|
||||
rc = sqlite4BtCsrOpen(p->pBt, 0, &pCsr);
|
||||
}
|
||||
if( rc==SQLITE4_OK ){
|
||||
if( bReverse ){
|
||||
if( pLast ){
|
||||
rc = sqlite4BtCsrSeek(pCsr, pLast, nLast, BT_SEEK_LE);
|
||||
}else{
|
||||
rc = sqlite4BtCsrLast(pCsr);
|
||||
}
|
||||
}else{
|
||||
rc = sqlite4BtCsrSeek(pCsr, pFirst, nFirst, BT_SEEK_GE);
|
||||
}
|
||||
if( rc==SQLITE4_INEXACT ) rc = SQLITE4_OK;
|
||||
|
||||
while( rc==SQLITE4_OK ){
|
||||
const void *pK = 0; int nK = 0;
|
||||
const void *pV = 0; int nV = 0;
|
||||
|
||||
rc = sqlite4BtCsrKey(pCsr, &pK, &nK);
|
||||
if( rc==SQLITE4_OK ){
|
||||
rc = sqlite4BtCsrData(pCsr, 0, -1, &pV, &nV);
|
||||
}
|
||||
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
if( bReverse ){
|
||||
if( pFirst ){
|
||||
int res;
|
||||
int nCmp = MIN(nK, nFirst);
|
||||
res = memcmp(pFirst, pK, nCmp);
|
||||
if( res>0 || (res==0 && nK<nFirst) ) break;
|
||||
}
|
||||
}else{
|
||||
if( pLast ){
|
||||
int res;
|
||||
int nCmp = MIN(nK, nLast);
|
||||
res = memcmp(pLast, pK, nCmp);
|
||||
if( res<0 || (res==0 && nK>nLast) ) break;
|
||||
}
|
||||
}
|
||||
|
||||
xCallback(pCtx, (void*)pK, nK, (void*)pV, nV);
|
||||
if( bReverse ){
|
||||
rc = sqlite4BtCsrPrev(pCsr);
|
||||
}else{
|
||||
rc = sqlite4BtCsrNext(pCsr);
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE4_NOTFOUND ) rc = SQLITE4_OK;
|
||||
|
||||
sqlite4BtCsrClose(pCsr);
|
||||
}
|
||||
|
||||
rc = btRestoreTransaction(p, iLevel, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_begin(TestDb *pTestDb, int iLvl){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
int rc = sqlite4BtBegin(p->pBt, iLvl);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_commit(TestDb *pTestDb, int iLvl){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
int rc = sqlite4BtCommit(p->pBt, iLvl);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bt_rollback(TestDb *pTestDb, int iLvl){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
int rc = sqlite4BtRollback(p->pBt, iLvl);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int testParseOption(
|
||||
const char **pzIn, /* IN/OUT: pointer to next option */
|
||||
const char **pzOpt, /* OUT: nul-terminated option name */
|
||||
const char **pzArg, /* OUT: nul-terminated option argument */
|
||||
char *pSpace /* Temporary space for output params */
|
||||
){
|
||||
const char *p = *pzIn;
|
||||
const char *pStart;
|
||||
int n;
|
||||
|
||||
char *pOut = pSpace;
|
||||
|
||||
while( *p==' ' ) p++;
|
||||
pStart = p;
|
||||
while( *p && *p!='=' ) p++;
|
||||
if( *p==0 ) return 1;
|
||||
|
||||
n = (p - pStart);
|
||||
memcpy(pOut, pStart, n);
|
||||
*pzOpt = pOut;
|
||||
pOut += n;
|
||||
*pOut++ = '\0';
|
||||
|
||||
p++;
|
||||
pStart = p;
|
||||
while( *p && *p!=' ' ) p++;
|
||||
n = (p - pStart);
|
||||
|
||||
memcpy(pOut, pStart, n);
|
||||
*pzArg = pOut;
|
||||
pOut += n;
|
||||
*pOut++ = '\0';
|
||||
|
||||
*pzIn = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int testParseInt(const char *z, int *piVal){
|
||||
int i = 0;
|
||||
const char *p = z;
|
||||
|
||||
while( *p>='0' && *p<='9' ){
|
||||
i = i*10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if( *p=='K' || *p=='k' ){
|
||||
i = i * 1024;
|
||||
p++;
|
||||
}else if( *p=='M' || *p=='m' ){
|
||||
i = i * 1024 * 1024;
|
||||
p++;
|
||||
}
|
||||
|
||||
if( *p ) return SQLITE4_ERROR;
|
||||
*piVal = i;
|
||||
return SQLITE4_OK;
|
||||
}
|
||||
|
||||
static int testBtConfigure(BtDb *pDb, const char *zCfg, int *pbMt){
|
||||
int rc = SQLITE4_OK;
|
||||
|
||||
if( zCfg ){
|
||||
struct CfgParam {
|
||||
const char *zParam;
|
||||
int eParam;
|
||||
} aParam[] = {
|
||||
{ "safety", BT_CONTROL_SAFETY },
|
||||
{ "autockpt", BT_CONTROL_AUTOCKPT },
|
||||
{ "multiproc", BT_CONTROL_MULTIPROC },
|
||||
{ "blksz", BT_CONTROL_BLKSZ },
|
||||
{ "pagesz", BT_CONTROL_PAGESZ },
|
||||
{ "mt", -1 },
|
||||
{ "fastinsert", -2 },
|
||||
{ 0, 0 }
|
||||
};
|
||||
const char *z = zCfg;
|
||||
int n = strlen(z);
|
||||
char *aSpace;
|
||||
const char *zOpt;
|
||||
const char *zArg;
|
||||
|
||||
aSpace = (char*)testMalloc(n+2);
|
||||
while( rc==SQLITE4_OK && 0==testParseOption(&z, &zOpt, &zArg, aSpace) ){
|
||||
int i;
|
||||
int iVal;
|
||||
rc = testArgSelect(aParam, "param", zOpt, &i);
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
|
||||
rc = testParseInt(zArg, &iVal);
|
||||
if( rc!=SQLITE4_OK ) break;
|
||||
|
||||
switch( aParam[i].eParam ){
|
||||
case -1:
|
||||
*pbMt = iVal;
|
||||
break;
|
||||
case -2:
|
||||
pDb->bFastInsert = 1;
|
||||
break;
|
||||
default:
|
||||
rc = sqlite4BtControl(pDb->pBt, aParam[i].eParam, (void*)&iVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
testFree(aSpace);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int test_bt_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
|
||||
static const DatabaseMethods SqlMethods = {
|
||||
bt_close,
|
||||
bt_write,
|
||||
bt_delete,
|
||||
bt_delete_range,
|
||||
bt_fetch,
|
||||
bt_scan,
|
||||
bt_begin,
|
||||
bt_commit,
|
||||
bt_rollback
|
||||
};
|
||||
BtDb *p = 0;
|
||||
bt_db *pBt = 0;
|
||||
int rc;
|
||||
sqlite4_env *pEnv = sqlite4_env_default();
|
||||
|
||||
if( bClear && zFilename && zFilename[0] ){
|
||||
char *zLog = sqlite3_mprintf("%s-wal", zFilename);
|
||||
unlink(zFilename);
|
||||
unlink(zLog);
|
||||
sqlite3_free(zLog);
|
||||
}
|
||||
|
||||
rc = sqlite4BtNew(pEnv, 0, &pBt);
|
||||
if( rc==SQLITE4_OK ){
|
||||
int mt = 0; /* True for multi-threaded connection */
|
||||
|
||||
p = (BtDb*)testMalloc(sizeof(BtDb));
|
||||
p->base.pMethods = &SqlMethods;
|
||||
p->pBt = pBt;
|
||||
p->pEnv = pEnv;
|
||||
p->nRef = 1;
|
||||
|
||||
p->env.pVfsCtx = (void*)p;
|
||||
p->env.xFullpath = btVfsFullpath;
|
||||
p->env.xOpen = btVfsOpen;
|
||||
p->env.xSize = btVfsSize;
|
||||
p->env.xRead = btVfsRead;
|
||||
p->env.xWrite = btVfsWrite;
|
||||
p->env.xTruncate = btVfsTruncate;
|
||||
p->env.xSync = btVfsSync;
|
||||
p->env.xSectorSize = btVfsSectorSize;
|
||||
p->env.xClose = btVfsClose;
|
||||
p->env.xUnlink = btVfsUnlink;
|
||||
p->env.xLock = btVfsLock;
|
||||
p->env.xTestLock = btVfsTestLock;
|
||||
p->env.xShmMap = btVfsShmMap;
|
||||
p->env.xShmBarrier = btVfsShmBarrier;
|
||||
p->env.xShmUnmap = btVfsShmUnmap;
|
||||
|
||||
sqlite4BtControl(pBt, BT_CONTROL_GETVFS, (void*)&p->pVfs);
|
||||
sqlite4BtControl(pBt, BT_CONTROL_SETVFS, (void*)&p->env);
|
||||
|
||||
rc = testBtConfigure(p, zSpec, &mt);
|
||||
if( rc==SQLITE4_OK ){
|
||||
rc = sqlite4BtOpen(pBt, zFilename);
|
||||
}
|
||||
|
||||
if( rc==SQLITE4_OK && mt ){
|
||||
int nAuto = 0;
|
||||
rc = bgc_attach(p, zSpec);
|
||||
sqlite4BtControl(pBt, BT_CONTROL_AUTOCKPT, (void*)&nAuto);
|
||||
}
|
||||
}
|
||||
|
||||
if( rc!=SQLITE4_OK && p ){
|
||||
bt_close(&p->base);
|
||||
}
|
||||
|
||||
*ppDb = &p->base;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int test_fbt_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
return test_bt_open("fast=1", zFilename, bClear, ppDb);
|
||||
}
|
||||
|
||||
int test_fbts_open(
|
||||
const char *zSpec,
|
||||
const char *zFilename,
|
||||
int bClear,
|
||||
TestDb **ppDb
|
||||
){
|
||||
return test_bt_open("fast=1 blksz=32K pagesz=512", zFilename, bClear, ppDb);
|
||||
}
|
||||
|
||||
|
||||
void tdb_bt_prepare_sync_crash(TestDb *pTestDb, int iSync){
|
||||
BtDb *p = (BtDb*)pTestDb;
|
||||
assert( pTestDb->pMethods->xClose==bt_close );
|
||||
assert( p->bCrash==0 );
|
||||
p->nCrashSync = iSync;
|
||||
}
|
||||
|
||||
bt_db *tdb_bt(TestDb *pDb){
|
||||
if( pDb->pMethods->xClose==bt_close ){
|
||||
return ((BtDb *)pDb)->pBt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
** Beginning of code for background checkpointer.
|
||||
*/
|
||||
|
||||
struct bt_ckpter {
|
||||
sqlite4_buffer file; /* File name */
|
||||
sqlite4_buffer spec; /* Options */
|
||||
int nLogsize; /* Minimum log size to checkpoint */
|
||||
int nRef; /* Number of clients */
|
||||
|
||||
int bDoWork; /* Set by client threads */
|
||||
pthread_t ckpter_thread; /* Checkpointer thread */
|
||||
pthread_cond_t ckpter_cond; /* Condition var the ckpter waits on */
|
||||
pthread_mutex_t ckpter_mutex; /* Mutex used with ckpter_cond */
|
||||
|
||||
bt_ckpter *pNext; /* Next object in list at gBgc.pCkpter */
|
||||
};
|
||||
|
||||
static struct GlobalBackgroundCheckpointer {
|
||||
bt_ckpter *pCkpter; /* Linked list of checkpointers */
|
||||
} gBgc;
|
||||
|
||||
static void *bgc_main(void *pArg){
|
||||
BtDb *pDb = 0;
|
||||
int rc;
|
||||
int mt;
|
||||
bt_ckpter *pCkpter = (bt_ckpter*)pArg;
|
||||
|
||||
rc = test_bt_open("", (char*)pCkpter->file.p, 0, (TestDb**)&pDb);
|
||||
assert( rc==SQLITE4_OK );
|
||||
rc = testBtConfigure(pDb, (char*)pCkpter->spec.p, &mt);
|
||||
|
||||
while( pCkpter->nRef>0 ){
|
||||
bt_db *db = pDb->pBt;
|
||||
int nLog = 0;
|
||||
|
||||
sqlite4BtBegin(db, 1);
|
||||
sqlite4BtCommit(db, 0);
|
||||
sqlite4BtControl(db, BT_CONTROL_LOGSIZE, (void*)&nLog);
|
||||
|
||||
if( nLog>=pCkpter->nLogsize ){
|
||||
int rc;
|
||||
bt_checkpoint ckpt;
|
||||
memset(&ckpt, 0, sizeof(bt_checkpoint));
|
||||
ckpt.nFrameBuffer = nLog/2;
|
||||
rc = sqlite4BtControl(db, BT_CONTROL_CHECKPOINT, (void*)&ckpt);
|
||||
assert( rc==SQLITE4_OK );
|
||||
sqlite4BtControl(db, BT_CONTROL_LOGSIZE, (void*)&nLog);
|
||||
}
|
||||
|
||||
/* The thread will wake up when it is signaled either because another
|
||||
** thread has created some work for this one or because the connection
|
||||
** is being closed. */
|
||||
pthread_mutex_lock(&pCkpter->ckpter_mutex);
|
||||
if( pCkpter->bDoWork==0 ){
|
||||
pthread_cond_wait(&pCkpter->ckpter_cond, &pCkpter->ckpter_mutex);
|
||||
}
|
||||
pCkpter->bDoWork = 0;
|
||||
pthread_mutex_unlock(&pCkpter->ckpter_mutex);
|
||||
}
|
||||
|
||||
if( pDb ) bt_close((TestDb*)pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bgc_logsize_cb(void *pCtx, int nLogsize){
|
||||
bt_ckpter *p = (bt_ckpter*)pCtx;
|
||||
if( nLogsize>=p->nLogsize ){
|
||||
pthread_mutex_lock(&p->ckpter_mutex);
|
||||
p->bDoWork = 1;
|
||||
pthread_cond_signal(&p->ckpter_cond);
|
||||
pthread_mutex_unlock(&p->ckpter_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static int bgc_attach(BtDb *pDb, const char *zSpec){
|
||||
int rc;
|
||||
int n;
|
||||
bt_info info;
|
||||
bt_ckpter *pCkpter;
|
||||
|
||||
/* Figure out the full path to the database opened by handle pDb. */
|
||||
info.eType = BT_INFO_FILENAME;
|
||||
info.pgno = 0;
|
||||
sqlite4_buffer_init(&info.output, 0);
|
||||
rc = sqlite4BtControl(pDb->pBt, BT_CONTROL_INFO, (void*)&info);
|
||||
if( rc!=SQLITE4_OK ) return rc;
|
||||
|
||||
sqlite4_mutex_enter(sqlite4_mutex_alloc(pDb->pEnv, SQLITE4_MUTEX_STATIC_KV));
|
||||
|
||||
/* Search for an existing bt_ckpter object. */
|
||||
n = info.output.n;
|
||||
for(pCkpter=gBgc.pCkpter; pCkpter; pCkpter=pCkpter->pNext){
|
||||
if( n==pCkpter->file.n && 0==memcmp(info.output.p, pCkpter->file.p, n) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Failed to find a suitable checkpointer. Create a new one. */
|
||||
if( pCkpter==0 ){
|
||||
bt_logsizecb cb;
|
||||
|
||||
pCkpter = testMalloc(sizeof(bt_ckpter));
|
||||
memcpy(&pCkpter->file, &info.output, sizeof(sqlite4_buffer));
|
||||
info.output.p = 0;
|
||||
pCkpter->pNext = gBgc.pCkpter;
|
||||
pCkpter->nLogsize = 1000;
|
||||
gBgc.pCkpter = pCkpter;
|
||||
pCkpter->nRef = 1;
|
||||
|
||||
sqlite4_buffer_init(&pCkpter->spec, 0);
|
||||
rc = sqlite4_buffer_set(&pCkpter->spec, zSpec, strlen(zSpec)+1);
|
||||
assert( rc==SQLITE4_OK );
|
||||
|
||||
/* Kick off the checkpointer thread. */
|
||||
if( rc==0 ) rc = pthread_cond_init(&pCkpter->ckpter_cond, 0);
|
||||
if( rc==0 ) rc = pthread_mutex_init(&pCkpter->ckpter_mutex, 0);
|
||||
if( rc==0 ){
|
||||
rc = pthread_create(&pCkpter->ckpter_thread, 0, bgc_main, (void*)pCkpter);
|
||||
}
|
||||
assert( rc==0 ); /* todo: Fix this */
|
||||
|
||||
/* Set up the logsize callback for the client thread */
|
||||
cb.pCtx = (void*)pCkpter;
|
||||
cb.xLogsize = bgc_logsize_cb;
|
||||
sqlite4BtControl(pDb->pBt, BT_CONTROL_LOGSIZECB, (void*)&cb);
|
||||
}else{
|
||||
pCkpter->nRef++;
|
||||
}
|
||||
|
||||
/* Assuming a checkpointer was encountered or effected, attach the
|
||||
** connection to it. */
|
||||
if( pCkpter ){
|
||||
pDb->pCkpter = pCkpter;
|
||||
}
|
||||
|
||||
sqlite4_mutex_leave(sqlite4_mutex_alloc(pDb->pEnv, SQLITE4_MUTEX_STATIC_KV));
|
||||
sqlite4_buffer_clear(&info.output);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bgc_detach(BtDb *pDb){
|
||||
int rc = SQLITE4_OK;
|
||||
bt_ckpter *pCkpter = pDb->pCkpter;
|
||||
if( pCkpter ){
|
||||
int bShutdown = 0; /* True if this is the last reference */
|
||||
|
||||
sqlite4_mutex_enter(sqlite4_mutex_alloc(pDb->pEnv,SQLITE4_MUTEX_STATIC_KV));
|
||||
pCkpter->nRef--;
|
||||
if( pCkpter->nRef==0 ){
|
||||
bt_ckpter **pp;
|
||||
|
||||
*pp = pCkpter->pNext;
|
||||
for(pp=&gBgc.pCkpter; *pp!=pCkpter; pp=&((*pp)->pNext));
|
||||
bShutdown = 1;
|
||||
}
|
||||
sqlite4_mutex_leave(sqlite4_mutex_alloc(pDb->pEnv,SQLITE4_MUTEX_STATIC_KV));
|
||||
|
||||
if( bShutdown ){
|
||||
void *pDummy;
|
||||
|
||||
/* Signal the checkpointer thread. */
|
||||
pthread_mutex_lock(&pCkpter->ckpter_mutex);
|
||||
pCkpter->bDoWork = 1;
|
||||
pthread_cond_signal(&pCkpter->ckpter_cond);
|
||||
pthread_mutex_unlock(&pCkpter->ckpter_mutex);
|
||||
|
||||
/* Join the checkpointer thread. */
|
||||
pthread_join(pCkpter->ckpter_thread, &pDummy);
|
||||
pthread_cond_destroy(&pCkpter->ckpter_cond);
|
||||
pthread_mutex_destroy(&pCkpter->ckpter_mutex);
|
||||
|
||||
sqlite4_buffer_clear(&pCkpter->file);
|
||||
sqlite4_buffer_clear(&pCkpter->spec);
|
||||
testFree(pCkpter);
|
||||
}
|
||||
|
||||
pDb->pCkpter = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** End of background checkpointer.
|
||||
*************************************************************************/
|
||||
@@ -1,223 +0,0 @@
|
||||
|
||||
#include "lsmtest.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Global variables used within this module.
|
||||
*/
|
||||
static struct TestutilGlobal {
|
||||
char **argv;
|
||||
int argc;
|
||||
} g = {0, 0};
|
||||
|
||||
static struct TestutilRnd {
|
||||
unsigned int aRand1[2048]; /* Bits 0..10 */
|
||||
unsigned int aRand2[2048]; /* Bits 11..21 */
|
||||
unsigned int aRand3[1024]; /* Bits 22..31 */
|
||||
} r;
|
||||
|
||||
/*************************************************************************
|
||||
** The following block is a copy of the implementation of SQLite function
|
||||
** sqlite3_randomness. This version has two important differences:
|
||||
**
|
||||
** 1. It always uses the same seed. So the sequence of random data output
|
||||
** is the same for every run of the program.
|
||||
**
|
||||
** 2. It is not threadsafe.
|
||||
*/
|
||||
static struct sqlite3PrngType {
|
||||
unsigned char i, j; /* State variables */
|
||||
unsigned char s[256]; /* State variables */
|
||||
} sqlite3Prng = {
|
||||
0xAF, 0x28,
|
||||
{
|
||||
0x71, 0xF5, 0xB4, 0x6E, 0x80, 0xAB, 0x1D, 0xB8,
|
||||
0xFB, 0xB7, 0x49, 0xBF, 0xFF, 0x72, 0x2D, 0x14,
|
||||
0x79, 0x09, 0xE3, 0x78, 0x76, 0xB0, 0x2C, 0x0A,
|
||||
0x8E, 0x23, 0xEE, 0xDF, 0xE0, 0x9A, 0x2F, 0x67,
|
||||
0xE1, 0xBE, 0x0E, 0xA7, 0x08, 0x97, 0xEB, 0x77,
|
||||
0x78, 0xBA, 0x9D, 0xCA, 0x49, 0x4C, 0x60, 0x9A,
|
||||
0xF6, 0xBD, 0xDA, 0x7F, 0xBC, 0x48, 0x58, 0x52,
|
||||
0xE5, 0xCD, 0x83, 0x72, 0x23, 0x52, 0xFF, 0x6D,
|
||||
0xEF, 0x0F, 0x82, 0x29, 0xA0, 0x83, 0x3F, 0x7D,
|
||||
0xA4, 0x88, 0x31, 0xE7, 0x88, 0x92, 0x3B, 0x9B,
|
||||
0x3B, 0x2C, 0xC2, 0x4C, 0x71, 0xA2, 0xB0, 0xEA,
|
||||
0x36, 0xD0, 0x00, 0xF1, 0xD3, 0x39, 0x17, 0x5D,
|
||||
0x2A, 0x7A, 0xE4, 0xAD, 0xE1, 0x64, 0xCE, 0x0F,
|
||||
0x9C, 0xD9, 0xF5, 0xED, 0xB0, 0x22, 0x5E, 0x62,
|
||||
0x97, 0x02, 0xA3, 0x8C, 0x67, 0x80, 0xFC, 0x88,
|
||||
0x14, 0x0B, 0x15, 0x10, 0x0F, 0xC7, 0x40, 0xD4,
|
||||
0xF1, 0xF9, 0x0E, 0x1A, 0xCE, 0xB9, 0x1E, 0xA1,
|
||||
0x72, 0x8E, 0xD7, 0x78, 0x39, 0xCD, 0xF4, 0x5D,
|
||||
0x2A, 0x59, 0x26, 0x34, 0xF2, 0x73, 0x0B, 0xA0,
|
||||
0x02, 0x51, 0x2C, 0x03, 0xA3, 0xA7, 0x43, 0x13,
|
||||
0xE8, 0x98, 0x2B, 0xD2, 0x53, 0xF8, 0xEE, 0x91,
|
||||
0x7D, 0xE7, 0xE3, 0xDA, 0xD5, 0xBB, 0xC0, 0x92,
|
||||
0x9D, 0x98, 0x01, 0x2C, 0xF9, 0xB9, 0xA0, 0xEB,
|
||||
0xCF, 0x32, 0xFA, 0x01, 0x49, 0xA5, 0x1D, 0x9A,
|
||||
0x76, 0x86, 0x3F, 0x40, 0xD4, 0x89, 0x8F, 0x9C,
|
||||
0xE2, 0xE3, 0x11, 0x31, 0x37, 0xB2, 0x49, 0x28,
|
||||
0x35, 0xC0, 0x99, 0xB6, 0xD0, 0xBC, 0x66, 0x35,
|
||||
0xF7, 0x83, 0x5B, 0xD7, 0x37, 0x1A, 0x2B, 0x18,
|
||||
0xA6, 0xFF, 0x8D, 0x7C, 0x81, 0xA8, 0xFC, 0x9E,
|
||||
0xC4, 0xEC, 0x80, 0xD0, 0x98, 0xA7, 0x76, 0xCC,
|
||||
0x9C, 0x2F, 0x7B, 0xFF, 0x8E, 0x0E, 0xBB, 0x90,
|
||||
0xAE, 0x13, 0x06, 0xF5, 0x1C, 0x4E, 0x52, 0xF7
|
||||
}
|
||||
};
|
||||
|
||||
/* Generate and return single random byte */
|
||||
static unsigned char randomByte(void){
|
||||
unsigned char t;
|
||||
sqlite3Prng.i++;
|
||||
t = sqlite3Prng.s[sqlite3Prng.i];
|
||||
sqlite3Prng.j += t;
|
||||
sqlite3Prng.s[sqlite3Prng.i] = sqlite3Prng.s[sqlite3Prng.j];
|
||||
sqlite3Prng.s[sqlite3Prng.j] = t;
|
||||
t += sqlite3Prng.s[sqlite3Prng.i];
|
||||
return sqlite3Prng.s[t];
|
||||
}
|
||||
|
||||
/*
|
||||
** Return N random bytes.
|
||||
*/
|
||||
static void randomBlob(int nBuf, unsigned char *zBuf){
|
||||
int i;
|
||||
for(i=0; i<nBuf; i++){
|
||||
zBuf[i] = randomByte();
|
||||
}
|
||||
}
|
||||
/*
|
||||
** End of code copied from SQLite.
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
int testPrngInit(void){
|
||||
randomBlob(sizeof(r.aRand1), (unsigned char *)r.aRand1);
|
||||
randomBlob(sizeof(r.aRand2), (unsigned char *)r.aRand2);
|
||||
randomBlob(sizeof(r.aRand3), (unsigned char *)r.aRand3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int testPrngValue(unsigned int iVal){
|
||||
return
|
||||
r.aRand1[iVal & 0x000007FF] ^
|
||||
r.aRand2[(iVal>>11) & 0x000007FF] ^
|
||||
r.aRand3[(iVal>>22) & 0x000003FF]
|
||||
;
|
||||
}
|
||||
|
||||
void testPrngArray(unsigned int iVal, unsigned int *aOut, int nOut){
|
||||
int i;
|
||||
for(i=0; i<nOut; i++){
|
||||
aOut[i] = testPrngValue(iVal+i);
|
||||
}
|
||||
}
|
||||
|
||||
void testPrngString(unsigned int iVal, char *aOut, int nOut){
|
||||
int i;
|
||||
for(i=0; i<(nOut-1); i++){
|
||||
aOut[i] = 'a' + (testPrngValue(iVal+i) % 26);
|
||||
}
|
||||
aOut[i] = '\0';
|
||||
}
|
||||
|
||||
void testErrorInit(int argc, char **argv){
|
||||
g.argc = argc;
|
||||
g.argv = argv;
|
||||
}
|
||||
|
||||
void testPrintError(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
va_start(ap, zFormat);
|
||||
vfprintf(stderr, zFormat, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void testPrintFUsage(const char *zFormat, ...){
|
||||
va_list ap;
|
||||
va_start(ap, zFormat);
|
||||
fprintf(stderr, "Usage: %s %s ", g.argv[0], g.argv[1]);
|
||||
vfprintf(stderr, zFormat, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void testPrintUsage(const char *zArgs){
|
||||
testPrintError("Usage: %s %s %s\n", g.argv[0], g.argv[1], zArgs);
|
||||
}
|
||||
|
||||
|
||||
static void argError(void *aData, const char *zType, int sz, const char *zArg){
|
||||
struct Entry { const char *zName; };
|
||||
struct Entry *pEntry;
|
||||
const char *zPrev = 0;
|
||||
|
||||
testPrintError("unrecognized %s \"%s\": must be ", zType, zArg);
|
||||
for(pEntry=(struct Entry *)aData;
|
||||
pEntry->zName;
|
||||
pEntry=(struct Entry *)&((unsigned char *)pEntry)[sz]
|
||||
){
|
||||
if( zPrev ){ testPrintError("%s, ", zPrev); }
|
||||
zPrev = pEntry->zName;
|
||||
}
|
||||
testPrintError("or %s\n", zPrev);
|
||||
}
|
||||
|
||||
int testArgSelectX(
|
||||
void *aData,
|
||||
const char *zType,
|
||||
int sz,
|
||||
const char *zArg,
|
||||
int *piOut
|
||||
){
|
||||
struct Entry { const char *zName; };
|
||||
struct Entry *pEntry;
|
||||
int nArg = strlen(zArg);
|
||||
|
||||
int i = 0;
|
||||
int iOut = -1;
|
||||
int nOut = 0;
|
||||
|
||||
for(pEntry=(struct Entry *)aData;
|
||||
pEntry->zName;
|
||||
pEntry=(struct Entry *)&((unsigned char *)pEntry)[sz]
|
||||
){
|
||||
int nName = strlen(pEntry->zName);
|
||||
if( nArg<=nName && memcmp(pEntry->zName, zArg, nArg)==0 ){
|
||||
iOut = i;
|
||||
if( nName==nArg ){
|
||||
nOut = 1;
|
||||
break;
|
||||
}
|
||||
nOut++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if( nOut!=1 ){
|
||||
argError(aData, zType, sz, zArg);
|
||||
}else{
|
||||
*piOut = iOut;
|
||||
}
|
||||
return (nOut!=1);
|
||||
}
|
||||
|
||||
struct timeval zero_time;
|
||||
|
||||
void testTimeInit(void){
|
||||
gettimeofday(&zero_time, 0);
|
||||
}
|
||||
|
||||
int testTimeGet(void){
|
||||
struct timeval now;
|
||||
gettimeofday(&now, 0);
|
||||
return
|
||||
(((int)now.tv_sec - (int)zero_time.tv_sec)*1000) +
|
||||
(((int)now.tv_usec - (int)zero_time.tv_usec)/1000);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
|
||||
#include "lsmtest.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define TICKS_PER_SECOND (10000000)
|
||||
#define TICKS_PER_MICROSECOND (10)
|
||||
#define TICKS_UNIX_EPOCH (116444736000000000LL)
|
||||
|
||||
int win32GetTimeOfDay(
|
||||
struct timeval *tp,
|
||||
void *tzp
|
||||
){
|
||||
FILETIME fileTime;
|
||||
ULONGLONG ticks;
|
||||
ULONGLONG unixTicks;
|
||||
|
||||
unused_parameter(tzp);
|
||||
memset(&fileTime, 0, sizeof(FILETIME));
|
||||
GetSystemTimeAsFileTime(&fileTime);
|
||||
ticks = (ULONGLONG)fileTime.dwHighDateTime << 32;
|
||||
ticks |= (ULONGLONG)fileTime.dwLowDateTime;
|
||||
unixTicks = ticks - TICKS_UNIX_EPOCH;
|
||||
tp->tv_sec = (long)(unixTicks / TICKS_PER_SECOND);
|
||||
unixTicks -= ((ULONGLONG)tp->tv_sec * TICKS_PER_SECOND);
|
||||
tp->tv_usec = (long)(unixTicks / TICKS_PER_MICROSECOND);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
-684
@@ -1,684 +0,0 @@
|
||||
/*
|
||||
** 2011-08-10
|
||||
**
|
||||
** 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 defines the LSM API.
|
||||
*/
|
||||
#ifndef _LSM_H
|
||||
#define _LSM_H
|
||||
#include <stddef.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Opaque handle types.
|
||||
*/
|
||||
typedef struct lsm_compress lsm_compress; /* Compression library functions */
|
||||
typedef struct lsm_compress_factory lsm_compress_factory;
|
||||
typedef struct lsm_cursor lsm_cursor; /* Database cursor handle */
|
||||
typedef struct lsm_db lsm_db; /* Database connection handle */
|
||||
typedef struct lsm_env lsm_env; /* Runtime environment */
|
||||
typedef struct lsm_file lsm_file; /* OS file handle */
|
||||
typedef struct lsm_mutex lsm_mutex; /* Mutex handle */
|
||||
|
||||
/* 64-bit integer type used for file offsets. */
|
||||
typedef long long int lsm_i64; /* 64-bit signed integer type */
|
||||
|
||||
/* Candidate values for the 3rd argument to lsm_env.xLock() */
|
||||
#define LSM_LOCK_UNLOCK 0
|
||||
#define LSM_LOCK_SHARED 1
|
||||
#define LSM_LOCK_EXCL 2
|
||||
|
||||
/* Flags for lsm_env.xOpen() */
|
||||
#define LSM_OPEN_READONLY 0x0001
|
||||
|
||||
/*
|
||||
** CAPI: Database Runtime Environment
|
||||
**
|
||||
** Run-time environment used by LSM
|
||||
*/
|
||||
struct lsm_env {
|
||||
int nByte; /* Size of this structure in bytes */
|
||||
int iVersion; /* Version number of this structure (1) */
|
||||
/****** file i/o ***********************************************/
|
||||
void *pVfsCtx;
|
||||
int (*xFullpath)(lsm_env*, const char *, char *, int *);
|
||||
int (*xOpen)(lsm_env*, const char *, int flags, lsm_file **);
|
||||
int (*xRead)(lsm_file *, lsm_i64, void *, int);
|
||||
int (*xWrite)(lsm_file *, lsm_i64, void *, int);
|
||||
int (*xTruncate)(lsm_file *, lsm_i64);
|
||||
int (*xSync)(lsm_file *);
|
||||
int (*xSectorSize)(lsm_file *);
|
||||
int (*xRemap)(lsm_file *, lsm_i64, void **, lsm_i64*);
|
||||
int (*xFileid)(lsm_file *, void *pBuf, int *pnBuf);
|
||||
int (*xClose)(lsm_file *);
|
||||
int (*xUnlink)(lsm_env*, const char *);
|
||||
int (*xLock)(lsm_file*, int, int);
|
||||
int (*xTestLock)(lsm_file*, int, int, int);
|
||||
int (*xShmMap)(lsm_file*, int, int, void **);
|
||||
void (*xShmBarrier)(void);
|
||||
int (*xShmUnmap)(lsm_file*, int);
|
||||
/****** memory allocation ****************************************/
|
||||
void *pMemCtx;
|
||||
void *(*xMalloc)(lsm_env*, size_t); /* malloc(3) function */
|
||||
void *(*xRealloc)(lsm_env*, void *, size_t); /* realloc(3) function */
|
||||
void (*xFree)(lsm_env*, void *); /* free(3) function */
|
||||
size_t (*xSize)(lsm_env*, void *); /* xSize function */
|
||||
/****** mutexes ****************************************************/
|
||||
void *pMutexCtx;
|
||||
int (*xMutexStatic)(lsm_env*,int,lsm_mutex**); /* Obtain a static mutex */
|
||||
int (*xMutexNew)(lsm_env*, lsm_mutex**); /* Get a new dynamic mutex */
|
||||
void (*xMutexDel)(lsm_mutex *); /* Delete an allocated mutex */
|
||||
void (*xMutexEnter)(lsm_mutex *); /* Grab a mutex */
|
||||
int (*xMutexTry)(lsm_mutex *); /* Attempt to obtain a mutex */
|
||||
void (*xMutexLeave)(lsm_mutex *); /* Leave a mutex */
|
||||
int (*xMutexHeld)(lsm_mutex *); /* Return true if mutex is held */
|
||||
int (*xMutexNotHeld)(lsm_mutex *); /* Return true if mutex not held */
|
||||
/****** other ****************************************************/
|
||||
int (*xSleep)(lsm_env*, int microseconds);
|
||||
|
||||
/* New fields may be added in future releases, in which case the
|
||||
** iVersion value will increase. */
|
||||
};
|
||||
|
||||
/*
|
||||
** Values that may be passed as the second argument to xMutexStatic.
|
||||
*/
|
||||
#define LSM_MUTEX_GLOBAL 1
|
||||
#define LSM_MUTEX_HEAP 2
|
||||
|
||||
/*
|
||||
** CAPI: LSM Error Codes
|
||||
*/
|
||||
#define LSM_OK 0
|
||||
#define LSM_ERROR 1
|
||||
#define LSM_BUSY 5
|
||||
#define LSM_NOMEM 7
|
||||
#define LSM_READONLY 8
|
||||
#define LSM_IOERR 10
|
||||
#define LSM_CORRUPT 11
|
||||
#define LSM_FULL 13
|
||||
#define LSM_CANTOPEN 14
|
||||
#define LSM_PROTOCOL 15
|
||||
#define LSM_MISUSE 21
|
||||
|
||||
#define LSM_MISMATCH 50
|
||||
|
||||
|
||||
#define LSM_IOERR_NOENT (LSM_IOERR | (1<<8))
|
||||
|
||||
/*
|
||||
** CAPI: Creating and Destroying Database Connection Handles
|
||||
**
|
||||
** Open and close a database connection handle.
|
||||
*/
|
||||
int lsm_new(lsm_env*, lsm_db **ppDb);
|
||||
int lsm_close(lsm_db *pDb);
|
||||
|
||||
/*
|
||||
** CAPI: Connecting to a Database
|
||||
*/
|
||||
int lsm_open(lsm_db *pDb, const char *zFilename);
|
||||
|
||||
/*
|
||||
** CAPI: Obtaining pointers to database environments
|
||||
**
|
||||
** Return a pointer to the environment used by the database connection
|
||||
** passed as the first argument. Assuming the argument is valid, this
|
||||
** function always returns a valid environment pointer - it cannot fail.
|
||||
*/
|
||||
lsm_env *lsm_get_env(lsm_db *pDb);
|
||||
|
||||
/*
|
||||
** The lsm_default_env() function returns a pointer to the default LSM
|
||||
** environment for the current platform.
|
||||
*/
|
||||
lsm_env *lsm_default_env(void);
|
||||
|
||||
|
||||
/*
|
||||
** CAPI: Configuring a database connection.
|
||||
**
|
||||
** The lsm_config() function is used to configure a database connection.
|
||||
*/
|
||||
int lsm_config(lsm_db *, int, ...);
|
||||
|
||||
/*
|
||||
** The following values may be passed as the second argument to lsm_config().
|
||||
**
|
||||
** LSM_CONFIG_AUTOFLUSH:
|
||||
** A read/write integer parameter.
|
||||
**
|
||||
** This value determines the amount of data allowed to accumulate in a
|
||||
** live in-memory tree before it is marked as old. After committing a
|
||||
** transaction, a connection checks if the size of the live in-memory tree,
|
||||
** including data structure overhead, is greater than the value of this
|
||||
** option in KB. If it is, and there is not already an old in-memory tree,
|
||||
** the live in-memory tree is marked as old.
|
||||
**
|
||||
** The maximum allowable value is 1048576 (1GB). There is no minimum
|
||||
** value. If this parameter is set to zero, then an attempt is made to
|
||||
** mark the live in-memory tree as old after each transaction is committed.
|
||||
**
|
||||
** The default value is 1024 (1MB).
|
||||
**
|
||||
** LSM_CONFIG_PAGE_SIZE:
|
||||
** A read/write integer parameter. This parameter may only be set before
|
||||
** lsm_open() has been called.
|
||||
**
|
||||
** LSM_CONFIG_BLOCK_SIZE:
|
||||
** A read/write integer parameter.
|
||||
**
|
||||
** This parameter may only be set before lsm_open() has been called. It
|
||||
** must be set to a power of two between 64 and 65536, inclusive (block
|
||||
** sizes between 64KB and 64MB).
|
||||
**
|
||||
** If the connection creates a new database, the block size of the new
|
||||
** database is set to the value of this option in KB. After lsm_open()
|
||||
** has been called, querying this parameter returns the actual block
|
||||
** size of the opened database.
|
||||
**
|
||||
** The default value is 1024 (1MB blocks).
|
||||
**
|
||||
** LSM_CONFIG_SAFETY:
|
||||
** A read/write integer parameter. Valid values are 0, 1 (the default)
|
||||
** and 2. This parameter determines how robust the database is in the
|
||||
** face of a system crash (e.g. a power failure or operating system
|
||||
** crash). As follows:
|
||||
**
|
||||
** 0 (off): No robustness. A system crash may corrupt the database.
|
||||
**
|
||||
** 1 (normal): Some robustness. A system crash may not corrupt the
|
||||
** database file, but recently committed transactions may
|
||||
** be lost following recovery.
|
||||
**
|
||||
** 2 (full): Full robustness. A system crash may not corrupt the
|
||||
** database file. Following recovery the database file
|
||||
** contains all successfully committed transactions.
|
||||
**
|
||||
** LSM_CONFIG_AUTOWORK:
|
||||
** A read/write integer parameter.
|
||||
**
|
||||
** LSM_CONFIG_AUTOCHECKPOINT:
|
||||
** A read/write integer parameter.
|
||||
**
|
||||
** If this option is set to non-zero value N, then a checkpoint is
|
||||
** automatically attempted after each N KB of data have been written to
|
||||
** the database file.
|
||||
**
|
||||
** The amount of uncheckpointed data already written to the database file
|
||||
** is a global parameter. After performing database work (writing to the
|
||||
** database file), the process checks if the total amount of uncheckpointed
|
||||
** data exceeds the value of this paramter. If so, a checkpoint is performed.
|
||||
** This means that this option may cause the connection to perform a
|
||||
** checkpoint even if the current connection has itself written very little
|
||||
** data into the database file.
|
||||
**
|
||||
** The default value is 2048 (checkpoint every 2MB).
|
||||
**
|
||||
** LSM_CONFIG_MMAP:
|
||||
** A read/write integer parameter. If this value is set to 0, then the
|
||||
** database file is accessed using ordinary read/write IO functions. Or,
|
||||
** if it is set to 1, then the database file is memory mapped and accessed
|
||||
** that way. If this parameter is set to any value N greater than 1, then
|
||||
** up to the first N KB of the file are memory mapped, and any remainder
|
||||
** accessed using read/write IO.
|
||||
**
|
||||
** The default value is 1 on 64-bit platforms and 32768 on 32-bit platforms.
|
||||
**
|
||||
**
|
||||
** LSM_CONFIG_USE_LOG:
|
||||
** A read/write boolean parameter. True (the default) to use the log
|
||||
** file normally. False otherwise.
|
||||
**
|
||||
** LSM_CONFIG_AUTOMERGE:
|
||||
** A read/write integer parameter. The minimum number of segments to
|
||||
** merge together at a time. Default value 4.
|
||||
**
|
||||
** LSM_CONFIG_MAX_FREELIST:
|
||||
** A read/write integer parameter. The maximum number of free-list
|
||||
** entries that are stored in a database checkpoint (the others are
|
||||
** stored elsewhere in the database).
|
||||
**
|
||||
** There is no reason for an application to configure or query this
|
||||
** parameter. It is only present because configuring a small value
|
||||
** makes certain parts of the lsm code easier to test.
|
||||
**
|
||||
** LSM_CONFIG_MULTIPLE_PROCESSES:
|
||||
** A read/write boolean parameter. This parameter may only be set before
|
||||
** lsm_open() has been called. If true, the library uses shared-memory
|
||||
** and posix advisory locks to co-ordinate access by clients from within
|
||||
** multiple processes. Otherwise, if false, all database clients must be
|
||||
** located in the same process. The default value is true.
|
||||
**
|
||||
** LSM_CONFIG_SET_COMPRESSION:
|
||||
** Set the compression methods used to compress and decompress database
|
||||
** content. The argument to this option should be a pointer to a structure
|
||||
** of type lsm_compress. The lsm_config() method takes a copy of the
|
||||
** structures contents.
|
||||
**
|
||||
** This option may only be used before lsm_open() is called. Invoking it
|
||||
** after lsm_open() has been called results in an LSM_MISUSE error.
|
||||
**
|
||||
** LSM_CONFIG_GET_COMPRESSION:
|
||||
** Query the compression methods used to compress and decompress database
|
||||
** content.
|
||||
**
|
||||
** LSM_CONFIG_SET_COMPRESSION_FACTORY:
|
||||
** Configure a factory method to be invoked in case of an LSM_MISMATCH
|
||||
** error.
|
||||
**
|
||||
** LSM_CONFIG_READONLY:
|
||||
** A read/write boolean parameter. This parameter may only be set before
|
||||
** lsm_open() is called.
|
||||
*/
|
||||
#define LSM_CONFIG_AUTOFLUSH 1
|
||||
#define LSM_CONFIG_PAGE_SIZE 2
|
||||
#define LSM_CONFIG_SAFETY 3
|
||||
#define LSM_CONFIG_BLOCK_SIZE 4
|
||||
#define LSM_CONFIG_AUTOWORK 5
|
||||
#define LSM_CONFIG_MMAP 7
|
||||
#define LSM_CONFIG_USE_LOG 8
|
||||
#define LSM_CONFIG_AUTOMERGE 9
|
||||
#define LSM_CONFIG_MAX_FREELIST 10
|
||||
#define LSM_CONFIG_MULTIPLE_PROCESSES 11
|
||||
#define LSM_CONFIG_AUTOCHECKPOINT 12
|
||||
#define LSM_CONFIG_SET_COMPRESSION 13
|
||||
#define LSM_CONFIG_GET_COMPRESSION 14
|
||||
#define LSM_CONFIG_SET_COMPRESSION_FACTORY 15
|
||||
#define LSM_CONFIG_READONLY 16
|
||||
|
||||
#define LSM_SAFETY_OFF 0
|
||||
#define LSM_SAFETY_NORMAL 1
|
||||
#define LSM_SAFETY_FULL 2
|
||||
|
||||
/*
|
||||
** CAPI: Compression and/or Encryption Hooks
|
||||
*/
|
||||
struct lsm_compress {
|
||||
void *pCtx;
|
||||
unsigned int iId;
|
||||
int (*xBound)(void *, int nSrc);
|
||||
int (*xCompress)(void *, char *, int *, const char *, int);
|
||||
int (*xUncompress)(void *, char *, int *, const char *, int);
|
||||
void (*xFree)(void *pCtx);
|
||||
};
|
||||
|
||||
struct lsm_compress_factory {
|
||||
void *pCtx;
|
||||
int (*xFactory)(void *, lsm_db *, unsigned int);
|
||||
void (*xFree)(void *pCtx);
|
||||
};
|
||||
|
||||
#define LSM_COMPRESSION_EMPTY 0
|
||||
#define LSM_COMPRESSION_NONE 1
|
||||
|
||||
/*
|
||||
** CAPI: Allocating and Freeing Memory
|
||||
**
|
||||
** Invoke the memory allocation functions that belong to environment
|
||||
** pEnv. Or the system defaults if no memory allocation functions have
|
||||
** been registered.
|
||||
*/
|
||||
void *lsm_malloc(lsm_env*, size_t);
|
||||
void *lsm_realloc(lsm_env*, void *, size_t);
|
||||
void lsm_free(lsm_env*, void *);
|
||||
|
||||
/*
|
||||
** CAPI: Querying a Connection For Operational Data
|
||||
**
|
||||
** Query a database connection for operational statistics or data.
|
||||
*/
|
||||
int lsm_info(lsm_db *, int, ...);
|
||||
|
||||
int lsm_get_user_version(lsm_db *, unsigned int *);
|
||||
int lsm_set_user_version(lsm_db *, unsigned int);
|
||||
|
||||
/*
|
||||
** The following values may be passed as the second argument to lsm_info().
|
||||
**
|
||||
** LSM_INFO_NWRITE:
|
||||
** The third parameter should be of type (int *). The location pointed
|
||||
** to by the third parameter is set to the number of 4KB pages written to
|
||||
** the database file during the lifetime of this connection.
|
||||
**
|
||||
** LSM_INFO_NREAD:
|
||||
** The third parameter should be of type (int *). The location pointed
|
||||
** to by the third parameter is set to the number of 4KB pages read from
|
||||
** the database file during the lifetime of this connection.
|
||||
**
|
||||
** LSM_INFO_DB_STRUCTURE:
|
||||
** The third argument should be of type (char **). The location pointed
|
||||
** to is populated with a pointer to a nul-terminated string containing
|
||||
** the string representation of a Tcl data-structure reflecting the
|
||||
** current structure of the database file. Specifically, the current state
|
||||
** of the worker snapshot. The returned string should be eventually freed
|
||||
** by the caller using lsm_free().
|
||||
**
|
||||
** The returned list contains one element for each level in the database,
|
||||
** in order from most to least recent. Each element contains a
|
||||
** single element for each segment comprising the corresponding level,
|
||||
** starting with the lhs segment, then each of the rhs segments (if any)
|
||||
** in order from most to least recent.
|
||||
**
|
||||
** Each segment element is itself a list of 4 integer values, as follows:
|
||||
**
|
||||
** <ol><li> First page of segment
|
||||
** <li> Last page of segment
|
||||
** <li> Root page of segment (if applicable)
|
||||
** <li> Total number of pages in segment
|
||||
** </ol>
|
||||
**
|
||||
** LSM_INFO_ARRAY_STRUCTURE:
|
||||
** There should be two arguments passed following this option (i.e. a
|
||||
** total of four arguments passed to lsm_info()). The first argument
|
||||
** should be the page number of the first page in a database array
|
||||
** (perhaps obtained from an earlier INFO_DB_STRUCTURE call). The second
|
||||
** trailing argument should be of type (char **). The location pointed
|
||||
** to is populated with a pointer to a nul-terminated string that must
|
||||
** be eventually freed using lsm_free() by the caller.
|
||||
**
|
||||
** The output string contains the text representation of a Tcl list of
|
||||
** integers. Each pair of integers represent a range of pages used by
|
||||
** the identified array. For example, if the array occupies database
|
||||
** pages 993 to 1024, then pages 2048 to 2777, then the returned string
|
||||
** will be "993 1024 2048 2777".
|
||||
**
|
||||
** If the specified integer argument does not correspond to the first
|
||||
** page of any database array, LSM_ERROR is returned and the output
|
||||
** pointer is set to a NULL value.
|
||||
**
|
||||
** LSM_INFO_LOG_STRUCTURE:
|
||||
** The third argument should be of type (char **). The location pointed
|
||||
** to is populated with a pointer to a nul-terminated string containing
|
||||
** the string representation of a Tcl data-structure. The returned
|
||||
** string should be eventually freed by the caller using lsm_free().
|
||||
**
|
||||
** The Tcl structure returned is a list of six integers that describe
|
||||
** the current structure of the log file.
|
||||
**
|
||||
** LSM_INFO_ARRAY_PAGES:
|
||||
**
|
||||
** LSM_INFO_PAGE_ASCII_DUMP:
|
||||
** As with LSM_INFO_ARRAY_STRUCTURE, there should be two arguments passed
|
||||
** with calls that specify this option - an integer page number and a
|
||||
** (char **) used to return a nul-terminated string that must be later
|
||||
** freed using lsm_free(). In this case the output string is populated
|
||||
** with a human-readable description of the page content.
|
||||
**
|
||||
** If the page cannot be decoded, it is not an error. In this case the
|
||||
** human-readable output message will report the systems failure to
|
||||
** interpret the page data.
|
||||
**
|
||||
** LSM_INFO_PAGE_HEX_DUMP:
|
||||
** This argument is similar to PAGE_ASCII_DUMP, except that keys and
|
||||
** values are represented using hexadecimal notation instead of ascii.
|
||||
**
|
||||
** LSM_INFO_FREELIST:
|
||||
** The third argument should be of type (char **). The location pointed
|
||||
** to is populated with a pointer to a nul-terminated string containing
|
||||
** the string representation of a Tcl data-structure. The returned
|
||||
** string should be eventually freed by the caller using lsm_free().
|
||||
**
|
||||
** The Tcl structure returned is a list containing one element for each
|
||||
** free block in the database. The element itself consists of two
|
||||
** integers - the block number and the id of the snapshot that freed it.
|
||||
**
|
||||
** LSM_INFO_CHECKPOINT_SIZE:
|
||||
** The third argument should be of type (int *). The location pointed to
|
||||
** by this argument is populated with the number of KB written to the
|
||||
** database file since the most recent checkpoint.
|
||||
**
|
||||
** LSM_INFO_TREE_SIZE:
|
||||
** If this value is passed as the second argument to an lsm_info() call, it
|
||||
** should be followed by two arguments of type (int *) (for a total of four
|
||||
** arguments).
|
||||
**
|
||||
** At any time, there are either one or two tree structures held in shared
|
||||
** memory that new database clients will access (there may also be additional
|
||||
** tree structures being used by older clients - this API does not provide
|
||||
** information on them). One tree structure - the current tree - is used to
|
||||
** accumulate new data written to the database. The other tree structure -
|
||||
** the old tree - is a read-only tree holding older data and may be flushed
|
||||
** to disk at any time.
|
||||
**
|
||||
** Assuming no error occurs, the location pointed to by the first of the two
|
||||
** (int *) arguments is set to the size of the old in-memory tree in KB.
|
||||
** The second is set to the size of the current, or live in-memory tree.
|
||||
**
|
||||
** LSM_INFO_COMPRESSION_ID:
|
||||
** This value should be followed by a single argument of type
|
||||
** (unsigned int *). If successful, the location pointed to is populated
|
||||
** with the database compression id before returning.
|
||||
*/
|
||||
#define LSM_INFO_NWRITE 1
|
||||
#define LSM_INFO_NREAD 2
|
||||
#define LSM_INFO_DB_STRUCTURE 3
|
||||
#define LSM_INFO_LOG_STRUCTURE 4
|
||||
#define LSM_INFO_ARRAY_STRUCTURE 5
|
||||
#define LSM_INFO_PAGE_ASCII_DUMP 6
|
||||
#define LSM_INFO_PAGE_HEX_DUMP 7
|
||||
#define LSM_INFO_FREELIST 8
|
||||
#define LSM_INFO_ARRAY_PAGES 9
|
||||
#define LSM_INFO_CHECKPOINT_SIZE 10
|
||||
#define LSM_INFO_TREE_SIZE 11
|
||||
#define LSM_INFO_FREELIST_SIZE 12
|
||||
#define LSM_INFO_COMPRESSION_ID 13
|
||||
|
||||
|
||||
/*
|
||||
** CAPI: Opening and Closing Write Transactions
|
||||
**
|
||||
** These functions are used to open and close transactions and nested
|
||||
** sub-transactions.
|
||||
**
|
||||
** The lsm_begin() function is used to open transactions and sub-transactions.
|
||||
** A successful call to lsm_begin() ensures that there are at least iLevel
|
||||
** nested transactions open. To open a top-level transaction, pass iLevel=1.
|
||||
** To open a sub-transaction within the top-level transaction, iLevel=2.
|
||||
** Passing iLevel=0 is a no-op.
|
||||
**
|
||||
** lsm_commit() is used to commit transactions and sub-transactions. A
|
||||
** successful call to lsm_commit() ensures that there are at most iLevel
|
||||
** nested transactions open. To commit a top-level transaction, pass iLevel=0.
|
||||
** To commit all sub-transactions inside the main transaction, pass iLevel=1.
|
||||
**
|
||||
** Function lsm_rollback() is used to roll back transactions and
|
||||
** sub-transactions. A successful call to lsm_rollback() restores the database
|
||||
** to the state it was in when the iLevel'th nested sub-transaction (if any)
|
||||
** was first opened. And then closes transactions to ensure that there are
|
||||
** at most iLevel nested transactions open. Passing iLevel=0 rolls back and
|
||||
** closes the top-level transaction. iLevel=1 also rolls back the top-level
|
||||
** transaction, but leaves it open. iLevel=2 rolls back the sub-transaction
|
||||
** nested directly inside the top-level transaction (and leaves it open).
|
||||
*/
|
||||
int lsm_begin(lsm_db *pDb, int iLevel);
|
||||
int lsm_commit(lsm_db *pDb, int iLevel);
|
||||
int lsm_rollback(lsm_db *pDb, int iLevel);
|
||||
|
||||
/*
|
||||
** CAPI: Writing to a Database
|
||||
**
|
||||
** Write a new value into the database. If a value with a duplicate key
|
||||
** already exists it is replaced.
|
||||
*/
|
||||
int lsm_insert(lsm_db*, const void *pKey, int nKey, const void *pVal, int nVal);
|
||||
|
||||
/*
|
||||
** Delete a value from the database. No error is returned if the specified
|
||||
** key value does not exist in the database.
|
||||
*/
|
||||
int lsm_delete(lsm_db *, const void *pKey, int nKey);
|
||||
|
||||
/*
|
||||
** Delete all database entries with keys that are greater than (pKey1/nKey1)
|
||||
** and smaller than (pKey2/nKey2). Note that keys (pKey1/nKey1) and
|
||||
** (pKey2/nKey2) themselves, if they exist in the database, are not deleted.
|
||||
**
|
||||
** Return LSM_OK if successful, or an LSM error code otherwise.
|
||||
*/
|
||||
int lsm_delete_range(lsm_db *,
|
||||
const void *pKey1, int nKey1, const void *pKey2, int nKey2
|
||||
);
|
||||
|
||||
/*
|
||||
** CAPI: Explicit Database Work and Checkpointing
|
||||
**
|
||||
** This function is called by a thread to work on the database structure.
|
||||
*/
|
||||
int lsm_work(lsm_db *pDb, int nMerge, int nKB, int *pnWrite);
|
||||
|
||||
int lsm_flush(lsm_db *pDb);
|
||||
|
||||
/*
|
||||
** Attempt to checkpoint the current database snapshot. Return an LSM
|
||||
** error code if an error occurs or LSM_OK otherwise.
|
||||
**
|
||||
** If the current snapshot has already been checkpointed, calling this
|
||||
** function is a no-op. In this case if pnKB is not NULL, *pnKB is
|
||||
** set to 0. Or, if the current snapshot is successfully checkpointed
|
||||
** by this function and pbKB is not NULL, *pnKB is set to the number
|
||||
** of bytes written to the database file since the previous checkpoint
|
||||
** (the same measure as returned by the LSM_INFO_CHECKPOINT_SIZE query).
|
||||
*/
|
||||
int lsm_checkpoint(lsm_db *pDb, int *pnKB);
|
||||
|
||||
/*
|
||||
** CAPI: Opening and Closing Database Cursors
|
||||
**
|
||||
** Open and close a database cursor.
|
||||
*/
|
||||
int lsm_csr_open(lsm_db *pDb, lsm_cursor **ppCsr);
|
||||
int lsm_csr_close(lsm_cursor *pCsr);
|
||||
|
||||
/*
|
||||
** CAPI: Positioning Database Cursors
|
||||
**
|
||||
** If the fourth parameter is LSM_SEEK_EQ, LSM_SEEK_GE or LSM_SEEK_LE,
|
||||
** this function searches the database for an entry with key (pKey/nKey).
|
||||
** If an error occurs, an LSM error code is returned. Otherwise, LSM_OK.
|
||||
**
|
||||
** If no error occurs and the requested key is present in the database, the
|
||||
** cursor is left pointing to the entry with the specified key. Or, if the
|
||||
** specified key is not present in the database the state of the cursor
|
||||
** depends on the value passed as the final parameter, as follows:
|
||||
**
|
||||
** LSM_SEEK_EQ:
|
||||
** The cursor is left at EOF (invalidated). A call to lsm_csr_valid()
|
||||
** returns non-zero.
|
||||
**
|
||||
** LSM_SEEK_LE:
|
||||
** The cursor is left pointing to the largest key in the database that
|
||||
** is smaller than (pKey/nKey). If the database contains no keys smaller
|
||||
** than (pKey/nKey), the cursor is left at EOF.
|
||||
**
|
||||
** LSM_SEEK_GE:
|
||||
** The cursor is left pointing to the smallest key in the database that
|
||||
** is larger than (pKey/nKey). If the database contains no keys larger
|
||||
** than (pKey/nKey), the cursor is left at EOF.
|
||||
**
|
||||
** If the fourth parameter is LSM_SEEK_LEFAST, this function searches the
|
||||
** database in a similar manner to LSM_SEEK_LE, with two differences:
|
||||
**
|
||||
** <ol><li>Even if a key can be found (the cursor is not left at EOF), the
|
||||
** lsm_csr_value() function may not be used (attempts to do so return
|
||||
** LSM_MISUSE).
|
||||
**
|
||||
** <li>The key that the cursor is left pointing to may be one that has
|
||||
** been recently deleted from the database. In this case it is
|
||||
** guaranteed that the returned key is larger than any key currently
|
||||
** in the database that is less than or equal to (pKey/nKey).
|
||||
** </ol>
|
||||
**
|
||||
** LSM_SEEK_LEFAST requests are intended to be used to allocate database
|
||||
** keys.
|
||||
*/
|
||||
int lsm_csr_seek(lsm_cursor *pCsr, const void *pKey, int nKey, int eSeek);
|
||||
|
||||
int lsm_csr_first(lsm_cursor *pCsr);
|
||||
int lsm_csr_last(lsm_cursor *pCsr);
|
||||
|
||||
/*
|
||||
** Advance the specified cursor to the next or previous key in the database.
|
||||
** Return LSM_OK if successful, or an LSM error code otherwise.
|
||||
**
|
||||
** Functions lsm_csr_seek(), lsm_csr_first() and lsm_csr_last() are "seek"
|
||||
** functions. Whether or not lsm_csr_next and lsm_csr_prev may be called
|
||||
** successfully also depends on the most recent seek function called on
|
||||
** the cursor. Specifically:
|
||||
**
|
||||
** <ul>
|
||||
** <li> At least one seek function must have been called on the cursor.
|
||||
** <li> To call lsm_csr_next(), the most recent call to a seek function must
|
||||
** have been either lsm_csr_first() or a call to lsm_csr_seek() specifying
|
||||
** LSM_SEEK_GE.
|
||||
** <li> To call lsm_csr_prev(), the most recent call to a seek function must
|
||||
** have been either lsm_csr_last() or a call to lsm_csr_seek() specifying
|
||||
** LSM_SEEK_LE.
|
||||
** </ul>
|
||||
**
|
||||
** Otherwise, if the above conditions are not met when lsm_csr_next or
|
||||
** lsm_csr_prev is called, LSM_MISUSE is returned and the cursor position
|
||||
** remains unchanged.
|
||||
*/
|
||||
int lsm_csr_next(lsm_cursor *pCsr);
|
||||
int lsm_csr_prev(lsm_cursor *pCsr);
|
||||
|
||||
/*
|
||||
** Values that may be passed as the fourth argument to lsm_csr_seek().
|
||||
*/
|
||||
#define LSM_SEEK_LEFAST -2
|
||||
#define LSM_SEEK_LE -1
|
||||
#define LSM_SEEK_EQ 0
|
||||
#define LSM_SEEK_GE 1
|
||||
|
||||
/*
|
||||
** CAPI: Extracting Data From Database Cursors
|
||||
**
|
||||
** Retrieve data from a database cursor.
|
||||
*/
|
||||
int lsm_csr_valid(lsm_cursor *pCsr);
|
||||
int lsm_csr_key(lsm_cursor *pCsr, const void **ppKey, int *pnKey);
|
||||
int lsm_csr_value(lsm_cursor *pCsr, const void **ppVal, int *pnVal);
|
||||
|
||||
/*
|
||||
** If no error occurs, this function compares the database key passed via
|
||||
** the pKey/nKey arguments with the key that the cursor passed as the first
|
||||
** argument currently points to. If the cursors key is less than, equal to
|
||||
** or greater than pKey/nKey, *piRes is set to less than, equal to or greater
|
||||
** than zero before returning. LSM_OK is returned in this case.
|
||||
**
|
||||
** Or, if an error occurs, an LSM error code is returned and the final
|
||||
** value of *piRes is undefined. If the cursor does not point to a valid
|
||||
** key when this function is called, LSM_MISUSE is returned.
|
||||
*/
|
||||
int lsm_csr_cmp(lsm_cursor *pCsr, const void *pKey, int nKey, int *piRes);
|
||||
|
||||
/*
|
||||
** CAPI: Change these!!
|
||||
**
|
||||
** Configure a callback to which debugging and other messages should
|
||||
** be directed. Only useful for debugging lsm.
|
||||
*/
|
||||
void lsm_config_log(lsm_db *, void (*)(void *, int, const char *), void *);
|
||||
|
||||
/*
|
||||
** Configure a callback that is invoked if the database connection ever
|
||||
** writes to the database file.
|
||||
*/
|
||||
void lsm_config_work_hook(lsm_db *, void (*)(lsm_db *, void *), void *);
|
||||
|
||||
/* ENDOFAPI */
|
||||
#ifdef __cplusplus
|
||||
} /* End of the 'extern "C"' block */
|
||||
#endif
|
||||
#endif /* ifndef _LSM_H */
|
||||
@@ -1,997 +0,0 @@
|
||||
/*
|
||||
** 2011-08-18
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** Internal structure definitions for the LSM module.
|
||||
*/
|
||||
#ifndef _LSM_INT_H
|
||||
#define _LSM_INT_H
|
||||
|
||||
#include "lsm.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef _MSC_VER
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
# ifdef LSM_DEBUG_EXPENSIVE
|
||||
# undef LSM_DEBUG_EXPENSIVE
|
||||
# endif
|
||||
# ifdef LSM_DEBUG
|
||||
# undef LSM_DEBUG
|
||||
# endif
|
||||
#else
|
||||
# ifndef LSM_DEBUG
|
||||
# define LSM_DEBUG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* #define LSM_DEBUG_EXPENSIVE 1 */
|
||||
|
||||
/*
|
||||
** Default values for various data structure parameters. These may be
|
||||
** overridden by calls to lsm_config().
|
||||
*/
|
||||
#define LSM_DFLT_PAGE_SIZE (4 * 1024)
|
||||
#define LSM_DFLT_BLOCK_SIZE (1 * 1024 * 1024)
|
||||
#define LSM_DFLT_AUTOFLUSH (1 * 1024 * 1024)
|
||||
#define LSM_DFLT_AUTOCHECKPOINT (i64)(2 * 1024 * 1024)
|
||||
#define LSM_DFLT_AUTOWORK 1
|
||||
#define LSM_DFLT_LOG_SIZE (128*1024)
|
||||
#define LSM_DFLT_AUTOMERGE 4
|
||||
#define LSM_DFLT_SAFETY LSM_SAFETY_NORMAL
|
||||
#define LSM_DFLT_MMAP (LSM_IS_64_BIT ? 1 : 32768)
|
||||
#define LSM_DFLT_MULTIPLE_PROCESSES 1
|
||||
#define LSM_DFLT_USE_LOG 1
|
||||
|
||||
/* Initial values for log file checksums. These are only used if the
|
||||
** database file does not contain a valid checkpoint. */
|
||||
#define LSM_CKSUM0_INIT 42
|
||||
#define LSM_CKSUM1_INIT 42
|
||||
|
||||
/* "mmap" mode is currently only used in environments with 64-bit address
|
||||
** spaces. The following macro is used to test for this. */
|
||||
#define LSM_IS_64_BIT (sizeof(void*)==8)
|
||||
|
||||
#define LSM_AUTOWORK_QUANT 32
|
||||
|
||||
typedef struct Database Database;
|
||||
typedef struct DbLog DbLog;
|
||||
typedef struct FileSystem FileSystem;
|
||||
typedef struct Freelist Freelist;
|
||||
typedef struct FreelistEntry FreelistEntry;
|
||||
typedef struct Level Level;
|
||||
typedef struct LogMark LogMark;
|
||||
typedef struct LogRegion LogRegion;
|
||||
typedef struct LogWriter LogWriter;
|
||||
typedef struct LsmString LsmString;
|
||||
typedef struct Mempool Mempool;
|
||||
typedef struct Merge Merge;
|
||||
typedef struct MergeInput MergeInput;
|
||||
typedef struct MetaPage MetaPage;
|
||||
typedef struct MultiCursor MultiCursor;
|
||||
typedef struct Page Page;
|
||||
typedef struct Redirect Redirect;
|
||||
typedef struct Segment Segment;
|
||||
typedef struct SegmentMerger SegmentMerger;
|
||||
typedef struct ShmChunk ShmChunk;
|
||||
typedef struct ShmHeader ShmHeader;
|
||||
typedef struct ShmReader ShmReader;
|
||||
typedef struct Snapshot Snapshot;
|
||||
typedef struct TransMark TransMark;
|
||||
typedef struct Tree Tree;
|
||||
typedef struct TreeCursor TreeCursor;
|
||||
typedef struct TreeHeader TreeHeader;
|
||||
typedef struct TreeMark TreeMark;
|
||||
typedef struct TreeRoot TreeRoot;
|
||||
|
||||
#ifndef _SQLITEINT_H_
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short int u16;
|
||||
typedef unsigned int u32;
|
||||
typedef lsm_i64 i64;
|
||||
typedef unsigned long long int u64;
|
||||
#endif
|
||||
|
||||
/* A page number is a 64-bit integer. */
|
||||
typedef i64 LsmPgno;
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
int lsmErrorBkpt(int);
|
||||
#else
|
||||
# define lsmErrorBkpt(x) (x)
|
||||
#endif
|
||||
|
||||
#define LSM_PROTOCOL_BKPT lsmErrorBkpt(LSM_PROTOCOL)
|
||||
#define LSM_IOERR_BKPT lsmErrorBkpt(LSM_IOERR)
|
||||
#define LSM_NOMEM_BKPT lsmErrorBkpt(LSM_NOMEM)
|
||||
#define LSM_CORRUPT_BKPT lsmErrorBkpt(LSM_CORRUPT)
|
||||
#define LSM_MISUSE_BKPT lsmErrorBkpt(LSM_MISUSE)
|
||||
|
||||
#define unused_parameter(x) (void)(x)
|
||||
#define array_size(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
|
||||
/* The size of each shared-memory chunk */
|
||||
#define LSM_SHM_CHUNK_SIZE (32*1024)
|
||||
|
||||
/* The number of bytes reserved at the start of each shm chunk for MM. */
|
||||
#define LSM_SHM_CHUNK_HDR (sizeof(ShmChunk))
|
||||
|
||||
/* The number of available read locks. */
|
||||
#define LSM_LOCK_NREADER 6
|
||||
|
||||
/* The number of available read-write client locks. */
|
||||
#define LSM_LOCK_NRWCLIENT 16
|
||||
|
||||
/* Lock definitions.
|
||||
*/
|
||||
#define LSM_LOCK_DMS1 1 /* Serialize connect/disconnect ops */
|
||||
#define LSM_LOCK_DMS2 2 /* Read-write connections */
|
||||
#define LSM_LOCK_DMS3 3 /* Read-only connections */
|
||||
#define LSM_LOCK_WRITER 4
|
||||
#define LSM_LOCK_WORKER 5
|
||||
#define LSM_LOCK_CHECKPOINTER 6
|
||||
#define LSM_LOCK_ROTRANS 7
|
||||
#define LSM_LOCK_READER(i) ((i) + LSM_LOCK_ROTRANS + 1)
|
||||
#define LSM_LOCK_RWCLIENT(i) ((i) + LSM_LOCK_READER(LSM_LOCK_NREADER))
|
||||
|
||||
#define LSM_N_LOCK LSM_LOCK_RWCLIENT(LSM_LOCK_NRWCLIENT)
|
||||
|
||||
/*
|
||||
** Meta-page size and usable size.
|
||||
*/
|
||||
#define LSM_META_PAGE_SIZE 4096
|
||||
|
||||
#define LSM_META_RW_PAGE_SIZE (LSM_META_PAGE_SIZE - LSM_N_LOCK)
|
||||
|
||||
/*
|
||||
** Hard limit on the number of free-list entries that may be stored in
|
||||
** a checkpoint (the remainder are stored as a system record in the LSM).
|
||||
** See also LSM_CONFIG_MAX_FREELIST.
|
||||
*/
|
||||
#define LSM_MAX_FREELIST_ENTRIES 24
|
||||
|
||||
#define LSM_MAX_BLOCK_REDIRECTS 16
|
||||
|
||||
#define LSM_ATTEMPTS_BEFORE_PROTOCOL 10000
|
||||
|
||||
|
||||
/*
|
||||
** Each entry stored in the LSM (or in-memory tree structure) has an
|
||||
** associated mask of the following flags.
|
||||
*/
|
||||
#define LSM_START_DELETE 0x01 /* Start of open-ended delete range */
|
||||
#define LSM_END_DELETE 0x02 /* End of open-ended delete range */
|
||||
#define LSM_POINT_DELETE 0x04 /* Delete this key */
|
||||
#define LSM_INSERT 0x08 /* Insert this key and value */
|
||||
#define LSM_SEPARATOR 0x10 /* True if entry is separator key only */
|
||||
#define LSM_SYSTEMKEY 0x20 /* True if entry is a system key (FREELIST) */
|
||||
|
||||
#define LSM_CONTIGUOUS 0x40 /* Used in lsm_tree.c */
|
||||
|
||||
/*
|
||||
** A string that can grow by appending.
|
||||
*/
|
||||
struct LsmString {
|
||||
lsm_env *pEnv; /* Run-time environment */
|
||||
int n; /* Size of string. -1 indicates error */
|
||||
int nAlloc; /* Space allocated for z[] */
|
||||
char *z; /* The string content */
|
||||
};
|
||||
|
||||
typedef struct LsmFile LsmFile;
|
||||
struct LsmFile {
|
||||
lsm_file *pFile;
|
||||
LsmFile *pNext;
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of the following type is used to store an ordered list of
|
||||
** u32 values.
|
||||
**
|
||||
** Note: This is a place-holder implementation. It should be replaced by
|
||||
** a version that avoids making a single large allocation when the array
|
||||
** contains a large number of values. For this reason, the internals of
|
||||
** this object should only manipulated by the intArrayXXX() functions in
|
||||
** lsm_tree.c.
|
||||
*/
|
||||
typedef struct IntArray IntArray;
|
||||
struct IntArray {
|
||||
int nAlloc;
|
||||
int nArray;
|
||||
u32 *aArray;
|
||||
};
|
||||
|
||||
struct Redirect {
|
||||
int n; /* Number of redirects */
|
||||
struct RedirectEntry {
|
||||
int iFrom;
|
||||
int iTo;
|
||||
} *a;
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure represents a point in the history of the
|
||||
** tree structure to roll back to. Refer to comments in lsm_tree.c for
|
||||
** details.
|
||||
*/
|
||||
struct TreeMark {
|
||||
u32 iRoot; /* Offset of root node in shm file */
|
||||
u32 nHeight; /* Current height of tree structure */
|
||||
u32 iWrite; /* Write offset in shm file */
|
||||
u32 nChunk; /* Number of chunks in shared-memory file */
|
||||
u32 iFirst; /* First chunk in linked list */
|
||||
u32 iNextShmid; /* Next id to allocate */
|
||||
int iRollback; /* Index in lsm->rollback to revert to */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure represents a point in the database log.
|
||||
*/
|
||||
struct LogMark {
|
||||
i64 iOff; /* Offset into log (see lsm_log.c) */
|
||||
int nBuf; /* Size of in-memory buffer here */
|
||||
u8 aBuf[8]; /* Bytes of content in aBuf[] */
|
||||
u32 cksum0; /* Checksum 0 at offset (iOff-nBuf) */
|
||||
u32 cksum1; /* Checksum 1 at offset (iOff-nBuf) */
|
||||
};
|
||||
|
||||
struct TransMark {
|
||||
TreeMark tree;
|
||||
LogMark log;
|
||||
};
|
||||
|
||||
/*
|
||||
** A structure that defines the start and end offsets of a region in the
|
||||
** log file. The size of the region in bytes is (iEnd - iStart), so if
|
||||
** iEnd==iStart the region is zero bytes in size.
|
||||
*/
|
||||
struct LogRegion {
|
||||
i64 iStart; /* Start of region in log file */
|
||||
i64 iEnd; /* End of region in log file */
|
||||
};
|
||||
|
||||
struct DbLog {
|
||||
u32 cksum0; /* Checksum 0 at offset iOff */
|
||||
u32 cksum1; /* Checksum 1 at offset iOff */
|
||||
i64 iSnapshotId; /* Log space has been reclaimed to this ss */
|
||||
LogRegion aRegion[3]; /* Log file regions (see docs in lsm_log.c) */
|
||||
};
|
||||
|
||||
struct TreeRoot {
|
||||
u32 iRoot;
|
||||
u32 nHeight;
|
||||
u32 nByte; /* Total size of this tree in bytes */
|
||||
u32 iTransId;
|
||||
};
|
||||
|
||||
/*
|
||||
** Tree header structure.
|
||||
*/
|
||||
struct TreeHeader {
|
||||
u32 iUsedShmid; /* Id of first shm chunk used by this tree */
|
||||
u32 iNextShmid; /* Shm-id of next chunk allocated */
|
||||
u32 iFirst; /* Chunk number of smallest shm-id */
|
||||
u32 nChunk; /* Number of chunks in shared-memory file */
|
||||
TreeRoot root; /* Root and height of current tree */
|
||||
u32 iWrite; /* Write offset in shm file */
|
||||
TreeRoot oldroot; /* Root and height of the previous tree */
|
||||
u32 iOldShmid; /* Last shm-id used by previous tree */
|
||||
u32 iUsrVersion; /* get/set_user_version() value */
|
||||
i64 iOldLog; /* Log offset associated with old tree */
|
||||
u32 oldcksum0;
|
||||
u32 oldcksum1;
|
||||
DbLog log; /* Current layout of log file */
|
||||
u32 aCksum[2]; /* Checksums 1 and 2. */
|
||||
};
|
||||
|
||||
/*
|
||||
** Database handle structure.
|
||||
**
|
||||
** mLock:
|
||||
** A bitmask representing the locks currently held by the connection.
|
||||
** An LSM database supports N distinct locks, where N is some number less
|
||||
** than or equal to 32. Locks are numbered starting from 1 (see the
|
||||
** definitions for LSM_LOCK_WRITER and co.).
|
||||
**
|
||||
** The least significant 32-bits in mLock represent EXCLUSIVE locks. The
|
||||
** most significant are SHARED locks. So, if a connection holds a SHARED
|
||||
** lock on lock region iLock, then the following is true:
|
||||
**
|
||||
** (mLock & ((iLock+32-1) << 1))
|
||||
**
|
||||
** Or for an EXCLUSIVE lock:
|
||||
**
|
||||
** (mLock & ((iLock-1) << 1))
|
||||
**
|
||||
** pCsr:
|
||||
** Points to the head of a linked list that contains all currently open
|
||||
** cursors. Once this list becomes empty, the user has no outstanding
|
||||
** cursors and the database handle can be successfully closed.
|
||||
**
|
||||
** pCsrCache:
|
||||
** This list contains cursor objects that have been closed using
|
||||
** lsm_csr_close(). Each time a cursor is closed, it is shifted from
|
||||
** the pCsr list to this list. When a new cursor is opened, this list
|
||||
** is inspected to see if there exists a cursor object that can be
|
||||
** reused. This is an optimization only.
|
||||
*/
|
||||
struct lsm_db {
|
||||
|
||||
/* Database handle configuration */
|
||||
lsm_env *pEnv; /* runtime environment */
|
||||
int (*xCmp)(void *, int, void *, int); /* Compare function */
|
||||
|
||||
/* Values configured by calls to lsm_config */
|
||||
int eSafety; /* LSM_SAFETY_OFF, NORMAL or FULL */
|
||||
int bAutowork; /* Configured by LSM_CONFIG_AUTOWORK */
|
||||
int nTreeLimit; /* Configured by LSM_CONFIG_AUTOFLUSH */
|
||||
int nMerge; /* Configured by LSM_CONFIG_AUTOMERGE */
|
||||
int bUseLog; /* Configured by LSM_CONFIG_USE_LOG */
|
||||
int nDfltPgsz; /* Configured by LSM_CONFIG_PAGE_SIZE */
|
||||
int nDfltBlksz; /* Configured by LSM_CONFIG_BLOCK_SIZE */
|
||||
int nMaxFreelist; /* Configured by LSM_CONFIG_MAX_FREELIST */
|
||||
int iMmap; /* Configured by LSM_CONFIG_MMAP */
|
||||
i64 nAutockpt; /* Configured by LSM_CONFIG_AUTOCHECKPOINT */
|
||||
int bMultiProc; /* Configured by L_C_MULTIPLE_PROCESSES */
|
||||
int bReadonly; /* Configured by LSM_CONFIG_READONLY */
|
||||
lsm_compress compress; /* Compression callbacks */
|
||||
lsm_compress_factory factory; /* Compression callback factory */
|
||||
|
||||
/* Sub-system handles */
|
||||
FileSystem *pFS; /* On-disk portion of database */
|
||||
Database *pDatabase; /* Database shared data */
|
||||
|
||||
int iRwclient; /* Read-write client lock held (-1 == none) */
|
||||
|
||||
/* Client transaction context */
|
||||
Snapshot *pClient; /* Client snapshot */
|
||||
int iReader; /* Read lock held (-1 == unlocked) */
|
||||
int bRoTrans; /* True if a read-only db trans is open */
|
||||
MultiCursor *pCsr; /* List of all open cursors */
|
||||
LogWriter *pLogWriter; /* Context for writing to the log file */
|
||||
int nTransOpen; /* Number of opened write transactions */
|
||||
int nTransAlloc; /* Allocated size of aTrans[] array */
|
||||
TransMark *aTrans; /* Array of marks for transaction rollback */
|
||||
IntArray rollback; /* List of tree-nodes to roll back */
|
||||
int bDiscardOld; /* True if lsmTreeDiscardOld() was called */
|
||||
|
||||
MultiCursor *pCsrCache; /* List of all closed cursors */
|
||||
|
||||
/* Worker context */
|
||||
Snapshot *pWorker; /* Worker snapshot (or NULL) */
|
||||
Freelist *pFreelist; /* See sortedNewToplevel() */
|
||||
int bUseFreelist; /* True to use pFreelist */
|
||||
int bIncrMerge; /* True if currently doing a merge */
|
||||
|
||||
int bInFactory; /* True if within factory.xFactory() */
|
||||
|
||||
/* Debugging message callback */
|
||||
void (*xLog)(void *, int, const char *);
|
||||
void *pLogCtx;
|
||||
|
||||
/* Work done notification callback */
|
||||
void (*xWork)(lsm_db *, void *);
|
||||
void *pWorkCtx;
|
||||
|
||||
u64 mLock; /* Mask of current locks. See lsmShmLock(). */
|
||||
lsm_db *pNext; /* Next connection to same database */
|
||||
|
||||
int nShm; /* Size of apShm[] array */
|
||||
void **apShm; /* Shared memory chunks */
|
||||
ShmHeader *pShmhdr; /* Live shared-memory header */
|
||||
TreeHeader treehdr; /* Local copy of tree-header */
|
||||
u32 aSnapshot[LSM_META_PAGE_SIZE / sizeof(u32)];
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
LsmPgno iFirst; /* First page of this run */
|
||||
LsmPgno iLastPg; /* Last page of this run */
|
||||
LsmPgno iRoot; /* Root page number (if any) */
|
||||
LsmPgno nSize; /* Size of this run in pages */
|
||||
|
||||
Redirect *pRedirect; /* Block redirects (or NULL) */
|
||||
};
|
||||
|
||||
/*
|
||||
** iSplitTopic/pSplitKey/nSplitKey:
|
||||
** If nRight>0, this buffer contains a copy of the largest key that has
|
||||
** already been written to the left-hand-side of the level.
|
||||
*/
|
||||
struct Level {
|
||||
Segment lhs; /* Left-hand (main) segment */
|
||||
int nRight; /* Size of apRight[] array */
|
||||
Segment *aRhs; /* Old segments being merged into this */
|
||||
int iSplitTopic; /* Split key topic (if nRight>0) */
|
||||
void *pSplitKey; /* Pointer to split-key (if nRight>0) */
|
||||
int nSplitKey; /* Number of bytes in split-key */
|
||||
|
||||
u16 iAge; /* Number of times data has been written */
|
||||
u16 flags; /* Mask of LEVEL_XXX bits */
|
||||
Merge *pMerge; /* Merge operation currently underway */
|
||||
Level *pNext; /* Next level in tree */
|
||||
};
|
||||
|
||||
/*
|
||||
** The Level.flags field is set to a combination of the following bits.
|
||||
**
|
||||
** LEVEL_FREELIST_ONLY:
|
||||
** Set if the level consists entirely of free-list entries.
|
||||
**
|
||||
** LEVEL_INCOMPLETE:
|
||||
** This is set while a new toplevel level is being constructed. It is
|
||||
** never set for any level other than a new toplevel.
|
||||
*/
|
||||
#define LEVEL_FREELIST_ONLY 0x0001
|
||||
#define LEVEL_INCOMPLETE 0x0002
|
||||
|
||||
|
||||
/*
|
||||
** A structure describing an ongoing merge. There is an instance of this
|
||||
** structure for every Level currently undergoing a merge in the worker
|
||||
** snapshot.
|
||||
**
|
||||
** It is assumed that code that uses an instance of this structure has
|
||||
** access to the associated Level struct.
|
||||
**
|
||||
** iOutputOff:
|
||||
** The byte offset to write to next within the last page of the
|
||||
** output segment.
|
||||
*/
|
||||
struct MergeInput {
|
||||
LsmPgno iPg; /* Page on which next input is stored */
|
||||
int iCell; /* Cell containing next input to merge */
|
||||
};
|
||||
struct Merge {
|
||||
int nInput; /* Number of input runs being merged */
|
||||
MergeInput *aInput; /* Array nInput entries in size */
|
||||
MergeInput splitkey; /* Location in file of current splitkey */
|
||||
int nSkip; /* Number of separators entries to skip */
|
||||
int iOutputOff; /* Write offset on output page */
|
||||
LsmPgno iCurrentPtr; /* Current pointer value */
|
||||
};
|
||||
|
||||
/*
|
||||
** The first argument to this macro is a pointer to a Segment structure.
|
||||
** Returns true if the structure instance indicates that the separators
|
||||
** array is valid.
|
||||
*/
|
||||
#define segmentHasSeparators(pSegment) ((pSegment)->sep.iFirst>0)
|
||||
|
||||
/*
|
||||
** The values that accompany the lock held by a database reader.
|
||||
*/
|
||||
struct ShmReader {
|
||||
u32 iTreeId;
|
||||
i64 iLsmId;
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure is stored in the first shared-memory
|
||||
** page. The shared-memory header.
|
||||
**
|
||||
** bWriter:
|
||||
** Immediately after opening a write transaction taking the WRITER lock,
|
||||
** each writer client sets this flag. It is cleared right before the
|
||||
** WRITER lock is relinquished. If a subsequent writer finds that this
|
||||
** flag is already set when a write transaction is opened, this indicates
|
||||
** that a previous writer failed mid-transaction.
|
||||
**
|
||||
** iMetaPage:
|
||||
** If the database file does not contain a valid, synced, checkpoint, this
|
||||
** value is set to 0. Otherwise, it is set to the meta-page number that
|
||||
** contains the most recently written checkpoint (either 1 or 2).
|
||||
**
|
||||
** hdr1, hdr2:
|
||||
** The two copies of the in-memory tree header. Two copies are required
|
||||
** in case a writer fails while updating one of them.
|
||||
*/
|
||||
struct ShmHeader {
|
||||
u32 aSnap1[LSM_META_PAGE_SIZE / 4];
|
||||
u32 aSnap2[LSM_META_PAGE_SIZE / 4];
|
||||
u32 bWriter;
|
||||
u32 iMetaPage;
|
||||
TreeHeader hdr1;
|
||||
TreeHeader hdr2;
|
||||
ShmReader aReader[LSM_LOCK_NREADER];
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure is stored at the start of each shared-memory
|
||||
** chunk except the first (which is the header chunk - see above).
|
||||
*/
|
||||
struct ShmChunk {
|
||||
u32 iShmid;
|
||||
u32 iNext;
|
||||
};
|
||||
|
||||
/*
|
||||
** Maximum number of shared-memory chunks allowed in the *-shm file. Since
|
||||
** each shared-memory chunk is 32KB in size, this is a theoretical limit only.
|
||||
*/
|
||||
#define LSM_MAX_SHMCHUNKS (1<<30)
|
||||
|
||||
/* Return true if shm-sequence "a" is larger than or equal to "b" */
|
||||
#define shm_sequence_ge(a, b) (((u32)a-(u32)b) < LSM_MAX_SHMCHUNKS)
|
||||
|
||||
#define LSM_APPLIST_SZ 4
|
||||
|
||||
/*
|
||||
** An instance of the following structure stores the in-memory part of
|
||||
** the current free block list. This structure is to the free block list
|
||||
** as the in-memory tree is to the users database content. The contents
|
||||
** of the free block list is found by merging the in-memory components
|
||||
** with those stored in the LSM, just as the contents of the database is
|
||||
** found by merging the in-memory tree with the user data entries in the
|
||||
** LSM.
|
||||
**
|
||||
** Each FreelistEntry structure in the array represents either an insert
|
||||
** or delete operation on the free-list. For deletes, the FreelistEntry.iId
|
||||
** field is set to -1. For inserts, it is set to zero or greater.
|
||||
**
|
||||
** The array of FreelistEntry structures is always sorted in order of
|
||||
** block number (ascending).
|
||||
**
|
||||
** When the in-memory free block list is written into the LSM, each insert
|
||||
** operation is written separately. The entry key is the bitwise inverse
|
||||
** of the block number as a 32-bit big-endian integer. This is done so that
|
||||
** the entries in the LSM are sorted in descending order of block id.
|
||||
** The associated value is the snapshot id, formated as a varint.
|
||||
*/
|
||||
struct Freelist {
|
||||
FreelistEntry *aEntry; /* Free list entries */
|
||||
int nEntry; /* Number of valid slots in aEntry[] */
|
||||
int nAlloc; /* Allocated size of aEntry[] */
|
||||
};
|
||||
struct FreelistEntry {
|
||||
u32 iBlk; /* Block number */
|
||||
i64 iId; /* Largest snapshot id to use this block */
|
||||
};
|
||||
|
||||
/*
|
||||
** A snapshot of a database. A snapshot contains all the information required
|
||||
** to read or write a database file on disk. See the description of struct
|
||||
** Database below for further details.
|
||||
*/
|
||||
struct Snapshot {
|
||||
Database *pDatabase; /* Database this snapshot belongs to */
|
||||
u32 iCmpId; /* Id of compression scheme */
|
||||
Level *pLevel; /* Pointer to level 0 of snapshot (or NULL) */
|
||||
i64 iId; /* Snapshot id */
|
||||
i64 iLogOff; /* Log file offset */
|
||||
Redirect redirect; /* Block redirection array */
|
||||
|
||||
/* Used by worker snapshots only */
|
||||
int nBlock; /* Number of blocks in database file */
|
||||
LsmPgno aiAppend[LSM_APPLIST_SZ]; /* Append point list */
|
||||
Freelist freelist; /* Free block list */
|
||||
u32 nWrite; /* Total number of pages written to disk */
|
||||
};
|
||||
#define LSM_INITIAL_SNAPSHOT_ID 11
|
||||
|
||||
/*
|
||||
** Functions from file "lsm_ckpt.c".
|
||||
*/
|
||||
int lsmCheckpointWrite(lsm_db *, u32 *);
|
||||
int lsmCheckpointLevels(lsm_db *, int, void **, int *);
|
||||
int lsmCheckpointLoadLevels(lsm_db *pDb, void *pVal, int nVal);
|
||||
|
||||
int lsmCheckpointRecover(lsm_db *);
|
||||
int lsmCheckpointDeserialize(lsm_db *, int, u32 *, Snapshot **);
|
||||
|
||||
int lsmCheckpointLoadWorker(lsm_db *pDb);
|
||||
int lsmCheckpointStore(lsm_db *pDb, int);
|
||||
|
||||
int lsmCheckpointLoad(lsm_db *pDb, int *);
|
||||
int lsmCheckpointLoadOk(lsm_db *pDb, int);
|
||||
int lsmCheckpointClientCacheOk(lsm_db *);
|
||||
|
||||
u32 lsmCheckpointNBlock(u32 *);
|
||||
i64 lsmCheckpointId(u32 *, int);
|
||||
u32 lsmCheckpointNWrite(u32 *, int);
|
||||
i64 lsmCheckpointLogOffset(u32 *);
|
||||
int lsmCheckpointPgsz(u32 *);
|
||||
int lsmCheckpointBlksz(u32 *);
|
||||
void lsmCheckpointLogoffset(u32 *aCkpt, DbLog *pLog);
|
||||
void lsmCheckpointZeroLogoffset(lsm_db *);
|
||||
|
||||
int lsmCheckpointSaveWorker(lsm_db *pDb, int);
|
||||
int lsmDatabaseFull(lsm_db *pDb);
|
||||
int lsmCheckpointSynced(lsm_db *pDb, i64 *piId, i64 *piLog, u32 *pnWrite);
|
||||
|
||||
int lsmCheckpointSize(lsm_db *db, int *pnByte);
|
||||
|
||||
int lsmInfoCompressionId(lsm_db *db, u32 *piCmpId);
|
||||
|
||||
/*
|
||||
** Functions from file "lsm_tree.c".
|
||||
*/
|
||||
int lsmTreeNew(lsm_env *, int (*)(void *, int, void *, int), Tree **ppTree);
|
||||
void lsmTreeRelease(lsm_env *, Tree *);
|
||||
int lsmTreeInit(lsm_db *);
|
||||
int lsmTreeRepair(lsm_db *);
|
||||
|
||||
void lsmTreeMakeOld(lsm_db *pDb);
|
||||
void lsmTreeDiscardOld(lsm_db *pDb);
|
||||
int lsmTreeHasOld(lsm_db *pDb);
|
||||
|
||||
int lsmTreeSize(lsm_db *);
|
||||
int lsmTreeEndTransaction(lsm_db *pDb, int bCommit);
|
||||
int lsmTreeLoadHeader(lsm_db *pDb, int *);
|
||||
int lsmTreeLoadHeaderOk(lsm_db *, int);
|
||||
|
||||
int lsmTreeInsert(lsm_db *pDb, void *pKey, int nKey, void *pVal, int nVal);
|
||||
int lsmTreeDelete(lsm_db *db, void *pKey1, int nKey1, void *pKey2, int nKey2);
|
||||
void lsmTreeRollback(lsm_db *pDb, TreeMark *pMark);
|
||||
void lsmTreeMark(lsm_db *pDb, TreeMark *pMark);
|
||||
|
||||
int lsmTreeCursorNew(lsm_db *pDb, int, TreeCursor **);
|
||||
void lsmTreeCursorDestroy(TreeCursor *);
|
||||
|
||||
int lsmTreeCursorSeek(TreeCursor *pCsr, void *pKey, int nKey, int *pRes);
|
||||
int lsmTreeCursorNext(TreeCursor *pCsr);
|
||||
int lsmTreeCursorPrev(TreeCursor *pCsr);
|
||||
int lsmTreeCursorEnd(TreeCursor *pCsr, int bLast);
|
||||
void lsmTreeCursorReset(TreeCursor *pCsr);
|
||||
int lsmTreeCursorKey(TreeCursor *pCsr, int *pFlags, void **ppKey, int *pnKey);
|
||||
int lsmTreeCursorFlags(TreeCursor *pCsr);
|
||||
int lsmTreeCursorValue(TreeCursor *pCsr, void **ppVal, int *pnVal);
|
||||
int lsmTreeCursorValid(TreeCursor *pCsr);
|
||||
int lsmTreeCursorSave(TreeCursor *pCsr);
|
||||
|
||||
void lsmFlagsToString(int flags, char *zFlags);
|
||||
|
||||
/*
|
||||
** Functions from file "mem.c".
|
||||
*/
|
||||
void *lsmMalloc(lsm_env*, size_t);
|
||||
void lsmFree(lsm_env*, void *);
|
||||
void *lsmRealloc(lsm_env*, void *, size_t);
|
||||
void *lsmReallocOrFree(lsm_env*, void *, size_t);
|
||||
void *lsmReallocOrFreeRc(lsm_env *, void *, size_t, int *);
|
||||
|
||||
void *lsmMallocZeroRc(lsm_env*, size_t, int *);
|
||||
void *lsmMallocRc(lsm_env*, size_t, int *);
|
||||
|
||||
void *lsmMallocZero(lsm_env *pEnv, size_t);
|
||||
char *lsmMallocStrdup(lsm_env *pEnv, const char *);
|
||||
|
||||
/*
|
||||
** Functions from file "lsm_mutex.c".
|
||||
*/
|
||||
int lsmMutexStatic(lsm_env*, int, lsm_mutex **);
|
||||
int lsmMutexNew(lsm_env*, lsm_mutex **);
|
||||
void lsmMutexDel(lsm_env*, lsm_mutex *);
|
||||
void lsmMutexEnter(lsm_env*, lsm_mutex *);
|
||||
int lsmMutexTry(lsm_env*, lsm_mutex *);
|
||||
void lsmMutexLeave(lsm_env*, lsm_mutex *);
|
||||
|
||||
#ifndef NDEBUG
|
||||
int lsmMutexHeld(lsm_env *, lsm_mutex *);
|
||||
int lsmMutexNotHeld(lsm_env *, lsm_mutex *);
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
** Start of functions from "lsm_file.c".
|
||||
*/
|
||||
int lsmFsOpen(lsm_db *, const char *, int);
|
||||
int lsmFsOpenLog(lsm_db *, int *);
|
||||
void lsmFsCloseLog(lsm_db *);
|
||||
void lsmFsClose(FileSystem *);
|
||||
|
||||
int lsmFsUnmap(FileSystem *);
|
||||
|
||||
int lsmFsConfigure(lsm_db *db);
|
||||
|
||||
int lsmFsBlockSize(FileSystem *);
|
||||
void lsmFsSetBlockSize(FileSystem *, int);
|
||||
int lsmFsMoveBlock(FileSystem *pFS, Segment *pSeg, int iTo, int iFrom);
|
||||
|
||||
int lsmFsPageSize(FileSystem *);
|
||||
void lsmFsSetPageSize(FileSystem *, int);
|
||||
|
||||
int lsmFsFileid(lsm_db *pDb, void **ppId, int *pnId);
|
||||
|
||||
/* Creating, populating, gobbling and deleting sorted runs. */
|
||||
void lsmFsGobble(lsm_db *, Segment *, LsmPgno *, int);
|
||||
int lsmFsSortedDelete(FileSystem *, Snapshot *, int, Segment *);
|
||||
int lsmFsSortedFinish(FileSystem *, Segment *);
|
||||
int lsmFsSortedAppend(FileSystem *, Snapshot *, Level *, int, Page **);
|
||||
int lsmFsSortedPadding(FileSystem *, Snapshot *, Segment *);
|
||||
|
||||
/* Functions to retrieve the lsm_env pointer from a FileSystem or Page object */
|
||||
lsm_env *lsmFsEnv(FileSystem *);
|
||||
lsm_env *lsmPageEnv(Page *);
|
||||
FileSystem *lsmPageFS(Page *);
|
||||
|
||||
int lsmFsSectorSize(FileSystem *);
|
||||
|
||||
void lsmSortedSplitkey(lsm_db *, Level *, int *);
|
||||
|
||||
/* Reading sorted run content. */
|
||||
int lsmFsDbPageLast(FileSystem *pFS, Segment *pSeg, Page **ppPg);
|
||||
int lsmFsDbPageGet(FileSystem *, Segment *, LsmPgno, Page **);
|
||||
int lsmFsDbPageNext(Segment *, Page *, int eDir, Page **);
|
||||
|
||||
u8 *lsmFsPageData(Page *, int *);
|
||||
int lsmFsPageRelease(Page *);
|
||||
int lsmFsPagePersist(Page *);
|
||||
void lsmFsPageRef(Page *);
|
||||
LsmPgno lsmFsPageNumber(Page *);
|
||||
|
||||
int lsmFsNRead(FileSystem *);
|
||||
int lsmFsNWrite(FileSystem *);
|
||||
|
||||
int lsmFsMetaPageGet(FileSystem *, int, int, MetaPage **);
|
||||
int lsmFsMetaPageRelease(MetaPage *);
|
||||
u8 *lsmFsMetaPageData(MetaPage *, int *);
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
int lsmFsDbPageIsLast(Segment *pSeg, Page *pPg);
|
||||
int lsmFsIntegrityCheck(lsm_db *);
|
||||
#endif
|
||||
|
||||
LsmPgno lsmFsRedirectPage(FileSystem *, Redirect *, LsmPgno);
|
||||
|
||||
int lsmFsPageWritable(Page *);
|
||||
|
||||
/* Functions to read, write and sync the log file. */
|
||||
int lsmFsWriteLog(FileSystem *pFS, i64 iOff, LsmString *pStr);
|
||||
int lsmFsSyncLog(FileSystem *pFS);
|
||||
int lsmFsReadLog(FileSystem *pFS, i64 iOff, int nRead, LsmString *pStr);
|
||||
int lsmFsTruncateLog(FileSystem *pFS, i64 nByte);
|
||||
int lsmFsTruncateDb(FileSystem *pFS, i64 nByte);
|
||||
int lsmFsCloseAndDeleteLog(FileSystem *pFS);
|
||||
|
||||
LsmFile *lsmFsDeferClose(FileSystem *pFS);
|
||||
|
||||
/* And to sync the db file */
|
||||
int lsmFsSyncDb(FileSystem *, int);
|
||||
|
||||
void lsmFsFlushWaiting(FileSystem *, int *);
|
||||
|
||||
/* Used by lsm_info(ARRAY_STRUCTURE) and lsm_config(MMAP) */
|
||||
int lsmInfoArrayStructure(lsm_db *pDb, int bBlock, LsmPgno iFirst, char **pz);
|
||||
int lsmInfoArrayPages(lsm_db *pDb, LsmPgno iFirst, char **pzOut);
|
||||
int lsmConfigMmap(lsm_db *pDb, int *piParam);
|
||||
|
||||
int lsmEnvOpen(lsm_env *, const char *, int, lsm_file **);
|
||||
int lsmEnvClose(lsm_env *pEnv, lsm_file *pFile);
|
||||
int lsmEnvLock(lsm_env *pEnv, lsm_file *pFile, int iLock, int eLock);
|
||||
int lsmEnvTestLock(lsm_env *pEnv, lsm_file *pFile, int iLock, int nLock, int);
|
||||
|
||||
int lsmEnvShmMap(lsm_env *, lsm_file *, int, int, void **);
|
||||
void lsmEnvShmBarrier(lsm_env *);
|
||||
void lsmEnvShmUnmap(lsm_env *, lsm_file *, int);
|
||||
|
||||
void lsmEnvSleep(lsm_env *, int);
|
||||
|
||||
int lsmFsReadSyncedId(lsm_db *db, int, i64 *piVal);
|
||||
|
||||
int lsmFsSegmentContainsPg(FileSystem *pFS, Segment *, LsmPgno, int *);
|
||||
|
||||
void lsmFsPurgeCache(FileSystem *);
|
||||
|
||||
/*
|
||||
** End of functions from "lsm_file.c".
|
||||
**************************************************************************/
|
||||
|
||||
/*
|
||||
** Functions from file "lsm_sorted.c".
|
||||
*/
|
||||
int lsmInfoPageDump(lsm_db *, LsmPgno, int, char **);
|
||||
void lsmSortedCleanup(lsm_db *);
|
||||
int lsmSortedAutoWork(lsm_db *, int nUnit);
|
||||
|
||||
int lsmSortedWalkFreelist(lsm_db *, int, int (*)(void *, int, i64), void *);
|
||||
|
||||
int lsmSaveWorker(lsm_db *, int);
|
||||
|
||||
int lsmFlushTreeToDisk(lsm_db *pDb);
|
||||
|
||||
void lsmSortedRemap(lsm_db *pDb);
|
||||
|
||||
void lsmSortedFreeLevel(lsm_env *pEnv, Level *);
|
||||
|
||||
int lsmSortedAdvanceAll(lsm_db *pDb);
|
||||
|
||||
int lsmSortedLoadMerge(lsm_db *, Level *, u32 *, int *);
|
||||
int lsmSortedLoadFreelist(lsm_db *pDb, void **, int *);
|
||||
|
||||
void *lsmSortedSplitKey(Level *pLevel, int *pnByte);
|
||||
|
||||
void lsmSortedSaveTreeCursors(lsm_db *);
|
||||
|
||||
int lsmMCursorNew(lsm_db *, MultiCursor **);
|
||||
void lsmMCursorClose(MultiCursor *, int);
|
||||
int lsmMCursorSeek(MultiCursor *, int, void *, int , int);
|
||||
int lsmMCursorFirst(MultiCursor *);
|
||||
int lsmMCursorPrev(MultiCursor *);
|
||||
int lsmMCursorLast(MultiCursor *);
|
||||
int lsmMCursorValid(MultiCursor *);
|
||||
int lsmMCursorNext(MultiCursor *);
|
||||
int lsmMCursorKey(MultiCursor *, void **, int *);
|
||||
int lsmMCursorValue(MultiCursor *, void **, int *);
|
||||
int lsmMCursorType(MultiCursor *, int *);
|
||||
lsm_db *lsmMCursorDb(MultiCursor *);
|
||||
void lsmMCursorFreeCache(lsm_db *);
|
||||
|
||||
int lsmSaveCursors(lsm_db *pDb);
|
||||
int lsmRestoreCursors(lsm_db *pDb);
|
||||
|
||||
void lsmSortedDumpStructure(lsm_db *pDb, Snapshot *, int, int, const char *);
|
||||
void lsmFsDumpBlocklists(lsm_db *);
|
||||
|
||||
void lsmSortedExpandBtreePage(Page *pPg, int nOrig);
|
||||
|
||||
void lsmPutU32(u8 *, u32);
|
||||
u32 lsmGetU32(u8 *);
|
||||
u64 lsmGetU64(u8 *);
|
||||
|
||||
/*
|
||||
** Functions from "lsm_varint.c".
|
||||
*/
|
||||
int lsmVarintPut32(u8 *, int);
|
||||
int lsmVarintGet32(u8 *, int *);
|
||||
int lsmVarintPut64(u8 *aData, i64 iVal);
|
||||
int lsmVarintGet64(const u8 *aData, i64 *piVal);
|
||||
|
||||
int lsmVarintLen64(i64);
|
||||
|
||||
int lsmVarintLen32(int);
|
||||
int lsmVarintSize(u8 c);
|
||||
|
||||
/*
|
||||
** Functions from file "main.c".
|
||||
*/
|
||||
void lsmLogMessage(lsm_db *, int, const char *, ...);
|
||||
int lsmInfoFreelist(lsm_db *pDb, char **pzOut);
|
||||
|
||||
/*
|
||||
** Functions from file "lsm_log.c".
|
||||
*/
|
||||
int lsmLogBegin(lsm_db *pDb);
|
||||
int lsmLogWrite(lsm_db *, int, void *, int, void *, int);
|
||||
int lsmLogCommit(lsm_db *);
|
||||
void lsmLogEnd(lsm_db *pDb, int bCommit);
|
||||
void lsmLogTell(lsm_db *, LogMark *);
|
||||
void lsmLogSeek(lsm_db *, LogMark *);
|
||||
void lsmLogClose(lsm_db *);
|
||||
|
||||
int lsmLogRecover(lsm_db *);
|
||||
int lsmInfoLogStructure(lsm_db *pDb, char **pzVal);
|
||||
|
||||
/* Valid values for the second argument to lsmLogWrite(). */
|
||||
#define LSM_WRITE 0x06
|
||||
#define LSM_DELETE 0x08
|
||||
#define LSM_DRANGE 0x0A
|
||||
|
||||
/**************************************************************************
|
||||
** Functions from file "lsm_shared.c".
|
||||
*/
|
||||
|
||||
int lsmDbDatabaseConnect(lsm_db*, const char *);
|
||||
void lsmDbDatabaseRelease(lsm_db *);
|
||||
|
||||
int lsmBeginReadTrans(lsm_db *);
|
||||
int lsmBeginWriteTrans(lsm_db *);
|
||||
int lsmBeginFlush(lsm_db *);
|
||||
|
||||
int lsmDetectRoTrans(lsm_db *db, int *);
|
||||
int lsmBeginRoTrans(lsm_db *db);
|
||||
|
||||
int lsmBeginWork(lsm_db *);
|
||||
void lsmFinishWork(lsm_db *, int, int *);
|
||||
|
||||
int lsmFinishRecovery(lsm_db *);
|
||||
void lsmFinishReadTrans(lsm_db *);
|
||||
int lsmFinishWriteTrans(lsm_db *, int);
|
||||
int lsmFinishFlush(lsm_db *, int);
|
||||
|
||||
int lsmSnapshotSetFreelist(lsm_db *, int *, int);
|
||||
|
||||
Snapshot *lsmDbSnapshotClient(lsm_db *);
|
||||
Snapshot *lsmDbSnapshotWorker(lsm_db *);
|
||||
|
||||
void lsmSnapshotSetCkptid(Snapshot *, i64);
|
||||
|
||||
Level *lsmDbSnapshotLevel(Snapshot *);
|
||||
void lsmDbSnapshotSetLevel(Snapshot *, Level *);
|
||||
|
||||
void lsmDbRecoveryComplete(lsm_db *, int);
|
||||
|
||||
int lsmBlockAllocate(lsm_db *, int, int *);
|
||||
int lsmBlockFree(lsm_db *, int);
|
||||
int lsmBlockRefree(lsm_db *, int);
|
||||
|
||||
void lsmFreelistDeltaBegin(lsm_db *);
|
||||
void lsmFreelistDeltaEnd(lsm_db *);
|
||||
int lsmFreelistDelta(lsm_db *pDb);
|
||||
|
||||
DbLog *lsmDatabaseLog(lsm_db *pDb);
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
int lsmHoldingClientMutex(lsm_db *pDb);
|
||||
int lsmShmAssertLock(lsm_db *db, int iLock, int eOp);
|
||||
int lsmShmAssertWorker(lsm_db *db);
|
||||
#endif
|
||||
|
||||
void lsmFreeSnapshot(lsm_env *, Snapshot *);
|
||||
|
||||
|
||||
/* Candidate values for the 3rd argument to lsmShmLock() */
|
||||
#define LSM_LOCK_UNLOCK 0
|
||||
#define LSM_LOCK_SHARED 1
|
||||
#define LSM_LOCK_EXCL 2
|
||||
|
||||
int lsmShmCacheChunks(lsm_db *db, int nChunk);
|
||||
int lsmShmLock(lsm_db *db, int iLock, int eOp, int bBlock);
|
||||
int lsmShmTestLock(lsm_db *db, int iLock, int nLock, int eOp);
|
||||
void lsmShmBarrier(lsm_db *db);
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
void lsmShmHasLock(lsm_db *db, int iLock, int eOp);
|
||||
#else
|
||||
# define lsmShmHasLock(x,y,z)
|
||||
#endif
|
||||
|
||||
int lsmReadlock(lsm_db *, i64 iLsm, u32 iShmMin, u32 iShmMax);
|
||||
|
||||
int lsmLsmInUse(lsm_db *db, i64 iLsmId, int *pbInUse);
|
||||
int lsmTreeInUse(lsm_db *db, u32 iLsmId, int *pbInUse);
|
||||
int lsmFreelistAppend(lsm_env *pEnv, Freelist *p, int iBlk, i64 iId);
|
||||
|
||||
int lsmDbMultiProc(lsm_db *);
|
||||
void lsmDbDeferredClose(lsm_db *, lsm_file *, LsmFile *);
|
||||
LsmFile *lsmDbRecycleFd(lsm_db *);
|
||||
|
||||
int lsmWalkFreelist(lsm_db *, int, int (*)(void *, int, i64), void *);
|
||||
|
||||
int lsmCheckCompressionId(lsm_db *, u32);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
** functions in lsm_str.c
|
||||
*/
|
||||
void lsmStringInit(LsmString*, lsm_env *pEnv);
|
||||
int lsmStringExtend(LsmString*, int);
|
||||
int lsmStringAppend(LsmString*, const char *, int);
|
||||
void lsmStringVAppendf(LsmString*, const char *zFormat, va_list, va_list);
|
||||
void lsmStringAppendf(LsmString*, const char *zFormat, ...);
|
||||
void lsmStringClear(LsmString*);
|
||||
char *lsmMallocPrintf(lsm_env*, const char*, ...);
|
||||
int lsmStringBinAppend(LsmString *pStr, const u8 *a, int n);
|
||||
|
||||
int lsmStrlen(const char *zName);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Round up a number to the next larger multiple of 8. This is used
|
||||
** to force 8-byte alignment on 64-bit architectures.
|
||||
*/
|
||||
#define ROUND8(x) (((x)+7)&~7)
|
||||
|
||||
#define LSM_MIN(x,y) ((x)>(y) ? (y) : (x))
|
||||
#define LSM_MAX(x,y) ((x)>(y) ? (x) : (y))
|
||||
|
||||
#endif
|
||||
-1239
File diff suppressed because it is too large
Load Diff
-3311
File diff suppressed because it is too large
Load Diff
-1156
File diff suppressed because it is too large
Load Diff
-1008
File diff suppressed because it is too large
Load Diff
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
** 2011-08-18
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** Helper routines for memory allocation.
|
||||
*/
|
||||
#include "lsmInt.h"
|
||||
|
||||
/*
|
||||
** The following routines are called internally by LSM sub-routines. In
|
||||
** this case a valid environment pointer must be supplied.
|
||||
*/
|
||||
void *lsmMalloc(lsm_env *pEnv, size_t N){
|
||||
assert( pEnv );
|
||||
return pEnv->xMalloc(pEnv, N);
|
||||
}
|
||||
void lsmFree(lsm_env *pEnv, void *p){
|
||||
assert( pEnv );
|
||||
pEnv->xFree(pEnv, p);
|
||||
}
|
||||
void *lsmRealloc(lsm_env *pEnv, void *p, size_t N){
|
||||
assert( pEnv );
|
||||
return pEnv->xRealloc(pEnv, p, N);
|
||||
}
|
||||
|
||||
/*
|
||||
** Core memory allocation routines for LSM.
|
||||
*/
|
||||
void *lsm_malloc(lsm_env *pEnv, size_t N){
|
||||
return lsmMalloc(pEnv ? pEnv : lsm_default_env(), N);
|
||||
}
|
||||
void lsm_free(lsm_env *pEnv, void *p){
|
||||
lsmFree(pEnv ? pEnv : lsm_default_env(), p);
|
||||
}
|
||||
void *lsm_realloc(lsm_env *pEnv, void *p, size_t N){
|
||||
return lsmRealloc(pEnv ? pEnv : lsm_default_env(), p, N);
|
||||
}
|
||||
|
||||
void *lsmMallocZero(lsm_env *pEnv, size_t N){
|
||||
void *pRet;
|
||||
assert( pEnv );
|
||||
pRet = lsmMalloc(pEnv, N);
|
||||
if( pRet ) memset(pRet, 0, N);
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void *lsmMallocRc(lsm_env *pEnv, size_t N, int *pRc){
|
||||
void *pRet = 0;
|
||||
if( *pRc==LSM_OK ){
|
||||
pRet = lsmMalloc(pEnv, N);
|
||||
if( pRet==0 ){
|
||||
*pRc = LSM_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void *lsmMallocZeroRc(lsm_env *pEnv, size_t N, int *pRc){
|
||||
void *pRet = 0;
|
||||
if( *pRc==LSM_OK ){
|
||||
pRet = lsmMallocZero(pEnv, N);
|
||||
if( pRet==0 ){
|
||||
*pRc = LSM_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void *lsmReallocOrFree(lsm_env *pEnv, void *p, size_t N){
|
||||
void *pNew;
|
||||
pNew = lsm_realloc(pEnv, p, N);
|
||||
if( !pNew ) lsm_free(pEnv, p);
|
||||
return pNew;
|
||||
}
|
||||
|
||||
void *lsmReallocOrFreeRc(lsm_env *pEnv, void *p, size_t N, int *pRc){
|
||||
void *pRet = 0;
|
||||
if( *pRc ){
|
||||
lsmFree(pEnv, p);
|
||||
}else{
|
||||
pRet = lsmReallocOrFree(pEnv, p, N);
|
||||
if( !pRet ) *pRc = LSM_NOMEM_BKPT;
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
char *lsmMallocStrdup(lsm_env *pEnv, const char *zIn){
|
||||
int nByte;
|
||||
char *zRet;
|
||||
nByte = strlen(zIn);
|
||||
zRet = lsmMalloc(pEnv, nByte+1);
|
||||
if( zRet ){
|
||||
memcpy(zRet, zIn, nByte+1);
|
||||
}
|
||||
return zRet;
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
** 2012-01-30
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** Mutex functions for LSM.
|
||||
*/
|
||||
#include "lsmInt.h"
|
||||
|
||||
/*
|
||||
** Allocate a new mutex.
|
||||
*/
|
||||
int lsmMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
|
||||
return pEnv->xMutexNew(pEnv, ppNew);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a handle for one of the static mutexes.
|
||||
*/
|
||||
int lsmMutexStatic(lsm_env *pEnv, int iMutex, lsm_mutex **ppStatic){
|
||||
return pEnv->xMutexStatic(pEnv, iMutex, ppStatic);
|
||||
}
|
||||
|
||||
/*
|
||||
** Free a mutex allocated by lsmMutexNew().
|
||||
*/
|
||||
void lsmMutexDel(lsm_env *pEnv, lsm_mutex *pMutex){
|
||||
if( pMutex ) pEnv->xMutexDel(pMutex);
|
||||
}
|
||||
|
||||
/*
|
||||
** Enter a mutex.
|
||||
*/
|
||||
void lsmMutexEnter(lsm_env *pEnv, lsm_mutex *pMutex){
|
||||
pEnv->xMutexEnter(pMutex);
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to enter a mutex, but do not block. If successful, return zero.
|
||||
** Otherwise, if the mutex is already held by some other thread and is not
|
||||
** entered, return non zero.
|
||||
**
|
||||
** Each successful call to this function must be matched by a call to
|
||||
** lsmMutexLeave().
|
||||
*/
|
||||
int lsmMutexTry(lsm_env *pEnv, lsm_mutex *pMutex){
|
||||
return pEnv->xMutexTry(pMutex);
|
||||
}
|
||||
|
||||
/*
|
||||
** Leave a mutex.
|
||||
*/
|
||||
void lsmMutexLeave(lsm_env *pEnv, lsm_mutex *pMutex){
|
||||
pEnv->xMutexLeave(pMutex);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** Return non-zero if the mutex passed as the second argument is held
|
||||
** by the calling thread, or zero otherwise. If the implementation is not
|
||||
** able to tell if the mutex is held by the caller, it should return
|
||||
** non-zero.
|
||||
**
|
||||
** This function is only used as part of assert() statements.
|
||||
*/
|
||||
int lsmMutexHeld(lsm_env *pEnv, lsm_mutex *pMutex){
|
||||
return pEnv->xMutexHeld ? pEnv->xMutexHeld(pMutex) : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return non-zero if the mutex passed as the second argument is not
|
||||
** held by the calling thread, or zero otherwise. If the implementation
|
||||
** is not able to tell if the mutex is held by the caller, it should
|
||||
** return non-zero.
|
||||
**
|
||||
** This function is only used as part of assert() statements.
|
||||
*/
|
||||
int lsmMutexNotHeld(lsm_env *pEnv, lsm_mutex *pMutex){
|
||||
return pEnv->xMutexNotHeld ? pEnv->xMutexNotHeld(pMutex) : 1;
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
** 2012-04-27
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** Dynamic string functions.
|
||||
*/
|
||||
#include "lsmInt.h"
|
||||
|
||||
/*
|
||||
** Turn bulk and uninitialized memory into an LsmString object
|
||||
*/
|
||||
void lsmStringInit(LsmString *pStr, lsm_env *pEnv){
|
||||
memset(pStr, 0, sizeof(pStr[0]));
|
||||
pStr->pEnv = pEnv;
|
||||
}
|
||||
|
||||
/*
|
||||
** Increase the memory allocated for holding the string. Realloc as needed.
|
||||
**
|
||||
** If a memory allocation error occurs, set pStr->n to -1 and free the existing
|
||||
** allocation. If a prior memory allocation has occurred, this routine is a
|
||||
** no-op.
|
||||
*/
|
||||
int lsmStringExtend(LsmString *pStr, int nNew){
|
||||
assert( nNew>0 );
|
||||
if( pStr->n<0 ) return LSM_NOMEM;
|
||||
if( pStr->n + nNew >= pStr->nAlloc ){
|
||||
int nAlloc = pStr->n + nNew + 100;
|
||||
char *zNew = lsmRealloc(pStr->pEnv, pStr->z, nAlloc);
|
||||
if( zNew==0 ){
|
||||
lsmFree(pStr->pEnv, pStr->z);
|
||||
nAlloc = 0;
|
||||
pStr->n = -1;
|
||||
}
|
||||
pStr->nAlloc = nAlloc;
|
||||
pStr->z = zNew;
|
||||
}
|
||||
return (pStr->z ? LSM_OK : LSM_NOMEM_BKPT);
|
||||
}
|
||||
|
||||
/*
|
||||
** Clear an LsmString object, releasing any allocated memory that it holds.
|
||||
** This also clears the error indication (if any).
|
||||
*/
|
||||
void lsmStringClear(LsmString *pStr){
|
||||
lsmFree(pStr->pEnv, pStr->z);
|
||||
lsmStringInit(pStr, pStr->pEnv);
|
||||
}
|
||||
|
||||
/*
|
||||
** Append N bytes of text to the end of an LsmString object. If
|
||||
** N is negative, append the entire string.
|
||||
**
|
||||
** If the string is in an error state, this routine is a no-op.
|
||||
*/
|
||||
int lsmStringAppend(LsmString *pStr, const char *z, int N){
|
||||
int rc;
|
||||
if( N<0 ) N = (int)strlen(z);
|
||||
rc = lsmStringExtend(pStr, N+1);
|
||||
if( pStr->nAlloc ){
|
||||
memcpy(pStr->z+pStr->n, z, N+1);
|
||||
pStr->n += N;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int lsmStringBinAppend(LsmString *pStr, const u8 *a, int n){
|
||||
int rc;
|
||||
rc = lsmStringExtend(pStr, n);
|
||||
if( pStr->nAlloc ){
|
||||
memcpy(pStr->z+pStr->n, a, n);
|
||||
pStr->n += n;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Append printf-formatted content to an LsmString.
|
||||
*/
|
||||
void lsmStringVAppendf(
|
||||
LsmString *pStr,
|
||||
const char *zFormat,
|
||||
va_list ap1,
|
||||
va_list ap2
|
||||
){
|
||||
#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__<199901L)) && \
|
||||
!defined(__APPLE__)
|
||||
extern int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
/* Compatibility crutch for C89 compilation mode. sqlite3_vsnprintf()
|
||||
does not work identically and causes test failures if used here.
|
||||
For the time being we are assuming that the target has vsnprintf(),
|
||||
but that is not guaranteed to be the case for pure C89 platforms.
|
||||
*/;
|
||||
#endif
|
||||
int nWrite;
|
||||
int nAvail;
|
||||
|
||||
nAvail = pStr->nAlloc - pStr->n;
|
||||
nWrite = vsnprintf(pStr->z + pStr->n, nAvail, zFormat, ap1);
|
||||
|
||||
if( nWrite>=nAvail ){
|
||||
lsmStringExtend(pStr, nWrite+1);
|
||||
if( pStr->nAlloc==0 ) return;
|
||||
nWrite = vsnprintf(pStr->z + pStr->n, nWrite+1, zFormat, ap2);
|
||||
}
|
||||
|
||||
pStr->n += nWrite;
|
||||
pStr->z[pStr->n] = 0;
|
||||
}
|
||||
|
||||
void lsmStringAppendf(LsmString *pStr, const char *zFormat, ...){
|
||||
va_list ap, ap2;
|
||||
va_start(ap, zFormat);
|
||||
va_start(ap2, zFormat);
|
||||
lsmStringVAppendf(pStr, zFormat, ap, ap2);
|
||||
va_end(ap);
|
||||
va_end(ap2);
|
||||
}
|
||||
|
||||
int lsmStrlen(const char *zName){
|
||||
int nRet = 0;
|
||||
while( zName[nRet] ) nRet++;
|
||||
return nRet;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write into memory obtained from lsm_malloc().
|
||||
*/
|
||||
char *lsmMallocPrintf(lsm_env *pEnv, const char *zFormat, ...){
|
||||
LsmString s;
|
||||
va_list ap, ap2;
|
||||
lsmStringInit(&s, pEnv);
|
||||
va_start(ap, zFormat);
|
||||
va_start(ap2, zFormat);
|
||||
lsmStringVAppendf(&s, zFormat, ap, ap2);
|
||||
va_end(ap);
|
||||
va_end(ap2);
|
||||
if( s.n<0 ) return 0;
|
||||
return (char *)lsmReallocOrFree(pEnv, s.z, s.n+1);
|
||||
}
|
||||
-2465
File diff suppressed because it is too large
Load Diff
@@ -1,753 +0,0 @@
|
||||
/*
|
||||
** 2011-12-03
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** Unix-specific run-time environment implementation for LSM.
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#if defined(__GNUC__) || defined(__TINYC__)
|
||||
/* workaround for ftruncate() visibility on gcc. */
|
||||
# ifndef _XOPEN_SOURCE
|
||||
# define _XOPEN_SOURCE 500
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include "lsmInt.h"
|
||||
|
||||
/* There is no fdatasync() call on Android */
|
||||
#ifdef __ANDROID__
|
||||
# define fdatasync(x) fsync(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** An open file is an instance of the following object
|
||||
*/
|
||||
typedef struct PosixFile PosixFile;
|
||||
struct PosixFile {
|
||||
lsm_env *pEnv; /* The run-time environment */
|
||||
const char *zName; /* Full path to file */
|
||||
int fd; /* The open file descriptor */
|
||||
int shmfd; /* Shared memory file-descriptor */
|
||||
void *pMap; /* Pointer to mapping of file fd */
|
||||
off_t nMap; /* Size of mapping at pMap in bytes */
|
||||
int nShm; /* Number of entries in array apShm[] */
|
||||
void **apShm; /* Array of 32K shared memory segments */
|
||||
};
|
||||
|
||||
static char *posixShmFile(PosixFile *p){
|
||||
char *zShm;
|
||||
int nName = strlen(p->zName);
|
||||
zShm = (char *)lsmMalloc(p->pEnv, nName+4+1);
|
||||
if( zShm ){
|
||||
memcpy(zShm, p->zName, nName);
|
||||
memcpy(&zShm[nName], "-shm", 5);
|
||||
}
|
||||
return zShm;
|
||||
}
|
||||
|
||||
static int lsmPosixOsOpen(
|
||||
lsm_env *pEnv,
|
||||
const char *zFile,
|
||||
int flags,
|
||||
lsm_file **ppFile
|
||||
){
|
||||
int rc = LSM_OK;
|
||||
PosixFile *p;
|
||||
|
||||
p = lsm_malloc(pEnv, sizeof(PosixFile));
|
||||
if( p==0 ){
|
||||
rc = LSM_NOMEM;
|
||||
}else{
|
||||
int bReadonly = (flags & LSM_OPEN_READONLY);
|
||||
int oflags = (bReadonly ? O_RDONLY : (O_RDWR|O_CREAT));
|
||||
memset(p, 0, sizeof(PosixFile));
|
||||
p->zName = zFile;
|
||||
p->pEnv = pEnv;
|
||||
p->fd = open(zFile, oflags, 0644);
|
||||
if( p->fd<0 ){
|
||||
lsm_free(pEnv, p);
|
||||
p = 0;
|
||||
if( errno==ENOENT ){
|
||||
rc = lsmErrorBkpt(LSM_IOERR_NOENT);
|
||||
}else{
|
||||
rc = LSM_IOERR_BKPT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*ppFile = (lsm_file *)p;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsWrite(
|
||||
lsm_file *pFile, /* File to write to */
|
||||
lsm_i64 iOff, /* Offset to write to */
|
||||
void *pData, /* Write data from this buffer */
|
||||
int nData /* Bytes of data to write */
|
||||
){
|
||||
int rc = LSM_OK;
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
off_t offset;
|
||||
|
||||
offset = lseek(p->fd, (off_t)iOff, SEEK_SET);
|
||||
if( offset!=iOff ){
|
||||
rc = LSM_IOERR_BKPT;
|
||||
}else{
|
||||
ssize_t prc = write(p->fd, pData, (size_t)nData);
|
||||
if( prc<0 ) rc = LSM_IOERR_BKPT;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsTruncate(
|
||||
lsm_file *pFile, /* File to write to */
|
||||
lsm_i64 nSize /* Size to truncate file to */
|
||||
){
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
int rc = LSM_OK; /* Return code */
|
||||
int prc; /* Posix Return Code */
|
||||
struct stat sStat; /* Result of fstat() invocation */
|
||||
|
||||
prc = fstat(p->fd, &sStat);
|
||||
if( prc==0 && sStat.st_size>nSize ){
|
||||
prc = ftruncate(p->fd, (off_t)nSize);
|
||||
}
|
||||
if( prc<0 ) rc = LSM_IOERR_BKPT;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsRead(
|
||||
lsm_file *pFile, /* File to read from */
|
||||
lsm_i64 iOff, /* Offset to read from */
|
||||
void *pData, /* Read data into this buffer */
|
||||
int nData /* Bytes of data to read */
|
||||
){
|
||||
int rc = LSM_OK;
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
off_t offset;
|
||||
|
||||
offset = lseek(p->fd, (off_t)iOff, SEEK_SET);
|
||||
if( offset!=iOff ){
|
||||
rc = LSM_IOERR_BKPT;
|
||||
}else{
|
||||
ssize_t prc = read(p->fd, pData, (size_t)nData);
|
||||
if( prc<0 ){
|
||||
rc = LSM_IOERR_BKPT;
|
||||
}else if( prc<nData ){
|
||||
memset(&((u8 *)pData)[prc], 0, nData - prc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsSync(lsm_file *pFile){
|
||||
int rc = LSM_OK;
|
||||
|
||||
#ifndef LSM_NO_SYNC
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
int prc = 0;
|
||||
|
||||
if( p->pMap ){
|
||||
prc = msync(p->pMap, p->nMap, MS_SYNC);
|
||||
}
|
||||
if( prc==0 ) prc = fdatasync(p->fd);
|
||||
if( prc<0 ) rc = LSM_IOERR_BKPT;
|
||||
#else
|
||||
(void)pFile;
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsSectorSize(lsm_file *pFile){
|
||||
return 512;
|
||||
}
|
||||
|
||||
static int lsmPosixOsRemap(
|
||||
lsm_file *pFile,
|
||||
lsm_i64 iMin,
|
||||
void **ppOut,
|
||||
lsm_i64 *pnOut
|
||||
){
|
||||
off_t iSz;
|
||||
int prc;
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
struct stat buf;
|
||||
|
||||
/* If the file is between 0 and 2MB in size, extend it in chunks of 256K.
|
||||
** Thereafter, in chunks of 1MB at a time. */
|
||||
const int aIncrSz[] = {256*1024, 1024*1024};
|
||||
int nIncrSz = aIncrSz[iMin>(2*1024*1024)];
|
||||
|
||||
if( p->pMap ){
|
||||
munmap(p->pMap, p->nMap);
|
||||
*ppOut = p->pMap = 0;
|
||||
*pnOut = p->nMap = 0;
|
||||
}
|
||||
|
||||
if( iMin>=0 ){
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
prc = fstat(p->fd, &buf);
|
||||
if( prc!=0 ) return LSM_IOERR_BKPT;
|
||||
iSz = buf.st_size;
|
||||
if( iSz<iMin ){
|
||||
iSz = ((iMin + nIncrSz-1) / nIncrSz) * nIncrSz;
|
||||
prc = ftruncate(p->fd, iSz);
|
||||
if( prc!=0 ) return LSM_IOERR_BKPT;
|
||||
}
|
||||
|
||||
p->pMap = mmap(0, iSz, PROT_READ|PROT_WRITE, MAP_SHARED, p->fd, 0);
|
||||
if( p->pMap==MAP_FAILED ){
|
||||
p->pMap = 0;
|
||||
return LSM_IOERR_BKPT;
|
||||
}
|
||||
p->nMap = iSz;
|
||||
}
|
||||
|
||||
*ppOut = p->pMap;
|
||||
*pnOut = p->nMap;
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static int lsmPosixOsFullpath(
|
||||
lsm_env *pEnv,
|
||||
const char *zName,
|
||||
char *zOut,
|
||||
int *pnOut
|
||||
){
|
||||
int nBuf = *pnOut;
|
||||
int nReq;
|
||||
|
||||
if( zName[0]!='/' ){
|
||||
char *z;
|
||||
char *zTmp;
|
||||
int nTmp = 512;
|
||||
zTmp = lsmMalloc(pEnv, nTmp);
|
||||
while( zTmp ){
|
||||
z = getcwd(zTmp, nTmp);
|
||||
if( z || errno!=ERANGE ) break;
|
||||
nTmp = nTmp*2;
|
||||
zTmp = lsmReallocOrFree(pEnv, zTmp, nTmp);
|
||||
}
|
||||
if( zTmp==0 ) return LSM_NOMEM_BKPT;
|
||||
if( z==0 ) return LSM_IOERR_BKPT;
|
||||
assert( z==zTmp );
|
||||
|
||||
nTmp = strlen(zTmp);
|
||||
nReq = nTmp + 1 + strlen(zName) + 1;
|
||||
if( nReq<=nBuf ){
|
||||
memcpy(zOut, zTmp, nTmp);
|
||||
zOut[nTmp] = '/';
|
||||
memcpy(&zOut[nTmp+1], zName, strlen(zName)+1);
|
||||
}
|
||||
lsmFree(pEnv, zTmp);
|
||||
}else{
|
||||
nReq = strlen(zName)+1;
|
||||
if( nReq<=nBuf ){
|
||||
memcpy(zOut, zName, strlen(zName)+1);
|
||||
}
|
||||
}
|
||||
|
||||
*pnOut = nReq;
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static int lsmPosixOsFileid(
|
||||
lsm_file *pFile,
|
||||
void *pBuf,
|
||||
int *pnBuf
|
||||
){
|
||||
int prc;
|
||||
int nBuf;
|
||||
int nReq;
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
struct stat buf;
|
||||
|
||||
nBuf = *pnBuf;
|
||||
nReq = (sizeof(buf.st_dev) + sizeof(buf.st_ino));
|
||||
*pnBuf = nReq;
|
||||
if( nReq>nBuf ) return LSM_OK;
|
||||
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
prc = fstat(p->fd, &buf);
|
||||
if( prc!=0 ) return LSM_IOERR_BKPT;
|
||||
|
||||
memcpy(pBuf, &buf.st_dev, sizeof(buf.st_dev));
|
||||
memcpy(&(((u8 *)pBuf)[sizeof(buf.st_dev)]), &buf.st_ino, sizeof(buf.st_ino));
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static int lsmPosixOsUnlink(lsm_env *pEnv, const char *zFile){
|
||||
int prc = unlink(zFile);
|
||||
return prc ? LSM_IOERR_BKPT : LSM_OK;
|
||||
}
|
||||
|
||||
static int lsmPosixOsLock(lsm_file *pFile, int iLock, int eType){
|
||||
int rc = LSM_OK;
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
static const short aType[3] = { F_UNLCK, F_RDLCK, F_WRLCK };
|
||||
struct flock lock;
|
||||
|
||||
assert( aType[LSM_LOCK_UNLOCK]==F_UNLCK );
|
||||
assert( aType[LSM_LOCK_SHARED]==F_RDLCK );
|
||||
assert( aType[LSM_LOCK_EXCL]==F_WRLCK );
|
||||
assert( eType>=0 && eType<array_size(aType) );
|
||||
assert( iLock>0 && iLock<=32 );
|
||||
|
||||
memset(&lock, 0, sizeof(lock));
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_len = 1;
|
||||
lock.l_type = aType[eType];
|
||||
lock.l_start = (4096-iLock);
|
||||
|
||||
if( fcntl(p->fd, F_SETLK, &lock) ){
|
||||
int e = errno;
|
||||
if( e==EACCES || e==EAGAIN ){
|
||||
rc = LSM_BUSY;
|
||||
}else{
|
||||
rc = LSM_IOERR_BKPT;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsTestLock(lsm_file *pFile, int iLock, int nLock, int eType){
|
||||
int rc = LSM_OK;
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
static const short aType[3] = { 0, F_RDLCK, F_WRLCK };
|
||||
struct flock lock;
|
||||
|
||||
assert( eType==LSM_LOCK_SHARED || eType==LSM_LOCK_EXCL );
|
||||
assert( aType[LSM_LOCK_SHARED]==F_RDLCK );
|
||||
assert( aType[LSM_LOCK_EXCL]==F_WRLCK );
|
||||
assert( eType>=0 && eType<array_size(aType) );
|
||||
assert( iLock>0 && iLock<=32 );
|
||||
|
||||
memset(&lock, 0, sizeof(lock));
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_len = nLock;
|
||||
lock.l_type = aType[eType];
|
||||
lock.l_start = (4096-iLock-nLock+1);
|
||||
|
||||
if( fcntl(p->fd, F_GETLK, &lock) ){
|
||||
rc = LSM_IOERR_BKPT;
|
||||
}else if( lock.l_type!=F_UNLCK ){
|
||||
rc = LSM_BUSY;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int lsmPosixOsShmMap(lsm_file *pFile, int iChunk, int sz, void **ppShm){
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
|
||||
*ppShm = 0;
|
||||
assert( sz==LSM_SHM_CHUNK_SIZE );
|
||||
if( iChunk>=p->nShm ){
|
||||
int i;
|
||||
void **apNew;
|
||||
int nNew = iChunk+1;
|
||||
off_t nReq = nNew * LSM_SHM_CHUNK_SIZE;
|
||||
struct stat sStat;
|
||||
|
||||
/* If the shared-memory file has not been opened, open it now. */
|
||||
if( p->shmfd<=0 ){
|
||||
char *zShm = posixShmFile(p);
|
||||
if( !zShm ) return LSM_NOMEM_BKPT;
|
||||
p->shmfd = open(zShm, O_RDWR|O_CREAT, 0644);
|
||||
lsmFree(p->pEnv, zShm);
|
||||
if( p->shmfd<0 ){
|
||||
return LSM_IOERR_BKPT;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the shared-memory file is not large enough to contain the
|
||||
** requested chunk, cause it to grow. */
|
||||
if( fstat(p->shmfd, &sStat) ){
|
||||
return LSM_IOERR_BKPT;
|
||||
}
|
||||
if( sStat.st_size<nReq ){
|
||||
if( ftruncate(p->shmfd, nReq) ){
|
||||
return LSM_IOERR_BKPT;
|
||||
}
|
||||
}
|
||||
|
||||
apNew = (void **)lsmRealloc(p->pEnv, p->apShm, sizeof(void *) * nNew);
|
||||
if( !apNew ) return LSM_NOMEM_BKPT;
|
||||
for(i=p->nShm; i<nNew; i++){
|
||||
apNew[i] = 0;
|
||||
}
|
||||
p->apShm = apNew;
|
||||
p->nShm = nNew;
|
||||
}
|
||||
|
||||
if( p->apShm[iChunk]==0 ){
|
||||
p->apShm[iChunk] = mmap(0, LSM_SHM_CHUNK_SIZE,
|
||||
PROT_READ|PROT_WRITE, MAP_SHARED, p->shmfd, iChunk*LSM_SHM_CHUNK_SIZE
|
||||
);
|
||||
if( p->apShm[iChunk]==MAP_FAILED ){
|
||||
p->apShm[iChunk] = 0;
|
||||
return LSM_IOERR_BKPT;
|
||||
}
|
||||
}
|
||||
|
||||
*ppShm = p->apShm[iChunk];
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static void lsmPosixOsShmBarrier(void){
|
||||
}
|
||||
|
||||
static int lsmPosixOsShmUnmap(lsm_file *pFile, int bDelete){
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
if( p->shmfd>0 ){
|
||||
int i;
|
||||
for(i=0; i<p->nShm; i++){
|
||||
if( p->apShm[i] ){
|
||||
munmap(p->apShm[i], LSM_SHM_CHUNK_SIZE);
|
||||
p->apShm[i] = 0;
|
||||
}
|
||||
}
|
||||
close(p->shmfd);
|
||||
p->shmfd = 0;
|
||||
if( bDelete ){
|
||||
char *zShm = posixShmFile(p);
|
||||
if( zShm ) unlink(zShm);
|
||||
lsmFree(p->pEnv, zShm);
|
||||
}
|
||||
}
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
|
||||
static int lsmPosixOsClose(lsm_file *pFile){
|
||||
PosixFile *p = (PosixFile *)pFile;
|
||||
lsmPosixOsShmUnmap(pFile, 0);
|
||||
if( p->pMap ) munmap(p->pMap, p->nMap);
|
||||
close(p->fd);
|
||||
lsm_free(p->pEnv, p->apShm);
|
||||
lsm_free(p->pEnv, p);
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static int lsmPosixOsSleep(lsm_env *pEnv, int us){
|
||||
#if 0
|
||||
/* Apparently on Android usleep() returns void */
|
||||
if( usleep(us) ) return LSM_IOERR;
|
||||
#endif
|
||||
usleep(us);
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** Memory allocation routines.
|
||||
*/
|
||||
#define BLOCK_HDR_SIZE ROUND8( sizeof(size_t) )
|
||||
|
||||
static void *lsmPosixOsMalloc(lsm_env *pEnv, size_t N){
|
||||
unsigned char * m;
|
||||
N += BLOCK_HDR_SIZE;
|
||||
m = (unsigned char *)malloc(N);
|
||||
*((size_t*)m) = N;
|
||||
return m + BLOCK_HDR_SIZE;
|
||||
}
|
||||
|
||||
static void lsmPosixOsFree(lsm_env *pEnv, void *p){
|
||||
if(p){
|
||||
free( ((unsigned char *)p) - BLOCK_HDR_SIZE );
|
||||
}
|
||||
}
|
||||
|
||||
static void *lsmPosixOsRealloc(lsm_env *pEnv, void *p, size_t N){
|
||||
unsigned char * m = (unsigned char *)p;
|
||||
if(1>N){
|
||||
lsmPosixOsFree( pEnv, p );
|
||||
return NULL;
|
||||
}else if(NULL==p){
|
||||
return lsmPosixOsMalloc(pEnv, N);
|
||||
}else{
|
||||
void * re = NULL;
|
||||
m -= BLOCK_HDR_SIZE;
|
||||
#if 0 /* arguable: don't shrink */
|
||||
size_t * sz = (size_t*)m;
|
||||
if(*sz >= (size_t)N){
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
re = realloc( m, N + BLOCK_HDR_SIZE );
|
||||
if(re){
|
||||
m = (unsigned char *)re;
|
||||
*((size_t*)m) = N;
|
||||
return m + BLOCK_HDR_SIZE;
|
||||
}else{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static size_t lsmPosixOsMSize(lsm_env *pEnv, void *p){
|
||||
unsigned char * m = (unsigned char *)p;
|
||||
return *((size_t*)(m-BLOCK_HDR_SIZE));
|
||||
}
|
||||
#undef BLOCK_HDR_SIZE
|
||||
|
||||
|
||||
#ifdef LSM_MUTEX_PTHREADS
|
||||
/*************************************************************************
|
||||
** Mutex methods for pthreads based systems. If LSM_MUTEX_PTHREADS is
|
||||
** missing then a no-op implementation of mutexes found in lsm_mutex.c
|
||||
** will be used instead.
|
||||
*/
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct PthreadMutex PthreadMutex;
|
||||
struct PthreadMutex {
|
||||
lsm_env *pEnv;
|
||||
pthread_mutex_t mutex;
|
||||
#ifdef LSM_DEBUG
|
||||
pthread_t owner;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
# define LSM_PTHREAD_STATIC_MUTEX { 0, PTHREAD_MUTEX_INITIALIZER, 0 }
|
||||
#else
|
||||
# define LSM_PTHREAD_STATIC_MUTEX { 0, PTHREAD_MUTEX_INITIALIZER }
|
||||
#endif
|
||||
|
||||
static int lsmPosixOsMutexStatic(
|
||||
lsm_env *pEnv,
|
||||
int iMutex,
|
||||
lsm_mutex **ppStatic
|
||||
){
|
||||
static PthreadMutex sMutex[2] = {
|
||||
LSM_PTHREAD_STATIC_MUTEX,
|
||||
LSM_PTHREAD_STATIC_MUTEX
|
||||
};
|
||||
|
||||
assert( iMutex==LSM_MUTEX_GLOBAL || iMutex==LSM_MUTEX_HEAP );
|
||||
assert( LSM_MUTEX_GLOBAL==1 && LSM_MUTEX_HEAP==2 );
|
||||
|
||||
*ppStatic = (lsm_mutex *)&sMutex[iMutex-1];
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static int lsmPosixOsMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
|
||||
PthreadMutex *pMutex; /* Pointer to new mutex */
|
||||
pthread_mutexattr_t attr; /* Attributes object */
|
||||
|
||||
pMutex = (PthreadMutex *)lsmMallocZero(pEnv, sizeof(PthreadMutex));
|
||||
if( !pMutex ) return LSM_NOMEM_BKPT;
|
||||
|
||||
pMutex->pEnv = pEnv;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&pMutex->mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
*ppNew = (lsm_mutex *)pMutex;
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
static void lsmPosixOsMutexDel(lsm_mutex *p){
|
||||
PthreadMutex *pMutex = (PthreadMutex *)p;
|
||||
pthread_mutex_destroy(&pMutex->mutex);
|
||||
lsmFree(pMutex->pEnv, pMutex);
|
||||
}
|
||||
|
||||
static void lsmPosixOsMutexEnter(lsm_mutex *p){
|
||||
PthreadMutex *pMutex = (PthreadMutex *)p;
|
||||
pthread_mutex_lock(&pMutex->mutex);
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
assert( !pthread_equal(pMutex->owner, pthread_self()) );
|
||||
pMutex->owner = pthread_self();
|
||||
assert( pthread_equal(pMutex->owner, pthread_self()) );
|
||||
#endif
|
||||
}
|
||||
|
||||
static int lsmPosixOsMutexTry(lsm_mutex *p){
|
||||
int ret;
|
||||
PthreadMutex *pMutex = (PthreadMutex *)p;
|
||||
ret = pthread_mutex_trylock(&pMutex->mutex);
|
||||
#ifdef LSM_DEBUG
|
||||
if( ret==0 ){
|
||||
assert( !pthread_equal(pMutex->owner, pthread_self()) );
|
||||
pMutex->owner = pthread_self();
|
||||
assert( pthread_equal(pMutex->owner, pthread_self()) );
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void lsmPosixOsMutexLeave(lsm_mutex *p){
|
||||
PthreadMutex *pMutex = (PthreadMutex *)p;
|
||||
#ifdef LSM_DEBUG
|
||||
assert( pthread_equal(pMutex->owner, pthread_self()) );
|
||||
pMutex->owner = 0;
|
||||
assert( !pthread_equal(pMutex->owner, pthread_self()) );
|
||||
#endif
|
||||
pthread_mutex_unlock(&pMutex->mutex);
|
||||
}
|
||||
|
||||
#ifdef LSM_DEBUG
|
||||
static int lsmPosixOsMutexHeld(lsm_mutex *p){
|
||||
PthreadMutex *pMutex = (PthreadMutex *)p;
|
||||
return pMutex ? pthread_equal(pMutex->owner, pthread_self()) : 1;
|
||||
}
|
||||
static int lsmPosixOsMutexNotHeld(lsm_mutex *p){
|
||||
PthreadMutex *pMutex = (PthreadMutex *)p;
|
||||
return pMutex ? !pthread_equal(pMutex->owner, pthread_self()) : 1;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
** End of pthreads mutex implementation.
|
||||
*************************************************************************/
|
||||
#else
|
||||
/*************************************************************************
|
||||
** Noop mutex implementation
|
||||
*/
|
||||
typedef struct NoopMutex NoopMutex;
|
||||
struct NoopMutex {
|
||||
lsm_env *pEnv; /* Environment handle (for xFree()) */
|
||||
int bHeld; /* True if mutex is held */
|
||||
int bStatic; /* True for a static mutex */
|
||||
};
|
||||
static NoopMutex aStaticNoopMutex[2] = {
|
||||
{0, 0, 1},
|
||||
{0, 0, 1},
|
||||
};
|
||||
|
||||
static int lsmPosixOsMutexStatic(
|
||||
lsm_env *pEnv,
|
||||
int iMutex,
|
||||
lsm_mutex **ppStatic
|
||||
){
|
||||
assert( iMutex>=1 && iMutex<=(int)array_size(aStaticNoopMutex) );
|
||||
*ppStatic = (lsm_mutex *)&aStaticNoopMutex[iMutex-1];
|
||||
return LSM_OK;
|
||||
}
|
||||
static int lsmPosixOsMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
|
||||
NoopMutex *p;
|
||||
p = (NoopMutex *)lsmMallocZero(pEnv, sizeof(NoopMutex));
|
||||
if( p ) p->pEnv = pEnv;
|
||||
*ppNew = (lsm_mutex *)p;
|
||||
return (p ? LSM_OK : LSM_NOMEM_BKPT);
|
||||
}
|
||||
static void lsmPosixOsMutexDel(lsm_mutex *pMutex) {
|
||||
NoopMutex *p = (NoopMutex *)pMutex;
|
||||
assert( p->bStatic==0 && p->pEnv );
|
||||
lsmFree(p->pEnv, p);
|
||||
}
|
||||
static void lsmPosixOsMutexEnter(lsm_mutex *pMutex){
|
||||
NoopMutex *p = (NoopMutex *)pMutex;
|
||||
assert( p->bHeld==0 );
|
||||
p->bHeld = 1;
|
||||
}
|
||||
static int lsmPosixOsMutexTry(lsm_mutex *pMutex){
|
||||
NoopMutex *p = (NoopMutex *)pMutex;
|
||||
assert( p->bHeld==0 );
|
||||
p->bHeld = 1;
|
||||
return 0;
|
||||
}
|
||||
static void lsmPosixOsMutexLeave(lsm_mutex *pMutex){
|
||||
NoopMutex *p = (NoopMutex *)pMutex;
|
||||
assert( p->bHeld==1 );
|
||||
p->bHeld = 0;
|
||||
}
|
||||
#ifdef LSM_DEBUG
|
||||
static int lsmPosixOsMutexHeld(lsm_mutex *pMutex){
|
||||
NoopMutex *p = (NoopMutex *)pMutex;
|
||||
return p ? p->bHeld : 1;
|
||||
}
|
||||
static int lsmPosixOsMutexNotHeld(lsm_mutex *pMutex){
|
||||
NoopMutex *p = (NoopMutex *)pMutex;
|
||||
return p ? !p->bHeld : 1;
|
||||
}
|
||||
#endif
|
||||
/***************************************************************************/
|
||||
#endif /* else LSM_MUTEX_NONE */
|
||||
|
||||
/* Without LSM_DEBUG, the MutexHeld tests are never called */
|
||||
#ifndef LSM_DEBUG
|
||||
# define lsmPosixOsMutexHeld 0
|
||||
# define lsmPosixOsMutexNotHeld 0
|
||||
#endif
|
||||
|
||||
lsm_env *lsm_default_env(void){
|
||||
static lsm_env posix_env = {
|
||||
sizeof(lsm_env), /* nByte */
|
||||
1, /* iVersion */
|
||||
/***** file i/o ******************/
|
||||
0, /* pVfsCtx */
|
||||
lsmPosixOsFullpath, /* xFullpath */
|
||||
lsmPosixOsOpen, /* xOpen */
|
||||
lsmPosixOsRead, /* xRead */
|
||||
lsmPosixOsWrite, /* xWrite */
|
||||
lsmPosixOsTruncate, /* xTruncate */
|
||||
lsmPosixOsSync, /* xSync */
|
||||
lsmPosixOsSectorSize, /* xSectorSize */
|
||||
lsmPosixOsRemap, /* xRemap */
|
||||
lsmPosixOsFileid, /* xFileid */
|
||||
lsmPosixOsClose, /* xClose */
|
||||
lsmPosixOsUnlink, /* xUnlink */
|
||||
lsmPosixOsLock, /* xLock */
|
||||
lsmPosixOsTestLock, /* xTestLock */
|
||||
lsmPosixOsShmMap, /* xShmMap */
|
||||
lsmPosixOsShmBarrier, /* xShmBarrier */
|
||||
lsmPosixOsShmUnmap, /* xShmUnmap */
|
||||
/***** memory allocation *********/
|
||||
0, /* pMemCtx */
|
||||
lsmPosixOsMalloc, /* xMalloc */
|
||||
lsmPosixOsRealloc, /* xRealloc */
|
||||
lsmPosixOsFree, /* xFree */
|
||||
lsmPosixOsMSize, /* xSize */
|
||||
/***** mutexes *********************/
|
||||
0, /* pMutexCtx */
|
||||
lsmPosixOsMutexStatic, /* xMutexStatic */
|
||||
lsmPosixOsMutexNew, /* xMutexNew */
|
||||
lsmPosixOsMutexDel, /* xMutexDel */
|
||||
lsmPosixOsMutexEnter, /* xMutexEnter */
|
||||
lsmPosixOsMutexTry, /* xMutexTry */
|
||||
lsmPosixOsMutexLeave, /* xMutexLeave */
|
||||
lsmPosixOsMutexHeld, /* xMutexHeld */
|
||||
lsmPosixOsMutexNotHeld, /* xMutexNotHeld */
|
||||
/***** other *********************/
|
||||
lsmPosixOsSleep, /* xSleep */
|
||||
};
|
||||
return &posix_env;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,201 +0,0 @@
|
||||
|
||||
/*
|
||||
** 2012-02-08
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** SQLite4-compatible varint implementation.
|
||||
*/
|
||||
#include "lsmInt.h"
|
||||
|
||||
/*************************************************************************
|
||||
** The following is a copy of the varint.c module from SQLite 4.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Decode the varint in z[]. Write the integer value into *pResult and
|
||||
** return the number of bytes in the varint.
|
||||
*/
|
||||
static int lsmSqlite4GetVarint64(const unsigned char *z, u64 *pResult){
|
||||
unsigned int x;
|
||||
if( z[0]<=240 ){
|
||||
*pResult = z[0];
|
||||
return 1;
|
||||
}
|
||||
if( z[0]<=248 ){
|
||||
*pResult = (z[0]-241)*256 + z[1] + 240;
|
||||
return 2;
|
||||
}
|
||||
if( z[0]==249 ){
|
||||
*pResult = 2288 + 256*z[1] + z[2];
|
||||
return 3;
|
||||
}
|
||||
if( z[0]==250 ){
|
||||
*pResult = (z[1]<<16) + (z[2]<<8) + z[3];
|
||||
return 4;
|
||||
}
|
||||
x = (z[1]<<24) + (z[2]<<16) + (z[3]<<8) + z[4];
|
||||
if( z[0]==251 ){
|
||||
*pResult = x;
|
||||
return 5;
|
||||
}
|
||||
if( z[0]==252 ){
|
||||
*pResult = (((u64)x)<<8) + z[5];
|
||||
return 6;
|
||||
}
|
||||
if( z[0]==253 ){
|
||||
*pResult = (((u64)x)<<16) + (z[5]<<8) + z[6];
|
||||
return 7;
|
||||
}
|
||||
if( z[0]==254 ){
|
||||
*pResult = (((u64)x)<<24) + (z[5]<<16) + (z[6]<<8) + z[7];
|
||||
return 8;
|
||||
}
|
||||
*pResult = (((u64)x)<<32) +
|
||||
(0xffffffff & ((z[5]<<24) + (z[6]<<16) + (z[7]<<8) + z[8]));
|
||||
return 9;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write a 32-bit unsigned integer as 4 big-endian bytes.
|
||||
*/
|
||||
static void lsmVarintWrite32(unsigned char *z, unsigned int y){
|
||||
z[0] = (unsigned char)(y>>24);
|
||||
z[1] = (unsigned char)(y>>16);
|
||||
z[2] = (unsigned char)(y>>8);
|
||||
z[3] = (unsigned char)(y);
|
||||
}
|
||||
|
||||
/*
|
||||
** Write a varint into z[]. The buffer z[] must be at least 9 characters
|
||||
** long to accommodate the largest possible varint. Return the number of
|
||||
** bytes of z[] used.
|
||||
*/
|
||||
static int lsmSqlite4PutVarint64(unsigned char *z, u64 x){
|
||||
unsigned int w, y;
|
||||
if( x<=240 ){
|
||||
z[0] = (unsigned char)x;
|
||||
return 1;
|
||||
}
|
||||
if( x<=2287 ){
|
||||
y = (unsigned int)(x - 240);
|
||||
z[0] = (unsigned char)(y/256 + 241);
|
||||
z[1] = (unsigned char)(y%256);
|
||||
return 2;
|
||||
}
|
||||
if( x<=67823 ){
|
||||
y = (unsigned int)(x - 2288);
|
||||
z[0] = 249;
|
||||
z[1] = (unsigned char)(y/256);
|
||||
z[2] = (unsigned char)(y%256);
|
||||
return 3;
|
||||
}
|
||||
y = (unsigned int)x;
|
||||
w = (unsigned int)(x>>32);
|
||||
if( w==0 ){
|
||||
if( y<=16777215 ){
|
||||
z[0] = 250;
|
||||
z[1] = (unsigned char)(y>>16);
|
||||
z[2] = (unsigned char)(y>>8);
|
||||
z[3] = (unsigned char)(y);
|
||||
return 4;
|
||||
}
|
||||
z[0] = 251;
|
||||
lsmVarintWrite32(z+1, y);
|
||||
return 5;
|
||||
}
|
||||
if( w<=255 ){
|
||||
z[0] = 252;
|
||||
z[1] = (unsigned char)w;
|
||||
lsmVarintWrite32(z+2, y);
|
||||
return 6;
|
||||
}
|
||||
if( w<=32767 ){
|
||||
z[0] = 253;
|
||||
z[1] = (unsigned char)(w>>8);
|
||||
z[2] = (unsigned char)w;
|
||||
lsmVarintWrite32(z+3, y);
|
||||
return 7;
|
||||
}
|
||||
if( w<=16777215 ){
|
||||
z[0] = 254;
|
||||
z[1] = (unsigned char)(w>>16);
|
||||
z[2] = (unsigned char)(w>>8);
|
||||
z[3] = (unsigned char)w;
|
||||
lsmVarintWrite32(z+4, y);
|
||||
return 8;
|
||||
}
|
||||
z[0] = 255;
|
||||
lsmVarintWrite32(z+1, w);
|
||||
lsmVarintWrite32(z+5, y);
|
||||
return 9;
|
||||
}
|
||||
|
||||
/*
|
||||
** End of SQLite 4 code.
|
||||
*************************************************************************/
|
||||
|
||||
int lsmVarintPut64(u8 *aData, i64 iVal){
|
||||
return lsmSqlite4PutVarint64(aData, (u64)iVal);
|
||||
}
|
||||
|
||||
int lsmVarintGet64(const u8 *aData, i64 *piVal){
|
||||
return lsmSqlite4GetVarint64(aData, (u64 *)piVal);
|
||||
}
|
||||
|
||||
int lsmVarintPut32(u8 *aData, int iVal){
|
||||
return lsmSqlite4PutVarint64(aData, (u64)iVal);
|
||||
}
|
||||
|
||||
int lsmVarintGet32(u8 *z, int *piVal){
|
||||
u64 i;
|
||||
int ret;
|
||||
|
||||
if( z[0]<=240 ){
|
||||
*piVal = z[0];
|
||||
return 1;
|
||||
}
|
||||
if( z[0]<=248 ){
|
||||
*piVal = (z[0]-241)*256 + z[1] + 240;
|
||||
return 2;
|
||||
}
|
||||
if( z[0]==249 ){
|
||||
*piVal = 2288 + 256*z[1] + z[2];
|
||||
return 3;
|
||||
}
|
||||
if( z[0]==250 ){
|
||||
*piVal = (z[1]<<16) + (z[2]<<8) + z[3];
|
||||
return 4;
|
||||
}
|
||||
|
||||
ret = lsmSqlite4GetVarint64(z, &i);
|
||||
*piVal = (int)i;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lsmVarintLen32(int n){
|
||||
u8 aData[9];
|
||||
return lsmVarintPut32(aData, n);
|
||||
}
|
||||
|
||||
int lsmVarintLen64(i64 n){
|
||||
u8 aData[9];
|
||||
return lsmVarintPut64(aData, n);
|
||||
}
|
||||
|
||||
/*
|
||||
** The argument is the first byte of a varint. This function returns the
|
||||
** total number of bytes in the entire varint (including the first byte).
|
||||
*/
|
||||
int lsmVarintSize(u8 c){
|
||||
if( c<241 ) return 1;
|
||||
if( c<249 ) return 2;
|
||||
return (int)(c - 246);
|
||||
}
|
||||
-1084
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
||||
# 2014 Dec 19
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. .. test]
|
||||
}
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Check if the lsm1 extension has been compiled.
|
||||
if {$::tcl_platform(platform) == "windows"} {
|
||||
set lsm1 lsm.dll
|
||||
} else {
|
||||
set lsm1 lsm.so
|
||||
}
|
||||
|
||||
if {[file exists [file join .. $lsm1]]} {
|
||||
proc return_if_no_lsm1 {} {}
|
||||
} else {
|
||||
proc return_if_no_lsm1 {} {
|
||||
finish_test
|
||||
return -code return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
proc load_lsm1_vtab {db} {
|
||||
db enable_load_extension 1
|
||||
db eval {SELECT load_extension('../lsm')}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
# 2017 July 14
|
||||
#
|
||||
# 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 lsm1 virtual table module.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] lsm1_common.tcl]
|
||||
set testprefix lsm1_simple
|
||||
return_if_no_lsm1
|
||||
load_lsm1_vtab db
|
||||
|
||||
forcedelete testlsm.db
|
||||
|
||||
do_execsql_test 100 {
|
||||
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,UINT,b,c,d);
|
||||
PRAGMA table_info(x1);
|
||||
} {
|
||||
0 a UINT 1 {} 1
|
||||
1 b {} 0 {} 0
|
||||
2 c {} 0 {} 0
|
||||
3 d {} 0 {} 0
|
||||
}
|
||||
|
||||
do_execsql_test 110 {
|
||||
INSERT INTO x1(a,b,c,d) VALUES(15, 11, 22, 33),(8,'banjo',x'333231',NULL),
|
||||
(12,NULL,3.25,-559281390);
|
||||
SELECT a, quote(b), quote(c), quote(d) FROM x1;
|
||||
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390 15 11 22 33}
|
||||
do_execsql_test 111 {
|
||||
SELECT a, quote(lsm1_key), quote(lsm1_value) FROM x1;
|
||||
} {8 X'08' X'2162616E6A6F1633323105' 12 X'0C' X'05320000000000000A401FFB42ABE9DB' 15 X'0F' X'4284C6'}
|
||||
|
||||
do_execsql_test 120 {
|
||||
UPDATE x1 SET d = d+1.0 WHERE a=15;
|
||||
SELECT a, quote(b), quote(c), quote(d) FROM x1;
|
||||
} {8 'banjo' X'333231' NULL 12 NULL 3.25 -559281390 15 11 22 34.0}
|
||||
|
||||
do_execsql_test 130 {
|
||||
UPDATE x1 SET a=123456789 WHERE a=12;
|
||||
SELECT a, quote(b), quote(c), quote(d) FROM x1;
|
||||
} {8 'banjo' X'333231' NULL 15 11 22 34.0 123456789 NULL 3.25 -559281390}
|
||||
do_execsql_test 131 {
|
||||
SELECT quote(lsm1_key), printf('0x%x',a) FROM x1 WHERE a > 100000000;
|
||||
} {X'FB075BCD15' 0x75bcd15}
|
||||
|
||||
do_execsql_test 140 {
|
||||
DELETE FROM x1 WHERE a=15;
|
||||
SELECT a, quote(b), quote(c), quote(d) FROM x1;
|
||||
} {8 'banjo' X'333231' NULL 123456789 NULL 3.25 -559281390}
|
||||
|
||||
do_test 150 {
|
||||
lsort [glob testlsm.db*]
|
||||
} {testlsm.db testlsm.db-log testlsm.db-shm}
|
||||
|
||||
db close
|
||||
do_test 160 {
|
||||
lsort [glob testlsm.db*]
|
||||
} {testlsm.db}
|
||||
|
||||
forcedelete testlsm.db
|
||||
forcedelete test.db
|
||||
sqlite3 db test.db
|
||||
load_lsm1_vtab db
|
||||
|
||||
|
||||
do_execsql_test 200 {
|
||||
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,TEXT,b,c,d);
|
||||
PRAGMA table_info(x1);
|
||||
} {
|
||||
0 a TEXT 1 {} 1
|
||||
1 b {} 0 {} 0
|
||||
2 c {} 0 {} 0
|
||||
3 d {} 0 {} 0
|
||||
}
|
||||
do_execsql_test 210 {
|
||||
INSERT INTO x1(a,b,c,d) VALUES(15, 11, 22, 33),(8,'banjo',x'333231',NULL),
|
||||
(12,NULL,3.25,-559281390);
|
||||
SELECT quote(a), quote(b), quote(c), quote(d), '|' FROM x1;
|
||||
} {'12' NULL 3.25 -559281390 | '15' 11 22 33 | '8' 'banjo' X'333231' NULL |}
|
||||
do_execsql_test 211 {
|
||||
SELECT quote(a), quote(lsm1_key), quote(lsm1_value), '|' FROM x1;
|
||||
} {'12' X'3132' X'05320000000000000A401FFB42ABE9DB' | '15' X'3135' X'4284C6' | '8' X'38' X'2162616E6A6F1633323105' |}
|
||||
do_execsql_test 212 {
|
||||
SELECT quote(a), quote(lsm1_key), quote(lsm1_value) FROM x1 WHERE a='12';
|
||||
} {'12' X'3132' X'05320000000000000A401FFB42ABE9DB'}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
forcedelete testlsm.db
|
||||
load_lsm1_vtab db
|
||||
do_execsql_test 300 {
|
||||
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,TEXT,b,c,d);
|
||||
}
|
||||
do_eqp_test 310 {
|
||||
SELECT * FROM x1 WHERE a=?
|
||||
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 0:}
|
||||
|
||||
do_eqp_test 320 {
|
||||
SELECT * FROM x1 WHERE a>?
|
||||
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 2:}
|
||||
|
||||
do_eqp_test 330 {
|
||||
SELECT * FROM x1 WHERE a<?
|
||||
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 3:}
|
||||
do_eqp_test 340 {
|
||||
SELECT * FROM x1 WHERE a BETWEEN ? AND ?
|
||||
} {SCAN TABLE x1 VIRTUAL TABLE INDEX 1:}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
forcedelete testlsm.db
|
||||
load_lsm1_vtab db
|
||||
do_execsql_test 400 {
|
||||
CREATE VIRTUAL TABLE x1 USING lsm1(testlsm.db,a,TEXT,b);
|
||||
INSERT INTO x1 VALUES('one', 1);
|
||||
INSERT INTO x1 VALUES('two', 2);
|
||||
INSERT INTO x1 VALUES('three', 3);
|
||||
INSERT INTO x1 VALUES('four', 4);
|
||||
INSERT INTO x1 VALUES('five', 5);
|
||||
}
|
||||
do_execsql_test 410 {
|
||||
SELECT b FROM x1 WHERE a = 'two'
|
||||
} {2}
|
||||
do_execsql_test 411 {
|
||||
SELECT b FROM x1 WHERE a = 'one'
|
||||
} {1}
|
||||
do_execsql_test 412 {
|
||||
SELECT b FROM x1 WHERE a = 'five'
|
||||
} {5}
|
||||
|
||||
do_execsql_test 420 {
|
||||
SELECT b FROM x1 WHERE a BETWEEN 'one' AND 'three';
|
||||
} {1 3}
|
||||
do_execsql_test 421 {
|
||||
SELECT b FROM x1 WHERE a BETWEEN 'five' AND 'two';
|
||||
} {5 4 1 3 2}
|
||||
do_execsql_test 421 {
|
||||
SELECT b FROM x1 WHERE a > 'five';
|
||||
} {4 1 3 2}
|
||||
do_execsql_test 421 {
|
||||
SELECT b FROM x1 WHERE a <= 'three';
|
||||
} {3 1 4 5}
|
||||
|
||||
finish_test
|
||||
@@ -1,88 +0,0 @@
|
||||
#!/bin/sh
|
||||
# restart with tclsh \
|
||||
exec tclsh "$0" "$@"
|
||||
|
||||
set srcdir [file dirname [file dirname [info script]]]
|
||||
set G(src) [string map [list %dir% $srcdir] {
|
||||
%dir%/lsm.h
|
||||
%dir%/lsmInt.h
|
||||
%dir%/lsm_vtab.c
|
||||
%dir%/lsm_ckpt.c
|
||||
%dir%/lsm_file.c
|
||||
%dir%/lsm_log.c
|
||||
%dir%/lsm_main.c
|
||||
%dir%/lsm_mem.c
|
||||
%dir%/lsm_mutex.c
|
||||
%dir%/lsm_shared.c
|
||||
%dir%/lsm_sorted.c
|
||||
%dir%/lsm_str.c
|
||||
%dir%/lsm_tree.c
|
||||
%dir%/lsm_unix.c
|
||||
%dir%/lsm_varint.c
|
||||
%dir%/lsm_win32.c
|
||||
}]
|
||||
|
||||
set G(hdr) {
|
||||
|
||||
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_LSM1)
|
||||
|
||||
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
|
||||
# define NDEBUG 1
|
||||
#endif
|
||||
#if defined(NDEBUG) && defined(SQLITE_DEBUG)
|
||||
# undef NDEBUG
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
set G(footer) {
|
||||
|
||||
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_LSM1) */
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Read and return the entire contents of text file $zFile from disk.
|
||||
#
|
||||
proc readfile {zFile} {
|
||||
set fd [open $zFile]
|
||||
set data [read $fd]
|
||||
close $fd
|
||||
return $data
|
||||
}
|
||||
|
||||
proc lsm1c_init {zOut} {
|
||||
global G
|
||||
set G(fd) stdout
|
||||
set G(fd) [open $zOut w]
|
||||
|
||||
puts -nonewline $G(fd) $G(hdr)
|
||||
}
|
||||
|
||||
proc lsm1c_printfile {zIn} {
|
||||
global G
|
||||
set data [readfile $zIn]
|
||||
set zTail [file tail $zIn]
|
||||
puts $G(fd) "#line 1 \"$zTail\""
|
||||
|
||||
foreach line [split $data "\n"] {
|
||||
if {[regexp {^# *include.*lsm} $line]} {
|
||||
set line "/* $line */"
|
||||
} elseif { [regexp {^(const )?[a-zA-Z][a-zA-Z0-9]* [*]?lsm[^_]} $line] } {
|
||||
set line "static $line"
|
||||
}
|
||||
puts $G(fd) $line
|
||||
}
|
||||
}
|
||||
|
||||
proc lsm1c_close {} {
|
||||
global G
|
||||
puts -nonewline $G(fd) $G(footer)
|
||||
if {$G(fd)!="stdout"} {
|
||||
close $G(fd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lsm1c_init lsm1.c
|
||||
foreach f $G(src) { lsm1c_printfile $f }
|
||||
lsm1c_close
|
||||
@@ -9,11 +9,6 @@ Each source file contains a description in its header comment. See the
|
||||
header comments for details about each extension. Additional notes are
|
||||
as follows:
|
||||
|
||||
* **carray.c** — This module implements the
|
||||
[carray](https://sqlite.org/carray.html) table-valued function.
|
||||
It is a good example of how to go about implementing a custom
|
||||
[table-valued function](https://sqlite.org/vtab.html#tabfunc2).
|
||||
|
||||
* **csv.c** — A [virtual table](https://sqlite.org/vtab.html)
|
||||
for reading
|
||||
[Comma-Separated-Value (CSV) files](https://en.wikipedia.org/wiki/Comma-separated_values).
|
||||
@@ -28,11 +23,6 @@ as follows:
|
||||
[SQLite amalgamation](https://sqlite.org/amalgamation.html). See
|
||||
<https://sqlite.org/json1.html> for additional information.
|
||||
|
||||
* **memvfs.c** — This file implements a custom
|
||||
[VFS](https://sqlite.org/vfs.html) that stores an entire database
|
||||
file in a single block of RAM. It serves as a good example of how
|
||||
to implement a simple custom VFS.
|
||||
|
||||
* **rot13.c** — This file implements the very simple rot13()
|
||||
substitution function. This file makes a good template for implementing
|
||||
new custom SQL functions for SQLite.
|
||||
|
||||
+5
-5
@@ -514,7 +514,7 @@ struct amatch_cursor {
|
||||
sqlite3_int64 iRowid; /* The rowid of the current word */
|
||||
amatch_langid iLang; /* Use this language ID */
|
||||
amatch_cost rLimit; /* Maximum cost of any term */
|
||||
int nBuf; /* Space allocated for zBuf */
|
||||
sqlite3_int64 nBuf; /* Space allocated for zBuf */
|
||||
int oomErr; /* True following an OOM error */
|
||||
int nWord; /* Number of amatch_word objects */
|
||||
char *zBuf; /* Temp-use buffer space */
|
||||
@@ -1039,7 +1039,7 @@ static void amatchAddWord(
|
||||
nTail = (int)strlen(zWordTail);
|
||||
if( nBase+nTail+3>pCur->nBuf ){
|
||||
pCur->nBuf = nBase+nTail+100;
|
||||
pCur->zBuf = sqlite3_realloc(pCur->zBuf, pCur->nBuf);
|
||||
pCur->zBuf = sqlite3_realloc64(pCur->zBuf, pCur->nBuf);
|
||||
if( pCur->zBuf==0 ){
|
||||
pCur->nBuf = 0;
|
||||
return;
|
||||
@@ -1105,13 +1105,13 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
|
||||
amatch_avl *pNode;
|
||||
int isMatch = 0;
|
||||
amatch_vtab *p = pCur->pVtab;
|
||||
int nWord;
|
||||
sqlite3_int64 nWord;
|
||||
int rc;
|
||||
int i;
|
||||
const char *zW;
|
||||
amatch_rule *pRule;
|
||||
char *zBuf = 0;
|
||||
char nBuf = 0;
|
||||
sqlite3_int64 nBuf = 0;
|
||||
char zNext[8];
|
||||
char zNextIn[8];
|
||||
int nNextIn;
|
||||
@@ -1158,7 +1158,7 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
|
||||
nWord = (int)strlen(pWord->zWord+2);
|
||||
if( nWord+20>nBuf ){
|
||||
nBuf = (char)(nWord+100);
|
||||
zBuf = sqlite3_realloc(zBuf, nBuf);
|
||||
zBuf = sqlite3_realloc64(zBuf, nBuf);
|
||||
if( zBuf==0 ) return SQLITE_NOMEM;
|
||||
}
|
||||
amatchStrcpy(zBuf, pWord->zWord+2);
|
||||
|
||||
+4
-2
@@ -207,7 +207,9 @@ static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
|
||||
|
||||
/* This function does the work for the SQLite base64(x) UDF. */
|
||||
static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
int nb, nc, nv = sqlite3_value_bytes(av[0]);
|
||||
sqlite3_int64 nb;
|
||||
sqlite3_int64 nv = sqlite3_value_bytes(av[0]);
|
||||
sqlite3_int64 nc;
|
||||
int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
|
||||
SQLITE_LIMIT_LENGTH, -1);
|
||||
char *cBuf;
|
||||
@@ -216,7 +218,7 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
switch( sqlite3_value_type(av[0]) ){
|
||||
case SQLITE_BLOB:
|
||||
nb = nv;
|
||||
nc = 4*(nv+2/3); /* quads needed */
|
||||
nc = 4*((nv+2)/3); /* quads needed */
|
||||
nc += (nc+(B64_DARK_MAX-1))/B64_DARK_MAX + 1; /* LFs and a 0-terminator */
|
||||
if( nvMax < nc ){
|
||||
sqlite3_result_error(context, "blob expanded to base64 too big", -1);
|
||||
|
||||
+1
-1
@@ -286,7 +286,7 @@ static void is_base85(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
|
||||
/* This function does the work for the SQLite base85(x) UDF. */
|
||||
static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
int nb, nc, nv = sqlite3_value_bytes(av[0]);
|
||||
sqlite3_int64 nb, nc, nv = sqlite3_value_bytes(av[0]);
|
||||
int nvMax = sqlite3_limit(sqlite3_context_db_handle(context),
|
||||
SQLITE_LIMIT_LENGTH, -1);
|
||||
char *cBuf;
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
** 2020-11-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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** Interface definitions for the CARRAY table-valued function
|
||||
** extension.
|
||||
*/
|
||||
|
||||
#ifndef _CARRAY_H
|
||||
#define _CARRAY_H
|
||||
|
||||
#include "sqlite3.h" /* Required for error code definitions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Use this interface to bind an array to the single-argument version
|
||||
** of CARRAY().
|
||||
*/
|
||||
SQLITE_API int sqlite3_carray_bind(
|
||||
sqlite3_stmt *pStmt, /* Statement to be bound */
|
||||
int i, /* Parameter index */
|
||||
void *aData, /* Pointer to array data */
|
||||
int nData, /* Number of data elements */
|
||||
int mFlags, /* CARRAY flags */
|
||||
void (*xDel)(void*) /* Destructgor for aData*/
|
||||
);
|
||||
|
||||
/* Allowed values for the mFlags parameter to sqlite3_carray_bind().
|
||||
*/
|
||||
#define CARRAY_INT32 0 /* Data is 32-bit signed integers */
|
||||
#define CARRAY_INT64 1 /* Data is 64-bit signed integers */
|
||||
#define CARRAY_DOUBLE 2 /* Data is doubles */
|
||||
#define CARRAY_TEXT 3 /* Data is char* */
|
||||
#define CARRAY_BLOB 4 /* Data is struct iovec */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of the 'extern "C"' block */
|
||||
#endif
|
||||
|
||||
#endif /* ifndef _CARRAY_H */
|
||||
+5
-38
@@ -197,8 +197,6 @@ struct CksmFile {
|
||||
char computeCksm; /* True to compute checksums.
|
||||
** Always true if reserve size is 8. */
|
||||
char verifyCksm; /* True to verify checksums */
|
||||
char isWal; /* True if processing a WAL file */
|
||||
char inCkpt; /* Currently doing a checkpoint */
|
||||
CksmFile *pPartner; /* Ptr from WAL to main-db, or from main-db to WAL */
|
||||
};
|
||||
|
||||
@@ -444,11 +442,9 @@ static int cksmRead(
|
||||
** (1) the size indicates that we are dealing with a complete
|
||||
** database page
|
||||
** (2) checksum verification is enabled
|
||||
** (3) we are not in the middle of checkpoint
|
||||
*/
|
||||
if( iAmt>=512 && (iAmt & (iAmt-1))==0 /* (1) */
|
||||
&& p->verifyCksm /* (2) */
|
||||
&& !p->inCkpt /* (3) */
|
||||
){
|
||||
u8 cksum[8];
|
||||
cksmCompute((u8*)zBuf, iAmt-8, cksum);
|
||||
@@ -489,7 +485,6 @@ static int cksmWrite(
|
||||
*/
|
||||
if( iAmt>=512
|
||||
&& p->computeCksm
|
||||
&& !p->inCkpt
|
||||
){
|
||||
cksmCompute((u8*)zBuf, iAmt-8, ((u8*)zBuf)+iAmt-8);
|
||||
}
|
||||
@@ -576,21 +571,6 @@ static int cksmFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
/* Do not allow page size changes on a checksum database */
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}else if( op==SQLITE_FCNTL_CKPT_START || op==SQLITE_FCNTL_CKPT_DONE ){
|
||||
p->inCkpt = op==SQLITE_FCNTL_CKPT_START;
|
||||
if( p->pPartner ) p->pPartner->inCkpt = p->inCkpt;
|
||||
}else if( op==SQLITE_FCNTL_CKSM_FILE ){
|
||||
/* This VFS needs to obtain a pointer to the corresponding database
|
||||
** file handle from within xOpen() calls to open wal files. To do this,
|
||||
** it uses the sqlite3_database_file_object() API to obtain a pointer
|
||||
** to the file-handle used by SQLite to access the db file. This is
|
||||
** fine if cksmvfs happens to be the top-level VFS, but not if there
|
||||
** are one or more wrapper VFS. To handle this case, this file-control
|
||||
** is used to extract the cksmvfs file-handle from any wrapper file
|
||||
** handle. */
|
||||
sqlite3_file **ppFile = (sqlite3_file**)pArg;
|
||||
*ppFile = (sqlite3_file*)p;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
rc = pFile->pMethods->xFileControl(pFile, op, pArg);
|
||||
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
|
||||
@@ -611,8 +591,10 @@ static int cksmSectorSize(sqlite3_file *pFile){
|
||||
** Return the device characteristic flags supported by a cksm-file.
|
||||
*/
|
||||
static int cksmDeviceCharacteristics(sqlite3_file *pFile){
|
||||
int devchar = 0;
|
||||
pFile = ORIGFILE(pFile);
|
||||
return pFile->pMethods->xDeviceCharacteristics(pFile);
|
||||
devchar = pFile->pMethods->xDeviceCharacteristics(pFile);
|
||||
return (devchar & ~SQLITE_IOCAP_SUBPAGE_READ);
|
||||
}
|
||||
|
||||
/* Create a shared memory file mapping */
|
||||
@@ -689,7 +671,7 @@ static int cksmOpen(
|
||||
sqlite3_vfs *pSubVfs;
|
||||
int rc;
|
||||
pSubVfs = ORIGVFS(pVfs);
|
||||
if( (flags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_WAL))==0 ){
|
||||
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
|
||||
return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
|
||||
}
|
||||
p = (CksmFile*)pFile;
|
||||
@@ -698,19 +680,6 @@ static int cksmOpen(
|
||||
pFile->pMethods = &cksm_io_methods;
|
||||
rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
|
||||
if( rc ) goto cksm_open_done;
|
||||
if( flags & SQLITE_OPEN_WAL ){
|
||||
sqlite3_file *pDb = sqlite3_database_file_object(zName);
|
||||
rc = pDb->pMethods->xFileControl(pDb, SQLITE_FCNTL_CKSM_FILE, (void*)&pDb);
|
||||
assert( rc==SQLITE_OK );
|
||||
p->pPartner = (CksmFile*)pDb;
|
||||
assert( p->pPartner->pPartner==0 );
|
||||
p->pPartner->pPartner = p;
|
||||
p->isWal = 1;
|
||||
p->computeCksm = p->pPartner->computeCksm;
|
||||
}else{
|
||||
p->isWal = 0;
|
||||
p->computeCksm = 0;
|
||||
}
|
||||
p->zFName = zName;
|
||||
cksm_open_done:
|
||||
if( rc ) pFile->pMethods = 0;
|
||||
@@ -820,9 +789,7 @@ static int cksmRegisterFunc(
|
||||
*/
|
||||
static int cksmRegisterVfs(void){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3_vfs *pOrig;
|
||||
if( sqlite3_vfs_find("cksmvfs")!=0 ) return SQLITE_OK;
|
||||
pOrig = sqlite3_vfs_find(0);
|
||||
sqlite3_vfs *pOrig = sqlite3_vfs_find(0);
|
||||
if( pOrig==0 ) return SQLITE_ERROR;
|
||||
cksm_vfs.iVersion = pOrig->iVersion;
|
||||
cksm_vfs.pAppData = pOrig;
|
||||
|
||||
@@ -370,6 +370,7 @@ static int completionFilter(
|
||||
if( pCur->nPrefix>0 ){
|
||||
pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
|
||||
if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
|
||||
pCur->nPrefix = (int)strlen(pCur->zPrefix);
|
||||
}
|
||||
iArg = 1;
|
||||
}
|
||||
@@ -378,6 +379,7 @@ static int completionFilter(
|
||||
if( pCur->nLine>0 ){
|
||||
pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
|
||||
if( pCur->zLine==0 ) return SQLITE_NOMEM;
|
||||
pCur->nLine = (int)strlen(pCur->zLine);
|
||||
}
|
||||
}
|
||||
if( pCur->zLine!=0 && pCur->zPrefix==0 ){
|
||||
@@ -389,6 +391,7 @@ static int completionFilter(
|
||||
if( pCur->nPrefix>0 ){
|
||||
pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
|
||||
if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
|
||||
pCur->nPrefix = (int)strlen(pCur->zPrefix);
|
||||
}
|
||||
}
|
||||
pCur->iRowid = 0;
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ static void compressFunc(
|
||||
pIn = sqlite3_value_blob(argv[0]);
|
||||
nIn = sqlite3_value_bytes(argv[0]);
|
||||
nOut = 13 + nIn + (nIn+999)/1000;
|
||||
pOut = sqlite3_malloc( nOut+5 );
|
||||
pOut = sqlite3_malloc64( nOut+5 );
|
||||
for(i=4; i>=0; i--){
|
||||
x[i] = (nIn >> (7*(4-i)))&0x7f;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ static void uncompressFunc(
|
||||
nOut = (nOut<<7) | (pIn[i]&0x7f);
|
||||
if( (pIn[i]&0x80)!=0 ){ i++; break; }
|
||||
}
|
||||
pOut = sqlite3_malloc( nOut+1 );
|
||||
pOut = sqlite3_malloc64( nOut+1 );
|
||||
rc = uncompress(pOut, &nOut, &pIn[i], nIn-i);
|
||||
if( rc==Z_OK ){
|
||||
sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
|
||||
|
||||
+7
-5
@@ -62,6 +62,9 @@ SQLITE_EXTENSION_INIT1
|
||||
# define CSV_NOINLINE
|
||||
#endif
|
||||
|
||||
#ifndef SQLITEINT_H
|
||||
typedef sqlite3_int64 i64;
|
||||
#endif
|
||||
|
||||
/* Max size of the error message in a CsvReader */
|
||||
#define CSV_MXERR 200
|
||||
@@ -74,9 +77,9 @@ typedef struct CsvReader CsvReader;
|
||||
struct CsvReader {
|
||||
FILE *in; /* Read the CSV text from this input stream */
|
||||
char *z; /* Accumulated text for a field */
|
||||
int n; /* Number of bytes in z */
|
||||
int nAlloc; /* Space allocated for z[] */
|
||||
int nLine; /* Current line number */
|
||||
i64 n; /* Number of bytes in z */
|
||||
i64 nAlloc; /* Space allocated for z[] */
|
||||
i64 nLine; /* Current line number */
|
||||
int bNotFirst; /* True if prior text has been seen */
|
||||
int cTerm; /* Character that terminated the most recent field */
|
||||
size_t iIn; /* Next unread character in the input buffer */
|
||||
@@ -174,7 +177,7 @@ static int csv_getc(CsvReader *p){
|
||||
** Return 0 on success and non-zero if there is an OOM error */
|
||||
static CSV_NOINLINE int csv_resize_and_append(CsvReader *p, char c){
|
||||
char *zNew;
|
||||
int nNew = p->nAlloc*2 + 100;
|
||||
i64 nNew = p->nAlloc*2 + 100;
|
||||
zNew = sqlite3_realloc64(p->z, nNew);
|
||||
if( zNew ){
|
||||
p->z = zNew;
|
||||
@@ -510,7 +513,6 @@ static int csvtabConnect(
|
||||
# define CSV_DATA (azPValue[1])
|
||||
# define CSV_SCHEMA (azPValue[2])
|
||||
|
||||
|
||||
assert( sizeof(azPValue)==sizeof(azParam) );
|
||||
memset(&sRdr, 0, sizeof(sRdr));
|
||||
memset(azPValue, 0, sizeof(azPValue));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user