Ops: Day-to-Day Operations
A Source Graph instance mostly runs itself: background workers synchronize repositories, index new branch heads and remove retired indexes. Operating it means watching health and jobs, keeping enough disk, reclaiming space when needed and knowing what an error code is telling you. Administrators do most of this from the website's Operations, Repositories and Settings pages; the same actions exist under /sourcegraph/api/admin/.
Health and status
| Check | Use |
|---|---|
GET /sourcegraph/healthz | Liveness — returns {"status":"alive"}; suitable for platform health checks |
GET /sourcegraph/readyz | Readiness — succeeds only when the repository catalog can be read; 503 otherwise |
GET /sourcegraph/access-policy | Whether public reading and sign-in are enabled |
| Operations page | Service status, request counts, mean and maximum time and error rate for search, read and read_many, active jobs, and per-instance heartbeats |
The Query errors page in settings keeps the most recent 1,000 failed queries with their request details; administrators can inspect or clear it. One entry represents one request. A read_many request also records batch counters — total items, succeeded, failed and returned content items — so a partly failed batch shows how much was still read: an empty file counts as a success, and an item that returned part of a file together with an error counts as failed with content. Older entries without counters are shown as unknown.
Background jobs
Every repository has its own job list, shown on the repository page's jobs tab.
- Kinds:
syncfetches monitored branches,indexbuilds an index for one commit, andpreparesynchronizes and indexes a requested commit, across all path groups if needed. - States:
queued,running,succeeded,failedorcancelled. - Automatic and manual work run on separate workers, so a long manual preparation does not block scheduled syncs.
- Recovery: a running job holds a 45-second lease that its worker renews. If a process dies, another worker takes the job over after the lease expires; after three attempts it fails with
RECOVERY_EXHAUSTED. Persisted jobs resume after a restart. - Budgets: a sync or index job may run for 45 minutes, or for the repository's Git timeout if that is longer (at most 60 minutes); a prepare job up to 16 times that, one path group after another.
- Capacity: up to 8 active jobs per repository (or one per path group when a monorepo has more than 8 groups), and at most 256 recorded jobs. A full queue returns
QUEUE_FULL. - Storage upkeep: jobs keep the repository within its storage budget themselves. A sync checks the budget before its Git fetch, a prepare job before fetching a SHA and an index job before it builds, releasing the oldest unprotected snapshots when needed. Preparation and index tasks first finish any Git collection still pending for the repository, and apply retention as soon as they publish. See Disk and storage.
Besides jobs, two background passes run every minute: an index collection round and a separate Git collection pass, both described in Disk and storage. Neither appears in the job list.
You can cancel a queued or running job from the jobs tab. Failed jobs also leave a short failure summary — task ID, kind, path group, commit, error code, attempts, completion time and duration, without raw error output or credentials — that outlives the job record (see below). It is history for diagnosis, not a sign of current readiness, and it does not use queue capacity or affect scheduling. Each completed job is also written to the service log as a structured repository_task_completed event with its repository, task, state and error code; unchanged automatic syncs that succeed are left out. Finished jobs are pruned automatically (see below); Clear completed tasks in settings removes finished records across all repositories immediately, keeping queued and running work, repositories and indexes; clearing failure history removes failure summaries with the same cutoff.
What is kept, and for how long
| Data | Retention |
|---|---|
| Snapshots | Current branch heads, pinned snapshots and commits of queued or running jobs are protected and always kept. Other snapshots follow the repository's retention — days since first observation or the number of most recently observed snapshots — applied after each successful sync and right after each preparation or index task publishes. When a path group reaches 4096 snapshots or the repository reaches its storage budget, the oldest unprotected snapshots are released first (see Disk and storage) |
| Search indexes | One per indexed commit; generations no retained snapshot references are removed when snapshots are released and by the background collection round |
| Git objects | Objects not reachable from any retained snapshot are removed by Git collection once snapshots are released; retained snapshots keep their complete trees and available files. Without synchronization, preparation or indexing nothing expires automatically |
| Branch and tag catalogs | Kept in service memory and refreshed in the background once older than 5 minutes (or three times the last refresh duration); exact lookups are cached for 30 seconds. Downloaded ref objects are deleted right after parsing |
| Finished jobs | 24 hours, or longer while a request receipt still refers to them. Automatic jobs keep at most 32 recent entries, and automatic syncs that found no changes are dropped right away |
| Job failure summaries | 7 days, at most 128 per repository; the oldest are dropped first |
| Request receipts (idempotency) | 24 hours, at most 256 per repository |
| Query error log | The most recent 1,000 entries |
| Usage observations behind the statistics | 30 days |
| Browser sessions | 90 days |
Identities, settings, pins, retention settings and stored credentials are never expired automatically; back them up as described in Ops: Self-Hosting Source Graph.
Rate limits
Two kinds of traffic are rate-limited in one-minute windows:
| Traffic | Limit |
|---|---|
| Anonymous requests | 1,200 per client and 3,000 in total per minute |
MCP prepare with a personal API key | 10 per key and 60 in total per minute |
An anonymous client is identified by its connection address; forwarded-for headers are not trusted. Behind a reverse proxy every anonymous request therefore arrives from the proxy's address and shares one per-client allowance. When a limit is reached the response is 429 RATE_LIMITED with Retry-After: 60. Signed-in sessions, other personal-key traffic and the service token are not rate-limited, so give heavy automated callers their own credential rather than relying on anonymous access. Per-request bounds — page sizes, line and byte limits — still apply to everyone; see HTTP and MCP.
Manual preparation is also paced per repository, whoever asks and through whichever surface — the website, HTTP or MCP. A request identical to a queued or running job (same path group, kind and revision) simply returns that job and adds no load. Any other new manual request within 30 seconds of the repository's last accepted one returns 429 RATE_LIMITED with Retry-After set to the remaining seconds. One request that queues every monorepo group counts once, and scheduled syncs and indexing are not paced.
Disk and storage
Fetching, indexing and ref downloads stop with INSUFFICIENT_STORAGE when the instance's free space falls below SOURCEGRAPH_MIN_FREE_BYTES (1 GiB by default). This floor protects the whole instance and is separate from any repository's budget. Reads and searches of existing indexes keep working. Keep extra free space for replacement packs, index builds, Git compaction and ref downloads.
Repository storage budget. Each repository has its own Storage budget (100 GiB by default, 1 GiB to 10 TiB) covering its Git objects, index shards and active preparation files. When usage reaches it, or a path group reaches 4096 snapshots, the oldest unprotected snapshots — by first observation — and their indexes are released instead of refusing work. Branch heads, pinned snapshots and commits of queued or running jobs are never released. Releases happen only at safe points inside the repository's own jobs:
- before the Git fetch of a sync or of a SHA preparation;
- before an index build starts, reserving 1.2 times the size of the path group's previous index;
- after a preparation or index task finishes.
The service first removes expired indexes, then releases at most 64 snapshots per batch in one update while holding the query lock, so reads of those versions finish first. Indexes that nothing references are removed, Git keeps only the retained snapshots and repacks reachable objects after checking free space, and usage is measured again; further batches follow until the reservation fits or nothing unprotected remains. Each batch is logged as snapshot_eviction. Released versions answer REVISION_NOT_ELIGIBLE and can be prepared again. A running build releases nothing, because its files are in use, and is stopped with REPOSITORY_STORAGE_LIMIT only above 120% of the budget; the release after it brings usage back under budget. Git compaction needs temporary working space and may briefly exceed the budget while it reclaims objects. When protected snapshots alone fill the budget or the 4096 versions, work stops with REPOSITORY_STORAGE_LIMIT or SNAPSHOT_LIMIT; remove pins you do not need or raise the budget.
Index collection. Index generations that no retained snapshot references are collected once their manifest is more than five minutes old: right after retention or a capacity release, and in a background round every minute that works repository by repository within a 30-second budget, deferring a repository with a running job to the next round. The Operations page shows pending expired indexes, deferred repositories, the last reclaim and the last problem; the same figures are in index_collection of GET /sourcegraph/api/admin/v1/statistics. The repository list can be sorted by disk usage to find the largest repositories.
Git collection. The control data decides which snapshots exist, and Git collection follows it. Each path group's Git store keeps a retention marker naming the snapshots it was last collected for. Before any change that releases versions commits — retention after a sync, preparation or index task, a capacity release or the 4096 limit — the marker of each affected path group is removed; if that fails, nothing is committed and the request returns RECLAIM_FAILED. A missing marker, or one naming a released commit, therefore means collection is unfinished, and only a successful collection writes it again. A separate background pass every minute, one pass at a time, finishes collection for such repositories using each repository's Git timeout rather than the index round's 30-second budget; a repository that is busy waits for the next pass. When a repository's files cannot be inspected, the pass logs git_reclaim_check with the repository, path group and a reason such as permission_denied, and checks it again next time. Preparation and index tasks also finish pending collection before they start, so an interrupted process or a failing later sync does not keep released space.
Ref discovery. Branch and tag catalogs (refs) and exact lookups of unmonitored names (resolve) download only commit and tag objects, without file trees, into scratch directories under refcache/tmp in the data directory. Each directory is removed after parsing, and any left by a stopped process are removed at startup. Every download is checked each second against its own limit — 256 MiB for a catalog refresh, 16 MiB for a lookup — a 4 GiB total for all ref downloads together and the instance free-space reserve, and is stopped and deleted when any is exceeded; a catalog over its limit is served with names only. At most 4 catalog refreshes run per instance; lookups run at most 2 per repository and 8 per instance, with at most 64 running or waiting, and a repository whose remote fails is backed off from 10 seconds up to 5 minutes. Catalogs live in service memory; beyond 1,000,000 refs in total the least recently used ones are dropped. A first listing that is not ready in time returns REFS_CATALOG_PREPARING, a busy, failing or backed-off remote REMOTE_UNAVAILABLE, and a remote the repository's code-source token cannot read REMOTE_ACCESS_DENIED; see Common errors.
Storage location. The Storage settings page shows where the bare Git mirrors live and lets an administrator move them to another absolute directory on the server; the service keeps them in a space folder inside it. Search indexes and their manifests always stay in the data root, so size both locations. Switching deletes the old Git copies and indexes, and every repository synchronizes and indexes again from the chosen location; preparation pauses until the old data has been cleaned up.
Repository maintenance
The repository page offers maintenance actions, each with a preview that shows what will be kept and how many bytes will be reclaimed:
- Create index — index a recent snapshot of a monitored branch, or any full 40-character SHA. A SHA that has not been synchronized is fetched directly and kept as an ordinary snapshot, released oldest first by retention and capacity like any other; add it to Pinned snapshots in settings to keep it. Ready indexes are reused.
- Clean old indexes — remove indexes other than the latest one of each monitored branch and the pinned snapshots. When a latest index is not ready yet, it removes only expired indexes and keeps the index of every retained version; the preview then shows
expired_only: true. - Delete — permanently remove the repository, its Git mirror and its indexes.
Stop running jobs before maintenance; otherwise it returns REPOSITORY_BUSY. A repository can also be disabled or soft-deleted from its settings, which keeps its data; a disabled, deleted repository can be purged for good one minute later.
Common errors
| Code | Status | What it means | What to do |
|---|---|---|---|
INDEX_NOT_READY | 409 | The commit is eligible but not indexed | Wait for the head index, or prepare that commit |
CONTENT_NOT_READY, SCOPE_NOT_READY | 409 | A monorepo path group is not prepared or synchronized at that commit | Prepare the commit for that group |
REVISION_NOT_ELIGIBLE | 404 | The commit is not among the repository's retained snapshots: it was never observed or prepared, or retention or capacity released it | Check the repository and full SHA together; to use a specific commit, prepare its full SHA. Never substitute another commit |
REPOSITORY_NOT_FOUND | 404 | The repository is not registered, or it is private and your credential cannot see it | Check the name, or ask its creator, a manager or an administrator for access |
BRANCH_NOT_MONITORED | 404 | The branch is not in the policy | Resolve it to a full SHA with resolve and prepare that, or add it to the repository's branches |
SHORT_SHA_UNSUPPORTED, INVALID_REVISION | 400 | Abbreviated SHA, HEAD, a revision expression or a name with unsupported characters | Pass a full 40-character SHA or a monitored branch; find the commit of a branch or tag with refs or resolve |
DEFAULT_BRANCH_NOT_OBSERVED | 409 | No sync has recorded the default branch yet | Wait for or request a sync |
PATH_NOT_REGISTERED | 400 | The path is outside the monorepo's path groups | Search registered paths, or add a group |
GIT_AUTH_FAILED, GIT_ACCESS_DENIED | 401, 403 | The Git host rejected the token | Update the personal or global token for the repository's code source (GitHub or custom Git) |
GIT_REPOSITORY_UNAVAILABLE | 404 | The repository does not exist, or the token used cannot see it; code hosts answer both the same way | Check the repository name, then the token's access to it. A user-registered repository is fetched with its creator's token first, then the global one |
PARTIAL_CLONE_UNSUPPORTED | 422 | The Git server cannot filter blobs for monorepo mode | Register in full mode, or use a server that supports partial clone |
HISTORY_SCAN_LIMIT | 422 | A fetch would scan more history than allowed | Narrow the retention policy or use a count |
REPOSITORY_STORAGE_LIMIT | 409 | Protected snapshots — branch heads, pins and active jobs — alone fill the repository's storage budget, or a running build passed 120% of it | Remove pins you do not need or raise the budget; older ordinary snapshots are released before the next attempt |
SNAPSHOT_LIMIT | 409 | Protected snapshots fill a path group's 4096 versions | Remove pins you do not need |
INSUFFICIENT_STORAGE | 503 (507 from ref discovery) | The instance's free disk is below SOURCEGRAPH_MIN_FREE_BYTES; this is not the repository budget | Free or add disk |
RECLAIM_FAILED | 503 | Releasing snapshots could not be completed safely, or their collection did not finish; collection continues in the background | Retry shortly; if it persists, check the retention_marker, git_reclaim and git_reclaim_check log events |
REFS_CATALOG_PREPARING | 503 | The first branch or tag listing of the repository is still being prepared | Retry after Retry-After, or resolve a complete branch or tag name meanwhile |
REMOTE_UNAVAILABLE | 502, 503 | The remote is unavailable, timed out or backed off, or ref downloads are using their whole disk allowance | Retry after Retry-After |
REMOTE_ACCESS_DENIED | 502 | The code-source token this repository uses cannot read its remote; the caller's own key is not the cause | A repository manager checks the creator's or global token for the code source |
QUEUE_FULL | 503 | Too many active or recorded jobs | Let jobs finish, cancel some, or clear finished jobs |
ENGINE_RESPONSE_TOO_LARGE | 502 | Even the smallest result page exceeded its budget | Narrow the pattern, globs or paths |
RATE_LIMITED | 429 | A rate limit or the per-repository preparation pacing was reached | Wait for the Retry-After seconds, or use a credential |
Git fetches and object hydration stop after the repository's Git timeout: 15 minutes by default, set globally in system settings to 15, 30, 45 or 60 minutes and overridable per repository. A task takes the value current when it starts; changing it does not interrupt running work or remove indexes, and it does not limit total indexing time. The background Git collection pass uses the same per-repository timeout.
运维:日常运维与排障
Source Graph 实例基本可以自行运转:后台 worker 会同步仓库、为新的分支最新提交建索引,并移除已退役的索引。运维工作主要是关注健康状态和任务、保证磁盘充足、在需要时回收空间,以及读懂错误码的含义。管理员的大部分操作都可以在网站的 Operations(运维)、Repositories(仓库)和 Settings(设置)页面完成;同样的操作也在 /sourcegraph/api/admin/ 下提供。
健康与状态
| 检查项 | 用途 |
|---|---|
GET /sourcegraph/healthz | 存活检查——返回 {"status":"alive"};适合用作平台健康检查 |
GET /sourcegraph/readyz | 就绪检查——仅当仓库目录可读时成功,否则返回 503 |
GET /sourcegraph/access-policy | 是否开启了公开阅读和登录 |
| Operations 页面 | 服务状态;search、read 和 read_many 的请求数、平均与最长耗时及错误率;活跃任务;以及各实例的心跳 |
设置中的 Query errors 页面保留最近 1,000 条失败查询及其请求详情;管理员可以查看或清空。每条记录对应一次请求。read_many 请求还会记录批量计数——总条目数、成功数、失败数和返回内容的条目数——因此部分失败的批次也能看出还读到了多少:空文件算作成功,返回了部分文件内容同时带有错误的条目算作失败但有内容。没有计数的旧记录显示为未知。
后台任务
每个仓库都有自己的任务列表,显示在仓库页面的任务标签页中。
- 类型:
sync拉取监控分支,index为单个提交建索引,prepare同步并为请求的提交建索引,必要时覆盖所有路径组。 - 状态:
queued、running、succeeded、failed或cancelled。 - 自动与手动任务 运行在不同的 worker 上,因此耗时较长的手动准备不会阻塞定时同步。
- 恢复: 运行中的任务持有一个 45 秒的租约,由其 worker 续期。如果进程退出,租约到期后会由另一个 worker 接管该任务;重试三次后任务失败并返回
RECOVERY_EXHAUSTED。已持久化的任务会在重启后继续执行。 - 时间预算: sync 或 index 任务最长可运行 45 分钟,若仓库的 Git 超时更长则以其为准(最多 60 分钟);prepare 任务最长可达其 16 倍,逐个路径组依次执行。
- 容量: 每个仓库最多 8 个活跃任务(当 Monorepo 的路径组多于 8 个时,每个路径组一个),最多记录 256 个任务。队列已满时返回
QUEUE_FULL。 - 存储维护: 任务自己负责让仓库保持在存储预算之内。sync 在 Git 拉取前、prepare 任务在拉取 SHA 前、index 任务在建索引前都会检查预算,必要时释放最旧的未受保护快照。准备和索引任务会先完成该仓库仍待进行的 Git 回收,并在发布后立即应用保留策略。见 磁盘与存储。
除任务外,还有两个每分钟运行一次的后台流程:一轮索引回收和一个独立的 Git 回收流程,两者都在 磁盘与存储 中说明。它们都不会出现在任务列表中。
你可以在任务标签页中取消排队中或运行中的任务。失败的任务还会留下一份简短的失败摘要——任务 ID、类型、路径组、提交、错误码、尝试次数、完成时间和耗时,不含原始错误输出或凭据——它比任务记录保留得更久(见下文)。它是用于诊断的历史,并不代表当前已就绪,也不占用队列容量或影响调度。每个完成的任务还会以结构化的 repository_task_completed 事件写入服务日志,包含仓库、任务、状态和错误码;未发现变更且成功的自动同步不会写入。已结束的任务会被自动清理(见下文);设置中的 Clear completed tasks 会立即移除所有仓库中已结束的任务记录,保留排队中和运行中的任务、仓库及索引;清除失败历史时,会按同一截止时间移除失败摘要。
保留哪些数据,保留多久
| 数据 | 保留策略 |
|---|---|
| 快照 | 当前的分支最新提交、被固定的快照,以及排队中或运行中任务所用的提交都受保护,始终保留。其他快照遵循仓库的保留策略——按首次观察到之后的天数,或按最近观察到的快照数量——在每次同步成功后,以及每个准备或索引任务发布后立即应用。当某个路径组达到 4096 个快照或仓库达到其存储预算时,最旧的未受保护快照会最先被释放(见 磁盘与存储) |
| 搜索索引 | 每个已建索引的提交一份;不被任何保留快照引用的代,会在快照被释放时以及由后台回收轮次移除 |
| Git 对象 | 不能从任何保留快照到达的对象,会在快照被释放后由 Git 回收移除;保留的快照会保留其完整的目录树和可用文件。没有同步、准备或建索引时,任何内容都不会自动过期 |
| 分支和标签目录 | 保存在服务内存中,超过 5 分钟(或上次刷新耗时的三倍)后在后台刷新;精确查询结果缓存 30 秒。下载的引用对象在解析后立即删除 |
| 已结束的任务 | 24 小时;如果仍有请求回执引用它们,则保留更久。自动任务最多保留最近 32 条,未发现变更的自动同步会立即丢弃 |
| 任务失败摘要 | 7 天,每个仓库最多 128 条;超出时先丢弃最旧的 |
| 请求回执(幂等) | 24 小时,每个仓库最多 256 条 |
| 查询错误日志 | 最近 1,000 条 |
| 统计数据所依据的使用记录 | 30 天 |
| 浏览器会话 | 90 天 |
身份、设置、固定、保留设置和已存储的凭据永远不会自动过期;请按照 运维:自行部署 Source Graph 中的说明进行备份。
限流
以下两类流量以一分钟为窗口进行限流:
| 流量 | 限制 |
|---|---|
| 匿名请求 | 每个客户端每分钟 1,200 次,总计每分钟 3,000 次 |
使用个人 API Key 调用 MCP prepare | 每个 Key 每分钟 10 次,总计每分钟 60 次 |
匿名客户端按其连接地址识别,不信任 forwarded-for 类请求头。因此在反向代理之后,所有匿名请求都来自代理的地址,共享同一个单客户端额度。触发限制时返回 429 RATE_LIMITED,并带有 Retry-After: 60。已登录会话、其他个人 Key 流量和服务令牌都不受限流约束,所以请为调用量大的自动化程序分配独立凭据,而不要依赖匿名访问。单请求的上限——分页大小、行数和字节数限制——仍对所有人生效;参见 HTTP 与 MCP 接口。
手动准备还会按仓库统一限速,无论由谁发起、通过哪个入口——网站、HTTP 或 MCP。与已排队或正在运行的任务完全相同(同一路径组、类型和版本)的请求会直接返回该任务,不增加负载。距该仓库上一次被接受的请求不足 30 秒的其他新手动请求,会返回 429 RATE_LIMITED,并把 Retry-After 设为剩余的秒数。一次为 Monorepo 所有路径组排队的请求只计一次,定时同步和建索引不受限速。
磁盘与存储
当实例的可用空间低于 SOURCEGRAPH_MIN_FREE_BYTES(默认 1 GiB)时,拉取、建索引和引用下载会停止并返回 INSUFFICIENT_STORAGE。这个下限保护的是整个实例,与任何仓库的存储预算无关。对现有索引的读取和搜索不受影响。请为替换用的 pack 文件、索引构建、Git 压缩和引用下载预留额外的可用空间。
仓库存储预算。 每个仓库都有自己的 Storage budget(存储预算,默认 100 GiB,范围 1 GiB 到 10 TiB),涵盖其 Git 对象、索引分片和进行中的准备文件。用量达到预算,或某个路径组达到 4096 个快照时,服务会按首次观察时间释放最旧的未受保护快照及其索引,而不是拒绝工作。分支最新提交、被固定的快照,以及排队中或运行中任务所用的提交永远不会被释放。释放只在仓库自身任务内的安全时机进行:
- 同步或 SHA 准备执行 Git 拉取之前;
- 建索引开始之前,预留该路径组上一份索引大小的 1.2 倍;
- 准备或索引任务完成之后。
服务先移除已过期的索引,然后在持有查询锁的情况下,以一次更新每批最多释放 64 个快照,因此对这些版本的读取会先完成。没有任何引用的索引会被移除,Git 只保留仍被保留的快照,并在检查可用空间后重新打包可达对象,然后重新测量用量;之后继续分批释放,直到预留空间足够或不再有未受保护的快照。每一批都会以 snapshot_eviction 记录日志。已释放的版本返回 REVISION_NOT_ELIGIBLE,可以再次准备。正在进行的构建不会释放任何内容,因为它的文件正在使用中;只有超出预算的 120% 时,它才会以 REPOSITORY_STORAGE_LIMIT 停止,构建之后的释放会让用量回到预算之内。Git 压缩需要临时工作空间,在回收对象时可能短暂超出预算。当受保护的快照本身就占满存储预算或 4096 个版本时,工作会以 REPOSITORY_STORAGE_LIMIT 或 SNAPSHOT_LIMIT 停止;请移除不需要的固定,或提高预算。
索引回收。 不被任何保留快照引用的索引代,在其清单生成超过五分钟后会被回收:时机包括应用保留策略或容量释放之后立即进行,以及每分钟一轮的后台回收——后台回收在 30 秒预算内逐个仓库进行,遇到有任务正在运行的仓库时推迟到下一轮。Operations 页面显示待回收的过期索引、被推迟的仓库、最近一次回收和最近一次问题;GET /sourcegraph/api/admin/v1/statistics 的 index_collection 中也有相同的数据。仓库列表可以按磁盘用量排序,以找出最大的仓库。
Git 回收。 控制数据决定哪些快照存在,Git 回收以它为准。每个路径组的 Git 存储都保存一个保留标记,记录上一次回收所依据的快照。在任何释放版本的变更提交之前——同步、准备或索引任务之后的保留策略、容量释放或 4096 上限——都会先移除每个受影响路径组的标记;如果移除失败,则不提交任何变更,请求返回 RECLAIM_FAILED。因此,标记缺失或标记中列有已释放的提交,就表示回收尚未完成,只有成功的回收才会重新写入标记。另有一个每分钟运行一次的独立后台流程(同一时间只运行一个),为这类仓库完成回收,它使用各仓库的 Git 超时,而不是索引回收轮次的 30 秒预算;正忙的仓库等待下一次。无法检查某个仓库的文件时,该流程会记录 git_reclaim_check,包含仓库、路径组和原因(如 permission_denied),并在下一次再次检查。准备和索引任务在开始前也会完成待进行的回收,因此进程中断或之后的同步失败都不会让已释放的空间一直被占用。
引用发现。 分支和标签目录(refs)以及未被监控名称的精确查询(resolve)只下载提交对象和标签对象(不含文件树),存放在数据目录下 refcache/tmp 中的临时目录里。每个目录在解析后删除,进程停止时遗留的目录会在启动时清除。每次下载每秒都会检查是否超出其自身上限(目录刷新 256 MiB,单次查询 16 MiB)、所有引用下载合计 4 GiB 的上限以及实例的空闲空间预留,任一项超出即停止并删除;超出上限的目录只提供名称。每个实例最多同时运行 4 个目录刷新;查询每个仓库最多同时 2 个、每个实例最多 8 个,运行中与等待中合计最多 64 个;远端失败的仓库会退避,时长从 10 秒逐步增加到 5 分钟。目录保存在服务内存中;引用总数超过 1,000,000 时,丢弃最近最少使用的目录。首次列出未能及时就绪时返回 REFS_CATALOG_PREPARING;远端繁忙、失败或正在退避时返回 REMOTE_UNAVAILABLE;仓库的代码源令牌无法读取远端时返回 REMOTE_ACCESS_DENIED;见 常见错误。
存储位置。 Storage(存储)设置页显示裸 Git 镜像的存放位置,管理员可以将其迁移到服务器上的另一个绝对路径目录;服务会把镜像放在该目录下的 space 文件夹中。搜索索引及其清单始终保留在数据根目录中,因此两个位置的容量都要规划好。切换位置会删除旧的 Git 副本和索引,所有仓库会在所选位置重新同步和建索引;在旧数据清理完成前,准备操作会暂停。
仓库维护
仓库页面提供若干维护操作,每项操作都有预览,显示将保留哪些内容以及将回收多少字节:
- Create index——为监控分支的某个近期快照,或任意 40 位完整 SHA 建索引。尚未同步的 SHA 会被直接拉取,作为普通快照保留,与其他快照一样由保留策略和容量限制按从旧到新的顺序释放;要一直保留它,请在设置中把它加入 Pinned snapshots。已就绪的索引会被复用。
- Clean old indexes——移除除每个监控分支最新索引和已固定快照索引之外的索引。当某个最新索引尚未就绪时,它只移除已过期的索引,并保留每个保留版本的索引;此时预览会显示
expired_only: true。 - Delete——永久移除仓库、其 Git 镜像和索引。
执行维护前请先停止运行中的任务,否则会返回 REPOSITORY_BUSY。也可以在仓库设置中停用或软删除仓库,这样会保留其数据;已停用并删除的仓库在一分钟后可以被彻底清除。
常见错误
| 错误码 | 状态码 | 含义 | 处理方式 |
|---|---|---|---|
INDEX_NOT_READY | 409 | 提交符合条件,但尚未建索引 | 等待分支最新提交的索引,或对该提交执行 prepare |
CONTENT_NOT_READY、SCOPE_NOT_READY | 409 | Monorepo 的某个路径组在该提交上尚未准备或同步 | 为该路径组准备该提交 |
REVISION_NOT_ELIGIBLE | 404 | 该提交不在仓库保留的快照中:它从未被观察到或准备过,或者已被保留策略或容量限制释放 | 先把仓库和完整 SHA 一起核对;要使用某个特定提交,就对它的完整 SHA 执行 prepare。不要用其他提交代替 |
REPOSITORY_NOT_FOUND | 404 | 仓库未登记,或者是私有仓库且你的凭据看不到它 | 核对名称,或向其创建者、管理者或管理员申请访问权限 |
BRANCH_NOT_MONITORED | 404 | 该分支不在保留策略中 | 用 resolve 把它解析为完整 SHA 并准备该 SHA,或将其加入仓库的分支列表 |
SHORT_SHA_UNSUPPORTED、INVALID_REVISION | 400 | 使用了短 SHA、HEAD、版本表达式,或包含不支持字符的名称 | 传入完整的 40 位 SHA 或监控分支;用 refs 或 resolve 查找分支或标签的提交 |
DEFAULT_BRANCH_NOT_OBSERVED | 409 | 尚无同步记录到默认分支 | 等待同步或主动请求同步 |
PATH_NOT_REGISTERED | 400 | 路径不在 Monorepo 的路径组内 | 搜索已登记的路径,或添加路径组 |
GIT_AUTH_FAILED、GIT_ACCESS_DENIED | 401、403 | Git 托管平台拒绝了令牌 | 更新仓库所属代码源(GitHub 或自定义 Git)的个人或全局令牌 |
GIT_REPOSITORY_UNAVAILABLE | 404 | 仓库不存在,或所用令牌看不到它;代码托管平台对两者的回应相同 | 先核对仓库名,再检查令牌对它的访问权限。用户登记的仓库先使用其创建者的令牌拉取,再使用全局令牌 |
PARTIAL_CLONE_UNSUPPORTED | 422 | Git 服务器无法为 Monorepo 模式过滤 blob | 以全量模式登记,或使用支持部分克隆的服务器 |
HISTORY_SCAN_LIMIT | 422 | 一次拉取要扫描的历史超出允许范围 | 收窄保留策略,或改用数量 |
REPOSITORY_STORAGE_LIMIT | 409 | 受保护的快照(分支最新提交、固定快照和活动任务所用的快照)本身就占满了仓库的存储预算,或正在进行的构建超出预算的 120% | 移除不需要的固定或提高预算;下次尝试前会先释放较早的普通快照 |
SNAPSHOT_LIMIT | 409 | 受保护的快照占满了某个路径组的 4096 个版本 | 移除不需要的固定 |
INSUFFICIENT_STORAGE | 503(引用发现返回 507) | 实例的可用磁盘低于 SOURCEGRAPH_MIN_FREE_BYTES;这不是仓库的存储预算 | 释放或扩充磁盘 |
RECLAIM_FAILED | 503 | 未能安全完成快照释放,或其回收尚未完成;回收会在后台继续 | 稍后重试;如果持续出现,请检查 retention_marker、git_reclaim 和 git_reclaim_check 日志事件 |
REFS_CATALOG_PREPARING | 503 | 仓库的首次分支或标签列表仍在准备中 | 在 Retry-After 之后重试,或在此期间解析完整的分支名或标签名 |
REMOTE_UNAVAILABLE | 502、503 | 远端不可用、超时或正在退避,或引用下载已用尽其全部磁盘额度 | 在 Retry-After 之后重试 |
REMOTE_ACCESS_DENIED | 502 | 该仓库使用的代码源令牌无法读取其远端;原因不在调用方自己的 Key | 由仓库管理者检查该代码源的创建者令牌或全局令牌 |
QUEUE_FULL | 503 | 活跃或已记录的任务过多 | 等待任务完成、取消部分任务,或清除已结束的任务 |
ENGINE_RESPONSE_TOO_LARGE | 502 | 即使最小的结果页也超出了预算 | 缩小模式、glob 或路径范围 |
RATE_LIMITED | 429 | 触发了限流,或触发了按仓库的准备限速 | 等待 Retry-After 给出的秒数,或使用凭据 |
Git 拉取和对象补全会在达到仓库的 Git 超时时停止:默认 15 分钟,可在系统设置中全局设为 15、30、45 或 60 分钟,并可按仓库覆盖。任务使用开始时的当前值;修改它不会中断正在运行的工作,也不会删除索引,并且它不限制建索引的总时长。后台 Git 回收流程使用同一个按仓库的超时。