Files
OmniRoute/docs/i18n/zh-TW/docs/ops/SQLITE_RUNTIME.md
Diego Rodrigues de Sa e Souza 8feea123bb feat(docs): mirror every docs/ page in all 65 locales (#14106)
* feat(docs): mirror every docs/ page in all 65 locales

Extends the documentation mirrors from the 22-page core set (#13940) to
every Markdown page under docs/: 152 sources x 65 locales = 9,880 mirrors
(6,208 new), language bars rewritten for the full locale list, state
adopted so the blocking drift gate now covers all 152 pages.

run-translation.mjs: an oversized block made only of table rows or list
items (PROVIDER_REFERENCE.md 244-row table, FREE_TIERS.md 71-item list) is
cut at item boundaries and rejoined without a blank line — the single
16-40 KB request outlived the backend socket for verbose scripts. 48
older mirrors whose tables had lost rows were retranslated with --force.

* docs(i18n): refresh mirrors for the sources the base changed since the branch cut

Section-level retranslation of the 29 docs (and README.md) whose source
or mirrors moved on release/v3.8.51 during the run, then state adoption;
the drift gate is green again on the merged tree.
2026-09-18 13:16:46 -03:00

7.9 KiB
Raw Blame History

SQLite Runtime Resolution (中文 (繁體))

🌐 Languages: 🇺🇸 English · 🇪🇹 am · 🇸🇦 ar · 🇦🇿 az · 🇧🇬 bg · 🇧🇩 bn · 🇨🇿 cs · 🇩🇰 da · 🇩🇪 de · 🇬🇷 el · 🇪🇸 es · 🇪🇪 et · 🇮🇷 fa · 🇫🇮 fi · 🇫🇷 fr · 🇮🇪 ga · 🇮🇳 gu · 🇳🇬 ha · 🇮🇱 he · 🇮🇳 hi · 🇭🇷 hr · 🇭🇺 hu · 🇦🇲 hy · 🇮🇩 id · 🇳🇬 ig · 🇮🇹 it · 🇯🇵 ja · 🇬🇪 ka · 🇰🇭 km · 🇮🇳 kn · 🇰🇷 ko · 🇱🇹 lt · 🇱🇻 lv · 🇮🇳 ml · 🇮🇳 mr · 🇲🇾 ms · 🇲🇹 mt · 🇲🇲 my · 🇳🇵 ne · 🇳🇱 nl · 🇳🇴 no · 🇮🇳 or · 🇮🇳 pa · 🇵🇭 phi · 🇵🇱 pl · 🇵🇹 pt · 🇧🇷 pt-BR · 🇷🇴 ro · 🇷🇺 ru · 🇱🇰 si · 🇸🇰 sk · 🇸🇮 sl · 🇷🇸 sr · 🇸🇪 sv · 🇰🇪 sw · 🇮🇳 ta · 🇮🇳 te · 🇹🇭 th · 🇹🇷 tr · 🇺🇦 uk-UA · 🇵🇰 ur · 🇺🇿 uz · 🇻🇳 vi · 🇳🇬 yo · 🇨🇳 zh-CN


OmniRoute 在啟動時會透過 5 步驟的備援鏈解析其 SQLite 驅動程式:

  1. 隨附的 better-sqlite3(透過 package.json 中的 dependencies — 速度最快、使用原生二進位檔;當建置工具可用時,由 npm install 安裝。

  2. 執行階段安裝的 better-sqlite3(位於 ~/.omniroute/runtime/ — 在首次執行時延遲安裝,scripts/build/postinstall.mjs → scripts/postinstall.mjs 安裝。 載入前會驗證原生 .node 魔術位元組ELF / Mach-O / PE 以防止載入損毀或屬於錯誤平台的二進位檔。

  3. node:sqliteNode ≥22.5 標準函式庫)— 不需要原生建置;當 兩個 better-sqlite3 路徑都失敗時使用。功能集有限。

  4. sql.jsWASM— 最終備援方案。可在任何環境中運作,但速度較慢, 且會按固定時間間隔寫入資料,而非同步寫入。

為什麼需要這麼複雜?

  • Windows EBUSY:如果先前版本的 better_sqlite3.node 被執行中的處理程序 鎖定,npm install -g omniroute@latest 可能會失敗。安裝至 ~/.omniroute/runtime/ 的執行階段安裝方式可避開全域 npm 快取。
  • 缺少建置工具:某些環境(沒有 VS Build Tools 的企業 Windows 環境、 最小化 Docker 映像)無法編譯 better-sqlite3。執行階段安裝程式會從 npm 登錄檔解析預先建置的二進位檔;即使此步驟失敗,備援驅動程式仍可確保 OmniRoute 能夠啟動。
  • 實體隔離系統:如果無法連線至 npm 登錄檔,node:sqlitesql.js 可確保基本功能仍然可用。

魔術位元組驗證

載入執行階段安裝的 .node 檔案前OmniRoute 會讀取前 8 個 位元組,並與已知的平台魔術位元組進行比對:

平台 位元組(十六進位) 標籤
Linux 7F 45 4C 46 elf
macOS 64 位元 BE FE ED FA CF macho
macOS 64 位元 LE CF FA ED FE macho-le
macOS fat通用格式 CA FE BA BE macho-fat
Windows 4D 5A (MZ) pe

若魔術位元組不相符 → 忽略該檔案,並繼續執行下一個備援步驟。

檢查使用中的驅動程式

import { getDriverInfo } from "@/lib/db/core";

const info = getDriverInfo();
// { source: "bundled" | "runtime" | "runtime-installed-now" | "node-sqlite" | "sql-js",
//   kind: "better-sqlite3" | "node-sqlite" | "sql-js" }

手動控制

# 略過 postinstall 預熱(適用於快速 CI 安裝)
OMNIROUTE_SKIP_POSTINSTALL=1 npm install -g omniroute

# 強制重新安裝執行階段 better-sqlite3
rm -rf ~/.omniroute/runtime
omniroute  # 將於下次啟動時重新安裝

# 檢查目前使用中的驅動程式
omniroute config db-info  # (如果 CLI 命令存在)

參考資料

實作:

  • bin/cli/runtime/magicBytes.mjs — 二進位魔術位元組驗證輔助工具
  • bin/cli/runtime/sqliteRuntime.mjs — 5 步驟執行階段解析器 + 延遲安裝程式
  • bin/cli/runtime/index.mjs — 啟動協調器(warmUpRuntimes()
  • scripts/postinstall.mjs — npm 安裝後掛鉤(非致命性預熱)
  • src/lib/db/core.ts — 匯出 ensureDbInitialized() / getDriverInfo()

單一寫入者拓撲(不支援 HA

上述驅動程式備援鏈仍在單一處理程序中執行。使用預設 SQLite 的 OmniRoute 是單一寫入者

  • 請勿將兩個 OmniRoute 複本連接至相同的 storage.sqlite 檔案。
  • 容器重新啟動、Recreate 部署、OOM 終止或 HEALTHCHECK 重新啟動,都會中斷 所有進行中的 SSE 工作階段。預設路徑不提供工作階段排空機制。
  • 如果協調器的存活性檢查將回應緩慢的 /healthz 視為故障,便會終止唯一的 複本。存活性檢查建議使用 TCP而就緒狀態檢查則使用 HTTP /healthz。請參閱 Docker 指南 — 可用性Kubernetes 探查建議