This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new f37afa829dd Fixed listEvents intermittent exception: (#9661)
f37afa829dd is described below
commit f37afa829dd6cddb64d028bf3d36106ff3955447
Author: mprokopchuk <[email protected]>
AuthorDate: Tue Sep 17 03:07:10 2024 -0700
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_vie [...]
---
server/src/main/java/com/cloud/api/query/QueryManagerImpl.java | 10 ++++++++--
server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java | 4 ++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index f4c9b19c192..4063cfe7a18 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -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);
diff --git a/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
b/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
index f51df27a741..b4316051e43 100644
--- a/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
@@ -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);