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

Fixes transaction operation not updating dataset entity count #245

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ Our guide to [contributing](CONTRIBUTING.md) outlines other aspects of how to co




19 changes: 18 additions & 1 deletion internal/server/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,12 +1476,16 @@ func (s *Store) ExecuteTransaction(transaction *Transaction) error {
txn := s.database.NewTransaction(true)
defer txn.Discard()

updateCountsPerDataset := make(map[string]int64)

for k, ds := range datasets {
entities := transaction.DatasetEntities[k]
_, err := ds.StoreEntitiesWithTransaction(entities, txnTime, txn)
newItems, err := ds.StoreEntitiesWithTransaction(entities, txnTime, txn)
if err != nil {
return err
}

updateCountsPerDataset[k] = newItems
}

err := s.commitIDTxn()
Expand All @@ -1494,5 +1498,18 @@ func (s *Store) ExecuteTransaction(transaction *Transaction) error {
return err
}

// update the txn counts
for k, v := range updateCountsPerDataset {
ds, ok := s.datasets.Load(k)
if !ok {
return errors.New("no dataset " + k)
}

err = ds.(*Dataset).updateDataset(v, nil)
if err != nil {
return err
}
}

return nil
}
45 changes: 45 additions & 0 deletions internal/server/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1798,12 +1798,57 @@ var _ = ginkgo.Describe("Scoped storage functions", func() {
txn.DatasetEntities["people"] = entities
txn.DatasetEntities["places"] = entities1

// get counts before txn
dsInfo, err := store.NamespaceManager.GetDatasetNamespaceInfo()

// check counts after txn
datasets := []string{"core.Dataset"}
dsEntity, err := store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, "people"), datasets)
Expect(err).To(BeNil())

if dsEntity != nil {
items, ok := dsEntity.Properties[dsInfo.ItemsKey]
Expect(ok).To(BeTrue())
Expect(items).To(Equal(float64(5)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong here, just wanted to mention Expect(items).To( BeEquivalent(5) ) as alternative syntax when you dont really care about the type.

}

// check that the item counts have been updated for places
dsEntity, err = store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, "places"), datasets)
Expect(err).To(BeNil())

if dsEntity != nil {
items, ok := dsEntity.Properties[dsInfo.ItemsKey]
Expect(ok).To(BeTrue())
Expect(items).To(Equal(float64(0)))
}

err = store.ExecuteTransaction(txn)
Expect(err).To(BeNil())

people := dsm.GetDataset("people")
peopleEntities, _ := people.GetEntities("", 100)
Expect(len(peopleEntities.Entities)).To(Equal(6))

// check counts after txn
datasets = []string{"core.Dataset"}
dsEntity, err = store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, people.ID), datasets)
Expect(err).To(BeNil())

if dsEntity != nil {
items, ok := dsEntity.Properties[dsInfo.ItemsKey]
Expect(ok).To(BeTrue())
Expect(items).To(Equal(float64(6)))
}

// check that the item counts have been updated for places
dsEntity, err = store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, "places"), datasets)
Expect(err).To(BeNil())

if dsEntity != nil {
items, ok := dsEntity.Properties[dsInfo.ItemsKey]
Expect(ok).To(BeTrue())
Expect(items).To(Equal(float64(1)))
}
})

ginkgo.It("should find deleted version of entity with lookup", func() {
Expand Down