@@ -1362,6 +1362,13 @@ func shouldSplit(plist *pb.PostingList) bool {
1362
1362
return plist .Size () >= maxListSize && len (plist .Pack .Blocks ) > 1
1363
1363
}
1364
1364
1365
+ func (out * rollupOutput ) updateSplits () {
1366
+ if out .plist == nil {
1367
+ out .plist = & pb.PostingList {}
1368
+ }
1369
+ out .plist .Splits = out .splits ()
1370
+ }
1371
+
1365
1372
func (out * rollupOutput ) recursiveSplit () {
1366
1373
// Call splitUpList. Otherwise the map of startUids to parts won't be initialized.
1367
1374
out .splitUpList ()
@@ -1388,7 +1395,7 @@ func (out *rollupOutput) splitUpList() {
1388
1395
var lists []* pb.PostingList
1389
1396
1390
1397
// If list is not split yet, insert the main list.
1391
- if len (out .plist . Splits ) == 0 {
1398
+ if len (out .parts ) == 0 {
1392
1399
lists = append (lists , out .plist )
1393
1400
}
1394
1401
@@ -1398,13 +1405,10 @@ func (out *rollupOutput) splitUpList() {
1398
1405
lists = append (lists , part )
1399
1406
}
1400
1407
1401
- // List of startUids for each list part after the splitting process is complete.
1402
- var newSplits []uint64
1403
-
1404
1408
for i , list := range lists {
1405
1409
startUid := uint64 (1 )
1406
1410
// If the list is split, select the right startUid for this list.
1407
- if len (out .plist . Splits ) > 0 {
1411
+ if len (out .parts ) > 0 {
1408
1412
startUid = out .plist .Splits [i ]
1409
1413
}
1410
1414
@@ -1414,23 +1418,11 @@ func (out *rollupOutput) splitUpList() {
1414
1418
startUids , pls := binSplit (startUid , list )
1415
1419
for i , startUid := range startUids {
1416
1420
out .parts [startUid ] = pls [i ]
1417
- newSplits = append (newSplits , startUid )
1418
1421
}
1419
- } else {
1420
- // No need to split the list. Add the startUid to the array of new splits.
1421
- newSplits = append (newSplits , startUid )
1422
1422
}
1423
1423
}
1424
1424
1425
- // No new lists were created so there's no need to update the list of splits.
1426
- if len (newSplits ) == len (lists ) {
1427
- return
1428
- }
1429
-
1430
- // The splits changed so update them.
1431
- out .plist = & pb.PostingList {
1432
- Splits : newSplits ,
1433
- }
1425
+ out .updateSplits ()
1434
1426
}
1435
1427
1436
1428
// binSplit takes the given plist and returns two new plists, each with
@@ -1468,28 +1460,26 @@ func binSplit(lowUid uint64, plist *pb.PostingList) ([]uint64, []*pb.PostingList
1468
1460
1469
1461
// removeEmptySplits updates the split list by removing empty posting lists' startUids.
1470
1462
func (out * rollupOutput ) removeEmptySplits () {
1471
- var splits []uint64
1472
1463
for startUid , plist := range out .parts {
1473
1464
// Do not remove the first split for now, as every multi-part list should always
1474
1465
// have a split starting with UID 1.
1475
1466
if startUid == 1 {
1476
- splits = append (splits , startUid )
1477
1467
continue
1478
1468
}
1479
1469
1480
- if ! isPlistEmpty (plist ) {
1481
- splits = append ( splits , startUid )
1470
+ if isPlistEmpty (plist ) {
1471
+ delete ( out . parts , startUid )
1482
1472
}
1483
1473
}
1484
- out .plist .Splits = splits
1485
- sortSplits (splits )
1474
+ out .updateSplits ()
1486
1475
1487
- if len (out .plist . Splits ) == 1 {
1476
+ if len (out .parts ) == 1 && isPlistEmpty ( out . parts [ 1 ]) {
1488
1477
// Only the first split remains. If it's also empty, remove it as well.
1489
1478
// This should mark the entire list for deletion. Please note that the
1490
1479
// startUid of the first part is always one because a node can never have
1491
1480
// its uid set to zero.
1492
1481
if isPlistEmpty (out .parts [1 ]) {
1482
+ delete (out .parts , 1 )
1493
1483
out .plist .Splits = []uint64 {}
1494
1484
}
1495
1485
}
0 commit comments