Skip to content

Commit c912454

Browse files
Fix errcheck in service/history/shard (#3755)
1 parent 5640a98 commit c912454

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

service/history/shard/context_impl.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
commonpb "go.temporal.io/api/common/v1"
3636
"go.temporal.io/api/enums/v1"
3737
"go.temporal.io/api/serviceerror"
38+
"go.uber.org/multierr"
3839
"golang.org/x/exp/maps"
3940

4041
"go.temporal.io/server/api/adminservice/v1"
@@ -1482,8 +1483,7 @@ func (s *ContextImpl) handleReadError(err error) error {
14821483
case *persistence.ShardOwnershipLostError:
14831484
// Shard is stolen, trigger shutdown of history engine.
14841485
// Handling of max read level doesn't matter here.
1485-
s.transition(contextRequestStop{})
1486-
return err
1486+
return multierr.Combine(err, s.transition(contextRequestStop{}))
14871487

14881488
default:
14891489
return err
@@ -1517,8 +1517,7 @@ func (s *ContextImpl) handleWriteErrorAndUpdateMaxReadLevelLocked(err error, new
15171517
case *persistence.ShardOwnershipLostError:
15181518
// Shard is stolen, trigger shutdown of history engine.
15191519
// Handling of max read level doesn't matter here.
1520-
s.transition(contextRequestStop{})
1521-
return err
1520+
return multierr.Combine(err, s.transition(contextRequestStop{}))
15221521

15231522
default:
15241523
// We have no idea if the write failed or will eventually make it to persistence. Try to re-acquire
@@ -1527,8 +1526,7 @@ func (s *ContextImpl) handleWriteErrorAndUpdateMaxReadLevelLocked(err error, new
15271526
// reliably check the outcome by performing a read. If we fail, we'll shut down the shard.
15281527
// Note that reacquiring the shard will cause the max read level to be updated
15291528
// to the new range (i.e. past newMaxReadLevel).
1530-
s.transition(contextRequestLost{})
1531-
return err
1529+
return multierr.Combine(err, s.transition(contextRequestLost{}))
15321530
}
15331531
}
15341532

@@ -1551,18 +1549,24 @@ func (s *ContextImpl) createEngine() Engine {
15511549

15521550
// start should only be called by the controller.
15531551
func (s *ContextImpl) start() {
1554-
s.transition(contextRequestAcquire{})
1552+
if err := s.transition(contextRequestAcquire{}); err != nil {
1553+
s.contextTaggedLogger.Error("Failed to start shard", tag.Error(err))
1554+
}
15551555
}
15561556

15571557
func (s *ContextImpl) Unload() {
1558-
s.transition(contextRequestStop{})
1558+
if err := s.transition(contextRequestStop{}); err != nil {
1559+
s.contextTaggedLogger.Error("Failed to unload shard", tag.Error(err))
1560+
}
15591561
}
15601562

15611563
// finishStop should only be called by the controller.
15621564
func (s *ContextImpl) finishStop() {
15631565
// After this returns, engineFuture.Set may not be called anymore, so if we don't get see
15641566
// an Engine here, we won't ever have one.
1565-
s.transition(contextRequestFinishStop{})
1567+
if err := s.transition(contextRequestFinishStop{}); err != nil {
1568+
s.contextTaggedLogger.Error("Failed to stop shard", tag.Error(err))
1569+
}
15661570

15671571
// use a context that we know is cancelled so that this doesn't block
15681572
engine, _ := s.engineFuture.Get(s.lifecycleCtx)
@@ -2064,7 +2068,9 @@ func (s *ContextImpl) acquireShard() {
20642068

20652069
// On any error, initiate shutting down the shard. If we already changed state
20662070
// because we got a ShardOwnershipLostError, this won't do anything.
2067-
s.transition(contextRequestStop{})
2071+
if err := s.transition(contextRequestStop{}); err != nil {
2072+
s.contextTaggedLogger.Error("Error stopping shard", tag.Error(err))
2073+
}
20682074
}
20692075
}
20702076

service/history/shard/context_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,17 @@ func (s *contextSuite) TestTimerMaxReadLevelUpdate_SingleProcessor() {
205205
s.timeSource.Update(now)
206206

207207
// make sure the scheduledTaskMaxReadLevelMap has value for both current cluster and alternative cluster
208-
s.mockShard.UpdateScheduledQueueExclusiveHighReadWatermark(cluster.TestCurrentClusterName, false)
209-
s.mockShard.UpdateScheduledQueueExclusiveHighReadWatermark(cluster.TestAlternativeClusterName, false)
208+
_, err := s.mockShard.UpdateScheduledQueueExclusiveHighReadWatermark(cluster.TestCurrentClusterName, false)
209+
s.NoError(err)
210+
_, err = s.mockShard.UpdateScheduledQueueExclusiveHighReadWatermark(cluster.TestAlternativeClusterName, false)
211+
s.NoError(err)
210212

211213
now = time.Now().Add(time.Minute)
212214
s.timeSource.Update(now)
213215

214216
// update in single processor mode
215-
s.mockShard.UpdateScheduledQueueExclusiveHighReadWatermark(cluster.TestCurrentClusterName, true)
217+
_, err = s.mockShard.UpdateScheduledQueueExclusiveHighReadWatermark(cluster.TestCurrentClusterName, true)
218+
s.NoError(err)
216219
scheduledTaskMaxReadLevelMap := s.mockShard.scheduledTaskMaxReadLevelMap
217220
s.Len(scheduledTaskMaxReadLevelMap, 2)
218221
s.True(scheduledTaskMaxReadLevelMap[cluster.TestCurrentClusterName].After(now))

service/history/shard/controller_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,9 @@ func (s *controllerSuite) TestShardControllerFuzz() {
790790
shardID := int32(rand.Intn(int(s.config.NumberOfShards))) + 1
791791
switch rand.Intn(5) {
792792
case 0:
793-
s.shardController.GetShardByID(shardID)
793+
if _, err := s.shardController.GetShardByID(shardID); err != nil {
794+
return err
795+
}
794796
case 1:
795797
if shard, err := s.shardController.GetShardByID(shardID); err == nil {
796798
_, _ = shard.GetEngine(ctx)

0 commit comments

Comments
 (0)