Ejemplo n.º 1
0
        public int JobResultRemote(ComputeJobHolder job, PlatformMemoryStream stream)
        {
            // 1. Unmarshal result.
            BinaryReader reader = _compute.Marshaller.StartUnmarshal(stream);

            var nodeId = reader.ReadGuid();

            Debug.Assert(nodeId.HasValue);

            bool cancelled = reader.ReadBoolean();

            try
            {
                object err;

                var data = BinaryUtils.ReadInvocationResult(reader, out err);

                // 2. Process the result.
                return((int)JobResult0(new ComputeJobResultImpl(data, (Exception)err, job.Job, nodeId.Value, cancelled)));
            }
            catch (Exception e)
            {
                Finish(default(TR), e);

                if (!(e is IgniteException))
                {
                    throw new IgniteException("Failed to process job result: " + e.Message, e);
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the job.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="writer">The writer.</param>
        /// <returns>Handle to the job holder</returns>
        private long WriteJob(IComputeJob job, PortableWriterImpl writer)
        {
            var jobHolder = new ComputeJobHolder((Ignite)_prj.Ignite, job);

            var jobHandle = Marshaller.Ignite.HandleRegistry.Allocate(jobHolder);

            writer.WriteLong(jobHandle);
            writer.WriteObject(jobHolder);

            return(jobHandle);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes job map.
        /// </summary>
        /// <param name="writer">Writer.</param>
        /// <param name="map">Map</param>
        /// <returns>Job handle list.</returns>
        private static List <long> WriteJobs(BinaryWriter writer, IDictionary <IComputeJob <T>, IClusterNode> map)
        {
            Debug.Assert(writer != null && map != null);

            writer.WriteInt(map.Count); // Amount of mapped jobs.

            var jobHandles = new List <long>(map.Count);
            var ignite     = writer.Marshaller.Ignite;

            try
            {
                foreach (KeyValuePair <IComputeJob <T>, IClusterNode> mapEntry in map)
                {
                    var job = new ComputeJobHolder(ignite, mapEntry.Key.ToNonGeneric());

                    IClusterNode node = mapEntry.Value;

                    var jobHandle = ignite.HandleRegistry.Allocate(job);

                    jobHandles.Add(jobHandle);

                    writer.WriteLong(jobHandle);

                    if (node.IsLocal)
                    {
                        writer.WriteBoolean(false); // Job is not serialized.
                    }
                    else
                    {
                        writer.WriteBoolean(true); // Job is serialized.
                        writer.WriteObject(job);
                    }

                    writer.WriteGuid(node.Id);
                }
            }
            catch (Exception)
            {
                foreach (var handle in jobHandles)
                {
                    ignite.HandleRegistry.Release(handle);
                }

                throw;
            }

            return(jobHandles);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes the job.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="writer">The writer.</param>
        /// <returns>Handle to the job holder</returns>
        private long WriteJob(IComputeJob job, BinaryWriter writer)
        {
            var jobHolder = new ComputeJobHolder((Ignite)_prj.Ignite, job);

            var jobHandle = Marshaller.Ignite.HandleRegistry.Allocate(jobHolder);

            writer.WriteLong(jobHandle);

            try
            {
                writer.WriteObjectDetached(jobHolder);
            }
            catch (Exception)
            {
                Marshaller.Ignite.HandleRegistry.Release(jobHandle);

                throw;
            }

            return(jobHandle);
        }
Ejemplo n.º 5
0
 /** <inheritDoc /> */
 public int JobResultLocal(ComputeJobHolder job)
 {
     return((int)JobResult0(job.JobResult));
 }
Ejemplo n.º 6
0
        public void Map(PlatformMemoryStream inStream, PlatformMemoryStream outStream)
        {
            IList <IClusterNode> subgrid;

            ClusterGroupImpl prj = (ClusterGroupImpl)_compute.ClusterGroup;

            var ignite = (Ignite)prj.Ignite;

            // 1. Unmarshal topology info if topology changed.
            var reader = prj.Marshaller.StartUnmarshal(inStream);

            if (reader.ReadBoolean())
            {
                long topVer = reader.ReadLong();

                List <IClusterNode> nodes = new List <IClusterNode>(reader.ReadInt());

                int nodesCnt = reader.ReadInt();

                subgrid = new List <IClusterNode>(nodesCnt);

                for (int i = 0; i < nodesCnt; i++)
                {
                    IClusterNode node = ignite.GetNode(reader.ReadGuid());

                    nodes.Add(node);

                    if (reader.ReadBoolean())
                    {
                        subgrid.Add(node);
                    }
                }

                // Update parent projection to help other task callers avoid this overhead.
                // Note that there is a chance that topology changed even further and this update fails.
                // It means that some of subgrid nodes could have left the Grid. This is not critical
                // for us, because Java will handle it gracefully.
                prj.UpdateTopology(topVer, nodes);
            }
            else
            {
                IList <IClusterNode> nodes = prj.NodesNoRefresh();

                Debug.Assert(nodes != null, "At least one topology update should have occurred.");

                subgrid = IgniteUtils.Shuffle(nodes);
            }

            // 2. Perform map.
            IDictionary <IComputeJob <T>, IClusterNode> map;
            Exception err;

            try
            {
                map = _task.Map(subgrid, _arg);

                err = null;
            }
            catch (Exception e)
            {
                map = null;

                err = e;

                // Java can receive another exception in case of marshalling failure but it is not important.
                Finish(default(TR), e);
            }

            // 3. Write map result to the output stream.
            PortableWriterImpl writer = prj.Marshaller.StartMarshal(outStream);

            try
            {
                if (err == null)
                {
                    writer.WriteBoolean(true); // Success flag.

                    if (map == null)
                    {
                        writer.WriteBoolean(false); // Map produced no result.
                    }
                    else
                    {
                        writer.WriteBoolean(true);  // Map produced result.
                        writer.WriteInt(map.Count); // Amount of mapped jobs.

                        var jobHandles = new List <long>(map.Count);

                        foreach (KeyValuePair <IComputeJob <T>, IClusterNode> mapEntry in map)
                        {
                            var job = new ComputeJobHolder(_compute.ClusterGroup.Ignite as Ignite, mapEntry.Key.ToNonGeneric());

                            IClusterNode node = mapEntry.Value;

                            var jobHandle = ignite.HandleRegistry.Allocate(job);

                            jobHandles.Add(jobHandle);

                            writer.WriteLong(jobHandle);

                            if (node.IsLocal)
                            {
                                writer.WriteBoolean(false); // Job is not serialized.
                            }
                            else
                            {
                                writer.WriteBoolean(true); // Job is serialized.
                                writer.WriteObject(job);
                            }

                            writer.WriteGuid(node.Id);
                        }

                        _jobHandles = jobHandles;
                    }
                }
                else
                {
                    writer.WriteBoolean(false); // Map failed.

                    // Write error as string because it is not important for Java, we need only to print
                    // a message in the log.
                    writer.WriteString("Map step failed [errType=" + err.GetType().Name +
                                       ", errMsg=" + err.Message + ']');
                }
            }
            catch (Exception e)
            {
                // Something went wrong during marshaling.
                Finish(default(TR), e);

                outStream.Reset();

                writer.WriteBoolean(false);    // Map failed.
                writer.WriteString(e.Message); // Write error message.
            }
            finally
            {
                prj.Marshaller.FinishMarshal(writer);
            }
        }