mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Update counting msg size
This commit is contained in:
parent
7e9839336c
commit
2ba07d2b11
3 changed files with 19 additions and 7 deletions
|
@ -15,9 +15,13 @@ type InnerHeadUpdate struct {
|
||||||
root *treechangeproto.RawTreeChangeWithId
|
root *treechangeproto.RawTreeChangeWithId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h InnerHeadUpdate) MsgSize() uint64 {
|
func (h InnerHeadUpdate) MsgSize() (size uint64) {
|
||||||
size := uint64(len(h.heads))
|
for _, head := range h.heads {
|
||||||
size += uint64(len(h.snapshotPath))
|
size += uint64(len(head))
|
||||||
|
}
|
||||||
|
for _, snapshotId := range h.snapshotPath {
|
||||||
|
size += uint64(len(snapshotId))
|
||||||
|
}
|
||||||
for _, change := range h.changes {
|
for _, change := range h.changes {
|
||||||
size += uint64(len(change.Id))
|
size += uint64(len(change.Id))
|
||||||
size += uint64(len(change.RawChange))
|
size += uint64(len(change.RawChange))
|
||||||
|
|
|
@ -73,8 +73,15 @@ func (m *syncMetric) UpdateQueueSize(size uint64, msgType int, add bool) {
|
||||||
atCount.Add(1)
|
atCount.Add(1)
|
||||||
m.totalSize.Add(intSize)
|
m.totalSize.Add(intSize)
|
||||||
} else {
|
} else {
|
||||||
atSize.Add(-intSize)
|
curCount := atCount.Load()
|
||||||
|
curSize := atSize.Load()
|
||||||
|
if curCount != 0 {
|
||||||
atCount.Add(-1)
|
atCount.Add(-1)
|
||||||
|
}
|
||||||
|
// TODO: fix the root cause :-)
|
||||||
|
if curSize > intSize {
|
||||||
|
atSize.Add(-intSize)
|
||||||
m.totalSize.Add(-intSize)
|
m.totalSize.Add(-intSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -71,11 +71,12 @@ func (m *multiQueue[T]) Add(ctx context.Context, threadId string, msg T) (err er
|
||||||
q = m.startThread(threadId)
|
q = m.startThread(threadId)
|
||||||
}
|
}
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
|
m.updateSize(msg, true)
|
||||||
err = q.TryAdd(msg)
|
err = q.TryAdd(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.updateSize(msg, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.updateSize(msg, true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue