@@ -131,12 +131,12 @@ public SqlServerFhirDataStore(
131
131
132
132
internal static TimeSpan MergeResourcesTransactionHeartbeatPeriod => TimeSpan . FromSeconds ( 10 ) ;
133
133
134
- private async Task DeleteBlobFromAdlsAsync ( long transactionId , CancellationToken cancellationToken )
134
+ private async Task DeleteBlobFromAdlsAsync ( long transactionId , int blobIndex , CancellationToken cancellationToken )
135
135
{
136
136
var start = DateTime . UtcNow ;
137
137
var sw = Stopwatch . StartNew ( ) ;
138
138
var retries = 0 ;
139
- var blobName = GetBlobNameForRaw ( transactionId ) ;
139
+ var blobName = GetBlobNameForRaw ( transactionId , blobIndex ) ;
140
140
while ( true )
141
141
{
142
142
try
@@ -165,32 +165,24 @@ private async Task PutRawResourcesIntoAdlsAsync(IReadOnlyList<MergeResourceWrapp
165
165
{
166
166
var start = DateTime . UtcNow ;
167
167
var sw = Stopwatch . StartNew ( ) ;
168
- var eol = Encoding . UTF8 . GetByteCount ( Environment . NewLine ) ;
169
168
var retries = 0 ;
170
- var blobName = GetBlobNameForRaw ( transactionId ) ;
171
169
while ( true )
172
170
{
173
171
try
174
172
{
175
- using var stream = await SqlAdlsClient . Container . GetBlockBlobClient ( blobName ) . OpenWriteAsync ( true , null , cancellationToken ) ;
176
- using var writer = new StreamWriter ( stream ) ;
177
- var offset = 0 ;
178
- foreach ( var resource in resources )
173
+ Parallel . For ( 0 , resources . Count , index =>
179
174
{
180
- resource . FileId = transactionId ;
181
- resource . OffsetInFile = offset ;
182
- var line = resource . ResourceWrapper . RawResource . Data ;
183
- offset += Encoding . UTF8 . GetByteCount ( line ) + eol ;
184
- await writer . WriteLineAsync ( line ) ;
185
- }
175
+ resources [ index ] . FileId = transactionId ;
176
+ resources [ index ] . OffsetInFile = index ;
177
+ var blobClient = SqlAdlsClient . Container . GetBlobClient ( GetBlobNameForRaw ( transactionId , index ) ) ;
178
+ blobClient . Upload ( BinaryData . FromString ( resources [ index ] . ResourceWrapper . RawResource . Data + Environment . NewLine ) , overwrite : true ) ;
179
+ } ) ;
186
180
187
- #pragma warning disable CA2016
188
- await writer . FlushAsync ( ) ;
189
181
break ;
190
182
}
191
183
catch ( Exception e )
192
184
{
193
- await StoreClient . TryLogEvent ( "PutRawResourcesIntoAdlsAsync" , "Error" , $ "blob= { blobName } error={ e } ", start , cancellationToken ) ;
185
+ await StoreClient . TryLogEvent ( "PutRawResourcesIntoAdlsAsync" , "Error" , $ "transactionId= { transactionId } error={ e } ", start , cancellationToken ) ;
194
186
if ( e . ToString ( ) . Contains ( "ConditionNotMet" , StringComparison . OrdinalIgnoreCase ) && retries ++ < 3 )
195
187
{
196
188
await Task . Delay ( 1000 , cancellationToken ) ;
@@ -202,12 +194,12 @@ private async Task PutRawResourcesIntoAdlsAsync(IReadOnlyList<MergeResourceWrapp
202
194
}
203
195
204
196
var mcsec = ( long ) Math . Round ( sw . Elapsed . TotalMilliseconds * 1000 , 0 ) ;
205
- await StoreClient . TryLogEvent ( "PutRawResourcesToAdls" , "Warn" , $ "mcsec={ mcsec } resources={ resources . Count } blob= { blobName } ", start , cancellationToken ) ;
197
+ await StoreClient . TryLogEvent ( "PutRawResourcesToAdls" , "Warn" , $ "mcsec={ mcsec } resources={ resources . Count } transactionId = { transactionId } ", start , cancellationToken ) ;
206
198
}
207
199
208
- internal static string GetBlobNameForRaw ( long fileId )
200
+ internal static string GetBlobNameForRaw ( long fileId , int blobIndex )
209
201
{
210
- return $ "hash-{ GetPermanentHashCode ( fileId ) } /transaction-{ fileId } .ndjson";
202
+ return $ "hash-{ GetPermanentHashCode ( fileId ) } /transaction-{ fileId } -index- { blobIndex } .ndjson";
211
203
}
212
204
213
205
private static string GetPermanentHashCode ( long tr )
0 commit comments