fix: close stream adaptive gaps and switch notify to stario v0.1.1
- make stream fast path honor adaptive soft payload limits end-to-end - split oversized fast-stream payloads into sequential frames before batching - use adaptive soft cap when encoding stream batch payloads - move timeout-like error detection into production code for adaptive tx - tune notify FrameReader read size explicitly to avoid throughput regression - drop local stario replace and depend on released b612.me/stario v0.1.1
This commit is contained in:
+158
-13
@@ -2,7 +2,7 @@ package notify
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -16,14 +16,14 @@ type bulkRuntime struct {
|
||||
mu sync.RWMutex
|
||||
handler func(BulkAcceptInfo) error
|
||||
bulks map[string]*bulkHandle
|
||||
data map[string]*bulkHandle
|
||||
data map[string]map[uint64]*bulkHandle
|
||||
}
|
||||
|
||||
func newBulkRuntime(rolePrefix string) *bulkRuntime {
|
||||
return &bulkRuntime{
|
||||
rolePrefix: rolePrefix,
|
||||
bulks: make(map[string]*bulkHandle),
|
||||
data: make(map[string]*bulkHandle),
|
||||
data: make(map[string]map[uint64]*bulkHandle),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ func (r *bulkRuntime) register(scope string, bulk *bulkHandle) error {
|
||||
if bulk == nil || bulk.id == "" {
|
||||
return errBulkIDEmpty
|
||||
}
|
||||
scope = normalizeFileScope(scope)
|
||||
key := bulkRuntimeKey(scope, bulk.id)
|
||||
dataKey := bulkRuntimeDataKey(scope, bulk.dataID)
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if _, ok := r.bulks[key]; ok {
|
||||
@@ -76,11 +76,16 @@ func (r *bulkRuntime) register(scope string, bulk *bulkHandle) error {
|
||||
if bulk.dataID == 0 {
|
||||
return errBulkDataIDEmpty
|
||||
}
|
||||
if _, ok := r.data[dataKey]; ok {
|
||||
dataScope := r.data[scope]
|
||||
if dataScope == nil {
|
||||
dataScope = make(map[uint64]*bulkHandle)
|
||||
r.data[scope] = dataScope
|
||||
}
|
||||
if _, ok := dataScope[bulk.dataID]; ok {
|
||||
return errBulkAlreadyExists
|
||||
}
|
||||
r.bulks[key] = bulk
|
||||
r.data[dataKey] = bulk
|
||||
dataScope[bulk.dataID] = bulk
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -99,10 +104,14 @@ func (r *bulkRuntime) lookupByDataID(scope string, dataID uint64) (*bulkHandle,
|
||||
if r == nil || dataID == 0 {
|
||||
return nil, false
|
||||
}
|
||||
key := bulkRuntimeDataKey(scope, dataID)
|
||||
scope = normalizeFileScope(scope)
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
bulk, ok := r.data[key]
|
||||
dataScope := r.data[scope]
|
||||
if dataScope == nil {
|
||||
return nil, false
|
||||
}
|
||||
bulk, ok := dataScope[dataID]
|
||||
return bulk, ok
|
||||
}
|
||||
|
||||
@@ -110,11 +119,17 @@ func (r *bulkRuntime) remove(scope string, bulkID string) {
|
||||
if r == nil || bulkID == "" {
|
||||
return
|
||||
}
|
||||
scope = normalizeFileScope(scope)
|
||||
key := bulkRuntimeKey(scope, bulkID)
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if bulk := r.bulks[key]; bulk != nil && bulk.dataID != 0 {
|
||||
delete(r.data, bulkRuntimeDataKey(scope, bulk.dataID))
|
||||
if dataScope := r.data[scope]; dataScope != nil {
|
||||
delete(dataScope, bulk.dataID)
|
||||
if len(dataScope) == 0 {
|
||||
delete(r.data, scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
delete(r.bulks, key)
|
||||
}
|
||||
@@ -149,6 +164,140 @@ func (r *bulkRuntime) closeMatching(match func(string) bool, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *bulkRuntime) resetDedicatedByConn(scope string, conn net.Conn, err error) {
|
||||
if r == nil || conn == nil {
|
||||
return
|
||||
}
|
||||
scope = normalizeFileScope(scope)
|
||||
resetErr := bulkRuntimeCloseError(err)
|
||||
prefix := scope + "\x00"
|
||||
r.mu.RLock()
|
||||
bulks := make([]*bulkHandle, 0, len(r.bulks))
|
||||
for key, bulk := range r.bulks {
|
||||
if bulk == nil {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix) {
|
||||
continue
|
||||
}
|
||||
if !bulk.Dedicated() {
|
||||
continue
|
||||
}
|
||||
if bulk.dedicatedConnSnapshot() != conn {
|
||||
continue
|
||||
}
|
||||
bulks = append(bulks, bulk)
|
||||
}
|
||||
r.mu.RUnlock()
|
||||
for _, bulk := range bulks {
|
||||
bulk.markReset(resetErr)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *bulkRuntime) handleDedicatedReadErrorByConn(scope string, conn net.Conn, err error) {
|
||||
if r == nil || conn == nil {
|
||||
return
|
||||
}
|
||||
scope = normalizeFileScope(scope)
|
||||
prefix := scope + "\x00"
|
||||
r.mu.RLock()
|
||||
bulks := make([]*bulkHandle, 0, len(r.bulks))
|
||||
for key, bulk := range r.bulks {
|
||||
if bulk == nil {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix) {
|
||||
continue
|
||||
}
|
||||
if !bulk.Dedicated() {
|
||||
continue
|
||||
}
|
||||
if bulk.dedicatedConnSnapshot() != conn {
|
||||
continue
|
||||
}
|
||||
bulks = append(bulks, bulk)
|
||||
}
|
||||
r.mu.RUnlock()
|
||||
for _, bulk := range bulks {
|
||||
handleDedicatedBulkReadError(bulk, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *bulkRuntime) attachSharedDedicatedConn(scope string, laneID uint32, conn net.Conn) {
|
||||
if r == nil || conn == nil {
|
||||
return
|
||||
}
|
||||
scope = normalizeFileScope(scope)
|
||||
laneID = normalizeBulkDedicatedLaneID(laneID)
|
||||
prefix := scope + "\x00"
|
||||
r.mu.RLock()
|
||||
bulks := make([]*bulkHandle, 0, len(r.bulks))
|
||||
for key, bulk := range r.bulks {
|
||||
if bulk == nil {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix) {
|
||||
continue
|
||||
}
|
||||
if !bulk.Dedicated() {
|
||||
continue
|
||||
}
|
||||
if bulk.dedicatedLaneIDSnapshot() != laneID {
|
||||
continue
|
||||
}
|
||||
bulks = append(bulks, bulk)
|
||||
}
|
||||
r.mu.RUnlock()
|
||||
for _, bulk := range bulks {
|
||||
current := bulk.dedicatedConnSnapshot()
|
||||
switch {
|
||||
case current == conn:
|
||||
_ = bulk.attachDedicatedConnShared(conn)
|
||||
case current == nil:
|
||||
_ = bulk.attachDedicatedConnShared(conn)
|
||||
default:
|
||||
oldConn, oldSender, err := bulk.replaceDedicatedConnShared(conn)
|
||||
if err != nil {
|
||||
bulk.markReset(err)
|
||||
continue
|
||||
}
|
||||
if oldSender != nil {
|
||||
oldSender.stop()
|
||||
}
|
||||
if oldConn != nil {
|
||||
_ = oldConn.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *bulkRuntime) dedicatedBulksForConn(scope string, conn net.Conn) []*bulkHandle {
|
||||
if r == nil || conn == nil {
|
||||
return nil
|
||||
}
|
||||
scope = normalizeFileScope(scope)
|
||||
prefix := scope + "\x00"
|
||||
r.mu.RLock()
|
||||
bulks := make([]*bulkHandle, 0, len(r.bulks))
|
||||
for key, bulk := range r.bulks {
|
||||
if bulk == nil {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix) {
|
||||
continue
|
||||
}
|
||||
if !bulk.Dedicated() {
|
||||
continue
|
||||
}
|
||||
if bulk.dedicatedConnSnapshot() != conn {
|
||||
continue
|
||||
}
|
||||
bulks = append(bulks, bulk)
|
||||
}
|
||||
r.mu.RUnlock()
|
||||
return bulks
|
||||
}
|
||||
|
||||
func (r *bulkRuntime) snapshots() []BulkSnapshot {
|
||||
if r == nil {
|
||||
return nil
|
||||
@@ -170,10 +319,6 @@ func bulkRuntimeKey(scope string, bulkID string) string {
|
||||
return normalizeFileScope(scope) + "\x00" + bulkID
|
||||
}
|
||||
|
||||
func bulkRuntimeDataKey(scope string, dataID uint64) string {
|
||||
return normalizeFileScope(scope) + "\x01" + strconv.FormatUint(dataID, 10)
|
||||
}
|
||||
|
||||
func bulkRuntimeCloseError(err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user