Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
8db9c2bc
Commit
8db9c2bc
authored
Sep 05, 2016
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved/added docstrings to support reference documentation on zodb.org
parent
975f715b
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
309 additions
and
56 deletions
+309
-56
src/ZODB/Connection.py
src/ZODB/Connection.py
+6
-2
src/ZODB/DB.py
src/ZODB/DB.py
+143
-47
src/ZODB/DemoStorage.py
src/ZODB/DemoStorage.py
+51
-0
src/ZODB/FileStorage/FileStorage.py
src/ZODB/FileStorage/FileStorage.py
+78
-1
src/ZODB/FileStorage/interfaces.py
src/ZODB/FileStorage/interfaces.py
+14
-5
src/ZODB/MappingStorage.py
src/ZODB/MappingStorage.py
+14
-0
src/ZODB/interfaces.py
src/ZODB/interfaces.py
+3
-1
No files found.
src/ZODB/Connection.py
View file @
8db9c2bc
...
@@ -78,9 +78,13 @@ def className(obj):
...
@@ -78,9 +78,13 @@ def className(obj):
IPersistentDataManager
,
IPersistentDataManager
,
ISynchronizer
)
ISynchronizer
)
class
Connection
(
ExportImport
,
object
):
class
Connection
(
ExportImport
,
object
):
"""Connection to ZODB for loading and storing objects."""
"""Connection to ZODB for loading and storing objects.
Connections manage object state in collaboration with transaction
managers. They're created by calling the
:meth:`~ZODB.DB.open` method on :py:class:`database
<ZODB.DB>` objects.
"""
_code_timestamp
=
0
_code_timestamp
=
0
...
...
src/ZODB/DB.py
View file @
8db9c2bc
This diff is collapsed.
Click to expand it.
src/ZODB/DemoStorage.py
View file @
8db9c2bc
...
@@ -40,10 +40,52 @@ from .utils import load_current, maxtid
...
@@ -40,10 +40,52 @@ from .utils import load_current, maxtid
ZODB
.
interfaces
.
IStorageIteration
,
ZODB
.
interfaces
.
IStorageIteration
,
)
)
class
DemoStorage
(
ConflictResolvingStorage
):
class
DemoStorage
(
ConflictResolvingStorage
):
"""A storage that stores changes against a read-only base database
This storage was originally meant to support distribution of
application demonstrations with populated read-only databases (on
CDROM) and writable in-memory databases.
Demo storages are extemely convenient for testing where setup of a
base database can be shared by many tests.
Demo storages are also handy for staging appplications where a
read-only snapshot of a production database (often accomplished
using a `beforestorage
<https://pypi.python.org/pypi/zc.beforestorage>`_) is combined
with a changes database implemented with a
:class:`~ZODB.FileStorage.FileStorage.FileStorage`.
"""
def
__init__
(
self
,
name
=
None
,
base
=
None
,
changes
=
None
,
def
__init__
(
self
,
name
=
None
,
base
=
None
,
changes
=
None
,
close_base_on_close
=
None
,
close_changes_on_close
=
None
):
close_base_on_close
=
None
,
close_changes_on_close
=
None
):
"""Create a demo storage
:param str name: The storage name used by the
:meth:`~ZODB.interfaces.IStorage.getName` and
:meth:`~ZODB.interfaces.IStorage.sortKey` methods.
:param object base: base storage
:param object changes: changes storage
:param bool close_base_on_close: A Flag indicating whether the base
database should be closed when the demo storage is closed.
:param bool close_changes_on_close: A Flag indicating whether the
changes database should be closed when the demo storage is closed.
If a base database isn't provided, a
:class:`~ZODB.MappingStorage.MappingStorage` will be
constructed and used.
If ``close_base_on_close`` isn't specified, it will be ``True`` if
a base database was provided and ``False`` otherwise.
If a changes database isn't provided, a
:class:`~ZODB.MappingStorage.MappingStorage` will be
constructed and used and blob support will be provided using a
temporary blob directory.
If ``close_changes_on_close`` isn't specified, it will be ``True`` if
a changes database was provided and ``False`` otherwise.
"""
if
close_base_on_close
is
None
:
if
close_base_on_close
is
None
:
if
base
is
None
:
if
base
is
None
:
...
@@ -51,6 +93,8 @@ class DemoStorage(ConflictResolvingStorage):
...
@@ -51,6 +93,8 @@ class DemoStorage(ConflictResolvingStorage):
close_base_on_close
=
False
close_base_on_close
=
False
else
:
else
:
close_base_on_close
=
True
close_base_on_close
=
True
elif
base
is
None
:
base
=
ZODB
.
MappingStorage
.
MappingStorage
()
self
.
base
=
base
self
.
base
=
base
self
.
close_base_on_close
=
close_base_on_close
self
.
close_base_on_close
=
close_base_on_close
...
@@ -285,10 +329,17 @@ class DemoStorage(ConflictResolvingStorage):
...
@@ -285,10 +329,17 @@ class DemoStorage(ConflictResolvingStorage):
raise
raise
def
pop
(
self
):
def
pop
(
self
):
"""Close the changes database and return the base.
"""
self
.
changes
.
close
()
self
.
changes
.
close
()
return
self
.
base
return
self
.
base
def
push
(
self
,
changes
=
None
):
def
push
(
self
,
changes
=
None
):
"""Create a new demo storage using the storage as a base.
The given changes are used as the changes for the returned
storage and ``False`` is passed as ``close_base_on_close``.
"""
return
self
.
__class__
(
base
=
self
,
changes
=
changes
,
return
self
.
__class__
(
base
=
self
,
changes
=
changes
,
close_base_on_close
=
False
)
close_base_on_close
=
False
)
...
...
src/ZODB/FileStorage/FileStorage.py
View file @
8db9c2bc
...
@@ -140,7 +140,8 @@ class FileStorage(
...
@@ -140,7 +140,8 @@ class FileStorage(
ConflictResolvingStorage
,
ConflictResolvingStorage
,
BaseStorage
,
BaseStorage
,
):
):
"""Storage that saves data in a file
"""
# Set True while a pack is in progress; undo is blocked for the duration.
# Set True while a pack is in progress; undo is blocked for the duration.
_pack_is_in_progress
=
False
_pack_is_in_progress
=
False
...
@@ -148,6 +149,82 @@ class FileStorage(
...
@@ -148,6 +149,82 @@ class FileStorage(
def
__init__
(
self
,
file_name
,
create
=
False
,
read_only
=
False
,
stop
=
None
,
def
__init__
(
self
,
file_name
,
create
=
False
,
read_only
=
False
,
stop
=
None
,
quota
=
None
,
pack_gc
=
True
,
pack_keep_old
=
True
,
packer
=
None
,
quota
=
None
,
pack_gc
=
True
,
pack_keep_old
=
True
,
packer
=
None
,
blob_dir
=
None
):
blob_dir
=
None
):
"""Create a file storage
:param str file_name: Path to store data file
:param bool create: Flag indicating whether a file should be
created even if it already exists.
:param bool read_only: Flag indicating whether the file is
read only. Only one process is able to open the file
non-read-only.
:param bytes stop: Time-travel transaction id
When the file is opened, data will be read up to the given
transaction id. Transaction ids correspond to times and
you can compute transaction ids for a given time using
:class:`~ZODB.TimeStamp.TimeStamp`.
:param int quota: File-size quota
:param bool pack_gc: Flag indicating whether garbage
collection should be performed when packing.
:param bool pack_keep_old: flag indicating whether old data
files should be retained after packing as a ``.old`` file.
:param callable packer: An alternative
:interface:`packer <ZODB.FileStorage.interfaces.IFileStoragePacker>`.
:param str blob_dir: A blob-directory path name.
Blobs will be supported if this option is provided.
A file storage stores data in a single file that behaves like
a traditional transaction log. New data records are appended
to the end of the file. Periodically, the file is packed to
free up space. When this is done, current records as of the
pack time or later are copied to a new file, which replaces
the old file.
FileStorages keep in-memory indexes mapping object oids to the
location of their current records in the file. Back pointers to
previous records allow access to non-current records from the
current records.
In addition to the data file, some ancillary files are
created. These can be lost without affecting data
integrity, however losing the index file may cause extremely
slow startup. Each has a name that's a concatenation of the
original file and a suffix. The files are listed below by
suffix:
.index
Snapshot of the in-memory index. This are created on
shutdown, packing, and after rebuilding an index when one
was not found. For large databases, creating a
file-storage object without an index file can take very
long because it's necessary to scan the data file to build
the index.
.lock
A lock file preventing multiple processes from opening a
file storage on non-read-only mode.
.tmp
A file used to store data being committed in the first phase
of 2-phase commit
.index_tmp
A temporary file used when saving the in-memory index to
avoid overwriting an existing index until a new index has
been fully saved.
.pack
A temporary file written while packing containing current
records as of and after the pack time.
.old
The previous database file after a pack.
When the database is packed, current records as of the pack
time and later are written to the ``.pack`` file. At the end
of packing, the ``.old`` file is removed, if it exists, and
the data file is renamed to the ``.old`` file and finally the
``.pack`` file is rewritten to the data file.
"""
if
read_only
:
if
read_only
:
self
.
_is_read_only
=
True
self
.
_is_read_only
=
True
...
...
src/ZODB/FileStorage/interfaces.py
View file @
8db9c2bc
...
@@ -16,18 +16,27 @@ import zope.interface
...
@@ -16,18 +16,27 @@ import zope.interface
class
IFileStoragePacker
(
zope
.
interface
.
Interface
):
class
IFileStoragePacker
(
zope
.
interface
.
Interface
):
def
__call__
(
storage
,
referencesf
,
stop
,
gc
):
def
__call__
(
storage
,
referencesf
,
stop
,
gc
):
"""Pack the file storage into a new file
r"""Pack the file storage into a new file
:param FileStorage storage: The storage object to be packed
:param callable referencesf: A function that extracts object
references from a pickle bytes string. This is usually
``ZODB.serialize.referencesf``.
:param bytes stop: A transaction id representing the time at
which to stop packing.
:param bool gc: A flag indicating whether garbage collection
should be performed.
The new file will have the same name as the old file with
The new file will have the same name as the old file with
'.pack'
appended. (The packer can get the old file name via
``.pack``
appended. (The packer can get the old file name via
storage._file.name.) If blobs are supported, if the storages
storage._file.name.) If blobs are supported, if the storages
blob_dir attribute is not None or empty, then a .removed file
blob_dir attribute is not None or empty, then a .removed file
m
ost be created in the blob directory. This file contain
s of
m
ust be created in the blob directory. This file contains record
s of
the form:
the form:
:
(oid+serial).encode('hex')+'\n'
(oid+serial).encode('hex')+'\n'
or, of the form:
or, of the form:
:
oid.encode('hex')+'\n'
oid.encode('hex')+'\n'
...
...
src/ZODB/MappingStorage.py
View file @
8db9c2bc
...
@@ -32,8 +32,22 @@ import zope.interface
...
@@ -32,8 +32,22 @@ import zope.interface
ZODB
.
interfaces
.
IStorageIteration
,
ZODB
.
interfaces
.
IStorageIteration
,
)
)
class
MappingStorage
(
object
):
class
MappingStorage
(
object
):
"""In-memory storage implementation
Note that this implementation is somewhat naive and inefficient
with regard to locking. It's implementation is primarily meant to
be a simple illustration of storage implementation. It's also
useful for testing and exploration where scalability and efficiency
are unimportant.
"""
def
__init__
(
self
,
name
=
'MappingStorage'
):
def
__init__
(
self
,
name
=
'MappingStorage'
):
"""Create a mapping storage
The name parameter is used by the
:meth:`~ZODB.interfaces.IStorage.getName` and
:meth:`~ZODB.interfaces.IStorage.sortKey` methods.
"""
self
.
__name__
=
name
self
.
__name__
=
name
self
.
_data
=
{}
# {oid->{tid->pickle}}
self
.
_data
=
{}
# {oid->{tid->pickle}}
self
.
_transactions
=
BTrees
.
OOBTree
.
OOBTree
()
# {tid->TransactionRecord}
self
.
_transactions
=
BTrees
.
OOBTree
.
OOBTree
()
# {tid->TransactionRecord}
...
...
src/ZODB/interfaces.py
View file @
8db9c2bc
...
@@ -437,7 +437,6 @@ class IStorage(Interface):
...
@@ -437,7 +437,6 @@ class IStorage(Interface):
"""A storage is responsible for storing and retrieving data of objects.
"""A storage is responsible for storing and retrieving data of objects.
Consistency and locking
Consistency and locking
-----------------------
When transactions are committed, a storage assigns monotonically
When transactions are committed, a storage assigns monotonically
increasing transaction identifiers (tids) to the transactions and
increasing transaction identifiers (tids) to the transactions and
...
@@ -472,6 +471,9 @@ class IStorage(Interface):
...
@@ -472,6 +471,9 @@ class IStorage(Interface):
Finalize the storage, releasing any external resources. The
Finalize the storage, releasing any external resources. The
storage should not be used after this method is called.
storage should not be used after this method is called.
Note that daabses close theor storages when they're closed, so
this method isn't generally called from application code.
"""
"""
def
getName
():
def
getName
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment