Skip to content

Commit

Permalink
Scattering cursor followup (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelGel authored Feb 9, 2021
1 parent 513ec31 commit 5cc6f0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
4 changes: 3 additions & 1 deletion pkg/dataplane/itemscursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func (ic *ItemsCursor) GetItem() Item {
}

func (ic *ItemsCursor) Scattered() bool {
return ic.scattered

// scattered flag applies only to the last item
return ic.scattered && ic.itemIndex == len(ic.items)
}

func (ic *ItemsCursor) setResponse(response *Response) {
Expand Down
18 changes: 3 additions & 15 deletions pkg/dataplane/test/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,7 @@ func (suite *syncKVTestSuite) TestScatteredCursor() {
suite.Require().NoError(err, "Failed to get cursor")

// extract and combine scattered items
scatteredItems := map[string]map[string]interface{}{}
var retrievedItems []map[string]interface{}
retrievedItems := map[string]map[string]interface{}{}
for cursor.NextSync() {
item := cursor.GetItem()
inode := item["__inode_number"]
Expand All @@ -965,25 +964,14 @@ func (suite *syncKVTestSuite) TestScatteredCursor() {
ctime := int64(ctimeSec.(int))*1e9 + int64(ctimeNSec.(int))
objectID := fmt.Sprintf("%d.%d", inode.(int), ctime)

scatteredItem, scatteredItemFound := scatteredItems[objectID]
scatteredItem, scatteredItemFound := retrievedItems[objectID]
if scatteredItemFound {
for key, value := range item {
scatteredItem[key] = value
}
item = scatteredItem
}
if cursor.Scattered() || scatteredItemFound {
scatteredItems[objectID] = item
} else {
retrievedItems = append(retrievedItems, item)
}

if !cursor.Scattered() {
for _, scatteredItem := range scatteredItems {
retrievedItems = append(retrievedItems, scatteredItem)
}
scatteredItems = map[string]map[string]interface{}{}
}
retrievedItems[objectID] = item
}
cursor.Release()

Expand Down

0 comments on commit 5cc6f0d

Please sign in to comment.