-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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-24323 SQL Calcite: Add query blocking tasks executor (allows t… #11833
Closed
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dfc23ed
IGNITE-24323 SQL Calcite: Add query blocking tasks executor (allows t…
alex-plekhanov 86fef11
IGNITE-24323 SQL Calcite: Add query blocking tasks executor (allows t…
alex-plekhanov 7fded30
IGNITE-24323 Review comments fixed
alex-plekhanov 9a7555c
IGNITE-24323 Review comments fixed
alex-plekhanov 1eee57b
IGNITE-24323 Review comments fixed
alex-plekhanov 2e68e3f
IGNITE-24323 Review comments fixed
alex-plekhanov 624019e
IGNITE-24323 Review comments fixed
alex-plekhanov 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
89 changes: 89 additions & 0 deletions
89
.../apache/ignite/internal/processors/query/calcite/exec/task/AbstractQueryTaskExecutor.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,89 @@ | ||
/* | ||
* 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.task; | ||
|
||
import org.apache.ignite.internal.GridKernalContext; | ||
import org.apache.ignite.internal.processors.query.calcite.exec.QueryTaskExecutor; | ||
import org.apache.ignite.internal.processors.query.calcite.util.AbstractService; | ||
import org.apache.ignite.internal.processors.security.SecurityContext; | ||
import org.apache.ignite.internal.util.typedef.internal.U; | ||
|
||
/** | ||
* Abstract query task executor. | ||
*/ | ||
public abstract class AbstractQueryTaskExecutor extends AbstractService implements QueryTaskExecutor, Thread.UncaughtExceptionHandler { | ||
/** */ | ||
public static final String THREAD_POOL_NAME = "CalciteQueryExecutor"; | ||
|
||
/** */ | ||
protected final GridKernalContext ctx; | ||
|
||
/** */ | ||
protected Thread.UncaughtExceptionHandler eHnd; | ||
|
||
/** */ | ||
protected AbstractQueryTaskExecutor(GridKernalContext ctx) { | ||
super(ctx); | ||
this.ctx = ctx; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void uncaughtException(Thread t, Throwable e) { | ||
if (eHnd != null) | ||
eHnd.uncaughtException(t, e); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void onStart(GridKernalContext ctx) { | ||
eHnd = ctx.uncaughtExceptionHandler(); | ||
|
||
super.onStart(ctx); | ||
} | ||
|
||
/** */ | ||
protected class SecurityAwareTask implements Runnable { | ||
/** */ | ||
private final SecurityContext secCtx; | ||
|
||
/** */ | ||
private final Runnable qryTask; | ||
|
||
/** */ | ||
public SecurityAwareTask(SecurityContext secCtx, Runnable qryTask) { | ||
this.secCtx = secCtx; | ||
this.qryTask = qryTask; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void run() { | ||
try (AutoCloseable ignored = ctx.security().withContext(secCtx)) { | ||
qryTask.run(); | ||
} | ||
catch (Throwable e) { | ||
U.warn(log, "Uncaught exception", e); | ||
|
||
/* | ||
* No exceptions are rethrown here to preserve the current thread from being destroyed, | ||
* because other queries may be pinned to the current thread id. | ||
* However, unrecoverable errors must be processed by FailureHandler. | ||
*/ | ||
uncaughtException(Thread.currentThread(), e); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...in/java/org/apache/ignite/internal/processors/query/calcite/exec/task/QueryAwareTask.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,26 @@ | ||
/* | ||
* 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.task; | ||
|
||
/** | ||
* Query aware task. | ||
*/ | ||
interface QueryAwareTask extends Runnable { | ||
/** */ | ||
public QueryKey queryKey(); | ||
} |
111 changes: 111 additions & 0 deletions
111
.../apache/ignite/internal/processors/query/calcite/exec/task/QueryBlockingTaskExecutor.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,111 @@ | ||
/* | ||
* 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.task; | ||
|
||
import java.util.UUID; | ||
import org.apache.ignite.configuration.IgniteConfiguration; | ||
import org.apache.ignite.internal.GridKernalContext; | ||
import org.apache.ignite.internal.managers.communication.GridIoPolicy; | ||
import org.apache.ignite.internal.processors.security.SecurityContext; | ||
import org.apache.ignite.internal.util.typedef.internal.S; | ||
import org.apache.ignite.internal.util.typedef.internal.U; | ||
import org.apache.ignite.thread.IgniteThreadPoolExecutor; | ||
|
||
import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName; | ||
import static org.apache.ignite.internal.processors.pool.PoolProcessor.THREAD_POOLS; | ||
|
||
/** | ||
* Query task executor based on queue with query blocking. | ||
*/ | ||
public class QueryBlockingTaskExecutor extends AbstractQueryTaskExecutor { | ||
/** */ | ||
private final QueryTasksQueue tasksQueue = new QueryTasksQueue(); | ||
|
||
/** */ | ||
private IgniteThreadPoolExecutor executor; | ||
|
||
/** */ | ||
public QueryBlockingTaskExecutor(GridKernalContext ctx) { | ||
super(ctx); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void execute(UUID qryId, long fragmentId, Runnable qryTask) { | ||
SecurityContext secCtx = ctx.security().securityContext(); | ||
|
||
QueryKey qryKey = new QueryKey(qryId, fragmentId); | ||
|
||
executor.execute(new QueryAndSecurityAwareTask(qryKey, secCtx, qryTask)); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void onStart(GridKernalContext ctx) { | ||
super.onStart(ctx); | ||
|
||
executor = new IgniteThreadPoolExecutor( | ||
"calciteQry", | ||
ctx.igniteInstanceName(), | ||
ctx.config().getQueryThreadPoolSize(), | ||
ctx.config().getQueryThreadPoolSize(), | ||
IgniteConfiguration.DFLT_THREAD_KEEP_ALIVE_TIME, | ||
tasksQueue.blockingQueue(), | ||
GridIoPolicy.CALLER_THREAD, | ||
eHnd | ||
) { | ||
@Override protected void afterExecute(Runnable r, Throwable t) { | ||
tasksQueue.unblockQuery(((QueryAwareTask)r).queryKey()); | ||
|
||
super.afterExecute(r, t); | ||
} | ||
}; | ||
|
||
// Prestart threads to ensure that all threads always use queue to poll tasks (without this call worker can | ||
// get its first task directly from 'execute' method, bypassing tasks queue). | ||
executor.prestartAllCoreThreads(); | ||
|
||
executor.registerMetrics(ctx.metric().registry(metricName(THREAD_POOLS, THREAD_POOL_NAME))); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void tearDown() { | ||
U.shutdownNow(getClass(), executor, log); | ||
} | ||
|
||
/** */ | ||
private class QueryAndSecurityAwareTask extends SecurityAwareTask implements QueryAwareTask { | ||
/** */ | ||
private final QueryKey qryKey; | ||
|
||
/** */ | ||
public QueryAndSecurityAwareTask(QueryKey qryKey, SecurityContext secCtx, Runnable qryTask) { | ||
super(secCtx, qryTask); | ||
|
||
this.qryKey = qryKey; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public QueryKey queryKey() { | ||
return qryKey; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public String toString() { | ||
return S.toString(QueryAndSecurityAwareTask.class, this); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/task/QueryKey.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,63 @@ | ||
/* | ||
* 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.task; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
import org.apache.ignite.internal.util.typedef.internal.S; | ||
import org.apache.ignite.internal.util.typedef.internal.U; | ||
|
||
/** | ||
* Query key. | ||
*/ | ||
class QueryKey { | ||
/** */ | ||
private final UUID qryId; | ||
|
||
/** */ | ||
private final long fragmentId; | ||
|
||
/** */ | ||
QueryKey(UUID qryId, long fragmentId) { | ||
this.qryId = qryId; | ||
this.fragmentId = fragmentId; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
|
||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
|
||
QueryKey key = (QueryKey)o; | ||
|
||
return fragmentId == key.fragmentId && Objects.equals(qryId, key.qryId); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public int hashCode() { | ||
return U.safeAbs(31 * (31 + (qryId != null ? qryId.hashCode() : 0)) + Long.hashCode(fragmentId)); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public String toString() { | ||
return S.toString(QueryKey.class, this); | ||
} | ||
} |
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.
All other pools names starts with capital letter.
Let's call it
CalciteQueryAwareExecutor
and the default oneCalciteExecutor
.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.
It's not a pool name, it's thread prefix. All other thread prefixes start with non-capital letters.