docs/design-docs/design_docs/20260526-external_table_add_column_refresh.md
Branch: design/external-refresh-add-column
Date: May 2026
Related Issue: #45881
External tables keep segment data in storage-v2 manifests that point to external files. Refresh normally preserves a current segment when its external file fragments are still present, and only creates new segments for new or rebalanced fragments.
That behavior is not enough after an additive schema change. If a user adds a new Milvus field mapped to an existing Parquet column, an unchanged external fragment still needs a new manifest column group and a new fake binlog entry. Keeping the old segment unchanged would leave the segment behind the latest collection schema, so the new field would not be covered by the segment manifest or by the load-time memory estimate.
This design extends refresh so an unchanged external fragment can produce a same-segment patch. The patch advances only the manifest path, fake binlog coverage, and schema version while preserving the segment ID and existing segment metadata.
external_field mappings.| Term | Meaning |
|---|---|
| External field | A Milvus field with external_field set, mapped to a column in the external source. |
| Fragment | A row range in an external file, identified by file path, start row, and end row. |
| Manifest column group | A storage-v2 manifest entry that maps one or more columns to a set of fragments. |
| Kept segment | An existing segment whose fragments and field coverage are still valid. |
| Patched segment | An existing segment whose fragments are still valid but whose manifest and fake binlogs must be advanced for newly added fields. |
| New segment | A segment created from orphan fragments after files are added, removed, or rebalanced. |
| Updated segment | DataCoord upsert payload. It can be either a patched existing segment or a new segment. |
AlterCollectionSchema(AddField)
|
v
Collection schema version advances
|
v
RefreshExternalCollection
|
v
DataCoord records refresh job schema_version
|
v
DataCoord creates refresh tasks with the same schema_version
|
v
DataNode compares current segment fragments with external fragments
|
+-- Fragment removed or new fragment found
| |
| v
| Rebalance orphan fragments into new segments
|
+-- Same fragments and all external fields covered
| |
| v
| Return segment ID in kept_segments
|
+-- Same fragments but newly added external fields missing
|
v
Append missing manifest column groups
|
v
Rebuild fake binlogs and schema_version
|
v
Return same segment ID in updated_segments
|
v
DataCoord validates schema_version and updated segment payload
|
v
DataCoord atomically drops obsolete segments, keeps valid segments,
and upserts patched or new segments
ExternalCollectionRefreshJob stores the collection schema version that was
current when the refresh job was accepted:
message ExternalCollectionRefreshJob {
...
int32 schema_version = 12;
}
This schema version is copied into every generated
ExternalCollectionRefreshTask:
message ExternalCollectionRefreshTask {
...
int32 schema_version = 18;
}
The stored value is a refresh boundary. DataNode receives the schema snapshot that DataCoord dispatches for the task, and DataCoord later rejects the result if the collection schema has advanced beyond the job schema version.
For compatibility with older persisted refresh metadata, schema_version == 0
means "unknown" and skips the version gate.
The refresh response already carries updated_segments. This design makes the
field an upsert payload:
kept_segments and updated_segments.This keeps the wire shape stable while extending the semantics from "new segments only" to "new or patched segments".
When RefreshExternalCollection accepts a job, DataCoord reads the current
collection schema and persists collection.Schema.Version on the job. Task
creation copies that value into each task.
This captures the exact schema version the refresh is allowed to produce.
Before dispatching a task to DataNode, DataCoord reloads the collection from meta. If the current schema version differs from the task schema version, the task fails before worker execution.
This prevents a task from using stale current segment metadata together with a newer schema snapshot.
Before applying a finished job, DataCoord validates that the collection schema version still matches the job schema version. If the schema changed while the job was running, the job result is rejected before any segment mutation.
applyExternalCollectionSegmentUpdate now validates both kept and updated
segments before mutating meta:
The mutation remains atomic through DataCoord segment update operators:
For an existing segment patch, only these fields are advanced:
ManifestPathSchemaVersionBinlogsStorageVersion, when present in the incoming payloadOther segment metadata, including segment ID, collection ID, partition ID, insert channel, row count, state, level, and index-adjacent metadata, is preserved from the existing segment.
DataNode builds the current segment-to-fragments mapping from existing manifest files, then compares it with the external fragments discovered by the explore manifest.
For each current segment:
ChildFields, the segment is patched in place.Orphan fragments are still balanced into new segments using the existing refresh path.
DataNode derives target external fields from the task schema:
external_field are considered.ChildFields.The missing set is expressed as external column names, not Milvus field IDs, because manifest column groups reference external source column names.
When missing columns are detected for an otherwise unchanged segment, DataNode:
SegmentInfo with:
The old segment is not mutated in DataNode. DataCoord performs the actual meta patch after validation.
GetUpdatedSegments() returns only segments DataCoord should upsert:
Unchanged kept segments are returned only by ID through kept_segments.
The packed manifest layer exposes ReadColumnGroupsFromManifest, which reads
both:
ReadFragmentsFromManifest is rebuilt on top of this function and deduplicates
fragments by (file_path, start_row, end_row).
AppendSegmentManifestColumns appends missing columns to an existing manifest:
If every requested column is already present for the same fragment set, the operation returns the original manifest path. This makes retry behavior idempotent.
Fragment identity is defined by:
file_path + start_row + end_row
The fragment ID assigned inside Go is local to the current list and is not used as persistent identity.
Refresh results are rejected before mutation if the collection schema version changed after job acceptance.
This avoids mixing an old task result with a newer schema. A user can retry refresh after the newer schema is stable.
DataCoord rejects invalid worker payloads before mutation. This includes row count mismatches, dropped segment patches, collection mismatches, empty manifests, empty fake binlogs, duplicate updated segment IDs, and kept/updated overlap.
If manifest append fails, DataNode fails the task. DataCoord does not apply a partial patch because the updated segment payload is not persisted as a finished result.
If field-size sampling cannot produce a positive memory estimate, DataNode fails the patch. This avoids persisting a segment that QueryNode cannot size correctly during load.
Persisted jobs or tasks without a schema version continue to run with
schema_version == 0. The schema-version gate is skipped for those records.
Existing segments do not need data migration. They are patched lazily on the next refresh when their fragment set is unchanged but their fake binlogs do not cover the latest external fields.
QueryNode continues to load segments from manifest path and fake binlogs. The patch updates those two inputs while preserving segment identity.
The implementation should cover:
kept_segments and
patched or new segments through updated_segments.Rebuilding every segment would be simple but expensive. It would also change segment IDs for data whose external fragments did not change, causing unnecessary reload and index-adjacent metadata churn.
This preserves old behavior but leaves newly added external fields uncovered by manifest column groups and fake binlogs. It does not satisfy AddField semantics.
A dedicated RPC would make the intent explicit but adds API surface and
duplicates refresh result handling. Reusing updated_segments as an upsert
payload keeps the refresh protocol compact and lets DataCoord enforce all
segment mutations in one path.