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

Refactor write batching #143

Merged
merged 4 commits into from
Jan 18, 2025
Merged

Conversation

bestbeforetoday
Copy link
Member

Avoid holding transaction-specific state in the handler, which must then be protected by multiple locks. This is error prone and is a potential performance bottleneck. Instead, extract batch writes to a separate struct for clarity, and maintain the batch write state in the stub, which is unique to a specific transaction so requires no locking.

The stub (and associated batch write state) is also discarded after a transaction invocation so there is no risk of memory leaks due to redundant batch write state being left in the shared handler.

Avoid holding transaction-specific state in the handler, which must then
be protected by multiple locks. This is error prone and is a potential
performance bottleneck. Instead, extract batch writes to a separate
struct for clarity, and maintain the batch write state in the stub,
which is unique to a specific transaction so requires no locking.

The stub (and associated batch write state) is also discarded after a
transaction invocation so there is no risk of memory leaks due to
redundant batch write state being left in the shared handler.

Signed-off-by: Mark S. Lewis <[email protected]>
@bestbeforetoday bestbeforetoday marked this pull request as ready for review January 17, 2025 15:16
@bestbeforetoday bestbeforetoday requested a review from a team as a code owner January 17, 2025 15:16
@bestbeforetoday
Copy link
Member Author

I'm not sure I trust the unit tests enough to be confident this refactor maintains exactly the previous behaviour. It needs a good eyeball and perhaps trying out in actual use. Presented for review at least to get feedback on the significantly simplified implementation approach.

Copy link
Contributor

@pfi79 pfi79 left a comment

Choose a reason for hiding this comment

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

So far, some important functionality has been lost. Requires very careful testing.

shim/batch.go Outdated Show resolved Hide resolved
shim/stub.go Outdated Show resolved Hide resolved
shim/batch.go Outdated Show resolved Hide resolved
@pfi79
Copy link
Contributor

pfi79 commented Jan 17, 2025

hyperledger/fabric#5086

shim/handler.go Show resolved Hide resolved
shim/handler.go Show resolved Hide resolved
@bestbeforetoday
Copy link
Member Author

I've have pushed an additional commit to address the bugs you highlighted and the key issue that I identified. I think the fact that significant functional differences are not caught by the unit tests while refactoring the implementation highlights that the unit tests are insufficient.

shim/batch.go Outdated Show resolved Hide resolved
- Check whether batching is supported when starting a batch.
- Better keying of batched writes.

Signed-off-by: Mark S. Lewis <[email protected]>
Signed-off-by: Mark S. Lewis <[email protected]>
shim/handler.go Show resolved Hide resolved
shim/batch.go Outdated Show resolved Hide resolved
@pfi79
Copy link
Contributor

pfi79 commented Jan 17, 2025

I've have pushed an additional commit to address the bugs you highlighted and the key issue that I identified. I think the fact that significant functional differences are not caught by the unit tests while refactoring the implementation highlights that the unit tests are insufficient.

When I wrote, I added some by analogy. Probably not enough. Can you prepare a list of those unit tests that you would like to see. And as soon as we finish with your pr, I will implement them.

@bestbeforetoday
Copy link
Member Author

I've have pushed an additional commit to address the bugs you highlighted and the key issue that I identified. I think the fact that significant functional differences are not caught by the unit tests while refactoring the implementation highlights that the unit tests are insufficient.

When I wrote, I added some by analogy. Probably not enough. Can you prepare a list of those unit tests that you would like to see. And as soon as we finish with your pr, I will implement them.

Every comment you have raised on this PR identifying a behavioural issue really should have been caught by unit tests. That would be a good list to work with.

- Preallocate writes slice.

Signed-off-by: Mark S. Lewis <[email protected]>
@pfi79 pfi79 merged commit 2a94538 into hyperledger:main Jan 18, 2025
6 checks passed
@bestbeforetoday bestbeforetoday deleted the batch-refactor branch January 19, 2025 10:57
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