birschick-bq commented on code in PR #3397:
URL: https://github.com/apache/arrow-adbc/pull/3397#discussion_r2338070954
##########
csharp/src/Telemetry/Traces/Exporters/FileExporter/TracingFile.cs:
##########
@@ -103,52 +113,85 @@ await ActionWithRetryAsync<IOException>(() =>
}
}
- private async Task WriteLinesAsync(IAsyncEnumerable<Stream> streams)
+ private async Task WriteSingleLineAsync(Stream stream)
{
- bool hasMoreData;
+ if ((_currentFileStream!.Length + stream.Length) >=
(_maxFileSizeKb * KbInByes))
+ {
+ // If tracing file is maxxed-out, start a new tracing file.
+ await OpenNewTracingFileAsync();
+ }
+ _currentFileStream!.Position = _currentFileStream.Length;
+ await stream.CopyToAsync(_currentFileStream);
+ }
+
+ private async Task OpenNewTracingFileAsync()
+ {
+ _currentFileStream?.Dispose();
+ _currentFileStream = null;
+ const int maxAttempts = 20;
+ int attempts = 0;
+ Exception? lastException;
+
do
{
- bool newFileRequired = false;
- _currentTraceFileInfo!.Refresh();
- using (FileStream fileStream =
_currentTraceFileInfo!.OpenWrite())
+ lastException = null;
+ _currentTraceFileInfo = new FileInfo(NewFileName());
+ try
{
- fileStream.Position = fileStream.Length;
- hasMoreData = false;
- await foreach (Stream stream in streams)
+ attempts++;
+ if (!_tracingDirectory.Exists)
{
- if (fileStream.Length >= _maxFileSizeKb * 1024)
- {
- hasMoreData = true;
- newFileRequired = true;
- break;
- }
-
- await stream.CopyToAsync(fileStream);
+ _tracingDirectory.Create();
}
+ _currentFileStream =
_currentTraceFileInfo.Open(FileMode.CreateNew, FileAccess.Write,
FileShare.Read);
+ }
+ catch (IOException ioEx)
+ when ((uint)ioEx.HResult == 0x80070020 //
ERROR_SHARING_VIOLATION
+ || ((uint)ioEx.HResult == 0x80070050)) //
ERROR_ALREADY_EXISTS)
Review Comment:
No portable way to detect these specific errors. Will remove the `when`
clause.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]