temporalio / temporalio/temporal

Do not block shard ownership assertion if `acquireShards` is blocked

Open
#3,134 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement potential-bug
Dominant language
Go
Stars
23.2k
Forks
1.9k
Avg merge
2d 8h
Merged PRs (30d)
228

Description

Do not block shard ownership assertion if acquireShards is blocked
v1.17.x logic:

shard controller will start a background thread periodically asserting shard ownership

for {
	select {
	...
	case <-acquireTicker.C:
		c.acquireShards()
	...
	}
}

if acquireShards is blocked due to whatever reason, then no further acquireShards will be executed.

OSS team should consider the following logic

var (
	ShardController struct {
		...

		shardAssertionInProgressMutex sync.Mutex
		shardAssertionInProgress map[int32]struct{}
		shardIDChan chan int32
		...
	}
)

func (sc *ShardController) eventLoop() {
	acquireTicker := time.NewTicker(c.config.AcquireShardInterval())
	defer acquireTicker.Stop()

	for {
		select {
		case <-c.shutdownCh:			
			return
		case <-acquireTicker.C:
			for i = 0; i < totalShardIDs; i++ {
				shardAssertionInProgressMutex.Lock()
				_, exist = sc.shardAssertionInProgress[i]
				if !exist {
					sc.shardAssertionInProgress[i] = struct{}{}
				}
				shardAssertionInProgressMutex.Unlock()
				if !exist {
					sc.shardIDChan <- i
				}
			}
		}
	}
}

func (sc *ShardController) acquireShard() {
	for shardID := range shardIDChan {
		...
		// shard ownership assertion logic here
		...
		
		shardAssertionInProgressMutex.Lock()
		delete(sc.shardAssertionInProgress, shardID)
		shardAssertionInProgressMutex.Unlock()
	}
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the shard controller's eventLoop, acquireShards, and acquireShard entry points and read how the periodic ownership assertion is currently dispatched. Confirm the change keeps later shard ownership assertions running when one acquire operation blocks, while preserving shutdown behavior and preventing duplicate assertions for the same shard.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.