[
https://issues.apache.org/jira/browse/GEODE-146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14943657#comment-14943657
]
ASF subversion and git services commented on GEODE-146:
-------------------------------------------------------
Commit 1512677f721279a05c6ebddad443d2043d032f99 in incubator-geode's branch
refs/heads/develop from [~huynhja]
[ https://git-wip-us.apache.org/repos/asf?p=incubator-geode.git;h=1512677 ]
[GEODE-146] Queries are not thread safe due to scopeId variable
ScopeId was not thread safe when stored and used in CompiledSelect
Multiple threads could set/unset the value. Instead it is stored in
the query execution context.
> Queries are not thread safe due to scopeId variable
> ---------------------------------------------------
>
> Key: GEODE-146
> URL: https://issues.apache.org/jira/browse/GEODE-146
> Project: Geode
> Issue Type: Bug
> Components: querying
> Reporter: Jason Huynh
> Assignee: Jason Huynh
>
> Currently queries are not thread safe although they should be. This is due
> to the way the scopeId is stored in the CompiledSelect. The fix consists of
> storing the scopeId in the execution context.
> public void testThreadSafetyOfCompiledSelectScopeId() throws Exception {
> Cache cache = CacheUtils.getCache();
> RegionFactory<Integer, Portfolio> rf = cache
> .createRegionFactory(RegionShortcut.PARTITION);
> Region r = rf.create("keyzset");
> for (int i = 0; i < 100; i++) {
> r.put(i, new Portfolio(i));
> }
> ScopeThreadingTestHook scopeIDTestHook = new ScopeThreadingTestHook(3);
> DefaultQuery.testHook = scopeIDTestHook;
> QueryService qs = cache.getQueryService();
> Query q = qs
> .newQuery("SELECT DISTINCT * FROM /keyzset.keySet key WHERE key.id >
> 0 AND key.id <= 0 ORDER BY key asc LIMIT $3");
> Thread q1 = new Thread(new QueryRunnable(q, new Object[] { 10, 20, 10 }));
> Thread q2 = new Thread(new QueryRunnable(q, new Object[] { 5, 10, 5 }));
> Thread q3 = new Thread(new QueryRunnable(q, new Object[] { 2, 10, 8 }));
> q1.start();
> q2.start();
> q3.start();
> q1.join();
> q2.join();
> q3.join();
> assertEquals("Exceptions were thrown due to DefaultQuery not being
> thread-safe", true, scopeIDTestHook.isOk());
> }
> private class QueryRunnable implements Runnable {
> private Query q;
> private Object[] params;
> public QueryRunnable(Query q, Object[] params) {
> this.q = q;
> this.params = params;
> }
> public void run() {
> try {
> q.execute(params);
> } catch (Exception e) {
> throw new TestException("exception occured while executing query", e);
> }
> }
> }
> public class ScopeThreadingTestHook implements DefaultQuery.TestHook {
> private CyclicBarrier barrier;
> private List<Exception> exceptionsThrown = new LinkedList<Exception>();
> public ScopeThreadingTestHook(int numThreads) {
> barrier = new CyclicBarrier(numThreads);
> }
> @Override
> public void doTestHook(int spot) {
> this.doTestHook(spot + "");
> }
> @Override
> public void doTestHook(String spot) {
> if (spot.equals("1")) {
> try {
> barrier.await(8, TimeUnit.SECONDS);
> } catch (InterruptedException e) {
> exceptionsThrown.add(e);
> Thread.currentThread().interrupt();
> } catch (Exception e) {
> exceptionsThrown.add(e);
> }
> }
> }
> public boolean isOk() {
> return exceptionsThrown.size() == 0;
> }
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)