Github user agneya2001 commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1240#discussion_r47481989 --- Diff: plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java --- @@ -186,7 +186,7 @@ public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { //check that there is at least one balance entry for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); - if (entry.getCreditsId() > 0) { + if (entry.getCreditsId() == 0) { --- End diff -- @DaanHoogland good that you are probing the logic. In a system where quota service has never run, there could be credit entries a admin may want to add some credit entries even before quota service has run. So at a point the db can have credit entries without any real balance entry. There could be a situation where there is a balance entry after several credit entries followed by another set of credit entries. When there is a balance entry it consolidates all the credit entries that happened before it. So when calculating balance you need to add all the credit entries that happened after a balance entry while ignoring all the credit entries that happened before the first balance entry. You till need to show all the credit entries that happened in between for the balance statement. When marvin tests were run the db was clean with only one credit entry. This was a special case where you add all the credit entries to show the final balance but you still need to show this credit entry in the balance statement. If quota service has run once it makes a 0 balance entry as part of bootstrapping. entry.getCreditsId() == 0, looks for real balance entry. A credit id that is non-zero refers to a credit entry with id being the credit id.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---