insertPosting inserts a new posting in the mutable layers. It updates the currentUids map.
(mpost *pb.Posting, hasCountIndex bool)
| 352 | |
| 353 | // insertPosting inserts a new posting in the mutable layers. It updates the currentUids map. |
| 354 | func (mm *MutableLayer) insertPosting(mpost *pb.Posting, hasCountIndex bool) { |
| 355 | if mm.readTs != 0 { |
| 356 | x.AssertTruef(mpost.StartTs == mm.readTs, "Diffrenent read ts and start ts found %d %d", mpost.StartTs, mm.readTs) |
| 357 | } |
| 358 | |
| 359 | mm.readTs = mpost.StartTs |
| 360 | |
| 361 | if hasDeleteAll(mpost) { |
| 362 | if mpost.CommitTs > mm.deleteAllMarker { |
| 363 | mm.deleteAllMarker = mpost.CommitTs |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if mpost.Uid != 0 { |
| 368 | // If hasCountIndex, in that case while inserting uids, if there's a delete, we only delete from the |
| 369 | // current entries, we dont' insert the delete posting. If we insert the delete posting, there won't be |
| 370 | // any set posting in the list. This would mess up the count. We can do this for all types, however, |
| 371 | // there might be a performance hit becasue of it. |
| 372 | mm.populateUidMap(mm.currentEntries) |
| 373 | if postIndex, ok := mm.currentUids[mpost.Uid]; ok { |
| 374 | if hasCountIndex && mpost.Op == Del { |
| 375 | // If the posting was there before, just remove it from the map, and then remove it |
| 376 | // from the array. |
| 377 | post := mm.currentEntries.Postings[postIndex] |
| 378 | if post.Op == Del { |
| 379 | // No need to do anything |
| 380 | mm.currentEntries.Postings[postIndex] = mpost |
| 381 | return |
| 382 | } |
| 383 | res := mm.currentEntries.Postings[:postIndex] |
| 384 | if postIndex+1 <= len(mm.currentEntries.Postings) { |
| 385 | res = append(res, |
| 386 | mm.currentEntries.Postings[(postIndex+1):]...) |
| 387 | } |
| 388 | mm.currentUids = nil |
| 389 | mm.currentEntries.Postings = res |
| 390 | return |
| 391 | } |
| 392 | mm.currentEntries.Postings[postIndex] = mpost |
| 393 | } else { |
| 394 | mm.currentEntries.Postings = append(mm.currentEntries.Postings, mpost) |
| 395 | mm.currentUids[mpost.Uid] = len(mm.currentEntries.Postings) - 1 |
| 396 | } |
| 397 | return |
| 398 | } |
| 399 | |
| 400 | mm.currentEntries.Postings = append(mm.currentEntries.Postings, mpost) |
| 401 | } |
| 402 | |
| 403 | func (mm *MutableLayer) print() string { |
| 404 | if mm == nil { |
no test coverage detected