github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/memstore/common/host_memory_manager.go (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package common
    16  
    17  // HostMemoryManager manages archive batch storage in host memory.
    18  // Specifically, it keeps track of memory usage of archive batches and makes
    19  // preloading and eviction decisions based on retention config.
    20  //
    21  // The space available to archive batches is defined as maxMem - unmanagedMem,
    22  // where unmanagedMem accounts for C allocated buffers in live batches and
    23  // primary keys, which changes over time.
    24  // Eviction of archive batches is configured at column level using two configs:
    25  // preloadingDays and priorities.
    26  //
    27  // Data eviction policy is defined as such:
    28  // Always evict data not in preloading zone first; Preloading data won’t be
    29  // evicted until all the non-preloading data are evicted and server is still
    30  // in short of memory.
    31  // For data within the same zone, eviction will happen based on column priority
    32  // For data with same priority, eviction will happen based on data time,
    33  // older data will be evicted first, for same old data, larger size columns
    34  // will be evicted first;
    35  //
    36  // HostMemoryManger will also maintain two go routines. One for preloading data
    37  // and another for eviction. Calling start to start those goroutines and call
    38  // stop to stop them. Stop is a blocking call.
    39  //
    40  // Both TriggerPreload and TriggerEviction are asynchronous calls.
    41  type HostMemoryManager interface {
    42  	ReportUnmanagedSpaceUsageChange(bytes int64)
    43  	ReportManagedObject(table string, shard, batchID, columnID int, bytes int64)
    44  	GetArchiveMemoryUsageByTableShard() (map[string]map[string]*ColumnMemoryUsage, error)
    45  	TriggerEviction()
    46  	TriggerPreload(tableName string, columnID int,
    47  		oldPreloadingDays int, newPreloadingDays int)
    48  	Start()
    49  	Stop()
    50  }
    51  
    52  // ColumnMemoryUsage contains column memory usage
    53  type ColumnMemoryUsage struct {
    54  	Preloaded    uint `json:"preloaded"`
    55  	NonPreloaded uint `json:"nonPreloaded"`
    56  	Live         uint `json:"live"`
    57  }