Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompoundMultiIndex returns duplicate entries with SingleIndexers #95

Open
radeksimko opened this issue Apr 15, 2021 · 2 comments
Open
Labels

Comments

@radeksimko
Copy link
Member

I'm not 100% sure this (mis)behaviour can be attributed to the combination of CompoundMultiIndex and single indexers actually, but I have a repro case which looks simple enough that it's hard to find any other cause there.

&memdb.CompoundMultiIndex{
	Indexes: []memdb.Indexer{
		&memdb.StringFieldIndex{Field: "Address"},
		&memdb.StringFieldIndex{Field: "Version"},
	},
	AllowMissing: true,
}

when a single entry is inserted into a table with such an index:

txn.Insert("providers", &entry{
	Address: "aws",
	Version: "1.0.0",
})

and subsequently looked up (in a separate transaction)

txn.Get("providers", "provider")

then the same entry is returned twice:

&entry{Address:"aws", Version:"1.0.0"}
&entry{Address:"aws", Version:"1.0.0"}

I can confirm it is the exact same entry by comparing the pointer address, which consequently also makes such index impossible to use in DeleteAll where each individual entry would be looked up again via id index (as part of Delete) while iterating over results and (obviously) the second duplicate no longer exists once the first (original) entry is deleted, so DeleteAll then returns "not found" error.

go-memdb/txn.go

Lines 313 to 329 in 542a580

// Get the primary ID of the object
idSchema := tableSchema.Indexes[id]
idIndexer := idSchema.Indexer.(SingleIndexer)
ok, idVal, err := idIndexer.FromObject(obj)
if err != nil {
return fmt.Errorf("failed to build primary index: %v", err)
}
if !ok {
return fmt.Errorf("object missing primary index")
}
// Lookup the object by ID first, check fi we should continue
idTxn := txn.writableIndex(table, id)
existing, ok := idTxn.Get(idVal)
if !ok {
return ErrNotFound
}

Here is a full repro case:

@radeksimko radeksimko added the bug label Apr 15, 2021
@dnephin
Copy link
Contributor

dnephin commented Nov 15, 2021

This may have been fixed by #108, it sounds related.

@radeksimko
Copy link
Member Author

According to the attached repro case it looks like it was not fixed yet

➜  go get github.com/hashicorp/go-memdb@422653b
go: downloading github.com/hashicorp/go-memdb v1.3.3-0.20211105203423-422653bbb902
go get: upgraded github.com/hashicorp/go-memdb v1.3.2 => v1.3.3-0.20211105203423-422653bbb902
➜ go mod tidy
➜ go run main.go
entry: &main.entry{Address:"aws", Version:"1.0.0"}
entry: &main.entry{Address:"aws", Version:"1.0.0"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants