Fixed golangci-lint issues: /fission/pkg/executor (#1842)
This commit is contained in:
@@ -37,6 +37,7 @@ type fscRequestType int
|
||||
|
||||
//type executorType int
|
||||
|
||||
// FunctionServiceCache Request Types
|
||||
const (
|
||||
TOUCH fscRequestType = iota
|
||||
LISTOLD
|
||||
@@ -45,6 +46,7 @@ const (
|
||||
)
|
||||
|
||||
type (
|
||||
// FuncSvc represents a function service
|
||||
FuncSvc struct {
|
||||
Name string // Name of object
|
||||
Function *metav1.ObjectMeta // function this pod/service is for
|
||||
@@ -57,6 +59,7 @@ type (
|
||||
Atime time.Time
|
||||
}
|
||||
|
||||
// FunctionServiceCache represents the function service cache
|
||||
FunctionServiceCache struct {
|
||||
logger *zap.Logger
|
||||
byFunction *cache.Cache // function-key -> funcSvc : map[string]*funcSvc
|
||||
@@ -66,18 +69,21 @@ type (
|
||||
|
||||
requestChannel chan *fscRequest
|
||||
}
|
||||
|
||||
fscRequest struct {
|
||||
requestType fscRequestType
|
||||
address string
|
||||
age time.Duration
|
||||
responseChannel chan *fscResponse
|
||||
}
|
||||
|
||||
fscResponse struct {
|
||||
objects []*FuncSvc
|
||||
error
|
||||
}
|
||||
)
|
||||
|
||||
// IsNotFoundError checks if err is ErrorNotFound.
|
||||
func IsNotFoundError(err error) bool {
|
||||
if fe, ok := err.(ferror.Error); ok {
|
||||
return fe.Code == ferror.ErrorNotFound
|
||||
@@ -85,6 +91,7 @@ func IsNotFoundError(err error) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsNameExistError checks if err is ErrorNameExists.
|
||||
func IsNameExistError(err error) bool {
|
||||
if fe, ok := err.(ferror.Error); ok {
|
||||
return fe.Code == ferror.ErrorNameExists
|
||||
@@ -92,6 +99,7 @@ func IsNameExistError(err error) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// MakeFunctionServiceCache starts and returns an instance of FunctionServiceCache.
|
||||
func MakeFunctionServiceCache(logger *zap.Logger) *FunctionServiceCache {
|
||||
fsc := &FunctionServiceCache{
|
||||
logger: logger.Named("function_service_cache"),
|
||||
@@ -151,6 +159,7 @@ func (fsc *FunctionServiceCache) service() {
|
||||
}
|
||||
}
|
||||
|
||||
// GetByFunction gets a function service from cache using function key.
|
||||
func (fsc *FunctionServiceCache) GetByFunction(m *metav1.ObjectMeta) (*FuncSvc, error) {
|
||||
key := crd.CacheKey(m)
|
||||
|
||||
@@ -167,6 +176,7 @@ func (fsc *FunctionServiceCache) GetByFunction(m *metav1.ObjectMeta) (*FuncSvc,
|
||||
return &fsvcCopy, nil
|
||||
}
|
||||
|
||||
// GetFuncSvc gets a function service from pool cache using function key.
|
||||
func (fsc *FunctionServiceCache) GetFuncSvc(m *metav1.ObjectMeta) (*FuncSvc, error) {
|
||||
key := crd.CacheKey(m)
|
||||
|
||||
@@ -184,6 +194,7 @@ func (fsc *FunctionServiceCache) GetFuncSvc(m *metav1.ObjectMeta) (*FuncSvc, err
|
||||
return &fsvcCopy, nil
|
||||
}
|
||||
|
||||
// GetByFunctionUID gets a function service from cache using function UUID.
|
||||
func (fsc *FunctionServiceCache) GetByFunctionUID(uid types.UID) (*FuncSvc, error) {
|
||||
mI, err := fsc.byFunctionUID.Get(uid)
|
||||
if err != nil {
|
||||
@@ -205,6 +216,7 @@ func (fsc *FunctionServiceCache) GetByFunctionUID(uid types.UID) (*FuncSvc, erro
|
||||
return &fsvcCopy, nil
|
||||
}
|
||||
|
||||
// AddFunc adds a function service to pool cache.
|
||||
func (fsc *FunctionServiceCache) AddFunc(fsvc FuncSvc) {
|
||||
fsc.connFunctionCache.SetValue(crd.CacheKey(fsvc.Function), fsvc.Address, &fsvc)
|
||||
now := time.Now()
|
||||
@@ -214,14 +226,17 @@ func (fsc *FunctionServiceCache) AddFunc(fsvc FuncSvc) {
|
||||
fsc.setFuncAlive(fsvc.Function.Name, string(fsvc.Function.UID), true)
|
||||
}
|
||||
|
||||
// GetTotalAvailable returns the total number active function services.
|
||||
func (fsc *FunctionServiceCache) GetTotalAvailable(m *metav1.ObjectMeta) int {
|
||||
return fsc.connFunctionCache.GetTotalAvailable(crd.CacheKey(m))
|
||||
}
|
||||
|
||||
// MarkAvailable marks the value at key [function][address] as available.
|
||||
func (fsc *FunctionServiceCache) MarkAvailable(key string, svcHost string) {
|
||||
fsc.connFunctionCache.MarkAvailable(key, svcHost)
|
||||
}
|
||||
|
||||
// Add adds a function service to cache if it does not exist already.
|
||||
func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
|
||||
existing, err := fsc.byFunction.Set(crd.CacheKey(fsvc.Function), &fsvc)
|
||||
if err != nil {
|
||||
@@ -268,6 +283,7 @@ func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TouchByAddress makes a TOUCH request to given address.
|
||||
func (fsc *FunctionServiceCache) TouchByAddress(address string) error {
|
||||
responseChannel := make(chan *fscResponse)
|
||||
fsc.requestChannel <- &fscRequest{
|
||||
@@ -294,20 +310,55 @@ func (fsc *FunctionServiceCache) _touchByAddress(address string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteEntry deletes a function service from cache.
|
||||
func (fsc *FunctionServiceCache) DeleteEntry(fsvc *FuncSvc) {
|
||||
fsc.byFunction.Delete(crd.CacheKey(fsvc.Function))
|
||||
fsc.byAddress.Delete(fsvc.Address)
|
||||
fsc.byFunctionUID.Delete(fsvc.Function.UID)
|
||||
msg := "error deleting function service"
|
||||
err := fsc.byFunction.Delete(crd.CacheKey(fsvc.Function))
|
||||
if err != nil {
|
||||
fsc.logger.Error(
|
||||
msg,
|
||||
zap.String("function", fsvc.Function.Name),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
err = fsc.byAddress.Delete(fsvc.Address)
|
||||
if err != nil {
|
||||
fsc.logger.Error(
|
||||
msg,
|
||||
zap.String("function", fsvc.Function.Name),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
err = fsc.byFunctionUID.Delete(fsvc.Function.UID)
|
||||
if err != nil {
|
||||
fsc.logger.Error(
|
||||
msg,
|
||||
zap.String("function", fsvc.Function.Name),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
fsc.observeFuncRunningTime(fsvc.Function.Name, string(fsvc.Function.UID), fsvc.Atime.Sub(fsvc.Ctime).Seconds())
|
||||
fsc.observeFuncAliveTime(fsvc.Function.Name, string(fsvc.Function.UID), time.Since(fsvc.Ctime).Seconds())
|
||||
fsc.setFuncAlive(fsvc.Function.Name, string(fsvc.Function.UID), false)
|
||||
}
|
||||
|
||||
// DeleteFunctionSvc deletes a function service at key composed of [function][address].
|
||||
func (fsc *FunctionServiceCache) DeleteFunctionSvc(fsvc *FuncSvc) {
|
||||
fsc.connFunctionCache.DeleteValue(crd.CacheKey(fsvc.Function), fsvc.Address)
|
||||
err := fsc.connFunctionCache.DeleteValue(crd.CacheKey(fsvc.Function), fsvc.Address)
|
||||
if err != nil {
|
||||
fsc.logger.Error(
|
||||
"error deleting function service",
|
||||
zap.Any("function", fsvc.Function.Name),
|
||||
zap.Any("address", fsvc.Address),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteOld deletes aged function service entries from cache.
|
||||
func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration) (bool, error) {
|
||||
if time.Since(fsvc.Atime) < minAge {
|
||||
return false, nil
|
||||
@@ -318,6 +369,7 @@ func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// DeleteOldPoolCache deletes aged function service entries from pool cache.
|
||||
func (fsc *FunctionServiceCache) DeleteOldPoolCache(fsvc *FuncSvc, minAge time.Duration) (bool, error) {
|
||||
if time.Since(fsvc.Atime) < minAge {
|
||||
return false, nil
|
||||
@@ -328,6 +380,7 @@ func (fsc *FunctionServiceCache) DeleteOldPoolCache(fsvc *FuncSvc, minAge time.D
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ListOld returns a list of aged function services in cache.
|
||||
func (fsc *FunctionServiceCache) ListOld(age time.Duration) ([]*FuncSvc, error) {
|
||||
responseChannel := make(chan *fscResponse)
|
||||
fsc.requestChannel <- &fscRequest{
|
||||
@@ -339,6 +392,7 @@ func (fsc *FunctionServiceCache) ListOld(age time.Duration) ([]*FuncSvc, error)
|
||||
return resp.objects, resp.error
|
||||
}
|
||||
|
||||
// ListOldForPool returns a list of aged function serices in cache for pooling.
|
||||
func (fsc *FunctionServiceCache) ListOldForPool(age time.Duration) ([]*FuncSvc, error) {
|
||||
responseChannel := make(chan *fscResponse)
|
||||
fsc.requestChannel <- &fscRequest{
|
||||
@@ -350,6 +404,7 @@ func (fsc *FunctionServiceCache) ListOldForPool(age time.Duration) ([]*FuncSvc,
|
||||
return resp.objects, resp.error
|
||||
}
|
||||
|
||||
// Log makes a LOG type cache request.
|
||||
func (fsc *FunctionServiceCache) Log() {
|
||||
fsc.logger.Info("--- FunctionService Cache Contents")
|
||||
responseChannel := make(chan *fscResponse)
|
||||
|
||||
Reference in New Issue
Block a user