public AppendRequestDescriptor(Stream data, StreamMetadata metadata, CancellationToken token) { Data = data.ThrowIfNull(nameof(data)); Metadata = metadata.ThrowIfNull(nameof(metadata)); Token = token.ThrowIfNull(nameof(token)); TaskSource = new TaskCompletionSource <object>(); }
/// <summary> /// Searches given metatdata in block and inserts at desired position if not found /// </summary> /// <param name="data">The <see cref="StreamMetadata"/> object to be added</param> public void Add(StreamMetadata data) { data.ThrowIfNull(nameof(data)); var index = payload.BinarySearch(data); if (index >= 0) { throw new ArgumentException(nameof(data.Key)); } index = ~index; payload.Insert(index, data); }
/// <summary> /// Adds metadata of written stream to index file /// </summary> /// <param name="streamMetadata">stream metadata to be added to index</param> /// <exception cref="System.ArgumentException">An element with the same key already exists</exception> public void Set(StreamMetadata streamMetadata) { streamMetadata.ThrowIfNull(nameof(streamMetadata)); var key = streamMetadata.Key; if (Contains(key)) { throw new ArgumentException(nameof(key)); } var blockInfo = header.Get(key); var block = new IndexBlock(); var oldLength = 0; if (blockInfo.Offset > 0) { if (blockInfo.Length + streamMetadata.SerializedLength < MaxIndexBlockLength) { blockProvider.Read(block, blockInfo.Offset, blockInfo.Length); oldLength = blockInfo.Length; } else { block = new IndexBlock(blockInfo); } } block.Add(streamMetadata); var offset = blockProvider.Write(block); var length = block.SerializedLength; blockInfo = new BlockInfo() { Offset = offset, Length = length }; header.Set(key, blockInfo); header.IndexWrittenLength += length - oldLength; header.StorageWrittenLength += streamMetadata.Length; }