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

timewheel启动了很久,新插入一个定时器直接就过期 #45

Open
tangeping opened this issue Jan 10, 2023 · 1 comment
Open

Comments

@tangeping
Copy link

tangeping commented Jan 10, 2023

currentTime 只有在advanceClock中更新。假如 timewheel开了很久了,bucket 中没有定时器,新插入一个定时器,addOrRun读到currentTime 是不是直接就过期了?

func (tw *TimingWheel) advanceClock(expiration int64) {
	currentTime := atomic.LoadInt64(&tw.currentTime)
	if expiration >= currentTime+tw.tick {
		currentTime = truncate(expiration, tw.tick)
		atomic.StoreInt64(&tw.currentTime, currentTime)

		// Try to advance the clock of the overflow wheel if present
		overflowWheel := atomic.LoadPointer(&tw.overflowWheel)
		if overflowWheel != nil {
			(*TimingWheel)(overflowWheel).advanceClock(currentTime)
		}
	}
}

@RussellLuo

@tangeping tangeping changed the title timewheel开了很久了,新插入一个定时器直接就过期 timewheel启动了很久,新插入一个定时器直接就过期 Jan 10, 2023
@ch0ngsheng
Copy link

时间轮的currentTime向前推进,是由DelayQueue中的堆顶元素过期的事件触发的。没有bucket到期就不会更新currentTime。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants