-
Notifications
You must be signed in to change notification settings - Fork 46
/
options.py
138 lines (123 loc) · 4.65 KB
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
##############################################################################
#
# Copyright (c) 2008 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from __future__ import absolute_import
from relstorage._compat import PYPY
class Options(object):
"""Options for configuring and tuning RelStorage.
These parameters can be provided as keyword options in the :class:`.RelStorage`
constructor. For example:
storage = RelStorage(adapter, pack_gc=True, pack_prepack_only=True)
Alternatively, the RelStorage constructor accepts an options
parameter, which should be an Options instance.
.. versionchanged:: 3.0
No longer accepts the ``poll_interval`` option.
.. versionchanged:: 2.0b2
The ``poll_interval`` option is now ignored and raises a warning. It is always
effectively 0.
.. versionchanged:: 2.0b7
The ``cache_delta_size_limit`` grew to 20000 on CPython.
"""
#: The name
name = None
#: Read only?
read_only = False
#: directory to hold blobs
blob_dir = None
#: Is the blob directory shared?
shared_blob_dir = True
#: How much local blob data to keep
blob_cache_size = None
#: ?
blob_cache_size_check = 10
#: The size to break blobs into for storage
blob_chunk_size = 1 << 20
#: Preserve history?
keep_history = True
#: File containing replica info
replica_conf = None
#: File containing read-only replica info
ro_replica_conf = None
#: ?
replica_timeout = 600.0
#: Specifies what to do when a database connection is stale.
revert_when_stale = False
#: Perform a GC when packing
pack_gc = True
#: Only prepack
pack_prepack_only = False
#: Skip prepack
pack_skip_prepack = False
#: Length of time to hold a lock.
pack_batch_timeout = 1.0
#: How long to pause if we can't get the lock
pack_commit_busy_delay = 5.0
#: List of memcache servers
cache_servers = () # ['127.0.0.1:11211']
#: Module to wrap a memcache connection with.
cache_module_name = 'relstorage.pylibmc_wrapper'
#: Database-specific prefix key
cache_prefix = ''
#: How much memory to use for the pickle cache
cache_local_mb = 10
#: The largest pickle to hold in the pickle cache
cache_local_object_max = 16384
#: How to compress local pickles
cache_local_compression = 'zlib'
#: Directory holding persistent cache files
cache_local_dir = None
#: How many persistent cache files to keep
cache_local_dir_count = 20
#: How many persistent cache files to read
cache_local_dir_read_count = None
#: How big a cache file can be
cache_local_dir_write_max_size = None
#: Compress the cache files?
cache_local_dir_compress = False
#: Switch checkpoints after this many writes
cache_delta_size_limit = 20000 if not PYPY else 10000
#: How long to wait for a commit lock
commit_lock_timeout = 30
#: Lock ID for Oracle
commit_lock_id = 0
#: Automatically create the schema if needed
create_schema = True
#: Which database driver to use
driver = 'auto'
# If share_local_cache is off, each storage instance has a private
# cache rather than a shared cache. This option exists mainly for
# simulating disconnected caches in tests.
share_local_cache = True
def __init__(self, **kwoptions):
for key, value in kwoptions.items():
if not hasattr(self, key):
raise TypeError("Unknown parameter: %s" % key)
setattr(self, key, value)
@classmethod
def copy_valid_options(cls, other_options):
"""
Produce a new options featuring only the valid settings from
*other_options*.
"""
option_dict = {}
for key in cls.valid_option_names():
value = getattr(other_options, key, None)
if value is not None:
option_dict[key] = value
return cls(**option_dict)
@classmethod
def valid_option_names(cls):
return [x for x in vars(cls)
if not callable(getattr(cls, x)) and not x.startswith('_')]
def __repr__(self):
return 'relstorage.options.Options(**' + repr(self.__dict__) + ')'