Hi,
We found that if the log level of the root logger is set to DEBUG, transactions hang indefinitely. I inserted a simple script to trigger the behavior. The document shouldn’t exist before running the script so the code will go to transaction branch.
import datetime
import logging.config
import sys
import couchbase
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster
from couchbase.exceptions import (
DocumentExistsException,
DocumentNotFoundException,
)
from couchbase.options import ClusterOptions
from couchbase.transactions import AttemptContext
COUCHBASE_CLUSTER = 'couchbase://localhost'
COUCHBASE_BUCKET = 'control'
COUCHBASE_USERNAME = 'Administrator'
COUCHBASE_PASSWORD = 'password'
def run_dummy_transaction():
# Initialize the Couchbase cluster
cluster = Cluster(COUCHBASE_CLUSTER, ClusterOptions(
PasswordAuthenticator(COUCHBASE_USERNAME, COUCHBASE_PASSWORD)
))
bucket = cluster.bucket(COUCHBASE_BUCKET)
collection = bucket.default_collection()
doc_id = 'dummy-doc'
doc_content = {'name': 'dummy', 'type': 'test'}
try:
collection.get_and_lock(doc_id, datetime.timedelta(seconds=15))
except DocumentNotFoundException:
def txn_logic(ctx: AttemptContext):
try:
ctx.insert(collection, doc_id, doc_content)
except DocumentExistsException:
pass
cluster.transactions.run(txn_logic)
logging.debug("Transaction committed successfully.")
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
run_dummy_transaction()
Setting the log level to INFO solves the problem. Another solution is creating a different logger and configure the SDK to use that logger, as follows:
dummy_logger = logging.getLogger('cb')
dummy_logger.propagate = False
couchbase.configure_logging(dummy_logger.name, dummy_logger.level)
I wonder if we are doing something wrong, or if there is a side effect that we couldn’t identified.
Environment:
- Couchbase Server Community 7.6.2
- Couchbase SDK v4.3.0
- Python 3.11.9