-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-28352 Calcite. User defined sql function miss entries are written under the same tx lock #12936
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
base: master
Are you sure you want to change the base?
IGNITE-28352 Calcite. User defined sql function miss entries are written under the same tx lock #12936
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||
|
|
||||||
| package org.apache.ignite.internal.processors.query.calcite.exec; | ||||||
|
|
||||||
| import java.util.Collection; | ||||||
| import java.util.Collections; | ||||||
| import java.util.Iterator; | ||||||
| import java.util.List; | ||||||
|
|
@@ -37,6 +38,7 @@ | |||||
| import org.apache.ignite.cache.query.QueryCancelledException; | ||||||
| import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; | ||||||
| import org.apache.ignite.cluster.ClusterNode; | ||||||
| import org.apache.ignite.configuration.TransactionConfiguration; | ||||||
| import org.apache.ignite.events.CacheQueryReadEvent; | ||||||
| import org.apache.ignite.events.EventType; | ||||||
| import org.apache.ignite.internal.GridKernalContext; | ||||||
|
|
@@ -78,6 +80,7 @@ | |||||
| import org.apache.ignite.internal.processors.query.calcite.message.MessageType; | ||||||
| import org.apache.ignite.internal.processors.query.calcite.message.QueryStartRequest; | ||||||
| import org.apache.ignite.internal.processors.query.calcite.message.QueryStartResponse; | ||||||
| import org.apache.ignite.internal.processors.query.calcite.message.QueryTxEntry; | ||||||
| import org.apache.ignite.internal.processors.query.calcite.metadata.AffinityService; | ||||||
| import org.apache.ignite.internal.processors.query.calcite.metadata.FragmentDescription; | ||||||
| import org.apache.ignite.internal.processors.query.calcite.metadata.FragmentMapping; | ||||||
|
|
@@ -205,6 +208,13 @@ public class ExecutionServiceImpl<Row> extends AbstractService implements Execut | |||||
| /** */ | ||||||
| private final Map<String, FragmentPlan> fragmentPlanCache = new GridBoundedConcurrentLinkedHashMap<>(1024); | ||||||
|
|
||||||
| /** | ||||||
| * Transaction modified entries holder. | ||||||
| * | ||||||
| * @see TransactionConfiguration#isTxAwareQueriesEnabled() | ||||||
| */ | ||||||
| private TxAwareModifiedEntriesHolder modifiedEntriesHolder; | ||||||
|
Contributor
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. Why not use just static |
||||||
|
|
||||||
| /** | ||||||
| * @param ctx Kernal. | ||||||
| */ | ||||||
|
|
@@ -477,13 +487,15 @@ public void injectService(InjectResourcesService injectSvc) { | |||||
| eventManager().addDiscoveryEventListener(discoLsnr, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT); | ||||||
|
|
||||||
| iteratorsHolder().init(); | ||||||
| modifiedEntriesHolder = new TxAwareModifiedEntriesHolder(U.isTxAwareQueriesEnabled(ctx)); | ||||||
| } | ||||||
|
|
||||||
| /** {@inheritDoc} */ | ||||||
| @Override public void tearDown() { | ||||||
| eventManager().removeDiscoveryEventListener(discoLsnr, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT); | ||||||
|
|
||||||
| iteratorsHolder().tearDown(); | ||||||
| modifiedEntriesHolder = null; | ||||||
| } | ||||||
|
|
||||||
| /** */ | ||||||
|
|
@@ -515,7 +527,8 @@ private FragmentPlan prepareFragment(BaseQueryContext ctx, String jsonFragment) | |||||
| case DML: | ||||||
| ListFieldsQueryCursor<?> cur = mapAndExecutePlan( | ||||||
| qry, | ||||||
| (MultiStepPlan)plan | ||||||
| (MultiStepPlan)plan, | ||||||
| modifiedEntriesHolder | ||||||
| ); | ||||||
|
|
||||||
| cur.iterator().hasNext(); | ||||||
|
|
@@ -525,7 +538,8 @@ private FragmentPlan prepareFragment(BaseQueryContext ctx, String jsonFragment) | |||||
| case QUERY: | ||||||
| return mapAndExecutePlan( | ||||||
| qry, | ||||||
| (MultiStepPlan)plan | ||||||
| (MultiStepPlan)plan, | ||||||
| modifiedEntriesHolder | ||||||
| ); | ||||||
|
|
||||||
| case EXPLAIN: | ||||||
|
|
@@ -577,7 +591,8 @@ private FieldsQueryCursor<List<?>> executeDdl(RootQuery<Row> qry, DdlPlan plan) | |||||
| /** */ | ||||||
| private ListFieldsQueryCursor<?> mapAndExecutePlan( | ||||||
| RootQuery<Row> qry, | ||||||
| MultiStepPlan plan | ||||||
| MultiStepPlan plan, | ||||||
| TxAwareModifiedEntriesHolder mofiedEntriesHolder | ||||||
|
Contributor
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. No need to pass this parameter, it's a non static method and always passed as |
||||||
| ) { | ||||||
| qry.mapping(); | ||||||
|
|
||||||
|
|
@@ -626,6 +641,8 @@ private ListFieldsQueryCursor<?> mapAndExecutePlan( | |||||
| MemoryTracker qryMemoryTracker = qry.createMemoryTracker(memoryTracker, cfg.getQueryMemoryQuota()); | ||||||
|
|
||||||
| final GridNearTxLocal userTx = Commons.queryTransaction(qry.context(), ctx.cache().context()); | ||||||
| final @Nullable Collection<QueryTxEntry> writeEntries = userTx == null ? | ||||||
| mofiedEntriesHolder.retrieve() : ExecutionContext.transactionChanges(userTx.writeEntries()); | ||||||
|
|
||||||
zstan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| ExecutionContext<Row> ectx = new ExecutionContext<>( | ||||||
| qry.context(), | ||||||
|
|
@@ -641,7 +658,8 @@ private ListFieldsQueryCursor<?> mapAndExecutePlan( | |||||
| createIoTracker(locNodeId, qry.localQueryId()), | ||||||
| timeout, | ||||||
| qryParams, | ||||||
| userTx == null ? null : ExecutionContext.transactionChanges(userTx.writeEntries())); | ||||||
| writeEntries, | ||||||
| mofiedEntriesHolder); | ||||||
|
|
||||||
| Node<Row> node = new LogicalRelImplementor<>(ectx, partitionService(), mailboxRegistry(), | ||||||
| exchangeService(), failureProcessor()).go(fragment.root()); | ||||||
|
|
@@ -901,7 +919,8 @@ private void onMessage(UUID nodeId, final QueryStartRequest msg) { | |||||
| createIoTracker(nodeId, msg.originatingQueryId()), | ||||||
| msg.timeout(), | ||||||
| Commons.parametersMap(msg.parameters()), | ||||||
| msg.queryTransactionEntries() | ||||||
| msg.queryTransactionEntries(), | ||||||
| null | ||||||
|
||||||
| null | |
| modifiedEntriesHolder |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * 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.processors.query.calcite.exec; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import org.apache.ignite.internal.processors.query.calcite.message.QueryTxEntry; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** Per thread modified entries holder. */ | ||
| public class TxAwareModifiedEntriesHolder { | ||
| /** Transaction modified entries holder. */ | ||
| @Nullable private final ThreadLocal<Collection<QueryTxEntry>> holder; | ||
|
|
||
| /** */ | ||
| public TxAwareModifiedEntriesHolder(boolean txAware) { | ||
| if (txAware) | ||
| holder = new ThreadLocal<>(); | ||
| else | ||
| holder = null; | ||
| } | ||
|
|
||
| /** Store entries if applicable. */ | ||
| public void store(Collection<QueryTxEntry> items) { | ||
| if (holder != null) | ||
| holder.set(items); | ||
| } | ||
|
|
||
| /** Retrieve entries if applicable. */ | ||
| @Nullable public Collection<QueryTxEntry> retrieve() { | ||
| if (holder != null) | ||
| return holder.get(); | ||
| else | ||
| return Collections.emptyList(); | ||
zstan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** Detach stored entries. */ | ||
| public void detach() { | ||
| if (holder != null) | ||
| holder.remove(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.