-
Notifications
You must be signed in to change notification settings - Fork 78
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
Use CompleteableFuture compose to centralize commit logic #978
Comments
I created a Gist containing some local experimentation I did. I am not in anyway advocating for this design, I am just experimenting with the high level decomposition and sharing the result for discussion. I am new to using thenCompose and was just trying it out. |
This is the commit code as it existed before being converted to an async process.
|
Just wanted to also copy some relevant comments from #722 by @jwonders, to avoid having to flip back and forth.
And
|
@keith-turner I've been trying to think of a way to synthesize @jwonders idea of an AysncCommitResult and your idea of having one main commit method to handle all the logic. Essentially Ultimately the last method, So using the two methods that @jwonders used above it would look something like this:
My two questions/issues are:
|
|
I was going to try and see how this worked in actual code and I noticed that this would not cover the case where we commit and return early. We could add a |
If anyone's interested I started to try and see how this would look/work in code. TransactionImpl and AsyncCommitResult. It's still pretty messy, but I've already been thinking of ways to clean it up. I didn't open a pull request because it doesn't compile, I have one error left that I need to take care of. So I still don't really know if it works but I just wanted to show an idea of what I was talking about. Some cleanup ideas:
|
@jkosh44 I'm interested in looking at it. I probably can't get to it until this weekend rthough. Hopefully the |
I have been looking at your changes, I am not sure the AsyncCommitResult path is improving the readability of the code. I have been thinking about this and experimented with another high level design. This design has CommitSteps can be chained together allowing someone to easily follow the overall commit logic. An example of the commit step is the LockPrimaryStep which does a conditional update. There are a few things I like about this pattern.
|
@keith-turner I haven't had a chance to look at the code in depth but it seems to achieve everything you were looking for. In terms of exception handling for CommitStep, I thin we can append For all the TODOs saying something along the lines of "do async" what do you think about just surrounding them with CompletableFuture.runAsync()`? |
I think either of those approaches would work. However I am still not very familiar with
I think that would work in some cases. If you think the approach I proposed is good, feel free to copy it or branch it. One thing I realized about this approach is that it makes the normal path easy to follow in the code. However the error path is still spread out in the code. |
It took me a little while to work my way through the transaction implementation. I made this diagram to help keep things straight in my head. I think it is pretty accurate although I didn't pay as close of attention to some of the error handling branches. The main thing to note is that some of the stages require a decision between more than two branches upon completion. The |
@jwonders the flow chart is really awesome! What did you use to create it? Would you be willing to contribute it? I think we could use that diagram to create a blog post explaining the commit process. The blog post could have short explanations of the steps and links to the code.
I agree with this. I can't think of a way to represent the error paths at the top level without making the code hard to follow at the top level. |
I used gliffy. Definitely willing to contribute it. Here is a gist of the json. https://gist.github.com/jwonders/f71425e6495e08d610ad69ff49735742 |
Hey, I haven't really been able to work on this because of the holidays/holiday preparation. I hope to start up on it again soon though. |
Hey sorry, so I got really distracted and took a bit of a hiatus. But I took a look at it this weekend and went through a first pass at filling it in, TransactionImpl. It's currently failing a lot of tests but surprisingly passing a lot too. I'm going to look at it some more tomorrow, but I just wanted to post this since I haven't posted in awhile. |
Ok so I created a pull request, #1001. It's not passing every test but it only seems to be failing 3 tests.Those three test are all from In general the way I dealt with the Visible For Testing methods were as follows. I would create a first step as whatever intermediate step that testing method was starting at, fill in the rest of the steps using Edit: right after typing this I just thought of a cleaner way. We wouldn't even need the two booleans if while filling in the next steps using
we'd have
|
Well that change seemed to have killed two birds with one stone, all tests pass now. I still want to refactor |
Opening this issue for follow on work identified in the comments of #975 and #722.
The text was updated successfully, but these errors were encountered: