github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/structs/memorystructs.go (about)

     1  /*
     2  Copyright 2023.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package structs
    18  
    19  import "sync/atomic"
    20  
    21  type AllSegStoreSummary struct {
    22  	TotalSegmentCount                  uint64
    23  	TotalMetricsSegmentCount           uint64
    24  	TotalTableCount                    uint64
    25  	InMemoryCMICount                   uint64
    26  	InMemorySearchMetadataCount        uint64
    27  	InMemoryBlockMicroIndexSizeMB      uint64
    28  	InMemorySsmSizeMB                  uint64
    29  	InMemoryMetricsSearchMetadataCount uint64
    30  	InMemoryMetricsBSumSizeMB          uint64
    31  }
    32  
    33  type MemoryTracker struct {
    34  	TotalAllocatableBytes     uint64 // total bytes that can be allocated. This should not include CmiRuntimeAllocatedBytes
    35  	CmiInMemoryAllocatedBytes uint64
    36  	CmiRuntimeAllocatedBytes  uint64
    37  	SegSearchRequestedBytes   uint64
    38  	SegWriterUsageBytes       uint64
    39  	SegStoreSummary           *AllSegStoreSummary
    40  	SsmInMemoryAllocatedBytes uint64
    41  	MetricsSegmentMaxSize     uint64
    42  }
    43  
    44  func (sum *AllSegStoreSummary) IncrementTotalSegmentCount() {
    45  	atomic.AddUint64(&sum.TotalSegmentCount, 1)
    46  }
    47  
    48  func (sum *AllSegStoreSummary) SetInMemoryBlockMicroIndexCount(count uint64) {
    49  	atomic.StoreUint64(&sum.InMemoryCMICount, count)
    50  }
    51  
    52  func (sum *AllSegStoreSummary) SetInMemorySearchmetadataCount(count uint64) {
    53  	atomic.StoreUint64(&sum.InMemorySearchMetadataCount, count)
    54  }
    55  
    56  func (sum *AllSegStoreSummary) SetInMemoryBlockMicroIndexSizeMB(size uint64) {
    57  	atomic.StoreUint64(&sum.InMemoryBlockMicroIndexSizeMB, size)
    58  }
    59  
    60  func (sum *AllSegStoreSummary) IncrementTotalTableCount() {
    61  	atomic.AddUint64(&sum.TotalTableCount, 1)
    62  }
    63  
    64  func (sum *AllSegStoreSummary) DecrementTotalTableCount() {
    65  	atomic.AddUint64(&sum.TotalTableCount, ^uint64(0))
    66  }
    67  
    68  func (sum *AllSegStoreSummary) DecrementTotalSegKeyCount() {
    69  	atomic.AddUint64(&sum.TotalSegmentCount, ^uint64(0))
    70  }
    71  
    72  func (sum *AllSegStoreSummary) SetInMemorySsmSizeMB(val uint64) {
    73  	atomic.StoreUint64(&sum.InMemorySsmSizeMB, val)
    74  }
    75  
    76  func (sum *AllSegStoreSummary) IncrementTotalMetricsSegmentCount() {
    77  	atomic.StoreUint64(&sum.TotalMetricsSegmentCount, 1)
    78  }
    79  
    80  func (sum *AllSegStoreSummary) SetInMemoryMetricsSearchmetadataCount(val uint64) {
    81  	atomic.StoreUint64(&sum.InMemoryMetricsSearchMetadataCount, val)
    82  }
    83  
    84  func (sum *AllSegStoreSummary) SetInMemoryMetricsSsmSizeMB(val uint64) {
    85  	atomic.StoreUint64(&sum.InMemoryMetricsBSumSizeMB, val)
    86  }
    87  
    88  func (sum *AllSegStoreSummary) DecrementTotalMetricsSegmentCount() {
    89  	if sum.TotalMetricsSegmentCount == 0 {
    90  		return
    91  	}
    92  	atomic.AddUint64(&sum.TotalMetricsSegmentCount, ^uint64(0))
    93  }