Skip to content

Commit

Permalink
[aggregator] Add ActivePlacementVersion to tcp client (#3071)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis authored Jan 11, 2021
1 parent dd84bb2 commit e22fb12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/aggregator/client/tcp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ func (c *TCPClient) ActivePlacement() (placement.Placement, int, error) {
return placement.Clone(), stagedPlacement.Version(), nil
}

// ActivePlacementVersion returns a copy of the currently active placement version. It is a far less expensive call
// than ActivePlacement, as it does not clone the placement.
func (c *TCPClient) ActivePlacementVersion() (int, error) {
stagedPlacement, onStagedPlacementDoneFn, err := c.placementWatcher.ActiveStagedPlacement()
if err != nil {
return 0, err
}
defer onStagedPlacementDoneFn()

return stagedPlacement.Version(), nil
}

// Flush flushes any remaining data buffered by the client.
func (c *TCPClient) Flush() error {
c.metrics.flush.Inc(1)
Expand Down
9 changes: 7 additions & 2 deletions src/aggregator/client/tcp_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ func TestTCPClientActivePlacement(t *testing.T) {
)

c.placementWatcher = watcher
watcher.EXPECT().ActiveStagedPlacement().Return(stagedPlacement, func() { doneCalls++ }, nil)
stagedPlacement.EXPECT().Version().Return(42)
watcher.EXPECT().ActiveStagedPlacement().Return(stagedPlacement, func() { doneCalls++ }, nil).Times(2)
stagedPlacement.EXPECT().Version().Return(42).Times(2)
stagedPlacement.EXPECT().ActivePlacement().Return(mockPl, func() { doneCalls++ }, nil)
mockPl.EXPECT().Clone().Return(emptyPl)

Expand All @@ -809,6 +809,11 @@ func TestTCPClientActivePlacement(t *testing.T) {
assert.Equal(t, 42, v)
assert.Equal(t, 2, doneCalls)
assert.Equal(t, emptyPl, pl)

v, err = c.ActivePlacementVersion()
assert.NoError(t, err)
assert.Equal(t, 42, v)
assert.Equal(t, 3, doneCalls)
}

func TestTCPClientInitAndClose(t *testing.T) {
Expand Down

0 comments on commit e22fb12

Please sign in to comment.