listLen() returns the length of the mutable layer at the readTs. If the readTs changes, the list len could change.
(readTs uint64)
| 195 | |
| 196 | // listLen() returns the length of the mutable layer at the readTs. If the readTs changes, the list len could change. |
| 197 | func (mm *MutableLayer) listLen(readTs uint64) int { |
| 198 | if mm == nil { |
| 199 | return 0 |
| 200 | } |
| 201 | |
| 202 | count := 0 |
| 203 | checkPostingForCount := func(pl *pb.PostingList) { |
| 204 | for _, mpost := range pl.Postings { |
| 205 | if hasDeleteAll(mpost) { |
| 206 | // We reach here via either iterating the entire mutable layer, or for just the |
| 207 | // current entries. For both of them we can only see the latest delete all. If a |
| 208 | // posting list has a delete all marker, we still need to set count for all the other |
| 209 | // entries. Hence we need to make sure that count = 0 before we reach here. |
| 210 | continue |
| 211 | } |
| 212 | count += getLengthDelta(mpost.Op) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // mm.committedUidsTime could be math.MaxUint64 or the actual value. If it's MaxUint64, we know there is no |
| 217 | // entry in the mm, and we can just do iterate. If value is set and readTs < committedUidsTime, we need to |
| 218 | // iterate. |
| 219 | if mm.length == math.MaxInt || readTs < mm.committedUidsTime { |
| 220 | mm.iterate(func(_ uint64, pl *pb.PostingList) { |
| 221 | checkPostingForCount(pl) |
| 222 | }, readTs) |
| 223 | return count |
| 224 | } |
| 225 | |
| 226 | count = mm.length |
| 227 | |
| 228 | if mm.currentEntries != nil && (readTs == mm.readTs) { |
| 229 | if mm.populateDeleteAll(readTs) == mm.readTs { |
| 230 | // If deleteAll is present, we don't need the count from mm.length. |
| 231 | count = 0 |
| 232 | } |
| 233 | checkPostingForCount(mm.currentEntries) |
| 234 | } |
| 235 | return count |
| 236 | } |
| 237 | |
| 238 | // populateDeleteAll() returns the deleteAllMarker under readTs. It also finds out and sets the global deleteAllMarker |
| 239 | // in hopes to cache it and use it later if required. |