| 200 | } |
| 201 | |
| 202 | func (i *ClusterIterator) next() bool { |
| 203 | if len(i.page) != 0 { |
| 204 | i.pos++ |
| 205 | if i.pos <= len(i.page) { |
| 206 | return true |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | i.resetPage() |
| 211 | |
| 212 | for { |
| 213 | if err := i.fetchData(); err != nil { |
| 214 | i.logger.Printf("[ERROR] Failed to fetch data: %s", err) |
| 215 | return false |
| 216 | } |
| 217 | if len(i.page) != 0 { |
| 218 | // We have data on the page to read. Stop the iteration. |
| 219 | break |
| 220 | } |
| 221 | |
| 222 | if len(i.route.PrimaryOwners) == 0 && len(i.route.ReplicaOwners) == 0 { |
| 223 | // We completed scanning all the owners. Stop the iteration. |
| 224 | break |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if len(i.page) == 0 && len(i.route.PrimaryOwners) == 0 && len(i.route.ReplicaOwners) == 0 { |
| 229 | i.partID++ |
| 230 | if i.partID >= i.partitionCount { |
| 231 | return false |
| 232 | } |
| 233 | i.reset() |
| 234 | return i.next() |
| 235 | } |
| 236 | i.pos = 1 |
| 237 | return true |
| 238 | } |
| 239 | |
| 240 | // Next returns true if there is more key in the iterator implementation. |
| 241 | // Otherwise, it returns false |