Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit e8ea4d9

Browse files
committed
AtomicCounter update
1 parent 7988ffa commit e8ea4d9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

google/cloud/spanner_v1/_helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ def __radd__(self, n):
699699
"""
700700
return self.__add__(n)
701701

702+
def reset(self):
703+
with self.__lock:
704+
self.__value = 0
705+
702706

703707
def _metadata_with_request_id(*args, **kwargs):
704708
return with_request_id(*args, **kwargs)

google/cloud/spanner_v1/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
except ImportError: # pragma: NO COVER
7171
HAS_GOOGLE_CLOUD_MONITORING_INSTALLED = False
7272

73+
from google.cloud.spanner_v1._helpers import AtomicCounter
7374

7475
_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)
7576
EMULATOR_ENV_VAR = "SPANNER_EMULATOR_HOST"
@@ -182,6 +183,8 @@ class Client(ClientWithProject):
182183
SCOPE = (SPANNER_ADMIN_SCOPE,)
183184
"""The scopes required for Google Cloud Spanner."""
184185

186+
NTH_CLIENT = AtomicCounter()
187+
185188
def __init__(
186189
self,
187190
project=None,
@@ -261,6 +264,12 @@ def __init__(
261264
"default_transaction_options must be an instance of DefaultTransactionOptions"
262265
)
263266
self._default_transaction_options = default_transaction_options
267+
self._nth_client_id = Client.NTH_CLIENT.increment()
268+
self._nth_request = AtomicCounter(0)
269+
270+
@property
271+
def _next_nth_request(self):
272+
return self._nth_request.increment()
264273

265274
@property
266275
def credentials(self):

0 commit comments

Comments
 (0)