[Streaming]Format java code using IDEA (#10440)

This commit is contained in:
Lixin Wei
2020-08-31 19:45:00 +08:00
committed by GitHub
parent afde3db4f0
commit 6bde6b493e
125 changed files with 548 additions and 433 deletions
@@ -12,6 +12,7 @@ public interface CommonConfig extends Config {
/**
* Ray streaming job id. Non-custom.
*
* @return Job id with string type.
*/
@DefaultValue(value = "default-job-id")
@@ -20,6 +21,7 @@ public interface CommonConfig extends Config {
/**
* Ray streaming job name. Non-custom.
*
* @return Job name with string type.
*/
@DefaultValue(value = "default-job-name")
@@ -11,8 +11,7 @@ public interface SchedulerConfig extends Config {
String WORKER_STARTING_WAIT_TIMEOUT_MS = "streaming.scheduler.worker.starting.timeout.ms";
/**
* The timeout ms of worker initiation.
* Default is: 10000ms(10s).
* The timeout ms of worker initiation. Default is: 10000ms(10s).
*
* @return timeout ms
*/
@@ -21,8 +20,7 @@ public interface SchedulerConfig extends Config {
int workerInitiationWaitTimeoutMs();
/**
* The timeout ms of worker starting.
* Default is: 10000ms(10s).
* The timeout ms of worker starting. Default is: 10000ms(10s).
*
* @return timeout ms
*/
@@ -17,6 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OutputCollector implements Collector<Record> {
private static final Logger LOGGER = LoggerFactory.getLogger(OutputCollector.class);
private final DataWriter writer;
@@ -27,15 +28,17 @@ public class OutputCollector implements Collector<Record> {
private final Serializer javaSerializer = new JavaSerializer();
private final Serializer crossLangSerializer = new CrossLangSerializer();
public OutputCollector(DataWriter writer,
Collection<String> outputChannelIds,
Collection<BaseActorHandle> targetActors,
Partition partition) {
public OutputCollector(
DataWriter writer,
Collection<String> outputChannelIds,
Collection<BaseActorHandle> targetActors,
Partition partition) {
this.writer = writer;
this.outputQueues = outputChannelIds.stream().map(ChannelId::from).toArray(ChannelId[]::new);
this.targetActors = targetActors;
this.targetLanguages = targetActors.stream()
.map(actor -> actor instanceof PyActorHandle ? Language.PYTHON : Language.JAVA)
.map(actor -> actor instanceof PyActorHandle ? Language.PYTHON :
Language.JAVA)
.toArray(Language[]::new);
this.partition = partition;
LOGGER.debug("OutputCollector constructed, outputChannelIds:{}, partition:{}.",
@@ -6,10 +6,10 @@ import java.io.Serializable;
import java.util.UUID;
/**
* Streaming system unique identity base class.
* For example, ${@link ContainerID }
* Streaming system unique identity base class. For example, ${@link ContainerID }
*/
public class AbstractID implements Serializable {
private UUID id;
public AbstractID() {
@@ -18,7 +18,7 @@ public class AbstractID implements Serializable {
@Override
public boolean equals(Object obj) {
return id.equals(((AbstractID)obj).getId());
return id.equals(((AbstractID) obj).getId());
}
public UUID getId() {
@@ -75,10 +75,10 @@ public class ExecutionEdge implements Serializable {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("source", sourceExecutionVertex)
.add("target", targetExecutionVertex)
.add("partition", partition)
.add("index", executionEdgeIndex)
.toString();
.add("source", sourceExecutionVertex)
.add("target", targetExecutionVertex)
.add("partition", partition)
.add("index", executionEdgeIndex)
.toString();
}
}
@@ -25,9 +25,7 @@ public class ExecutionGraph implements Serializable {
private Map<String, String> jobConfig;
/**
* Data map for execution job vertex.
* key: job vertex id.
* value: execution job vertex.
* Data map for execution job vertex. key: job vertex id. value: execution job vertex.
*/
private Map<Integer, ExecutionJobVertex> executionJobVertexMap;
@@ -166,8 +164,11 @@ public class ExecutionGraph implements Serializable {
*/
public List<BaseActorHandle> getNonSourceActors() {
List<ExecutionJobVertex> executionJobVertices = getExecutionJobVertexList().stream()
.filter(executionJobVertex -> executionJobVertex.isTransformationVertex()
|| executionJobVertex.isSinkVertex())
.filter(executionJobVertex ->
executionJobVertex
.isTransformationVertex()
|| executionJobVertex
.isSinkVertex())
.collect(Collectors.toList());
return getActorsFromJobVertices(executionJobVertices);
@@ -17,7 +17,6 @@ import org.aeonbits.owner.ConfigFactory;
/**
* Physical job vertex.
*
* <p>Execution job vertex is the physical form of {@link JobVertex} and
* every execution job vertex is corresponding to a group of {@link ExecutionVertex}.
*/
@@ -29,8 +28,8 @@ public class ExecutionJobVertex {
private final int executionJobVertexId;
/**
* Use jobVertex id and operator(use {@link StreamOperator}'s name) as name.
* e.g. 1-SourceOperator
* Use jobVertex id and operator(use {@link StreamOperator}'s name) as name. e.g.
* 1-SourceOperator
*/
private final String executionJobVertexName;
private final StreamOperator streamOperator;
@@ -48,8 +48,8 @@ public class ExecutionVertex implements Serializable {
private int parallelism;
/**
* Ordered sub index for execution vertex in a execution job vertex.
* Might be changed in dynamic scheduling.
* Ordered sub index for execution vertex in a execution job vertex. Might be changed in dynamic
* scheduling.
*/
private int executionVertexIndex;
@@ -102,8 +102,8 @@ public class ExecutionVertex implements Serializable {
}
/**
* Unique name generated by execution job vertex name and index of current execution vertex.
* e.g. 1-SourceOperator-3 (vertex index is 3)
* Unique name generated by execution job vertex name and index of current execution vertex. e.g.
* 1-SourceOperator-3 (vertex index is 3)
*/
public String getExecutionVertexName() {
return executionJobVertexName + "-" + executionVertexIndex;
@@ -239,7 +239,7 @@ public class ExecutionVertex implements Serializable {
@Override
public boolean equals(Object obj) {
if (obj instanceof ExecutionVertex) {
return this.executionVertexId == ((ExecutionVertex)obj).getExecutionVertexId();
return this.executionVertexId == ((ExecutionVertex) obj).getExecutionVertexId();
}
return false;
}
@@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TwoInputProcessor<T, O> extends StreamProcessor<Record, TwoInputOperator<T, O>> {
private static final Logger LOGGER = LoggerFactory.getLogger(TwoInputProcessor.class);
private String leftStream;
@@ -47,8 +47,7 @@ public class Container implements Serializable {
private Map<String, Double> availableResources = new HashMap<>();
/**
* List of {@link ExecutionVertex} ids
* belong to the container.
* List of {@link ExecutionVertex} ids belong to the container.
*/
private List<Integer> executionVertexIds = new ArrayList<>();
@@ -6,4 +6,5 @@ import io.ray.streaming.runtime.core.common.AbstractID;
* Container unique identifier.
*/
public class ContainerID extends AbstractID {
}
@@ -6,12 +6,12 @@ package io.ray.streaming.runtime.core.resource;
public enum ResourceType {
/**
*Cpu resource key.
* Cpu resource key.
*/
CPU("CPU"),
/**
*Gpu resource key.
* Gpu resource key.
*/
GPU("GPU"),
@@ -28,6 +28,7 @@ public class Resources implements Serializable {
/**
* Get registered containers, the container list is read-only.
*
* @return container list.
*/
public ImmutableList<Container> getRegisteredContainers() {
@@ -52,7 +53,8 @@ public class Resources implements Serializable {
public ImmutableMap<UniqueId, Container> getRegisteredContainerMap() {
return ImmutableMap.copyOf(registerContainers.stream()
.collect(java.util.stream.Collectors.toMap(Container::getNodeId, c -> c)));
.collect(java.util.stream.Collectors
.toMap(Container::getNodeId, c -> c)));
}
@Override
@@ -8,7 +8,6 @@ import java.io.Serializable;
/**
* Runtime context for job master.
*
* <p>Including: graph, resource, checkpoint info, etc.
*/
public class JobRuntimeContext implements Serializable {
@@ -5,7 +5,6 @@ import io.ray.streaming.runtime.core.graph.executiongraph.ExecutionGraph;
/**
* Graph manager is one of the important roles of JobMaster. It mainly focuses on graph management.
*
* <p>
* Such as:
* <ol>
@@ -77,7 +77,7 @@ public class ResourceManagerImpl implements ResourceManager {
ResourceAssignStrategyType resourceAssignStrategyType =
ResourceAssignStrategyType.PIPELINE_FIRST_STRATEGY;
this.resourceAssignStrategy = ResourceAssignStrategyFactory.getStrategy(
resourceAssignStrategyType);
resourceAssignStrategyType);
LOG.info("Slot assign strategy: {}.", resourceAssignStrategy.getName());
//Init resource
@@ -89,7 +89,8 @@ public class ResourceManagerImpl implements ResourceManager {
}
@Override
public ResourceAssignmentView assignResource(List<Container> containers,
public ResourceAssignmentView assignResource(
List<Container> containers,
ExecutionGraph executionGraph) {
return resourceAssignStrategy.assignResource(containers, executionGraph);
}
@@ -106,8 +107,8 @@ public class ResourceManagerImpl implements ResourceManager {
}
/**
* Check the status of ray cluster node and update the internal resource information of
* streaming system.
* Check the status of ray cluster node and update the internal resource information of streaming
* system.
*/
private void checkAndUpdateResource() {
//Get add&del nodes(node -> container)
@@ -117,7 +118,8 @@ public class ResourceManagerImpl implements ResourceManager {
.filter(this::isAddedNode).collect(Collectors.toList());
List<UniqueId> deleteNodes = resources.getRegisteredContainerMap().keySet().stream()
.filter(nodeId -> !latestNodeInfos.containsKey(nodeId)).collect(Collectors.toList());
.filter(nodeId -> !latestNodeInfos.containsKey(nodeId))
.collect(Collectors.toList());
LOG.info("Latest node infos: {}, current containers: {}, add nodes: {}, delete nodes: {}.",
latestNodeInfos, resources.getRegisteredContainers(), addNodes, deleteNodes);
@@ -156,7 +158,6 @@ public class ResourceManagerImpl implements ResourceManager {
// failover case: container has already allocated actors
double availableCapacity = actorNumPerContainer - container.getAllocatedActorNum();
//Create ray resource.
Ray.setResource(container.getNodeId(), container.getName(), availableCapacity);
//Mark container is already registered.
@@ -164,7 +165,7 @@ public class ResourceManagerImpl implements ResourceManager {
// update container's available dynamic resources
container.getAvailableResources()
.put(container.getName(), availableCapacity);
.put(container.getName(), availableCapacity);
// update register container list
resources.registerContainer(container);
@@ -15,8 +15,8 @@ public class ViewBuilder {
}
public static ResourceAssignmentView buildResourceAssignmentView(List<Container> containers) {
Map<ContainerID, List<Integer>> assignmentView = containers.stream()
.collect(java.util.stream.Collectors.toMap(Container::getId,
Map<ContainerID, List<Integer>> assignmentView =
containers.stream().collect(java.util.stream.Collectors.toMap(Container::getId,
Container::getExecutionVertexIds));
return ResourceAssignmentView.of(assignmentView);
@@ -12,8 +12,7 @@ import java.util.List;
public interface ResourceAssignStrategy {
/**
* Assign {@link Container} for
* {@link ExecutionVertex}
* Assign {@link Container} for {@link ExecutionVertex}
*
* @param containers registered container
* @param executionGraph execution graph
@@ -17,11 +17,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Based on Ray dynamic resource function, resource details(by ray gcs get) and
* execution logic diagram, PipelineFirstStrategy provides a actor scheduling
* strategies to make the cluster load balanced and controllable scheduling.
* Assume that we have 2 containers and have a DAG graph composed of a source node with parallelism
* of 2 and a sink node with parallelism of 2, the structure will be like:
* Based on Ray dynamic resource function, resource details(by ray gcs get) and execution logic
* diagram, PipelineFirstStrategy provides a actor scheduling strategies to make the cluster load
* balanced and controllable scheduling. Assume that we have 2 containers and have a DAG graph
* composed of a source node with parallelism of 2 and a sink node with parallelism of 2, the
* structure will be like:
* <pre>
* container_0
* |- source_1
@@ -38,7 +38,7 @@ public class PipelineFirstStrategy implements ResourceAssignStrategy {
private int currentContainerIndex = 0;
/**
* Assign resource to each execution vertex in the given execution graph.
* Assign resource to each execution vertex in the given execution graph.
*
* @param containers registered containers
* @param executionGraph execution graph
@@ -125,6 +125,7 @@ public class PipelineFirstStrategy implements ResourceAssignStrategy {
/**
* Find a container which matches required resource
*
* @param requiredResource required resource
* @param containers registered containers
* @return container that matches the required resource
@@ -151,6 +152,7 @@ public class PipelineFirstStrategy implements ResourceAssignStrategy {
/**
* Check if current container has enough resource
*
* @param requiredResource required resource
* @param container container
* @return true if matches, false else
@@ -198,6 +200,7 @@ public class PipelineFirstStrategy implements ResourceAssignStrategy {
/**
* Get current container
*
* @param containers registered container
* @return current container to allocate actor
*/
@@ -9,6 +9,7 @@ public interface JobScheduler {
/**
* Schedule streaming job using the physical plan.
*
* @param executionGraph physical plan
* @return scheduling result
*/
@@ -18,7 +18,8 @@ public class ScheduleException extends RuntimeException {
super(cause);
}
protected ScheduleException(String message, Throwable cause, boolean enableSuppression,
protected ScheduleException(
String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
@@ -171,8 +171,8 @@ public class WorkerLifecycleController {
List<ExecutionVertex> executionVertices) {
final Object asyncContext = Ray.getAsyncContext();
List<CompletableFuture<Boolean>> futureResults = executionVertices.stream()
.map(vertex -> CompletableFuture.supplyAsync(() -> {
List<CompletableFuture<Boolean>> futureResults =
executionVertices.stream().map(vertex -> CompletableFuture.supplyAsync(() -> {
Ray.setAsyncContext(asyncContext);
return operation.apply(vertex);
})).collect(Collectors.toList());
@@ -34,8 +34,8 @@ public class GraphPbBuilder {
List<ExecutionVertex> upstreamVertices = executionVertex.getInputVertices();
List<RemoteCall.ExecutionVertexContext.ExecutionVertex> upstreamVertexPbs =
upstreamVertices.stream()
.map(this::buildVertex)
.collect(Collectors.toList());
.map(this::buildVertex)
.collect(Collectors.toList());
builder.addAllUpstreamExecutionVertices(upstreamVertexPbs);
// build downstream vertices
@@ -127,7 +127,8 @@ public class GraphPbBuilder {
private byte[] serializePythonChainedOperator(ChainedPythonOperator operator) {
List<byte[]> serializedOperators = operator.getOperators().stream()
.map(this::serializeOperator).collect(Collectors.toList());
.map(this::serializeOperator)
.collect(Collectors.toList());
return serializer.serialize(Arrays.asList(
serializedOperators,
operator.getConfigs()
@@ -23,15 +23,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Gateway for streaming python api.
* All calls on DataStream in python will be mapped to DataStream call in java by this
* PythonGateway using ray calls.
* <p>
* Note: this class needs to be in sync with `GatewayClient` in
* `streaming/python/runtime/gateway_client.py`
* Gateway for streaming python api. All calls on DataStream in python will be mapped to DataStream
* call in java by this PythonGateway using ray calls. this class needs to be in sync with
* GatewayClient in `streaming/python/runtime/gateway_client.py`
*/
@SuppressWarnings("unchecked")
public class PythonGateway {
private static final Logger LOG = LoggerFactory.getLogger(PythonGateway.class);
private static final String REFERENCE_ID_PREFIX = "__gateway_reference_id__";
private static MsgPackSerializer serializer = new MsgPackSerializer();
@@ -169,8 +167,9 @@ public class PythonGateway {
.toArray(Class[]::new);
Optional<Method> any = methods.stream()
.filter(m -> {
boolean exactMatch = Arrays.equals(m.getParameterTypes(), paramsTypes) ||
Arrays.equals(m.getParameterTypes(), unwrappedTypes);
boolean exactMatch =
Arrays.equals(m.getParameterTypes(), paramsTypes) ||
Arrays.equals(m.getParameterTypes(), unwrappedTypes);
if (exactMatch) {
return true;
} else if (paramsTypes.length == m.getParameterTypes().length) {
@@ -12,8 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Ray call worker.
* It takes the communication job from {@link JobMaster} to {@link JobWorker}.
* Ray call worker. It takes the communication job from {@link JobMaster} to {@link JobWorker}.
*/
public class RemoteCallWorker {
@@ -6,10 +6,11 @@ import java.util.Arrays;
import java.util.List;
/**
* A serializer for cross-lang serialization between java/python.
* TODO implements a more sophisticated serialization framework
* A serializer for cross-lang serialization between java/python. TODO implements a more
* sophisticated serialization framework
*/
public class CrossLangSerializer implements Serializer {
private static final byte RECORD_TYPE_ID = 0;
private static final byte KEY_RECORD_TYPE_ID = 1;
@@ -3,6 +3,7 @@ package io.ray.streaming.runtime.serialization;
import io.ray.runtime.serializer.FstSerializer;
public class JavaSerializer implements Serializer {
@Override
public byte[] serialize(Object object) {
return FstSerializer.encode(object);
@@ -1,6 +1,7 @@
package io.ray.streaming.runtime.serialization;
public interface Serializer {
byte CROSS_LANG_TYPE_ID = 0;
byte JAVA_TYPE_ID = 1;
byte PYTHON_TYPE_ID = 2;
@@ -42,7 +42,7 @@ public class ChannelCreationParametersBuilder {
String language =
asyncFunctionDescriptor instanceof JavaFunctionDescriptor ? "Java" : "Python";
return "Language: " + language + " Desc: " + asyncFunctionDescriptor.toList() + " "
+ syncFunctionDescriptor.toList();
+ syncFunctionDescriptor.toList();
}
// Get actor id in bytes, called from jni.
@@ -93,14 +93,16 @@ public class ChannelCreationParametersBuilder {
public ChannelCreationParametersBuilder() {
}
public static void setJavaReaderFunctionDesc(JavaFunctionDescriptor asyncFunc,
JavaFunctionDescriptor syncFunc) {
public static void setJavaReaderFunctionDesc(
JavaFunctionDescriptor asyncFunc,
JavaFunctionDescriptor syncFunc) {
javaReaderAsyncFuncDesc = asyncFunc;
javaReaderSyncFuncDesc = syncFunc;
}
public static void setJavaWriterFunctionDesc(JavaFunctionDescriptor asyncFunc,
JavaFunctionDescriptor syncFunc) {
public static void setJavaWriterFunctionDesc(
JavaFunctionDescriptor asyncFunc,
JavaFunctionDescriptor syncFunc) {
javaWriterAsyncFuncDesc = asyncFunc;
javaWriterSyncFuncDesc = syncFunc;
}
@@ -109,19 +111,23 @@ public class ChannelCreationParametersBuilder {
List<String> queues,
List<BaseActorHandle> actors) {
return buildParameters(queues, actors, javaWriterAsyncFuncDesc, javaWriterSyncFuncDesc,
pyWriterAsyncFunctionDesc, pyWriterSyncFunctionDesc);
pyWriterAsyncFunctionDesc, pyWriterSyncFunctionDesc);
}
public ChannelCreationParametersBuilder buildOutputQueueParameters(List<String> queues,
List<BaseActorHandle> actors) {
public ChannelCreationParametersBuilder buildOutputQueueParameters(
List<String> queues,
List<BaseActorHandle> actors) {
return buildParameters(queues, actors, javaReaderAsyncFuncDesc, javaReaderSyncFuncDesc,
pyReaderAsyncFunctionDesc, pyReaderSyncFunctionDesc);
pyReaderAsyncFunctionDesc, pyReaderSyncFunctionDesc);
}
private ChannelCreationParametersBuilder buildParameters(List<String> queues,
private ChannelCreationParametersBuilder buildParameters(
List<String> queues,
List<BaseActorHandle> actors,
JavaFunctionDescriptor javaAsyncFunctionDesc, JavaFunctionDescriptor javaSyncFunctionDesc,
PyFunctionDescriptor pyAsyncFunctionDesc, PyFunctionDescriptor pySyncFunctionDesc
JavaFunctionDescriptor javaAsyncFunctionDesc,
JavaFunctionDescriptor javaSyncFunctionDesc,
PyFunctionDescriptor pyAsyncFunctionDesc,
PyFunctionDescriptor pySyncFunctionDesc
) {
parameters = new ArrayList<>(queues.size());
@@ -12,10 +12,11 @@ import java.util.Set;
import sun.nio.ch.DirectBuffer;
/**
* ChannelID is used to identify a transfer channel between a upstream worker
* and downstream worker.
* ChannelID is used to identify a transfer channel between a upstream worker and downstream
* worker.
*/
public class ChannelId {
public static final int ID_LENGTH = 20;
private static final FinalizableReferenceQueue REFERENCE_QUEUE = new FinalizableReferenceQueue();
// This ensures that the FinalizablePhantomReference itself is not garbage-collected.
@@ -132,7 +133,7 @@ public class ChannelId {
* Generate channel name, which will be 20 character
*
* @param fromTaskId upstream task id
* @param toTaskId downstream task id
* @param toTaskId downstream task id
* @return channel name
*/
public static String genIdStr(int fromTaskId, int toTaskId, long ts) {
@@ -7,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChannelUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ChannelUtils.class);
static byte[] toNativeConf(StreamingWorkerConfig workerConfig) {
@@ -6,6 +6,7 @@ import java.nio.ByteBuffer;
* DataMessage represents data between upstream and downstream operator
*/
public class DataMessage implements Message {
private final ByteBuffer body;
private final long msgId;
private final long timestamp;
@@ -14,10 +14,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* DataReader is wrapper of streaming c++ DataReader, which read data
* from channels of upstream workers
* DataReader is wrapper of streaming c++ DataReader, which read data from channels of upstream
* workers
*/
public class DataReader {
private static final Logger LOG = LoggerFactory.getLogger(DataReader.class);
private long nativeReaderPtr;
@@ -25,12 +26,13 @@ public class DataReader {
/**
* @param inputChannels input channels ids
* @param fromActors upstream input actors
* @param workerConfig configuration
* @param fromActors upstream input actors
* @param workerConfig configuration
*/
public DataReader(List<String> inputChannels,
List<BaseActorHandle> fromActors,
StreamingWorkerConfig workerConfig) {
public DataReader(
List<String> inputChannels,
List<BaseActorHandle> fromActors,
StreamingWorkerConfig workerConfig) {
Preconditions.checkArgument(inputChannels.size() > 0);
Preconditions.checkArgument(inputChannels.size() == fromActors.size());
ChannelCreationParametersBuilder initialParameters =
@@ -169,10 +171,11 @@ public class DataReader {
byte[] configBytes,
boolean isMock);
private native void getBundleNative(long nativeReaderPtr,
long timeoutMillis,
long params,
long metaAddress);
private native void getBundleNative(
long nativeReaderPtr,
long timeoutMillis,
long params,
long metaAddress);
private native void stopReaderNative(long nativeReaderPtr);
@@ -191,6 +194,7 @@ public class DataReader {
}
static class BundleMeta {
// kMessageBundleHeaderSize + kUniqueIDSize:
// magicNum(4b) + bundleTs(8b) + lastMessageId(8b) + messageListSize(4b)
// + bundleType(4b) + rawBundleSize(4b) + channelID(20b)
@@ -13,10 +13,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* DataWriter is a wrapper of streaming c++ DataWriter, which sends data
* to downstream workers
* DataWriter is a wrapper of streaming c++ DataWriter, which sends data to downstream workers
*/
public class DataWriter {
private static final Logger LOG = LoggerFactory.getLogger(DataWriter.class);
private long nativeWriterPtr;
@@ -29,12 +29,13 @@ public class DataWriter {
/**
* @param outputChannels output channels ids
* @param toActors downstream output actors
* @param workerConfig configuration
* @param toActors downstream output actors
* @param workerConfig configuration
*/
public DataWriter(List<String> outputChannels,
List<BaseActorHandle> toActors,
StreamingWorkerConfig workerConfig) {
public DataWriter(
List<String> outputChannels,
List<BaseActorHandle> toActors,
StreamingWorkerConfig workerConfig) {
Preconditions.checkArgument(!outputChannels.isEmpty());
Preconditions.checkArgument(outputChannels.size() == toActors.size());
ChannelCreationParametersBuilder initialParameters =
@@ -66,7 +67,7 @@ public class DataWriter {
/**
* Write msg into the specified channel
*
* @param id channel id
* @param id channel id
* @param item message item data section is specified by [position, limit).
*/
public void write(ChannelId id, ByteBuffer item) {
@@ -80,9 +81,10 @@ public class DataWriter {
/**
* Write msg into the specified channels
*
* @param ids channel ids
* @param item message item data section is specified by [position, limit).
* item doesn't have to be a direct buffer.
* @param ids channel ids
* @param item message item data section is specified by [position, limit). item doesn't have
* to
* be a direct buffer.
*/
public void write(Set<ChannelId> ids, ByteBuffer item) {
int size = item.remaining();
@@ -6,7 +6,7 @@ public interface Message {
/**
* Message data
*
* <p>
* Message body is a direct byte buffer, which may be invalid after call next
* <code>DataReader#getBundleNative</code>. Please consume this buffer fully
* before next call <code>getBundleNative</code>.
@@ -8,7 +8,7 @@ import java.util.Map;
public class CommonUtils {
public static Map<String, Object> strMapToObjectMap(Map<String, String> srcMap) {
Map<String,Object> destMap = (Map) srcMap;
Map<String, Object> destMap = (Map) srcMap;
return destMap;
}
}
@@ -34,8 +34,8 @@ public class RayUtils {
*/
public static Map<UniqueId, NodeInfo> getAliveNodeInfoMap() {
return getAllNodeInfo().stream()
.filter(nodeInfo -> nodeInfo.isAlive)
.collect(Collectors.toMap(nodeInfo -> nodeInfo.nodeId, nodeInfo -> nodeInfo));
.filter(nodeInfo -> nodeInfo.isAlive)
.collect(Collectors.toMap(nodeInfo -> nodeInfo.nodeId, nodeInfo -> nodeInfo));
}
private static List<NodeInfo> mockContainerResources() {
@@ -20,8 +20,7 @@ import org.slf4j.LoggerFactory;
/**
* The streaming worker implementation class, it is ray actor. JobWorker is created by
* {@link JobMaster} through ray api, and JobMaster communicates
* with JobWorker through Ray.call().
* {@link JobMaster} through ray api, and JobMaster communicates with JobWorker through Ray.call().
*
* <p>The JobWorker is responsible for creating tasks and defines the methods of communication
* between workers.
@@ -147,8 +146,7 @@ public class JobWorker implements Serializable {
}
/**
* Used by upstream streaming queue to send data to this actor
* and receive result from this actor
* Used by upstream streaming queue to send data to this actor and receive result from this actor
*/
public byte[] onReaderMessageSync(byte[] buffer) {
if (transferHandler == null) {
@@ -165,8 +163,8 @@ public class JobWorker implements Serializable {
}
/**
* Used by downstream streaming queue to send data to this actor
* and receive result from this actor
* Used by downstream streaming queue to send data to this actor and receive result from this
* actor
*/
public byte[] onWriterMessageSync(byte[] buffer) {
if (transferHandler == null) {
@@ -56,10 +56,10 @@ public class JobWorkerContext implements Serializable {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("workerId", getWorkerId())
.add("workerName", getWorkerName())
.add("config", getConfig())
.toString();
.add("workerId", getWorkerId())
.add("workerName", getWorkerName())
.add("config", getConfig())
.toString();
}
public byte[] getPythonWorkerContextBytes() {
@@ -68,10 +68,11 @@ public class JobWorkerContext implements Serializable {
new GraphPbBuilder().buildExecutionVertexContext(executionVertex);
byte[] contextBytes = RemoteCall.PythonJobWorkerContext.newBuilder()
.setMasterActor(ByteString.copyFrom((((NativeActorHandle) (master)).toBytes())))
.setExecutionVertexContext(executionVertexContext)
.build()
.toByteArray();
.setMasterActor(
ByteString.copyFrom((((NativeActorHandle) (master)).toBytes())))
.setExecutionVertexContext(executionVertexContext)
.build()
.toByteArray();
return contextBytes;
}
@@ -19,6 +19,7 @@ import java.util.Map;
* Use Ray to implement RuntimeContext.
*/
public class StreamingRuntimeContext implements RuntimeContext {
/**
* Backend for keyed state. This might be empty if we're not on a keyed stream.
*/
@@ -33,7 +34,8 @@ public class StreamingRuntimeContext implements RuntimeContext {
private Long checkpointId;
private Map<String, String> config;
public StreamingRuntimeContext(ExecutionVertex executionVertex, Map<String, String> config,
public StreamingRuntimeContext(
ExecutionVertex executionVertex, Map<String, String> config,
int parallelism) {
this.taskId = executionVertex.getExecutionVertexId();
this.config = config;
@@ -115,8 +117,9 @@ public class StreamingRuntimeContext implements RuntimeContext {
return this.keyStateBackend.getMapState(stateDescriptor);
}
protected void stateSanityCheck(AbstractStateDescriptor stateDescriptor,
AbstractKeyStateBackend backend) {
protected void stateSanityCheck(
AbstractStateDescriptor stateDescriptor,
AbstractKeyStateBackend backend) {
Preconditions.checkNotNull(stateDescriptor, "The state properties must not be null");
Preconditions.checkNotNull(backend, "backend must not be null");
}
@@ -9,6 +9,7 @@ import io.ray.streaming.runtime.transfer.Message;
import io.ray.streaming.runtime.worker.JobWorker;
public abstract class InputStreamTask extends StreamTask {
private volatile boolean running = true;
private volatile boolean stopped = false;
private long readTimeoutMillis;
@@ -56,8 +57,8 @@ public abstract class InputStreamTask extends StreamTask {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("taskId", taskId)
.add("processor", processor)
.toString();
.add("taskId", taskId)
.add("processor", processor)
.toString();
}
}
@@ -14,8 +14,8 @@ public class SourceStreamTask extends StreamTask {
private final SourceProcessor sourceProcessor;
/**
* SourceStreamTask for executing a {@link SourceOperator}.
* It is responsible for running the corresponding source operator.
* SourceStreamTask for executing a {@link SourceOperator}. It is responsible for running the
* corresponding source operator.
*/
public SourceStreamTask(int taskId, Processor sourceProcessor, JobWorker jobWorker) {
super(taskId, sourceProcessor, jobWorker);
@@ -19,11 +19,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class StreamTask implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(StreamTask.class);
protected int taskId;
@@ -44,7 +44,7 @@ public abstract class StreamTask implements Runnable {
prepareTask();
this.thread = new Thread(Ray.wrapRunnable(this),
this.getClass().getName() + "-" + System.currentTimeMillis());
this.getClass().getName() + "-" + System.currentTimeMillis());
this.thread.setDaemon(true);
}
@@ -16,8 +16,8 @@ public class TwoInputStreamTask extends InputStreamTask {
String leftStream,
String rightStream) {
super(taskId, processor, jobWorker);
((TwoInputProcessor)(super.processor)).setLeftStream(leftStream);
((TwoInputProcessor)(super.processor)).setRightStream(rightStream);
((TwoInputProcessor) (super.processor)).setLeftStream(leftStream);
((TwoInputProcessor) (super.processor)).setRightStream(rightStream);
}
}
@@ -25,12 +25,12 @@ public abstract class BaseUnitTest {
@BeforeMethod
public void testBegin(Method method) {
LOG.info(">>>>>>>>>>>>>>>>>>>> Test case: {}.{} began >>>>>>>>>>>>>>>>>>>>",
method.getDeclaringClass(), method.getName());
method.getDeclaringClass(), method.getName());
}
@AfterMethod
public void testEnd(Method method) {
LOG.info(">>>>>>>>>>>>>>>>>>>> Test case: {}.{} end >>>>>>>>>>>>>>>>>>>>",
method.getDeclaringClass(), method.getName());
method.getDeclaringClass(), method.getName());
}
}
@@ -50,11 +50,11 @@ public class ExecutionGraphTest extends BaseUnitTest {
executionGraph.getExecutionVertexIdGenerator().get());
executionGraph.getAllExecutionVertices().forEach(vertex -> {
Assert.assertNotNull(vertex.getStreamOperator());
Assert.assertNotNull(vertex.getExecutionJobVertexName());
Assert.assertNotNull(vertex.getVertexType());
Assert.assertNotNull(vertex.getLanguage());
Assert.assertEquals(vertex.getExecutionVertexName(),
Assert.assertNotNull(vertex.getStreamOperator());
Assert.assertNotNull(vertex.getExecutionJobVertexName());
Assert.assertNotNull(vertex.getVertexType());
Assert.assertNotNull(vertex.getLanguage());
Assert.assertEquals(vertex.getExecutionVertexName(),
vertex.getExecutionJobVertexName() + "-" + vertex.getExecutionVertexIndex());
});
@@ -66,10 +66,11 @@ public class ExecutionGraphTest extends BaseUnitTest {
List<ExecutionVertex> upStreamVertices = upStream.getExecutionVertices();
List<ExecutionVertex> downStreamVertices = downStream.getExecutionVertices();
upStreamVertices.forEach(vertex -> {
Assert.assertEquals((double) vertex.getResource().get(ResourceType.CPU.name()), 2.0);
vertex.getOutputEdges().forEach(upStreamOutPutEdge -> {
Assert.assertTrue(downStreamVertices.contains(upStreamOutPutEdge.getTargetExecutionVertex()));
});
Assert.assertEquals((double) vertex.getResource().get(ResourceType.CPU.name()), 2.0);
vertex.getOutputEdges().forEach(upStreamOutPutEdge -> {
Assert
.assertTrue(downStreamVertices.contains(upStreamOutPutEdge.getTargetExecutionVertex()));
});
});
}
@@ -18,6 +18,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
public class HybridStreamTest {
private static final Logger LOG = LoggerFactory.getLogger(HybridStreamTest.class);
public static class Mapper1 implements MapFunction<Object, Object> {
@@ -17,7 +17,8 @@ import org.testng.Assert;
import org.testng.annotations.Test;
public class UnionStreamTest {
private static final Logger LOG = LoggerFactory.getLogger( UnionStreamTest.class );
private static final Logger LOG = LoggerFactory.getLogger(UnionStreamTest.class);
@Test(timeOut = 60000)
public void testUnionStream() throws Exception {
@@ -46,7 +46,8 @@ public class WordCountTest extends BaseUnitTest implements Serializable {
.filter(pair -> !pair.word.contains("world"))
.keyBy(pair -> pair.word)
.reduce((ReduceFunction<WordAndCount>) (oldValue, newValue) ->
new WordAndCount(oldValue.word, oldValue.count + newValue.count))
new WordAndCount(oldValue.word,
oldValue.count + newValue.count))
.sink((SinkFunction<WordAndCount>)
result -> wordCount.put(result.word, result.count));
@@ -2,6 +2,7 @@ package io.ray.streaming.runtime.python;
import static org.testng.Assert.assertEquals;
import io.ray.streaming.api.stream.StreamSink;
import io.ray.streaming.jobgraph.JobGraph;
import io.ray.streaming.jobgraph.JobGraphBuilder;
@@ -3,6 +3,7 @@ package io.ray.streaming.runtime.serialization;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import io.ray.streaming.message.KeyRecord;
import io.ray.streaming.message.Record;
import org.apache.commons.lang3.builder.EqualsBuilder;
@@ -17,10 +18,10 @@ public class CrossLangSerializerTest {
Record record = new Record("value");
record.setStream("stream1");
assertTrue(EqualsBuilder.reflectionEquals(record,
serializer.deserialize(serializer.serialize(record))));
serializer.deserialize(serializer.serialize(record))));
KeyRecord keyRecord = new KeyRecord("key", "value");
keyRecord.setStream("stream2");
assertEquals(keyRecord,
serializer.deserialize(serializer.serialize(keyRecord)));
serializer.deserialize(serializer.serialize(keyRecord)));
}
}
@@ -3,6 +3,7 @@ package io.ray.streaming.runtime.serialization;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -18,7 +19,7 @@ public class MsgPackSerializerTest {
MsgPackSerializer serializer = new MsgPackSerializer();
assertEquals(serializer.deserialize(
serializer.serialize((byte)1)), (byte)1);
serializer.serialize((byte) 1)), (byte) 1);
}
@Test
@@ -1,12 +1,12 @@
package io.ray.streaming.runtime.streamingqueue;
import io.ray.api.ActorHandle;
import io.ray.api.BaseActorHandle;
import io.ray.api.Ray;
import io.ray.api.ActorHandle;
import io.ray.runtime.functionmanager.JavaFunctionDescriptor;
import io.ray.streaming.runtime.config.StreamingWorkerConfig;
import io.ray.streaming.runtime.transfer.ChannelId;
import io.ray.streaming.runtime.transfer.ChannelCreationParametersBuilder;
import io.ray.streaming.runtime.transfer.ChannelId;
import io.ray.streaming.runtime.transfer.DataMessage;
import io.ray.streaming.runtime.transfer.DataReader;
import io.ray.streaming.runtime.transfer.DataWriter;
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import org.testng.Assert;
public class Worker {
private static final Logger LOGGER = LoggerFactory.getLogger(Worker.class);
protected TransferHandler transferHandler = null;
@@ -50,6 +51,7 @@ public class Worker {
}
class ReaderWorker extends Worker {
private static final Logger LOGGER = LoggerFactory.getLogger(ReaderWorker.class);
private String name = null;
@@ -170,6 +172,7 @@ class ReaderWorker extends Worker {
}
class WriterWorker extends Worker {
private static final Logger LOGGER = LoggerFactory.getLogger(WriterWorker.class);
private String name = null;
@@ -2,6 +2,7 @@ package io.ray.streaming.runtime.transfer;
import static org.testng.Assert.assertEquals;
import io.ray.streaming.runtime.BaseUnitTest;
import io.ray.streaming.runtime.util.EnvUtil;
import org.testng.annotations.Test;
@@ -21,12 +21,11 @@ public class Mockitools {
public static void mockGscApi() {
PowerMockito.mockStatic(RayUtils.class);
PowerMockito.when(RayUtils.getAliveNodeInfoMap())
.thenReturn(mockGetNodeInfoMap(mockGetAllNodeInfo()));
.thenReturn(mockGetNodeInfoMap(mockGetAllNodeInfo()));
}
/**
* Mock get all node info from GCS
* @return
*/
public static List<NodeInfo> mockGetAllNodeInfo() {
List<NodeInfo> nodeInfos = new LinkedList<>();
@@ -55,21 +54,22 @@ public class Mockitools {
/**
* Mock get node info map
*
* @param nodeInfos all node infos fetched from GCS
* @return node info map, key is node unique id, value is node info
*/
public static Map<UniqueId, NodeInfo> mockGetNodeInfoMap(List<NodeInfo> nodeInfos) {
return nodeInfos.stream().filter(nodeInfo -> nodeInfo.isAlive).collect(
Collectors.toMap(nodeInfo -> nodeInfo.nodeId, nodeInfo -> nodeInfo));
Collectors.toMap(nodeInfo -> nodeInfo.nodeId, nodeInfo -> nodeInfo));
}
private static NodeInfo mockNodeInfo(int i, Map<String, Double> resources) {
return new NodeInfo(
createNodeId(i),
"localhost" + i,
"localhost" + i,
true,
resources);
createNodeId(i),
"localhost" + i,
"localhost" + i,
true,
resources);
}
private static UniqueId createNodeId(int id) {
@@ -2,6 +2,7 @@ package io.ray.streaming.runtime.util;
import static org.testng.Assert.assertEquals;
import java.io.Serializable;
import java.util.Collections;
import org.testng.annotations.Test;
@@ -9,6 +10,7 @@ import org.testng.annotations.Test;
public class ReflectionUtilsTest {
static class Foo implements Serializable {
public void f1() {
}