Fixed listEvents intermittent exception: (#9661)

com.mysql.cj.jdbc.ClientPreparedStatement: SELECT event_view.id, event_view.uuid, event_view.type, event_view.state, event_view.description, event_view.created, event_view.user_id, event_view.user_name, event_view.level, event_view.start_id, event_view.start_uuid, event_view.parameters, event_view.account_id, event_view.account_uuid, event_view.account_name, event_view.account_type, event_view.domain_id, event_view.domain_uuid, event_view.domain_name, event_view.domain_path, event_view.resource_id, event_view.resource_type, event_view.project_id, event_view.project_uuid, event_view.project_name, event_view.archived, event_view.display FROM event_view WHERE event_view.id IN )
This commit is contained in:
mprokopchuk 2024-09-17 03:07:10 -07:00 committed by GitHub
parent a88967bf61
commit f37afa829d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -818,8 +818,14 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Integer count = eventIdPage.second();
Long[] idArray = eventIdPage.first().toArray(new Long[0]);
if (count == 0) {
return new Pair<>(new ArrayList<>(), count);
/**
* Need to check array empty, because {@link com.cloud.utils.db.GenericDaoBase#searchAndCount(SearchCriteria, Filter, boolean)}
* makes two calls: first to get objects and second to get count.
* List events has start date filter, there is highly possible cause where no objects loaded
* and next millisecond new event added and finally we ended up with count = 1 and no ids.
*/
if (count == 0 || idArray.length < 1) {
count = 0;
}
List<EventJoinVO> events = _eventJoinDao.searchByIds(idArray);

View File

@ -131,6 +131,10 @@ public class EventJoinDaoImpl extends GenericDaoBase<EventJoinVO, Long> implemen
@Override
public List<EventJoinVO> searchByIds(Long... ids) {
// return empty collection if there are no ids.
if (ids.length == 0) {
return List.of();
}
SearchCriteria<EventJoinVO> sc = vrSearch.create();
sc.setParameters("idIN", ids);
return searchIncludingRemoved(sc, null, null, false);