use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.
the class RegionProvider method getOrCreateRegion0.
private Region<?, ?> getOrCreateRegion0(ByteArrayWrapper key, RedisDataType type, ExecutionHandlerContext context, boolean addToMeta) {
checkDataType(key, type);
Region<?, ?> r = this.regions.get(key);
if (r != null && r.isDestroyed()) {
removeKey(key, type);
r = null;
}
if (r == null) {
String stringKey = key.toString();
Lock lock = this.locks.get(stringKey);
if (lock == null) {
this.locks.putIfAbsent(stringKey, new ReentrantLock());
lock = this.locks.get(stringKey);
}
try {
lock.lock();
r = regions.get(key);
if (r == null) {
// Can create
boolean hasTransaction = context != null && context.hasTransaction();
// without context
CacheTransactionManager txm = null;
TransactionId transactionId = null;
try {
if (hasTransaction) {
txm = cache.getCacheTransactionManager();
transactionId = txm.suspend();
}
Exception concurrentCreateDestroyException = null;
do {
concurrentCreateDestroyException = null;
r = createRegionGlobally(stringKey);
try {
if (type == RedisDataType.REDIS_LIST) {
doInitializeList(key, r);
} else if (type == RedisDataType.REDIS_SORTEDSET) {
try {
doInitializeSortedSet(key, r);
} catch (RegionNotFoundException | IndexInvalidException e) {
concurrentCreateDestroyException = e;
}
}
} catch (QueryInvalidException e) {
if (e.getCause() instanceof RegionNotFoundException) {
concurrentCreateDestroyException = e;
}
}
} while (concurrentCreateDestroyException != null);
this.regions.put(key, r);
if (addToMeta) {
RedisDataType existingType = metaPutIfAbsent(key, type);
if (existingType != null && existingType != type)
throw new RedisDataTypeMismatchException("The key name \"" + key + "\" is already used by a " + existingType.toString());
}
} finally {
if (hasTransaction)
txm.resume(transactionId);
}
}
} finally {
lock.unlock();
}
}
return r;
}
use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.
the class NonDistinctOrderByDUnitImpl method createIndex.
protected void createIndex(VM vm, final String indexName, IndexType indexType, final String indexedExpression, final String fromClause) {
int indxTypeCode = -1;
if (indexType.equals(IndexType.FUNCTIONAL)) {
indxTypeCode = 0;
} else if (indexType.equals(IndexType.PRIMARY_KEY)) {
indxTypeCode = 1;
} else if (indexType.equals(IndexType.HASH)) {
indxTypeCode = 2;
}
final int finalIndxTypeCode = indxTypeCode;
vm.invoke(new SerializableRunnable("create index") {
public void run() {
try {
Cache cache = getCache();
IndexType indxType = null;
if (finalIndxTypeCode == 0) {
indxType = IndexType.FUNCTIONAL;
} else if (finalIndxTypeCode == 1) {
indxType = IndexType.PRIMARY_KEY;
} else if (finalIndxTypeCode == 2) {
indxType = IndexType.HASH;
}
cache.getQueryService().createIndex(indexName, indxType, indexedExpression, fromClause);
} catch (RegionNotFoundException e) {
fail(e.toString());
} catch (IndexExistsException e) {
fail(e.toString());
} catch (IndexNameConflictException e) {
fail(e.toString());
}
}
});
}
use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForDuplicatePRIndexCreate.
/**
* This function creates a duplicate index should throw an IndexNameConflictException and if not
* the test should fail.
*/
public CacheSerializableRunnable getCacheSerializableRunnableForDuplicatePRIndexCreate(final String prRegionName, final String indexName, final String indexedExpression, final String fromClause, final String alias) {
SerializableRunnable prIndexCreator = new CacheSerializableRunnable("DuplicatePartitionedIndexCreator") {
@Override
public void run2() {
Cache cache = getCache();
LogWriter logger = cache.getLogger();
QueryService qs = cache.getQueryService();
Region region = cache.getRegion(prRegionName);
try {
if (null != fromClause) {
qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause);
throw new RuntimeException("Should throw an exception because " + "the index with name : " + indexName + " should already exists");
} else {
qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, region.getFullPath() + " " + alias);
throw new RuntimeException("Should throw an exception because " + "the index with name : " + indexName + " should already exists");
}
} catch (IndexExistsException e) {
logger.info("Index Exists Excetpiont righteously throw ", e);
} catch (IndexNameConflictException ex) {
logger.info("Gott the right exception");
} catch (RegionNotFoundException exx) {
// TODO Auto-generated catch block
Assert.fail("Region Not found in this vm ", exx);
}
}
};
return (CacheSerializableRunnable) prIndexCreator;
}
use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.
the class PRQueryCacheClosedJUnitTest method testQueryOnSingleDataStoreWithCacheClose.
/**
* Tests the execution of query on a PartitionedRegion created on a single data store. <br>
* 1. Creates a PR with redundancy=0 on a single VM. <br>
* 2. Puts some test Objects in cache.<br>
* 3. Create a Thread and fire queries on the data and verifies the result.<br>
* 4. Create another Thread and call cache#close()<br>
* 5. Recreates the cache after a delay of 1500ms
*
*
* @throws Exception
*/
@Test
public void testQueryOnSingleDataStoreWithCacheClose() throws Exception {
logger.info("PRQueryRegionDestroyedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Test Started ");
logger.info("PRQueryRegionDestroyedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: creating PR Region ");
final Region region = PartitionedRegionTestHelper.createPartitionedRegion(regionName, localMaxMemory, redundancy);
final Region localRegion = PartitionedRegionTestHelper.createLocalRegion(localRegionName);
final StringBuffer errorBuf = new StringBuffer("");
PortfolioData[] portfolios = new PortfolioData[dataSize];
try {
for (int j = 0; j < dataSize; j++) {
portfolios[j] = new PortfolioData(j);
}
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: populating PortfolioData into the PR Datastore ");
populateData(region, portfolios);
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: populating PortfolioData into the PR Datastore ");
populateData(localRegion, portfolios);
final String[] queryString = { "ID = 0 OR ID = 1", "ID > 4 AND ID < 9", "ID = 5", "ID < 5 ", "ID <= 5" };
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Creating a Thread which will fire queries on the datastore");
Thread t1 = new Thread(new Runnable() {
public void run() {
final String expectedCacheClosedException = CacheClosedException.class.getName();
logger.info("<ExpectedException action=add>" + expectedCacheClosedException + "</ExpectedException>");
for (int i = 0; i < queryString.length; i++) {
try {
SelectResults resSetPR = region.query(queryString[i]);
SelectResults resSetLocal = localRegion.query(queryString[i]);
String failureString = PartitionedRegionTestHelper.compareResultSets(resSetPR, resSetLocal);
Thread.sleep(delayQuery);
if (failureString != null) {
errorBuf.append(failureString);
throw (new Exception(failureString));
}
} catch (InterruptedException ie) {
fail("interrupted");
} catch (CancelException cce) {
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: CancelException as Expected " + cce);
}// it's also possible to get a RegionNotFoundException
catch (RegionNotFoundException rnfe) {
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: RegionNotFoundException as Expected " + rnfe);
} catch (Exception qe) {
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Unexpected Exception " + qe);
encounteredException = true;
StringWriter sw = new StringWriter();
qe.printStackTrace(new PrintWriter(sw, true));
errorBuf.append(sw);
}
}
logger.info("<ExpectedException action=remove>" + expectedCacheClosedException + "</ExpectedException>");
}
});
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Creating a Thread which will call cache.close() on the datastore ");
Thread t2 = new Thread(new Runnable() {
public void run() {
PartitionedRegionTestHelper.closeCache();
try {
Thread.sleep(delayCC);
} catch (InterruptedException ie) {
fail("interrupted");
}
PartitionedRegionTestHelper.createCache();
}
});
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Initiating the Threads");
t1.start();
t2.start();
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Waiting for the Threads to join ");
ThreadUtils.join(t1, 30 * 1000);
ThreadUtils.join(t2, 30 * 1000);
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: checking for any Unexpected Exception's occurred");
assertFalse("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Exception occurred in Query-thread: " + errorBuf, encounteredException);
} catch (Exception e) {
e.printStackTrace();
fail("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Test failed because of exception " + e);
}
logger.info("PRQueryCacheClosedJUnitTest#testQueryOnSingleDataStoreWithCacheClose: Test Ended");
}
use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.
the class PRColocatedEquiJoinDUnitTest method testPRRRNonLocalQueryingWithNoRROnOneNode.
/**
* A very basic dunit test that <br>
* 1. Creates two PR Data Stores with redundantCopies = 1. 2. Populates the region with test data.
* 3. Fires a LOCAL query on one data store VM and verifies the result.
*
* @throws Exception
*/
@Test
public void testPRRRNonLocalQueryingWithNoRROnOneNode() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
setCacheInVMs(vm0, vm1);
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Querying PR Test with DACK Started");
// Creting PR's on the participating VM's
// Creating DataStore node on the VM0.
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Creating the DataStore node in the PR");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, 0, Portfolio.class));
vm1.invoke(PRQHelp.getCacheSerializableRunnableForPRCreate(name, 0, Portfolio.class));
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Successfully created the DataStore node in the PR");
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Successfully Created PR's across all VM's");
// Creating Colocated Region DataStore node on the VM0.
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Creating the Colocated DataStore node in the RR");
vm0.invoke(PRQHelp.getCacheSerializableRunnableForLocalRegionCreation(coloName, NewPortfolio.class));
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Successfully Created PR's across all VM's");
final Portfolio[] portfolio = createPortfoliosAndPositions(cntDest);
final NewPortfolio[] newPortfolio = createNewPortfoliosAndPositions(cntDest);
// Putting the data into the PR's created
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(coloName, newPortfolio, cnt, cntDest));
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Inserted Portfolio data across PR's");
// querying the VM for data and comparing the result with query result of
// local region.
// querying the VM for data
vm0.invoke(new CacheSerializableRunnable("PRQuery") {
@Override
public void run2() throws CacheException {
// Helper classes and function
class TestQueryFunction extends FunctionAdapter {
@Override
public boolean hasResult() {
return true;
}
@Override
public boolean isHA() {
return false;
}
private final String id;
public TestQueryFunction(String id) {
super();
this.id = id;
}
@Override
public void execute(FunctionContext context) {
Cache cache = CacheFactory.getAnyInstance();
QueryService queryService = cache.getQueryService();
ArrayList allQueryResults = new ArrayList();
String qstr = (String) context.getArguments();
try {
Query query = queryService.newQuery(qstr);
context.getResultSender().sendResult((ArrayList) ((SelectResults) query.execute((RegionFunctionContext) context)).asList());
context.getResultSender().lastResult(null);
} catch (Exception e) {
e.printStackTrace();
throw new FunctionException(e);
}
}
@Override
public String getId() {
return this.id;
}
}
Cache cache = getCache();
// Querying the PR region
String[] queries = new String[] { "r1.ID = r2.id" };
Object[][] r = new Object[queries.length][2];
Region region = null;
region = cache.getRegion(name);
assertNotNull(region);
region = cache.getRegion(coloName);
assertNotNull(region);
QueryService qs = getCache().getQueryService();
Object[] params;
try {
for (int j = 0; j < queries.length; j++) {
getCache().getLogger().info("About to execute local query: " + queries[j]);
Function func = new TestQueryFunction("testfunction");
Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, /" + coloName + " r2 where " + queries[j]).execute(func).getResult();
r[j][0] = ((ArrayList) funcResult).get(0);
}
fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully without RR region on one of the nodes");
} catch (FunctionException e) {
if (e.getCause() instanceof RegionNotFoundException) {
LogWriterUtils.getLogWriter().info("Query received FunctionException successfully while using QueryService.");
} else {
fail("RegionNotFoundException must be thrown here");
}
}
}
});
LogWriterUtils.getLogWriter().info("PRQBasicQueryDUnitTest#testPRBasicQuerying: Querying PR's Test ENDED");
}
Aggregations