sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
+47
@@ -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()
|
||||
+12
-2
@@ -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
|
||||
Reference in new issue
Block a user