Commit Graph

435 Commits

Author SHA1 Message Date
Howard Chu
d327a36ad8 Fix mdb_env_set_mapsize()
Don't allow shrinking below minimum size for an already open env.
2013-10-04 02:55:34 -07:00
Howard Chu
2520247ba1 ITS#7715 always set filesize for WRITEMAP 2013-10-04 02:46:38 -07:00
Hallvard Furuseth
9f7ae8925f Add Caveat: Readers need write access. Whitespace. 2013-10-04 00:51:58 +02:00
Hallvard Furuseth
0f9b79e12c Maintain MDB_cursor.mc_top 2013-10-04 00:32:35 +02:00
Hallvard Furuseth
99ea7669a3 mdb_cursor_sibling(): Fix error result 2013-10-03 23:59:25 +02:00
Hallvard Furuseth
8f075595a1 mdb_node_add(): Plug page leak when MDB_PAGE_FULL.
Do not fail after mdb_page_new() succeeds.
2013-10-03 23:59:25 +02:00
Hallvard Furuseth
3a1d73daff Optimize code holding reader mutex 2013-10-03 23:59:24 +02:00
Hallvard Furuseth
3d67838a59 Set MDB_xcursor DB_DIRTY, clear md_name.
Both were unused and md_name was unmaintained -- except
mdb_cursor_touch(xcursor) would abuse md_name as a key to
touch MAIN_DBI if it could somehow get passed ! DB_DIRTY.
2013-10-03 23:59:24 +02:00
Hallvard Furuseth
07dc79a7c3 Set subDB DBI=parent DBI, fix MDB_DUPSORT delete.
xcursor DBIs were parent DBI+1 for debugging. Instead output
-(parent DBI).  Fixes a crash in mdb_cursor_del0()'s xcursor
tracking, it forgot to subtract 1 for C_SUB cursors.
2013-10-03 23:59:24 +02:00
Howard Chu
79eac42c0f s/MDB_NORDLOCK/MDB_NOLOCK/
Leave all lock management to the caller.
2013-10-03 10:26:44 -07:00
Howard Chu
a1685c3ef7 More doc for MDB_NORDLOCK 2013-10-01 23:36:57 -07:00
Howard Chu
f739940547 Add MDB_NORDLOCK to omit all reader table usage
Calling app wants to manage its own locking.
2013-10-01 13:16:38 -07:00
Hallvard Furuseth
e3f6c152c5 Drop unneeded code.
MDB_txn.mt_toggle: Use (mt_txnid & 1) instead.
Drop error checks which will be repeated.
mdb_cursor_set(): Turn assert into if/return to match the above.
mdb_cursor_del(): 'flags' are now used as bitflags.
2013-09-23 20:21:11 +02:00
Hallvard Furuseth
2980bd30f5 Clean up and simplify mdb_page_search().
Only named DBs can have DB_STALE, and they do not use MDB_PS_MODIFY.
Replace magic key values with flags.  Drop duplicated comments at
mdb_page_search_root() vs. mdb_page_search(), and rephrase.
2013-09-23 20:21:11 +02:00
Hallvard Furuseth
31cfca9316 Tweak MDB_DEBUG output 2013-09-23 20:20:42 +02:00
Hallvard Furuseth
7bdb5be0b5 Rename SWAP() to avoid conflict with sqlightning.
Happened since sqlightning #includes mdb.c, midl.c.
2013-09-23 20:20:05 +02:00
Hallvard Furuseth
52cb8b3417 mdb_page_unspill(): Rename local vars.
The names have caused bugs, "txn" was treated as
the current transaction.
2013-09-23 20:13:27 +02:00
Hallvard Furuseth
8e1d10e828 ITS#7515 Fix mdb_page_unspill() in nested txn.
Malloc a page in this txn, not in a parent.
2013-09-23 20:13:27 +02:00
Hallvard Furuseth
a3b3482854 ITS#7515 Fix mdb_txn_commit(nested txn with spills).
Catch malloc error.
Fix hunt for dirty vs spilled pages: Don't leave x at a deleted pageno.
Cleanup: Factor out variables, squash pages already marked for deletion.
2013-09-23 20:13:27 +02:00
Hallvard Furuseth
bc48a40621 ITS#7515 Fix mt_dirty_room in nested txns.
Fix description & code: Also ignore dirty pages hidden by
spilled pages, as they won't merge into our dirty_list.
Update it in mdb_page_flush() instead of mdb_page_spill().
2013-09-23 20:13:27 +02:00
Hallvard Furuseth
cfe262dce9 ITS#7515 mdb_pages_xkeep(): Careful about xcursors.
Don't prod sub-pages or pages referring to uninitialized xcursors.
2013-09-23 20:13:27 +02:00
Hallvard Furuseth
5b96d68faf mdb_pages_xkeep(): Reformat, use common flag mask 2013-09-23 20:13:27 +02:00
Hallvard Furuseth
5b21307f29 Update MDB documentation and comments. 2013-09-23 20:09:47 +02:00
Hallvard Furuseth
3335b25834 ITS#7682 mdb_env_copy(): Avoid Linux O_DIRECT bug.
Use fcntl() to set the flag.  Linux open(,O_DIRECT...) can create
the file even on failure, if the filesystem lacks O_DIRECT support.
2013-09-23 20:07:29 +02:00
Howard Chu
912e09fd04 ITS#7681 fix 18a07eb7c2
Set rc=0 when taking the SET_RANGE branch
2013-09-21 14:51:01 -07:00
Howard Chu
0144da6eab ITS#7701 fix mdb_rebalance
Must copy tmp cursor back to real cursor when merging into tmp cursor.
2013-09-21 14:37:11 -07:00
Howard Chu
0f842a2710 Release 0.9.8 2013-09-09 08:29:46 -07:00
Howard Chu
7e58cc0fd3 updates 2013-09-05 16:23:49 -07:00
Salvador Ortiz
cfc13e2b48 ITS#7682 In mdb_env_copy retry open if O_DIRECT fails 2013-09-05 16:20:18 -07:00
Howard Chu
90c55178db More for 5f6fa8c042
Reset delete flag in cursor_put().
2013-09-05 06:02:07 -07:00
Claude Brisson
18a07eb7c2 ITS#7681 fix mdb_cursor_set behaviour for MDB_SET_RANGE 2013-09-05 05:57:03 -07:00
Howard Chu
5f6fa8c042 Remember if last cursor op was a delete
If so, don't advance cursor on next NEXT. Also, init xcursor
on the next GET_CURRENT.
2013-09-03 16:10:20 -07:00
Howard Chu
3d59ca3558 Add a changelog 2013-08-28 20:22:41 -07:00
Howard Chu
5c5300c604 Bump version to 0.9.8 2013-08-28 19:17:25 -07:00
Howard Chu
2e7130cab0 Allow mdb_env_set_mapsize() on an open environment
The caller is responsible for making sure no transactions are
active in this process before resizing. This is slightly lighter
weight than doing a full env_close/env_open cycle.
2013-08-28 19:12:59 -07:00
Howard Chu
2a28686e4f ITS#7672 fix mdb_dbi_flags
Use a txn instead of env argument. Only return persistent flags.
2013-08-27 06:28:30 -07:00
Hallvard Furuseth
4dd10d70a5 mdb_page_unspill(): Fix dirty_room in nested txn 2013-08-25 23:59:58 +02:00
Howard Chu
56c2a8d04a Another take on spill_pgs and deletes 2013-08-24 20:37:45 +01:00
Howard Chu
b917266ca1 Cleanup prev commit 2013-08-24 11:54:05 -07:00
Howard Chu
41bf5c906a Speedup deletion from spill_pgs 2013-08-24 19:51:47 +01:00
Howard Chu
6423c87749 ITS#7671 always return the key for a dup val 2013-08-23 07:36:07 -07:00
Howard Chu
e15a90c762 ITS#7670 Tweak cursor_del0
Always leave cursor pointing at "next" node, if any.
Find next sibling if we're already at end of current page.
2013-08-23 04:55:41 -07:00
Hallvard Furuseth
6616034eb9 mdb_page_spill(): Fix nested txn mt_dirty_room 2013-08-23 13:52:35 +02:00
Hallvard Furuseth
392be3a7c6 Simplify last commits 2013-08-23 13:52:35 +02:00
Howard Chu
45c4ed1805 Tweak prev commit
If somehow "need" is larger than the list size, don't
try to fake out the dirty list.
2013-08-22 21:29:53 -07:00
Howard Chu
7b1db13050 Less aggressive page_spill
spilling all possible pages is a waste because the majority will be
needed again. Just do 1/8th of the dirty list instead.
2013-08-22 18:51:48 -07:00
Howard Chu
c22a7d98ec Update caveats now that mdb_reader_check exists 2013-08-20 17:37:53 -07:00
Howard Chu
214e9ed07d Silence warnings 2013-08-14 09:57:25 -07:00
Hallvard Furuseth
82b27c09c9 Tweak ITS#7615 fix: Obey strict-aliasing rules.
Do not access a long long as an array of longs.
2013-08-14 15:21:59 +02:00
Howard Chu
76f0a02485 ITS#7664 better fix
For RDONLY, don't get lockfile until we know datafile exists.
Also, don't try to create a new datafile for me_mfd if someone
deleted it after we got me_fd.
2013-08-13 13:12:47 -07:00
Howard Chu
a77ffaaa5d Revert "ITS#7664 delete lockfile if there is no environment"
This reverts commit 8725838409.
2013-08-13 13:05:32 -07:00
Howard Chu
8725838409 ITS#7664 delete lockfile if there is no environment 2013-08-13 11:34:32 -07:00
Howard Chu
eaeeecc3b2 Fix uninit'd mem ref in mdb_page_split
Don't compare cursors beyond their depth. (detected by valgrind)
2013-08-12 12:43:42 -07:00
Howard Chu
6ecee1cbf9 Tweak NODUPDATA flag check
Should allow for the possibility of future flag combos.
2013-08-11 17:25:00 -07:00
Howard Chu
5a5d33ff33 Fix obscure MDB_MULTIPLE bug
If a key has a single existing value, and then a put (MDB_MULTIPLE)
is done where the first of the multiple values matches the existing
value, the put would return SUCCESS without writing any of the
values. Fixed to loop to the next value as intended.
2013-08-11 17:15:03 -07:00
Howard Chu
76f8b77e36 Point to mdb.c for docs on macros in Makefile 2013-08-10 16:19:44 -07:00
Hallvard Furuseth
9c49ef1d71 Avoid compiling debug args with C90 compilers.
Use double DPRINTF() parenthesis, so varargs macros are not needed.
Parenthesize MDB_DEBUG, in case the user defines it as foo || bar.
2013-08-10 13:50:10 +02:00
Hallvard Furuseth
76d31573a4 Refuse ops on bad txns 2013-08-10 13:23:30 +02:00
Hallvard Furuseth
9beea541e1 Replace EINVALs with generalized MDB_INCOMPATIBLE.
Also check xcursor instead of DUPSORT, it's slightly briefer.
2013-08-10 13:23:30 +02:00
John Hewson
ef899fe84e ITS#7656 fix install target 2013-08-10 04:13:24 -07:00
Salvador Ortiz
86551828ab ITS#7660 Add mdb_txn_env to API 2013-08-10 04:06:16 -07:00
Hallvard Furuseth
5645812f41 mdb_txn_commit(): Always commit if MDB_TXN_SPILLS.
Checking dirty_list was insufficient after a spill
with no named databases and no positioned cursors.
2013-08-10 12:29:45 +02:00
Salvador Ortiz
92eb220184 ITS#7661 mdb_dbi_flags(): Allow main DBI 2013-08-10 09:42:19 +02:00
Salvador Ortiz
335f0e4cee mdb_del must ignore data if db not opened with MDB_DUPSORT 2013-08-09 09:05:44 -07:00
Howard Chu
1ac3c8308f Add mdb_env_get_maxkeysize() 2013-08-09 04:51:33 -07:00
Hallvard Furuseth
1ecd86b14c Replace unpredictable EINVAL error returns.
Return EINVAL only for simple programmer errors.
2013-08-09 13:05:14 +02:00
Hallvard Furuseth
22c104c5d7 Re-fix reader-pid code 2013-08-09 12:54:42 +02:00
Hallvard Furuseth
38b11b1de1 mdb_cursorpages_mark: Mark current txn and no more.
Ignore parent txn cursors since it is the current txn's dirty_list
which will be flushed. But check the current txn also when clearing,
since cursors can have pages which are dirty in a parent.

Check !mc_xcursor instead of !MDB_DUPSORT.  Equivalent for valid
data, but a bit safer if the sub-DB flags are corrupt.
2013-08-08 19:57:52 +02:00
Hallvard Furuseth
2bd5d8102e Fix mdb_ovpage_free() vs. spill.
Ensure me_pghead has room before removing from spill/dirty list.
Don't return pages to me_pghead in nested txns, use mt_free_pgs.
2013-08-08 19:57:52 +02:00
Hallvard Furuseth
c3547e81f3 Fix page spilling when MDB_WRITEMAP.
mdb_page_spill(): Don't binary-search the unsorted dirty_list.
mdb_page_flush(): Don't overwrite unprocessed dirty_list items.
2013-08-08 19:57:51 +02:00
Hallvard Furuseth
ee5ba85565 Set MDB_TXN_ERROR when inconsistent txn state 2013-08-08 19:57:51 +02:00
Hallvard Furuseth
ffd2287b55 Factor out MDB_env. 2013-08-08 19:54:54 +02:00
Hallvard Furuseth
d66739f947 MDB_LOCK_VERSION -> MDB_LOCK_FORMAT.
Pid locking needs a different lockfile-version: MDB_env's with and
without pid locking must not coexist, they can sabotage each other.
Store MDB_LOCK_FORMAT = (version | "use locking" flag) instead.
2013-08-08 19:43:04 +02:00
Hallvard Furuseth
1878213092 Fix mdb_reader_pid().
Treat unexpected errors as "don't know".  Invert Pidcheck return
value, so nonzero including error codes = "the process may exist".

On Windows: Catch exited but still existing processes.  Handle
undefined PROCESS_QUERY_LIMITED_INFORMATION.
On Unix: don't trust F_GETLK error to leave the input alone,
the fcntl() doc seems unclear.
2013-08-08 19:43:04 +02:00
Howard Chu
636c2d2a29 Use proper printf format on Windows 2013-08-07 12:42:46 -07:00
Hallvard Furuseth
74ed1757a4 Silence warnings 2013-08-05 10:01:39 +02:00
Hallvard Furuseth
27435aa5ac Tweak comments 2013-08-05 09:55:57 +02:00
Hallvard Furuseth
6214423163 Clarify doc: mdb_copy, nested txns, mdb_drop().
mdb_copy: Does not copy lockfile. Can trigger file growth.
mdb_txn_begin(): Clarify usage restrictions.
mdb_drop(): State what to do rather than what will be done, since
closing the handle could otherwise be read as happening even at failure.
2013-08-05 09:55:48 +02:00
Howard Chu
2cc2574d84 Tweak prev commit again
Make sure errors are propagated from init_meta
2013-07-31 08:09:40 -07:00
Howard Chu
bc03467040 Fix typo in Win32 branch 2013-07-30 13:44:28 -07:00
Howard Chu
254b77e63d Cleanup prev commit
Loop on copyfd meta write, since pipes may return after partial write.
2013-07-30 12:47:12 -07:00
Howard Chu
eff35fcb2a ITS#7652 fix I/O error checks
partial revert of d6d2638acc and
26a25df5fc

The original code was already tested and working correctly.
2013-07-30 10:22:12 -07:00
Howard Chu
acf20f77f3 Tweak mdb_envinfo numreaders
Return the actual shared reader count when it exists, not
just the current process env's reader count.
2013-07-28 17:02:51 -07:00
Howard Chu
e8ba9dbd28 ITS#7615 use shorter names for semaphores
NetBSD can only handle up to 14 chars, we were using 21. Now
we encode to 15, and for NetBSD truncate the last char.
2013-07-26 10:19:54 -07:00
Howard Chu
de72c08660 Tweak reader_pid check
Check again after acquiring rmutex. Avoids potential issue with
a duplicate pid coming in between initial check and rmutex.
2013-07-19 09:57:33 -07:00
Howard Chu
b1dc72b6b5 Get pid lock outside of rmutex
Avoid holding rmutex for longer than necessary.
2013-07-19 09:55:10 -07:00
Howard Chu
5ca73f864f Tweak reader checks
Use mti_numreaders for loop limit, not me_maxreaders.
2013-07-18 15:24:09 -07:00
Howard Chu
a4bbe57f8b Add mdb_reader_check() 2013-07-18 10:47:29 -07:00
Howard Chu
4d7c9e5bca Split MDB_VERSION to MDB_DATA/MDB_LOCK VERSION 2013-07-18 09:11:09 -07:00
Howard Chu
68a0adc59f Tweak reader_list 2013-07-18 09:00:51 -07:00
Howard Chu
360d0492db Tweak mdb_stat(1)
Don't obtain reader txn before displaying reader table. Exit
after reader table if no other DB query options were given.
2013-07-18 08:33:24 -07:00
Howard Chu
49289f0d2e Add mdb_reader_list()
Dump the active slots in the reader table.
2013-07-18 07:45:12 -07:00
Howard Chu
fc137e39a3 Add mdb_dbi_flags()
Retrieve the flags from a DB handle.
2013-07-15 10:57:13 -07:00
Howard Chu
501eac2fc4 Fix child txn dirty_room counts in spill/unspill
Don't count pages twice if they're already accounted in an ancestor txn.
2013-07-14 16:53:04 -07:00
Howard Chu
2c3488aeeb More for stale sub-cursor flags
Same fix for cursor_first/last.
2013-07-14 08:28:26 -07:00
Howard Chu
56a41d87d4 Fix stale sub-cursor C_INIT flag
Whenever we enter cursor_set() the sub-cursor's flag must be
cleared. If the new cursor position has valid subdata it will
be initialized again, if not then the sub-cursor has nothing
to point to.
2013-07-14 08:20:18 -07:00
Howard Chu
8ae56c34d5 Tweak comments, defaults should be OK already 2013-07-12 13:55:18 -07:00
Howard Chu
fa7228962b Bump version to 0.9.7 2013-07-12 13:36:05 -07:00
Hallvard Furuseth
f04dc0ebd2 Also set/clear P_KEEP in parent txn's cursors 2013-07-12 13:17:04 -07:00
Howard Chu
e9ed4d75f7 Spill pages, take 3 2013-07-12 13:17:04 -07:00
Howard Chu
d7bc4baf63 Delay touching pages until cursor is positioned.
This avoids unnecessary rewrites of pages that do not change.
(Restructuring for upcoming mdb_page_spill work.)
2013-07-12 13:17:04 -07:00
Hallvard Furuseth
c09db5757d Simplify: Always set C_UNTRACK for tracked cursors.
TODO: Rename C_UNTRACK to C_TRACKED.  Omitted now for readability.
The current name is because it's lazy: not always set when tracked.
2013-07-12 13:17:04 -07:00
Hallvard Furuseth
6741f9c0ef Save freelist using proper mdb_cursor_put().
(Restructuring for upcoming mdb_page_spill work.)
mdb_freelist_save() can't just Get() the destination, since
mdb_page_spill() may have put the destination in the read-only map.

TODO: Can this new put() modify the freelist, which would break it? The
final iteration's put() can shorten the node, the rest uses MDB_CURRENT.

We could set P_KEEP on dirty freeDB leaves and ovpages, since they are
all about to be modified.  But the code in this commit must stay anyway,
if mdb should support dropping a 256G DB. I.e. too big for dirty_list.
2013-07-12 13:17:04 -07:00
Howard Chu
08373439a6 Move code out to mdb_page_dirty() 2013-07-12 13:17:04 -07:00
Howard Chu
87a7f06feb Factor out parent 2013-07-12 13:17:04 -07:00
Howard Chu
ba6dfe0bbb Fix env_read_header() on Windows
Commit d6d2638acc broke read
on zero-length files.
2013-07-12 12:55:08 -07:00
Hallvard Furuseth
3d46d5502a Do not follow uninited cursors' page pointers.
Nor uninited cursors' subcursors' page pointers.
2013-07-10 22:11:44 +02:00
Howard Chu
b711c07f34 Fix rebalance/cursor adjust
When collapsing root, must also move cursor index down,
not just the page pointer.

Also in mtest, break from NEXT loops on error, otherwise it just
prints the previous key/data again, which looks confusing.
2013-07-10 11:04:37 -07:00
Howard Chu
f81eb631ff Cursors: Clear C_EOF when clearing C_INITIALIZED 2013-07-10 08:49:29 -07:00
Howard Chu
64676da8d9 Fixup other cursors after delete op 2013-07-09 14:21:35 -07:00
Hallvard Furuseth
a77767013a ITS#7515 Reject conflicting page versions.
If mdb_page_touch() sees a page in txn's dirty_list, that
is the page version txn's cursors should have.  Fail if
the user may be seeing and depending on another version.
2013-07-07 17:14:38 +02:00
Hallvard Furuseth
be47ca7667 ITS#7515 Fix tracking of parent txn's cursors.
Restore mc_flags and xcursors, they were tracked but not merged.
Simplify: Track parent txn's original cursors after backing them
up, instead of tracking copies and merging them back at commit.
2013-07-07 17:13:27 +02:00
Hallvard Furuseth
9be6af0dcb Simplify MDB_cursor: Drop flags C_ALLOCD,C_SHADOW. 2013-07-07 17:13:27 +02:00
Hallvard Furuseth
3d1e709504 Silence more uninit warnings 2013-07-06 21:42:45 +02:00
Howard Chu
06a3ad08cd Silence uninit warning in prev commit 2013-07-02 02:23:49 -07:00
Howard Chu
589370d880 Tweaks for MDB_MULTIPLE
Terminate loop on intermediate failures, return count of written items,
document usage.
2013-07-02 02:19:17 -07:00
Howard Chu
fb674c1cf5 ITS#7635 simplify 9474c1a0b6 2013-07-01 14:53:29 -07:00
Howard Chu
9474c1a0b6 ITS#7635 fix read txn potential data race 2013-07-01 13:41:23 -07:00
Howard Chu
3347a02905 Fix uninit warnings, lseek usage 2013-06-30 07:40:02 -07:00
Hallvard Furuseth
7f67383552 Fix alloc/free issues.
Page leak, mdb_page_alloc(). On error, don't shorten me_pghead.
Memleak, mdb_ovpage_free(). Free page or keep it in dirty_list.
Bad MIDL, mdb_midl_need(). Fix midl[-1] (allocated size).
2013-06-26 18:02:52 +02:00
Hallvard Furuseth
12c558fe13 Factor out some vars, simplify. 2013-06-26 18:02:48 +02:00
Hallvard Furuseth
b7ce06f5c5 Makefile/user-macro comments. 2013-06-26 18:02:26 +02:00
Hallvard Furuseth
26a25df5fc Tweak I/O, fix last commit. 2013-06-26 18:02:17 +02:00
Hallvard Furuseth
d6d2638acc Improve MDB error handling, drop seek calls.
Catch I/O errors. Do nothing between OS call failure and ErrCode().
Do not use errno after non-OS-errors like write() >= 0, which could
give a failure return of success (errno 0) or some irrelevant error
code.  Drop seek calls, use pwrite/pread/Windows OVERLAPPED offset.
2013-06-22 23:15:10 +02:00
Hallvard Furuseth
a5701cf2fe Fix Windows I/O.
Don't put a 64-bit filesize in a 32-bit int before shifting
down.  Always pass &sizehi to SetFilePointer->maxsize, so
sizelo not is treated a signed distance.  Hide unused vars
when _WIN32.  Reinitialize OVERLAPPED before reuse.
2013-06-22 23:01:30 +02:00
Hallvard Furuseth
3d4ba01e8b Catch more MDB errors. DPRINTF in mdb_env_reset0. 2013-06-22 22:17:41 +02:00
Hallvard Furuseth
51ff20a4d6 Tweak MIDLs, catch errors.
Grow midls earlier in order to catch errors earlier.  Use
mdb_midl_need() instead of mdb_midl_grow(), then mdb_midl_xappend()
needs no error checks. Factor out mdb_midl_append_range().
2013-06-22 22:10:43 +02:00
Hallvard Furuseth
6b200e3beb Factor out MDB variables/expressions, cleanup.
mdb_page_malloc(): Take a txn arg instead of a cursor.
2013-06-22 12:30:04 +02:00
Hallvard Furuseth
9e6ef6c88f Rearrange MDB dirty page code.
Split out mdb_dpage_free(), mdb_page_flush() and clean up.
2013-06-22 11:56:04 +02:00
Hallvard Furuseth
c6f9323b3d Simplify mdb_page_alloc().
Merge if() branches. Restore retry=500 when MDB_PARANOID, for clarity.
2013-06-20 07:41:35 +02:00
Hallvard Furuseth
4a9ee2cb72 ITS#7620: Keep empty IDLs. Tweak mdb_page_alloc().
MDB_env.me_pghead: Don't free it when empty. mdb_ovpage_free()
needs it, but cannot allocate it.
mdb_midl_alloc(): Fill in length=0.
mdb_page_alloc(): Also Skip freeDB if txnid<3, instead of <4,
and consistently DPRINTF consumed IDLs.
2013-06-20 07:41:35 +02:00
Howard Chu
1d94ea5b55 ITS#7623 Clear P_SUBP on conversion from fake page 2013-06-17 22:26:11 +02:00
Hallvard Furuseth
60086c1bc7 ITS#7515 Nested MDB txns: Inherit txn flags.
Committing a nested txn lost the MDB_TXN_DIRTY flag
in the parent, unless the child had set it too.
2013-06-13 08:58:25 +02:00
Hallvard Furuseth
7030ad16e2 Clean up mdb_page_touch(), mdb_page_copy().
When copying, round up/down to aligned sizes. Skip the unused portion,
this was not done when touching a page dirty in the parent txn.
No other change in behavior.

Simplify mdb_page_touch(), including: Drop test m3==mc, the condition
is caught below. Don't "modify" the parent's pgno into the same pgno,
when a nested txn copies a parent's page into its freelist.
2013-06-13 08:58:24 +02:00
Hallvard Furuseth
79844bd446 ITS#7594 Fix MDB cursor tracking with subDBs.
The tracking code should not change the current cursor.
It did when that was a C_SUB cursor, which should not be
checked against the tracked cursors but their xcursors.

However, do not bother to skip the tracking code for the
current cursor when it would not change that cursor anyway.
2013-06-13 08:58:24 +02:00
Hallvard Furuseth
2bacf6e59e ITS#7594 Invalidate a dropped MDB DB's cursors. 2013-06-13 08:58:24 +02:00
Hallvard Furuseth
62e4c4f9d0 Don't #define _GNU_SOURCE if already defined. 2013-06-13 08:58:24 +02:00
Hallvard Furuseth
c37a11a424 More for ITS#7620 Fix mdb_ovpage_free().
Do not binary-search dirty_list, it is unsorted when MDB_WRITEMAP.
Catch errors. In nested txns, put the page in mt_free_pgs after
all since pages dirty in a parent txn would add complexities.
2013-06-13 08:25:25 +02:00
Howard Chu
2d0b362b6f Partial revert c2cac4588a
MDB_NEXT was fine before, duh.
2013-06-12 08:41:32 -07:00
Hallvard Furuseth
99427aa7de Drop me_pgfree, add mdb_freelist_save().
Split up saving me_pghead, to make me_pgfree unneeded. Also mf_pghead
is now a midl. Needed after e7f6767ea8
("Return fresh overflow pages to current pghead").
Tweak MDB_DEBUG freelist output, make it ascending.
2013-06-12 17:20:42 +02:00
Howard Chu
c2cac4588a Fix CURSOR_NEXT/PREV on emptied DB 2013-06-11 17:13:08 -07:00
Howard Chu
bcb67dd22f Make sure mdb_stat() gets valid data 2013-06-08 14:10:08 -07:00
Howard Chu
e7f6767ea8 Return fresh overflow pages to current pghead
And remove them from the current dirty list.
2013-06-06 16:44:02 -07:00
Howard Chu
aff123ba11 ITS#7594 more for subDB cursor fix 2013-06-05 16:13:43 -07:00
Howard Chu
3b623d66e1 ITS#7594 better fix
Update the subDB cursor, don't invalidate it
2013-06-05 15:23:54 -07:00
Howard Chu
65faa5ed7e tweak mdb_copy, trap signals 2013-05-30 15:56:30 -07:00
Howard Chu
d29b9600e6 Windows portability fixes for prev commit 2013-05-30 15:33:59 -07:00
Howard Chu
f207c50b15 Add warning about interrupting copy 2013-05-30 13:13:33 -07:00
Howard Chu
ad573fe125 Fix prev commit 2013-05-30 13:09:28 -07:00
Howard Chu
c68e5ae9be Add mdb_env_copyfd()
Allow writing backup to an already opened file handle, for piping
to tar/gzip/ssh/whatever.
2013-05-30 13:06:12 -07:00
Howard Chu
4b49291653 Add _M_IX86 macro for MSVC 2013-05-25 10:16:55 -07:00
Howard Chu
e31c7d3b31 ITS#7594 De-init other subcursors in page_touch 2013-05-23 12:17:21 -07:00
Hallvard Furuseth
92fe958805 Drop unused liblmdb MIDL-range support. 2013-05-21 23:58:57 +02:00
Hallvard Furuseth
feaeab0c04 Factor out mdb_find_oldest,mdb_dlist_free,dirty_list.
Do not rescan reader table (mdb_find_oldest) after "goto again".
Skip clearing dirty_list[nonzero].mid in mdb_dlist_free(); it
was not done in mdb_reset0() anyway.
2013-05-21 23:55:13 +02:00
Hallvard Furuseth
5ea1cd8f6d mdb_stat cleanup.
Exit with success when there was no failure.
Do not use data containing NUL as a DB name (which is a C string).
2013-05-21 23:48:27 +02:00
Hallvard Furuseth
a1b16ce5f0 ITS#7598 Tweak MDB_<NEXT/PREV>_NODUP,fix mdb_stat.
MDB_NEXT_NODUP, MDB_PREV_NODUP: Allow for non-MDB_DUPSORT databases.
No mdb.c code changes needed.

mdb_stat.c: Use MDB_NEXT_NODUP, to avoid a crash with a DUPSORT mainDB.
2013-05-21 22:44:51 +02:00
Hallvard Furuseth
1b6d7ee7e1 ITS#7598 mdb_dbi_open(named DB): Check mainDB flags.
Reject attempts to open named databases if the main
database has flag MDB_DUPSORT or MDB_INTEGERKEY.

DUPSORT would require an xcursor for the DB, INTEGERKEY
would expect the DB name to be a binary integer.
2013-05-21 19:04:52 +02:00
Hallvard Furuseth
a2ce25482a ITS#7515 Fix nested txn touch of subpage/ovpage.
mdb_page_touch(): Don't touch a subpage, replacing with non-subpage.
mdb_cursor_put(): Don't overwrite ancestor txn's dirty overflow page.
2013-05-20 23:12:52 +02:00
Hallvard Furuseth
5bdf2aae6e Tweak mdb_page_malloc(),mdb_page_get() semantics.
mdb_page_malloc(): Add "number of pages" parameter.
mdb_page_get(): Add output param for how page was found.
Do not set return params on error.
mdb_cursor_put(): Catch mdb_page_get() error.

Prepares for next commit, no change in caller behavior other
than on mdb_page_get error.
2013-05-20 23:12:26 +02:00
Hallvard Furuseth
2eb50b1d2e More ITS#7589 followup: OVPAGES() -> mp_pages. 2013-05-19 19:08:07 +02:00
Hallvard Furuseth
e4ce404992 More ITS#7589: Fix prev commit.
mp_pages gives #pages in the ovpage. OVPAGES() no longer does.
2013-05-19 18:38:13 +02:00
Hallvard Furuseth
0cdd9dffdd ITS#7589 mdb_cursor_put(): Update ovpage nodesize.
Update the nodesize when overwriting an overflow page.
As before, do not attempt to shrink the page.
2013-05-17 19:31:17 +02:00
Howard Chu
833cd905b7 Include <netinet/in.h> for Solaris 8
Needed for <resolv.h>, which is needed for BYTE_ORDER.
2013-05-15 11:50:40 -07:00
Howard Chu
7233bc295b Fix mdb_page_split - nested split
If updating a page's separator triggers a split in its parent,
we may have missed adjusting the parent's cursor position.
2013-05-14 16:57:50 -07:00
Howard Chu
1105aa35ba Doxygen cleanup 2013-05-13 12:36:47 -07:00
Howard Chu
9ebd5992c9 Fix 66c839f029
Forgot #include <errno.h>
2013-05-10 05:56:16 -07:00
Howard Chu
66c839f029 Refactor mdb_midl_append, add mdb_midl_grow() 2013-05-09 17:27:29 -07:00
Hallvard Furuseth
2d6aed7537 ITS#7515 Fix nested transaction error handling.
mdb_txn_begin(): Do not free(mt_free_pgs), it needs mdb_midl_free().
mdb_txn_commit(): Catch commit(child) error.
2013-05-05 15:13:31 +02:00
Hallvard Furuseth
521fdb00cc Fix mdb_env_close(unopened MDB_env).
Do not try to scan me_dbxs in a closed/never-opened MDB_env.
Broken by 7d643d3acb
and 151c416b46.
2013-05-05 14:26:05 +02:00
Hallvard Furuseth
0b9a208530 Simplify/cleanup mdb_cursor_init, C_ALLOCD.
No real change.
mdb_cursor_init() checks if it needs mx, so pass it unconditionally.
Set C_ALLOCD for shadow cursors, for clarity. (It was always set as
it should anyway from the origin cursor, which would have C_ALLOCD.)
2013-05-04 12:53:43 +02:00
Hallvard Furuseth
f355de0298 MDB warning cleanup.
Unused function when MDB_DEBUG. Unused 'excl' param.
2013-05-04 12:41:28 +02:00
Hallvard Furuseth
b389341b4b mdb_dcmp(): Assume the database has MDB_DUPSORT.
There was little point in returning EINVAL when not: Comparing (A,B)
and (B,A) would claim (A > B && B > A), which could confuse callers.
2013-05-04 12:34:49 +02:00
Hallvard Furuseth
91a93004ce Update MDB doc: Cursors, DB handles, data lifetime 2013-05-04 12:34:20 +02:00
Hallvard Furuseth
385889b0be Allow mdb_cursor_close() after readonly txn ends.
Catch mdb_cursor_renew(write txn's cursor).  Add flag C_UNTRACK, so
mdb_cursor_close need not peek inside a possibly-freed readonly txn.
2013-05-04 12:34:02 +02:00
Hallvard Furuseth
17ffe9c992 Close cursors when commit(writer). Factor out code.
Close remaining cursors when committing a write txn. The doc says this
happens, and it avoids cursor tracking when updating mainDB + freeDB.

Rename mdb_cursor_merge() -> mdb_cursors_close() for code reuse,
and add a merge option.  Simplify its loop a bit.

Factor out cleanup of DBIs.
2013-05-04 12:33:06 +02:00
Hallvard Furuseth
dca0cef678 Plug txn leak and MDB_NOTLS slot leaks on error.
On mdb_env_copy() error: Abort the txn.
On mdb_txn_renew0() error: Release new MDB_NOTLS reader slot.
2013-05-04 12:31:31 +02:00
Hallvard Furuseth
f45d40a88b Cleaner "Support mdb_txn_abort(a reset txn)".
Redo 8a562f560e so !mt_dbxs indicates
"txn was reset", so mt_numdbs gets one magic value instead of two.
2013-05-04 10:03:19 +02:00
Hallvard Furuseth
151c416b46 Update fixes for dbi_open/close, ITS#7515.
Reset me_dbflags[dbi] when closing DBI, to get rid of MDB_VALID flag.
mdb_env_close(): Re-fix DB-name memleak. DBIs > me_numdbs may exist.
2013-05-04 10:03:19 +02:00
Howard Chu
21da623bf4 Allow reading freelist while working on it
The circular dependency issues appear to have been resolved.
Still, need to watch closely, maybe revert this change if
problems arise.
2013-05-01 22:45:15 -07:00
Howard Chu
568c22c4cc Avoid assert
Due to underfilled branch page. We're in the process of merging/moving
nodes to it because we already know it's underfilled. Took this approach
rather than just removing the assert in mdb_page_search_root, because
that assert may yet catch other situations we don't know about.

(Although, it has been there since the original commit of mdb.c and
has never triggered any other times...)
2013-04-30 21:09:09 -07:00
Hallvard Furuseth
37bd48a618 Plug mdb_cursor_renew() memleak 2013-04-30 21:06:36 -07:00
Howard Chu
c057582573 Fix MDB_LAST, reset cursor index 2013-04-20 19:30:06 -07:00
Howard Chu
da3e4d78d6 Fix typo from 7aba5f5ab9 2013-04-20 09:47:33 -07:00
Hallvard Furuseth
9dd61011fe Tweak comments/readability.
Show MDB_PERSISTENT/MDB_VALID/DB_VALID relationship.
mdb_txn_renew0(): Remove obsolete "cannot fail" comment.
2013-04-18 08:00:03 +02:00
Howard Chu
272e4e98ad Add MDB_NOTLS envflag. 2013-04-18 04:17:03 +02:00
Hallvard Furuseth
afe488d8a9 Catch MDB txn reuse/sync errors. 2013-04-18 04:16:07 +02:00
Hallvard Furuseth
8a562f560e Support mdb_txn_abort(a reset txn). 2013-04-18 04:15:45 +02:00
Hallvard Furuseth
ce6335b0d9 Cleanup for TLS key and read-only filesystem.
Move key init into mdb_env_setup_locks().
Don't create unused TLS key when read-only filesystem.
Drop internal flag MDB_ROFS, we can instead test either
!me_txns, !mt_u.reader or me_lfd==INVALID_HANDLE_VALUE.
2013-04-18 04:15:13 +02:00
Hallvard Furuseth
65a6542765 Clean up MDB_env setup.
Malloc before I/O. Avoids possible malloc error after I/O.
Don't allocate dirty & free lists when MDB_RDONLY.
Factor out code.
2013-04-18 04:13:43 +02:00
Howard Chu
dbb9ded2f8 Fix mdb_rebalance
Don't do anything with (fake root) subpages
2013-04-17 14:33:41 -07:00
Howard Chu
aca6c08897 ITS#7574 blind fix
Fix 227329c8e1, don't persist
the MDB_VALID bit in db.md_flags.
2013-04-16 12:05:03 -07:00
Howard Chu
92fc932f21 fix prev commit 2013-04-15 09:30:39 -07:00
Howard Chu
0cccf79a02 Fix mdb_rebalance
Need to check NUMKEYS as well as fill threshold, when deciding
whether to change anything. Don't let the page drop below the
minimum number of keys.
2013-04-14 23:59:54 -07:00
Howard Chu
14c5a5dff1 Revert "ITS#7570 fix MDB_GET_MULTIPLE and MDB_NEXT_MULTIPLE"
This reverts commit 372b3ddb85.

Original code works as designed.
2013-04-14 16:53:30 -07:00
Claude Brisson
372b3ddb85 ITS#7570 fix MDB_GET_MULTIPLE and MDB_NEXT_MULTIPLE 2013-04-11 15:10:23 -07:00
Howard Chu
fbe6a6051b Fix 227329c8e1
mdb_dbi_close() must allow any dbi < maxdbs, since opens in an
uncommitted txn don't increment env->me_numdbs.
2013-04-07 19:21:46 -07:00
Howard Chu
e43fa77eaa Revert "Fix 6beaad52129da5353fd40c0ec48e6a78c4f71a2e"
This reverts commit 8eef7a4275.
Previous commit was correct, duplicate keys should not appear here.
2013-04-05 03:44:56 -07:00
Howard Chu
227329c8e1 Fixes for dbi_open/close, ITS#7515 2013-04-05 02:58:08 -07:00
Howard Chu
6b46799379 ITS#7561 Fix mdb_drop bugs
Check for overflow pages, reset cursor position properly.
2013-04-04 16:52:55 -07:00
Howard Chu
8eef7a4275 Fix 6beaad5212
In APPEND don't immediately reject matching key, since this
is valid for APPENDDUP.
2013-04-04 07:25:21 -07:00