Search in sources :

Example 61 with VisibleForTesting

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;
}
Also used : ResourceId(org.apache.beam.sdk.io.fs.ResourceId) IOException(java.io.IOException) File(java.io.File) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 62 with VisibleForTesting

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;
}
Also used : IOException(java.io.IOException) File(java.io.File) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 63 with VisibleForTesting

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);
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 64 with VisibleForTesting

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);
    }
}
Also used : ParallelInstruction(com.google.api.services.dataflow.model.ParallelInstruction) PartialGroupByKeyInstruction(com.google.api.services.dataflow.model.PartialGroupByKeyInstruction) IOException(java.io.IOException) Source(com.google.api.services.dataflow.model.Source) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 65 with VisibleForTesting

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;
}
Also used : LogicalEndpoint(org.apache.beam.sdk.fn.data.LogicalEndpoint) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)81 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)17 ParameterizedType (java.lang.reflect.ParameterizedType)15 Type (java.lang.reflect.Type)15 Parameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter)14 BundleFinalizerParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.BundleFinalizerParameter)14 PipelineOptionsParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.PipelineOptionsParameter)14 RestrictionParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.RestrictionParameter)14 RestrictionTrackerParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.RestrictionTrackerParameter)14 SchemaElementParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.SchemaElementParameter)14 StateParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.StateParameter)14 TimerFamilyParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.TimerFamilyParameter)14 TimerParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.TimerParameter)14 WatermarkEstimatorParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.WatermarkEstimatorParameter)14 WatermarkEstimatorStateParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.WatermarkEstimatorStateParameter)14 WindowParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.WindowParameter)14 TypeParameter (org.apache.beam.sdk.values.TypeParameter)14 DoFn (org.apache.beam.sdk.transforms.DoFn)10 Map (java.util.Map)7