- 将 RecordStream 出站路径收敛为单 writer loop - 支持在 batch header 中 piggyback AckSeq,保留独立 ack 作为兼容回退 - 增加 record stream 打开阶段能力协商,支持 mixed-version peer 自动降级 - 补充 RecordSnapshot 与 diagnostics summary 的 record-plane 观测项 - 增加 batch/ack/error frame、piggyback ack、barrier 等待拆分与 apply backlog 指标 - 收紧 TransportConn detach 后的 runtime snapshot 语义 - 补充 README 中的 RecordStream 语义、兼容行为与诊断快照说明 - 补充相关单测与 race 回归验证
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package notify
|
|
|
|
import "context"
|
|
|
|
func (c *ClientCommon) SetRecordStreamHandler(fn func(RecordAcceptInfo) error) {
|
|
runtime := c.getRecordRuntime()
|
|
if runtime == nil {
|
|
return
|
|
}
|
|
runtime.setHandler(fn)
|
|
}
|
|
|
|
func (c *ClientCommon) OpenRecordStream(ctx context.Context, opt RecordOpenOptions) (RecordStream, error) {
|
|
if c == nil {
|
|
return nil, errStreamClientNil
|
|
}
|
|
opt = normalizeRecordOpenOptions(opt)
|
|
stream, err := c.OpenStream(ctx, opt.Stream)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
record, err := WrapStreamAsRecord(stream, opt)
|
|
if err != nil {
|
|
_ = stream.Reset(err)
|
|
return nil, err
|
|
}
|
|
bindRecordRuntime(record, c.getRecordRuntime())
|
|
return record, nil
|
|
}
|
|
|
|
func (c *ClientCommon) claimInboundRecordStream(stream *streamHandle) (bool, error) {
|
|
if stream == nil || stream.Channel() != StreamRecordChannel {
|
|
return false, nil
|
|
}
|
|
runtime := c.getRecordRuntime()
|
|
if runtime == nil {
|
|
return true, errRecordRuntimeNil
|
|
}
|
|
handler := runtime.handlerSnapshot()
|
|
if handler == nil {
|
|
return true, errRecordHandlerNotConfigured
|
|
}
|
|
record, err := WrapStreamAsRecord(stream, RecordOpenOptions{
|
|
Stream: StreamOpenOptions{
|
|
ID: stream.ID(),
|
|
Channel: stream.Channel(),
|
|
Metadata: stream.Metadata(),
|
|
ReadTimeout: stream.readTimeoutSnapshot(),
|
|
WriteTimeout: stream.writeTimeoutSnapshot(),
|
|
},
|
|
})
|
|
if err != nil {
|
|
return true, err
|
|
}
|
|
bindRecordRuntime(record, runtime)
|
|
info := RecordAcceptInfo{
|
|
ID: stream.ID(),
|
|
Metadata: stream.Metadata(),
|
|
TransportGeneration: stream.TransportGeneration(),
|
|
RecordStream: record,
|
|
}
|
|
go func() {
|
|
if err := handler(info); err != nil {
|
|
_ = record.Reset(err)
|
|
}
|
|
}()
|
|
return true, nil
|
|
}
|