3
3
"""
4
4
5
5
import logging
6
- import os
7
6
import shutil
8
7
import subprocess
9
8
from pathlib import Path
10
9
from typing import Optional
11
10
12
11
import click
13
12
import sqlalchemy
13
+ from gymlib .symlinks_paths import get_pgbin_symlink_path , get_repo_symlink_path
14
14
15
15
from benchmark .constants import DEFAULT_SCALE_FACTOR
16
16
from benchmark .job .load_info import JobLoadInfo
35
35
fully_resolve_path ,
36
36
get_dbdata_tgz_filename ,
37
37
get_default_dbdata_parent_dpath ,
38
- get_default_pgbin_path ,
39
38
is_fully_resolved ,
40
39
is_ssd ,
41
40
link_result ,
@@ -61,7 +60,38 @@ def postgres_group(dbgym_workspace: DBGymWorkspace) -> None:
61
60
help = "Include this flag to rebuild Postgres even if it already exists." ,
62
61
)
63
62
def postgres_build (dbgym_workspace : DBGymWorkspace , rebuild : bool ) -> None :
64
- _build_repo (dbgym_workspace , rebuild )
63
+ _postgres_build (dbgym_workspace , rebuild )
64
+
65
+
66
+ def _postgres_build (dbgym_workspace : DBGymWorkspace , rebuild : bool ) -> None :
67
+ """
68
+ This function exists as a hook for integration tests.
69
+ """
70
+ expected_repo_symlink_dpath = get_repo_symlink_path (
71
+ dbgym_workspace .dbgym_workspace_path
72
+ )
73
+ if not rebuild and expected_repo_symlink_dpath .exists ():
74
+ logging .getLogger (DBGYM_LOGGER_NAME ).info (
75
+ f"Skipping _postgres_build: { expected_repo_symlink_dpath } "
76
+ )
77
+ return
78
+
79
+ logging .getLogger (DBGYM_LOGGER_NAME ).info (
80
+ f"Setting up repo in { expected_repo_symlink_dpath } "
81
+ )
82
+ repo_real_dpath = dbgym_workspace .dbgym_this_run_path / "repo"
83
+ repo_real_dpath .mkdir (parents = False , exist_ok = False )
84
+ subprocess_run (
85
+ f"./_build_repo.sh { repo_real_dpath } " ,
86
+ cwd = dbgym_workspace .base_dbgym_repo_dpath / "dbms" / "postgres" ,
87
+ )
88
+
89
+ # only link at the end so that the link only ever points to a complete repo
90
+ repo_symlink_dpath = dbgym_workspace .link_result (repo_real_dpath )
91
+ assert expected_repo_symlink_dpath .samefile (repo_symlink_dpath )
92
+ logging .getLogger (DBGYM_LOGGER_NAME ).info (
93
+ f"Set up repo in { expected_repo_symlink_dpath } "
94
+ )
65
95
66
96
67
97
@postgres_group .command (
@@ -75,7 +105,7 @@ def postgres_build(dbgym_workspace: DBGymWorkspace, rebuild: bool) -> None:
75
105
"--pgbin-path" ,
76
106
type = Path ,
77
107
default = None ,
78
- help = f"The path to the bin containing Postgres executables. The default is { get_default_pgbin_path (WORKSPACE_PATH_PLACEHOLDER )} ." ,
108
+ help = f"The path to the bin containing Postgres executables. The default is { get_pgbin_symlink_path (WORKSPACE_PATH_PLACEHOLDER )} ." ,
79
109
)
80
110
@click .option (
81
111
"--intended-dbdata-hardware" ,
@@ -99,7 +129,7 @@ def postgres_dbdata(
99
129
) -> None :
100
130
# Set args to defaults programmatically (do this before doing anything else in the function)
101
131
if pgbin_path is None :
102
- pgbin_path = get_default_pgbin_path (dbgym_workspace .dbgym_workspace_path )
132
+ pgbin_path = get_pgbin_symlink_path (dbgym_workspace .dbgym_workspace_path )
103
133
if dbdata_parent_dpath is None :
104
134
dbdata_parent_dpath = get_default_dbdata_parent_dpath (
105
135
dbgym_workspace .dbgym_workspace_path
@@ -127,40 +157,6 @@ def postgres_dbdata(
127
157
)
128
158
129
159
130
- def _get_pgbin_symlink_path (dbgym_workspace : DBGymWorkspace ) -> Path :
131
- return dbgym_workspace .cur_symlinks_build_path (
132
- "repo.link" , "boot" , "build" , "postgres" , "bin"
133
- )
134
-
135
-
136
- def _get_repo_symlink_path (dbgym_workspace : DBGymWorkspace ) -> Path :
137
- return dbgym_workspace .cur_symlinks_build_path ("repo.link" )
138
-
139
-
140
- def _build_repo (dbgym_workspace : DBGymWorkspace , rebuild : bool ) -> None :
141
- expected_repo_symlink_dpath = _get_repo_symlink_path (dbgym_workspace )
142
- if not rebuild and expected_repo_symlink_dpath .exists ():
143
- logging .getLogger (DBGYM_LOGGER_NAME ).info (
144
- f"Skipping _build_repo: { expected_repo_symlink_dpath } "
145
- )
146
- return
147
-
148
- logging .getLogger (DBGYM_LOGGER_NAME ).info (
149
- f"Setting up repo in { expected_repo_symlink_dpath } "
150
- )
151
- repo_real_dpath = dbgym_workspace .cur_task_runs_build_path ("repo" , mkdir = True )
152
- subprocess_run (
153
- f"./build_repo.sh { repo_real_dpath } " , cwd = dbgym_workspace .cur_source_path ()
154
- )
155
-
156
- # only link at the end so that the link only ever points to a complete repo
157
- repo_symlink_dpath = link_result (dbgym_workspace , repo_real_dpath )
158
- assert expected_repo_symlink_dpath .samefile (repo_symlink_dpath )
159
- logging .getLogger (DBGYM_LOGGER_NAME ).info (
160
- f"Set up repo in { expected_repo_symlink_dpath } "
161
- )
162
-
163
-
164
160
def _create_dbdata (
165
161
dbgym_workspace : DBGymWorkspace ,
166
162
benchmark_name : str ,
@@ -216,7 +212,9 @@ def _create_dbdata(
216
212
217
213
def _generic_dbdata_setup (dbgym_workspace : DBGymWorkspace ) -> None :
218
214
# get necessary vars
219
- pgbin_real_dpath = _get_pgbin_symlink_path (dbgym_workspace ).resolve ()
215
+ pgbin_real_dpath = get_pgbin_symlink_path (
216
+ dbgym_workspace .dbgym_workspace_path
217
+ ).resolve ()
220
218
assert pgbin_real_dpath .exists ()
221
219
dbgym_pguser = DBGYM_POSTGRES_USER
222
220
dbgym_pgpass = DBGYM_POSTGRES_PASS
0 commit comments