Skip to content

Commit

Permalink
quota: realtime usage update for metrics, logical/physical sizes, and…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
bom-d-van committed Jun 28, 2022
1 parent 1182c9c commit c9012dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions carbonserver/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ func (ti *trieIndex) insert(path string, logicalSize, physicalSize, dataPoints,
var start, nlen int
var sn, newn *trieNode
var cur = ti.root
var dirMetas = make([]trieMeta, 0, 32)
outer:
// why len(path)+1: make sure the last node is also processed in the loop
for i := 0; i < len(path)+1; i++ {
Expand Down Expand Up @@ -649,6 +650,10 @@ outer:
if child.dir() {
cur = child
cur.gen = ti.root.gen

if child.meta != nil {
dirMetas = append(dirMetas, child.meta)
}
continue outer
}
}
Expand Down Expand Up @@ -720,7 +725,20 @@ outer:
cur.addChild(child)
cur = child

// TODO: need to support realtime and concurrent index?
ti.fileCount++

for _, dm := range dirMetas {
meta, ok := dm.(*dirMeta)
if !ok || meta.usage == nil {
continue
}

atomic.AddInt64(&meta.usage.Metrics, 1)
atomic.AddInt64(&meta.usage.LogicalSize, logicalSize)
atomic.AddInt64(&meta.usage.PhysicalSize, physicalSize)
atomic.AddInt64(&meta.usage.DataPoints, dataPoints)
}
}

return cur, nil
Expand Down

0 comments on commit c9012dd

Please sign in to comment.