fix(cloud): enforce instance capacity ceilings

This commit is contained in:
Junyan Qin
2026-07-29 13:45:58 +08:00
parent e52d6880f5
commit c89e6f3bd2
25 changed files with 1062 additions and 87 deletions
+14
View File
@@ -159,6 +159,7 @@ class PersistenceManager:
for manager in database.preregistered_managers:
if manager.name == database_type:
self.db = manager(self.ap, url_override=self._database_url_override)
self.db.persistence_mode = self.mode.value
await self.db.initialize()
selected_manager = self.db
break
@@ -195,6 +196,17 @@ class PersistenceManager:
if engine is not None:
await engine.dispose()
def get_resource_stats(self) -> dict[str, int]:
"""Return database-manager-owned aggregate resource gauges."""
resource_stats = getattr(getattr(self, 'db', None), 'resource_stats', None)
if not callable(resource_stats):
return {}
try:
return resource_stats()
except Exception:
return {}
@contextlib.asynccontextmanager
async def _release_migration_lock(self) -> typing.AsyncIterator[None]:
"""Serialize the complete PostgreSQL migration and validation window."""
@@ -1865,11 +1877,13 @@ class PersistenceManager:
return active.session
def _scoped_uow(self, scope: PersistenceScope) -> TenantUnitOfWork:
on_pool_timeout = getattr(getattr(self, 'db', None), 'record_pool_timeout', None)
return TenantUnitOfWork(
self.get_db_engine(),
scope=scope,
active_transaction=self._active_transaction,
active_scope=self._active_scope,
on_pool_timeout=(on_pool_timeout if callable(on_pool_timeout) else None),
)
def _get_active_transaction(self) -> ActiveScopedTransaction | None: