Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf652bf4

Browse files
committed
Merge branch 'master' into logical. Also testgres.pubsub was added to the Sphinx templates and module header was added as well.
2 parents138c6cc +869920c commitf652bf4

File tree

10 files changed

+193
-180
lines changed

10 files changed

+193
-180
lines changed

‎LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
testgres is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.
22

3-
Copyright (c) 2016-2017, Postgres Professional
3+
Copyright (c) 2016-2018, Postgres Professional
44

55
Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
66

‎docs/source/testgres.rst

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,14 @@ testgres.backup
1717
:undoc-members:
1818
:show-inheritance:
1919

20-
testgres.cache
21-
--------------
22-
23-
..automodule::testgres.cache
24-
:members:
25-
:undoc-members:
26-
:show-inheritance:
27-
2820
testgres.config
2921
---------------
3022

3123
..automodule::testgres.config
3224
:members:
3325
:undoc-members:
3426
:show-inheritance:
27+
:member-order: groupwise
3528

3629
testgres.connection
3730
-------------------
@@ -41,30 +34,6 @@ testgres.connection
4134
:undoc-members:
4235
:show-inheritance:
4336

44-
testgres.consts
45-
---------------
46-
47-
..automodule::testgres.consts
48-
:members:
49-
:undoc-members:
50-
:show-inheritance:
51-
52-
testgres.decorators
53-
-------------------
54-
55-
..automodule::testgres.decorators
56-
:members:
57-
:undoc-members:
58-
:show-inheritance:
59-
60-
testgres.defaults
61-
-----------------
62-
63-
..automodule::testgres.defaults
64-
:members:
65-
:undoc-members:
66-
:show-inheritance:
67-
6837
testgres.enums
6938
--------------
7039

@@ -81,35 +50,28 @@ testgres.exceptions
8150
:undoc-members:
8251
:show-inheritance:
8352

84-
testgres.logger
85-
---------------
86-
87-
..automodule::testgres.logger
88-
:members:
89-
:undoc-members:
90-
:show-inheritance:
91-
9253
testgres.node
9354
-------------
9455

95-
..automodule::testgres.node
96-
:members:
97-
:undoc-members:
98-
:show-inheritance:
99-
100-
testgres.utils
101-
--------------
56+
..autoclass::testgres.node.PostgresNode
57+
:members:
10258

103-
..automodule::testgres.utils
104-
:members:
105-
:undoc-members:
106-
:show-inheritance:
59+
..automethod::__init__
10760

61+
..autoclass::testgres.node.ProcessProxy
62+
:members:
10863

109-
Module contents
64+
testgres.pubsub
11065
---------------
11166

112-
..automodule::testgres
113-
:members:
114-
:undoc-members:
115-
:show-inheritance:
67+
..automodule::testgres.pubsub
68+
69+
..autoclass::testgres.node.Publication
70+
:members:
71+
72+
..automethod::__init__
73+
74+
..autoclass::testgres.node.Subscription
75+
:members:
76+
77+
..automethod::__init__

‎testgres/api.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@
2828
... replica.catchup() # wait until changes are visible
2929
... print(replica.execute('postgres', 'select count(*) from test'))
3030
PostgresNode(name='...', port=..., base_dir='...')
31-
[(3,)]
32-
33-
Copyright (c) 2016, Postgres Professional
31+
[(3L,)]
3432
"""
35-
36-
fromfunctoolsimportwraps
37-
3833
from .nodeimportPostgresNode
3934

4035

41-
@wraps(PostgresNode.__init__)
4236
defget_new_node(name=None,base_dir=None,**kwargs):
37+
"""
38+
Simply a wrapper around :class:`.PostgresNode` constructor.
39+
See :meth:`.PostgresNode.__init__` for details.
40+
"""
4341
# NOTE: leave explicit 'name' and 'base_dir' for compatibility
4442
returnPostgresNode(name=name,base_dir=base_dir,**kwargs)

‎testgres/backup.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self,
4343
Create a new backup.
4444
4545
Args:
46-
node: PostgresNode we're going to backup.
46+
node::class:`.PostgresNode` we're going to backup.
4747
base_dir: where should we store it?
4848
username: database user name.
4949
xlog_method: none | fetch | stream (see docs)
@@ -74,15 +74,14 @@ def __init__(self,
7474

7575
data_dir=os.path.join(self.base_dir,DATA_DIR)
7676

77-
# yapf: disable
7877
_params= [
7978
get_bin_path("pg_basebackup"),
8079
"-p",str(node.port),
8180
"-h",node.host,
8281
"-U",username,
8382
"-D",data_dir,
8483
"-X",xlog_method.value
85-
]
84+
]# yapf: disable
8685
execute_utility(_params,self.log_file)
8786

8887
def__enter__(self):
@@ -137,16 +136,15 @@ def spawn_primary(self, name=None, destroy=True):
137136
destroy: should we convert this backup into a node?
138137
139138
Returns:
140-
New instance of PostgresNode.
139+
New instance of:class:`.PostgresNode`.
141140
"""
142141

143142
# Prepare a data directory for this node
144143
base_dir=self._prepare_dir(destroy)
145144

146145
# Build a new PostgresNode
147146
from .nodeimportPostgresNode
148-
withclean_on_error(PostgresNode(name=name,
149-
base_dir=base_dir))asnode:
147+
withclean_on_error(PostgresNode(name=name,base_dir=base_dir))asnode:
150148

151149
# New nodes should always remove dir tree
152150
node._should_rm_dirs=True
@@ -166,7 +164,7 @@ def spawn_replica(self, name=None, destroy=True, slot=None):
166164
destroy: should we convert this backup into a node?
167165
168166
Returns:
169-
New instance of PostgresNode.
167+
New instance of:class:`.PostgresNode`.
170168
"""
171169

172170
# Build a new PostgresNode
@@ -180,6 +178,11 @@ def spawn_replica(self, name=None, destroy=True, slot=None):
180178
returnnode
181179

182180
defcleanup(self):
181+
"""
182+
Remove all files that belong to this backup.
183+
No-op if it's been converted to a PostgresNode (destroy=True).
184+
"""
185+
183186
ifself._available:
184187
self._available=False
185188
rmtree(self.base_dir,ignore_errors=True)

‎testgres/config.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,40 @@
1313

1414
classGlobalConfig(object):
1515
"""
16-
Global config (override default settings).
17-
18-
Attributes:
19-
cache_initdb: shall we use cached initdb instance?
20-
cached_initdb_dir: shall we create a temp dir for cached initdb?
21-
cached_initdb_unique: shall we assign new node a unique system id?
22-
23-
cache_pg_config: shall we cache pg_config results?
24-
25-
temp_dir: base temp dir for nodes with default 'base_dir'.
26-
27-
use_python_logging: use python logging configuration for all nodes.
28-
error_log_lines: N of log lines to be shown in exception (0=inf).
29-
30-
node_cleanup_full: shall we remove EVERYTHING (including logs)?
31-
node_cleanup_on_good_exit: remove base_dir on nominal __exit__().
32-
node_cleanup_on_bad_exit: remove base_dir on __exit__() via exception.
33-
34-
NOTE: attributes must not be callable or begin with __.
16+
Global configuration object which allows user to override default settings.
3517
"""
18+
# NOTE: attributes must not be callable or begin with __.
3619

3720
cache_initdb=True
38-
_cached_initdb_dir=None
21+
""" shall we use cached initdb instance? """
22+
3923
cached_initdb_unique=False
24+
""" shall we give new node a unique system id? """
4025

4126
cache_pg_config=True
27+
""" shall we cache pg_config results? """
4228

4329
use_python_logging=False
30+
""" enable python logging subsystem (see logger.py). """
31+
4432
error_log_lines=20
33+
""" N of log lines to be shown in exceptions (0=inf). """
4534

4635
node_cleanup_full=True
36+
""" shall we remove EVERYTHING (including logs)? """
37+
4738
node_cleanup_on_good_exit=True
39+
""" remove base_dir on nominal __exit__(). """
40+
4841
node_cleanup_on_bad_exit=False
42+
""" remove base_dir on __exit__() via exception. """
43+
44+
_cached_initdb_dir=None
45+
""" underlying class attribute for cached_initdb_dir property """
4946

5047
@property
5148
defcached_initdb_dir(self):
49+
""" path to a temp directory for cached initdb. """
5250
returnself._cached_initdb_dir
5351

5452
@cached_initdb_dir.setter
@@ -60,6 +58,7 @@ def cached_initdb_dir(self, value):
6058

6159
@property
6260
deftemp_dir(self):
61+
""" path to temp dir containing nodes with default 'base_dir'. """
6362
returntempfile.tempdir
6463

6564
@temp_dir.setter
@@ -82,6 +81,10 @@ def __setattr__(self, name, value):
8281
super(GlobalConfig,self).__setattr__(name,value)
8382

8483
defkeys(self):
84+
"""
85+
Return a list of all available settings.
86+
"""
87+
8588
keys= []
8689

8790
forkeyindir(GlobalConfig):
@@ -91,15 +94,29 @@ def keys(self):
9194
returnkeys
9295

9396
defitems(self):
97+
"""
98+
Return setting-value pairs.
99+
"""
100+
94101
return ((key,self[key])forkeyinself.keys())
95102

96103
defupdate(self,config):
104+
"""
105+
Extract setting-value pairs from 'config' and
106+
assign those values to corresponding settings
107+
of this GlobalConfig object.
108+
"""
109+
97110
forkey,valueinconfig.items():
98111
self[key]=value
99112

100113
returnself
101114

102115
defcopy(self):
116+
"""
117+
Return a copy of this object.
118+
"""
119+
103120
returncopy.copy(self)
104121

105122

@@ -124,8 +141,8 @@ def _rm_cached_initdb_dirs():
124141

125142
defpush_config(**options):
126143
"""
127-
Permanently set custom GlobalConfig options
128-
andput previous settings on top of stack.
144+
Permanently set custom GlobalConfig options and
145+
put previous settings on top of the config stack.
129146
"""
130147

131148
# push current config to stack
@@ -150,10 +167,12 @@ def pop_config():
150167
defscoped_config(**options):
151168
"""
152169
Temporarily set custom GlobalConfig options for this context.
170+
Previous options are pushed to the config stack.
153171
154172
Example:
155173
>>> from .api import get_new_node
156174
>>> with scoped_config(cache_initdb=False):
175+
... # create a new node with fresh initdb
157176
... with get_new_node().init().start() as node:
158177
... print(node.execute('select 1'))
159178
[(1,)]
@@ -173,7 +192,7 @@ def scoped_config(**options):
173192
defconfigure_testgres(**options):
174193
"""
175194
Adjust current global options.
176-
Look at GlobalConfig to learnwhat can be set.
195+
Look attheGlobalConfig to learnabout existing settings.
177196
"""
178197

179198
testgres_config.update(options)

‎testgres/consts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
UTILS_LOG_FILE="utils.log"
2626
BACKUP_LOG_FILE="backup.log"
2727

28-
# default replication slots number
29-
REPLICATION_SLOTS=10
28+
# defaults for node settings
29+
MAX_REPLICATION_SLOTS=10
30+
MAX_WAL_SENDERS=10
31+
WAL_KEEP_SEGMENTS=20

‎testgres/enums.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
classXLogMethod(Enum):
66
"""
7-
Available WAL methods for NodeBackup
7+
Available WAL methods for:class:`.NodeBackup`
88
"""
99

1010
none='none'
@@ -14,7 +14,7 @@ class XLogMethod(Enum):
1414

1515
classIsolationLevel(Enum):
1616
"""
17-
Transaction isolation level for NodeConnection
17+
Transaction isolation level for:class:`.NodeConnection`
1818
"""
1919

2020
ReadUncommitted='read uncommitted'
@@ -58,7 +58,6 @@ class ProcessType(Enum):
5858

5959
@staticmethod
6060
deffrom_process(process):
61-
# yapf: disable
6261
# legacy names for older releases of PG
6362
alternative_names= {
6463
ProcessType.LogicalReplicationLauncher: [
@@ -67,7 +66,7 @@ def from_process(process):
6766
ProcessType.BackgroundWriter: [
6867
'writer'
6968
],
70-
}
69+
}# yapf: disable
7170

7271
# we deliberately cut special words and spaces
7372
cmdline=''.join(process.cmdline()) \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp