* Add fixes for failure in specialization * reduce specialization in progress and remove expired requests from queue when specialization is timed out * rename markSpecializationFailure and remove logger from the queue * refactor clean up code in api.go and add test case for queue Details: - Cleanup svc waiting for the counter in the pool manager if specialization fails - Cleanup active requests counter in pool manager if client exists the demand for function service while we have allocated function service - Consider specialization timeout if pod ready timeout > specialization timeout in waiting for ready pod. We also consider if the request to choosePod is cancelled. - We ensure if we have requests waiting for service requests but if there is no pod in the specialization we clean up those. --------- Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> Co-authored-by: Pranoy Kundu <pranoy1998k@gmail.com>
71 lines
1.1 KiB
Go
71 lines
1.1 KiB
Go
package fscache
|
|
|
|
import (
|
|
"container/list"
|
|
"sync"
|
|
)
|
|
|
|
type Queue struct {
|
|
items *list.List
|
|
mutex sync.Mutex
|
|
}
|
|
|
|
func NewQueue() *Queue {
|
|
return &Queue{
|
|
items: list.New(),
|
|
}
|
|
}
|
|
|
|
func (q *Queue) Push(item *svcWait) {
|
|
q.mutex.Lock()
|
|
defer q.mutex.Unlock()
|
|
q.items.PushBack(item)
|
|
}
|
|
|
|
func (q *Queue) Pop() *svcWait {
|
|
q.mutex.Lock()
|
|
defer q.mutex.Unlock()
|
|
|
|
item := q.items.Front()
|
|
if item == nil {
|
|
return nil
|
|
}
|
|
q.items.Remove(item)
|
|
svcWait, ok := item.Value.(*svcWait)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return svcWait
|
|
}
|
|
|
|
func (q *Queue) Expired() int {
|
|
q.mutex.Lock()
|
|
defer q.mutex.Unlock()
|
|
|
|
expired := 0
|
|
svcExpired := []*list.Element{}
|
|
for item := q.items.Front(); item != nil; item = item.Next() {
|
|
svcWait, ok := item.Value.(*svcWait)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if svcWait.ctx.Err() != nil {
|
|
close(svcWait.svcChannel)
|
|
svcExpired = append(svcExpired, item)
|
|
expired = expired + 1
|
|
}
|
|
}
|
|
|
|
for _, item := range svcExpired {
|
|
q.items.Remove(item)
|
|
}
|
|
|
|
return expired
|
|
}
|
|
|
|
func (q *Queue) Len() int {
|
|
q.mutex.Lock()
|
|
defer q.mutex.Unlock()
|
|
return q.items.Len()
|
|
}
|