Skip to content

Commit f3144dc

Browse files
authored
[SchemaRegistry] remove cache from client (Azure#20760)
* remove cache from client * changelog
1 parent f8ff686 commit f3144dc

13 files changed

+187
-425
lines changed

sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
### Other Changes
2020

2121
- Updated azure-core dependency to 1.17.1.
22+
- Removed caching support of registered schemas so requests are sent to the service to register schemas, get schema properties, and get schemas.
2223

2324
## 1.0.0b2 (2021-08-17)
2425

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_schema_registry_client.py

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def __init__(self, endpoint, credential, **kwargs):
6464
self._generated_client = AzureSchemaRegistry(
6565
credential=credential, endpoint=endpoint, **kwargs
6666
)
67-
self._description_to_properties = {}
68-
self._id_to_schema = {}
6967

7068
def __enter__(self):
7169
# type: () -> SchemaRegistryClient
@@ -128,20 +126,7 @@ def register_schema(
128126

129127
response = self._generated_client.send_request(request)
130128
response.raise_for_status()
131-
schema_properties = _parse_response_schema_properties(response)
132-
133-
schema_description = (
134-
group_name,
135-
name,
136-
content,
137-
serialization_type,
138-
)
139-
self._id_to_schema[schema_properties.id] = Schema(
140-
content, schema_properties
141-
)
142-
self._description_to_properties[schema_description] = schema_properties
143-
144-
return schema_properties
129+
return _parse_response_schema_properties(response)
145130

146131
def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
147132
# type: (str, Any) -> Schema
@@ -162,15 +147,10 @@ def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
162147
:caption: Get schema by id.
163148
164149
"""
165-
try:
166-
return self._id_to_schema[id]
167-
except KeyError:
168-
request = schema_rest.build_get_by_id_request(schema_id=id)
169-
response = self._generated_client.send_request(request, **kwargs)
170-
response.raise_for_status()
171-
schema = _parse_response_schema(response)
172-
self._id_to_schema[id] = schema
173-
return schema
150+
request = schema_rest.build_get_by_id_request(schema_id=id)
151+
response = self._generated_client.send_request(request, **kwargs)
152+
response.raise_for_status()
153+
return _parse_response_schema(response)
174154

175155
def get_schema_properties(
176156
self, group_name, name, content, serialization_type, **kwargs
@@ -204,30 +184,15 @@ def get_schema_properties(
204184
except AttributeError:
205185
pass
206186

207-
try:
208-
properties = self._description_to_properties[
209-
(group_name, name, content, serialization_type)
210-
]
211-
return properties
212-
except KeyError:
213-
request = schema_rest.build_query_id_by_content_request(
214-
group_name=group_name,
215-
schema_name=name,
216-
content=content,
217-
serialization_type=serialization_type,
218-
content_type=kwargs.pop("content_type", "application/json"),
219-
**kwargs
220-
)
221-
222-
response = self._generated_client.send_request(request, **kwargs)
223-
response.raise_for_status()
224-
schema_properties = _parse_response_schema_properties(response)
225-
226-
if not self._id_to_schema.get(schema_properties.id):
227-
self._id_to_schema[schema_properties.id] = Schema(content, schema_properties)
228-
else:
229-
schema_properties = self._id_to_schema[schema_properties.id].properties
230-
self._description_to_properties[
231-
(group_name, name, content, serialization_type)
232-
] = schema_properties
233-
return schema_properties
187+
request = schema_rest.build_query_id_by_content_request(
188+
group_name=group_name,
189+
schema_name=name,
190+
content=content,
191+
serialization_type=serialization_type,
192+
content_type=kwargs.pop("content_type", "application/json"),
193+
**kwargs
194+
)
195+
196+
response = self._generated_client.send_request(request, **kwargs)
197+
response.raise_for_status()
198+
return _parse_response_schema_properties(response)

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/aio/_schema_registry_client_async.py

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ def __init__(
6565
**kwargs: Any
6666
) -> None:
6767
self._generated_client = AzureSchemaRegistry(credential, endpoint, **kwargs)
68-
self._description_to_properties = {}
69-
self._id_to_schema = {}
7068

7169
async def __aenter__(self):
7270
await self._generated_client.__aenter__()
@@ -128,20 +126,7 @@ async def register_schema(
128126

129127
response = await self._generated_client.send_request(request)
130128
response.raise_for_status()
131-
schema_properties = _parse_response_schema_properties(response)
132-
133-
schema_description = (
134-
group_name,
135-
name,
136-
content,
137-
serialization_type,
138-
)
139-
self._id_to_schema[schema_properties.id] = Schema(
140-
content, schema_properties
141-
)
142-
self._description_to_properties[schema_description] = schema_properties
143-
144-
return schema_properties
129+
return _parse_response_schema_properties(response)
145130

146131
async def get_schema(
147132
self,
@@ -165,15 +150,10 @@ async def get_schema(
165150
:caption: Get schema by id.
166151
167152
"""
168-
try:
169-
return self._id_to_schema[id]
170-
except KeyError:
171-
request = schema_rest.build_get_by_id_request(schema_id=id)
172-
response = await self._generated_client.send_request(request, **kwargs)
173-
response.raise_for_status()
174-
schema = _parse_response_schema(response)
175-
self._id_to_schema[id] = schema
176-
return schema
153+
request = schema_rest.build_get_by_id_request(schema_id=id)
154+
response = await self._generated_client.send_request(request, **kwargs)
155+
response.raise_for_status()
156+
return _parse_response_schema(response)
177157

178158
async def get_schema_properties(
179159
self,
@@ -209,30 +189,15 @@ async def get_schema_properties(
209189
except AttributeError:
210190
pass
211191

212-
try:
213-
properties = self._description_to_properties[
214-
(group_name, name, content, serialization_type)
215-
]
216-
return properties
217-
except KeyError:
218-
request = schema_rest.build_query_id_by_content_request(
219-
group_name=group_name,
220-
schema_name=name,
221-
content=content,
222-
serialization_type=serialization_type,
223-
content_type=kwargs.pop("content_type", "application/json"),
224-
**kwargs
225-
)
226-
227-
response = await self._generated_client.send_request(request, **kwargs)
228-
response.raise_for_status()
229-
schema_properties = _parse_response_schema_properties(response)
230-
231-
if not self._id_to_schema.get(schema_properties.id):
232-
self._id_to_schema[schema_properties.id] = Schema(content, schema_properties)
233-
else:
234-
schema_properties = self._id_to_schema[schema_properties.id].properties
235-
self._description_to_properties[
236-
(group_name, name, content, serialization_type)
237-
] = schema_properties
238-
return schema_properties
192+
request = schema_rest.build_query_id_by_content_request(
193+
group_name=group_name,
194+
schema_name=name,
195+
content=content,
196+
serialization_type=serialization_type,
197+
content_type=kwargs.pop("content_type", "application/json"),
198+
**kwargs
199+
)
200+
201+
response = await self._generated_client.send_request(request, **kwargs)
202+
response.raise_for_status()
203+
return _parse_response_schema_properties(response)

sdk/schemaregistry/azure-schemaregistry/tests/async_tests/recordings/test_schema_registry_async.test_schema_basic_async.yaml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ interactions:
1616
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482?api-version=2020-09-01-preview
1717
response:
1818
body:
19-
string: '{"id":"c87ba6c2c15e4645b3665802159c6b37"}'
19+
string: '{"id":"d919a8923e2446e69614c0220d967dd7"}'
2020
headers:
2121
content-type: application/json
22-
date: Fri, 03 Sep 2021 21:37:45 GMT
22+
date: Mon, 20 Sep 2021 20:08:28 GMT
2323
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482/versions/1?api-version=2020-09-01-preview
24-
schema-id: c87ba6c2c15e4645b3665802159c6b37
25-
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/c87ba6c2c15e4645b3665802159c6b37?api-version=2020-09-01-preview
24+
schema-id: d919a8923e2446e69614c0220d967dd7
25+
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
2626
schema-version: '1'
2727
schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/test-schema-basic-asynce5e1482/versions?api-version=2020-09-01-preview
2828
serialization-type: Avro
@@ -33,6 +33,34 @@ interactions:
3333
code: 200
3434
message: OK
3535
url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/test-schema-basic-asynce5e1482?api-version=2020-09-01-preview
36+
- request:
37+
body: null
38+
headers:
39+
Accept:
40+
- text/plain; charset=utf-8
41+
User-Agent:
42+
- azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0)
43+
method: GET
44+
uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
45+
response:
46+
body:
47+
string: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}'
48+
headers:
49+
content-type: application/json
50+
date: Mon, 20 Sep 2021 20:08:29 GMT
51+
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482/versions/1?api-version=2020-09-01-preview
52+
schema-id: d919a8923e2446e69614c0220d967dd7
53+
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
54+
schema-version: '1'
55+
schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/test-schema-basic-asynce5e1482/versions?api-version=2020-09-01-preview
56+
serialization-type: Avro
57+
server: Microsoft-HTTPAPI/2.0
58+
strict-transport-security: max-age=31536000
59+
transfer-encoding: chunked
60+
status:
61+
code: 200
62+
message: OK
63+
url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
3664
- request:
3765
body: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}'
3866
headers:
@@ -50,13 +78,13 @@ interactions:
5078
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482?api-version=2020-09-01-preview
5179
response:
5280
body:
53-
string: '{"id":"c87ba6c2c15e4645b3665802159c6b37"}'
81+
string: '{"id":"d919a8923e2446e69614c0220d967dd7"}'
5482
headers:
5583
content-type: application/json
56-
date: Fri, 03 Sep 2021 21:37:45 GMT
84+
date: Mon, 20 Sep 2021 20:08:30 GMT
5785
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482/versions/1?api-version=2020-09-01-preview
58-
schema-id: c87ba6c2c15e4645b3665802159c6b37
59-
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/c87ba6c2c15e4645b3665802159c6b37?api-version=2020-09-01-preview
86+
schema-id: d919a8923e2446e69614c0220d967dd7
87+
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
6088
schema-version: '1'
6189
schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/test-schema-basic-asynce5e1482/versions?api-version=2020-09-01-preview
6290
serialization-type: Avro

sdk/schemaregistry/azure-schemaregistry/tests/async_tests/recordings/test_schema_registry_async.test_schema_negative_no_schema_async.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ interactions:
1111
response:
1212
body:
1313
string: '{"Code":400,"Detail":"SubCode=40000, UnknownType:The request is invalid.
14-
[MGResponseHttpError=BadRequest]. TrackingId:faf1cce9-f0c7-4dfb-bdcc-4410c3f74b30_G29,
14+
[MGResponseHttpError=BadRequest]. TrackingId:4f653bc2-9ef4-4b83-8632-3aa321d9b8e5_G29,
1515
SystemTracker:swathip-test-eventhubs.servicebus.windows.net:$schemagroups\/getSchemaById\/a,
16-
Timestamp:2021-09-03T21:37:47"}'
16+
Timestamp:2021-09-20T20:08:31"}'
1717
headers:
1818
content-type: application/json
19-
date: Fri, 03 Sep 2021 21:37:47 GMT
19+
date: Mon, 20 Sep 2021 20:08:30 GMT
2020
server: Microsoft-HTTPAPI/2.0
2121
strict-transport-security: max-age=31536000
2222
transfer-encoding: chunked
@@ -36,11 +36,11 @@ interactions:
3636
response:
3737
body:
3838
string: '{"Code":404,"Detail":"Schema id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa does
39-
not exist. TrackingId:520d7a70-c165-4edd-8855-046ff6be2f72_G29, SystemTracker:swathip-test-eventhubs.servicebus.windows.net:$schemagroups\/getSchemaById\/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
40-
Timestamp:2021-09-03T21:37:48"}'
39+
not exist. TrackingId:79cdec74-b17a-4334-a0bd-0ceeb9253ca4_G29, SystemTracker:swathip-test-eventhubs.servicebus.windows.net:$schemagroups\/getSchemaById\/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
40+
Timestamp:2021-09-20T20:08:31"}'
4141
headers:
4242
content-type: application/json
43-
date: Fri, 03 Sep 2021 21:37:47 GMT
43+
date: Mon, 20 Sep 2021 20:08:31 GMT
4444
server: Microsoft-HTTPAPI/2.0
4545
strict-transport-security: max-age=31536000
4646
transfer-encoding: chunked

sdk/schemaregistry/azure-schemaregistry/tests/async_tests/recordings/test_schema_registry_async.test_schema_same_twice_async.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ interactions:
1616
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1?api-version=2020-09-01-preview
1717
response:
1818
body:
19-
string: '{"id":"99a89631052e4a22a9fca816cbd2761a"}'
19+
string: '{"id":"d6fb6739c94a45328ee36d163a7ee4de"}'
2020
headers:
2121
content-type: application/json
22-
date: Fri, 03 Sep 2021 21:37:54 GMT
22+
date: Mon, 20 Sep 2021 20:08:37 GMT
2323
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1/versions/1?api-version=2020-09-01-preview
24-
schema-id: 99a89631052e4a22a9fca816cbd2761a
25-
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/99a89631052e4a22a9fca816cbd2761a?api-version=2020-09-01-preview
24+
schema-id: d6fb6739c94a45328ee36d163a7ee4de
25+
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d6fb6739c94a45328ee36d163a7ee4de?api-version=2020-09-01-preview
2626
schema-version: '1'
2727
schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/test-schema-twice-async7bfd16a1/versions?api-version=2020-09-01-preview
2828
serialization-type: Avro
@@ -50,13 +50,13 @@ interactions:
5050
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1?api-version=2020-09-01-preview
5151
response:
5252
body:
53-
string: '{"id":"99a89631052e4a22a9fca816cbd2761a"}'
53+
string: '{"id":"d6fb6739c94a45328ee36d163a7ee4de"}'
5454
headers:
5555
content-type: application/json
56-
date: Fri, 03 Sep 2021 21:37:55 GMT
56+
date: Mon, 20 Sep 2021 20:08:38 GMT
5757
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1/versions/1?api-version=2020-09-01-preview
58-
schema-id: 99a89631052e4a22a9fca816cbd2761a
59-
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/99a89631052e4a22a9fca816cbd2761a?api-version=2020-09-01-preview
58+
schema-id: d6fb6739c94a45328ee36d163a7ee4de
59+
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d6fb6739c94a45328ee36d163a7ee4de?api-version=2020-09-01-preview
6060
schema-version: '1'
6161
schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/test-schema-twice-async7bfd16a1/versions?api-version=2020-09-01-preview
6262
serialization-type: Avro

0 commit comments

Comments
 (0)