From 5cc6f0d023cc786aa5f184911e9bba0ac8b55128 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 9 Feb 2021 14:30:50 +0200 Subject: [PATCH] Scattering cursor followup (#87) --- pkg/dataplane/itemscursor.go | 4 +++- pkg/dataplane/test/sync_test.go | 18 +++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/pkg/dataplane/itemscursor.go b/pkg/dataplane/itemscursor.go index a39664b..8ad4b73 100644 --- a/pkg/dataplane/itemscursor.go +++ b/pkg/dataplane/itemscursor.go @@ -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) { diff --git a/pkg/dataplane/test/sync_test.go b/pkg/dataplane/test/sync_test.go index bcd5531..008e846 100644 --- a/pkg/dataplane/test/sync_test.go +++ b/pkg/dataplane/test/sync_test.go @@ -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"] @@ -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()