Skip to content

Commit

Permalink
Schema version in query cache key (#6990)
Browse files Browse the repository at this point in the history
so that the cache table can be append-only to avoid concurrent update errors.
  • Loading branch information
fantix authored Mar 5, 2024
1 parent 4a9fbc5 commit fb09377
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 152 deletions.
1 change: 1 addition & 0 deletions edb/server/compiler/rpc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cdef class CompilationRequest:
readonly object session_config
object database_config
object system_config
object schema_version

bytes serialized_cache
object cache_key
Expand Down
3 changes: 3 additions & 0 deletions edb/server/compiler/rpc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class CompilationRequest:
) -> CompilationRequest:
...

def set_schema_version(self, version: uuid.UUID) -> CompilationRequest:
...

def serialize(self) -> bytes:
...

Expand Down
10 changes: 10 additions & 0 deletions edb/server/compiler/rpc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ cdef class CompilationRequest:
self.cache_key = None
return self

def set_schema_version(self, version: uuid.UUID) -> CompilationRequest:
self.schema_version = version
self.serialized_cache = None
self.cache_key = None
return self

def deserialize(self, bytes data, str query_text) -> CompilationRequest:
if data[0] == 0:
self._deserialize_v0(data, query_text)
Expand Down Expand Up @@ -217,6 +223,10 @@ cdef class CompilationRequest:
)
hash_obj.update(serialized_comp_config)

# Must set_schema_version() before serializing compilation request
assert self.schema_version is not None
hash_obj.update(self.schema_version.bytes)

cache_key_bytes = hash_obj.digest()
self.cache_key = uuidgen.from_bytes(cache_key_bytes)

Expand Down
8 changes: 4 additions & 4 deletions edb/server/dbview/dbview.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ cdef class Database:
cdef schedule_config_update(self)

cdef _invalidate_caches(self)
cdef _cache_compiled_query(self, key, compiled, schema_version)
cdef _cache_compiled_query(self, key, compiled)
cdef _new_view(self, query_cache, protocol_version)
cdef _remove_view(self, view)
cdef _update_backend_ids(self, new_types)
Expand Down Expand Up @@ -152,6 +152,7 @@ cdef class DatabaseConnectionView:
object __weakref__

cdef _reset_tx_state(self)
cdef inline _check_in_tx_error(self, query_unit_group)

cdef clear_tx_error(self)
cdef rollback_tx_to_savepoint(self, name)
Expand All @@ -162,10 +163,9 @@ cdef class DatabaseConnectionView:
cpdef in_tx(self)
cpdef in_tx_error(self)

cdef cache_compiled_query(
self, object key, object query_unit_group, schema_version
)
cdef cache_compiled_query(self, object key, object query_unit_group)
cdef lookup_compiled_query(self, object key)
cdef as_compiled(self, query_req, query_unit_group, bint use_metrics=?)

cdef tx_error(self)

Expand Down
Loading

0 comments on commit fb09377

Please sign in to comment.