fsanyoto commited on
Commit
ac97ffa
·
verified ·
1 Parent(s): d11d07e

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "d1884950f7",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "b0197f374",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- d1884950f7
 
1
+ b0197f374
platform/harness/datastore.py CHANGED
@@ -950,13 +950,15 @@ _COUNT_CACHE_MAX = 256
950
  _COUNT_CACHE_LOCK = _thr.RLock()
951
 
952
 
953
- def _invalidate_counts(path=None):
 
954
  with _COUNT_CACHE_LOCK:
955
- _MIRROR_WRITES[0] += 1
956
  _COUNT_CACHE.clear()
957
- handle = _HANDLES_LIVE.get(str(Path(path or DB_PATH).resolve()))
958
- if handle is not None:
959
- handle.writes += 1
 
 
960
 
961
 
962
  def note_mirror_install(path=None, *, cur=None):
@@ -987,7 +989,7 @@ def mirror_generation(cur=None):
987
 
988
 
989
  def mirror_writes(cur=None):
990
- """Return writes affecting the cursor's tenant, retaining the legacy single-store token."""
991
  handle = getattr(cur, "_mirror_handle", None)
992
  return handle.writes if handle is not None else _MIRROR_WRITES[0]
993
 
@@ -1559,6 +1561,80 @@ def versioned_write(tenant_key=None):
1559
  _follow_version(force=True)
1560
 
1561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1562
  class _TimedCursor:
1563
  """Keep cursor chaining and thread-local identity while timing execute and result conversion."""
1564
 
@@ -1651,6 +1727,7 @@ class _TimedCursor:
1651
 
1652
  def _run(self, name, acc, execute, args, kwargs):
1653
  writes = False
 
1654
  bound_writer = None
1655
  transaction = None
1656
  if execute:
@@ -1661,13 +1738,15 @@ class _TimedCursor:
1661
  try:
1662
  statements = self._cursor.extract_statements(statement)
1663
  writes = any(s.type.name not in {"SELECT", "TRANSACTION"} for s in statements)
 
 
1664
  for parsed in statements:
1665
  if parsed.type.name == "TRANSACTION":
1666
  transaction = not re.match(r"\s*(COMMIT|ROLLBACK|END)\b", parsed.query, re.I)
1667
  except Exception as exc:
1668
  _request_timing.raise_if_resource_error(exc)
1669
  # Unclassified statements cannot establish a reusable read snapshot.
1670
- writes, self._in_transaction = True, True
1671
  if transaction is not None:
1672
  # A failed statement batch may leave its BEGIN active.
1673
  self._in_transaction = True
@@ -1677,7 +1756,7 @@ class _TimedCursor:
1677
  bound_writer = self._mirror_handle or _HANDLES_LIVE.get(str(self._mirror_path))
1678
  if bound_writer is not None:
1679
  bound_writer.active_writes += 1
1680
- _invalidate_counts(self._mirror_path)
1681
  started = time.perf_counter()
1682
  try:
1683
  with _request_timing.thread_scope(), _request_timing.duckdb_operation(self._cursor):
@@ -1695,7 +1774,7 @@ class _TimedCursor:
1695
  _ACTIVE_WRITES[0] -= 1
1696
  if bound_writer is not None:
1697
  bound_writer.active_writes -= 1
1698
- _invalidate_counts(self._mirror_path)
1699
  if acc is not None and self._request is acc:
1700
  elapsed = (time.perf_counter() - started) * 1000
1701
  self._statement_ms += elapsed
 
950
  _COUNT_CACHE_LOCK = _thr.RLock()
951
 
952
 
953
+ def _invalidate_counts(path=None, *, source_write=True):
954
+ """Clear count results for all writes; only source writes move the mirror identity."""
955
  with _COUNT_CACHE_LOCK:
 
956
  _COUNT_CACHE.clear()
957
+ if source_write:
958
+ _MIRROR_WRITES[0] += 1
959
+ handle = _HANDLES_LIVE.get(str(Path(path or DB_PATH).resolve()))
960
+ if handle is not None:
961
+ handle.writes += 1
962
 
963
 
964
  def note_mirror_install(path=None, *, cur=None):
 
989
 
990
 
991
  def mirror_writes(cur=None):
992
+ """Return permanent-source writes for this tenant, or the legacy single-store token."""
993
  handle = getattr(cur, "_mirror_handle", None)
994
  return handle.writes if handle is not None else _MIRROR_WRITES[0]
995
 
 
1561
  _follow_version(force=True)
1562
 
1563
 
1564
+ def _temporary_write(cur, statements):
1565
+ """Prove a single write affects only a local relation; unfamiliar cases stay source writes."""
1566
+ if len(statements) != 1:
1567
+ return False # A batch may create/drop a shadow before a later persistent write.
1568
+ try:
1569
+ sql = statements[0].query
1570
+ encoded = sql.encode("utf-8")
1571
+ tokens = duckdb.tokenize(sql)
1572
+ words = [encoded[start:tokens[i + 1][0] if i + 1 < len(tokens) else len(encoded)]
1573
+ .decode("utf-8").strip() for i, (start, _kind) in enumerate(tokens)]
1574
+ upper = [word.upper() for word in words]
1575
+ create = 3 if upper[:3] == ["CREATE", "OR", "REPLACE"] else 1
1576
+ if (upper[:1] == ["CREATE"] and len(upper) > create + 1
1577
+ and upper[create] in {"TEMP", "TEMPORARY"}
1578
+ and upper[create + 1] in {"TABLE", "VIEW"}):
1579
+ return True
1580
+ kind = "table"
1581
+ if upper[:2] in (["INSERT", "INTO"], ["DELETE", "FROM"]):
1582
+ index = 2
1583
+ elif upper[:1] == ["UPDATE"]:
1584
+ index = 1
1585
+ elif upper[:2] in (["DROP", "TABLE"], ["DROP", "VIEW"]):
1586
+ kind, index = upper[1].lower(), 2
1587
+ if upper[index:index + 2] == ["IF", "EXISTS"]:
1588
+ index += 2
1589
+ else:
1590
+ return False
1591
+ names = []
1592
+ fold = str.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")
1593
+ while index < len(words):
1594
+ word = words[index]
1595
+ if re.fullmatch(r'"(?:[^"]|"")+"', word):
1596
+ names.append(word[1:-1].replace('""', '"').translate(fold))
1597
+ elif _IDENT_OK.fullmatch(word):
1598
+ names.append(word.translate(fold))
1599
+ else:
1600
+ return False
1601
+ index += 1
1602
+ if index >= len(words) or words[index] != ".":
1603
+ break
1604
+ index += 1
1605
+ if not names or len(names) > 3:
1606
+ return False
1607
+ if upper[0] == "DROP" and words[index:] not in ([], [";"]):
1608
+ return False # In particular, CASCADE may affect persistent dependants.
1609
+ if len(names) == 3:
1610
+ if names[:2] != ["temp", "main"]:
1611
+ return False
1612
+ elif len(names) == 2 and names[0] == "temp":
1613
+ if cur.execute("SELECT EXISTS (SELECT 1 FROM duckdb_schemas() "
1614
+ "WHERE lower(schema_name)='temp' AND NOT internal)").fetchone()[0]:
1615
+ return False
1616
+ else:
1617
+ # Prove the default DuckDB search order, including TEMP shadows of main tables.
1618
+ # Custom search paths or ambiguous two-part catalog names remain conservative.
1619
+ if len(names) == 2 and names[0] != "main":
1620
+ return False
1621
+ schema, search, ambiguous = cur.execute(
1622
+ "SELECT current_schema(), current_setting('search_path'), "
1623
+ "EXISTS (SELECT 1 FROM duckdb_databases() WHERE lower(database_name)='main')"
1624
+ ).fetchone()
1625
+ if schema != "main" or search or (len(names) == 2 and ambiguous):
1626
+ return False
1627
+ catalogue, column = (("duckdb_views", "view_name") if kind == "view"
1628
+ else ("duckdb_tables", "table_name"))
1629
+ return cur.execute(
1630
+ f"SELECT count(*)=1 FROM {catalogue}() WHERE temporary AND schema_name='main' "
1631
+ f"AND translate({column}, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')=?",
1632
+ [names[-1]]).fetchone()[0]
1633
+ except Exception as exc:
1634
+ _request_timing.raise_if_resource_error(exc)
1635
+ return False
1636
+
1637
+
1638
  class _TimedCursor:
1639
  """Keep cursor chaining and thread-local identity while timing execute and result conversion."""
1640
 
 
1727
 
1728
  def _run(self, name, acc, execute, args, kwargs):
1729
  writes = False
1730
+ source_write = True
1731
  bound_writer = None
1732
  transaction = None
1733
  if execute:
 
1738
  try:
1739
  statements = self._cursor.extract_statements(statement)
1740
  writes = any(s.type.name not in {"SELECT", "TRANSACTION"} for s in statements)
1741
+ if writes:
1742
+ source_write = not _temporary_write(self._cursor, statements)
1743
  for parsed in statements:
1744
  if parsed.type.name == "TRANSACTION":
1745
  transaction = not re.match(r"\s*(COMMIT|ROLLBACK|END)\b", parsed.query, re.I)
1746
  except Exception as exc:
1747
  _request_timing.raise_if_resource_error(exc)
1748
  # Unclassified statements cannot establish a reusable read snapshot.
1749
+ writes, source_write, self._in_transaction = True, True, True
1750
  if transaction is not None:
1751
  # A failed statement batch may leave its BEGIN active.
1752
  self._in_transaction = True
 
1756
  bound_writer = self._mirror_handle or _HANDLES_LIVE.get(str(self._mirror_path))
1757
  if bound_writer is not None:
1758
  bound_writer.active_writes += 1
1759
+ _invalidate_counts(self._mirror_path, source_write=source_write)
1760
  started = time.perf_counter()
1761
  try:
1762
  with _request_timing.thread_scope(), _request_timing.duckdb_operation(self._cursor):
 
1774
  _ACTIVE_WRITES[0] -= 1
1775
  if bound_writer is not None:
1776
  bound_writer.active_writes -= 1
1777
+ _invalidate_counts(self._mirror_path, source_write=source_write)
1778
  if acc is not None and self._request is acc:
1779
  elapsed = (time.perf_counter() - started) * 1000
1780
  self._statement_ms += elapsed
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 3b5e8894edea476bd7dd250f8db2a6f22f250380b758a21524dca98c9f42bd9e
 
1
+ 5961efa485d5f97b5e51b75dbb137cc7e396465d94dfb66eff86cc268de083d7