Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not get item from an unsync backend #5836

Merged
merged 5 commits into from
Jun 14, 2021
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
1 change: 1 addition & 0 deletions engine/cdn/cdn_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ func (s *Service) getRandomItemUnitIDByItemID(ctx context.Context, itemID string

itemUnits = s.Units.FilterItemUnitReaderByType(itemUnits)
itemUnits = s.Units.FilterItemUnitFromBuffer(itemUnits)
itemUnits = s.Units.FilterNotSyncBackend(itemUnits)

if len(itemUnits) == 0 {
return "", "", sdk.WithStack(fmt.Errorf("unable to find item units for item with id: %s", itemID))
Expand Down
3 changes: 3 additions & 0 deletions engine/cdn/cdn_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (s *Service) ComputeMetrics(ctx context.Context) {

var storageStats []storage.Stat
for _, su := range s.Units.Storages {
if !su.CanSync() {
continue
}
storageStats = append(storageStats, s.countItemsForUnit(ctx, su)...)
}

Expand Down
20 changes: 20 additions & 0 deletions engine/cdn/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ func (x RunningStorageUnits) GetBuffer(bufferType sdk.CDNItemType) BufferUnit {
}
}

func (x *RunningStorageUnits) CanSync(unitID string) bool {
for _, unit := range x.Storages {
if unit.ID() == unitID {
return unit.CanSync()
}
}
return false
}

func (x *RunningStorageUnits) FilterNotSyncBackend(ius []sdk.CDNItemUnit) []sdk.CDNItemUnit {
itemsUnits := make([]sdk.CDNItemUnit, 0, len(ius))
for _, u := range ius {
if !x.CanSync(u.UnitID) {
continue
}
itemsUnits = append(itemsUnits, u)
}
return itemsUnits
}

func (x *RunningStorageUnits) FilterItemUnitFromBuffer(ius []sdk.CDNItemUnit) []sdk.CDNItemUnit {
itemsUnits := make([]sdk.CDNItemUnit, 0, len(ius))
for _, u := range ius {
Expand Down
7 changes: 7 additions & 0 deletions engine/sql/cdn/014_cdn_type_index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +migrate Up
SELECT create_index('item', 'idx_item_type_status', 'type,status');
SELECT create_index('storage_unit_item', 'idx_storage_unit_type_item_unit_id', 'type,unit_id');

-- +migrate Down
DROP INDEX "idx_item_type_status";
DROP INDEX "idx_storage_unit_type_item_unit_id"