Skip to content

Commit 5d879a2

Browse files
authored
switch on blancing checking (#11668)
1 parent 02afce5 commit 5d879a2

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

ydb/tests/olap/lib/ydb_cluster.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def execute_single_result_query(cls, query, timeout=10):
179179

180180
@classmethod
181181
@allure.step('Check if YDB alive')
182-
def check_if_ydb_alive(cls, timeout=10, balanced_paths=None):
182+
def check_if_ydb_alive(cls, timeout=10, balanced_paths=None) -> tuple[str, str]:
183183
def _check_node(n):
184184
name = 'UnknownNode'
185185
error = None
@@ -197,6 +197,7 @@ def _check_node(n):
197197
return error
198198

199199
errors = []
200+
warnings = []
200201
try:
201202
nodes = cls.get_cluster_nodes(db_only=True)
202203
expected_nodes_count = os.getenv('EXPECTED_DYN_NODES_COUNT')
@@ -216,55 +217,53 @@ def _check_node(n):
216217
ok_node_count += 1
217218
if ok_node_count < nodes_count:
218219
errors.append(f'Only {ok_node_count} from {ok_node_count} dynnodes are ok: {",".join(node_errors)}')
219-
if os.getenv('TEST_CHECK_BALANCING', 'no') == 'yes':
220-
paths_to_balance = []
221-
if isinstance(balanced_paths, str):
222-
paths_to_balance += cls._get_tables(balanced_paths)
223-
elif isinstance(balanced_paths, list):
224-
for path in balanced_paths:
225-
paths_to_balance += cls._get_tables(path)
226-
for p in paths_to_balance:
227-
table_nodes = cls.get_cluster_nodes(p)
228-
min = None
229-
max = None
230-
if expected_nodes_count:
231-
if len(table_nodes) < expected_nodes_count:
232-
min = 0
233-
for tn in table_nodes:
234-
tablet_count = 0
235-
for tablet in tn.get("Tablets", []):
236-
if tablet.get("State") != "Green":
237-
errors.append(f'Node {tn.get("SystemState", {}).get("Host")}: {tablet.get("Count")} tablets of type {tablet.get("Type")} in {tablet.get("State")} state')
238-
if tablet.get("Type") in {"ColumnShard", "DataShard"}:
239-
tablet_count += tablet.get("Count")
240-
if tablet_count > 0:
241-
if min is None or tablet_count < min:
242-
min = tablet_count
243-
if max is None or tablet_count > max:
244-
max = tablet_count
245-
if min is None or max is None:
246-
errors.append(f'Table {p} has no tablets')
247-
elif max - min > 1:
248-
errors.append(f'Table {p} is not balanced: {min}-{max} shards.')
249-
LOGGER.info(f'Table {p} balance: {min}-{max} shards.')
220+
paths_to_balance = []
221+
if isinstance(balanced_paths, str):
222+
paths_to_balance += cls._get_tables(balanced_paths)
223+
elif isinstance(balanced_paths, list):
224+
for path in balanced_paths:
225+
paths_to_balance += cls._get_tables(path)
226+
for p in paths_to_balance:
227+
table_nodes = cls.get_cluster_nodes(p)
228+
min = None
229+
max = None
230+
if expected_nodes_count:
231+
if len(table_nodes) < expected_nodes_count:
232+
min = 0
233+
for tn in table_nodes:
234+
tablet_count = 0
235+
for tablet in tn.get("Tablets", []):
236+
if tablet.get("State") != "Green":
237+
warnings.append(f'Node {tn.get("SystemState", {}).get("Host")}: {tablet.get("Count")} tablets of type {tablet.get("Type")} in {tablet.get("State")} state')
238+
if tablet.get("Type") in {"ColumnShard", "DataShard"}:
239+
tablet_count += tablet.get("Count")
240+
if tablet_count > 0:
241+
if min is None or tablet_count < min:
242+
min = tablet_count
243+
if max is None or tablet_count > max:
244+
max = tablet_count
245+
if min is None or max is None:
246+
warnings.append(f'Table {p} has no tablets')
247+
elif max - min > 1:
248+
warnings.append(f'Table {p} is not balanced: {min}-{max} shards.')
249+
LOGGER.info(f'Table {p} balance: {min}-{max} shards.')
250250

251251
cls.execute_single_result_query("select 1", timeout)
252252
except BaseException as ex:
253253
errors.append(f"Cannot connect to YDB: {ex}")
254-
if len(errors) == 0:
255-
return None
256-
error = ', '.join(errors)
257-
LOGGER.error(error)
258-
return error
254+
error = ', '.join(errors) if len(errors) > 0 else None
255+
warning = ', '.join(warnings) if len(warnings) > 0 else None
256+
LOGGER.error(f'Errors: {error}, warnings: {warning}')
257+
return error, warning
259258

260259
@classmethod
261260
@allure.step('Wait YDB alive')
262261
def wait_ydb_alive(cls, timeout=10, balanced_paths=None):
263262
deadline = time() + timeout
264263
error = None
265264
while time() < deadline:
266-
error = cls.check_if_ydb_alive(deadline - time(), balanced_paths=balanced_paths)
267-
if error is None:
265+
error, warning = cls.check_if_ydb_alive(deadline - time(), balanced_paths=balanced_paths)
266+
if error is None and warning is None:
268267
break
269268
sleep(1)
270269
return error

ydb/tests/olap/scenario/helpers/scenario_tests_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def check_if_ydb_alive(timeout: float = 10) -> bool:
320320
assert sth.check_if_ydb_alive()
321321
"""
322322

323-
return YdbCluster.check_if_ydb_alive(timeout) is None
323+
return YdbCluster.check_if_ydb_alive(timeout)[0] is None
324324

325325
def execute_scheme_query(
326326
self,

0 commit comments

Comments
 (0)