1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
batchbuf.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
package memqueue
import "github.com/elastic/beats/libbeat/publisher"
type batchBuffer struct {
next *batchBuffer
flushed bool
events []publisher.Event
clients []clientState
}
func newBatchBuffer(sz int) *batchBuffer {
b := &batchBuffer{}
b.init(sz)
return b
}
func (b *batchBuffer) init(sz int) {
b.events = make([]publisher.Event, 0, sz)
b.clients = make([]clientState, 0, sz)
}
func (b *batchBuffer) initWith(sz int, old batchBuffer) {
events, clients := old.events, old.clients
L := len(events)
b.events = make([]publisher.Event, L, sz)
b.clients = make([]clientState, L, sz)
copy(b.events, events)
copy(b.clients, clients)
}
func (b *batchBuffer) add(event publisher.Event, st clientState) {
b.events = append(b.events, event)
b.clients = append(b.clients, st)
}
func (b *batchBuffer) length() int {
return len(b.events)
}
func (b *batchBuffer) capacity() int {
return cap(b.events)
}
func (b *batchBuffer) cancel(st *produceState) int {
events := b.events[:0]
clients := b.clients[:0]
removed := 0
for i := range b.clients {
if b.clients[i].state == st {
removed++
continue
}
events = append(events, b.events[i])
clients = append(clients, b.clients[i])
}
b.events = events
b.clients = clients
return removed
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.0.0-rc2

搜索帮助

0d507c66 1850385 C8b1a773 1850385