use of org.apache.geode.GemFireIOException in project geode by apache.
the class StatArchiveWriter method destroyedResourceInstance.
public void destroyedResourceInstance(ResourceInstance resourceInstance) {
if (logger.isTraceEnabled(LogMarker.STATISTICS)) {
logger.trace(LogMarker.STATISTICS, "StatArchiveWriter#destroyedResourceInstance resourceInstance={}", resourceInstance);
}
if (!this.addedResources.contains(resourceInstance)) {
// Fix for bug #45377
return;
}
this.sampleWrittenForResources.remove(resourceInstance);
this.addedResources.remove(resourceInstance);
try {
this.dataOut.writeByte(RESOURCE_INSTANCE_DELETE_TOKEN);
this.dataOut.writeInt(resourceInstance.getId());
if (this.trace && (traceStatisticsName == null || traceStatisticsName.equals(resourceInstance.getStatistics().getTextId())) && (traceStatisticsTypeName == null || traceStatisticsTypeName.equals(resourceInstance.getResourceType().getStatisticsType().getName()))) {
this.traceDataOut.println("destroyedResourceInstance#writeByte RESOURCE_INSTANCE_DELETE_TOKEN: " + RESOURCE_INSTANCE_DELETE_TOKEN);
this.traceDataOut.println("destroyedResourceInstance#writeInt resourceInstance.getId(): " + resourceInstance.getId());
}
} catch (IOException ex) {
throw new GemFireIOException(LocalizedStrings.StatArchiveWriter_FAILED_WRITING_DELETE_RESOURCE_INSTANCE_TO_STATISTIC_ARCHIVE.toLocalizedString(), ex);
}
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class StatArchiveHandler method changeArchiveFile.
/**
* Changes the archive file to the new file or disables archiving if an empty string is specified.
* <p/>
* If the file name matches any archive file(s) already in {@link #archiveDir} then this may
* trigger rolling and/or removal if appropriate based on
* {@link StatArchiveHandlerConfig#getArchiveFileSizeLimit() file size limit} and
* {@link StatArchiveHandlerConfig#getArchiveDiskSpaceLimit() disk space limit}.
* <p/>
* If resetHandler is true, then this handler will reset itself with the SampleCollector by
* removing and re-adding itself in order to receive allocation notifications about all resource
* types and instances.
*
* @param newFile
* @param resetHandler
* @param nanosTimeStamp
*/
private void changeArchiveFile(File newFile, boolean resetHandler, long nanosTimeStamp) {
final boolean isDebugEnabled_STATISTICS = logger.isTraceEnabled(LogMarker.STATISTICS);
if (isDebugEnabled_STATISTICS) {
logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile newFile={}, nanosTimeStamp={}", newFile, nanosTimeStamp);
}
StatArchiveWriter newArchiver = null;
boolean archiveClosed = false;
if (newFile.getPath().equals("")) {
// disable archiving
if (!this.disabledArchiving) {
this.disabledArchiving = true;
logger.info(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_DISABLING_STATISTIC_ARCHIVAL));
}
} else {
this.disabledArchiving = false;
if (this.config.getArchiveFileSizeLimit() != 0) {
// to getRollingArchiveName(newFile).
if (archiver != null) {
archiveClosed = true;
synchronized (this) {
if (resetHandler) {
if (isDebugEnabled_STATISTICS) {
logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile removing handler");
}
this.collector.removeSampleHandler(this);
}
try {
archiver.close();
} catch (GemFireException ignore) {
logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_STATISTIC_ARCHIVE_CLOSE_FAILED_BECAUSE__0, ignore.getMessage()));
}
}
}
}
if (newFile.exists()) {
File oldFile;
if (this.config.getArchiveFileSizeLimit() != 0) {
oldFile = getRollingArchiveName(newFile, archiveClosed);
} else {
oldFile = getRenameArchiveName(newFile);
}
if (!newFile.renameTo(oldFile)) {
logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_COULD_NOT_RENAME_0_TO_1, new Object[] { newFile, oldFile }));
} else {
logger.info(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_RENAMED_OLD_EXISTING_ARCHIVE_TO__0_, oldFile));
}
} else {
if (!newFile.getAbsoluteFile().getParentFile().equals(archiveDir)) {
this.archiveDir = newFile.getAbsoluteFile().getParentFile();
if (!this.archiveDir.exists()) {
this.archiveDir.mkdirs();
}
}
if (this.config.getArchiveFileSizeLimit() != 0) {
initMainArchiveId(newFile);
}
}
try {
StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(newFile.getAbsolutePath()).setSystemId(this.config.getSystemId()).setSystemStartTime(this.config.getSystemStartTime()).setSystemDirectoryPath(this.config.getSystemDirectoryPath()).setProductDescription(this.config.getProductDescription()).build();
newArchiver = new StatArchiveWriter(archiveDescriptor);
newArchiver.initialize(nanosTimeStamp);
} catch (GemFireIOException ex) {
logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_COULD_NOT_OPEN_STATISTIC_ARCHIVE_0_CAUSE_1, new Object[] { newFile, ex.getLocalizedMessage() }));
throw ex;
}
}
synchronized (this) {
if (archiveClosed) {
if (archiver != null) {
removeOldArchives(newFile, this.config.getArchiveDiskSpaceLimit());
}
} else {
if (resetHandler) {
if (isDebugEnabled_STATISTICS) {
logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile removing handler");
}
this.collector.removeSampleHandler(this);
}
if (archiver != null) {
try {
archiver.close();
} catch (GemFireException ignore) {
logger.warn(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_STATISTIC_ARCHIVE_CLOSE_FAILED_BECAUSE__0, ignore.getMessage()));
}
removeOldArchives(newFile, this.config.getArchiveDiskSpaceLimit());
}
}
archiver = newArchiver;
if (resetHandler && newArchiver != null) {
if (isDebugEnabled_STATISTICS) {
logger.trace(LogMarker.STATISTICS, "StatArchiveHandler#changeArchiveFile adding handler");
}
this.collector.addSampleHandler(this);
}
}
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class DiskStoreCommands method upgradeOfflineDiskStore.
@CliCommand(value = CliStrings.UPGRADE_OFFLINE_DISK_STORE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
public Result upgradeOfflineDiskStore(@CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME, mandatory = true, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS__HELP) String[] diskDirs, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE, unspecifiedDefaultValue = "-1", help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE__HELP) long maxOplogSize, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J__HELP) String[] jvmProps) throws InterruptedException {
Result result = null;
LogWrapper logWrapper = LogWrapper.getInstance();
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
String errorMessage = "";
Process upgraderProcess = null;
try {
String validatedDirectories = validatedDirectories(diskDirs);
if (validatedDirectories != null) {
throw new IllegalArgumentException("Could not find " + CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS + ": \"" + validatedDirectories + "\"");
}
List<String> commandList = new ArrayList<String>();
commandList.add(System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + "java");
configureLogging(commandList);
if (jvmProps != null && jvmProps.length != 0) {
for (int i = 0; i < jvmProps.length; i++) {
commandList.add(jvmProps[i]);
}
}
commandList.add("-classpath");
commandList.add(System.getProperty("java.class.path", "."));
commandList.add(DiskStoreUpgrader.class.getName());
commandList.add(CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME + "=" + diskStoreName);
if (diskDirs != null && diskDirs.length != 0) {
StringBuilder builder = new StringBuilder();
int arrayLength = diskDirs.length;
for (int i = 0; i < arrayLength; i++) {
if (File.separatorChar == '\\') {
// see 46120
builder.append(diskDirs[i].replace("\\", "/"));
} else {
builder.append(diskDirs[i]);
}
if (i + 1 != arrayLength) {
builder.append(',');
}
}
commandList.add(CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS + "=" + builder.toString());
}
// -1 is ignore as maxOplogSize
commandList.add(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE + "=" + maxOplogSize);
ProcessBuilder procBuilder = new ProcessBuilder(commandList);
// procBuilder.redirectErrorStream(true);
upgraderProcess = procBuilder.start();
InputStream inputStream = upgraderProcess.getInputStream();
InputStream errorStream = upgraderProcess.getErrorStream();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream));
BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream));
String line = null;
while ((line = inputReader.readLine()) != null) {
output.append(line).append(GfshParser.LINE_SEPARATOR);
}
line = null;
boolean switchToStackTrace = false;
while ((line = errorReader.readLine()) != null) {
if (!switchToStackTrace && DiskStoreUpgrader.STACKTRACE_START.equals(line)) {
switchToStackTrace = true;
} else if (switchToStackTrace) {
error.append(line).append(GfshParser.LINE_SEPARATOR);
} else {
errorMessage = errorMessage + line;
}
}
if (!errorMessage.isEmpty()) {
throw new GemFireIOException(errorMessage);
}
upgraderProcess.destroy();
result = ResultBuilder.createInfoResult(output.toString());
} catch (IOException e) {
if (output.length() != 0) {
Gfsh.println(output.toString());
}
String fieldsMessage = (maxOplogSize != -1 ? CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE + "=" + maxOplogSize + "," : "");
fieldsMessage += CliUtil.arrayToString(diskDirs);
String errorString = CliStrings.format(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MSG__ERROR_WHILE_COMPACTING_DISKSTORE_0_WITH_1_REASON_2, new Object[] { diskStoreName, fieldsMessage });
result = ResultBuilder.createUserErrorResult(errorString);
if (logWrapper.fineEnabled()) {
logWrapper.fine(e.getMessage(), e);
}
} catch (GemFireIOException e) {
if (output.length() != 0) {
Gfsh.println(output.toString());
}
result = ResultBuilder.createUserErrorResult(errorMessage);
if (logWrapper.fineEnabled()) {
logWrapper.fine(error.toString());
}
} catch (IllegalArgumentException e) {
if (output.length() != 0) {
Gfsh.println(output.toString());
}
result = ResultBuilder.createUserErrorResult(e.getMessage());
} finally {
if (upgraderProcess != null) {
try {
// just to check whether the process has exited
// Process.exitValue() throws IllegalStateException if Process is alive
upgraderProcess.exitValue();
} catch (IllegalThreadStateException itse) {
// not yet terminated, destroy the process
upgraderProcess.destroy();
}
}
}
return result;
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class JGroupsMessengerJUnitTest method testSendUnreliably.
@Test
public void testSendUnreliably() throws Exception {
for (int i = 0; i < 2; i++) {
boolean enableMcast = (i == 1);
initMocks(enableMcast);
InternalDistributedMember mbr = createAddress(8888);
DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
when(msg.getMulticast()).thenReturn(enableMcast);
if (!enableMcast) {
// for non-mcast we send a message with a reply-processor
when(msg.getProcessorId()).thenReturn(1234);
} else {
// for mcast we send a direct-ack message and expect the messenger
// to register it
stub(msg.isDirectAck()).toReturn(true);
}
when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
interceptor.collectMessages = true;
try {
messenger.sendUnreliably(msg);
} catch (GemFireIOException e) {
fail("expected success");
}
if (enableMcast) {
verify(msg, atLeastOnce()).registerProcessor();
}
verify(msg).toData(isA(DataOutput.class));
assertTrue("expected 1 message but found " + interceptor.collectedMessages, interceptor.collectedMessages.size() == 1);
assertTrue(interceptor.collectedMessages.get(0).isFlagSet(Message.Flag.NO_RELIABILITY));
}
}
use of org.apache.geode.GemFireIOException in project geode by apache.
the class ClientServerMiscDUnitTest method testLargeMessageIsRejected.
/**
* GEODE-478 - large payloads are rejected by client->server
*/
@Test
public void testLargeMessageIsRejected() throws Exception {
PORT1 = initServerCache(false);
createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), PORT1);
Region region = static_cache.getRegion(REGION_NAME1);
Op operation = new Op() {
@Override
public Object attempt(Connection cnx) throws Exception {
throw new MessageTooLargeException("message is too big");
}
@Override
public boolean useThreadLocalConnection() {
return false;
}
};
try {
((LocalRegion) region).getServerProxy().getPool().execute(operation);
} catch (GemFireIOException e) {
assertTrue(e.getCause() instanceof MessageTooLargeException);
return;
}
fail("expected an exception to be thrown");
}
Aggregations