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

Commit636d0f9

Browse files
authored
Merge branch 'master' into unique_system_ids_for_cached_initdb
2 parentsc2f0156 +5bd8d48 commit636d0f9

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

‎testgres/backup.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from .constsimport \
1010
DATA_DIR, \
11+
TMP_NODE, \
12+
TMP_BACKUP, \
1113
PG_CONF_FILE, \
1214
BACKUP_LOG_FILE, \
1315
DEFAULT_XLOG_METHOD
@@ -49,7 +51,7 @@ def __init__(self,
4951

5052
# Set default arguments
5153
username=usernameordefault_username()
52-
base_dir=base_dirortempfile.mkdtemp()
54+
base_dir=base_dirortempfile.mkdtemp(prefix=TMP_BACKUP)
5355

5456
# public
5557
self.original_node=node
@@ -96,7 +98,7 @@ def _prepare_dir(self, destroy):
9698
available=notdestroy
9799

98100
ifavailable:
99-
dest_base_dir=tempfile.mkdtemp()
101+
dest_base_dir=tempfile.mkdtemp(prefix=TMP_NODE)
100102

101103
data1=os.path.join(self.base_dir,DATA_DIR)
102104
data2=os.path.join(dest_base_dir,DATA_DIR)

‎testgres/config.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
fromcontextlibimportcontextmanager
99

10+
from .constsimportTMP_CACHE
11+
1012

1113
classGlobalConfig(object):
1214
"""
@@ -103,6 +105,7 @@ def copy(self):
103105
config_stack= []
104106

105107

108+
@atexit.register
106109
defrm_cached_initdb_dirs():
107110
fordincached_initdb_dirs:
108111
shutil.rmtree(d,ignore_errors=True)
@@ -163,8 +166,5 @@ def configure_testgres(**options):
163166
testgres_config.update(options)
164167

165168

166-
# NOTE: to be executed at exit()
167-
atexit.register(rm_cached_initdb_dirs)
168-
169169
# NOTE: assign initial cached dir for initdb
170-
testgres_config.cached_initdb_dir=tempfile.mkdtemp()
170+
testgres_config.cached_initdb_dir=tempfile.mkdtemp(prefix=TMP_CACHE)

‎testgres/consts.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
DATA_DIR="data"
55
LOGS_DIR="logs"
66

7+
# prefixes for temp dirs
8+
TMP_NODE='tgsn_'
9+
TMP_DUMP='tgsd_'
10+
TMP_CACHE='tgsc_'
11+
TMP_BACKUP='tgsb_'
12+
713
# path to control file
814
XLOG_CONTROL_FILE="global/pg_control"
915

‎testgres/node.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from .constsimport \
2424
DATA_DIR, \
2525
LOGS_DIR, \
26+
TMP_NODE, \
27+
TMP_DUMP, \
2628
PG_CONF_FILE, \
2729
PG_AUTO_CONF_FILE, \
2830
HBA_CONF_FILE, \
@@ -106,7 +108,9 @@ def __enter__(self):
106108
def__exit__(self,type,value,traceback):
107109
self.free_port()
108110

109-
got_exception=valueisnotNone
111+
# NOTE: ctrl+C does not count!
112+
got_exception=typeisnotNoneandtype!=KeyboardInterrupt
113+
110114
c1=self.cleanup_on_good_exitandnotgot_exception
111115
c2=self.cleanup_on_bad_exitandgot_exception
112116

@@ -152,8 +156,9 @@ def _try_shutdown(self, max_attempts):
152156
exceptExecUtilException:
153157
pass# one more time
154158
exceptException:
155-
# TODO: probably kill stray instance
159+
# TODO: probablyshouldkill stray instance
156160
eprint('cannot stop node {}'.format(self.name))
161+
break
157162

158163
attempts+=1
159164

@@ -195,7 +200,7 @@ def _create_recovery_conf(self, username):
195200

196201
def_prepare_dirs(self):
197202
ifnotself.base_dir:
198-
self.base_dir=tempfile.mkdtemp()
203+
self.base_dir=tempfile.mkdtemp(prefix=TMP_NODE)
199204

200205
ifnotos.path.exists(self.base_dir):
201206
os.makedirs(self.base_dir)
@@ -713,7 +718,7 @@ def dump(self, filename=None, dbname=None, username=None):
713718
"""
714719

715720
deftmpfile():
716-
fd,fname=tempfile.mkstemp()
721+
fd,fname=tempfile.mkstemp(prefix=TMP_DUMP)
717722
os.close(fd)
718723
returnfname
719724

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp