forked from zweix123/bustub_2023spring_backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
executable file
·290 lines (261 loc) · 10.1 KB
/
script.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re, os
from typing import Optional
try:
from dryad import Dryad, DryadFlag, run_shell_cmd
except Exception as e:
print("install dryad: ")
print(" git clone https://github.com/zweix123/dryad.git")
print(" cd dryad")
print(" pip install .")
exit(-1)
SQL = """
SELECT * FROM test_1 t1, test_2 t2 WHERE t1.colA = t2.colA AND t1.colB = t2.colC;
"""
TREE_INPUT = """
2 3
i 1
i 2
i 3
d 2
i 2
d 3
"""
TREE_SUFFIX = """
g my-tree.dot
q
"""
TERRIER_OUT_FILE = "terrier-bench.txt"
def cmd_viz_repl():
"""
VSCode B+Tree REPL: 支持size的初始化和命令i、d、q
强烈建议在VSCode终端使用(注意每次交互会移动光标)
需要环境有软件graphviz(即命令dot)
本质就是记录输入, 换行时拼接调用
"""
def run_cmd(cmd: str):
run_shell_cmd("\n".join(["cd build", cmd]))
# compile
run_cmd("make b_plus_tree_printer -j$(nproc)")
print(cmd_viz_repl.__doc__)
init_input = input("init: ")
# check and config init input
pattern = re.compile(r"^\d+\s+\d+$") # 匹配一行两个空格隔开的整数的正则表达式
if pattern.match(init_input) is None:
print(f'初始语句"{init_input}"不合法, 请使用空格隔开的两个整数')
exit(-1)
init_input += "\n"
# constant
DOT_FILE_NAME = "my-tree.dot"
SUFFIX_INPUT = f"\ng {DOT_FILE_NAME}\nq\n"
input_sum = ""
while True:
line = input()
if line.strip() == "q":
break
try:
action, key = line.strip().split()
except Exception as e:
print("[\033[31mInvalid Args\033[0m] Do not process, continue inputting.")
continue
if action not in ("i", "d") or key.isdigit() is False:
print("[\033[31mInvalid Args\033[0m] Do not process, continue inputting.")
continue
# gen dot file
run_cmd(
f'echo "{init_input + input_sum + line + SUFFIX_INPUT}" | ./bin/b_plus_tree_printer > /dev/null'
)
# check dot file
if os.path.exists(os.path.join("build", DOT_FILE_NAME)) is False:
print("[\033[31mError Exe\033[0m] 官方脚本未生成dot文件, 猜测图为空, 该输入回退, 继续输入.")
continue
# accept input
input_sum += line
# viz
run_cmd(f"dot -Tpng -O {DOT_FILE_NAME}")
run_cmd(f"code {DOT_FILE_NAME}.png")
# sufix handle
run_cmd(f"rm {DOT_FILE_NAME}")
def debug_terrier_helper():
"""
final_helper
处理命令生成的脚本
主要是对特定格式进行解析然后按6.824的方式输出
需要CPP端的配合, 已在梗犬测试代码(terrier_debug.cpp)中修改
"""
from rich import print as rich_print
from rich.columns import Columns
from rich.console import Console
width = Console().size.width
COL_NUM = 5
def pick(line: str) -> (Optional[str], Optional[str]):
PATTERN = r"T(\d): (.*)"
match = re.match(PATTERN, line)
if match is not None:
index = int(match.group(1)) - 1
msg = match.group(2)
return (index, msg)
else:
return (None, None)
else_msg = ""
cols = ["Thread" + str(i) for i in range(5)]
col_width = int(width / COL_NUM)
cols = Columns(cols, width=col_width - 1, equal=True, expand=True)
rich_print(cols)
with open(f"build/{TERRIER_OUT_FILE}", "r") as f:
for line in f:
i, msg = pick(line)
if i is None:
assert msg is None, "Logic Error"
else_msg += line
continue
cols = ["" for _ in range(COL_NUM)]
cols[i] = msg
col_width = int(width / COL_NUM)
cols = Columns(cols, width=col_width - 1, equal=True, expand=True)
rich_print(cols)
# print(else_msg)
CMDS = {
DryadFlag.PrefixCmd: "cd build",
"viz": [
"make b_plus_tree_printer -j$(nproc)",
f'echo "{TREE_INPUT + TREE_SUFFIX}" | ./bin/b_plus_tree_printer',
"dot -Tpng -O my-tree.dot",
"code my-tree.dot.png",
],
"viz-repl": cmd_viz_repl,
"format": {
"default": ["make format", "make check-lint"],
"1": ["make check-clang-tidy-p1"],
"2": ["make check-clang-tidy-p2"],
"3": ["make check-clang-tidy-p3"],
"4": ["make check-clang-tidy-p4"],
},
"test": {
"1": {
"1": [
"make lru_k_replacer_test -j$(nproc)",
"./test/lru_k_replacer_test",
],
"2": [
"make buffer_pool_manager_test -j$(nproc)",
"./test/buffer_pool_manager_test",
],
"3": [
"make page_guard_test -j$(nproc)",
"./test/page_guard_test",
],
},
"2": {
# 按照Task视角
# Check Point 1
"1": ['echo "Pages Structure."'],
"2a": ['echo "Insert and Search."'],
# Check Point 2
"2b": ['echo "Delete."'],
"3": ['echo "Interator"'],
"4": ['echo "Concurrency"'],
# 按照Check Pointer视角
"cp1": [
"make b_plus_tree_insert_test -j$(nproc)",
"./test/b_plus_tree_insert_test",
"make b_plus_tree_sequential_scale_test -j$(nproc)",
"./test/b_plus_tree_sequential_scale_test",
],
"cp2": [
"make b_plus_tree_insert_test -j$(nproc)",
"./test/b_plus_tree_insert_test",
"make b_plus_tree_delete_test -j$(nproc)",
"./test/b_plus_tree_delete_test",
"make b_plus_tree_sequential_scale_test -j$(nproc)",
"./test/b_plus_tree_sequential_scale_test",
"make b_plus_tree_concurrent_test -j$(nproc)",
"./test/b_plus_tree_concurrent_test",
],
# 按照开发流程视角
"main": ['echo "Main."'],
},
"3": [
"make -j$(nproc) sqllogictest",
'echo "Task 1"',
"./bin/bustub-sqllogictest ../test/sql/p3.00-primer.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.01-seqscan.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.02-insert.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.04-delete.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.03-update.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.05-index-scan.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.06-empty-table.slt --verbose",
'echo "Aggregation"',
"./bin/bustub-sqllogictest ../test/sql/p3.07-simple-agg.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.08-group-agg-1.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.09-group-agg-2.slt --verbose",
'echo "NestedLoopJoin"',
"./bin/bustub-sqllogictest ../test/sql/p3.10-simple-join.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.11-multi-way-join.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.12-repeat-execute.slt --verbose",
'echo "NestedIndexJoin(实际无效, GradeScope也未测试, Planer并未生成NestedIndexJoin结点, sqllogictest相关的检测终止了进程)"',
# "./bin/bustub-sqllogictest ../test/sql/p3.13-nested-index-join.slt --verbose",
'echo "HashJoin"',
"./bin/bustub-sqllogictest ../test/sql/p3.14-hash-join.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.15-multi-way-hash-join.slt --verbose",
'echo "Task 3"',
"./bin/bustub-sqllogictest ../test/sql/p3.16-sort-limit.slt --verbose",
"./bin/bustub-sqllogictest ../test/sql/p3.17-topn.slt --verbose",
# "./bin/bustub-sqllogictest ../test/sql/p3.18-integration-1.slt --verbose",
# "./bin/bustub-sqllogictest ../test/sql/p3.19-integration-2.slt --verbose",
'echo "leaderboard"',
# "./bin/bustub-sqllogictest ../test/sql/p3.leaderboard-q1.slt --verbose",
# "./bin/bustub-sqllogictest ../test/sql/p3.leaderboard-q2.slt --verbose",
# "./bin/bustub-sqllogictest ../test/sql/p3.leaderboard-q3.slt --verbose",
],
"4": {
"1": [
"make lock_manager_test -j`nproc`",
"./test/lock_manager_test",
],
"2": [
"make deadlock_detection_test -j`nproc`",
"./test/deadlock_detection_test",
"make wuxiao_deadlock_detection_test -j`nproc`",
"./test/wuxiao_deadlock_detection_test",
],
"3": [
"make zweix_lock_manager_test -j`nproc`",
"./test/zweix_lock_manager_test ",
"make txn_integration_test -j`nproc`",
"./test/txn_integration_test ",
"make wuxiao_lock_manager_test -j`nproc`",
"./test/wuxiao_lock_manager_test",
"make wuxiao_lock_manager_compability_test -j`nproc`",
"./test/wuxiao_lock_manager_compability_test",
"make wuxiao_lock_manager_isolation_test -j`nproc`",
"./test/wuxiao_lock_manager_isolation_test",
],
},
},
"submit": {
"1": ["make submit-p1"],
"2": ["make submit-p2"],
"3": ["make submit-p3"],
"4": ["make submit-p4"],
},
"run": [
"make -j`nproc` shell",
"./bin/bustub-shell",
],
"test-SQL": [
"make -j`nproc` shell",
f'echo "{SQL}" | ./bin/bustub-shell 2> /dev/null',
],
"test-terrier": [
"make -j`nproc` terrier-bench",
"./bin/bustub-terrier-bench --duration 30000",
],
"terrier-debug": [
"make -j`nproc` terrier-debug",
f"./bin/bustub-terrier-debug --duration 30000 > {TERRIER_OUT_FILE} 2>&1 || true",
debug_terrier_helper,
],
}
Dryad(cmd_tree=CMDS)