- OpenBaselineStack 用目标库解析出的 profile 校验 schema(134 合法), contract.WeKnoraVersion 取 profile 值 - no-gate 维护参数(IngressMode/IngressAck/HealthURL)从配置透传, 否则 0.9.0 目标会被当成缺闸门拒绝 - 索引写入与校验按 profile 决定是否补 tenant_id(0.9.0 索引无该字段)
This commit is contained in:
@@ -44,6 +44,9 @@ type Profile struct {
|
||||
// IndexContractSource 说明该版本的索引名从哪里读。空值等于"读不到",
|
||||
// 不允许回退成空串去匹配任何索引。
|
||||
IndexContractSource string
|
||||
// IndexTenantField 表示该版本的索引文档带 tenant_id。0.9.0 的分块文档只有
|
||||
// knowledge_base_id,写索引时补 tenant_id 会与目标实际文档不一致。
|
||||
IndexTenantField bool
|
||||
}
|
||||
|
||||
var profiles = map[int]Profile{
|
||||
@@ -78,6 +81,7 @@ var profiles = map[int]Profile{
|
||||
{"index", "chunks"},
|
||||
},
|
||||
IndexContractSource: "vector_stores.index_config.index_name",
|
||||
IndexTenantField: true,
|
||||
},
|
||||
V090Version: {
|
||||
Name: "v090",
|
||||
@@ -122,6 +126,7 @@ var profiles = map[int]Profile{
|
||||
`CREATE TRIGGER trg_chunk_images_update AFTER UPDATE ON public.chunks FOR EACH ROW WHEN ((((old.image_info ~~ '[%'::text) OR (new.image_info ~~ '[%'::text)) AND ((old.image_info IS DISTINCT FROM new.image_info) OR (old.is_enabled IS DISTINCT FROM new.is_enabled) OR (old.status IS DISTINCT FROM new.status) OR (old.deleted_at IS DISTINCT FROM new.deleted_at) OR (old.tenant_id IS DISTINCT FROM new.tenant_id) OR ((old.knowledge_base_id)::text IS DISTINCT FROM (new.knowledge_base_id)::text) OR ((old.knowledge_id)::text IS DISTINCT FROM (new.knowledge_id)::text) OR ((old.chunk_type)::text IS DISTINCT FROM (new.chunk_type)::text) OR (old.created_at IS DISTINCT FROM new.created_at) OR (old.updated_at IS DISTINCT FROM new.updated_at)))) EXECUTE FUNCTION chunk_images_sync()`,
|
||||
},
|
||||
IndexContractSource: "config ELASTICSEARCH_INDEX",
|
||||
IndexTenantField: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"knowledge-governance/internal/librarysnapshot"
|
||||
"knowledge-governance/internal/objectgateway"
|
||||
v071 "knowledge-governance/internal/releaseadapter/v071"
|
||||
"knowledge-governance/internal/releasebundle"
|
||||
)
|
||||
|
||||
// OpenMaintenance 按部署配置装配实例级维护目标;未接线时返回明确原因。
|
||||
@@ -34,6 +33,9 @@ func OpenMaintenance(config appconfig.Config) (*librarymaintenance.Manager, erro
|
||||
Writers: config.LibraryTargetWriters,
|
||||
NonWriters: config.LibraryTargetNonWriters,
|
||||
DockerSocket: config.LibraryTargetDockerSocket,
|
||||
IngressMode: config.LibraryTargetIngressMode,
|
||||
IngressAck: config.LibraryTargetNoIngressAck,
|
||||
HealthURL: config.LibraryTargetHealthURL,
|
||||
IngressURL: config.LibraryTargetIngressURL,
|
||||
IngressService: config.LibraryTargetIngressService,
|
||||
IngressDrainFile: config.LibraryTargetIngressDrainFile,
|
||||
@@ -298,10 +300,22 @@ func OpenBaselineStack(ctx context.Context, config appconfig.Config, scope strin
|
||||
target.Close()
|
||||
return nil, nil, fmt.Errorf("读取目标 WeKnora schema 版本失败: %w", err)
|
||||
}
|
||||
if dirty || schemaVersion != releasebundle.WeKnoraMigrationV071 {
|
||||
if dirty {
|
||||
target.Close()
|
||||
return nil, nil, fmt.Errorf("目标 schema 版本 %d(dirty=%v)与受支持的 %d 不一致,拒绝建基线",
|
||||
schemaVersion, dirty, releasebundle.WeKnoraMigrationV071)
|
||||
return nil, nil, fmt.Errorf("目标 schema 版本 %d 处于 dirty 状态,拒绝建基线", schemaVersion)
|
||||
}
|
||||
// 契约按目标库自己的 schema 解析,而不是写死 74:0.9.0 的 schema 是 134,
|
||||
// 它的表集合、索引来源与 Wiki 部件都和 0.7.1 不同,用 74 的常量建基线
|
||||
// 会把另一套栈的记录写进权威版本。
|
||||
profile, err := v071.ResolveSchemaProfile(ctx, target.Pool(), "baseline contract")
|
||||
if err != nil {
|
||||
target.Close()
|
||||
return nil, nil, fmt.Errorf("解析目标 schema profile 失败: %w", err)
|
||||
}
|
||||
if profile.SchemaVersion != schemaVersion {
|
||||
target.Close()
|
||||
return nil, nil, fmt.Errorf("目标 schema 版本 %d 与解析出的 profile %s(%d)不一致,拒绝建基线",
|
||||
schemaVersion, profile.Name, profile.SchemaVersion)
|
||||
}
|
||||
embeddingModel := config.LibraryEmbeddingModel
|
||||
embeddingDimension := config.LibraryEmbeddingDimension
|
||||
@@ -333,7 +347,7 @@ WHERE kb.id = $1 AND kb.deleted_at IS NULL`, scopeCfg.target.KnowledgeBaseID).Sc
|
||||
return nil, nil, fmt.Errorf("读取目标 embedding 模型绑定失败: %w", err)
|
||||
}
|
||||
contract := librarysnapshot.Compatibility{
|
||||
WeKnoraVersion: releasebundle.WeKnoraVersionV071,
|
||||
WeKnoraVersion: profile.WeKnoraVersion,
|
||||
SchemaVersion: schemaVersion,
|
||||
RetrieverEngine: "elasticsearch_v8",
|
||||
EmbeddingModel: embeddingModel,
|
||||
|
||||
@@ -43,7 +43,7 @@ func archiveIndexMap(archive *librarysnapshot.Archive, manifest librarysnapshot.
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func targetIndexSource(raw json.RawMessage, tenant uint64, kb string) (json.RawMessage, error) {
|
||||
func targetIndexSource(raw json.RawMessage, tenant uint64, kb string, withTenant bool) (json.RawMessage, error) {
|
||||
var source map[string]json.RawMessage
|
||||
if json.Unmarshal(raw, &source) != nil || source == nil {
|
||||
return nil, errors.New("index source must be object")
|
||||
@@ -52,7 +52,9 @@ func targetIndexSource(raw json.RawMessage, tenant uint64, kb string) (json.RawM
|
||||
if json.Unmarshal(source["content"], &content) != nil || strings.HasPrefix(content, indexClaimPrefix) {
|
||||
return nil, errors.New("index source lacks string content or contains an unfinished transient claim")
|
||||
}
|
||||
source["tenant_id"], _ = json.Marshal(tenant)
|
||||
if withTenant {
|
||||
source["tenant_id"], _ = json.Marshal(tenant)
|
||||
}
|
||||
source["knowledge_base_id"], _ = json.Marshal(kb)
|
||||
encoded, err := json.Marshal(source)
|
||||
if err != nil {
|
||||
@@ -111,7 +113,7 @@ func (t *ProductionLibraryTarget) planIndex(ctx context.Context, archive *librar
|
||||
}
|
||||
var wanted json.RawMessage
|
||||
if raw, ok := after[id]; ok {
|
||||
wanted, err = targetIndexSource(raw, t.scope.TenantID, t.scope.KnowledgeBaseID)
|
||||
wanted, err = targetIndexSource(raw, t.scope.TenantID, t.scope.KnowledgeBaseID, t.schema.IndexTenantField)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -151,7 +153,7 @@ func (t *ProductionLibraryTarget) validateIndexPlanBinding(archive *librarysnaps
|
||||
delete(ids, change.ID)
|
||||
var wanted json.RawMessage
|
||||
if raw, ok := after[change.ID]; ok {
|
||||
wanted, err = targetIndexSource(raw, set.TenantID, set.KnowledgeBaseID)
|
||||
wanted, err = targetIndexSource(raw, set.TenantID, set.KnowledgeBaseID, t.schema.IndexTenantField)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func ScopeContentCounts(ctx context.Context, pool *pgxpool.Pool, identity Produc
|
||||
counts := make(map[string]int64, len(profile.Tables))
|
||||
for _, table := range profile.Tables {
|
||||
var count int64
|
||||
if err := pool.QueryRow(ctx, fmt.Sprintf(`SELECT count(*) FROM %s WHERE %s`, table, scopeWhere(table)),
|
||||
if err := pool.QueryRow(ctx, fmt.Sprintf(`SELECT count(*) FROM %s WHERE %s`, table, scopeWhereFor(profile.Tables, table)),
|
||||
identity.TenantID, identity.KnowledgeBaseID).Scan(&count); err != nil {
|
||||
return nil, fmt.Errorf("count %s: %w", table, err)
|
||||
}
|
||||
|
||||
@@ -276,7 +276,11 @@ func (t *ProductionLibraryTarget) verifyIndexDigest(ctx context.Context, archive
|
||||
if err := json.Unmarshal(document.Source, &source); err != nil {
|
||||
return errors.New("归档索引文档不是对象")
|
||||
}
|
||||
source["tenant_id"], _ = json.Marshal(t.scope.TenantID)
|
||||
// 0.9.0 的分块文档只有 knowledge_base_id(索引里没有 tenant_id),
|
||||
// 规范化必须按目标 profile 来,否则"写对了"也会被判成生产缺少字段。
|
||||
if t.schema.IndexTenantField {
|
||||
source["tenant_id"], _ = json.Marshal(t.scope.TenantID)
|
||||
}
|
||||
source["knowledge_base_id"], _ = json.Marshal(t.scope.KnowledgeBaseID)
|
||||
encoded, err := json.Marshal(source)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user