fix(release): 以实例身份阻断绑定与发布跨实例
网页可能在实例 A 上列库并保存生产绑定,而文档发布执行器实际连实例 B。 克隆实例可以有相同知识库 ID、名称甚至租户,单靠 ID 无法证明写的是同一个 目标。现在绑定保存会冻结候选实例地址/租户,发布计划把身份冻结到每个项, 执行器在 Contract/Prepare/Activate/Restore/Compensate 前核对;不一致以 release_contract_mismatch 非重试失败关闭,不写目标。整库发布目标不变。 测试入库对象在上传前记录实际实例地址/租户;轮询、验收、移除先核对当前 连接,改绑实例或租户后旧对象不会被克隆实例接管。旧行没有身份时失败关闭。 「知识库绑定」保存要求对内/对外各选一个库,不再把显式未绑定回落到部署 默认 ID,避免换绑实例后带过去旧对象的默认库。 验证:隔离 PostgreSQL 覆盖绑定身份落库与发布计划冻结;v071 用同 ID/同租户 的 A/B 实例做正反例;四个测试 handler 的实例错配负例;前端 607 项通过。
This commit is contained in:
@@ -29,22 +29,27 @@ type PublicationForUpload struct {
|
||||
SourceItemVersionID string
|
||||
TestKBID string
|
||||
KnowledgeID string
|
||||
IngestState governance.IngestState
|
||||
ProcessingState governance.ProcessingState
|
||||
TargetScope governance.Visibility
|
||||
ContentObjectID string
|
||||
SHA256 string
|
||||
SizeBytes int64
|
||||
MIME string
|
||||
ValidatedFormat string
|
||||
LocalSpoolRef string
|
||||
Title string
|
||||
// 对象实际写入的测试实例身份;空 = 迁移前的旧行,无法证明归属。
|
||||
TestInstanceURL string
|
||||
TestInstanceTenant uint64
|
||||
IngestState governance.IngestState
|
||||
ProcessingState governance.ProcessingState
|
||||
TargetScope governance.Visibility
|
||||
ContentObjectID string
|
||||
SHA256 string
|
||||
SizeBytes int64
|
||||
MIME string
|
||||
ValidatedFormat string
|
||||
LocalSpoolRef string
|
||||
Title string
|
||||
}
|
||||
|
||||
type PublicationForPoll struct {
|
||||
ID string
|
||||
TestKBID string
|
||||
KnowledgeID string
|
||||
TestInstanceURL string
|
||||
TestInstanceTenant uint64
|
||||
ProcessingState governance.ProcessingState
|
||||
PollSequence int
|
||||
LastRemoteStatus string
|
||||
@@ -55,9 +60,11 @@ type PublicationForPoll struct {
|
||||
}
|
||||
|
||||
type PublicationForValidation struct {
|
||||
ID string
|
||||
TestKBID string
|
||||
KnowledgeID string
|
||||
ID string
|
||||
TestKBID string
|
||||
KnowledgeID string
|
||||
TestInstanceURL string
|
||||
TestInstanceTenant uint64
|
||||
// TargetScope 决定这条知识发到哪个生产库(对内/对外)。自动批准策略依赖它:
|
||||
// 默认只自动批准"对内","对外"仍要人工。
|
||||
TargetScope string
|
||||
@@ -71,6 +78,7 @@ type LegacyVerificationCandidate struct {
|
||||
|
||||
const loadPublicationForUploadSQL = `
|
||||
SELECT p.id, p.source_item_version_id, p.test_kb_id, p.knowledge_id,
|
||||
p.test_instance_url, p.test_instance_tenant,
|
||||
p.ingest_state, p.processing_state, p.target_scope,
|
||||
co.id, co.sha256, co.size_bytes, co.mime, co.validated_format,
|
||||
co.local_spool_ref, si.title
|
||||
@@ -89,7 +97,8 @@ WHERE p.id = $1
|
||||
`
|
||||
|
||||
const loadPublicationForPollSQL = `
|
||||
SELECT id, test_kb_id, knowledge_id, processing_state, poll_sequence,
|
||||
SELECT id, test_kb_id, knowledge_id, test_instance_url, test_instance_tenant,
|
||||
processing_state, poll_sequence,
|
||||
last_remote_status, last_remote_updated_at, processing_started_at,
|
||||
last_observed_at, updated_at
|
||||
FROM test_publications
|
||||
@@ -97,7 +106,7 @@ WHERE id = $1
|
||||
`
|
||||
|
||||
const loadPublicationForValidationSQL = `
|
||||
SELECT id, test_kb_id, knowledge_id, target_scope
|
||||
SELECT id, test_kb_id, knowledge_id, test_instance_url, test_instance_tenant, target_scope
|
||||
FROM test_publications
|
||||
WHERE id = $1
|
||||
AND ingest_state = 'uploaded'
|
||||
@@ -223,8 +232,10 @@ ON CONFLICT (idempotency_key) DO NOTHING
|
||||
const markUploadingSQL = `
|
||||
UPDATE test_publications
|
||||
SET ingest_state = 'uploading',
|
||||
test_instance_url = $2,
|
||||
test_instance_tenant = $3,
|
||||
last_error = '',
|
||||
updated_at = $2
|
||||
updated_at = $4
|
||||
WHERE id = $1
|
||||
AND ingest_state IN ('pending', 'uploading')
|
||||
AND processing_state = 'pending'
|
||||
@@ -393,6 +404,8 @@ func (s *Store) LoadPublicationForUpload(ctx context.Context, publicationID stri
|
||||
&candidate.SourceItemVersionID,
|
||||
&candidate.TestKBID,
|
||||
&candidate.KnowledgeID,
|
||||
&candidate.TestInstanceURL,
|
||||
&candidate.TestInstanceTenant,
|
||||
&ingestState,
|
||||
&processingState,
|
||||
&candidate.TargetScope,
|
||||
@@ -422,6 +435,8 @@ func (s *Store) LoadPublicationForPoll(ctx context.Context, publicationID string
|
||||
&publication.ID,
|
||||
&publication.TestKBID,
|
||||
&publication.KnowledgeID,
|
||||
&publication.TestInstanceURL,
|
||||
&publication.TestInstanceTenant,
|
||||
&processingState,
|
||||
&publication.PollSequence,
|
||||
&publication.LastRemoteStatus,
|
||||
@@ -446,6 +461,8 @@ func (s *Store) LoadPublicationForValidation(ctx context.Context, publicationID
|
||||
&publication.ID,
|
||||
&publication.TestKBID,
|
||||
&publication.KnowledgeID,
|
||||
&publication.TestInstanceURL,
|
||||
&publication.TestInstanceTenant,
|
||||
&publication.TargetScope,
|
||||
)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
@@ -594,8 +611,8 @@ func (s *Store) RetryPublication(ctx context.Context, publicationID string, now
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) MarkUploading(ctx context.Context, publicationID string, now time.Time) error {
|
||||
tag, err := s.db.Exec(ctx, markUploadingSQL, publicationID, now)
|
||||
func (s *Store) MarkUploading(ctx context.Context, publicationID, instanceURL string, instanceTenant uint64, now time.Time) error {
|
||||
tag, err := s.db.Exec(ctx, markUploadingSQL, publicationID, instanceURL, instanceTenant, now)
|
||||
if err != nil {
|
||||
return fmt.Errorf("mark test publication uploading: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user