-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new storage interface, IExternalGC, to support external garbage
collection, http://wiki.zope.org/ZODB/ExternalGC, has been defined and implemented for FileStorage.
- Loading branch information
Jim Fulton
committed
Dec 18, 2008
1 parent
ecdb05b
commit d2d83b8
Showing
6 changed files
with
201 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
Storage Support for external GC | ||
=============================== | ||
|
||
A storage that provides IExternalGC supports external garbage | ||
collectors by providing a deleteObject method that transactionally | ||
deletes an object. | ||
|
||
A create_storage function is provided that creates a storage. | ||
|
||
>>> storage = create_storage() | ||
>>> import ZODB.blob, transaction | ||
>>> db = ZODB.DB(storage) | ||
>>> conn = db.open() | ||
>>> conn.root()[0] = conn.root().__class__() | ||
>>> conn.root()[1] = ZODB.blob.Blob('some data') | ||
>>> transaction.commit() | ||
>>> oid0 = conn.root()[0]._p_oid | ||
>>> oid1 = conn.root()[1]._p_oid | ||
>>> del conn.root()[0] | ||
>>> del conn.root()[1] | ||
>>> transaction.commit() | ||
|
||
At this point, object 0 and 1 is garbage, but it's still in the storage: | ||
|
||
>>> p0, s0 = storage.load(oid0, '') | ||
>>> p1, s1 = storage.load(oid1, '') | ||
|
||
Now we'll use the new deleteObject API to delete the objects. We can't | ||
go through the database to do this, so we'll have to manage the | ||
transaction ourselves. | ||
|
||
>>> txn = transaction.begin() | ||
>>> storage.tpc_begin(txn) | ||
>>> tid = storage.deleteObject(oid0, s0, txn) | ||
>>> tid = storage.deleteObject(oid1, s1, txn) | ||
>>> storage.tpc_vote(txn) | ||
>>> storage.tpc_finish(txn) | ||
|
||
Now if we try to load data for the objects, we get a POSKeyError: | ||
|
||
|
||
>>> storage.load(oid0, '') # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
>>> storage.load(oid1, '') # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
We can still get the data if we load before the time we deleted. | ||
|
||
>>> storage.loadBefore(oid0, conn.root()._p_serial) == (p0, s0, tid) | ||
True | ||
>>> storage.loadBefore(oid1, conn.root()._p_serial) == (p1, s1, tid) | ||
True | ||
>>> open(storage.loadBlob(oid1, s1)).read() | ||
'some data' | ||
|
||
If we pack, however, the old data will be removed and the data will be | ||
gone: | ||
|
||
>>> import time | ||
>>> db.pack(time.time()+1) | ||
|
||
>>> storage.load(oid0, '') # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
>>> storage.load(oid1, '') # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
>>> storage.loadBefore(oid0, conn.root()._p_serial) # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
>>> storage.loadBefore(oid1, conn.root()._p_serial) # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
>>> storage.loadBlob(oid1, s1) # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
POSKeyError: ... | ||
|
||
A conflict error is raised if the serial we provide to deleteObject | ||
isn't current: | ||
|
||
>>> conn.root()[0] = conn.root().__class__() | ||
>>> transaction.commit() | ||
>>> oid = conn.root()[0]._p_oid | ||
>>> bad_serial = conn.root()[0]._p_serial | ||
>>> conn.root()[0].x = 1 | ||
>>> transaction.commit() | ||
|
||
>>> txn = transaction.begin() | ||
>>> storage.tpc_begin(txn) | ||
>>> storage.deleteObject(oid, bad_serial, txn) # doctest: +ELLIPSIS | ||
Traceback (most recent call last): | ||
... | ||
ConflictError: database conflict error ... | ||
|
||
>>> storage.tpc_abort(txn) | ||
|
||
>>> storage.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters