Skip to content

Commit c9012dd

Browse files
committed
quota: realtime usage update for metrics, logical/physical sizes, and data points
Without this patch, it is possible for some namespaces to have a window of 1-3 `carbonserver.quota-usage-report-frequency` to conduct quota enforcement penetration. However, this patch can still only enforce it for existing namespaces that has already being annotated by *trieIndex.applyQuotas. For new namespaces, the possibility still exists. A separate patch of approach is needed.
1 parent 1182c9c commit c9012dd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

carbonserver/trie.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ func (ti *trieIndex) insert(path string, logicalSize, physicalSize, dataPoints,
538538
var start, nlen int
539539
var sn, newn *trieNode
540540
var cur = ti.root
541+
var dirMetas = make([]trieMeta, 0, 32)
541542
outer:
542543
// why len(path)+1: make sure the last node is also processed in the loop
543544
for i := 0; i < len(path)+1; i++ {
@@ -649,6 +650,10 @@ outer:
649650
if child.dir() {
650651
cur = child
651652
cur.gen = ti.root.gen
653+
654+
if child.meta != nil {
655+
dirMetas = append(dirMetas, child.meta)
656+
}
652657
continue outer
653658
}
654659
}
@@ -720,7 +725,20 @@ outer:
720725
cur.addChild(child)
721726
cur = child
722727

728+
// TODO: need to support realtime and concurrent index?
723729
ti.fileCount++
730+
731+
for _, dm := range dirMetas {
732+
meta, ok := dm.(*dirMeta)
733+
if !ok || meta.usage == nil {
734+
continue
735+
}
736+
737+
atomic.AddInt64(&meta.usage.Metrics, 1)
738+
atomic.AddInt64(&meta.usage.LogicalSize, logicalSize)
739+
atomic.AddInt64(&meta.usage.PhysicalSize, physicalSize)
740+
atomic.AddInt64(&meta.usage.DataPoints, dataPoints)
741+
}
724742
}
725743

726744
return cur, nil

0 commit comments

Comments
 (0)