|
| 1 | +import datetime |
| 2 | +import logging |
| 3 | +import os |
| 4 | +import pytest |
| 5 | +import random |
| 6 | +import yatest.common |
| 7 | +import ydb |
| 8 | + |
| 9 | +from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator |
| 10 | +from ydb.tests.library.harness.kikimr_runner import KiKiMR |
| 11 | +from ydb.tests.library.test_meta import link_test_case |
| 12 | +from ydb.tests.olap.common.ydb_client import YdbClient |
| 13 | + |
| 14 | +logger = logging.getLogger(__name__) |
| 15 | + |
| 16 | + |
| 17 | +class TestOverlappingPortions(object): |
| 18 | + test_name = "overlapping_portions" |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def setup_class(cls): |
| 22 | + ydb_path = yatest.common.build_path(os.environ.get("YDB_DRIVER_BINARY")) |
| 23 | + logger.info(yatest.common.execute([ydb_path, "-V"], wait=True).stdout.decode("utf-8")) |
| 24 | + config = KikimrConfigGenerator( |
| 25 | + column_shard_config={"compaction_enabled": False}, |
| 26 | + grouped_memory_limiter_config={ |
| 27 | + "enabled": True, |
| 28 | + "memory_limit": 100 * 1024 * 1024, |
| 29 | + "hard_memory_limit": 100 * 1024 * 1024, |
| 30 | + }, |
| 31 | + ) |
| 32 | + cls.cluster = KiKiMR(config) |
| 33 | + cls.cluster.start() |
| 34 | + node = cls.cluster.nodes[1] |
| 35 | + cls.ydb_client = YdbClient(database=f"/{config.domain_name}", endpoint=f"grpc://{node.host}:{node.port}") |
| 36 | + cls.ydb_client.wait_connection() |
| 37 | + |
| 38 | + def write_data( |
| 39 | + self, |
| 40 | + table: str, |
| 41 | + timestamp_from_ms: int, |
| 42 | + rows: int, |
| 43 | + value: int = 1, |
| 44 | + ): |
| 45 | + column_types = ydb.BulkUpsertColumns() |
| 46 | + column_types.add_column("ts", ydb.PrimitiveType.Timestamp) |
| 47 | + column_types.add_column("s", ydb.PrimitiveType.String) |
| 48 | + column_types.add_column("val", ydb.PrimitiveType.Uint64) |
| 49 | + |
| 50 | + chunk_size = 100 |
| 51 | + while rows: |
| 52 | + current_chunk_size = min(chunk_size, rows) |
| 53 | + data = [ |
| 54 | + { |
| 55 | + "ts": timestamp_from_ms + i, |
| 56 | + "s": random.randbytes(1024 * 10), |
| 57 | + "val": value, |
| 58 | + } |
| 59 | + for i in range(current_chunk_size) |
| 60 | + ] |
| 61 | + self.ydb_client.bulk_upsert( |
| 62 | + table, |
| 63 | + column_types, |
| 64 | + data, |
| 65 | + ) |
| 66 | + timestamp_from_ms += current_chunk_size |
| 67 | + rows -= current_chunk_size |
| 68 | + assert rows >= 0 |
| 69 | + |
| 70 | + def write_and_check(self, table_path, count): |
| 71 | + ts_start = int(datetime.datetime.now().timestamp() * 1000000) |
| 72 | + for value in range(count): |
| 73 | + self.write_data(table_path, ts_start, 100, value) |
| 74 | + |
| 75 | + self.ydb_client.query( |
| 76 | + f""" |
| 77 | + select * from `{table_path}` |
| 78 | + """ |
| 79 | + ) |
| 80 | + |
| 81 | + @link_test_case("#15512") |
| 82 | + def test(self): |
| 83 | + test_dir = f"{self.ydb_client.database}/{self.test_name}" |
| 84 | + table_path = f"{test_dir}/table" |
| 85 | + |
| 86 | + self.ydb_client.query( |
| 87 | + f""" |
| 88 | + CREATE TABLE `{table_path}` ( |
| 89 | + ts Timestamp NOT NULL, |
| 90 | + s String, |
| 91 | + val Uint64, |
| 92 | + PRIMARY KEY(ts), |
| 93 | + ) |
| 94 | + WITH ( |
| 95 | + STORE = COLUMN, |
| 96 | + AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1 |
| 97 | + ) |
| 98 | + """ |
| 99 | + ) |
| 100 | + |
| 101 | + self.write_and_check(table_path, 1) |
| 102 | + |
| 103 | + with pytest.raises(ydb.issues.GenericError, match=r'.*cannot allocate memory.*'): |
| 104 | + self.write_and_check(table_path, 100) |
0 commit comments