ListLongerThanWithQueryCount filters the active running queries against the given duration and the index name along with the total active query count. TODO - Incoming queries shouldn't get blocked due to lock deprivations from the frequent read operations.
(longerThan time.Duration, indexName string)
| 131 | // TODO - Incoming queries shouldn't get blocked due to lock deprivations |
| 132 | // from the frequent read operations. |
| 133 | func (qs *QuerySupervisor) ListLongerThanWithQueryCount(longerThan time.Duration, |
| 134 | indexName string) (queryMap map[uint64]*RunningQueryDetails, activeQueryCount int) { |
| 135 | var i int |
| 136 | qs.m.RLock() |
| 137 | // upfront initialisations to save frequent allocator trips. |
| 138 | queryMap = make(map[uint64]*RunningQueryDetails, len(qs.queryMap)) |
| 139 | pool := make([]RunningQueryDetails, len(qs.queryMap)) |
| 140 | |
| 141 | for key, val := range qs.queryMap { |
| 142 | timeSince := time.Since(val.addedAt) |
| 143 | if timeSince > longerThan && |
| 144 | (indexName == "" || indexName == val.IndexName) { |
| 145 | pool[i].QueryContext = val |
| 146 | pool[i].ExecutionTime = fmt.Sprintf("%s", timeSince) |
| 147 | queryMap[key] = &pool[i] |
| 148 | i++ |
| 149 | } |
| 150 | } |
| 151 | activeQueryCount = len(qs.queryMap) |
| 152 | qs.m.RUnlock() |
| 153 | |
| 154 | return queryMap, activeQueryCount |
| 155 | } |
| 156 | |
| 157 | func (qs *QuerySupervisor) ExecutionTime(id uint64) (time.Duration, bool) { |
| 158 | qs.m.RLock() |
no outgoing calls