geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anthony Baker (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (GEODE-146) Queries are not thread safe due to scopeId variable
Date Fri, 15 Jan 2016 06:14:53 GMT

     [ https://issues.apache.org/jira/browse/GEODE-146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Anthony Baker closed GEODE-146.
-------------------------------

> 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
>             Fix For: 1.0.0-incubating.M1
>
>
> 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)

Mime
View raw message