public async Task <ITask> GetTask(CancellationToken token)
        {
            await EnsureInit();

            ITransaction tx  = null;
            ITask        ret = null;

            try
            {
                tx = ServiceFabricUtils.CreateTransaction();
                await ServiceFabricUtils.DoWithTimeoutRetry(async() =>
                {
                    var result = await m_queue.TryDequeueAsync(tx, TimeSpan.FromSeconds(10), m_cancel);
                    if (result.HasValue)
                    {
                        ret = Utils.Deserialize <ITask>(result.Value);
                    }
                });

                if (ret == null)
                {
                    tx.Dispose(); return(null);
                }
                m_tx[ret] = tx;
                return(ret);
            }
            catch
            {
                ReleaseTx(ret, tx);
                throw;
            }
        }
Ejemplo n.º 2
0
        private async Task <IEnumerable <Chunk> > GetChunks_impl(Guid?replicaId)
        {
            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
retry:
                try
                {
                    if (replicaId.HasValue)
                    {
                        var res = await m_chunktable.TryGetValueAsync(tx, replicaId.Value);

                        if (res.HasValue)
                        {
                            return(Utils.Deserialize <Chunk[]>(res.Value));
                        }
                    }
                    else
                    {
                        var res = await m_chunktable.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                        var          enumerator = res.GetAsyncEnumerator();
                        List <Chunk> chunks     = new List <Chunk>();
                        while (await enumerator.MoveNextAsync(m_cancel))
                        {
                            chunks.AddRange(Utils.Deserialize <Chunk[]>(enumerator.Current.Value));
                        }
                        return(chunks);
                    }
                }
                catch (TimeoutException) { await Task.Delay(1000); goto retry; }
                catch (Exception ex) { Log.WriteLine(LogLevel.Error, "{0}", $"ServiceFabricChunkTable: {ex.ToString()}"); }
                finally { await tx.CommitAsync(); }
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <inheritdocs/>
        public async Task DeleteEntry(Guid replicaId)
        {
            await EnsureChunkTables();

            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
                await ServiceFabricUtils.DoWithTimeoutRetry(
                    async() => await m_chunktable.TryRemoveAsync(tx, replicaId));
            }
        }
        public async Task PostTask(ITask task)
        {
            await EnsureInit();

            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
                await ServiceFabricUtils.DoWithTimeoutRetry(
                    async() => await m_queue.EnqueueAsync(tx, Utils.Serialize(task), TimeSpan.FromSeconds(10), m_cancel),
                    async() => await m_tagCounter.AddOrUpdateAsync(tx, task.Tag, 1, (k, v) => v + 1),
                    async() => await tx.CommitAsync());
            }
        }
Ejemplo n.º 5
0
        /// <inheritdocs/>
        public async Task SetChunks(Guid replicaId, IEnumerable <Chunk> chunks)
        {
            var payload = Utils.Serialize(chunks.ToArray());

            await EnsureChunkTables();

            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
                await ServiceFabricUtils.DoWithTimeoutRetry(
                    async() => await m_chunktable.SetAsync(tx, replicaId, payload),
                    async() => await tx.CommitAsync());
            }
        }
        public async Task Wait(Guid tag)
        {
            await EnsureInit();

            await ServiceFabricUtils.DoWithTimeoutRetry(
                async() =>
            {
                using (var tx = ServiceFabricUtils.CreateTransaction())
                {
                    int cnt    = 0;
                    var result = await m_tagCounter.TryGetValueAsync(tx, tag, TimeSpan.FromSeconds(10), m_cancel);
                    if (result.HasValue)
                    {
                        cnt = result.Value;
                    }
                    if (cnt != 0)
                    {
                        throw new TimeoutException();
                    }
                }
            });
        }