Support for multi-index uniqueness constraints
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with NewTable, the index definitions, and Insert/WriteTxn behavior shown in the issue; trace how a unique secondary index replacement is handled. Done means conflicting entries are validated against their primary keys and the requested configurable handling for insert errors is addressed, with the existing “latest” use case considered.
Written by the indexing model from the issue text.
Description
Consider the following:
type Object struct {
A string
B string
}
var (
AIndex = index[...]{
FromObject: ... return index.NewKeySet(index.String(obj.A)) ...
Unique: true,
}
BIndex = index[...]{
FromObject: ... return index.NewKeySet(index.String(obj.B)) ...
Unique: true,
}
}
func NewObjectTable(db *DB) (RWTable[Object], error) {
return NewTable(db, "objects", AIndex, BIndex)
}
var tbl RWTable[Object]
wtxn := db.WriteTxn(tbl)
tbl.Insert(wtxn, Object{"A", "B"})
tbl.Insert(wtxn, Object{"B", "B"})
wtxn.Commit()
Following the inserts the indexes now contain:
AIndex = {"A": Object{"A", "B"}, "B": Object{"B", "B"}}
BIndex = {"B": Object{"B", "B"}}
We've now silently lost the association from "B" to Object{"A", "B"}. For most use-cases this is a bug and the fact that this overriding happens silently could be a foot-gun. The one use-case where I could see this behavior being useful is to have a "latest" index.
Consider adding support for validating that an entry in a secondary unique index can only be replaced if the primary keys match.
Since Insert errors are not often checked currently (they're currently exceptional errors such as trying to insert with a WriteTxn that doesn't lock the table), also consider adding support for configuring the handling for errors to allow panicing in CI tests and logging errors in production.
- Dominant language
- Go
- Stars
- 103
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cilium/statedb
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
google/osv-scanner#3327 ·
Maintainers usually reply within 1 day
-
tld-snapshot
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
awslabs/ferret-scan#1064 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
VictoriaMetrics/VictoriaTraces#335 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainers usually reply within 1 day