Skip to content

Commit f974823

Browse files
feat: add generated sync client (#1017)
1 parent 1193530 commit f974823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+8448
-55
lines changed

.cross_sync/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ CrossSync provides a set of annotations to mark up async classes, to guide the g
6262

6363
### Code Generation
6464

65-
Generation can be initiated using `python .cross_sync/generate.py .`
65+
Generation can be initiated using `nox -s generate_sync`
6666
from the root of the project. This will find all classes with the `__CROSS_SYNC_OUTPUT__ = "path/to/output"`
6767
annotation, and generate a sync version of classes marked with `@CrossSync.convert_sync` at the output path.
6868

docs/async_data_client/async_data_usage.rst

-18
This file was deleted.

docs/async_data_client/async_data_client.rst renamed to docs/data_client/async_data_client.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Bigtable Data Client Async
77
performance benefits, the codebase should be designed to be async from the ground up.
88

99

10-
.. autoclass:: google.cloud.bigtable.data._async.client.BigtableDataClientAsync
10+
.. autoclass:: google.cloud.bigtable.data.BigtableDataClientAsync
1111
:members:
1212
:show-inheritance:
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Data Client
2+
===========
3+
4+
Sync Surface
5+
------------
6+
7+
.. toctree::
8+
:maxdepth: 3
9+
10+
sync_data_client
11+
sync_data_table
12+
sync_data_mutations_batcher
13+
sync_data_execute_query_iterator
14+
15+
Async Surface
16+
-------------
17+
18+
.. toctree::
19+
:maxdepth: 3
20+
21+
async_data_client
22+
async_data_table
23+
async_data_mutations_batcher
24+
async_data_execute_query_iterator
25+
26+
Common Classes
27+
--------------
28+
29+
.. toctree::
30+
:maxdepth: 3
31+
32+
common_data_read_rows_query
33+
common_data_row
34+
common_data_row_filters
35+
common_data_mutations
36+
common_data_read_modify_write_rules
37+
common_data_exceptions
38+
common_data_execute_query_values
39+
common_data_execute_query_metadata

docs/data_client/sync_data_client.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bigtable Data Client
2+
~~~~~~~~~~~~~~~~~~~~
3+
4+
.. autoclass:: google.cloud.bigtable.data.BigtableDataClient
5+
:members:
6+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Execute Query Iterator
2+
~~~~~~~~~~~~~~~~~~~~~~
3+
4+
.. autoclass:: google.cloud.bigtable.data.execute_query.ExecuteQueryIterator
5+
:members:
6+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Mutations Batcher
2+
~~~~~~~~~~~~~~~~~
3+
4+
.. automodule:: google.cloud.bigtable.data._sync_autogen.mutations_batcher
5+
:members:
6+
:show-inheritance:

docs/data_client/sync_data_table.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Table
2+
~~~~~
3+
4+
.. autoclass:: google.cloud.bigtable.data.Table
5+
:members:
6+
:show-inheritance:

docs/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Client Types
66
-------------
77
.. toctree::
8-
:maxdepth: 2
8+
:maxdepth: 3
99

10+
data_client/data_client_usage
1011
classic_client/usage
11-
async_data_client/async_data_usage
1212

1313

1414
Changelog

docs/scripts/patch_devsite_toc.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def __init__(self, dir_name, index_file_name):
117117
continue
118118
# bail when toc indented block is done
119119
if not line.startswith(" ") and not line.startswith("\t"):
120-
break
120+
in_toc = False
121+
continue
121122
# extract entries
122123
self.items.append(self.extract_toc_entry(line.strip()))
123124

@@ -194,9 +195,7 @@ def validate_toc(toc_file_path, expected_section_list, added_sections):
194195
# Add secrtions for the async_data_client and classic_client directories
195196
toc_path = "_build/html/docfx_yaml/toc.yml"
196197
custom_sections = [
197-
TocSection(
198-
dir_name="async_data_client", index_file_name="async_data_usage.rst"
199-
),
198+
TocSection(dir_name="data_client", index_file_name="data_client_usage.rst"),
200199
TocSection(dir_name="classic_client", index_file_name="usage.rst"),
201200
]
202201
add_sections(toc_path, custom_sections)
@@ -210,7 +209,7 @@ def validate_toc(toc_file_path, expected_section_list, added_sections):
210209
"bigtable APIs",
211210
"Changelog",
212211
"Multiprocessing",
213-
"Async Data Client",
212+
"Data Client",
214213
"Classic Client",
215214
],
216215
added_sections=custom_sections,

google/cloud/bigtable/data/__init__.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
from google.cloud.bigtable.data._async.client import BigtableDataClientAsync
1919
from google.cloud.bigtable.data._async.client import TableAsync
20-
2120
from google.cloud.bigtable.data._async.mutations_batcher import MutationsBatcherAsync
21+
from google.cloud.bigtable.data._sync_autogen.client import BigtableDataClient
22+
from google.cloud.bigtable.data._sync_autogen.client import Table
23+
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import MutationsBatcher
2224

2325
from google.cloud.bigtable.data.read_rows_query import ReadRowsQuery
2426
from google.cloud.bigtable.data.read_rows_query import RowRange
@@ -52,20 +54,32 @@
5254
from google.cloud.bigtable.data._async._read_rows import _ReadRowsOperationAsync
5355
from google.cloud.bigtable.data._async._mutate_rows import _MutateRowsOperationAsync
5456

57+
from google.cloud.bigtable_v2.services.bigtable.client import (
58+
BigtableClient,
59+
)
60+
from google.cloud.bigtable.data._sync_autogen._read_rows import _ReadRowsOperation
61+
from google.cloud.bigtable.data._sync_autogen._mutate_rows import _MutateRowsOperation
62+
5563
from google.cloud.bigtable.data._cross_sync import CrossSync
5664

5765
CrossSync.add_mapping("GapicClient", BigtableAsyncClient)
66+
CrossSync._Sync_Impl.add_mapping("GapicClient", BigtableClient)
5867
CrossSync.add_mapping("_ReadRowsOperation", _ReadRowsOperationAsync)
68+
CrossSync._Sync_Impl.add_mapping("_ReadRowsOperation", _ReadRowsOperation)
5969
CrossSync.add_mapping("_MutateRowsOperation", _MutateRowsOperationAsync)
70+
CrossSync._Sync_Impl.add_mapping("_MutateRowsOperation", _MutateRowsOperation)
6071
CrossSync.add_mapping("MutationsBatcher", MutationsBatcherAsync)
61-
72+
CrossSync._Sync_Impl.add_mapping("MutationsBatcher", MutationsBatcher)
6273

6374
__version__: str = package_version.__version__
6475

6576
__all__ = (
6677
"BigtableDataClientAsync",
6778
"TableAsync",
6879
"MutationsBatcherAsync",
80+
"BigtableDataClient",
81+
"Table",
82+
"MutationsBatcher",
6983
"RowKeySamples",
7084
"ReadRowsQuery",
7185
"RowRange",

google/cloud/bigtable/data/_async/_mutate_rows.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

google/cloud/bigtable/data/_async/_read_rows.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

google/cloud/bigtable/data/_async/client.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -85,8 +85,10 @@
8585
)
8686
from google.cloud.bigtable.data._async.mutations_batcher import _MB_SIZE
8787
else:
88+
from typing import Iterable # noqa: F401
8889
from grpc import insecure_channel
8990
from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport as TransportType # type: ignore
91+
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE
9092

9193

9294
if TYPE_CHECKING:
@@ -100,6 +102,13 @@
100102
from google.cloud.bigtable.data.execute_query._async.execute_query_iterator import (
101103
ExecuteQueryIteratorAsync,
102104
)
105+
else:
106+
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import ( # noqa: F401
107+
MutationsBatcher,
108+
)
109+
from google.cloud.bigtable.data.execute_query._sync_autogen.execute_query_iterator import ( # noqa: F401
110+
ExecuteQueryIterator,
111+
)
103112

104113

105114
__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen.client"

google/cloud/bigtable/data/_async/mutations_batcher.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
#
1515
from __future__ import annotations
1616

17-
from typing import Sequence, TYPE_CHECKING
17+
from typing import Sequence, TYPE_CHECKING, cast
1818
import atexit
1919
import warnings
2020
from collections import deque
@@ -250,7 +250,7 @@ def __init__(
250250
)
251251
# used by sync class to manage flush_internal tasks
252252
self._sync_flush_executor = (
253-
concurrent.futures.ThreadPoolExecutor(max_workers=1)
253+
concurrent.futures.ThreadPoolExecutor(max_workers=4)
254254
if not CrossSync.is_async
255255
else None
256256
)
@@ -305,7 +305,7 @@ async def append(self, mutation_entry: RowMutationEntry):
305305
# TODO: return a future to track completion of this entry
306306
if self._closed.is_set():
307307
raise RuntimeError("Cannot append to closed MutationsBatcher")
308-
if isinstance(mutation_entry, Mutation): # type: ignore
308+
if isinstance(cast(Mutation, mutation_entry), Mutation):
309309
raise ValueError(
310310
f"invalid mutation type: {type(mutation_entry).__name__}. Only RowMutationEntry objects are supported by batcher"
311311
)

google/cloud/bigtable/data/_helpers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
if TYPE_CHECKING:
3030
import grpc
3131
from google.cloud.bigtable.data import TableAsync
32+
from google.cloud.bigtable.data import Table
3233

3334
"""
3435
Helper functions used in various places in the library.
@@ -120,7 +121,7 @@ def _retry_exception_factory(
120121
def _get_timeouts(
121122
operation: float | TABLE_DEFAULT,
122123
attempt: float | None | TABLE_DEFAULT,
123-
table: "TableAsync",
124+
table: "TableAsync" | "Table",
124125
) -> tuple[float, float]:
125126
"""
126127
Convert passed in timeout values to floats, using table defaults if necessary.
@@ -207,7 +208,7 @@ def _get_error_type(
207208

208209
def _get_retryable_errors(
209210
call_codes: Sequence["grpc.StatusCode" | int | type[Exception]] | TABLE_DEFAULT,
210-
table: "TableAsync",
211+
table: "TableAsync" | "Table",
211212
) -> list[type[Exception]]:
212213
"""
213214
Convert passed in retryable error codes to a list of exception types.

0 commit comments

Comments
 (0)