-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathtest_checkpoint_sync.py
More file actions
320 lines (320 loc) · 10.8 KB
/
test_checkpoint_sync.py
File metadata and controls
320 lines (320 loc) · 10.8 KB
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# from tests.shared_test_pipeline import SharedTestPipeline
# from tests import enterprise_only
# from feldera.runtime_config import RuntimeConfig, Storage
# from feldera.enums import PipelineStatus, FaultToleranceModel
# from typing import Optional
# import os
# import sys
# import time
# from uuid import uuid4
# import random
# import pytest
#
#
# DEFAULT_ENDPOINT = os.environ.get(
# "DEFAULT_MINIO_ENDPOINT", "http://minio.extra.svc.cluster.local:9000"
# )
# DEFAULT_BUCKET = "default"
# ACCESS_KEY = "minio"
# SECRET_KEY = "miniopasswd"
#
#
# def storage_cfg(
# pipeline_name: str,
# endpoint: Optional[str] = None,
# start_from_checkpoint: Optional[str] = None,
# strict: bool = False,
# auth_err: bool = False,
# standby: bool = False,
# pull_interval: int = 2,
# ) -> dict:
# return {
# "backend": {
# "name": "file",
# "config": {
# "sync": {
# "bucket": f"{DEFAULT_BUCKET}/{pipeline_name}",
# "access_key": ACCESS_KEY,
# "secret_key": SECRET_KEY if not auth_err else SECRET_KEY + "extra",
# "provider": "Minio",
# "endpoint": endpoint or DEFAULT_ENDPOINT,
# "start_from_checkpoint": start_from_checkpoint,
# "fail_if_no_checkpoint": strict,
# "standby": standby,
# "pull_interval": pull_interval,
# }
# },
# }
# }
#
#
# class TestCheckpointSync(SharedTestPipeline):
# @enterprise_only
# def test_checkpoint_sync(
# self,
# from_uuid: bool = False,
# random_uuid: bool = False,
# clear_storage: bool = True,
# auth_err: bool = False,
# strict: bool = False,
# expect_empty: bool = False,
# standby: bool = False,
# ):
# """
# CREATE TABLE t0 (c0 INT, c1 VARCHAR);
# CREATE MATERIALIZED VIEW v0 AS SELECT * FROM t0;
# """
#
# storage_config = storage_cfg(self.pipeline.name)
# ft = FaultToleranceModel.AtLeastOnce
#
# self.pipeline.set_runtime_config(
# RuntimeConfig(
# fault_tolerance_model=ft, storage=Storage(config=storage_config)
# )
# )
# self.pipeline.start()
#
# random.seed(time.time())
# total = random.randint(10, 20)
# data = [{"c0": i, "c1": str(i)} for i in range(1, total)]
# self.pipeline.input_json("t0", data)
# self.pipeline.execute("INSERT INTO t0 VALUES (21, 'exists')")
#
# start = time.time()
# timeout = 5
#
# while True:
# processed = self.pipeline.stats().global_metrics.total_processed_records
# if processed == total:
# break
#
# if time.time() - start > timeout:
# raise TimeoutError(
# f"timed out while waiting for pipeline to process {total} records"
# )
#
# time.sleep(0.1)
#
# got_before = list(self.pipeline.query("SELECT * FROM v0"))
# print(f"{self.pipeline.name}: records: {total}, {got_before}", file=sys.stderr)
#
# if len(got_before) != processed:
# raise RuntimeError(
# f"adhoc query returned {len(got_before)} but {processed} records were processed: {got_before}"
# )
#
# self.pipeline.checkpoint(wait=True)
# uuid = self.pipeline.sync_checkpoint(wait=True)
#
# self.pipeline.stop(force=True)
#
# if clear_storage:
# self.pipeline.clear_storage()
#
# if random_uuid:
# uuid = uuid4()
#
# # Restart pipeline from checkpoint
# storage_config = storage_cfg(
# pipeline_name=self.pipeline.name,
# start_from_checkpoint=uuid if from_uuid else "latest",
# auth_err=auth_err,
# strict=strict,
# standby=standby,
# )
# self.pipeline.set_runtime_config(
# RuntimeConfig(
# fault_tolerance_model=ft, storage=Storage(config=storage_config)
# )
# )
#
# if not standby:
# self.pipeline.start()
# else:
# self.pipeline.start(wait=False)
#
# # wait for the pipeline to initialize
# start = time.monotonic()
# # wait for a maximum of 120 seconds for the pipeline to provison
# end = start + 120
#
# # wait for the pipeline to finish provisoning
# for log in self.pipeline.logs():
# if "checkpoint pulled successfully" in log:
# break
#
# if time.monotonic() > end:
# raise TimeoutError(
# f"{self.pipeline.name} timedout waiting to pull checkpoint"
# )
#
# if standby:
# # wait for 8 seconds, this should be more than enough time
# time.sleep(8)
# assert self.pipeline.status() == PipelineStatus.INITIALIZING
#
# self.pipeline.activate(timeout_s=10)
#
# got_after = list(self.pipeline.query("SELECT * FROM v0"))
#
# print(
# f"{self.pipeline.name}: after: {len(got_after)}, {got_after}",
# file=sys.stderr,
# )
#
# if expect_empty:
# got_before = []
#
# self.assertCountEqual(got_before, got_after)
#
# self.pipeline.stop(force=True)
#
# if clear_storage:
# self.pipeline.clear_storage()
#
# @enterprise_only
# def test_from_uuid(self):
# self.test_checkpoint_sync(from_uuid=True)
#
# @enterprise_only
# def test_without_clearing_storage(self):
# self.test_checkpoint_sync(clear_storage=False)
#
# @enterprise_only
# def test_autherr_fail(self):
# with self.assertRaisesRegex(RuntimeError, "SignatureDoesNotMatch"):
# self.test_checkpoint_sync(auth_err=True, strict=True)
#
# @enterprise_only
# def test_autherr(self):
# self.test_checkpoint_sync(auth_err=True, strict=False, expect_empty=True)
#
# @enterprise_only
# def test_nonexistent_checkpoint_fail(self):
# with self.assertRaisesRegex(RuntimeError, "were not found in source"):
# self.test_checkpoint_sync(random_uuid=True, from_uuid=True, strict=True)
#
# @enterprise_only
# def test_nonexistent_checkpoint(self):
# self.test_checkpoint_sync(random_uuid=True, from_uuid=True, expect_empty=True)
#
# @enterprise_only
# def test_standby_activation(self):
# self.test_checkpoint_sync(standby=True)
#
# @enterprise_only
# def test_standby_activation_from_uuid(self):
# self.test_checkpoint_sync(standby=True, from_uuid=True)
#
# @enterprise_only
# def test_standby_fallback(self, from_uuid: bool = False):
# # Step 1: Start main pipeline
# storage_config = storage_cfg(self.pipeline.name)
# ft = FaultToleranceModel.AtLeastOnce
# self.pipeline.set_runtime_config(
# RuntimeConfig(
# fault_tolerance_model=ft, storage=Storage(config=storage_config)
# )
# )
# self.pipeline.start()
#
# # Insert initial data
# random.seed(time.time())
# total_initial = random.randint(10, 20)
# data_initial = [{"c0": i, "c1": str(i)} for i in range(1, total_initial)]
# self.pipeline.input_json("t0", data_initial)
# self.pipeline.execute("INSERT INTO t0 VALUES (21, 'exists')")
# self.pipeline.wait_for_completion()
#
# got_before = list(self.pipeline.query("select * from v0"))
#
# # Step 2: Create checkpoint and sync
# self.pipeline.checkpoint(wait=True)
# uuid = self.pipeline.sync_checkpoint(wait=True)
#
# # Step 3: Start standby pipeline
# standby = self.new_pipeline_with_suffix("standby")
# pull_interval = 1
# standby.set_runtime_config(
# RuntimeConfig(
# fault_tolerance_model=ft,
# storage=Storage(
# config=storage_cfg(
# self.pipeline.name,
# start_from_checkpoint=uuid if from_uuid else "latest",
# standby=True,
# pull_interval=pull_interval,
# )
# ),
# )
# )
# standby.start(wait=False)
#
# # Wait until standby pulls the first checkpoint
# start = time.monotonic()
# end = start + 120
# for log in standby.logs():
# if "checkpoint pulled successfully" in log:
# break
# if time.monotonic() > end:
# raise TimeoutError(
# "Timed out waiting for standby pipeline to pull checkpoint"
# )
#
# # Step 4: Add more data and make 3-10 checkpoints
# extra_ckpts = random.randint(3, 10)
# total_additional = 0
#
# for i in range(extra_ckpts):
# new_val = 100 + i
# new_data = [{"c0": new_val, "c1": f"extra_{new_val}"}]
# self.pipeline.input_json("t0", new_data)
# self.pipeline.wait_for_completion()
# total_additional += 1
# self.pipeline.checkpoint(wait=True)
# self.pipeline.sync_checkpoint(wait=True)
# time.sleep(0.2)
#
# got_expected = (
# got_before if from_uuid else list(self.pipeline.query("SELECT * FROM v0"))
# )
# print(
# f"{self.pipeline.name}: final records before shutdown: {got_expected}",
# file=sys.stderr,
# )
#
# # Step 5: Stop main and activate standby
# self.pipeline.stop(force=True)
#
# assert standby.status() == PipelineStatus.INITIALIZING
# standby.activate(timeout_s=(pull_interval * extra_ckpts) + 60)
#
# for log in standby.logs():
# if "activated" in log:
# break
# if time.monotonic() > end:
# raise TimeoutError("Timed out waiting for standby pipeline to activate")
#
# # Step 6: Validate standby has all expected records
# got_after = list(standby.query("SELECT * FROM v0"))
# print(
# f"{standby.name}: final records after activation: {got_after}",
# file=sys.stderr,
# )
# self.assertCountEqual(got_expected, got_after)
#
# # Cleanup
# standby.stop(force=True)
#
# standby.start()
# got_final = list(standby.query("SELECT * FROM v0"))
# standby.stop(force=True)
#
# self.assertCountEqual(got_after, got_final)
#
# self.pipeline.clear_storage()
#
# @enterprise_only
# def test_standby_fallback_from_uuid(self):
# self.test_standby_fallback(from_uuid=True)