1f2e74acca
- 完善 stream/bulk DataID 分配、预留和双向命名空间,修复并发打开及 dedicated/shared 回退时的 ID 冲突 - 将收发、回复、恢复任务和 sidecar 绑定原始会话与物理连接,防止重连后的旧消息误操作新连接 - 加强 close/reset 身份校验及实例移除检查,修复 dedicated attach 失败、通道引用和资源回收竞态 - 收紧批量发送器停止准入,确保在途入队完成后统一清理请求、缓冲区和等待者 - 修复 record 满队列死锁、取消时序号消耗及关闭竞态,确保关闭有界并返回真实错误 - 增加协商式 record 逻辑半关闭,保留反向 ACK;通过 reset 传递 RecordFailure,避免背压掩盖原始失败原因 - 补齐帧长度、批次数量、序号溢出和未确认窗口校验,提前拒绝超限数据并按字节预算拆批 - 为入站分发增加全局及单连接的条数、字节预算和阻塞背压,关闭时唤醒等待者,消除正常断连日志噪音 - 完善 bulk 窗口释放失败处理与传输诊断,补充并发、重连、背压、协议边界及真实 TCP 回归覆盖
248 lines
5.2 KiB
Go
248 lines
5.2 KiB
Go
package notify
|
|
|
|
import "sync/atomic"
|
|
|
|
const (
|
|
ownerSessionStateIdle int32 = iota
|
|
ownerSessionStateStarting
|
|
ownerSessionStateRunning
|
|
ownerSessionStateStopping
|
|
ownerSessionStateFinalizing
|
|
ownerSessionStateStopped
|
|
)
|
|
|
|
func beginOwnerSessionStart(state *atomic.Int32) bool {
|
|
if state == nil {
|
|
return false
|
|
}
|
|
for {
|
|
current := state.Load()
|
|
switch current {
|
|
case ownerSessionStateIdle, ownerSessionStateStopped:
|
|
if state.CompareAndSwap(current, ownerSessionStateStarting) {
|
|
return true
|
|
}
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
func rollbackOwnerSessionStart(state *atomic.Int32) {
|
|
if state == nil {
|
|
return
|
|
}
|
|
state.CompareAndSwap(ownerSessionStateStarting, ownerSessionStateIdle)
|
|
}
|
|
|
|
func markOwnerSessionStarted(state *atomic.Int32) {
|
|
if state == nil {
|
|
return
|
|
}
|
|
for {
|
|
current := state.Load()
|
|
switch current {
|
|
case ownerSessionStateRunning:
|
|
return
|
|
case ownerSessionStateStopping, ownerSessionStateFinalizing:
|
|
return
|
|
case ownerSessionStateStarting, ownerSessionStateIdle, ownerSessionStateStopped:
|
|
if state.CompareAndSwap(current, ownerSessionStateRunning) {
|
|
return
|
|
}
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func markOwnerSessionStopping(state *atomic.Int32) bool {
|
|
if state == nil {
|
|
return false
|
|
}
|
|
for {
|
|
current := state.Load()
|
|
switch current {
|
|
case ownerSessionStateStopping, ownerSessionStateFinalizing, ownerSessionStateStopped:
|
|
return false
|
|
case ownerSessionStateRunning, ownerSessionStateStarting:
|
|
if state.CompareAndSwap(current, ownerSessionStateStopping) {
|
|
return true
|
|
}
|
|
case ownerSessionStateIdle:
|
|
if state.CompareAndSwap(current, ownerSessionStateStopped) {
|
|
return true
|
|
}
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
// claimOwnerSessionStop elects exactly one caller to run session cleanup.
|
|
// finalizing remains externally visible as "stopping" while preventing a
|
|
// concurrent Stop/read-error path from entering cleanup a second time.
|
|
func claimOwnerSessionStop(state *atomic.Int32) bool {
|
|
if state == nil {
|
|
return false
|
|
}
|
|
for {
|
|
current := state.Load()
|
|
switch current {
|
|
case ownerSessionStateFinalizing, ownerSessionStateStopped:
|
|
return false
|
|
case ownerSessionStateIdle, ownerSessionStateStarting, ownerSessionStateRunning, ownerSessionStateStopping:
|
|
if state.CompareAndSwap(current, ownerSessionStateFinalizing) {
|
|
return true
|
|
}
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
func markOwnerSessionStopped(state *atomic.Int32) {
|
|
if state == nil {
|
|
return
|
|
}
|
|
for {
|
|
current := state.Load()
|
|
if current == ownerSessionStateStopped {
|
|
return
|
|
}
|
|
if state.CompareAndSwap(current, ownerSessionStateStopped) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func ownerSessionStateName(state int32) string {
|
|
switch state {
|
|
case ownerSessionStateIdle:
|
|
return "idle"
|
|
case ownerSessionStateStarting:
|
|
return "starting"
|
|
case ownerSessionStateRunning:
|
|
return "running"
|
|
case ownerSessionStateStopping, ownerSessionStateFinalizing:
|
|
return "stopping"
|
|
case ownerSessionStateStopped:
|
|
return "stopped"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
func ownerSessionStateValue(state *atomic.Int32) int32 {
|
|
if state == nil {
|
|
return ownerSessionStateIdle
|
|
}
|
|
return state.Load()
|
|
}
|
|
|
|
func (c *ClientCommon) beginClientSessionStart() bool {
|
|
if c == nil {
|
|
return false
|
|
}
|
|
return beginOwnerSessionStart(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) rollbackClientSessionStart() {
|
|
if c == nil {
|
|
return
|
|
}
|
|
rollbackOwnerSessionStart(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) markClientSessionStarted() {
|
|
if c == nil {
|
|
return
|
|
}
|
|
markOwnerSessionStarted(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) markClientSessionStopped() {
|
|
if c == nil {
|
|
return
|
|
}
|
|
markOwnerSessionStopped(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) markClientSessionStopping() bool {
|
|
if c == nil {
|
|
return false
|
|
}
|
|
return markOwnerSessionStopping(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) claimClientSessionStop() bool {
|
|
if c == nil {
|
|
return false
|
|
}
|
|
return claimOwnerSessionStop(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) ownerSessionState() int32 {
|
|
if c == nil {
|
|
return ownerSessionStateIdle
|
|
}
|
|
return ownerSessionStateValue(&c.sessionOwnerState)
|
|
}
|
|
|
|
func (c *ClientCommon) ownerSessionStateName() string {
|
|
return ownerSessionStateName(c.ownerSessionState())
|
|
}
|
|
|
|
func (s *ServerCommon) beginServerSessionStart() bool {
|
|
if s == nil {
|
|
return false
|
|
}
|
|
return beginOwnerSessionStart(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) rollbackServerSessionStart() {
|
|
if s == nil {
|
|
return
|
|
}
|
|
rollbackOwnerSessionStart(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) markServerSessionStarted() {
|
|
if s == nil {
|
|
return
|
|
}
|
|
markOwnerSessionStarted(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) markServerSessionStopped() {
|
|
if s == nil {
|
|
return
|
|
}
|
|
markOwnerSessionStopped(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) markServerSessionStopping() bool {
|
|
if s == nil {
|
|
return false
|
|
}
|
|
return markOwnerSessionStopping(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) claimServerSessionStop() bool {
|
|
if s == nil {
|
|
return false
|
|
}
|
|
return claimOwnerSessionStop(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) ownerSessionState() int32 {
|
|
if s == nil {
|
|
return ownerSessionStateIdle
|
|
}
|
|
return ownerSessionStateValue(&s.sessionOwnerState)
|
|
}
|
|
|
|
func (s *ServerCommon) ownerSessionStateName() string {
|
|
return ownerSessionStateName(s.ownerSessionState())
|
|
}
|