Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 27dfdca

Browse files
feat(v1): Support Multiple Read Replicas when creating Instance (#135)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 408360267 Source-Link: googleapis/googleapis@8625cf0 Source-Link: https://github.com/googleapis/googleapis-gen/commit/d84247808680a19dec0d3f3b52a28e2d3050beaf Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDg0MjQ3ODA4NjgwYTE5ZGVjMGQzZjNiNTJhMjhlMmQzMDUwYmVhZiJ9
1 parent 05fdc79 commit 27dfdca

File tree

9 files changed

+112
-35
lines changed

9 files changed

+112
-35
lines changed

google/cloud/redis/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from google.cloud.redis_v1.types.cloud_redis import ListInstancesRequest
3333
from google.cloud.redis_v1.types.cloud_redis import ListInstancesResponse
3434
from google.cloud.redis_v1.types.cloud_redis import LocationMetadata
35+
from google.cloud.redis_v1.types.cloud_redis import NodeInfo
3536
from google.cloud.redis_v1.types.cloud_redis import OperationMetadata
3637
from google.cloud.redis_v1.types.cloud_redis import OutputConfig
3738
from google.cloud.redis_v1.types.cloud_redis import UpdateInstanceRequest
@@ -54,6 +55,7 @@
5455
"ListInstancesRequest",
5556
"ListInstancesResponse",
5657
"LocationMetadata",
58+
"NodeInfo",
5759
"OperationMetadata",
5860
"OutputConfig",
5961
"UpdateInstanceRequest",

google/cloud/redis_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .types.cloud_redis import ListInstancesRequest
3131
from .types.cloud_redis import ListInstancesResponse
3232
from .types.cloud_redis import LocationMetadata
33+
from .types.cloud_redis import NodeInfo
3334
from .types.cloud_redis import OperationMetadata
3435
from .types.cloud_redis import OutputConfig
3536
from .types.cloud_redis import UpdateInstanceRequest
@@ -52,6 +53,7 @@
5253
"ListInstancesRequest",
5354
"ListInstancesResponse",
5455
"LocationMetadata",
56+
"NodeInfo",
5557
"OperationMetadata",
5658
"OutputConfig",
5759
"UpdateInstanceRequest",

google/cloud/redis_v1/services/cloud_redis/async_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ async def update_instance(
497497
- ``labels``
498498
- ``memorySizeGb``
499499
- ``redisConfig``
500+
- ``replica_count``
500501
501502
This corresponds to the ``update_mask`` field
502503
on the ``request`` instance; if ``request`` is provided, this
@@ -874,7 +875,7 @@ async def failover_instance(
874875
timeout: float = None,
875876
metadata: Sequence[Tuple[str, str]] = (),
876877
) -> operation_async.AsyncOperation:
877-
r"""Initiates a failover of the master node to current
878+
r"""Initiates a failover of the primary node to current
878879
replica node for a specific STANDARD tier Cloud
879880
Memorystore for Redis instance.
880881

google/cloud/redis_v1/services/cloud_redis/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ def update_instance(
687687
- ``labels``
688688
- ``memorySizeGb``
689689
- ``redisConfig``
690+
- ``replica_count``
690691
691692
This corresponds to the ``update_mask`` field
692693
on the ``request`` instance; if ``request`` is provided, this
@@ -1064,7 +1065,7 @@ def failover_instance(
10641065
timeout: float = None,
10651066
metadata: Sequence[Tuple[str, str]] = (),
10661067
) -> operation.Operation:
1067-
r"""Initiates a failover of the master node to current
1068+
r"""Initiates a failover of the primary node to current
10681069
replica node for a specific STANDARD tier Cloud
10691070
Memorystore for Redis instance.
10701071

google/cloud/redis_v1/services/cloud_redis/transports/grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def failover_instance(
492492
) -> Callable[[cloud_redis.FailoverInstanceRequest], operations_pb2.Operation]:
493493
r"""Return a callable for the failover instance method over gRPC.
494494
495-
Initiates a failover of the master node to current
495+
Initiates a failover of the primary node to current
496496
replica node for a specific STANDARD tier Cloud
497497
Memorystore for Redis instance.
498498

google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def failover_instance(
508508
]:
509509
r"""Return a callable for the failover instance method over gRPC.
510510
511-
Initiates a failover of the master node to current
511+
Initiates a failover of the primary node to current
512512
replica node for a specific STANDARD tier Cloud
513513
Memorystore for Redis instance.
514514

google/cloud/redis_v1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ListInstancesRequest,
2828
ListInstancesResponse,
2929
LocationMetadata,
30+
NodeInfo,
3031
OperationMetadata,
3132
OutputConfig,
3233
UpdateInstanceRequest,
@@ -48,6 +49,7 @@
4849
"ListInstancesRequest",
4950
"ListInstancesResponse",
5051
"LocationMetadata",
52+
"NodeInfo",
5153
"OperationMetadata",
5254
"OutputConfig",
5355
"UpdateInstanceRequest",

google/cloud/redis_v1/types/cloud_redis.py

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
__protobuf__ = proto.module(
2323
package="google.cloud.redis.v1",
2424
manifest={
25+
"NodeInfo",
2526
"Instance",
2627
"ListInstancesRequest",
2728
"ListInstancesResponse",
@@ -44,6 +45,21 @@
4445
)
4546

4647

48+
class NodeInfo(proto.Message):
49+
r"""Node specific properties.
50+
51+
Attributes:
52+
id (str):
53+
Output only. Node identifying string. e.g.
54+
'node-0', 'node-1'
55+
zone (str):
56+
Output only. Location of the node.
57+
"""
58+
59+
id = proto.Field(proto.STRING, number=1,)
60+
zone = proto.Field(proto.STRING, number=2,)
61+
62+
4763
class Instance(proto.Message):
4864
r"""A Google Cloud Redis instance.
4965
@@ -69,19 +85,21 @@ class Instance(proto.Message):
6985
Resource labels to represent user provided
7086
metadata
7187
location_id (str):
72-
Optional. The zone where the instance will be provisioned.
73-
If not provided, the service will choose a zone for the
74-
instance. For STANDARD_HA tier, instances will be created
75-
across two zones for protection against zonal failures. If
76-
[alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id]
77-
is also provided, it must be different from
78-
[location_id][google.cloud.redis.v1.Instance.location_id].
88+
Optional. The zone where the instance will be
89+
provisioned. If not provided, the service will
90+
choose a zone from the specified region for the
91+
instance. For standard tier, additional nodes
92+
will be added across multiple zones for
93+
protection against zonal failures. If specified,
94+
at least one node will be provisioned in this
95+
zone.
7996
alternative_location_id (str):
80-
Optional. Only applicable to STANDARD_HA tier which protects
81-
the instance against zonal failures by provisioning it
82-
across two zones. If provided, it must be a different zone
83-
from the one provided in
84-
[location_id][google.cloud.redis.v1.Instance.location_id].
97+
Optional. If specified, at least one node will be
98+
provisioned in this zone in addition to the zone specified
99+
in location_id. Only applicable to standard tier. If
100+
provided, it must be a different zone from the one provided
101+
in [location_id]. Additional nodes beyond the first 2 will
102+
be placed in zones selected by the service.
85103
redis_version (str):
86104
Optional. The version of Redis software. If not provided,
87105
latest supported version will be used. Currently, the
@@ -90,14 +108,17 @@ class Instance(proto.Message):
90108
- ``REDIS_3_2`` for Redis 3.2 compatibility
91109
- ``REDIS_4_0`` for Redis 4.0 compatibility (default)
92110
- ``REDIS_5_0`` for Redis 5.0 compatibility
111+
- ``REDIS_6_X`` for Redis 6.x compatibility
93112
reserved_ip_range (str):
94-
Optional. The CIDR range of internal
95-
addresses that are reserved for this instance.
96-
If not provided, the service will choose an
97-
unused /29 block, for example, 10.0.0.0/29 or
98-
192.168.0.0/29. Ranges must be unique and non-
99-
overlapping with existing subnets in an
100-
authorized network.
113+
Optional. For DIRECT_PEERING mode, the CIDR range of
114+
internal addresses that are reserved for this instance.
115+
Range must be unique and non-overlapping with existing
116+
subnets in an authorized network. For PRIVATE_SERVICE_ACCESS
117+
mode, the name of one allocated IP address ranges associated
118+
with this private service access connection. If not
119+
provided, the service will choose an unused /29 block, for
120+
example, 10.0.0.0/29 or 192.168.0.0/29. For
121+
READ_REPLICAS_ENABLED the default block size is /28.
101122
host (str):
102123
Output only. Hostname or IP address of the
103124
exposed Redis endpoint used by clients to
@@ -106,15 +127,10 @@ class Instance(proto.Message):
106127
Output only. The port number of the exposed
107128
Redis endpoint.
108129
current_location_id (str):
109-
Output only. The current zone where the Redis endpoint is
110-
placed. For Basic Tier instances, this will always be the
111-
same as the
112-
[location_id][google.cloud.redis.v1.Instance.location_id]
113-
provided by the user at creation time. For Standard Tier
114-
instances, this can be either
115-
[location_id][google.cloud.redis.v1.Instance.location_id] or
116-
[alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id]
117-
and can change after a failover event.
130+
Output only. The current zone where the Redis primary node
131+
is located. In basic tier, this will always be the same as
132+
[location_id]. In standard tier, this can be the zone of any
133+
node in the instance.
118134
create_time (google.protobuf.timestamp_pb2.Timestamp):
119135
Output only. The time the instance was
120136
created.
@@ -163,6 +179,25 @@ class Instance(proto.Message):
163179
connect_mode (google.cloud.redis_v1.types.Instance.ConnectMode):
164180
Optional. The network connect mode of the Redis instance. If
165181
not provided, the connect mode defaults to DIRECT_PEERING.
182+
replica_count (int):
183+
Optional. The number of replica nodes. Valid range for
184+
standard tier is [1-5] and defaults to 1. Valid value for
185+
basic tier is 0 and defaults to 0.
186+
nodes (Sequence[google.cloud.redis_v1.types.NodeInfo]):
187+
Output only. Info per node.
188+
read_endpoint (str):
189+
Output only. Hostname or IP address of the
190+
exposed readonly Redis endpoint. Standard tier
191+
only. Targets all healthy replica nodes in
192+
instance. Replication is asynchronous and
193+
replica nodes will exhibit some lag behind the
194+
primary. Write requests must target 'host'.
195+
read_endpoint_port (int):
196+
Output only. The port number of the exposed
197+
readonly redis endpoint. Standard tier only.
198+
Write requests should target 'port'.
199+
read_replicas_mode (google.cloud.redis_v1.types.Instance.ReadReplicasMode):
200+
Optional. Read replica mode.
166201
"""
167202

168203
class State(proto.Enum):
@@ -189,6 +224,12 @@ class ConnectMode(proto.Enum):
189224
DIRECT_PEERING = 1
190225
PRIVATE_SERVICE_ACCESS = 2
191226

227+
class ReadReplicasMode(proto.Enum):
228+
r"""Read replicas mode."""
229+
READ_REPLICAS_MODE_UNSPECIFIED = 0
230+
READ_REPLICAS_DISABLED = 1
231+
READ_REPLICAS_ENABLED = 2
232+
192233
name = proto.Field(proto.STRING, number=1,)
193234
display_name = proto.Field(proto.STRING, number=2,)
194235
labels = proto.MapField(proto.STRING, proto.STRING, number=3,)
@@ -210,6 +251,11 @@ class ConnectMode(proto.Enum):
210251
authorized_network = proto.Field(proto.STRING, number=20,)
211252
persistence_iam_identity = proto.Field(proto.STRING, number=21,)
212253
connect_mode = proto.Field(proto.ENUM, number=22, enum=ConnectMode,)
254+
replica_count = proto.Field(proto.INT32, number=31,)
255+
nodes = proto.RepeatedField(proto.MESSAGE, number=32, message="NodeInfo",)
256+
read_endpoint = proto.Field(proto.STRING, number=33,)
257+
read_endpoint_port = proto.Field(proto.INT32, number=34,)
258+
read_replicas_mode = proto.Field(proto.ENUM, number=35, enum=ReadReplicasMode,)
213259

214260

215261
class ListInstancesRequest(proto.Message):
@@ -253,9 +299,9 @@ class ListInstancesResponse(proto.Message):
253299
If the ``location_id`` in the parent field of the request is
254300
"-", all regions available to the project are queried, and
255301
the results aggregated. If in such an aggregated query a
256-
location is unavailable, a dummy Redis entry is included in
257-
the response with the ``name`` field set to a value of the
258-
form
302+
location is unavailable, a placeholder Redis entry is
303+
included in the response with the ``name`` field set to a
304+
value of the form
259305
``projects/{project_id}/locations/{location_id}/instances/``-
260306
and the ``status`` field set to ERROR and ``status_message``
261307
field set to "location not available for ListInstances".
@@ -333,6 +379,7 @@ class UpdateInstanceRequest(proto.Message):
333379
- ``labels``
334380
- ``memorySizeGb``
335381
- ``redisConfig``
382+
- ``replica_count``
336383
instance (google.cloud.redis_v1.types.Instance):
337384
Required. Update description. Only fields specified in
338385
update_mask are updated.

tests/unit/gapic/redis_v1/test_cloud_redis.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ def test_get_instance(
842842
authorized_network="authorized_network_value",
843843
persistence_iam_identity="persistence_iam_identity_value",
844844
connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING,
845+
replica_count=1384,
846+
read_endpoint="read_endpoint_value",
847+
read_endpoint_port=1920,
848+
read_replicas_mode=cloud_redis.Instance.ReadReplicasMode.READ_REPLICAS_DISABLED,
845849
)
846850
response = client.get_instance(request)
847851

@@ -868,6 +872,13 @@ def test_get_instance(
868872
assert response.authorized_network == "authorized_network_value"
869873
assert response.persistence_iam_identity == "persistence_iam_identity_value"
870874
assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING
875+
assert response.replica_count == 1384
876+
assert response.read_endpoint == "read_endpoint_value"
877+
assert response.read_endpoint_port == 1920
878+
assert (
879+
response.read_replicas_mode
880+
== cloud_redis.Instance.ReadReplicasMode.READ_REPLICAS_DISABLED
881+
)
871882

872883

873884
def test_get_instance_from_dict():
@@ -922,6 +933,10 @@ async def test_get_instance_async(
922933
authorized_network="authorized_network_value",
923934
persistence_iam_identity="persistence_iam_identity_value",
924935
connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING,
936+
replica_count=1384,
937+
read_endpoint="read_endpoint_value",
938+
read_endpoint_port=1920,
939+
read_replicas_mode=cloud_redis.Instance.ReadReplicasMode.READ_REPLICAS_DISABLED,
925940
)
926941
)
927942
response = await client.get_instance(request)
@@ -949,6 +964,13 @@ async def test_get_instance_async(
949964
assert response.authorized_network == "authorized_network_value"
950965
assert response.persistence_iam_identity == "persistence_iam_identity_value"
951966
assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING
967+
assert response.replica_count == 1384
968+
assert response.read_endpoint == "read_endpoint_value"
969+
assert response.read_endpoint_port == 1920
970+
assert (
971+
response.read_replicas_mode
972+
== cloud_redis.Instance.ReadReplicasMode.READ_REPLICAS_DISABLED
973+
)
952974

953975

954976
@pytest.mark.asyncio

0 commit comments

Comments
 (0)