private IRecord GetRecord(long recordId) { var record = new Record(recordId); try { var currentBlockId = record.Id; do { var block = _blockStorage.Find(currentBlockId); if (block == null) { if (currentBlockId == RecordZero) { block = _blockStorage.Create(); return(RecordZero.WithBlocks(new[] { block })); } else { throw new Exception("Block not found by id: " + currentBlockId); } } if (block.IsDeleted) { throw new InvalidDataException("Block not found: " + currentBlockId); } record.Blocks.Add(block); currentBlockId = block.GetHeaderValue(BlockHeader.NextBlock); } while (currentBlockId != 0); } catch (Exception) { record.Dispose(); throw; } return(record); }