birschick-bq commented on code in PR #3397:
URL: https://github.com/apache/arrow-adbc/pull/3397#discussion_r2338073507


##########
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)
+                {
+                    lastException = ioEx;
+                    // If we can't open the file, just set to null.
+                    _currentFileStream = null;
+                    int delayMs = ThreadLocalRandom.Next(5, 10 * attempts);
+                    await Task.Delay(delayMs).ConfigureAwait(false);

Review Comment:
   I've now applied them to all `await`s in these two file/classes.



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to