Bulk loader: add --preserve-schema flag to error instead of auto-converting uid predicates to [uid]

Đang mở
#9,780 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 10 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
74/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend, databases

Hướng nghiên cứu

Bắt đầu trong dgraph/cmd/bulk/reduce.go tại phần phát hiện xung đột UID hiện có và đọc dgraph/cmd/bulk/schema.go, đặc biệt là setSchemaAsList. Xem xét testBulkSingleUid trong systest/bulk_live/common/bulk_live_cases.go và thêm một phiên bản tương ứng cho strict mode. Hoàn tất khi dgraph bulk chấp nhận --preserve-schema, báo lỗi kèm predicate và subject UID đối với các xung đột scalar, đồng thời mặc định vẫn giữ nguyên hành vi cảnh báo và mở rộng hiện tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Stale

Summary

The bulk loader silently rewrites a predicate's schema from uid to [uid] when it encounters more than one UID for a subject/predicate pair. This proposal adds a --preserve-schema flag so users can opt into strict behavior: fail the load with a clear error instead of widening the schema.

Current behavior

Given this schema:

<somepred>: uid .

and RDF like:

_:abc <somepred> _:123 .
_:abc <somepred> _:456 .

the bulk loader detects the conflict in the reduce phase, prints a warning, and forces the schema to [uid]:

https://github.com/dgraph-io/dgraph/blob/main/dgraph/cmd/bulk/reduce.go#L876-L891

This behavior is deliberate. It came from #3659, which fixed a data-loss bug: before that change, extra UIDs on a scalar uid predicate were silently dropped. Forcing the schema to a list was the conservative choice (keep all the data, let the user sort it out once the cluster is up). The problem is there's no way to opt out. Users who treat their schema file as the source of truth only discover the rewrite after the load completes, and the warning names the predicate but is easy to miss in bulk loader output.

Note this is a bulk-loader-only behavior. The live loader never modifies an existing schema; with <somepred>: uid already defined, live-loaded mutations follow scalar semantics (last write wins).

Proposal

Add a --preserve-schema flag to dgraph bulk (default false, preserving current behavior):

  • --preserve-schema=false (default): current behavior. Warn and widen the predicate to a list.

  • --preserve-schema=true: the schema file is authoritative. When the reducer finds more than one UID for a scalar uid predicate, fail the load with an error naming the predicate and the subject UID, e.g.:

    predicate <somepred> is defined as uid (not a list), but subject 0x2 has 2 values;
    rerun without --preserve-schema to widen the schema to [uid], or fix the input data
    

Implementation should be small: the detection already exists in reduce.go, and setSchemaAsList in dgraph/cmd/bulk/schema.go is only called from that one site. The strict path just returns an error instead.

Scope notes
  • The check runs in the reduce phase over merged posting lists, so the original RDF line is no longer available. We can report the predicate and subject UID, but per-line attribution would require map-phase tracking across shards. I'd keep that out of scope for the first pass.
  • The original request also floated a "keep the scalar schema and last-write-wins" mode. I'd skip that too: which value wins is nondeterministic in a map/reduce load, so it's a footgun. Error-or-widen covers the real use cases.
  • testBulkSingleUid in systest/bulk_live/common/bulk_live_cases.go locks in the current force-to-list behavior and should gain a strict-mode counterpart.

References

  • Original fix that introduced the auto-widening: #3659
Ngôn ngữ chính
Go
Star
21.8k
Fork
1.6k
Merge trung bình
11 ngày 7 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dgraph-io/dgraph

Tất cả issue của dgraph-io/dgraph

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.