コード例 #1
0
        private async Task LnmPublishingThread(IRingMasterRequestHandler client, CancellationToken token, int threadId)
        {
            var rnd = new Random();

            while (!token.IsCancellationRequested)
            {
                try
                {
                    var vnet = $"/Instance{this.ServiceContext.ReplicaOrInstanceId}/vnets/{CreateSpanningVnetId(threadId)}";
                    var stat = await client.Exists(vnet, null, true);

                    var ops = new List <Op>();

                    if (stat == null)
                    {
                        ops.Add(Op.Create($"{vnet}/mappings/v4ca", null, null, CreateMode.PersistentAllowPathCreation));
                        ops.Add(Op.Create($"{vnet}/lnms/thread-{threadId}", null, null, CreateMode.PersistentAllowPathCreation));

                        await client.Multi(ops, true);

                        ops.Clear();

                        this.IncrementTotalDataCount(2);
                    }

                    var mappingCount = rnd.Next(1, 1024 * 8);
                    for (int i = 0; i < mappingCount; i++)
                    {
                        ops.Add(Op.Create($"{vnet}/mappings/v4ca/{i}", null, null, CreateMode.PersistentAllowPathCreation));
                    }

                    this.IncrementTotalDataCount(ops.Count);
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    await client.Multi(ops, true);

                    ops.Clear();

                    for (int i = 0; i < mappingCount; i++)
                    {
                        var data = new byte[rnd.Next(this.MinDataSize, this.MaxDataSize)];
                        ops.Add(Op.SetData($"{vnet}/mappings/v4ca/{i}", data, -1));
                        this.AddTotalDataSize(data.Length);
                    }

                    this.IncrementTotalDataCount(mappingCount);
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    await client.Multi(ops, true);

                    ops.Clear();
                }
                catch (Exception ex)
                {
                    this.IncrementTotalFailures();

                    // Ignore and keep going
                    this.Log($"FAIL in {threadId}: {ex.Message}");
                }
            }
        }