Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/types/sharddistributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package types

import "fmt"

//go:generate enumer -type=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode -json -output sharddistributor_statuses_enumer_generated.go
//go:generate enumer -type=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode -trimprefix=ExecutorStatus,ShardStatus,AssignmentStatus,MigrationMode -json -output sharddistributor_statuses_enumer_generated.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this changes the DB data, is there something we should be cautious about when deploying (we are still prototyping, so now is the time to do it, but is there anything we need to do?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's going to change the DB data, and I agree it's the best time to do it :)
One of the reasons that all our data stored in ETCD contains a type prefix, for example: AssignmentStatusREADY was stored as AssignmentStatusREADY, but not like READY. For me, it was a bit confusing, so I assumed it wasn't done in purpose and was just a typ,o and we should fix it now.

I haven't tested this in terms of backward compatibility, so I assume that SD may fail and it will not work with the existing data stored in etcd, so perhaps we need to clean up the database before deploying.


type GetShardOwnerRequest struct {
ShardKey string
Expand Down Expand Up @@ -198,7 +198,7 @@ func (v *ExecutorHeartbeatResponse) GetMigrationPhase() (o MigrationMode) {
}

type ShardAssignment struct {
Status AssignmentStatus
Status AssignmentStatus `json:"status"`
}

func (v *ShardAssignment) GetStatus() (o AssignmentStatus) {
Expand Down
110 changes: 55 additions & 55 deletions common/types/sharddistributor_statuses_enumer_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions service/sharddistributor/handler/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func (h *executor) Heartbeat(ctx context.Context, request *types.ExecutorHeartbe
// If the state has changed we need to update heartbeat data.
// Otherwise, we want to do it with controlled frequency - at most every _heartbeatRefreshRate.
if previousHeartbeat != nil && request.Status == previousHeartbeat.Status && mode == types.MigrationModeONBOARDED {
lastHeartbeatTime := time.Unix(previousHeartbeat.LastHeartbeat, 0)
lastHeartbeatTime := previousHeartbeat.LastHeartbeat
if now.Sub(lastHeartbeatTime) < _heartbeatRefreshRate {
return _convertResponse(assignedShards, mode), nil
}
}

newHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: request.Status,
ReportedShards: request.ShardStatusReports,
Metadata: request.GetMetadata(),
Expand All @@ -103,7 +103,7 @@ func (h *executor) Heartbeat(ctx context.Context, request *types.ExecutorHeartbe
func (h *executor) assignShardsInCurrentHeartbeat(ctx context.Context, request *types.ExecutorHeartbeatRequest) (*store.AssignedState, error) {
assignedShards := store.AssignedState{
AssignedShards: make(map[string]*types.ShardAssignment),
LastUpdated: h.timeSource.Now().Unix(),
LastUpdated: h.timeSource.Now().UTC(),
ModRevision: int64(0),
}
err := h.storage.DeleteExecutors(ctx, request.GetNamespace(), []string{request.GetExecutorID()}, store.NopGuard())
Expand Down
35 changes: 18 additions & 17 deletions service/sharddistributor/handler/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestHeartbeat(t *testing.T) {

mockStore.EXPECT().GetHeartbeat(gomock.Any(), namespace, executorID).Return(nil, nil, store.ErrExecutorNotFound)
mockStore.EXPECT().RecordHeartbeat(gomock.Any(), namespace, executorID, store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
})

Expand All @@ -65,7 +65,7 @@ func TestHeartbeat(t *testing.T) {
}

previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
}

Expand All @@ -91,7 +91,7 @@ func TestHeartbeat(t *testing.T) {
}

previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
}

Expand All @@ -100,7 +100,7 @@ func TestHeartbeat(t *testing.T) {

mockStore.EXPECT().GetHeartbeat(gomock.Any(), namespace, executorID).Return(&previousHeartbeat, nil, nil)
mockStore.EXPECT().RecordHeartbeat(gomock.Any(), namespace, executorID, store.HeartbeatState{
LastHeartbeat: mockTimeSource.Now().Unix(),
LastHeartbeat: mockTimeSource.Now().UTC(),
Status: types.ExecutorStatusACTIVE,
})

Expand All @@ -124,13 +124,13 @@ func TestHeartbeat(t *testing.T) {
}

previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
}

mockStore.EXPECT().GetHeartbeat(gomock.Any(), namespace, executorID).Return(&previousHeartbeat, nil, nil)
mockStore.EXPECT().RecordHeartbeat(gomock.Any(), namespace, executorID, store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusDRAINING,
})

Expand Down Expand Up @@ -178,7 +178,7 @@ func TestHeartbeat(t *testing.T) {
Status: types.ExecutorStatusACTIVE,
}
previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
}

Expand Down Expand Up @@ -207,7 +207,7 @@ func TestHeartbeat(t *testing.T) {
Status: types.ExecutorStatusACTIVE,
}
previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
}

Expand Down Expand Up @@ -240,7 +240,7 @@ func TestHeartbeat(t *testing.T) {
}

previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
ReportedShards: map[string]*types.ShardStatusReport{
"shard1": {Status: types.ShardStatusREADY, ShardLoad: 1.0},
Expand Down Expand Up @@ -269,13 +269,14 @@ func TestHeartbeat(t *testing.T) {
return nil
},
)
mockStore.EXPECT().RecordHeartbeat(gomock.Any(), namespace, executorID, store.HeartbeatState{
LastHeartbeat: now.Unix(),
Status: types.ExecutorStatusACTIVE,
ReportedShards: map[string]*types.ShardStatusReport{
"shard0": {Status: types.ShardStatusREADY, ShardLoad: 1.0},
mockStore.EXPECT().RecordHeartbeat(gomock.Any(), namespace, executorID, gomock.AssignableToTypeOf(store.HeartbeatState{})).DoAndReturn(
func(_ context.Context, _ string, _ string, hb store.HeartbeatState) error {
// Validate status and reported shards, ignore exact timestamp
require.Equal(t, types.ExecutorStatusACTIVE, hb.Status)
require.Contains(t, hb.ReportedShards, "shard0")
return nil
},
})
)

_, err := handler.Heartbeat(ctx, req)
require.NoError(t, err)
Expand Down Expand Up @@ -303,7 +304,7 @@ func TestHeartbeat(t *testing.T) {
}

previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
ReportedShards: map[string]*types.ShardStatusReport{
"shard1": {Status: types.ShardStatusREADY, ShardLoad: 1.0},
Expand Down Expand Up @@ -346,7 +347,7 @@ func TestHeartbeat(t *testing.T) {
}

previousHeartbeat := store.HeartbeatState{
LastHeartbeat: now.Unix(),
LastHeartbeat: now,
Status: types.ExecutorStatusACTIVE,
ReportedShards: map[string]*types.ShardStatusReport{
"shard1": {Status: types.ShardStatusREADY, ShardLoad: 1.0},
Expand Down
Loading
Loading