use of org.apache.geode.LogWriter in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForRemoveIndex.
/**
* Cacheserializable runnable which removes all the index on a partitioned region
*
* @param name name of the partitioned regions
* @return CacheSerializableRunnable
*/
public CacheSerializableRunnable getCacheSerializableRunnableForRemoveIndex(final String name, final boolean random) {
return new CacheSerializableRunnable("PrRemoveIndex") {
@Override
public void run2() {
Cache cache1 = getCache();
LogWriter logger = cache1.getLogger();
logger.info("Got the following cache : " + cache1);
Region parRegion = cache1.getRegion(name);
QueryService qs = cache1.getQueryService();
if (!random) {
Collection indexes = qs.getIndexes();
assertEquals(3, indexes.size());
Iterator it = indexes.iterator();
while (it.hasNext()) logger.info("Following indexes found : " + it.next());
qs.removeIndexes(parRegion);
logger.info("Removed all the index on this paritioned regions : " + parRegion);
indexes = qs.getIndexes();
assertEquals(0, ((LocalRegion) parRegion).getIndexManager().getIndexes().size());
assertEquals(0, indexes.size());
// should not cause any kind of exception just a check.
qs.removeIndexes(parRegion);
} else {
// pick a random index and remvoe it
Collection indexes = qs.getIndexes(parRegion);
assertEquals(3, indexes.size());
assertEquals(3, ((LocalRegion) parRegion).getIndexManager().getIndexes().size());
synchronized (indexes) {
Iterator it = indexes.iterator();
while (it.hasNext()) {
Index in = (Index) it.next();
qs.removeIndex(in);
}
}
indexes = qs.getIndexes(parRegion);
assertEquals(0, indexes.size());
assertEquals(0, ((LocalRegion) parRegion).getIndexManager().getIndexes().size());
}
}
};
}
use of org.apache.geode.LogWriter in project geode by apache.
the class StructSetOrResultsSet method compareQueryResultsWithExternallySortedResults.
private void compareQueryResultsWithExternallySortedResults(SelectResults sr, Object[] externallySorted, String query, Wrapper wrapper) {
if (sr.size() == externallySorted.length) {
CacheUtils.log("Both SelectResults are of Same Size i.e. Size= " + sr.size());
} else {
fail("FAILED:SelectResults size is different in both the cases. Size1=" + sr.size() + " Size2 = " + externallySorted.length + "; failed query=" + query);
}
Collection coll1 = null;
coll1 = sr.asList();
int j = 0;
if (wrapper.validationLevel != ValidationLevel.ORDER_BY_ONLY) {
for (Object o : externallySorted) {
boolean removed = coll1.remove(o);
if (!removed) {
LogWriter logger = CacheUtils.getLogger();
logger.error("order by inconsistency at element index = " + j);
logger.error(" query result =****");
logger.error(" query result =" + coll1.toString());
logger.error(" query result elementType=" + sr.getCollectionType().getElementType());
logger.error(" externally sorted result =****");
logger.error(ArrayUtils.toString(externallySorted));
fail("failed query due to element mismatch=" + query);
}
++j;
}
assertTrue(coll1.isEmpty());
}
if (wrapper.validationLevel != ValidationLevel.MATCH_ONLY) {
coll1 = sr.asList();
Iterator itert1 = coll1.iterator();
int i = 0;
for (Object o : externallySorted) {
if (wrapper.obc.compare(o, itert1.next()) != 0) {
LogWriter logger = CacheUtils.getLogger();
logger.error("order by inconsistency at element index = " + i);
logger.error(" query result =****");
logger.error(" query result =" + coll1.toString());
logger.error(" externally sorted result =****");
logger.error(ArrayUtils.toString(externallySorted));
fail("failed query due to order mismatch=" + query);
}
++i;
}
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class HeapEvictor method onEvent.
@Override
public void onEvent(final MemoryEvent event) {
if (DISABLE_HEAP_EVICTIOR_THREAD_POOL) {
return;
}
// in this VM ...
if (isRunning() && event.isLocal()) {
if (event.getState().isEviction()) {
final LogWriter logWriter = cache.getLogger();
// Have we previously received an eviction event and already started eviction ...
if (this.mustEvict.get() == true) {
if (logWriter.fineEnabled()) {
logWriter.fine("Updating eviction in response to memory event: " + event + ". previousBytesUsed=" + previousBytesUsed);
}
// to update the number of fast loops to perform.
synchronized (evictionLock) {
numEvictionLoopsCompleted = 0;
numFastLoops = (int) ((event.getBytesUsed() - event.getThresholds().getEvictionThresholdClearBytes() + getTotalBytesToEvict()) / getTotalBytesToEvict());
evictionLock.notifyAll();
}
// already a thread running the evictions, so we're done.
return;
}
if (!this.mustEvict.compareAndSet(false, true)) {
// Another thread just started evicting.
return;
}
numEvictionLoopsCompleted = 0;
numFastLoops = (int) ((event.getBytesUsed() - event.getThresholds().getEvictionThresholdClearBytes() + getTotalBytesToEvict()) / getTotalBytesToEvict());
if (logWriter.fineEnabled()) {
logWriter.fine("Starting eviction in response to memory event: " + event);
}
// The new thread which will run in a loop performing evictions
final Runnable evictionManagerTask = new Runnable() {
@Override
public void run() {
// Has the test hook been set which will cause eviction to abort early
if (numEvictionLoopsCompleted < testAbortAfterLoopCount) {
try {
// Submit tasks into the queue to do the evictions
if (EVICT_HIGH_ENTRY_COUNT_BUCKETS_FIRST) {
createAndSubmitWeightedRegionEvictionTasks();
} else {
for (RegionEvictorTask task : createRegionEvictionTasks()) {
executeInThreadPool(task);
}
}
RegionEvictorTask.setLastTaskCompletionTime(System.currentTimeMillis());
// and changing the number of fast loops to perform.
synchronized (evictionLock) {
int delayTime = getEvictionLoopDelayTime();
if (logWriter.fineEnabled()) {
logWriter.fine("Eviction loop delay time calculated to be " + delayTime + " milliseconds. Fast Loops=" + numFastLoops + ", Loop #=" + numEvictionLoopsCompleted + 1);
}
numEvictionLoopsCompleted++;
try {
// Wait and release the lock so that the number of fast loops
// needed can be updated by another thread processing a new
// eviction event.
evictionLock.wait(delayTime);
} catch (InterruptedException iex) {
// Loop and try again
}
}
// Do we think we're still above the eviction threshold ...
if (HeapEvictor.this.mustEvict.get()) {
// Submit this runnable back into the thread pool and execute
// another pass at eviction.
executeInThreadPool(this);
}
} catch (RegionDestroyedException e) {
// logging an error message. fixes bug 48162
if (HeapEvictor.this.mustEvict.get()) {
executeInThreadPool(this);
}
}
}
}
};
// Submit the first pass at eviction into the pool
executeInThreadPool(evictionManagerTask);
} else {
this.mustEvict.set(false);
}
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class LocalRegion method postCreateRegion.
/**
* Called after this region has been completely created
*
* @since GemFire 5.0
*
* @see DistributedRegion#postDestroyRegion(boolean, RegionEventImpl)
*/
protected void postCreateRegion() {
if (getEvictionAttributes().getAlgorithm().isLRUHeap()) {
final LogWriter logWriter = this.cache.getLogger();
float evictionPercentage = DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE;
// This is new to 6.5. If a heap lru region is created
// we make sure that the eviction percentage is enabled.
InternalResourceManager rm = this.cache.getInternalResourceManager();
if (!getOffHeap()) {
if (!rm.getHeapMonitor().hasEvictionThreshold()) {
float criticalPercentage = rm.getCriticalHeapPercentage();
if (criticalPercentage > 0.0f) {
if (criticalPercentage >= 10.f) {
evictionPercentage = criticalPercentage - 5.0f;
} else {
evictionPercentage = criticalPercentage;
}
}
rm.setEvictionHeapPercentage(evictionPercentage);
if (logWriter.fineEnabled()) {
logWriter.fine("Enabled heap eviction at " + evictionPercentage + " percent for LRU region");
}
}
} else {
if (!rm.getOffHeapMonitor().hasEvictionThreshold()) {
float criticalPercentage = rm.getCriticalOffHeapPercentage();
if (criticalPercentage > 0.0f) {
if (criticalPercentage >= 10.f) {
evictionPercentage = criticalPercentage - 5.0f;
} else {
evictionPercentage = criticalPercentage;
}
}
rm.setEvictionOffHeapPercentage(evictionPercentage);
if (logWriter.fineEnabled()) {
logWriter.fine("Enabled off-heap eviction at " + evictionPercentage + " percent for LRU region");
}
}
}
}
if (!isInternalRegion()) {
getCachePerfStats().incRegions(1);
if (getMembershipAttributes().hasRequiredRoles()) {
getCachePerfStats().incReliableRegions(1);
}
}
if (hasListener()) {
RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_CREATE, null, false, getMyId());
dispatchListenerEvent(EnumListenerEvent.AFTER_REGION_CREATE, event);
}
releaseAfterRegionCreateEventLatch();
SystemMemberCacheEventProcessor.send(getCache(), this, Operation.REGION_CREATE);
initializingRegion.remove();
}
use of org.apache.geode.LogWriter in project geode by apache.
the class XmlAuthorization method init.
/**
* Cache authorization information for all users statically. This method is not thread-safe and is
* should either be invoked only once, or the caller should take the appropriate locks.
*
* @param cache reference to the cache object for the distributed system
*/
private static void init(final Cache cache) throws NotAuthorizedException {
final LogWriter systemLogWriter = cache.getLogger();
final String xmlDocumentUri = (String) cache.getDistributedSystem().getSecurityProperties().get(DOC_URI_PROP_NAME);
try {
if (xmlDocumentUri == null) {
throw new NotAuthorizedException("No ACL file defined using tag [" + DOC_URI_PROP_NAME + "] in system properties");
}
if (xmlDocumentUri.equals(XmlAuthorization.currentDocUri)) {
if (XmlAuthorization.xmlLoadFailure != null) {
throw XmlAuthorization.xmlLoadFailure;
}
return;
}
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setValidating(true);
final DocumentBuilder builder = factory.newDocumentBuilder();
final XmlErrorHandler errorHandler = new XmlErrorHandler(systemLogWriter, xmlDocumentUri);
builder.setErrorHandler(errorHandler);
builder.setEntityResolver(new AuthzDtdResolver());
final Document xmlDocument = builder.parse(xmlDocumentUri);
XmlAuthorization.userRoles = new HashMap<String, HashSet<String>>();
XmlAuthorization.rolePermissions = new HashMap<String, Map<String, Map<OperationCode, FunctionSecurityPrmsHolder>>>();
final NodeList roleUserNodes = xmlDocument.getElementsByTagName(TAG_ROLE);
for (int roleIndex = 0; roleIndex < roleUserNodes.getLength(); roleIndex++) {
final Node roleUserNode = roleUserNodes.item(roleIndex);
final String roleName = getAttributeValue(roleUserNode, ATTR_ROLENAME);
final NodeList userNodes = roleUserNode.getChildNodes();
for (int userIndex = 0; userIndex < userNodes.getLength(); userIndex++) {
final Node userNode = userNodes.item(userIndex);
if (TAG_USER.equals(userNode.getNodeName())) {
final String userName = getNodeValue(userNode);
HashSet<String> userRoleSet = XmlAuthorization.userRoles.get(userName);
if (userRoleSet == null) {
userRoleSet = new HashSet<String>();
XmlAuthorization.userRoles.put(userName, userRoleSet);
}
userRoleSet.add(roleName);
} else {
throw new SAXParseException("Unknown tag [" + userNode.getNodeName() + "] as child of tag [" + TAG_ROLE + ']', null);
}
}
}
final NodeList rolePermissionNodes = xmlDocument.getElementsByTagName(TAG_PERMS);
for (int permIndex = 0; permIndex < rolePermissionNodes.getLength(); permIndex++) {
final Node rolePermissionNode = rolePermissionNodes.item(permIndex);
final String roleName = getAttributeValue(rolePermissionNode, ATTR_ROLE);
Map<String, Map<OperationCode, FunctionSecurityPrmsHolder>> regionOperationMap = XmlAuthorization.rolePermissions.get(roleName);
if (regionOperationMap == null) {
regionOperationMap = new HashMap<String, Map<OperationCode, FunctionSecurityPrmsHolder>>();
XmlAuthorization.rolePermissions.put(roleName, regionOperationMap);
}
final NodeList operationNodes = rolePermissionNode.getChildNodes();
final HashMap<OperationCode, FunctionSecurityPrmsHolder> operationMap = new HashMap<OperationCode, FunctionSecurityPrmsHolder>();
for (int opIndex = 0; opIndex < operationNodes.getLength(); opIndex++) {
final Node operationNode = operationNodes.item(opIndex);
if (TAG_OP.equals(operationNode.getNodeName())) {
final String operationName = getNodeValue(operationNode);
final OperationCode code = OperationCode.valueOf(operationName);
if (code == null) {
throw new SAXParseException("Unknown operation [" + operationName + ']', null);
}
if (code != OperationCode.EXECUTE_FUNCTION) {
operationMap.put(code, null);
} else {
final String optimizeForWrite = getAttributeValue(operationNode, ATTR_FUNCTION_OPTIMIZE_FOR_WRITE);
final String functionAttr = getAttributeValue(operationNode, ATTR_FUNCTION_IDS);
final String keysAttr = getAttributeValue(operationNode, ATTR_FUNCTION_KEY_SET);
Boolean isOptimizeForWrite;
HashSet<String> functionIds;
HashSet<String> keySet;
if (optimizeForWrite == null || optimizeForWrite.length() == 0) {
isOptimizeForWrite = null;
} else {
isOptimizeForWrite = Boolean.parseBoolean(optimizeForWrite);
}
if (functionAttr == null || functionAttr.length() == 0) {
functionIds = null;
} else {
final String[] functionArray = functionAttr.split(",");
functionIds = new HashSet<String>();
for (int strIndex = 0; strIndex < functionArray.length; ++strIndex) {
functionIds.add((functionArray[strIndex]));
}
}
if (keysAttr == null || keysAttr.length() == 0) {
keySet = null;
} else {
final String[] keySetArray = keysAttr.split(",");
keySet = new HashSet<String>();
for (int strIndex = 0; strIndex < keySetArray.length; ++strIndex) {
keySet.add((keySetArray[strIndex]));
}
}
final FunctionSecurityPrmsHolder functionContext = new FunctionSecurityPrmsHolder(isOptimizeForWrite, functionIds, keySet);
operationMap.put(code, functionContext);
}
} else {
throw new SAXParseException("Unknown tag [" + operationNode.getNodeName() + "] as child of tag [" + TAG_PERMS + ']', null);
}
}
final String regionNames = getAttributeValue(rolePermissionNode, ATTR_REGIONS);
if (regionNames == null || regionNames.length() == 0) {
regionOperationMap.put(EMPTY_VALUE, operationMap);
} else {
final String[] regionNamesSplit = regionNames.split(",");
for (int strIndex = 0; strIndex < regionNamesSplit.length; ++strIndex) {
regionOperationMap.put(normalizeRegionName(regionNamesSplit[strIndex]), operationMap);
}
}
}
XmlAuthorization.currentDocUri = xmlDocumentUri;
} catch (Exception ex) {
String message;
if (ex instanceof NotAuthorizedException) {
message = ex.getMessage();
} else {
message = ex.getClass().getName() + ": " + ex.getMessage();
}
systemLogWriter.warning("XmlAuthorization.init: " + message);
XmlAuthorization.xmlLoadFailure = new NotAuthorizedException(message, ex);
throw XmlAuthorization.xmlLoadFailure;
}
}
Aggregations