use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class MemoryMonitor method tryUploadHeapDumpIfItExists.
@VisibleForTesting
boolean tryUploadHeapDumpIfItExists() {
if (uploadFilePath == null) {
return false;
}
boolean uploadedHeapDump = false;
File localSource = getDefaultHeapDumpPath();
LOG.info("Looking for heap dump at {}", localSource);
if (localSource.exists()) {
LOG.warn("Heap dump {} detected, attempting to upload file to ", localSource);
String remoteDest = String.format("%s/heap_dump%s.hprof", uploadFilePath, UUID.randomUUID().toString());
ResourceId resource = FileSystems.matchNewResource(remoteDest, false);
try {
uploadFile(localSource, resource);
uploadedHeapDump = true;
LOG.warn("Heap dump {} uploaded to {}", localSource, remoteDest);
} catch (IOException e) {
LOG.error("Error uploading heap dump to {}", remoteDest, e);
}
try {
Files.delete(localSource.toPath());
LOG.info("Deleted local heap dump {}", localSource);
} catch (IOException e) {
LOG.warn("Unable to delete local heap dump {}", localSource, e);
}
}
return uploadedHeapDump;
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class MemoryMonitor method dumpHeap.
/**
* Dump the current heap profile to a file in the given directory and return its name.
*
* <p>NOTE: We deliberately don't salt the heap dump filename so as to minimize disk impact of
* repeated dumps. These files can be of comparable size to the local disk.
*/
@VisibleForTesting
static synchronized File dumpHeap(File directory) throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, MBeanException, IOException {
boolean liveObjectsOnly = false;
File fileName = new File(directory, "heap_dump.hprof");
if (fileName.exists() && !fileName.delete()) {
throw new IOException("heap_dump.hprof already existed and couldn't be deleted!");
}
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName oname = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
Object[] parameters = { fileName.getPath(), liveObjectsOnly };
String[] signatures = { String.class.getName(), boolean.class.getName() };
mbs.invoke(oname, "dumpHeap", parameters, signatures);
if (java.nio.file.FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
Files.setPosixFilePermissions(fileName.toPath(), ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ));
} else {
fileName.setReadable(true, true);
}
LOG.warn("Heap dumped to {}", fileName);
return fileName;
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project flink by apache.
the class FlinkMetricContainer method getFlinkMetricIdentifierString.
@VisibleForTesting
static String getFlinkMetricIdentifierString(MetricKey metricKey) {
MetricName metricName = metricKey.metricName();
ArrayList<String> scopeComponents = getNameSpaceArray(metricKey);
List<String> results = scopeComponents.subList(0, scopeComponents.size() / 2);
results.add(metricName.getName());
return String.join(METRIC_KEY_SEPARATOR, results);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class LengthPrefixUnknownCoders method forParallelInstruction.
/**
* Wrap unknown coders with a {@link LengthPrefixCoder} for the given {@link ParallelInstruction}.
*/
@VisibleForTesting
static ParallelInstruction forParallelInstruction(ParallelInstruction input, boolean replaceWithByteArrayCoder) throws Exception {
try {
ParallelInstruction instruction = clone(input, ParallelInstruction.class);
if (instruction.getRead() != null) {
Source cloudSource = instruction.getRead().getSource();
cloudSource.setCodec(forCodec(cloudSource.getCodec(), replaceWithByteArrayCoder));
} else if (instruction.getWrite() != null) {
com.google.api.services.dataflow.model.Sink cloudSink = instruction.getWrite().getSink();
cloudSink.setCodec(forCodec(cloudSink.getCodec(), replaceWithByteArrayCoder));
} else if (instruction.getParDo() != null) {
instruction.setParDo(forParDoInstruction(instruction.getParDo(), replaceWithByteArrayCoder));
} else if (instruction.getPartialGroupByKey() != null) {
PartialGroupByKeyInstruction pgbk = instruction.getPartialGroupByKey();
pgbk.setInputElementCodec(forCodec(pgbk.getInputElementCodec(), replaceWithByteArrayCoder));
} else if (instruction.getFlatten() != null) {
// FlattenInstructions have no codecs to wrap.
} else {
throw new RuntimeException("Unknown parallel instruction: " + input);
}
return instruction;
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to replace unknown coder with " + "LengthPrefixCoder for : {%s}", input), e);
}
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.
the class RemoteGrpcPortWriteOperation method shouldWait.
/**
* Attempt to bound the amount of unconsumed data written to the buffer in absolute time.
*/
@VisibleForTesting
boolean shouldWait() throws Exception {
if (!usingElementsProcessed) {
return false;
}
int numSent = elementsSent.get();
if (numSent >= targetElementsSent) {
if (elementsFlushed < numSent) {
receiver.flush();
elementsFlushed = numSent;
}
int numProcessed = elementsProcessed.get();
// Otherwise, wait until the SDK has processed at least one element before continuing.
if (numProcessed < 0) {
targetElementsSent = Integer.MAX_VALUE;
} else if (numProcessed == 0) {
targetElementsSent = 1;
} else {
double rate;
if (numProcessed == 1) {
rate = (double) numProcessed / (currentTimeMillis.get() - firstElementSentMillis);
} else {
rate = ((double) numProcessed - 1) / (currentTimeMillis.get() - secondElementSentMillis);
}
// Note that numProcessed is always increasing up to numSent, and rate is always positive,
// so eventually we'll return True.
targetElementsSent = (int) Math.min(numProcessed + rate * MAX_BUFFER_MILLIS + 1, Integer.MAX_VALUE);
}
}
return numSent >= targetElementsSent;
}
Aggregations