Skip to content

Commit 0919887

Browse files
committed
fix(shard-distributor): make DeleteShardStats non-transactional and fix cleanup condition
DeleteShardStats doesn't need transactional guards since we are just working with telemetry. Signed-off-by: Andreas Holt <[email protected]>
1 parent c6959bf commit 0919887

File tree

5 files changed

+14
-32
lines changed

5 files changed

+14
-32
lines changed

service/sharddistributor/leader/process/processor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ func (p *namespaceProcessor) runShardStatsCleanupLoop(ctx context.Context) {
237237
continue
238238
}
239239
staleShardStats := p.identifyStaleShardStats(namespaceState)
240-
if len(staleShardStats) > 0 {
240+
if len(staleShardStats) == 0 {
241241
// No stale shard stats to delete
242242
continue
243243
}
244-
if err := p.shardStore.DeleteShardStats(ctx, p.namespaceCfg.Name, staleShardStats, p.election.Guard()); err != nil {
244+
if err := p.shardStore.DeleteShardStats(ctx, p.namespaceCfg.Name, staleShardStats); err != nil {
245245
p.logger.Error("Failed to delete stale shard stats", tag.Error(err))
246246
}
247247
}

service/sharddistributor/store/etcd/executorstore/etcdstore.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -625,37 +625,19 @@ func (s *executorStoreImpl) DeleteExecutors(ctx context.Context, namespace strin
625625
return nil
626626
}
627627

628-
func (s *executorStoreImpl) DeleteShardStats(ctx context.Context, namespace string, shardIDs []string, guard store.GuardFunc) error {
628+
func (s *executorStoreImpl) DeleteShardStats(ctx context.Context, namespace string, shardIDs []string) error {
629629
if len(shardIDs) == 0 {
630630
return nil
631631
}
632-
var ops []clientv3.Op
632+
633633
for _, shardID := range shardIDs {
634634
shardStatsKey, err := etcdkeys.BuildShardKey(s.prefix, namespace, shardID, etcdkeys.ShardStatisticsKey)
635635
if err != nil {
636636
return fmt.Errorf("build shard statistics key: %w", err)
637637
}
638-
ops = append(ops, clientv3.OpDelete(shardStatsKey))
639-
}
640-
641-
nativeTxn := s.client.Txn(ctx)
642-
guardedTxn, err := guard(nativeTxn)
643-
644-
if err != nil {
645-
return fmt.Errorf("apply transaction guard: %w", err)
646-
}
647-
etcdGuardedTxn, ok := guardedTxn.(clientv3.Txn)
648-
if !ok {
649-
return fmt.Errorf("guard function returned invalid transaction type")
650-
}
651-
652-
etcdGuardedTxn = etcdGuardedTxn.Then(ops...)
653-
resp, err := etcdGuardedTxn.Commit()
654-
if err != nil {
655-
return fmt.Errorf("commit shard statistics deletion: %w", err)
656-
}
657-
if !resp.Succeeded {
658-
return fmt.Errorf("transaction failed, leadership may have changed")
638+
if _, err := s.client.Delete(ctx, shardStatsKey); err != nil {
639+
return fmt.Errorf("delete shard statistics: %w", err)
640+
}
659641
}
660642
return nil
661643
}

service/sharddistributor/store/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Store interface {
6363
AssignShards(ctx context.Context, namespace string, request AssignShardsRequest, guard GuardFunc) error
6464
Subscribe(ctx context.Context, namespace string) (<-chan int64, error)
6565
DeleteExecutors(ctx context.Context, namespace string, executorIDs []string, guard GuardFunc) error
66-
DeleteShardStats(ctx context.Context, namespace string, shardIDs []string, guard GuardFunc) error
66+
DeleteShardStats(ctx context.Context, namespace string, shardIDs []string) error
6767

6868
GetShardOwner(ctx context.Context, namespace, shardID string) (*ShardOwner, error)
6969
SubscribeToAssignmentChanges(ctx context.Context, namespace string) (<-chan map[*ShardOwner][]string, func(), error)

service/sharddistributor/store/store_mock.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/sharddistributor/store/wrappers/metered/store_generated.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)