Added code to prevent deletion of active fn pod (#1724)

Co-authored-by: Vishal <vishal-biyani@users.noreply.github.com>
This commit is contained in:
Rahul Bhati
2020-09-28 14:09:55 +05:30
committed by GitHub
co-authored by Vishal
parent ef65602b79
commit c605d1d2c6
3 changed files with 16 additions and 10 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ func (fsc *FunctionServiceCache) service() {
} }
fsc.logger.Info("function service cache", zap.Int("item_count", len(funcCopy)), zap.Strings("cache", info)) fsc.logger.Info("function service cache", zap.Int("item_count", len(funcCopy)), zap.Strings("cache", info))
case LISTOLDPOOL: case LISTOLDPOOL:
fscs := fsc.connFunctionCache.ListValue() fscs := fsc.connFunctionCache.ListAvailableValue()
funcObjects := make([]*FuncSvc, 0) funcObjects := make([]*FuncSvc, 0)
for _, funcSvc := range fscs { for _, funcSvc := range fscs {
fsvc := funcSvc.(*FuncSvc) fsvc := funcSvc.(*FuncSvc)
+8 -6
View File
@@ -28,7 +28,7 @@ type requestType int
const ( const (
getValue requestType = iota getValue requestType = iota
listValue listAvailableValue
getTotalAvailable getTotalAvailable
setValue setValue
markAvailable markAvailable
@@ -99,11 +99,13 @@ func (c *Cache) service() {
resp.error = ferror.MakeError(ferror.ErrorNotFound, fmt.Sprintf("funtion '%v' No inactive function found", req.function)) resp.error = ferror.MakeError(ferror.ErrorNotFound, fmt.Sprintf("funtion '%v' No inactive function found", req.function))
} }
req.responseChannel <- resp req.responseChannel <- resp
case listValue: case listAvailableValue:
vals := make([]interface{}, 0) vals := make([]interface{}, 0)
for _, values := range c.cache { for _, values := range c.cache {
for _, value := range values { for _, value := range values {
vals = append(vals, value.val) if !value.isActive {
vals = append(vals, value.val)
}
} }
} }
resp.allValues = vals resp.allValues = vals
@@ -159,11 +161,11 @@ func (c *Cache) GetValue(function interface{}) (interface{}, error) {
return resp.value, resp.error return resp.value, resp.error
} }
// ListValue returns a list of the function services stored in the Cache // ListAvailableValue returns a list of the available function services stored in the Cache
func (c *Cache) ListValue() []interface{} { func (c *Cache) ListAvailableValue() []interface{} {
respChannel := make(chan *response) respChannel := make(chan *response)
c.requestChannel <- &request{ c.requestChannel <- &request{
requestType: listValue, requestType: listAvailableValue,
responseChannel: respChannel, responseChannel: respChannel,
} }
resp := <-respChannel resp := <-respChannel
+7 -3
View File
@@ -21,9 +21,9 @@ func TestPoolCache(t *testing.T) {
c.SetValue("func2", "ip22", "value22") c.SetValue("func2", "ip22", "value22")
cc := c.ListValue() cc := c.ListAvailableValue()
if len(cc) != 3 { if len(cc) != 0 {
log.Panicf("expected 2 items") log.Panicf("expected 0 available items")
} }
active := c.GetTotalAvailable("func2") active := c.GetTotalAvailable("func2")
if active != 2 { if active != 2 {
@@ -33,7 +33,11 @@ func TestPoolCache(t *testing.T) {
c.DeleteValue("func2", "ip2") c.DeleteValue("func2", "ip2")
c.MarkAvailable("func", "ip") c.MarkAvailable("func", "ip")
cc = c.ListAvailableValue()
if len(cc) != 1 {
log.Panic("expected 1 available items, received", len(cc))
}
_, err := c.GetValue("func") _, err := c.GetValue("func")
checkErr(err) checkErr(err)