-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Report
YDB Python SDK version:
Environment
Environment is irrelevant for reproduction - issue is in code example
Current behavior:
In the transactional topic write example (topic_transactions_async_example.py
):
- Each call to
tx_writer
without explicitproducer_id
generates a new random producer_id - Transaction retries create additional producer_ids
- This rapidly consumes the producer_id limit (100K per 14 days)
- The example encourages production-unsafe usage patterns
Expected behavior:
Examples should demonstrate best practices:
- Explicit
producer_id
should be used to avoid random ID generation - Example should be resilient to transaction retries
- Should show either fixed producer_id or partition_id usage
- Should not risk exhausting producer_id limits in production scenarios
Steps to reproduce:
- Use example from
topic_transactions_async_example.py
- Run
write_with_tx_example
method in a loop or with frequent retries - Observe rapid growth of producer_ids in the topic
Related code:
https://github.com/ydb-platform/ydb-python-sdk/blob/main/examples/topic/topic_transactions_async_example.py#L28
async def write_with_tx_example(driver: ydb.aio.Driver, topic: str, message_count: int = 10):
async with ydb.aio.QuerySessionPool(driver) as session_pool:
async def callee(tx: ydb.aio.QueryTxContext):
tx_writer: ydb.TopicTxWriterAsyncIO = driver.topic_client.tx_writer(tx, topic)
for i in range(message_count):
async with await tx.execute(query=f"select {i} as res;") as result_stream:
async for result_set in result_stream:
message = str(result_set.rows[0]["res"])
await tx_writer.write(ydb.TopicWriterMessage(message))
print(f"Message {result_set.rows[0]['res']} was written with tx.")
await session_pool.retry_tx_async(callee)
Other information:
Current example can exhaust 100K producer_id limit under moderate load
Possible Solutions
Fixed producer_id
Explicit partition selection
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working