Skip to content
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

[LEDGER] merge queryHelper with the queryExecutor #1097

Merged

Conversation

cendhu
Copy link
Contributor

@cendhu cendhu commented Apr 15, 2020

Type of change

  • Improvement (improvement to code)

Description

In the lockbasedtxmgr package, we have a lockBasedQueryExecutor and a lockBasedTxSimulator struct. The lockBasedTxSimulator implements mainly SetXXX() APIs while the lockBasedQueryExecutor implements GetXXX() APIs. As the transaction simulation also involves query, the lockBasedTxSimulator encapsulate lockBasedQueryExecutor.

Only in the lockBasedTxSimulator, we collect readSet while using GetXXX() and writeSet while using SetXXX(). However, when we use lockBasedQueryExecutor alone, we don't collect readSet.

Currently, we have an unnecessary indirection with QueryHelper and it makes code readability a bit hard. Hence, we merge the QueryHelper with the lockBasedQueryExecutor itself.

Further, due to stutters, we rename
lockBasedTxSimulator => txSimulator
lockBasedQueryExecutor => queryExecutor
lockbased_query_executor.go => query_executor.go
lockbased_tx_simulator.go => tx_simulator.go

Additional details

Note that NewQueryExecutor() and NewTxSimulator() return interface rather than a struct. It will be fixed when we remove the TxMgr interface.

Related issues

FAB-17760

@cendhu cendhu requested a review from a team as a code owner April 15, 2020 14:12
Copy link
Contributor

@manish-sethi manish-sethi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except one comment about making the structs exported type.

On this side, I would also like to suggest that the reviews would be easier if you can make changes in stages. For instance, in this PR, you moved functions around at the same time which redendered whole diff. Changes in this PR could be split into three

  1. Removal of queryexector + renaming the helper
  2. Merging of unexported and exported functions, where applicable
  3. Moving functions around
  4. introduce flag instead of checking rwsetBuilder != nil

type lockBasedTxSimulator struct {
lockBasedQueryExecutor
// TxSimulator is a transaction simulator used in `LockBasedTxMgr`
type TxSimulator struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you made this exported. This should not be constructed outside this package. Same comment about QueryExecutor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexported struct implementing an exported function looks weird. Some discussion on this happened in #1094 Hence, I exported the struct.

Btw, the initial goal was to first merge #1094, second merge #1095, and finally make the following change in this PR as mentioned in the PR description. NewTxSimulation() and NewQueryExecutor() to return the struct instead of an interface as it is a widely suggested way when there is a single implementation for an interface. Now, the above-mentioned change will be done once the post-order tx execution is moved from validator to the lockbasedtxmgr and the TxMgr interface is removed.

@cendhu
Copy link
Contributor Author

cendhu commented Apr 17, 2020

On this side, I would also like to suggest that the reviews would be easier if you can make changes in stages. For instance, in this PR, you moved functions around at the same time which redendered whole diff. Changes in this PR could be split into three

Removal of queryexector + renaming the helper
Merging of unexported and exported functions, where applicable
Moving functions around
introduce flag instead of checking rwsetBuilder != nil

Sure. Going forward, I will push the stacked commits. It is helpful for the review and also to not waste time on fixing conflicts.

@cendhu cendhu requested a review from manish-sethi April 17, 2020 12:02
cendhu added 2 commits April 18, 2020 10:53
In lockbasedtxmgr, we have a lockBasedQueryExecutor and a
lockBasedTxSimulator struct. The lockBasedTxSimulator implements
mainly SetXXX() APIs while lockBasedQueryExecutor implements GetXXX()
APIs. As the transaction simulation also involves query, the
lockBasedTxSimulator encapsulate lockBasedQueryExecutor. Only in
the lockBasedTxSimulator, we collect readSet while using GetXXX()
and writeSet while using SetXXX(). However, when we use
lockBasedQueryExecutor alone, we don't collect readSet.

Currently, we have an unnecessary indirection with QueryHelper
and it makes code readability a bit hard. Hence, we merge
the QueryHelper with the lockBasedQueryExecutor itself
and do some renaming of files/structs too.

Signed-off-by: senthil <cendhu@gmail.com>
Signed-off-by: senthil <cendhu@gmail.com>
@cendhu cendhu force-pushed the merge-queryHelper-with-queryExecutor branch from 3d55670 to 802e617 Compare April 18, 2020 05:43
@cendhu
Copy link
Contributor Author

cendhu commented Apr 18, 2020

Fixed conflicts and review comments.

@manish-sethi manish-sethi merged commit 9ccf752 into hyperledger:master Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants