use of org.apache.geode.GemFireIOException in project geode by apache.
the class CacheServerImpl method getAttribFactoryForClientMessagesRegion.
public static AttributesFactory getAttribFactoryForClientMessagesRegion(InternalCache cache, String ePolicy, int capacity, String overflowDir, boolean isDiskStore) throws InvalidValueException, GemFireIOException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
if (isDiskStore) {
// overflowDir parameter is actually diskstore name
factory.setDiskStoreName(overflowDir);
// client subscription queue is always overflow to disk, so do async
// see feature request #41479
factory.setDiskSynchronous(true);
} else if (overflowDir == null || overflowDir.equals(ClientSubscriptionConfig.DEFAULT_OVERFLOW_DIRECTORY)) {
factory.setDiskStoreName(null);
// client subscription queue is always overflow to disk, so do async
// see feature request #41479
factory.setDiskSynchronous(true);
} else {
File dir = new File(overflowDir + File.separatorChar + generateNameForClientMsgsRegion(OSProcess.getId()));
// This will delete the overflow directory when virtual machine terminates.
dir.deleteOnExit();
if (!dir.mkdirs() && !dir.isDirectory()) {
throw new GemFireIOException("Could not create client subscription overflow directory: " + dir.getAbsolutePath());
}
File[] dirs = { dir };
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setAutoCompact(true).setDiskDirsAndSizes(dirs, new int[] { MAX_VALUE }).create("bsi");
factory.setDiskStoreName("bsi");
// backward compatibility, it was sync
factory.setDiskSynchronous(true);
}
factory.setDataPolicy(DataPolicy.NORMAL);
// enable statistics
factory.setStatisticsEnabled(true);
/* setting LIFO related eviction attributes */
if (HARegionQueue.HA_EVICTION_POLICY_ENTRY.equals(ePolicy)) {
factory.setEvictionAttributes(EvictionAttributes.createLIFOEntryAttributes(capacity, EvictionAction.OVERFLOW_TO_DISK));
} else if (HARegionQueue.HA_EVICTION_POLICY_MEMORY.equals(ePolicy)) {
// condition refinement
factory.setEvictionAttributes(EvictionAttributes.createLIFOMemoryAttributes(capacity, EvictionAction.OVERFLOW_TO_DISK));
} else {
// throw invalid eviction policy exception
throw new InvalidValueException(LocalizedStrings.CacheServerImpl__0_INVALID_EVICTION_POLICY.toLocalizedString(ePolicy));
}
return factory;
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class JGroupsMessenger method waitForMessageState.
@Override
public void waitForMessageState(InternalDistributedMember sender, Map state) throws InterruptedException {
Long seqno = (Long) state.get("JGroups.mcastState");
if (seqno == null) {
return;
}
long timeout = services.getConfig().getDistributionConfig().getAckWaitThreshold() * 1000L;
long startTime = System.currentTimeMillis();
long warnTime = startTime + timeout;
long quitTime = warnTime + timeout - 1000L;
boolean warned = false;
for (; ; ) {
String received = "none";
long highSeqno = 0;
synchronized (scheduledMcastSeqnos) {
MessageTracker tracker = scheduledMcastSeqnos.get(sender);
if (tracker == null) {
// no longer in the membership view
break;
}
highSeqno = tracker.get();
}
if (logger.isDebugEnabled()) {
logger.debug("waiting for multicast messages from {}. Current seqno={} and expected seqno={}", sender, highSeqno, seqno);
}
if (highSeqno >= seqno.longValue()) {
break;
}
long now = System.currentTimeMillis();
if (!warned && now >= warnTime) {
warned = true;
received = String.valueOf(highSeqno);
logger.warn("{} seconds have elapsed while waiting for multicast messages from {}. Received {} but expecting at least {}.", Long.toString((warnTime - startTime) / 1000L), sender, received, seqno);
}
if (now >= quitTime) {
throw new GemFireIOException("Multicast operations from " + sender + " did not distribute within " + (now - startTime) + " milliseconds");
}
Thread.sleep(50);
}
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class JGroupsMessenger method createJGMessage.
/**
* This is the constructor to use to create a JGroups message holding a GemFire
* DistributionMessage. It sets the appropriate flags in the Message and properly serializes the
* DistributionMessage for the recipient's product version
*
* @param gfmsg the DistributionMessage
* @param src the sender address
* @param version the version of the recipient
* @return the new message
*/
Message createJGMessage(DistributionMessage gfmsg, JGAddress src, short version) {
if (gfmsg instanceof DirectReplyMessage) {
((DirectReplyMessage) gfmsg).registerProcessor();
}
Message msg = new Message();
msg.setDest(null);
msg.setSrc(src);
setMessageFlags(gfmsg, msg);
try {
long start = services.getStatistics().startMsgSerialization();
HeapDataOutputStream out_stream = new HeapDataOutputStream(Version.fromOrdinalOrCurrent(version));
Version.CURRENT.writeOrdinal(out_stream, true);
if (encrypt != null) {
out_stream.writeBoolean(true);
writeEncryptedMessage(gfmsg, version, out_stream);
} else {
out_stream.writeBoolean(false);
serializeMessage(gfmsg, out_stream);
}
msg.setBuffer(out_stream.toByteArray());
services.getStatistics().endMsgSerialization(start);
} catch (IOException | GemFireIOException ex) {
logger.warn("Error serializing message", ex);
if (ex instanceof GemFireIOException) {
throw (GemFireIOException) ex;
} else {
GemFireIOException ioe = new GemFireIOException("Error serializing message");
ioe.initCause(ex);
throw ioe;
}
} catch (Exception ex) {
logger.warn("Error serializing message", ex);
GemFireIOException ioe = new GemFireIOException("Error serializing message");
ioe.initCause(ex.getCause());
throw ioe;
}
return msg;
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class StatArchiveWriter method sampled.
public void sampled(long nanosTimeStamp, List<ResourceInstance> resourceInstances) {
if (logger.isTraceEnabled(LogMarker.STATISTICS)) {
logger.trace(LogMarker.STATISTICS, "StatArchiveWriter#sampled nanosTimeStamp={}, resourceInstances={}", nanosTimeStamp, resourceInstances);
}
try {
this.dataOut.writeByte(SAMPLE_TOKEN);
if (this.trace) {
this.traceDataOut.println("sampled#writeByte SAMPLE_TOKEN: " + SAMPLE_TOKEN);
}
writeTimeStamp(nanosTimeStamp);
for (ResourceInstance ri : resourceInstances) {
writeSample(ri);
}
writeResourceInst(ILLEGAL_RESOURCE_INST_ID);
this.dataOut.flush();
if (this.trace) {
this.traceDataOut.flush();
}
} catch (IOException ex) {
throw new GemFireIOException(LocalizedStrings.StatArchiveWriter_FAILED_WRITING_SAMPLE_TO_STATISTIC_ARCHIVE.toLocalizedString(), ex);
}
// only inc after sample done w/o an exception thrown
this.sampleCount++;
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class StatArchiveWriter method allocatedResourceInstance.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "This is only for debugging and there is never more than one instance being traced because there is only one stat sampler.")
public void allocatedResourceInstance(ResourceInstance statResource) {
if (logger.isTraceEnabled(LogMarker.STATISTICS)) {
logger.trace(LogMarker.STATISTICS, "StatArchiveWriter#allocatedResourceInstance statResource={}", statResource);
}
if (statResource.getResourceType().getStatisticDescriptors().length >= ILLEGAL_STAT_OFFSET) {
throw new InternalGemFireException(LocalizedStrings.StatArchiveWriter_COULD_NOT_ARCHIVE_TYPE_0_BECAUSE_IT_HAD_MORE_THAN_1_STATISTICS.toLocalizedString(new Object[] { statResource.getResourceType().getStatisticsType().getName(), Integer.valueOf(ILLEGAL_STAT_OFFSET - 1) }));
}
if (statResource.getStatistics().isClosed()) {
return;
}
this.addedResources.add(statResource);
try {
this.dataOut.writeByte(RESOURCE_INSTANCE_CREATE_TOKEN);
this.dataOut.writeInt(statResource.getId());
this.dataOut.writeUTF(statResource.getStatistics().getTextId());
this.dataOut.writeLong(statResource.getStatistics().getNumericId());
this.dataOut.writeInt(statResource.getResourceType().getId());
if (this.trace && (traceStatisticsName == null || traceStatisticsName.equals(statResource.getStatistics().getTextId())) && (traceStatisticsTypeName == null || traceStatisticsTypeName.equals(statResource.getResourceType().getStatisticsType().getName()))) {
traceResourceInstId = statResource.getId();
this.traceDataOut.println("writeHeader traceResourceInstId: " + traceResourceInstId);
this.traceDataOut.println("allocatedResourceInstance#writeByte RESOURCE_INSTANCE_CREATE_TOKEN: " + RESOURCE_INSTANCE_CREATE_TOKEN);
this.traceDataOut.println("allocatedResourceInstance#writeInt statResource.getId(): " + statResource.getId());
this.traceDataOut.println("allocatedResourceInstance#writeUTF statResource.getStatistics().getTextId(): " + statResource.getStatistics().getTextId());
this.traceDataOut.println("allocatedResourceInstance#writeLong statResource.getStatistics().getNumericId(): " + statResource.getStatistics().getNumericId());
this.traceDataOut.println("allocatedResourceInstance#writeInt statResource.getResourceType().getId(): " + statResource.getResourceType().getId());
}
} catch (IOException ex) {
throw new GemFireIOException(LocalizedStrings.StatArchiveWriter_FAILED_WRITING_NEW_RESOURCE_INSTANCE_TO_STATISTIC_ARCHIVE.toLocalizedString(), ex);
}
}
Aggregations