sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

No files matched your search

@@ -0,0 +1,47 @@
"""Serialize SQLite schema initialization across containers sharing a directory."""
import asyncio
import os
from contextlib import asynccontextmanager
@asynccontextmanager
async def sqlite_setup_lock(path: str):
if path == ":memory:" or path.startswith("file:"):
yield
return
with open(path + ".setup.lock", "a+b") as handle:
if os.name == "nt":
import msvcrt
if os.fstat(handle.fileno()).st_size == 0:
handle.write(b"0")
handle.flush()
def acquire():
handle.seek(0)
msvcrt.locking(handle.fileno(), msvcrt.LK_NBLCK, 1)
def release():
handle.seek(0)
msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
else:
import fcntl
def acquire():
fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
def release():
fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
async with asyncio.timeout(60):
while True:
try:
acquire()
break
except (BlockingIOError, PermissionError):
await asyncio.sleep(0.05)
try:
yield
finally:
release()
@@ -93,7 +93,12 @@ async def _async_store(config) -> AsyncIterator[BaseStore]:
ensure_sqlite_parent_dir(conn_str)
async with AsyncSqliteStore.from_conn_string(conn_str) as store:
await store.setup()
from deerflow.runtime.store._sqlite_setup import sqlite_setup_lock
async with sqlite_setup_lock(conn_str):
await store.conn.execute("PRAGMA busy_timeout=30000")
await store.conn.execute("PRAGMA journal_mode=WAL")
await store.setup()
logger.info("Store: using AsyncSqliteStore (%s)", conn_str)
yield store
return
@@ -146,5 +151,10 @@ async def make_store(app_config: AppConfig | None = None) -> AsyncIterator[BaseS
yield InMemoryStore()
return
async with _async_store(app_config.checkpointer) as store:
from deerflow.runtime.checkpointer.async_provider import _sqlite_conn_str_for_postgres_fallback, _use_postgres_enabled
checkpoint = app_config.checkpointer
if checkpoint.type == "postgres" and not _use_postgres_enabled(checkpoint):
checkpoint = checkpoint.model_copy(update={"type": "sqlite", "connection_string": _sqlite_conn_str_for_postgres_fallback(checkpoint)})
async with _async_store(checkpoint) as store:
yield store