Exemplo n.º 1
0
        public async Task <ulong> AddEntryAsync(LogEntry entry, byte[] secretKey = null, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(0UL);
            }

            entry.RoundTripCheck(_typeProvider, secretKey);

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            entry.Serialize(new LogSerializeContext(bw, _typeProvider), false);
            var value = ms.ToArray();

            var index = await _sequence.GetNextValueAsync();

            using var tx = env.Value.BeginTransaction(TransactionBeginFlags.None);
            using var db = tx.OpenDatabase();

            var key = _keyBuilder.BuildKey(index, entry);

            if (key.Length >= MaxKeySizeBytes)
            {
                throw new InvalidOperationException($"Keys must be less than {MaxKeySizeBytes} bytes in length.");
            }

            tx.Put(db, key, value);
            tx.Commit();

            entry.Index = index;
            return(index);
        }
Exemplo n.º 2
0
        public async Task <ulong> AddRecordAsync(Record record, byte[] secretKey     = null,
                                                 CancellationToken cancellationToken = default)
        {
            var sequence = AddRecord(record, await _sequence.GetNextValueAsync(), cancellationToken);
            await _events.OnAddedAsync(this, record, cancellationToken);

            return(sequence);
        }