Hello all,

Ignite.NET, nuget package 2.6.0, .NETFramework 4.7.2

I am quite a novice with Apache Ignite. I am looking for solution to cancel 
running tasks on Ignite cluster.
Based on examples I tried following code:

    public class HangingDemo
    {
        public IIgnite Ignite { get; }

        public HangingDemo(IIgnite ignite)
        {
            Ignite = ignite;
        }

        public async Task Run()
        {
            using (var cts = new 
CancellationTokenSource(TimeSpan.FromSeconds(1)))
            {
                var cancelledJobsCount = await 
Ignite.GetCompute().ExecuteAsync(new SimpleTask(), 5, cts.Token);

                // never happens !!!
                Console.WriteLine("{0} jobs were cancelled", 
cancelledJobsCount);
            }
        }
    }

    public class SimpleTask : ComputeTaskSplitAdapter<int, bool, int>
    {
        protected override ICollection<IComputeJob<bool>> Split(int gridSize, 
int jobsCount)
        {
            return Enumerable
                .Range(1, jobsCount)
                .Select(i => new SimpleJob { Id = i })
                .Cast<IComputeJob<bool>>()
                .ToList();
        }

        public override int Reduce(IList<IComputeJobResult<bool>> results)
        {
            return results.Count(i => i.Data);
        }
    }

    public class SimpleJob : IComputeJob<bool>
    {
        private bool _isCancelled;

        public int Id { get; set; }

        public bool Execute()
        {
            Console.WriteLine("Start job {0}", Id);

            Thread.Sleep(TimeSpan.FromSeconds(2));

            return Volatile.Read(ref _isCancelled);
        }

        public void Cancel()
        {
            // never happens !!!
            Volatile.Write(ref _isCancelled, true);
        }
    }

Unfortunately the program hangs and the line "Console.WriteLine("{0} jobs were 
cancelled", cancelledJobsCount)" will never be reached.
Console output:
Start job 5
Start job 2
Start job 4
Start job 1
Start job 3
INFO  
org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestProtocol [] 
Command protocol successfully stopped: TCP binary
WARN  org.apache.ignite.internal.processors.task.GridTaskProcessor [] Will 
cancel unfinished tasks due to stopping of the grid [cnt=1]

Questions:

1.       Program hangs.

2.       SimpleJob.Cancel is never called.

3.       Am I on a right direction? How I can cancel already running task/job?

Thank you for your help,
Max

Reply via email to