Skip to content

Commit

Permalink
Merge pull request #5 from plone/zrs
Browse files Browse the repository at this point in the history
ZRS support
  • Loading branch information
vangheem committed May 30, 2013
2 parents de3011e + d65fc3a commit 6fef4be
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Changelog
1.2.6 (unreleased)
------------------

- Nothing changed yet.
- add support for setting zeoserver as read only
[vangheem]

- Add integration with ZRS
[vangheem]


1.2.5 (2013-05-23)
Expand Down
30 changes: 30 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,33 @@ pack-password
If the ZEO server uses authentication, this is the password used by the
zeopack script to connect to the ZEO server.


ZRS
---

First off, you'll need to specify the recipe to install zc.zrs. To do so,
just slightly change the way the recipe option is specified in your zeoserver
buildout part::

[zeoserver]
recipe = plone.recipe.zeoserver[zrs]
...


replicate-to
url for secondary servers to connect to

replicate-from
url of primary server to replicate from

keep-alive-delay
In some network configurations, TCP connections are broken after extended
periods of inactivity. This may even be done in a way that a client doesn't
detect the disconnection. To prevent this, you can use the keep-alive-delay
option to cause the secondary storage to send periodic no-operation
messages to the server.


Monitoring
----------

Expand Down Expand Up @@ -187,6 +214,9 @@ relative-paths
Set this to `true` to make the generated scripts use relative
paths. You can also enable this in the `[buildout]` section.

read-only
Set zeoserver to run in read-only mode


Usage
-----
Expand Down
8 changes: 6 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[buildout]
develop = .
develop =
.
../zc.zrs

parts = test zeo

[test]
recipe = zc.recipe.testrunner
eggs = plone.recipe.zeoserver
eggs =
plone.recipe.zeoserver[zrs]

[zeo]
recipe = plone.recipe.zeoserver
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
'ZODB3 >= 3.8',
'ZopeUndo',
] + additional_install_requires,
extras_require={
'zrs': ['zc.zrs']
},
zip_safe=False,
entry_points = {
'zc.buildout': ['default = plone.recipe.zeoserver:Recipe'],
Expand Down
38 changes: 36 additions & 2 deletions src/plone/recipe/zeoserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import zc.buildout
import zc.recipe.egg

try:
import zc.zrs
HAS_ZRS = True
except ImportError:
HAS_ZRS = False
join = os.path.join

curdir = os.path.dirname(__file__)
Expand Down Expand Up @@ -221,6 +226,24 @@ def build_zeo_conf(self):
pack_keep_old = pack_keep_old,
)

# ZRS config
rfrom = options.get('replicate-from')
rto = options.get('replicate-to')
if HAS_ZRS and (rfrom or rto):
replicate = ''
if rfrom:
replicate += "\nreplicate-from %s" % rfrom
if rto:
replicate += "\nreplicate-to %s" % rto
keep_alive = options.get('keep-alive-delay', '60')
storage = zrs_template % dict(
storage=storage,
keep_alive=keep_alive,
replicate=replicate,
storage_number=storage_number
)

read_only = options.get('read-only', 'false')
zeo_conf = zeo_conf_template % dict(
instance_home = instance_home,
effective_user = effective_user,
Expand All @@ -235,6 +258,7 @@ def build_zeo_conf(self):
zeo_conf_additional = zeo_conf_additional,
monitor_address = monitor_address,
zeo_log_level = zeo_log_level,
read_only = read_only
)

zeo_conf_path = os.path.join(location, 'etc', 'zeo.conf')
Expand Down Expand Up @@ -355,7 +379,7 @@ def install_scripts(self):
"opts['-B'] or blob_dir")

# Make sure the recipe itself and its dependencies are on the path
extra_paths = [ws.by_key[options['recipe']].location]
extra_paths = [ws.by_key[options['recipe'].replace('[zrs]', '')].location]
extra_paths.append(ws.by_key['zc.buildout'].location)
extra_paths.append(ws.by_key['zc.recipe.egg'].location)
zc.buildout.easy_install.scripts(
Expand Down Expand Up @@ -481,6 +505,16 @@ def _write_file(self, path, content):
""".strip()


zrs_template = """
%%import zc.zrs
<zrs %(storage_number)s>
%(replicate)s
keep-alive-delay %(keep_alive)s
%(storage)s
</zrs>""".strip()


z_log_file = """\
<logfile>
path %(filename)s
Expand All @@ -500,7 +534,7 @@ def _write_file(self, path, content):
<zeo>
address %(zeo_address)s
read-only false
read-only %(read_only)s
invalidation-queue-size %(invalidation_queue_size)s
pid-filename %(pid_file)s
%(authentication)s
Expand Down
2 changes: 2 additions & 0 deletions src/plone/recipe/zeoserver/tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def setUp(test):
install('nt_svcutils', test)
install('zope.mkzeoinstance', test)
install('ZopeUndo', test)
install('zc.zrs', test)
install('Twisted', test)
dependencies = pkg_resources.working_set.require('ZODB3')
for dep in dependencies:
try:
Expand Down
71 changes: 71 additions & 0 deletions src/plone/recipe/zeoserver/tests/zeoserver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,77 @@ We should have a basic zeo.conf::
<BLANKLINE>
<BLANKLINE>


Zope Replication Services
=========================

Now, let's create a simple buildout to create a primary replication::

>>> primaryzrs = '''
... [buildout]
... parts = zeo
... find-links = %(sample_buildout)s/eggs
...
... [zeo]
... recipe = plone.recipe.zeoserver[zrs]
... replicate-to = 127.0.0.1:5000
... ''' % globals()
>>> write('buildout.cfg', primaryzrs)
>>> print system(join('bin', 'buildout'))
...
Uninstalling zeo.
Installing zeo.
...

We should have primary zrs config in zeo.conf::

>>> zeo = os.path.join(sample_buildout, 'parts', 'zeo')
>>> print open(os.path.join(zeo, 'etc', 'zeo.conf')).read()
%define INSTANCE ...
...
%import zc.zrs
<BLANKLINE>
<zrs>
replicate-to 127.0.0.1:5000
...
<filestorage 1>
...
<BLANKLINE>

And for a secondary::

>>> primaryzrs = '''
... [buildout]
... parts = zeo
... find-links = %(sample_buildout)s/eggs
...
... [zeo]
... recipe = plone.recipe.zeoserver[zrs]
... replicate-from = 127.0.0.1:5000
... ''' % globals()
>>> write('buildout.cfg', primaryzrs)
>>> print system(join('bin', 'buildout'))
...
Uninstalling zeo.
Installing zeo.
...

We should have primary zrs config in zeo.conf::

>>> zeo = os.path.join(sample_buildout, 'parts', 'zeo')
>>> print open(os.path.join(zeo, 'etc', 'zeo.conf')).read()
%define INSTANCE ...
...
%import zc.zrs
<BLANKLINE>
<zrs>
replicate-from 127.0.0.1:5000
...
<filestorage 1>
...
<BLANKLINE>


Custom Zeo log
==============

Expand Down

0 comments on commit 6fef4be

Please sign in to comment.