-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeVaultService._queryBy does not preserve requested order from Sort #7277
Comments
I see that Kotlin Sets preserve the order meaning that here the issue is not related to a mapping from List to Set, but to the fact that here: Most probably we have to do not invoke groupBy operation on an original Set. |
In summary, in NodeVaultService._queryBy() method, SQL Query results list elements are mapped to StateRefs and put in Set. Then the Set is used to populate List which is returned in a Vault.Page. This means that if we used any sort on a page, then this can be lost due to mapping to Set.
More simple example what is happening here is when we query vault we translate:
List->Set->List
and this is how we can loose the order.
Line in which problem occurs:
corda/node/src/main/kotlin/net/corda/node/services/vault/NodeVaultService.kt
Line 738 in 149ccdb
Code snippet:
Example case:
TradeState {
linearId: UUID,
status: String,
our_state: Boolean
}
SQL Query results:
AA0E62E56670A1D58A37434B1378424B02DD0AD284B4623FF0FEB2F0CA8C77F0(1)
C4566AEFCEF53AE98101D6AEEE9F82E05052A2F8A1B56BE793F39F91A5278568(1)
AA0E62E56670A1D58A37434B1378424B02DD0AD284B4623FF0FEB2F0CA8C77F0(0)
Vault.Page - StateAndRefs:
AA0E62E56670A1D58A37434B1378424B02DD0AD284B4623FF0FEB2F0CA8C77F0(1)
AA0E62E56670A1D58A37434B1378424B02DD0AD284B4623FF0FEB2F0CA8C77F0(0)
C4566AEFCEF53AE98101D6AEEE9F82E05052A2F8A1B56BE793F39F91A5278568(1)
2 last elements were swapped, which is wrong as SQL results were correctly sorted.
SQL query extracted from logs:
From the _queryBy logic it seems that sorting should work randomly, but in reality it works most of the time, except when in returned results there are states from the same transaction.
The text was updated successfully, but these errors were encountered: