|
4 | 4 | import logging |
5 | 5 | import yatest.common |
6 | 6 | import ydb |
| 7 | +import random |
7 | 8 |
|
8 | 9 | from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator |
9 | 10 | from ydb.tests.library.harness.kikimr_runner import KiKiMR |
@@ -103,6 +104,20 @@ def _setup_ydb(cls, writing_in_flight_requests_count_limit, writing_in_flight_re |
103 | 104 | cls.ydb_client = YdbClient(endpoint=f"grpc://{node.host}:{node.port}", database=f"/{config.domain_name}") |
104 | 105 | cls.ydb_client.wait_connection(timeout=60) |
105 | 106 |
|
| 107 | + @classmethod |
| 108 | + def _setup_ydb_rp(cls): |
| 109 | + ydb_path = yatest.common.build_path(os.environ.get("YDB_DRIVER_BINARY")) |
| 110 | + logger.info(yatest.common.execute([ydb_path, "-V"], wait=True).stdout.decode("utf-8")) |
| 111 | + config = KikimrConfigGenerator( |
| 112 | + extra_feature_flags={"enable_olap_reject_probability": True}, |
| 113 | + memory_controller_config={"max_tx_in_fly": 0}, |
| 114 | + ) |
| 115 | + cls.cluster = KiKiMR(config) |
| 116 | + cls.cluster.start() |
| 117 | + node = cls.cluster.nodes[1] |
| 118 | + cls.ydb_client = YdbClient(endpoint=f"grpc://{node.host}:{node.port}", database=f"/{config.domain_name}") |
| 119 | + cls.ydb_client.wait_connection(timeout=60) |
| 120 | + |
106 | 121 | def get_row_count(self) -> int: |
107 | 122 | return self.ydb_client.query(f"select count(*) as Rows from `{self.table_name}`")[0].rows[0]["Rows"] |
108 | 123 |
|
@@ -156,6 +171,7 @@ def test_overloads_bulk_upsert(self, writing_in_flight_requests_count_limit, wri |
156 | 171 | @pytest.mark.parametrize('writing_in_flight_requests_count_limit, writing_in_flight_request_bytes_limit', [(1, 10000), (2, 10000), (1000, 1), (1000, 2), (1, 1), (2, 2)]) |
157 | 172 | def test_overloads_workload(self, writing_in_flight_requests_count_limit, writing_in_flight_request_bytes_limit): |
158 | 173 | self._setup_ydb(writing_in_flight_requests_count_limit, writing_in_flight_request_bytes_limit) |
| 174 | + |
159 | 175 | wait_time: int = 60 |
160 | 176 | self.table_name: str = f"log_{writing_in_flight_requests_count_limit}_{writing_in_flight_request_bytes_limit}" |
161 | 177 |
|
@@ -191,3 +207,55 @@ def test_overloads_workload(self, writing_in_flight_requests_count_limit, writin |
191 | 207 |
|
192 | 208 | logging.info(f"Count rows after insert {self.get_row_count()}") |
193 | 209 | assert self.get_row_count() != 0 |
| 210 | + |
| 211 | + def test_overloads_reject_probability(self): |
| 212 | + self._setup_ydb_rp() |
| 213 | + |
| 214 | + table_path = f"{self.ydb_client.database}/table_for_test_overloads_reject_probability" |
| 215 | + self.ydb_client.query( |
| 216 | + f""" |
| 217 | + CREATE TABLE `{table_path}` ( |
| 218 | + id Uint64 NOT NULL, |
| 219 | + v1 Int64, |
| 220 | + v2 Int64, |
| 221 | + PRIMARY KEY(id), |
| 222 | + ) |
| 223 | + WITH ( |
| 224 | + STORE = COLUMN, |
| 225 | + PARTITION_COUNT = 1, |
| 226 | + AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1 |
| 227 | + ) |
| 228 | + """ |
| 229 | + ) |
| 230 | + |
| 231 | + column_types = ydb.BulkUpsertColumns() |
| 232 | + column_types.add_column("id", ydb.PrimitiveType.Uint64) |
| 233 | + column_types.add_column("v1", ydb.PrimitiveType.Int64) |
| 234 | + column_types.add_column("v2", ydb.PrimitiveType.Int64) |
| 235 | + |
| 236 | + rows_count = 1000 |
| 237 | + |
| 238 | + data = [ |
| 239 | + { |
| 240 | + "id": i, |
| 241 | + "v1": 1, |
| 242 | + "v2": -1, |
| 243 | + } |
| 244 | + for i in range(rows_count) |
| 245 | + ] |
| 246 | + |
| 247 | + self.ydb_client.bulk_upsert(table_path, column_types, data) |
| 248 | + |
| 249 | + futures = [] |
| 250 | + |
| 251 | + for _ in range(19): |
| 252 | + lb = random.randint(0, rows_count) |
| 253 | + futures.append(self.ydb_client.query_async(f"UPDATE `{table_path}` SET v1 = v1 + 1, v2 = v2 - 1 WHERE id > {lb};")) |
| 254 | + |
| 255 | + for future in futures: |
| 256 | + future.result() |
| 257 | + |
| 258 | + monitor = self.cluster.monitors[0].fetch() |
| 259 | + _, rejectProbabilityCount = monitor.get_by_name('Deriviative/Overload/RejectProbability/Count')[0] |
| 260 | + |
| 261 | + assert rejectProbabilityCount > 0 |
0 commit comments