// Writes all records in order into the same chunk. They can either be appended to the current // chunk or written into a brand new chunk. // // Throws on IO errors. Can block on IO. // // The only exception it throws is TimeSeriesWriteException. You can examine its Result field // to figure out what happened to the record(s) you were trying to write. InnerException is the // culprit. It's never null. public async Task WriteBatchAsync(IEnumerable <T> records) { TimeSeriesWriteResult res = TimeSeriesWriteResult.RecordsDropped; try { if (records == null) { throw new ArgumentNullException(nameof(records)); } IOutputChunk buf = await _writer.LockChunkAsync(); try { IEnumerator <T> e = records.GetEnumerator(); if (!e.MoveNext()) { buf.Abandon(); return; } if (buf.IsNew) { buf.UserData.Long0 = Encoder.EncodePrimary(buf.Stream, e.Current).ToUniversalTime().Ticks; // If the block is set up to automatically close after a certain number of bytes is // written, tell it to exclude snapshot bytes from the calculation. This is necessary // to avoid creating a new block on every call to Write() if snapshots happen to // be large. if (buf.CloseAtSize.HasValue) { buf.CloseAtSize += buf.Stream.Length; } } else { Encoder.EncodeSecondary(buf.Stream, e.Current); } while (e.MoveNext()) { Encoder.EncodeSecondary(buf.Stream, e.Current); } res = TimeSeriesWriteResult.RecordsBuffered; } catch { res = TimeSeriesWriteResult.ChunkDropped; buf.Abandon(); throw; } finally { await buf.DisposeAsync(); } } catch (Exception e) { throw new TimeSeriesWriteException(e, res); } }
public TimeSeriesWriteException(Exception inner, TimeSeriesWriteResult result) : base(result.ToString(), inner) { Result = result; }