element-hq / element-hq/dendrite
State key NID mappings can be missing
- Dominant language
- Go
- Stars
- 965
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
*This issue was originally created by [**@kegsay**](https://github.com/kegsay) at .*
`error="found 33449 users but only have state key nids for 33447 of them"``
Caused by `roomserver` code in storage: `JoinedUsersSetInRooms`:
```go
func (d *Database) JoinedUsersSetInRooms(ctx context.Context, roomIDs []string) (map[string]int, error) {
roomNIDs, err := d.RoomsTable.BulkSelectRoomNIDs(ctx, roomIDs)
if err != nil {
return nil, err
}
userNIDToCount, err := d.MembershipTable.SelectJoinedUsersSetForRooms(ctx, roomNIDs)
if err != nil {
return nil, err
}
stateKeyNIDs := make([]types.EventStateKeyNID, len(userNIDToCount))
i := 0
for nid := range userNIDToCount {
stateKeyNIDs[i] = nid
i++
}
nidToUserID, err := d.EventStateKeysTable.BulkSelectEventStateKey(ctx, stateKeyNIDs)
if err != nil {
return nil, err
}
if len(nidToUserID) != len(userNIDToCount) {
return nil, fmt.Errorf("found %d users but only have state key nids for %d of them", len(userNIDToCount), len(nidToUserID))
}
```
It shouldn't be possible to have NIDs in the membership table but not in the state keys table, but apparently it is.
Contributor guide
Research direction
Start with the roomserver storage entry point JoinedUsersSetInRooms and trace the MembershipTable and EventStateKeysTable queries that produce the two NID sets. Reproduce or inspect the mismatch, then determine its cause and define completion as consistent state-key mappings or an intentional, tested handling of missing mappings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100