Esempio n. 1
0
        public async Task <CloudEventLogSegment> GetLogSegmentedAsync(CloudEventLogPosition next, int takeCount = 1000, CancellationToken cancellationToken = default(CancellationToken))
        {
            var results1 = await _tableClient.GetLogSegmentedAsync(next, takeCount, cancellationToken);

            var results2 = await _blobClient.FetchAsync(results1.Results);

            var results3 = new List <CloudEvent>();

            byte[] scratch = null;
            foreach (var item in results2)
            {
                var e = new CloudEvent();
                e.Id = new CloudEventLogPosition(item.Log, item.Position).Value;
                e.ReadFrom(item.Data.GetStream(), ref scratch);
                results3.Add(e);
            }

            CloudEventLogPosition next2 = next;

            if (0 < results2.Count)
            {
                var lst = results2[results2.Count - 1];

                next2 = new CloudEventLogPosition(lst.Log, lst.Position + lst.Data.Count);
            }

            return(new CloudEventLogSegment(results3, next2));
        }
        public async Task <bool> CommitAsync(CloudEventLogPosition lsnStart, IEnumerable <CloudEventHeader> headers, CancellationToken cancellationToken = default(CancellationToken))
        {
            var b = new TableBatchOperation();

            var idx = new MemoryStream();

            long p = 0;

            foreach (var h in headers)
            {
                var lsn = new CloudEventLogPosition(lsnStart.Log, lsnStart.Position + p);
                b.Insert(new CloudEventStreamEntity(h.StreamId, h.SequenceNumber, lsn, (int)h.Length), echoContent: false);
                idx.WriteVarInt63(h.Length);
                p += h.Length;
            }

            var lsnEnd = new CloudEventLogPosition(lsnStart.Log, lsnStart.Position + p);

            b.Insert(new CloudEventTransactionLogEntity(lsnStart, lsnEnd, idx.ToArray()), echoContent: false);

            var table = await _table;

            try
            {
                // commit!
                await table.ExecuteBatchAsync(b, cancellationToken);

                return(true);
            }
            catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == 409)
            {
                return(false); // conflict!
            }
        }
Esempio n. 3
0
        private static string GetAppendBlobName(long logNumber)
        {
            // descending sort order
            var lsn = new CloudEventLogPosition(CloudEventLogPosition.MaxValue.Log - logNumber, 0);

            return(AppendBlobPrefix + lsn.LogFixed8 + ".dat");
        }
Esempio n. 4
0
 public CloudEventStreamEntity(Guid streamId, int sequenceNumber, CloudEventLogPosition lsn, int length)
 {
     PartitionKey = CloudEventTransaction.PartitionKey;
     RowKey       = CloudEventTransaction.RowKeyStreamPrefix + streamId.ToByteArray().Encode32() + "-" + ((long)sequenceNumber).ToFixed(10);
     Log          = (int)lsn.Log;
     Position     = lsn.Position;
     Length       = length;
 }
        public CloudEventTransactionLogEntity(CloudEventLogPosition tranStart, CloudEventLogPosition tranEnd, byte[] lengths)
        {
            var tranEnd2 = new CloudEventLogPosition(tranEnd.Log, tranEnd.Position - 1); // see GetEnd

            PartitionKey = CloudEventTransaction.PartitionKey;
            RowKey       = CloudEventTransaction.RowKeyTransactionPrefix + tranEnd.LogFixed8 + "-" + tranEnd2.PositionFixed12;
            Position     = tranStart.Value;
            Lengths      = lengths;
        }
Esempio n. 6
0
        public void TestMethod1(long hi, long lo)
        {
            var a = new CloudEventLogPosition(hi, lo);

            Assert.AreEqual(hi, a.Log);
            Assert.AreEqual(lo, a.Position);

            var v = a.Value;
            var b = new CloudEventLogPosition(v);

            Assert.AreEqual(hi, b.Log);
            Assert.AreEqual(lo, b.Position);
        }
        public async Task <CloudEventLogPositionLengthSegment> GetLogSegmentedAsync(CloudEventLogPosition next, int takeCount = 1000, CancellationToken cancellationToken = default(CancellationToken))
        {
            var table = await _table;

            var q = new TableQuery <CloudEventTransactionLogEntity>
            {
                FilterString =
                    TableQuery.CombineFilters(
                        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, CloudEventTransaction.PartitionKey),
                        TableOperators.And,
                        TableQuery.CombineFilters(
                            TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, CloudEventTransaction.RowKeyTransactionPrefix + CloudEventLogPosition.MinValue),
                            TableOperators.And,
                            TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, CloudEventTransaction.RowKeyTransactionPrefix + CloudEventLogPosition.MaxValue)
                            )
                        ),
                TakeCount = takeCount
            };

            var continuationToken = new TableContinuationToken
            {
                NextPartitionKey = CloudEventTransaction.PartitionKey,
                NextRowKey       = CloudEventTransaction.RowKeyTransactionPrefix + next
            };

            var querySegment = await table.ExecuteQuerySegmentedAsync(q, continuationToken);

            var results2 = new List <CloudEventLogPositionLength>();

            foreach (var result in querySegment.Results)
            {
                var idx = new MemoryStream(result.Lengths);

                var p = 0L;
                while (idx.Position < idx.Length)
                {
                    // todo: skip

                    var size = idx.ReadVarInt63();
                    results2.Add(new CloudEventLogPositionLength(result.Log, result.Position + p, (int)size));
                    p += size;
                }

                next = result.GetEnd(); // todo: what if location is past max block count?
            }

            return(new CloudEventLogPositionLengthSegment(results2, querySegment.ContinuationToken));
        }
 public CloudEventLogSegment(List <CloudEvent> results, CloudEventLogPosition next)
 {
     this.Results = results;
     this.Next    = next;
 }