private Task SaveAsync(ContainerActiveEntity prevEntry)
        {
            TableOperation insertOperation = TableOperation.InsertOrReplace(prevEntry);

            var instanceTable = _tableLookup.GetTableForDateTime(prevEntry.StartTime);

            // Execute the insert operation.
            return(instanceTable.SafeExecuteAsync(insertOperation));
        }
Exemple #2
0
        // Limit of 100 per batch.
        // Parallel uploads.
        public static async Task WriteBatchAsync <T>(this ILogTableProvider logTableProvider, IEnumerable <T> e1) where T : TableEntity, IEntityWithEpoch
        {
            HashSet <string> rowKeys = new HashSet <string>();

            int batchSize = 90;

            // Batches must be within a single table partition, so Key is "tableName + ParitionKey".
            var batches = new Dictionary <string, Tuple <CloudTable, TableBatchOperation> >();

            List <Task> t = new List <Task>();

            foreach (var e in e1)
            {
                if (!rowKeys.Add(e.RowKey))
                {
                    // Already present
                }

                var epoch         = e.GetEpoch();
                var instanceTable = logTableProvider.GetTableForDateTime(epoch);

                string key = instanceTable.Name + "/" + e.PartitionKey;

                Tuple <CloudTable, TableBatchOperation> tuple;
                if (!batches.TryGetValue(key, out tuple))
                {
                    tuple        = Tuple.Create(instanceTable, new TableBatchOperation());
                    batches[key] = tuple;
                }
                TableBatchOperation batch = tuple.Item2;

                batch.InsertOrMerge(e);
                if (batch.Count >= batchSize)
                {
                    Task tUpload = instanceTable.SafeExecuteAsync(batch);
                    t.Add(tUpload);

                    batches.Remove(key);
                }
            }

            // Flush remaining
            foreach (var tuple in batches.Values)
            {
                var instanceTable = tuple.Item1;
                var batch         = tuple.Item2;
                if (batch.Count > 0)
                {
                    Task tUpload = instanceTable.SafeExecuteAsync(batch);
                    t.Add(tUpload);
                }
            }

            await Task.WhenAll(t);
        }
        ///
        protected override async Task WriteEntry(long ticks, int currentActive, int totalThisPeriod)
        {
            if (currentActive == 0 && totalThisPeriod == 0)
            {
                return; // skip logging if no activity
            }
            var entity = new InstanceCountEntity(ticks, _containerName)
            {
                CurrentActive        = currentActive,
                TotalThisPeriod      = totalThisPeriod,
                MachineSize          = _containerSize,
                DurationMilliseconds = (int)this.PollingInterval.TotalMilliseconds
            };

            TableOperation opInsert = TableOperation.Insert(entity);

            var instanceTable = _tableLookup.GetTableForDateTime(new DateTime(ticks, DateTimeKind.Utc));
            await instanceTable.SafeExecuteAsync(opInsert);
        }
Exemple #4
0
        public static CloudTable GetTableForTimeBucket(this ILogTableProvider tableLookup, long timeBucket)
        {
            var time = ConvertToDateTime(timeBucket);

            return(tableLookup.GetTableForDateTime(time));
        }