-
Notifications
You must be signed in to change notification settings - Fork 115
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
Reorganize local storing of Tx #1569
Open
plyhun
wants to merge
15
commits into
hotfix-1.10.x
Choose a base branch
from
hotfix-1.10.x-sup-16182
base: hotfix-1.10.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
21ab948
SUP-16182: Use Vertx context for tx storage
plyhun b6fa1f5
SUP-16182: Use Vertx context for tx storage pt2
plyhun 77d8e59
SUP-16182: Use Vertx context for tx storage pt3
plyhun adae05e
Parallel upload fix
plyhun 16a1700
Comments
plyhun c1906b1
Other way to store Tx
plyhun 0cec36b
Stress test
plyhun 13195ff
More stress
plyhun 2ed9611
Test fixes
plyhun be5fc28
Changelog
plyhun 8a52fac
Revert "Test fixes"
plyhun 5675f9a
Revert "More stress"
plyhun 7bbd03b
Revert "Stress test"
plyhun 70d33e8
Revert "Comments"
plyhun 17db8fc
Revert "Parallel upload fix"
plyhun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.gentics.mesh.core.db; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import com.gentics.mesh.cache.CacheCollection; | ||
import com.gentics.mesh.context.InternalActionContext; | ||
|
@@ -12,6 +13,9 @@ | |
import com.gentics.mesh.event.EventQueueBatch; | ||
import com.gentics.mesh.security.SecurityUtils; | ||
|
||
import io.vertx.reactivex.core.Context; | ||
import io.vertx.reactivex.core.Vertx; | ||
|
||
/** | ||
* A {@link Tx} is an interface for autoclosable transactions. | ||
*/ | ||
|
@@ -23,22 +27,32 @@ public interface Tx extends BaseTransaction, DaoCollection, CacheCollection, Sec | |
static ThreadLocal<Tx> threadLocalGraph = new ThreadLocal<>(); | ||
|
||
/** | ||
* Set the nested active transaction for the current thread. | ||
* Set the nested active transaction for the current Vert.x context, or thread. | ||
* | ||
* @param tx | ||
* Transaction | ||
*/ | ||
static void setActive(Tx tx) { | ||
Tx.threadLocalGraph.set(tx); | ||
Optional.ofNullable(Vertx.currentContext()) | ||
.ifPresentOrElse( | ||
ctx -> ctx.putLocal("tx", Optional.ofNullable(tx)), | ||
() -> Tx.threadLocalGraph.set(tx) | ||
); | ||
} | ||
|
||
/** | ||
* Return the current active transaction. A transaction should be the only place where this threadlocal is updated. | ||
* Return the current active transaction. A transaction should be the only place where this context/threadlocal is updated. | ||
* | ||
* @return Currently active transaction | ||
*/ | ||
static Tx get() { | ||
return Tx.threadLocalGraph.get(); | ||
Optional<Context> maybeVertxContext = Optional.ofNullable(Vertx.currentContext()); | ||
if (maybeVertxContext.isPresent()) { | ||
Context vertxContext = maybeVertxContext.get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mix the cases where we have an empty Context, and where we have no Context at all. |
||
return Optional.ofNullable(vertxContext.<Optional<Tx>>getLocal("tx")).flatMap(Function.identity()).orElse(null); | ||
} else { | ||
return Tx.threadLocalGraph.get(); | ||
} | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual change. There are
get()
andgetLocal()
in the Vert.xContext
, which seem to be functionally equal, butgetLocal()
has internal usages.