localcache

package
v0.0.0-...-72af66c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0, BSD-2-Clause Imports: 32 Imported by: 0

Documentation

Overview

Package localcache provides local cache

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConcurrentLimit

func CreateConcurrentLimit(n *node.Node) (num int64)

func DecrNodeConcurrent

func DecrNodeConcurrent(n *node.Node) error

func DeleteInstanceInfoMap

func DeleteInstanceInfoMap(ctx context.Context, insID string) error

func DeleteNodeMetric

func DeleteNodeMetric(ctx context.Context, nodeID string) error

DeleteNodeMetric removes both current and legacy metric keys for a retired node. Cache eviction remains correct if Redis is temporarily unavailable, so callers may log this error after the database transaction has committed.

func DeleteSandboxCache

func DeleteSandboxCache(sandboxID string)

func DeleteSandboxProxyMap

func DeleteSandboxProxyMap(ctx context.Context, sandboxID string) error

func DeleteTemplateImageJobPullProgress

func DeleteTemplateImageJobPullProgress(ctx context.Context, jobID string) error

func DeregisterTemplateReplica

func DeregisterTemplateReplica(templateID, nodeID string)

func EvictNode

func EvictNode(nodeID string)

EvictNode synchronously removes every scheduler-local view owned by nodeID. It is used after a node deletion commits and by metadata reloads on replicas that observe the deleted registration later.

func GetCacheItems

func GetCacheItems() map[string]cache.Item

func GetDescribeTask

func GetDescribeTask(ctx context.Context, taskID string) (*types.DescribeTaskMap, bool)

func GetHealthyNodes

func GetHealthyNodes(n int) node.NodeList

func GetHealthyNodesByInstanceType

func GetHealthyNodesByInstanceType(n int, product string) node.NodeList

func GetImageStateByNode

func GetImageStateByNode(imageName string, nodeName string) *fwk.ImageStateSummary

func GetInstanceInfoMap

func GetInstanceInfoMap(ctx context.Context, insID string) (*types.InstanceInfoMap, bool)

func GetNode

func GetNode(id string) (*node.Node, bool)

func GetNodes

func GetNodes(n int) node.NodeList

func GetNodesByIp

func GetNodesByIp(ip string) (*node.Node, bool)

func GetSandboxProxyMap

func GetSandboxProxyMap(ctx context.Context, sandboxID string) (*types.SandboxProxyMap, bool)

func GetSchedulableNodesByInstanceType

func GetSchedulableNodesByInstanceType(n int, product string) node.NodeList

GetSchedulableNodesByInstanceType returns healthy nodes that may receive new sandboxes. Cordon filtering happens before limit n so isolated nodes do not consume PreSelectNum. Healthy-but-isolated nodes remain in GetHealthyNodes*.

func GetTemplateImageJobPullProgress

func GetTemplateImageJobPullProgress(ctx context.Context, jobID string) (*types.TemplateImageJobPullProgressMap, bool)

func HealthyMasterNodes

func HealthyMasterNodes() (num int64)

func IncrNodeConcurrent

func IncrNodeConcurrent(n *node.Node) error

func Init

func Init(ctx context.Context) error

func InvalidateImageState

func InvalidateImageState(imageName string)

func IsSnapshotStorageWriteAllowed

func IsSnapshotStorageWriteAllowed(mode string) bool

func ListKnownSandboxIDs

func ListKnownSandboxIDs() []string

func LoadImageScore

func LoadImageScore()

func LocalCreateConcurrentLimit

func LocalCreateConcurrentLimit(n *node.Node) (num int64)

func MaxMvmLimit

func MaxMvmLimit(n *node.Node) (num int64)

func NotifyEvent

func NotifyEvent(e *Event) error

func RangeDBHost

func RangeDBHost(index, size int, product string) ([]*node.Node, int)

func RealMaxMvmLimit

func RealMaxMvmLimit(n *node.Node) (num int64)

func RealTimeCreateConcurrentLimit

func RealTimeCreateConcurrentLimit(n *node.Node) (num int64)

func RegisterNodeLoader

func RegisterNodeLoader(loader func(context.Context) ([]*node.Node, error))

func RegisterTemplateReplica

func RegisterTemplateReplica(templateID, nodeID string, sizeBytes int64)

func ResetSnapshotStorageStateCacheForTest

func ResetSnapshotStorageStateCacheForTest()

ResetSnapshotStorageStateCacheForTest clears the in-process snapshot storage state cache. It is exported solely so cross-package tests (for example, templatecenter) can isolate cache state between cases. Production code MUST NOT call this.

func SetDescribeTask

func SetDescribeTask(ctx context.Context, taskInfo *types.DescribeTaskMap) error

func SetInstanceInfoField

func SetInstanceInfoField(ctx context.Context, insID string, kv ...string) error

func SetInstanceInfoMap

func SetInstanceInfoMap(ctx context.Context, insInfo *types.InstanceInfoMap) error

func SetSandboxCache

func SetSandboxCache(sandboxID string, cache *SandboxCache)

func SetSandboxProxyMap

func SetSandboxProxyMap(ctx context.Context, proxyInfo *types.SandboxProxyMap) error

func SetSnapshotStorageState

func SetSnapshotStorageState(state SnapshotStorageState)

func SetTemplateImageJobPullProgress

func SetTemplateImageJobPullProgress(ctx context.Context, progress *types.TemplateImageJobPullProgressMap) error

func SetTemplateImageJobPullProgressNoTTL

func SetTemplateImageJobPullProgressNoTTL(ctx context.Context, progress *types.TemplateImageJobPullProgressMap) error

func SyncNodeTemplates

func SyncNodeTemplates(nodeID string, templateIDs []string)

func UpdateNodeMetricInProcess

func UpdateNodeMetricInProcess(m *NodeMetric) error

UpdateNodeMetricInProcess pushes a metric directly into the receiving cubemaster's local cache so scheduling on this replica does not have to wait for the next Redis tick. Only the groups marked present on the NodeMetric (HasAllocated / HasDisk) are written; other fields keep whatever value the previous Redis tick or heartbeat installed, which preserves the partial-update semantics the Redis writer relies on.

Returns an error if the node is unknown to this replica (which is normal during cold start and will self-heal when reload syncs the registration table).

func UpsertNode

func UpsertNode(n *node.Node)

func WriteNodeMetric

func WriteNodeMetric(ctx context.Context, m *NodeMetric) error

WriteNodeMetric persists a cubelet-reported metric snapshot to Redis so all cubemaster replicas converge on the same view through their existing loopUpdateMetric tick. We deliberately overwrite update_at with the server-side timestamp passed in (which the heartbeat handler clamps to time.Now()) so clock skew on individual cubelets cannot push entries past or stall the MetricUpdateTimeout filter.

Types

type Event

type Event struct {
	Type   EventType
	InsIDs []string
}

type EventType

type EventType string
const (
	ADD    EventType = "add"
	DEL    EventType = "del"
	UPDATE EventType = "update"
	DOWN   EventType = "down"
)

type NodeMetric

type NodeMetric struct {
	NodeID     string
	MetricTime time.Time

	HasAllocated  bool
	MilliCPUUsage int64
	MemoryMBUsage int64
	MvmNum        int64
	NicQueues     int64

	HasDisk             bool
	DataDiskUsagePer    float64
	StorageDiskUsagePer float64
	SysDiskUsagePer     float64
}

NodeMetric is the in-API-process view of a cubelet's resource report. It is shared by the heartbeat handler and Redis fan-out so all paths agree on field semantics. All numeric fields use the same units as RedisNodeInfo (milli-cpu, MB, 0~100 percent) so cross-replica scheduling stays stable regardless of whether a master saw the cubelet directly or learned about it through Redis.

HasAllocated and HasDisk distinguish "cubelet reported zero" from "cubelet did not report this group". Without these flags an empty section in a heartbeat would clobber the previous valid values in Redis, because HSET cannot tell apart "set to zero" from "leave untouched". The two flags map 1:1 to the Allocated / DiskUsage sub structures on UpdateNodeStatusRequest, so a partial heartbeat (allocated-only, disk-only, or anything in between) round-trips without corrupting the other group's prior state.

type RedisNodeInfo

type RedisNodeInfo struct {
	InsID string `json:"InstanceID" redis:"ins_id"`

	QuotaCpuUsage int64 `json:"QuotaCpuUsage" redis:"quota_cpu_usage"`

	QuotaMemUsage int64 `json:"QuotaMemUsage" redis:"quota_mem_mb_usage"`

	CpuUtil float64 `json:"CpuUtil" redis:"cpu_util"`

	CpuLoadUsage float64 `json:"CpuLoadUsage" redis:"cpu_load_usage"`

	MemUsage int64 `json:"MemUsage" redis:"mem_load_mb_usage"`

	DataDiskUsagePer    float64 `json:"DataDiskUsagePer" redis:"data_disk_usage_per"`
	StorageDiskUsagePer float64 `json:"StorageDiskUsagePer" redis:"storage_disk_usage_per"`
	SysDiskUsagePer     float64 `json:"SysDiskUsagePer" redis:"sys_disk_usage_per"`

	MvmNum int64 `json:"mvm_num" redis:"mvm_num"`

	MetricUpdate string `json:"MetricUpdateAt" redis:"update_at"`

	RealTimeCreateNum int64 `json:"RealTimeCreateNum,omitempty" redis:"realtime_create_num"`

	NICQueues int64 `json:"nic_queues,omitempty" redis:"nic_queues"`
}

type SandboxCache

type SandboxCache struct {
	SandboxID string
	HostIP    string
}

func GetSandboxCache

func GetSandboxCache(sandboxID string) *SandboxCache

type SnapshotStorageState

type SnapshotStorageState struct {
	NodeID        string
	NodeIP        string
	UsagePct      uint64
	Mode          string
	LastError     string
	LastUpdatedAt int64
}

func GetSnapshotStorageState

func GetSnapshotStorageState(nodeID, nodeIP string) (SnapshotStorageState, bool)

func ListSnapshotStorageStates

func ListSnapshotStorageStates() []SnapshotStorageState

ListSnapshotStorageStates returns all currently cached snapshot storage states, deduplicated by (NodeID, NodeIP). It is intended for the snapshot reconciler to keep retrying nodes whose last refresh ended in failure even when the healthy-node list (backed by redis) is temporarily empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL