Skip to content

Commit

Permalink
[SchemaRegistry] remove cache from client (Azure#20760)
Browse files Browse the repository at this point in the history
* remove cache from client

* changelog
  • Loading branch information
swathipil authored Sep 22, 2021
1 parent f8ff686 commit f3144dc
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 425 deletions.
1 change: 1 addition & 0 deletions sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Other Changes

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

## 1.0.0b2 (2021-08-17)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def __init__(self, endpoint, credential, **kwargs):
self._generated_client = AzureSchemaRegistry(
credential=credential, endpoint=endpoint, **kwargs
)
self._description_to_properties = {}
self._id_to_schema = {}

def __enter__(self):
# type: () -> SchemaRegistryClient
Expand Down Expand Up @@ -128,20 +126,7 @@ def register_schema(

response = self._generated_client.send_request(request)
response.raise_for_status()
schema_properties = _parse_response_schema_properties(response)

schema_description = (
group_name,
name,
content,
serialization_type,
)
self._id_to_schema[schema_properties.id] = Schema(
content, schema_properties
)
self._description_to_properties[schema_description] = schema_properties

return schema_properties
return _parse_response_schema_properties(response)

def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
# type: (str, Any) -> Schema
Expand All @@ -162,15 +147,10 @@ def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
:caption: Get schema by id.
"""
try:
return self._id_to_schema[id]
except KeyError:
request = schema_rest.build_get_by_id_request(schema_id=id)
response = self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
schema = _parse_response_schema(response)
self._id_to_schema[id] = schema
return schema
request = schema_rest.build_get_by_id_request(schema_id=id)
response = self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema(response)

def get_schema_properties(
self, group_name, name, content, serialization_type, **kwargs
Expand Down Expand Up @@ -204,30 +184,15 @@ def get_schema_properties(
except AttributeError:
pass

try:
properties = self._description_to_properties[
(group_name, name, content, serialization_type)
]
return properties
except KeyError:
request = schema_rest.build_query_id_by_content_request(
group_name=group_name,
schema_name=name,
content=content,
serialization_type=serialization_type,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
)

response = self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
schema_properties = _parse_response_schema_properties(response)

if not self._id_to_schema.get(schema_properties.id):
self._id_to_schema[schema_properties.id] = Schema(content, schema_properties)
else:
schema_properties = self._id_to_schema[schema_properties.id].properties
self._description_to_properties[
(group_name, name, content, serialization_type)
] = schema_properties
return schema_properties
request = schema_rest.build_query_id_by_content_request(
group_name=group_name,
schema_name=name,
content=content,
serialization_type=serialization_type,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
)

response = self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema_properties(response)
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def __init__(
**kwargs: Any
) -> None:
self._generated_client = AzureSchemaRegistry(credential, endpoint, **kwargs)
self._description_to_properties = {}
self._id_to_schema = {}

async def __aenter__(self):
await self._generated_client.__aenter__()
Expand Down Expand Up @@ -128,20 +126,7 @@ async def register_schema(

response = await self._generated_client.send_request(request)
response.raise_for_status()
schema_properties = _parse_response_schema_properties(response)

schema_description = (
group_name,
name,
content,
serialization_type,
)
self._id_to_schema[schema_properties.id] = Schema(
content, schema_properties
)
self._description_to_properties[schema_description] = schema_properties

return schema_properties
return _parse_response_schema_properties(response)

async def get_schema(
self,
Expand All @@ -165,15 +150,10 @@ async def get_schema(
:caption: Get schema by id.
"""
try:
return self._id_to_schema[id]
except KeyError:
request = schema_rest.build_get_by_id_request(schema_id=id)
response = await self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
schema = _parse_response_schema(response)
self._id_to_schema[id] = schema
return schema
request = schema_rest.build_get_by_id_request(schema_id=id)
response = await self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema(response)

async def get_schema_properties(
self,
Expand Down Expand Up @@ -209,30 +189,15 @@ async def get_schema_properties(
except AttributeError:
pass

try:
properties = self._description_to_properties[
(group_name, name, content, serialization_type)
]
return properties
except KeyError:
request = schema_rest.build_query_id_by_content_request(
group_name=group_name,
schema_name=name,
content=content,
serialization_type=serialization_type,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
)

response = await self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
schema_properties = _parse_response_schema_properties(response)

if not self._id_to_schema.get(schema_properties.id):
self._id_to_schema[schema_properties.id] = Schema(content, schema_properties)
else:
schema_properties = self._id_to_schema[schema_properties.id].properties
self._description_to_properties[
(group_name, name, content, serialization_type)
] = schema_properties
return schema_properties
request = schema_rest.build_query_id_by_content_request(
group_name=group_name,
schema_name=name,
content=content,
serialization_type=serialization_type,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
)

response = await self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema_properties(response)
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interactions:
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482?api-version=2020-09-01-preview
response:
body:
string: '{"id":"c87ba6c2c15e4645b3665802159c6b37"}'
string: '{"id":"d919a8923e2446e69614c0220d967dd7"}'
headers:
content-type: application/json
date: Fri, 03 Sep 2021 21:37:45 GMT
date: Mon, 20 Sep 2021 20:08:28 GMT
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482/versions/1?api-version=2020-09-01-preview
schema-id: c87ba6c2c15e4645b3665802159c6b37
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/c87ba6c2c15e4645b3665802159c6b37?api-version=2020-09-01-preview
schema-id: d919a8923e2446e69614c0220d967dd7
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
schema-version: '1'
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
serialization-type: Avro
Expand All @@ -33,6 +33,34 @@ interactions:
code: 200
message: OK
url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/test-schema-basic-asynce5e1482?api-version=2020-09-01-preview
- request:
body: null
headers:
Accept:
- text/plain; charset=utf-8
User-Agent:
- azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
response:
body:
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"]}]}'
headers:
content-type: application/json
date: Mon, 20 Sep 2021 20:08:29 GMT
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482/versions/1?api-version=2020-09-01-preview
schema-id: d919a8923e2446e69614c0220d967dd7
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
schema-version: '1'
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
serialization-type: Avro
server: Microsoft-HTTPAPI/2.0
strict-transport-security: max-age=31536000
transfer-encoding: chunked
status:
code: 200
message: OK
url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
- request:
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"]}]}'
headers:
Expand All @@ -50,13 +78,13 @@ interactions:
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482?api-version=2020-09-01-preview
response:
body:
string: '{"id":"c87ba6c2c15e4645b3665802159c6b37"}'
string: '{"id":"d919a8923e2446e69614c0220d967dd7"}'
headers:
content-type: application/json
date: Fri, 03 Sep 2021 21:37:45 GMT
date: Mon, 20 Sep 2021 20:08:30 GMT
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-basic-asynce5e1482/versions/1?api-version=2020-09-01-preview
schema-id: c87ba6c2c15e4645b3665802159c6b37
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/c87ba6c2c15e4645b3665802159c6b37?api-version=2020-09-01-preview
schema-id: d919a8923e2446e69614c0220d967dd7
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d919a8923e2446e69614c0220d967dd7?api-version=2020-09-01-preview
schema-version: '1'
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
serialization-type: Avro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ interactions:
response:
body:
string: '{"Code":400,"Detail":"SubCode=40000, UnknownType:The request is invalid.
[MGResponseHttpError=BadRequest]. TrackingId:faf1cce9-f0c7-4dfb-bdcc-4410c3f74b30_G29,
[MGResponseHttpError=BadRequest]. TrackingId:4f653bc2-9ef4-4b83-8632-3aa321d9b8e5_G29,
SystemTracker:swathip-test-eventhubs.servicebus.windows.net:$schemagroups\/getSchemaById\/a,
Timestamp:2021-09-03T21:37:47"}'
Timestamp:2021-09-20T20:08:31"}'
headers:
content-type: application/json
date: Fri, 03 Sep 2021 21:37:47 GMT
date: Mon, 20 Sep 2021 20:08:30 GMT
server: Microsoft-HTTPAPI/2.0
strict-transport-security: max-age=31536000
transfer-encoding: chunked
Expand All @@ -36,11 +36,11 @@ interactions:
response:
body:
string: '{"Code":404,"Detail":"Schema id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa does
not exist. TrackingId:520d7a70-c165-4edd-8855-046ff6be2f72_G29, SystemTracker:swathip-test-eventhubs.servicebus.windows.net:$schemagroups\/getSchemaById\/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
Timestamp:2021-09-03T21:37:48"}'
not exist. TrackingId:79cdec74-b17a-4334-a0bd-0ceeb9253ca4_G29, SystemTracker:swathip-test-eventhubs.servicebus.windows.net:$schemagroups\/getSchemaById\/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
Timestamp:2021-09-20T20:08:31"}'
headers:
content-type: application/json
date: Fri, 03 Sep 2021 21:37:47 GMT
date: Mon, 20 Sep 2021 20:08:31 GMT
server: Microsoft-HTTPAPI/2.0
strict-transport-security: max-age=31536000
transfer-encoding: chunked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interactions:
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1?api-version=2020-09-01-preview
response:
body:
string: '{"id":"99a89631052e4a22a9fca816cbd2761a"}'
string: '{"id":"d6fb6739c94a45328ee36d163a7ee4de"}'
headers:
content-type: application/json
date: Fri, 03 Sep 2021 21:37:54 GMT
date: Mon, 20 Sep 2021 20:08:37 GMT
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1/versions/1?api-version=2020-09-01-preview
schema-id: 99a89631052e4a22a9fca816cbd2761a
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/99a89631052e4a22a9fca816cbd2761a?api-version=2020-09-01-preview
schema-id: d6fb6739c94a45328ee36d163a7ee4de
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d6fb6739c94a45328ee36d163a7ee4de?api-version=2020-09-01-preview
schema-version: '1'
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
serialization-type: Avro
Expand Down Expand Up @@ -50,13 +50,13 @@ interactions:
uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1?api-version=2020-09-01-preview
response:
body:
string: '{"id":"99a89631052e4a22a9fca816cbd2761a"}'
string: '{"id":"d6fb6739c94a45328ee36d163a7ee4de"}'
headers:
content-type: application/json
date: Fri, 03 Sep 2021 21:37:55 GMT
date: Mon, 20 Sep 2021 20:08:38 GMT
location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/test-schema-twice-async7bfd16a1/versions/1?api-version=2020-09-01-preview
schema-id: 99a89631052e4a22a9fca816cbd2761a
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/99a89631052e4a22a9fca816cbd2761a?api-version=2020-09-01-preview
schema-id: d6fb6739c94a45328ee36d163a7ee4de
schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/d6fb6739c94a45328ee36d163a7ee4de?api-version=2020-09-01-preview
schema-version: '1'
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
serialization-type: Avro
Expand Down
Loading

0 comments on commit f3144dc

Please sign in to comment.