Repository: threefoldtech/zos
Pull request #362 (2019-11-04 15:05:05)

the from cursor is last res.ID + 1

codecov[bot]: # [Codecov](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=h1) Report
> Merging [#362](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=desc) into [master](https://codecov.io/gh/threefoldtech/zos/commit/9c1ed35d2ca3d7b578e6cf352df4445a72158b5c?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/threefoldtech/zos/pull/362/graphs/tree.svg?width=650&token=f7Vmq1OAEm&height=150&src=pr)](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #362   +/-   ##
=======================================
  Coverage   40.85%   40.85%           
=======================================
  Files          61       61           
  Lines        3782     3782           
=======================================
  Hits         1545     1545           
  Misses       2032     2032           
  Partials      205      205
```


| [Impacted Files](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/provision/remote\_store.go](https://codecov.io/gh/threefoldtech/zos/pull/362/diff?src=pr&el=tree#diff-cGtnL3Byb3Zpc2lvbi9yZW1vdGVfc3RvcmUuZ28=) | `0% <ø> (ø)` | :arrow_up: |
| [pkg/provision/source.go](https://codecov.io/gh/threefoldtech/zos/pull/362/diff?src=pr&el=tree#diff-cGtnL3Byb3Zpc2lvbi9zb3VyY2UuZ28=) | `32.09% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=footer). Last update [9c1ed35...ee69795](https://codecov.io/gh/threefoldtech/zos/pull/362?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pkg/provision/remote_store.go b/pkg/provision/remote_store.go
index f0080a77..e50a691e 100644
--- a/pkg/provision/remote_store.go
+++ b/pkg/provision/remote_store.go
@@ -51,7 +51,7 @@ func (s *HTTPStore) Reserve(r *Reservation, nodeID pkg.Identifier) (string, erro
 }
 
 // Poll retrieves reservations from BCDB. from acts like a cursor, first call should use
-// 0  to retrieve everything. Next calls should use the last (MAX) ID of the previous poll.
+// 0  to retrieve everything. Next calls should use the last+1 ID of the previous poll.
 // Note that from is a reservation ID not a workload ID. so user the Reservation.SplitID() method
 // to get the reservation part.
 func (s *HTTPStore) Poll(nodeID pkg.Identifier, from uint64) ([]*Reservation, error) {
diff --git a/pkg/provision/source.go b/pkg/provision/source.go
index 167829a5..e42a5b44 100644
--- a/pkg/provision/source.go
+++ b/pkg/provision/source.go
@@ -28,7 +28,7 @@ var (
 type ReservationPoller interface {
 	// Poll ask the store to send us reservation for a specific node ID
 	// from is the used as a filter to which reservation to use as
-	// reservation.ID > from. So a client to the Poll method should make
+	// reservation.ID >= from. So a client to the Poll method should make
 	// sure to call it with the last (MAX) reservation ID he receieved.
 	Poll(nodeID pkg.Identifier, from uint64) ([]*Reservation, error)
 }
@@ -55,13 +55,13 @@ func (s *pollSource) Reservations(ctx context.Context) <-chan *Reservation {
 	// after that, we only ask for the new reservations
 	go func() {
 		defer close(ch)
-		var from uint64
+		var next uint64
 		on := time.Now()
 		for {
 			time.Sleep(time.Until(on))
 			on = time.Now().Add(s.maxSleep)
 
-			res, err := s.store.Poll(pkg.StrIdentifier(s.nodeID), from)
+			res, err := s.store.Poll(pkg.StrIdentifier(s.nodeID), next)
 			if err != nil && err != ErrPollEOS {
 				log.Error().Err(err).Msg("failed to get reservation")
 				continue
@@ -72,13 +72,13 @@ func (s *pollSource) Reservations(ctx context.Context) <-chan *Reservation {
 				return
 			default:
 				for _, r := range res {
-					next, _, err := r.SplitID()
+					current, _, err := r.SplitID()
 					if err != nil {
 						log.Warn().Err(err).Str("id", r.ID).Msg("skipping reservation")
 						continue
 					}
-					if next > from {
-						from = next
+					if current >= next {
+						next = current + 1
 					}
 					ch <- r
 				}
diff --git a/tools/bcdb_mock/reservation_store.go b/tools/bcdb_mock/reservation_store.go
index 16933503..180b0072 100644
--- a/tools/bcdb_mock/reservation_store.go
+++ b/tools/bcdb_mock/reservation_store.go
@@ -105,7 +105,7 @@ func (s *reservationsStore) GetReservations(nodeID string, from uint64) []*provi
 		}
 
 		if from == 0 ||
-			(!r.Reservation.Expired() && resID > from) ||
+			(!r.Reservation.Expired() && resID >= from) ||
 			(r.Reservation.ToDelete && !r.Deleted) {
 			output = append(output, r.Reservation)
 		}


Test patch:
diff --git a/pkg/provision/source_test.go b/pkg/provision/source_test.go
index a0473046..47888297 100644
--- a/pkg/provision/source_test.go
+++ b/pkg/provision/source_test.go
@@ -62,7 +62,7 @@ func TestHTTPReservationSourceMultiple(t *testing.T) {
 			&Reservation{ID: "2-1"},
 		}, nil) // return nil error so it tries again
 
-	store.On("Poll", nodeID, uint64(2)).
+	store.On("Poll", nodeID, uint64(3)).
 		Return([]*Reservation{
 			&Reservation{ID: "3-1"},
 			&Reservation{ID: "4-1"},