Commit 6b3733d
authored
feat(rag): implement zero-downtime KB update framework with system config management (#275)
## Because
- **System configuration updates require zero-downtime**: RAG systems
need to update embedding models/configurations without service
interruption or data loss
- **Multi-tenant systems need audit trails**: System administrators need
visibility into which embedding system each KB is using and historical
changes
- **Rollback capability is critical**: Production systems require the
ability to revert to previous configurations if updates fail or cause
issues
- **Test reliability must be deterministic**: Integration tests were
flaky due to race conditions, zombie resources, and incomplete error
handling
## This commit
### 🎯 Core Framework: Zero-Downtime KB Update System
- **Implements 6-phase staging-based update workflow** (Prepare →
Reprocess → Synchronize → Validate → Swap → Cleanup) that enables live
system configuration changes without downtime
- **Adds dual-processing mechanism** where files uploaded during updates
are processed for both production and target (staging/rollback) KBs to
prevent data loss
- **Implements atomic 3-step resource swap** using temporary UID to
exchange resources between KBs while keeping production KB UID constant
for ACL preservation
- **Adds rollback retention system** with configurable retention periods
and automatic/manual cleanup workflows for rollback KBs
### 🔧 System Configuration Management API
- **Adds new `System` database table and models** (migration 000037) to
manage embedding configurations as first-class entities with UID and ID
- **Implements `ExecuteKnowledgeBaseUpdate` admin API** to trigger
system-wide or selective KB updates to new system configurations
- **Implements `GetKnowledgeBaseUpdateStatusAdmin` API** to monitor
update progress across all KBs with status details, error messages,
current/previous system IDs
- **Implements `SetRollbackRetentionAdmin` API** to dynamically adjust
rollback retention periods with flexible time units
(seconds/minutes/hours/days)
- **Implements `PurgeRollbackAdmin` API** for immediate manual cleanup
of rollback KBs
- **Implements `AbortKnowledgeBaseUpdateAdmin` API** to safely cancel
in-progress updates with proper staging KB cleanup
- **Adds `system_uid` foreign key to KB table** linking each KB to its
embedding system for audit trails and update tracking
- **Adds `previous_system_uid` tracking** to record the system before
updates/rollbacks for historical audit
### 📊 Database Schema Changes
- **Migration 000037**: Renames `embedding_config` to `system_config`,
adds `system_uid` and `previous_system_uid` to KB table, adds
`update_error_message` for failure diagnostics
- **Adds `rollback_retention_until` timestamp field** for per-KB
retention customization
- **Implements atomic transactional deletion** with row-level locking
(`SELECT ... FOR UPDATE`) to prevent TOCTOU race conditions
### 🐛 Critical Bug Fixes
- **Fixes workflow defer block to ALWAYS set terminal status** even when
staging KB creation fails, preventing tests from timing out waiting for
status updates
- **Fixes teardown to only wait for production KB workflows** (not
staging KBs), eliminating false "workflows still running" messages
- **Fixes `SetRollbackRetentionAdmin` to update rollback KB retention**
(not production KB) so cleanup workflows check the correct field
- **Fixes `RescheduleCleanupWorkflow` to use `TerminateWorkflow`**
instead of `CancelWorkflow` for synchronous termination before starting
new workflow
- **Implements explicit hard-delete for staging KB cleanup** in
`CleanupOldKnowledgeBaseActivity` to remove zombie files (soft-delete
doesn't cascade)
- **Implements hard-delete in `DeleteAllKnowledgeBaseFiles`** using
`Unscoped()` for physical file removal during cleanup
### 🧹 Code Quality & Maintenance
- **Removes all deprecated file process statuses**
(`FILE_PROCESS_STATUS_CONVERTING`, `FILE_PROCESS_STATUS_WAITING`,
`FILE_PROCESS_STATUS_SUMMARIZING`) from codebase and tests
- **Reverts preset pipeline initialization method** (from commit
[`89d528f`](89d528f))
to fix initialization race conditions
- **Optimizes `GetKnowledgeBaseUpdateStatusAdmin` API** to pre-fetch
systems into cache, eliminating N+1 query problem
- **Renames `upgrade` terminology to `update`** throughout codebase for
consistency (upgradeCompleted → updateCompleted)1 parent 89d3bf7 commit 6b3733d
File tree
100 files changed
+27324
-7139
lines changed- cmd
- init
- worker
- integration-test
- data
- proto/artifact
- artifact/v1alpha
- v1alpha
- scripts
- pkg
- db/migration
- handler
- mock
- pipeline
- preset/pipelines
- indexing-embed/v1.0.0
- indexing-generate-content/v1.4.0
- indexing-generate-summary/v1.0.0
- repository
- service
- types
- worker
- mock
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
100 files changed
+27324
-7139
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| 54 | + | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| |||
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
| 201 | + | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| 120 | + | |
116 | 121 | | |
117 | 122 | | |
118 | 123 | | |
| |||
299 | 304 | | |
300 | 305 | | |
301 | 306 | | |
| 307 | + | |
| 308 | + | |
302 | 309 | | |
303 | 310 | | |
304 | | - | |
305 | | - | |
| 311 | + | |
| 312 | + | |
306 | 313 | | |
307 | 314 | | |
308 | 315 | | |
| |||
409 | 416 | | |
410 | 417 | | |
411 | 418 | | |
| 419 | + | |
| 420 | + | |
412 | 421 | | |
413 | 422 | | |
414 | 423 | | |
| |||
782 | 791 | | |
783 | 792 | | |
784 | 793 | | |
| 794 | + | |
785 | 795 | | |
786 | 796 | | |
787 | 797 | | |
| |||
858 | 868 | | |
859 | 869 | | |
860 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
861 | 874 | | |
862 | 875 | | |
863 | 876 | | |
| |||
874 | 887 | | |
875 | 888 | | |
876 | 889 | | |
| 890 | + | |
877 | 891 | | |
878 | 892 | | |
879 | 893 | | |
| |||
890 | 904 | | |
891 | 905 | | |
892 | 906 | | |
| 907 | + | |
| 908 | + | |
893 | 909 | | |
894 | 910 | | |
895 | 911 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
134 | | - | |
| 137 | + | |
135 | 138 | | |
136 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
137 | 144 | | |
138 | 145 | | |
139 | 146 | | |
| |||
Binary file not shown.
0 commit comments