Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion edb/server/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@


from __future__ import annotations
from typing import Any, Mapping, TypedDict
from typing import Any, Mapping, TypedDict, TYPE_CHECKING

import enum

import immutables

from edb import errors
from edb.edgeql.qltypes import ConfigScope
if TYPE_CHECKING:
from edb.server import server

from .ops import OpCode, Operation, SettingValue
from .ops import (
Expand Down
4 changes: 1 addition & 3 deletions edb/server/dbview/dbview.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ cdef class DatabaseIndex:
object _comp_sys_config
object _std_schema
object _global_schema_pickle
object _default_sysconfig
object _sys_config_spec
object _cached_compiler_args

Expand Down Expand Up @@ -242,9 +241,8 @@ cdef class DatabaseConnectionView:
cpdef get_database_config(self)
cdef set_database_config(self, new_conf)

cdef get_system_config(self)
cpdef get_compilation_system_config(self)
cdef config_lookup(self, name)
cdef lookup_config(self, name)

cdef set_modaliases(self, new_aliases)
cpdef get_modaliases(self)
Expand Down
9 changes: 2 additions & 7 deletions edb/server/dbview/dbview.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,17 @@ class DatabaseIndex:
*,
std_schema: s_schema.Schema,
global_schema_pickle: bytes,
sys_config: Config,
default_sysconfig: Config,
sys_config_spec: config.Spec,
sys_config: server.ServerSysConfig,
) -> None:
...

def count_connections(self, dbname: str) -> int:
...

def get_sys_config(self) -> Config:
...

def get_compilation_system_config(self) -> Config:
...

def update_sys_config(self, sys_config: Config) -> None:
def update_sys_config(self) -> None:
...

def has_db(self, dbname: str) -> bool:
Expand Down
68 changes: 24 additions & 44 deletions edb/server/dbview/dbview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,10 @@ cdef class Database:
spec = self._index._sys_config_spec
if self.user_config_spec is not None:
spec = config.ChainedSpec(spec, self.user_config_spec)
return config.lookup(
return self._index._sys_config.lookup(
name,
self.db_config or DEFAULT_CONFIG,
self._index._sys_config,
spec=spec,
configs=(self.db_config or DEFAULT_CONFIG,),
spec=spec
)


Expand Down Expand Up @@ -806,9 +805,6 @@ cdef class DatabaseConnectionView:
pass


cdef get_system_config(self):
return self._db._index.get_sys_config()

cpdef get_compilation_system_config(self):
return self._db._index.get_compilation_system_config()

Expand Down Expand Up @@ -1291,12 +1287,13 @@ cdef class DatabaseConnectionView:
self._reset_tx_state()
return side_effects

cdef config_lookup(self, name):
return self.server.config_lookup(
cdef lookup_config(self, name):
return self.server.config.lookup(
name,
self.get_session_config(),
self.get_database_config(),
self.get_system_config(),
configs=(
self.get_session_config(),
self.get_database_config(),
),
)

async def recompile_cached_queries(
Expand All @@ -1310,7 +1307,7 @@ cdef class DatabaseConnectionView:
concurrency_control = asyncio.Semaphore(compile_concurrency)
rv = []

recompile_timeout = self.config_lookup(
recompile_timeout = self.lookup_config(
"auto_rebuild_query_cache_timeout",
)

Expand Down Expand Up @@ -1567,7 +1564,7 @@ cdef class DatabaseConnectionView:
if unit.user_schema:
user_schema = unit.user_schema
user_schema_version = unit.user_schema_version
if user_schema and not self.config_lookup(
if user_schema and not self.lookup_config(
"auto_rebuild_query_cache",
):
user_schema = None
Expand Down Expand Up @@ -1893,7 +1890,7 @@ cdef class DatabaseConnectionView:
if self.in_tx():
isolation = self._in_tx_isolation_level
else:
isolation = self.config_lookup(
isolation = self.lookup_config(
"default_transaction_isolation"
)
if isolation and isolation.to_str() == "RepeatableRead":
Expand All @@ -1915,7 +1912,7 @@ cdef class DatabaseConnectionView:
)

if not self.in_tx() and has_write:
access_mode = self.config_lookup("default_transaction_access_mode")
access_mode = self.lookup_config("default_transaction_access_mode")
if access_mode and access_mode.to_str() == "ReadOnly":
raise query_capabilities.make_error(
~enums.Capability.WRITE,
Expand Down Expand Up @@ -1947,17 +1944,15 @@ cdef class DatabaseIndex:
std_schema,
global_schema_pickle,
sys_config,
default_sysconfig, # system config without system override
sys_config_spec,
):
self._dbs = {}
self._server = tenant.server
self._tenant = tenant
self._std_schema = std_schema
self._global_schema_pickle = global_schema_pickle
self._default_sysconfig = default_sysconfig
self._sys_config_spec = sys_config_spec
self.update_sys_config(sys_config)
self._sys_config = sys_config
self._sys_config_spec = sys_config.settings
self.update_sys_config()
self._cached_compiler_args = None

def count_connections(self, dbname: str):
Expand All @@ -1968,23 +1963,15 @@ cdef class DatabaseIndex:

return sum(1 for dbv in (<Database>db)._views if not dbv.is_transient)

def get_sys_config(self):
return self._sys_config

def get_compilation_system_config(self):
return self._comp_sys_config

def update_sys_config(self, sys_config):
def update_sys_config(self):
cdef Database db
for db in self._dbs.values():
db.dbver = next_dbver()

with self._default_sysconfig.mutate() as mm:
mm.update(sys_config)
sys_config = mm.finish()
self._sys_config = sys_config
self._comp_sys_config = config.get_compilation_config(
sys_config, spec=self._sys_config_spec)
self._comp_sys_config = self._sys_config.get_compilation_config()
self.invalidate_caches()

def has_db(self, dbname):
Expand Down Expand Up @@ -2079,10 +2066,8 @@ cdef class DatabaseIndex:
def iter_dbs(self):
return iter(self._dbs.values())

async def _save_system_overrides(self, conn, spec):
data = config.to_json(
spec,
self._sys_config,
async def _save_system_overrides(self, conn):
data = self._sys_config.to_json(
setting_filter=lambda v: v.source == 'system override',
include_source=False,
)
Expand Down Expand Up @@ -2116,11 +2101,10 @@ cdef class DatabaseIndex:
# _save_system_overrides *must* happen before
# the callbacks below, because certain config changes
# may cause the backend connection to drop.
self.update_sys_config(
op.apply(spec, self._sys_config)
)
self._sys_config.apply(op)
self.update_sys_config()

await self._save_system_overrides(conn, spec)
await self._save_system_overrides(conn)

if op.opcode is config.OpCode.CONFIG_ADD:
await self._server._on_system_config_add(op.setting_name, op_value)
Expand Down Expand Up @@ -2175,8 +2159,4 @@ cdef class DatabaseIndex:
return self._cached_compiler_args

def lookup_config(self, name: str):
return config.lookup(
name,
self._sys_config,
spec=self._sys_config_spec,
)
return self._sys_config.lookup(name)
14 changes: 12 additions & 2 deletions edb/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
from . import pgcluster
from . import service_manager


if TYPE_CHECKING:
from . import server
from edb.server import bootstrap
Expand Down Expand Up @@ -207,6 +206,11 @@ async def _run_server(

with signalctl.SignalController(signal.SIGINT, signal.SIGTERM) as sc:
from . import tenant as edbtenant
from . import server

sys_config = server.ServerSysConfig(
config_settings=compiler.state.config_spec
)

# max_backend_connections should've been calculated already by now
assert args.max_backend_connections is not None
Expand All @@ -216,6 +220,7 @@ async def _run_server(
max_backend_connections=args.max_backend_connections,
backend_adaptive_ha=args.backend_adaptive_ha,
extensions_dir=args.extensions_dir,
sys_config=sys_config,
)
tenant.set_init_con_data(init_con_data)
tenant.set_reloadable_files(
Expand Down Expand Up @@ -531,6 +536,7 @@ async def run_server(
from edb.schema import reflection as s_refl
from . import bootstrap
from . import multitenant
from . import server

try:
stdlib: bootstrap.StdlibBits | None
Expand Down Expand Up @@ -595,13 +601,17 @@ async def run_server(
compiler_state.config_spec,
)

sys_config, backend_settings, init_con_data = (
config_map, backend_settings, init_con_data = (
initialize_static_cfg(
args,
is_remote_cluster=True,
compiler=compiler,
)
)
sys_config = server.ServerSysConfig(
config_settings=compiler_state.config_spec,
sys_config=config_map,
)
del compiler
if backend_settings:
abort(
Expand Down
13 changes: 6 additions & 7 deletions edb/server/multitenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@

class MultiTenantServer(server.BaseServer):
_config_file: pathlib.Path
_sys_config: Mapping[str, config.SettingValue]
_init_con_data: list[config.ConState]

_tenants_by_sslobj: MutableMapping
Expand All @@ -88,15 +87,13 @@ def __init__(
config_file: pathlib.Path,
*,
compiler_pool_tenant_cache_size: int,
sys_config: Mapping[str, config.SettingValue],
init_con_data: list[config.ConState],
sys_queries: Mapping[str, bytes],
report_config_typedesc: dict[defines.ProtocolVersion, bytes],
**kwargs,
):
super().__init__(**kwargs)
self._config_file = config_file
self._sys_config = sys_config
self._init_con_data = init_con_data
self._compiler_pool_tenant_cache_size = compiler_pool_tenant_cache_size

Expand All @@ -113,9 +110,6 @@ def __init__(
self._sys_queries = sys_queries
self._report_config_typedesc = report_config_typedesc

def _get_sys_config(self) -> Mapping[str, config.SettingValue]:
return self._sys_config

def _sni_callback(self, sslobj, server_name, _sslctx):
if server_name is None:
self._tenants_by_sslobj[sslobj] = edbtenant.host_tenant
Expand Down Expand Up @@ -242,11 +236,16 @@ async def _create_tenant(self, conf: TenantConfig) -> edbtenant.Tenant:
"No secret key"
)

sys_config = server.ServerSysConfig(
config_settings=self._sys_config.settings
)

tenant = edbtenant.Tenant(
cluster,
instance_name=conf["instance-name"],
max_backend_connections=max_conns,
backend_adaptive_ha=conf.get("backend-adaptive-ha", False),
sys_config=sys_config,
)
tenant.set_init_con_data(self._init_con_data)
config_file = conf.get("config-file")
Expand Down Expand Up @@ -440,7 +439,7 @@ def _get_compiler_args(self) -> dict[str, Any]:
async def run_server(
args: srvargs.ServerConfig,
*,
sys_config: Mapping[str, config.SettingValue],
sys_config: server.ServerSysConfig,
init_con_data: list[config.ConState],
sys_queries: Mapping[str, bytes],
report_config_typedesc: dict[defines.ProtocolVersion, bytes],
Expand Down
4 changes: 2 additions & 2 deletions edb/server/net_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class TenantState:


async def _http_task(tenant: edbtenant.Tenant, state: TenantState) -> None:
http_max_connections = tenant._server.config_lookup(
'http_max_connections', tenant.get_sys_config()
http_max_connections = tenant.config.lookup(
'http_max_connections'
)
http_client = state.http_client
http_client._update_limit(http_max_connections)
Expand Down
2 changes: 1 addition & 1 deletion edb/server/protocol/frontend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ cdef class FrontendConnection(AbstractFrontendConnection):
# (such as the ability to write to a protected socket).
if self._external_auth:
authmethods = [
self.server.config_settings.get_type_by_name('cfg::Trust')()
self.server.config.settings.get_type_by_name('cfg::Trust')()
]
else:
authmethods = await self.tenant.get_auth_methods(
Expand Down
2 changes: 1 addition & 1 deletion edb/server/protocol/protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ cdef class HttpProtocol:

config = db.db_config.get('cors_allow_origins')
if config is None:
config = self.tenant.get_sys_config().get('cors_allow_origins')
config = self.tenant.config.lookup('cors_allow_origins')

allowed_origins = config.value if config else None
overrides = self.server.get_cors_always_allowed_origins()
Expand Down
Loading
Loading