-
Notifications
You must be signed in to change notification settings - Fork 100
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
IGNITE-24053 Jdbc. Use single observable time tracker for multiple JDBC connections #5069
Open
xtern
wants to merge
9
commits into
apache:main
Choose a base branch
from
gridgain:ignite-24053
base: main
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.
+622
−248
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6d0fba5
IGNITE-24053 Use single obserable time tracker for multiple JDBC conn…
xtern abf855c
IGNITE-24053 (minor) Code cleanup.
xtern 1f93be5
IGNITE-24053 (minor) Javadoc.
xtern 40eb5b6
IGNITE-24053 Move HybridTimestampTracker to core module.
xtern 3e7f227
IGNITE-24053 Use time tracker instead of AtomicLong on client side.
xtern 19dbf65
IGNITE-24053 (minor) Added TODO.
xtern 6454eda
IGNITE-24053 Fix single server test.
xtern 499dada
IGNITE-24053 Remove observableTimestamp from Internal transaction.
xtern 8a210ce
IGNITE-24053 Javadoc improved.
xtern 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
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
34 changes: 34 additions & 0 deletions
34
...main/java/org/apache/ignite/internal/jdbc/proto/event/JdbcObservableTimeAwareRequest.java
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.internal.jdbc.proto.event; | ||
|
||
import org.apache.ignite.internal.hlc.HybridTimestampTracker; | ||
|
||
/** | ||
* An extension to JDBC request that provides the ability to update and read client observable time. | ||
*/ | ||
abstract class JdbcObservableTimeAwareRequest { | ||
/** Tracker of the latest time observed by client. */ | ||
@SuppressWarnings("TransientFieldInNonSerializableClass") | ||
private final transient HybridTimestampTracker timestampTracker = HybridTimestampTracker.atomicTracker(null); | ||
|
||
/** Returns the tracker of the latest time observed by client. */ | ||
public HybridTimestampTracker timestampTracker() { | ||
return timestampTracker; | ||
} | ||
} |
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
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
138 changes: 138 additions & 0 deletions
138
.../client-handler/src/main/java/org/apache/ignite/client/handler/JdbcConnectionContext.java
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.client.handler; | ||
|
||
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; | ||
|
||
import java.time.ZoneId; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.apache.ignite.internal.hlc.HybridTimestamp; | ||
import org.apache.ignite.internal.hlc.HybridTimestampTracker; | ||
import org.apache.ignite.internal.tx.InternalTransaction; | ||
import org.apache.ignite.internal.tx.InternalTxOptions; | ||
import org.apache.ignite.internal.tx.TxManager; | ||
import org.apache.ignite.lang.CancelHandle; | ||
import org.apache.ignite.lang.CancellationToken; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* JDBC connection context. | ||
*/ | ||
class JdbcConnectionContext { | ||
private final AtomicBoolean closed = new AtomicBoolean(); | ||
|
||
private final Object mux = new Object(); | ||
|
||
private final TxManager txManager; | ||
|
||
private final ZoneId timeZoneId; | ||
|
||
private final ConcurrentMap<Long, CancelHandle> cancelHandles = new ConcurrentHashMap<>(); | ||
|
||
private @Nullable InternalTransaction tx; | ||
|
||
JdbcConnectionContext( | ||
TxManager txManager, | ||
ZoneId timeZoneId | ||
) { | ||
this.txManager = txManager; | ||
this.timeZoneId = timeZoneId; | ||
} | ||
|
||
ZoneId timeZoneId() { | ||
return timeZoneId; | ||
} | ||
|
||
/** | ||
* Gets the transaction associated with the current connection, starts a new one if it doesn't already exist. | ||
* | ||
* <p>NOTE: this method is not thread-safe and should only be called by a single thread. | ||
* | ||
* @return Transaction associated with the current connection. | ||
*/ | ||
InternalTransaction getOrStartTransaction(HybridTimestampTracker timestampTracker) { | ||
if (tx == null) { | ||
tx = txManager.beginExplicitRw(timestampTracker, InternalTxOptions.defaults()); | ||
} | ||
|
||
return tx; | ||
} | ||
|
||
/** | ||
* Finishes active transaction, if one exists. | ||
* | ||
* <p>NOTE: this method is not thread-safe and should only be called by a single thread. | ||
* | ||
* @param commit {@code True} to commit, {@code false} to rollback. | ||
* @return Future that represents the pending completion of the operation. | ||
*/ | ||
CompletableFuture<@Nullable HybridTimestamp> finishTransactionAsync(boolean commit) { | ||
InternalTransaction tx0 = tx; | ||
|
||
tx = null; | ||
|
||
if (tx0 == null) { | ||
return nullCompletedFuture(); | ||
} | ||
|
||
return commit | ||
? tx0.commitAsync().thenApply(ignore -> tx0.observableTimestamp()) | ||
: tx0.rollbackAsync().thenApply(ignore -> null); | ||
} | ||
|
||
boolean valid() { | ||
return !closed.get(); | ||
} | ||
|
||
void close() { | ||
if (!closed.compareAndSet(false, true)) { | ||
return; | ||
} | ||
|
||
synchronized (mux) { | ||
finishTransactionAsync(false); | ||
} | ||
} | ||
|
||
CancellationToken registerExecution(long token) { | ||
CancelHandle handle = CancelHandle.create(); | ||
|
||
CancelHandle previousHandle = cancelHandles.putIfAbsent(token, handle); | ||
|
||
assert previousHandle == null; | ||
|
||
return handle.token(); | ||
} | ||
|
||
void deregisterExecution(long token) { | ||
cancelHandles.remove(token); | ||
} | ||
|
||
CompletableFuture<Void> cancelExecution(long token) { | ||
CancelHandle handle = cancelHandles.remove(token); | ||
|
||
if (handle == null) { | ||
return nullCompletedFuture(); | ||
} | ||
|
||
return handle.cancelAsync(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
|
||
import static org.apache.ignite.internal.jdbc.proto.IgniteQueryErrorCode.UNSUPPORTED_OPERATION; | ||
import static org.apache.ignite.internal.sql.engine.SqlQueryType.DDL; | ||
import static org.apache.ignite.internal.sql.engine.SqlQueryType.DML; | ||
import static org.apache.ignite.internal.sql.engine.SqlQueryType.KILL; | ||
import static org.apache.ignite.internal.sql.engine.SqlQueryType.TX_CONTROL; | ||
|
||
|
@@ -49,16 +48,12 @@ | |
* Contains common methods used to process jdbc requests. | ||
*/ | ||
abstract class JdbcHandlerBase { | ||
|
||
/** {@link SqlQueryType}s allowed in JDBC select statements. **/ | ||
public static final Set<SqlQueryType> SELECT_STATEMENT_QUERIES = Set.of( | ||
SqlQueryType.QUERY, | ||
SqlQueryType.EXPLAIN | ||
); | ||
|
||
/** {@link SqlQueryType}s allowed in JDBC update statements. **/ | ||
public static final Set<SqlQueryType> UPDATE_STATEMENT_QUERIES = Set.of(DML, DDL, KILL); | ||
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. was not used |
||
|
||
/** {@link SqlQueryType}s types that return 0 in executeUpdate and execute / getUpdateCount. **/ | ||
public static final Set<SqlQueryType> ZERO_UPDATE_COUNT_QUERIES = Set.of(DDL, KILL, TX_CONTROL); | ||
|
||
|
Oops, something went wrong.
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.
this class is simply moved to the top level