cloudstack-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLOUDSTACK-10320) Invalid pair for response object breaking response parsing
Date Mon, 19 Mar 2018 08:18:01 GMT

    [ https://issues.apache.org/jira/browse/CLOUDSTACK-10320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16404475#comment-16404475
] 

ASF GitHub Bot commented on CLOUDSTACK-10320:
---------------------------------------------

marcaurele commented on a change in pull request #2481: CLOUDSTACK-10320 - Invalid pair for
response object breaking response parsing
URL: https://github.com/apache/cloudstack/pull/2481#discussion_r175355297
 
 

 ##########
 File path: framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
 ##########
 @@ -1323,6 +1327,11 @@ protected void addJoins(StringBuilder str, Collection<JoinBuilder<SearchCriteria
     public Pair<List<T>, Integer> searchAndDistinctCount(final SearchCriteria<T>
sc, final Filter filter) {
         List<T> objects = search(sc, filter, null, false);
         Integer count = getDistinctCount(sc);
+        // Count cannot be 0 if there is at least a result in the list, see CLOUDSTACK-10320
+        if (count == 0 && !objects.isEmpty()) {
+            // Cannot assume if it's more than one since the count is distinct vs search
+            count = 1;
 
 Review comment:
   Because the search is mostly done against views which don't return distinct rows due to
the *not so smart* queries fetching the details rows. Look at the APIHelper with iterate on
duplicate row entries, but only append the details.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Invalid pair for response object breaking response parsing
> ----------------------------------------------------------
>
>                 Key: CLOUDSTACK-10320
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10320
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the default.) 
>          Components: API
>            Reporter: Marc-Aurèle Brothier
>            Assignee: Marc-Aurèle Brothier
>            Priority: Major
>
> Under some circumstances, the API is returning an invalid response, for simplicity I
will expose the JSON case. The API response on a listVirtualMachines can be this string:
> {code:java}
> { "listvirtualmachinesresponse" :  ] } }{code}
> To understand how this is possible, assume you have more than one management server and
one is processing the destroy of a virtual machine in the account X which is the only one
it has. Another process is returning the result of listVirtualMachines for that same account
X. During the listVM command, the result set is fetch with a searchAndDistinctCount due to
the view ([https://github.com/apache/cloudstack/blob/master/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1024).]
This is done through 2 queries in the GenericDao [https://github.com/apache/cloudstack/blob/master/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1323]
and if you encounter the _right_ conditions, the VM will be marked as removed in between those
2 queries. This results in having a Pair result with at least one object but a count of 0.
Then following how is done the serialization of the response at [https://github.com/apache/cloudstack/blob/master/server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java#L86]
you will reach the case where your output is the one previously mentioned.
> To overcome this issue, there isn't a true fix but only a better pair response to ensure
a correct response formatting. If the result set contains at least something, the count cannot
be 0 but we cannot guess the correct answer, but only state it has at least one element.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message