Repository navigation
No format change: caches made by 0.3.5 and later open as they are. One behavior change, for a child process forked at the wrong moment, and fixes from the same review as 0.4.7 that touch the engine's core.
Changed
- A child forked inside a transaction, or from inside a cache call that has its connection out, can't use that cache at all. Every call on it in that child raises the new
ForkedInsideTransactionError, aRuntimeError, at once, reads included, for the life of the process, on adurable=Truehandle too;close()still works, other caches are unaffected, and on aFanoutCacheonly the shard involved is refused. Before, a child forked insidewith cache.transact():could still read, and one forked from a pickle hook or adecodefunction reading a small value inside a call could read and write. Both were unsafe: such a child holds none of the file locks SQLite believes it holds, so once the parent closed, its reads went stale and itssetcalls returnedTrueand were lost, with no error and nothing forcheck()to find. Fork before or after the block, or start workers withspawnorforkserver(D-020; see Concurrency and forks). The child logs one warning on thediskcache_oxidelogger naming the directories. - A
Cacheslookup and adurable=TrueDjango alias raiseForkedInsideTransactionErrorin such a child, where any other failed open hands out aNullCacheand retries. No retry can help that child, and a silentNullCachewould hide a fork in the wrong place for the life of the worker. incranddecrraiseValueErrorfor adeltaordefaultthat is an infinity or a NaN (D-064). A counter that reached NaN was stored with no value, sogetraisedCorruptValueErrorand the nextincrraisedTypeError. A counter left that way by an earlier version stays unreadable until it's overwritten or deleted.- The error
this database can't be written in a process forked inside a transactionis gone: that child now gets the error above for every call.
Fixed
- Another library's before-fork hook that used a cache (one registered before
diskcache_oxidewas imported, so it runs after ours) left its connection open across the fork, and the child then lost its writes once the parent closed. A connection given back between the fork hooks is closed now, and that child works. - A child forked while another thread was leaving the forking thread's transaction (
__exit__called from a second thread) kept a lock level nothing could release:os.fork()from another thread of that child hung, and leaving the block there waited out the timeout. It raisesRuntimeErrorat once now, and later forks go ahead. - One row with a damaged
filenameorsizecolumn (the wrong SQLite type, as a bad page or an edit by hand leaves it) made everyget,delete,clear()andcheck(fix=True)that reached it raiseOSError: Invalid column type, and once it was the oldest row, everysetthat had to evict. A row with a damagedfilename, or a damagedsizeon a value stored in a file, reads as a miss and is removed like any other, andcheck()reports a row with a wrong-typedmode,size,store_seq,expire_timeorfilename(damaged row N: its COLUMN is stored as TYPE), whichfix=Trueremoves. - One row with a damaged
store_seqcolumn decided every later sequence number. Text or a BLOB there gave each later write on any key the same number, soclear()could return 0 and leave entries behind, andpopand the queue calls lost their exactly-once footing; a large REAL made everyset,expire(),cull()andclear()raise. The next number is worked out from the sound ones only now, so such a row affects only the calls that reach it (by its key, or as the head of a queue) untilcheck(fix=True)removes it.check()also reports astore_seqof 2^62 - 1 or more as damaged. - A damaged next sequence number in the cache's one
staterow (text, a BLOB, a REAL, or 2^62 or more) wasn't reported bycheck()and wasn't repaired, and with a fractional REAL thereincron a stored number wrote that REAL into the entry's own row, after which reading the entry raised. Every write fails withOSErroron such a cache now,clear(),evict,expire()andcull()still run, andcheck()reports it (damaged cache state: its COLUMN is stored as TYPE);check(fix=True)sets the number past every entry's. Deleting an entry whose own number was the last one below 2^62 left the cache unwritable with nothing to repair it;check()reports that entry as damaged andfix=Truerepairs both. check()raisedOSErrorinstead of reporting when a stored total (countorsizeinstate) was of another type, or when an entry'ssizewas an integer large enough to overflow the sum, and removing an entry with a hugely negativesizeturned the stored total into a REAL that every latervolume(),setandcheck()raised on. Asizebelow 0 or above 2^48 is a damaged column now: it counts as 0,check()reports it, andfix=Trueremoves the entry and recounts the totals.check()also missed an entry whose stored file name was the empty string, and entries sharing one file name beyond the first 512.- In a child that can't use a cache after a fork (see Changed), several calls didn't say so. Opening a
FanoutCachethere withsize_limit,cull_limitoreviction_policywrote those settings to the shards ahead of the one it couldn't use, for every process, and then raised; no shard is touched now. A call on a handle the child had closed reopened it, with a new connection on the file, before raising.Cache.evict(None)returned 0, andremove_old_formats()ran. Leaving the inheritedwith cache.transact():block raisedTransactionAborted, or returned quietly on an exception, when another thread had rolled the transaction back just before the fork. And in another library'safter_in_childhook registered beforediskcache_oxidewas imported,stats()answered, leaving the block could wait out the timeout, andFanoutCache.clear()could empty some shards before raising. All of these raiseForkedInsideTransactionErrorat once now, and change nothing. - A
Cachesregistry or adurable=TrueDjango alias that had failed to open a cache in the parent kept serving thatNullCachein a forked child for the rest of the parent's retry window (up to 10 seconds). A child starts without its parent's failed opens now: it opens the cache itself, or raisesForkedInsideTransactionErrorif it can't use it. - A pickle hook or a registered type's
decodethat called a cache its process couldn't use after a fork had itsRuntimeErrorread as a value that can't be decoded, so the read deleted the row it was reading from a healthy cache, or answered a miss. The error passes through as itself now and the row stays. check(fix=True)could remove the value file of a transaction held open for over an hour in another process, which then committed an entry with no file. It removes a file no entry names only under the write lock now, so it waits for that transaction (and raisesTimeoutif it outlasts the timeout).- With a
types=registry on a handle, a value of a class registered only in the global registry was stored under the global name and read back through the handle's own registration of that name, as another class.setraisesTypeErrorfor it now. - Background maintenance's checkpoint read "another connection is checkpointing" as "everything is copied" and went on to reset the write-ahead log under the write lock, where the whole copy could then run and hold up writers.
check(fix=True)could wait about twice itstimeout: theVACUUMat its end and the checkpoint after it each got the full time.