| 1726 | |
| 1727 | |
| 1728 | class TransactionConfig: |
| 1729 | _TXN_ALLOWED_KEYS = {"durability", "cleanup_window", "timeout", |
| 1730 | "expiration_time", "cleanup_lost_attempts", "cleanup_client_attempts", |
| 1731 | "metadata_collection", "scan_consistency"} |
| 1732 | |
| 1733 | @overload |
| 1734 | def __init__(self, |
| 1735 | durability=None, # type: Optional[ServerDurability] |
| 1736 | cleanup_window=None, # type: Optional[timedelta] |
| 1737 | kv_timeout=None, # type: Optional[timedelta] |
| 1738 | expiration_time=None, # type: Optional[timedelta] |
| 1739 | cleanup_lost_attempts=None, # type: Optional[bool] |
| 1740 | cleanup_client_attempts=None, # type: Optional[bool] |
| 1741 | metadata_collection=None, # type: Optional[TransactionKeyspace] |
| 1742 | scan_consistency=None # type: Optional[QueryScanConsistency] |
| 1743 | ): |
| 1744 | """ |
| 1745 | Configuration for Transactions. |
| 1746 | |
| 1747 | Args: |
| 1748 | durability (:class:`ServerDurability`, optional): Desired durability level for all transaction operations. |
| 1749 | cleanup_window (timedelta, optional): The query metadata is cleaned up over a the cleanup_window. |
| 1750 | Longer windows mean less background activity, shorter intervals will clean things faster. |
| 1751 | kv_timeout: (timedelta, optional): **DEPRECATED** Currently a no-op. KV operation timeout. |
| 1752 | expiration_time: (timedelta, optional): **DEPRECATED** Use timeout instead. Maximum amount of time a transaction can take before rolling back. |
| 1753 | cleanup_lost_attempts: (bool, optional): If False, then we don't do any background cleanup. |
| 1754 | cleanup_client_attempts: (bool, optional): if False, we don't do any cleanup as a transaction finishes. |
| 1755 | metadata_collection: (:class:`couchbase.transactions.TransactionKeyspace, optional): All transaction |
| 1756 | metadata uses the specified bucket/scope/collection. |
| 1757 | scan_consistency: (:class:`QueryScanConsistency`, optional): Scan consistency to use for all transactional |
| 1758 | queries. |
| 1759 | timeout: (timedelta, optional): Maximum amount of time a transaction can take before rolling back. |
| 1760 | """ # noqa: E501 |
| 1761 | |
| 1762 | def __init__(self, # noqa: C901 |
| 1763 | **kwargs # type: dict[str, Any] |
| 1764 | ): # noqa: C901 |
| 1765 | # CXXCBC-391: Adds support for ExtSDKIntegration which removes kv_timeout, the cluster kv_durable |
| 1766 | # timeout is used internally |
| 1767 | if 'kv_timeout' in kwargs: |
| 1768 | kwargs.pop('kv_timeout') |
| 1769 | Supportability.option_deprecated('kv_timeout') |
| 1770 | kwargs = {k: v for k, v in kwargs.items() if k in TransactionConfig._TXN_ALLOWED_KEYS} |
| 1771 | # convert everything here... |
| 1772 | durability = kwargs.pop("durability", None) |
| 1773 | if durability: |
| 1774 | kwargs["durability_level"] = durability.level.value |
| 1775 | if kwargs.get('cleanup_window', None): |
| 1776 | kwargs['cleanup_window'] = int(kwargs['cleanup_window'].total_seconds() * 1e6) |
| 1777 | coll = kwargs.pop("metadata_collection", None) |
| 1778 | # CXXCBC-391: Adds support for ExtSDKIntegration which changes expiration_time -> timeout |
| 1779 | if 'expiration_time' in kwargs or 'timeout' in kwargs: |
| 1780 | Supportability.option_deprecated('expiration_time', 'timeout') |
| 1781 | timeout = kwargs.pop('expiration_time', None) |
| 1782 | # if timeout is also in the options, override expiration_time |
| 1783 | if 'timeout' in kwargs: |
| 1784 | timeout = kwargs.get('timeout', None) |
| 1785 | if timeout: |
no outgoing calls