You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "sureshanaparti (via GitHub)" <gi...@apache.org> on 2026/02/05 14:04:46 UTC

[PR] Db filter with limit [cloudstack]

sureshanaparti opened a new pull request, #12598:
URL: https://github.com/apache/cloudstack/pull/12598

   ### Description
   
   This PR allows the limit queries without random ordering.
   
   <!--- Describe your changes in DETAIL - And how has behaviour functionally changed. -->
   
   <!-- For new features, provide link to FS, dev ML discussion etc. -->
   <!-- In case of bug fix, the expected and actual behaviours, steps to reproduce. -->
   
   <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged -->
   <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" -->
   <!-- Fixes: # -->
   
   <!--- ******************************************************************************* -->
   <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. -->
   <!--- PLEASE PUT AN 'X' in only **ONE** box -->
   <!--- ******************************************************************************* -->
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [x] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] Build/CI
   - [ ] Test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [x] Minor
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### Screenshots (if appropriate):
   
   ### How Has This Been Tested?
   
   <!-- Please describe in detail how you tested your changes. -->
   <!-- Include details of your testing environment, and the tests you ran to -->
   
   #### How did you try to break this feature and the system with this change?
   
   <!-- see how your change affects other areas of the code, etc. -->
   
   <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3876033987

   @sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on code in PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#discussion_r2769362933


##########
framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java:
##########
@@ -347,7 +347,7 @@ public List<T> lockRows(final SearchCriteria<T> sc, final Filter filter, final b
     @Override
     @DB()
     public T lockOneRandomRow(final SearchCriteria<T> sc, final boolean exclusive) {
-        final Filter filter = new Filter(1);
+        final Filter filter = new Filter(1, true);

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3854316108

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16714


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3853932008

   @sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3870799837

   > @sureshanaparti btw, I think that it may be good to change the usages of `Filter(long limit)` to `Filter(long limit, true)` for the sake of clarity, and either remove `Filter(long limit)` or change it to `this(limit, false)` to avoid unintended behavior in the future
   
   @winterhazel there are references with Filter(1) and random sorting doesn't make sense there, updated `Filter(long limit)` to call `this(limit, false)`.  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on code in PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#discussion_r2769574725


##########
framework/db/src/main/java/com/cloud/utils/db/Filter.java:
##########
@@ -57,8 +57,21 @@ public Filter(Class<?> clazz, String field, boolean ascending) {
     }
 
     public Filter(long limit) {
-        _orderBy = " ORDER BY RAND()";
-        _limit = limit;
+        this(limit, true);
+    }
+
+    /**
+     * Constructor for creating a filter with random ordering
+     * @param limit the maximum number of results to return
+     * @param randomize if true, orders results randomly
+     */
+    public Filter(long limit, boolean randomize) {
+        if (randomize) {
+            _orderBy = " ORDER BY RAND()" ;
+            _limit = limit;
+        } else {
+            _limit = limit;
+        }

Review Comment:
   ```suggestion
          _limit = limit;
           if (randomize) {
               _orderBy = " ORDER BY RAND()" ;
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3871177147

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16746


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3853993780

   > @sureshanaparti , what are we using this for? It is a framework level change without usage, I am really wondering.
   
   random sorting may not be required in all cases. It requires the use of a temporary table for the sort, which is taking more time for a simple lookup by name of a VM.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3881910364

   @nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3871189723

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16747


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3854212186

   @sureshanaparti btw, I think that it may be good to change the usages of `Filter(long limit)` to `Filter(long limit, true)` for the sake of clarity, and either remove it or change it to `this(limit, false)`  to avoid unintended behavior in the future


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3876026004

   @blueorangutan package


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3875372370

   > > > @sureshanaparti btw, I think that it may be good to change the usages of `Filter(long limit)` to `Filter(long limit, true)` for the sake of clarity, and either remove `Filter(long limit)` or change it to `this(limit, false)` to avoid unintended behavior in the future
   > > 
   > > 
   > > @winterhazel there are references with Filter(1) and random sorting doesn't make sense there, updated `Filter(long limit)` to call `this(limit, false)`.
   > 
   > @sureshanaparti the random sorting does make sense in `com.cloud.utils.db.GenericDaoBase#lockOneRandomRow`, `com.cloud.utils.db.GenericDaoBase#findOneIncludingRemovedBy`, `com.cloud.host.dao.HostDaoImpl#findAnyStateHypervisorHostInCluster`, and `org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl#findOneByZoneAndProtocol`. Could you update those to call `Filter(1, true)` to restore the previous behavior?
   
   oh sorry, correct. I'll check and update. thanks @winterhazel 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on code in PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#discussion_r2781797822


##########
framework/db/src/main/java/com/cloud/utils/db/Filter.java:
##########
@@ -57,8 +57,21 @@ public Filter(Class<?> clazz, String field, boolean ascending) {
     }
 
     public Filter(long limit) {
-        _orderBy = " ORDER BY RAND()";
-        _limit = limit;
+        this(limit, true);
+    }
+
+    /**
+     * Constructor for creating a filter with random ordering
+     * @param limit the maximum number of results to return
+     * @param randomize if true, orders results randomly
+     */
+    public Filter(long limit, boolean randomize) {
+        if (randomize) {
+            _orderBy = " ORDER BY RAND()" ;
+            _limit = limit;
+        } else {
+            _limit = limit;
+        }

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3870811015

   @sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3889518889

   > @winterhazel , are you ok with the current state? @sureshanaparti , can you make some test recommendations?
   
   @DaanHoogland smoke tests should be enough to cover the earlier random ordering cases, for filter with limit - remove the record of setting 'store.download.follow.redirects' from configuration table and restart MS (should have at least 1 zone) - check for the log "_Updating value for configuration: store.download.follow.redirects to true_". Enable trace to check the exact queries.
   
   https://github.com/apache/cloudstack/blob/34f6f413a1f8808919025f20e8d45525ae32f0d7/server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L476-L481


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland merged PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3853964932

   ## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/12598?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 4.15%. Comparing base ([`3d7d412`](https://app.codecov.io/gh/apache/cloudstack/commit/3d7d412d5bedf77c8994553562a1ba2c0c65cfbe?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`b57892b`](https://app.codecov.io/gh/apache/cloudstack/commit/b57892b73a9a8b828656fd516c0995fcfa468cfa?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   > :exclamation:  There is a different number of reports uploaded between BASE (3d7d412) and HEAD (b57892b). Click for more details.
   > 
   > <details><summary>HEAD has 1 upload less than BASE</summary>
   >
   >| Flag | BASE (3d7d412) | HEAD (b57892b) |
   >|------|------|------|
   >|unittests|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               4.20   #12598       +/-   ##
   =============================================
   - Coverage     16.26%    4.15%   -12.11%     
   =============================================
     Files          5661      404     -5257     
     Lines        500010    32965   -467045     
     Branches      60715     5893    -54822     
   =============================================
   - Hits          81331     1370    -79961     
   + Misses       409606    31419   -378187     
   + Partials       9073      176     -8897     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/12598/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/12598/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.15% <ø> (ø)` | |
   | [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/12598/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/cloudstack/pull/12598?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3870850515

   @sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3876330639

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16777


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3886128927

   <b>[SF] Trillian test result (tid-15432)</b>
   Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
   Total time taken: 50856 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12598-t15432-kvm-ol8.zip
   Smoke tests completed. 140 look OK, 1 have errors, 0 did not run
   Only failed and skipped tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_01_isolate_network_FW_PF_default_routes_egress_true | `Failure` | 95.50 | test_routers_network_ops.py
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on code in PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#discussion_r2769574725


##########
framework/db/src/main/java/com/cloud/utils/db/Filter.java:
##########
@@ -57,8 +57,21 @@ public Filter(Class<?> clazz, String field, boolean ascending) {
     }
 
     public Filter(long limit) {
-        _orderBy = " ORDER BY RAND()";
-        _limit = limit;
+        this(limit, true);
+    }
+
+    /**
+     * Constructor for creating a filter with random ordering
+     * @param limit the maximum number of results to return
+     * @param randomize if true, orders results randomly
+     */
+    public Filter(long limit, boolean randomize) {
+        if (randomize) {
+            _orderBy = " ORDER BY RAND()" ;
+            _limit = limit;
+        } else {
+            _limit = limit;
+        }

Review Comment:
   ```suggestion
           _limit = limit;
           if (randomize) {
               _orderBy = " ORDER BY RAND()" ;
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3876025173

   > > > > @sureshanaparti btw, I think that it may be good to change the usages of `Filter(long limit)` to `Filter(long limit, true)` for the sake of clarity, and either remove `Filter(long limit)` or change it to `this(limit, false)` to avoid unintended behavior in the future
   > > > 
   > > > 
   > > > @winterhazel there are references with Filter(1) and random sorting doesn't make sense there, updated `Filter(long limit)` to call `this(limit, false)`.
   > > 
   > > 
   > > @sureshanaparti the random sorting does make sense in `com.cloud.utils.db.GenericDaoBase#lockOneRandomRow`, `com.cloud.utils.db.GenericDaoBase#findOneIncludingRemovedBy`, `com.cloud.host.dao.HostDaoImpl#findAnyStateHypervisorHostInCluster`, and `org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl#findOneByZoneAndProtocol`. Could you update those to call `Filter(1, true)` to restore the previous behavior?
   > 
   > oh sorry, correct. I'll check and update. thanks @winterhazel
   
   updated @winterhazel 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3872615299

   > > @sureshanaparti btw, I think that it may be good to change the usages of `Filter(long limit)` to `Filter(long limit, true)` for the sake of clarity, and either remove `Filter(long limit)` or change it to `this(limit, false)` to avoid unintended behavior in the future
   > 
   > @winterhazel there are references with Filter(1) and random sorting doesn't make sense there, updated `Filter(long limit)` to call `this(limit, false)`.
   
   @sureshanaparti the random sorting does make sense in `com.cloud.utils.db.GenericDaoBase#lockOneRandomRow` and `com.cloud.utils.db.GenericDaoBase#findOneIncludingRemovedBy`, `com.cloud.host.dao.HostDaoImpl#findAnyStateHypervisorHostInCluster`, and `org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl#findOneByZoneAndProtocol`. Could you update those to call `Filter(1, true)` to restore the previous behavior?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3870845936

   @blueorangutan package


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3889203303

   @winterhazel , are you ok with the current state?
   @sureshanaparti , can you make some test recommendations?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "nvazquez (via GitHub)" <gi...@apache.org>.
nvazquez commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3881905248

   @blueorangutan test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "nvazquez (via GitHub)" <gi...@apache.org>.
nvazquez commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3881609004

   @blueorangutan test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3854176931

   > @sureshanaparti , what are we using this for? It is a framework level change without usage, I am really wondering.
   
   @DaanHoogland there are some usages for it. I used an alternative approach in https://github.com/apache/cloudstack/pull/12522/changes/02d8f18809db3a754c89ea80a711af4aab7af627 for batch expunge. That one line in `GenericDaoBase` may be changed to `filter = new Filter(batchSizeFinal, false);`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3854221227

   ok, guys, I see how it could have been useful for instance in @winterhazel ’s change. In this PR however it is not used at all. Are we planning to …?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3853938395

   @sureshanaparti , what are we using this for? It is a framework level change without usage, I am really wondering.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3853913963

   @blueorangutan package


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Allow limit queries without random ordering [cloudstack]

Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #12598:
URL: https://github.com/apache/cloudstack/pull/12598#issuecomment-3870805075

   @blueorangutan package


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org