internal PhysicalLogWriter(
            ILogicalLog logicalLogStream,
            LogRecord tailRecord,
            PhysicalLogWriterCallbackManager callbackManager,
            Exception closedException,
            ITracer tracer,
            int maxWriteCacheSizeInMB,
            IncomingBytesRateCounterWriter incomingBytesRateCounterWriter,
            LogFlushBytesRateCounterWriter logFlushBytesRateCounterWriter,
            AvgBytesPerFlushCounterWriter bytesPerFlushCounterWriter,
            AvgFlushLatencyCounterWriter avgFlushLatencyCounterWriter,
            AvgSerializationLatencyCounterWriter avgSerializationLatencyCounterWriter)
        {
            Utility.Assert(callbackManager != null, "PhysicalLogWriter cannot accept null callback managers");

            this.incomingBytesRateCounterWriter       = incomingBytesRateCounterWriter;
            this.logFlushBytesRateCounterWriter       = logFlushBytesRateCounterWriter;
            this.bytesPerFlushCounterWriter           = bytesPerFlushCounterWriter;
            this.avgFlushLatencyCounterWriter         = avgFlushLatencyCounterWriter;
            this.avgSerializationLatencyCounterWriter = avgSerializationLatencyCounterWriter;

            this.maxWriteCacheSizeInBytes = maxWriteCacheSizeInMB * 1024 * 1024;
            this.Init(tracer, closedException);
            this.logicalLogStream = logicalLogStream;
            this.callbackManager  = callbackManager;
            this.SetTailRecord(tailRecord);
            Utility.Assert(
                this.currentLogTailPosition == (ulong)logicalLogStream.WritePosition,
                "this.currentLogTailPosition:{0} should be equal to logicalLogStream.WritePosition:{1}",
                this.currentLogTailPosition, logicalLogStream.WritePosition);
            this.recordWriter           = new BinaryWriter(new MemoryStream());
            this.recomputeRecordOffsets = false;
        }
Example #2
0
        int numberWriteRecords = 0x4000;    // 1GB log space
        private async Task Write4KLogFile(
            ILogicalLog lLog
            )
        {
            byte[] writeRecord = new byte[writeRecordSize];

            try
            {
                if (_DedicatedLogOnly)
                {
                    await lLog.ConfigureWritesToOnlyDedicatedLogAsync(CancellationToken.None);
                }


                for (int i = 0; i < numberWriteRecords; i++)
                {
                    for (int j = 0; j < writeRecordSize; j++)
                    {
                        writeRecord[j] = (byte)(i * j);
                    }

                    await lLog.AppendAsync(writeRecord, 0, writeRecord.Length, CancellationToken.None);

                    await lLog.FlushWithMarkerAsync(CancellationToken.None);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        internal PhysicalLogWriter(
            ILogicalLog logicalLogStream,
            PhysicalLogWriterCallbackManager callbackManager,
            ITracer tracer,
            int maxWriteCacheSizeInMB,
            IncomingBytesRateCounterWriter incomingBytesRateCounterWriter,
            LogFlushBytesRateCounterWriter logFlushBytesRateCounterWriter,
            AvgBytesPerFlushCounterWriter bytesPerFlushCounterWriter,
            AvgFlushLatencyCounterWriter avgFlushLatencyCounterWriter,
            AvgSerializationLatencyCounterWriter avgSerializationLatencyCounterWriter,
            bool recomputeRecordOffsets)
        {
            Utility.Assert(callbackManager != null, "PhysicalLogWriter cannot accept null callback managers");

            this.maxWriteCacheSizeInBytes = maxWriteCacheSizeInMB * 1024 * 1024;
            this.Init(tracer, null);
            this.logicalLogStream                     = logicalLogStream;
            this.callbackManager                      = callbackManager;
            this.currentLogTailPosition               = (ulong)logicalLogStream.WritePosition;
            this.currentLogTailRecord                 = LogRecord.InvalidLogRecord;
            this.currentLogTailPsn                    = new PhysicalSequenceNumber(-1);
            this.lastPhysicalRecord                   = null;
            this.incomingBytesRateCounterWriter       = incomingBytesRateCounterWriter;
            this.logFlushBytesRateCounterWriter       = logFlushBytesRateCounterWriter;
            this.bytesPerFlushCounterWriter           = bytesPerFlushCounterWriter;
            this.avgFlushLatencyCounterWriter         = avgFlushLatencyCounterWriter;
            this.avgSerializationLatencyCounterWriter = avgSerializationLatencyCounterWriter;
            this.recordWriter           = new BinaryWriter(new MemoryStream());
            this.recomputeRecordOffsets = recomputeRecordOffsets;
        }
Example #4
0
        public async Task SetupLogUsageNotificationAsync(ILogicalLog lLog, uint PercentUsage, CancellationToken CancelToken)
        {
            Fired = false;
            await lLog.WaitCapacityNotificationAsync(PercentUsage, CancelToken);

            Fired = true;
        }
Example #5
0
        void AppendLogicalLog(
            ILogicalLog logicalLog,
            byte[] buffer)
        {
            Task t = logicalLog.AppendAsync(buffer, 0, buffer.Length, CancellationToken.None);

            t.Wait();
        }
Example #6
0
        // Truncate the most recent information
        void TruncateTail(
            ILogicalLog logicalLog,
            long streamOffset)
        {
            Task t = logicalLog.TruncateTail(streamOffset, CancellationToken.None);

            t.Wait();
        }
Example #7
0
        private async Task LogPerformanceWorkloadWorker(
            ILogicalLog lLog,
            byte[] recordBuffer,
            TestLogNotification tn75,
            CancellationToken tn75CancelToken,
            CancellationToken CancelToken
            )
        {
            try
            {
                Task taskUsageNotification75;
                long bytes = 0;
                taskUsageNotification75 = tn75.SetupLogUsageNotificationAsync(lLog, 75, tn75CancelToken);

                if (_DedicatedLogOnly)
                {
                    await lLog.ConfigureWritesToOnlyDedicatedLogAsync(CancellationToken.None);
                }

                bool canceled = false;
                this.StartPerfWorkloads.WaitOne();

                while (!canceled)
                {
                    await lLog.AppendAsync(recordBuffer, 0, 40, /*recordBuffer.Length,*/ CancellationToken.None);

                    bytes += 40; /*recordBuffer.Length;*/

                    if (tn75.Fired)
                    {
                        //
                        // Truncate back to 10%
                        //
                        long allowedData        = lLog.Length / 10;
                        long truncationPosition = bytes - allowedData;
                        lLog.TruncateHead(truncationPosition);
                        taskUsageNotification75 = tn75.SetupLogUsageNotificationAsync(lLog, 75, tn75CancelToken);
                    }

                    if (CancelToken.IsCancellationRequested)
                    {
                        canceled = true;
                    }
                }
                await lLog.FlushWithMarkerAsync(CancellationToken.None);

                Interlocked.Add(ref this.TotalByteCount, bytes);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Tasks completed");

            return;
        }
Example #8
0
        private async Task ReadLogFileBypassStream(
            ILogicalLog lLog,
            int readRecordSize
            )
        {
            long totalWriteBytes = lLog.Length;

            byte[] readRecord = new byte[readRecordSize];

            long ticksWaiting   = 0;
            long ticksReading   = 0;
            long frequencyPerMs = Stopwatch.Frequency / 1000;

            Stopwatch swTotal   = new Stopwatch();
            Stopwatch swWaiting = new Stopwatch();
            Stopwatch swReading = new Stopwatch();

            long totalReadBytes = 0;

            swTotal.Start();
            while (totalReadBytes < totalWriteBytes)
            {
                long bytesRead;

                swReading.Restart();
                bytesRead = await lLog.ReadAsync(readRecord, 0, readRecord.Length, readRecord.Length, CancellationToken.None);

                swReading.Stop();
                totalReadBytes += bytesRead;
                ticksReading   += swReading.ElapsedTicks;

#if INCLUDE_WAITING_TIME
                swWaiting.Restart();
                int waitingms = rnd.Next(15);
                if (waitingms == 3)
                {
                    waitingms = 1;
                }
                else
                {
                    waitingms = 0;
                }

                await Task.Delay(waitingms);

                swWaiting.Stop();
                ticksWaiting += swWaiting.ElapsedTicks;
#endif
            }
            swTotal.Stop();

            Console.WriteLine("Bypass Stream: Size {0} Bytes Read {1} Elapsed ms {2} Waiting ms {3} Reading ms {4}",
                              readRecord.Length, totalReadBytes, swTotal.ElapsedMilliseconds, ticksWaiting / frequencyPerMs, ticksReading / frequencyPerMs);

            return;
        }
Example #9
0
        async Task <ILogicalLog> OpenLogicalLog(
            IPhysicalLog phylog,
            Guid logicalLogId)
        {
            ILogicalLog t = await phylog.OpenLogicalLogAsync(
                logicalLogId,
                "",
                CancellationToken.None);

            return(t);
        }
Example #10
0
        internal virtual async Task CloseLogAsync(CancellationToken cancellationToken)
        {
            var snapLogicalLog = this.logicalLog;

            if (snapLogicalLog != null)
            {
                this.logicalLog = null;
                await snapLogicalLog.CloseAsync(cancellationToken).ConfigureAwait(false);

                snapLogicalLog.Dispose();
            }
        }
Example #11
0
        private void StartWorkloadThreads(
            ILogicalLog[] lLog,
            int numberTasks,
            int RecordSize,
            CancellationTokenSource[] CancelToken,
            out float MBPerSecond
            )
        {
            Task[] tasks = new Task[numberTasks];
            TotalByteCount = 0;

            for (int i = 0; i < numberTasks; i++)
            {
                int ii = i;
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    ILogicalLog logicalLog = lLog[ii];
                    Write4KLogFile(logicalLog).Wait();
                    LogPerformanceWorkloadWorker(logicalLog, RecordSize, CancellationToken.None).Wait();
                });
            }

            this.StartPerfWorkloads.Set();

            Task.WaitAll(tasks);

            Console.WriteLine("Number Tasks: {0}", numberTasks);
            Console.WriteLine("RecordSize {0}", RecordSize);
            Console.WriteLine("Total bytes {0}", TotalByteCount);

            // renable when old style perf is needed
#if false
            long  bytesPerSecond = TotalByteCount / (TotalElapsedMs / 1000);
            float mbPerSecond    = (bytesPerSecond / (1024 * 1024));
            Console.WriteLine("Bytes per second:             {0}\nMB per second:             {1}", bytesPerSecond, mbPerSecond);
#endif

            long byteCount = TotalByteCount;
            long bytesPerSecondLargeReads = TotalByteCount / (TotalElapsedMsLargeReads / 1000);

            float mbPerSecondLargeReads = (bytesPerSecondLargeReads / (1024 * 1024));

            Console.WriteLine("Bytes per second Large Reads: {0}\nMB per second Large Reads: {1}", bytesPerSecondLargeReads, mbPerSecondLargeReads);

            MBPerSecond = mbPerSecondLargeReads;
        }
Example #12
0
        int ReadLogicalLog(
            ILogicalLog logicalLog,
            byte[] buffer,
            int readOffset,
            int bufferOffset,
            int count)
        {
            if (readOffset != -1)
            {
                logicalLog.SeekForRead(readOffset, SeekOrigin.Begin);
            }

            Task <int> t = logicalLog.ReadAsync(buffer, bufferOffset, count, 0, CancellationToken.None);

            t.Wait();
            return(t.Result);
        }
Example #13
0
        private async Task Write4KLogFile(
            ILogicalLog lLog,
            string s
            )
        {
            byte[] writeRecord = new byte[writeRecordSize];

            long ticksWriting   = 0;
            long frequencyPerMs = Stopwatch.Frequency / 1000;

            Stopwatch swTotal   = new Stopwatch();
            Stopwatch swWriting = new Stopwatch();

            try
            {
                if (_DedicatedLogOnly)
                {
                    await lLog.ConfigureWritesToOnlyDedicatedLogAsync(CancellationToken.None);
                }

                swTotal.Start();
                for (int i = 0; i < _NumberRecords; i++)
                {
                    for (int j = 0; j < writeRecordSize; j++)
                    {
                        writeRecord[j] = (byte)(i * j);
                    }

                    swWriting.Restart();
                    await lLog.AppendAsync(writeRecord, 0, writeRecord.Length, CancellationToken.None);

                    swWriting.Stop();
                    ticksWriting += swWriting.ElapsedTicks;
                }
                await lLog.FlushWithMarkerAsync(CancellationToken.None);

                swTotal.Stop();

                Console.WriteLine("Write {0}: Total ms {1} Writing ms {2}", s, swTotal.ElapsedMilliseconds, ticksWriting / frequencyPerMs);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Example #14
0
        public void LogPerformanceWorkloadTest(
            out float MBPerSecond
            )
        {
            try
            {
                //* Local functions
                Func <ILogManager>
                MakeManager = (() =>
                {
                    Task <ILogManager> t = LogManager.OpenAsync(LogManager.LoggerType.Default, CancellationToken.None);
                    t.Wait();
                    return(t.Result);
                });

                Func <ILogManager, string, Guid, long, uint, uint, IPhysicalLog>
                MakePhyLog = ((
                                  ILogManager manager,
                                  string pathToCommonContainer,
                                  Guid physicalLogId,
                                  long containerSize,
                                  uint maximumNumberStreams,
                                  uint maximumLogicalLogBlockSize) =>
                {
                    Task <IPhysicalLog> t = manager.CreatePhysicalLogAsync(
                        pathToCommonContainer,
                        physicalLogId,
                        containerSize,
                        maximumNumberStreams,
                        maximumLogicalLogBlockSize,
                        0,                             // Physical logs are not sparse
                        CancellationToken.None);

                    t.Wait();
                    return(t.Result);
                });

                Func <ILogManager, string, Guid, IPhysicalLog>
                OpenPhyLog = ((
                                  ILogManager manager,
                                  string pathToCommonContainer,
                                  Guid physicalLogId) =>
                {
                    Task <IPhysicalLog> t = manager.OpenPhysicalLogAsync(
                        pathToCommonContainer,
                        physicalLogId,
                        false,
                        CancellationToken.None);

                    t.Wait();
                    return(t.Result);
                });

                string physLogName = PlatformPathPrefix + _SharedDrive + PlatformPathDelimiter + "PerfWorkloadTestP.log";

                ILogManager logManager = MakeManager();

                try
                {
                    File.Delete(physLogName.Substring(4));
                }
                catch (Exception)
                {
                    // ok if this fails
                }

                Console.WriteLine("Raw Record size is {0}", _RecordSize);
                Guid         logId   = Guid.NewGuid();
                string       logName = physLogName;
                IPhysicalLog phyLog  = MakePhyLog(
                    logManager,
                    logName,
                    logId,
                    _LogSize,
                    0,
                    4 * _RecordSize);

                //
                // Determine the largest record size. We write full records to maximmize our I/O rate.
                // Max record size is determined by the Maximum block size plus the metadata space (4K) minus the
                // overhead of the headers.
                //
                //const int MaxLogBlkSize = 1024 * 1024;
                //const int recordSize = 131;


                CancellationTokenSource[] cancelToken = new CancellationTokenSource[_NumberTasks];
                Task[]        tasks        = new Task[_NumberTasks];
                ILogicalLog[] lLogs        = new ILogicalLog[_NumberTasks];
                int           bytesToWrite = 1;

                this.StartPerfWorkloads.Reset();

                for (int i = 0; i < _NumberTasks; i++)
                {
                    //
                    // MUltiply record size by 4 so log is created with correct geometry
                    //

                    Guid   lLogId         = Guid.NewGuid();
                    string logicalLogName = PlatformPathPrefix + _DedicatedDrive + PlatformPathDelimiter + "Perf" + lLogId.ToString() + ".log";
                    lLogs[i] = CreateLogicalLog(phyLog,
                                                lLogId,
                                                null,
                                                logicalLogName,
                                                null,
                                                _LlogSize,
                                                4 * _RecordSize);

                    lLogs[i].CloseAsync(CancellationToken.None).Wait();
                    lLogs[i] = null;
                    lLogs[i] = OpenLogicalLog(phyLog, lLogId);

                    //
                    // Harvest the size of a complete buffer to write
                    //
                    bytesToWrite = (int)lLogs[i].MaximumBlockSize;
                }

                //
                // Get a buffer
                //
                Console.WriteLine("Each formatted record contains {0} bytes", bytesToWrite);

                StartWorkloadThreads(lLogs, _NumberTasks, (int)_RecordSize, cancelToken, out MBPerSecond);

                for (int i = 0; i < _NumberTasks; i++)
                {
                    lLogs[i].CloseAsync(CancellationToken.None).Wait();
                    lLogs[i] = null;
                }

                phyLog.CloseAsync(CancellationToken.None).Wait();
                phyLog = null;

                //* Cleanup
                logManager.DeletePhysicalLogAsync(logName, logId, CancellationToken.None).Wait();
                logManager.CloseAsync(CancellationToken.None).Wait();

                try
                {
                    File.Delete(physLogName.Substring(4));
                }
                catch (Exception)
                {
                    // ok if this fails
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
Example #15
0
        private async Task LogPerformanceWorkloadWorker(
            ILogicalLog lLog,
            int readRecordSize,
            CancellationToken CancelToken
            )
        {
            int totalWriteBytes = numberWriteRecords * writeRecordSize;

            byte[] readRecord = new byte[readRecordSize];

            //
            // Compute old way
            //
            Stopwatch sw = new Stopwatch();

            int numberReadRecords = (totalWriteBytes / readRecordSize) + 1;

            lLog.SeekForRead(0, System.IO.SeekOrigin.Begin);

            int  writtenRecordIndex  = 0;
            int  writtenRecordOffset = 0;
            long time;

            // Reenable this only to test old style performance
#if false
            sw.Start();
            for (int i = 0; i < numberReadRecords; i++)
            {
                int bytesRead;

                bytesRead = await lLog.ReadAsync(readRecord, 0, readRecordSize, 0, CancellationToken.None);

                for (int j = 0; j < bytesRead; j++)
                {
                    if (readRecord[j] != (byte)(writtenRecordOffset * writtenRecordIndex))
                    {
                        Console.WriteLine("Old Failed validation {0} {1}", writtenRecordIndex, writtenRecordOffset);
                        throw new InvalidDataException();
                    }
                    writtenRecordOffset++;
                    if (writtenRecordOffset == writeRecordSize)
                    {
                        writtenRecordIndex++;
                        writtenRecordOffset = 0;
                    }
                }
            }
            sw.Stop();
            time = sw.ElapsedMilliseconds;
            Interlocked.Add(ref this.TotalByteCount, totalWriteBytes);
            Interlocked.Add(ref this.TotalElapsedMs, time);

            Console.WriteLine("Read with small records {0} ms", time);
#endif

            // Compute New Way
            writtenRecordIndex  = 0;
            writtenRecordOffset = 0;

            sw = new Stopwatch();

            lLog.SeekForRead(0, System.IO.SeekOrigin.Begin);

            sw.Start();
            for (int i = 0; i < numberReadRecords; i++)
            {
                int bytesRead;

                bytesRead = await lLog.ReadAsync(readRecord, 0, readRecordSize, readRecordSize, CancellationToken.None);

                for (int j = 0; j < bytesRead; j++)
                {
                    if (readRecord[j] != (byte)(writtenRecordOffset * writtenRecordIndex))
                    {
                        Console.WriteLine("New Failed validation {0} {1}", writtenRecordIndex, writtenRecordOffset);
                        throw new InvalidDataException();
                    }
                    writtenRecordOffset++;
                    if (writtenRecordOffset == writeRecordSize)
                    {
                        writtenRecordIndex++;
                        writtenRecordOffset = 0;
                    }
                }
            }
            sw.Stop();
            time = sw.ElapsedMilliseconds;

            Console.WriteLine("Read with large records {0} ms", time);
            Interlocked.Add(ref this.TotalElapsedMsLargeReads, time);

            return;
        }
Example #16
0
        private async Task ReadLogFileByStream(
            ILogicalLog lLog,
            string s,
            int readRecordSize
            )
        {
            long totalWriteBytes = lLog.Length;

            byte[] readRecord = new byte[readRecordSize];
            Random rnd        = new Random();

            long ticksWaiting = 0;
            long ticksReading = 0;

            Stopwatch swTotal        = new Stopwatch();
            Stopwatch swWaiting      = new Stopwatch();
            Stopwatch swReading      = new Stopwatch();
            long      frequencyPerMs = Stopwatch.Frequency / 1000;

            Stream stream;

            //       This should be 0 so the log will figure it out from reading
            //       directly from the log. This uses a new IOCTL that returns
            //       the max record size and not the max user record size. If the driver
            //       is an old driver then default max record size to 1MB
            //
            stream = lLog.CreateReadStream(1024 * 1024);  // This should match replicator

            stream.Seek(0, System.IO.SeekOrigin.Begin);

            long totalReadBytes = 0;

            swTotal.Start();
            while (totalReadBytes < totalWriteBytes)
            {
                long bytesRead = readRecordSize;

#if RANDOM_READ_SIZES
                bytesRead = rnd.Next(readRecordSize - 1) + 1;

                if (bytesRead + totalReadBytes > totalWriteBytes)
                {
                    bytesRead = totalWriteBytes - totalReadBytes;
                }
#endif
                swReading.Restart();
                bytesRead = await ReadAsync(stream, readRecord, (int)bytesRead);

                swReading.Stop();
                totalReadBytes += bytesRead;
                ticksReading   += swReading.ElapsedTicks;

#if INCLUDE_WAITING_TIME
                swWaiting.Restart();
                int waitingms = rnd.Next(15);
                if (waitingms == 3)
                {
                    waitingms = 1;
                }
                else
                {
                    waitingms = 0;
                }

                await Task.Delay(waitingms);

                swWaiting.Stop();
                ticksWaiting += swWaiting.ElapsedTicks;
#endif
            }
            swTotal.Stop();

            Console.WriteLine("By {0} Stream: Size {1} Bytes Read {2} Elapsed ms {3} Waiting ms {4} Reading ms {5}",
                              s, readRecordSize, totalReadBytes, swTotal.ElapsedMilliseconds, ticksWaiting / frequencyPerMs, ticksReading / frequencyPerMs);

            return;
        }
Example #17
0
 // Truncate the oldest information
 void TruncateHead(
     ILogicalLog logicalLog,
     long streamOffset)
 {
     logicalLog.TruncateHead(streamOffset);
 }
Example #18
0
        private void StartWorkloadThreads(
            ILogicalLog[] lLog,
            byte[] recordBuffer,
            TestLogNotification[] tn75,
            CancellationTokenSource[] tn75CancelToken,
            CancellationTokenSource[] CancelToken,
            out float MBPerSecond
            )
        {
            int numberTasks = tn75.Length;

            Task[] tasks = new Task[numberTasks];

            TotalByteCount = 0;

            for (int i = 0; i < numberTasks; i++)
            {
                int ii = i;
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    ILogicalLog logicalLog    = lLog[ii];
                    TestLogNotification tn75a = tn75[ii];
                    CancellationToken tn75ct  = tn75CancelToken[ii].Token;
                    CancellationToken ct      = CancelToken[ii].Token;
                    LogPerformanceWorkloadWorker(logicalLog, recordBuffer, tn75a, tn75ct, ct).Wait();
                });
            }

            long StartTicks = DateTime.Now.Ticks;

            this.StartPerfWorkloads.Set();
            Thread.CurrentThread.Join(TimeSpan.FromSeconds(_TimeToRunInSeconds));

            for (int i = 0; i < numberTasks; i++)
            {
                try
                {
                    tn75CancelToken[i].Cancel();
                }
                catch
                {
                }
                CancelToken[i].Cancel();
            }

            Task.WaitAll(tasks);

            long byteCount = TotalByteCount;
            long EndTicks  = DateTime.Now.Ticks;

            long totalTimeInSeconds = (EndTicks - StartTicks) / 10000000;
            long bytesPerSecond     = TotalByteCount / totalTimeInSeconds;

            float mbPerSecond = (bytesPerSecond / (1024 * 1024));

            Console.WriteLine("Number Tasks: {0}", numberTasks);
            Console.WriteLine("Seconds running {0}", totalTimeInSeconds);
            Console.WriteLine("RecordSize {0}", recordBuffer.Length);
            Console.WriteLine("Total bytes {0}", TotalByteCount);
            Console.WriteLine("Bytes per second: {0}\nMB per second: {1}", bytesPerSecond, mbPerSecond);

            MBPerSecond = mbPerSecond;
        }
Example #19
0
 /// <summary>
 /// Truncate the most recent information
 /// </summary>
 async void TruncateTail(
     ILogicalLog logicalLog,
     long streamOffset)
 {
     await logicalLog.TruncateTail(streamOffset, CancellationToken.None);
 }
Example #20
0
        protected override async Task <ILogicalLog> CreateLogFileAsync(
            bool createNew,
            CancellationToken cancellationToken)
        {
            Utility.Assert(
                (this.LogicalLog == null) || (this.LogicalLog.IsFunctional == false),
                "(this.logicalLog == null) || (this.logicalLog.IsFunctional == false) Is logical log present: {0}",
                this.LogicalLog != null);

            // Open or create the logical log
            ILogicalLog log = null;

            await this.OpenPhysicalLogAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                // NOTE: only works to fully recover when currentLogFileAlias == baseLogFileAlias
                var currentLogId =
                    await
                    this.physicalLog.RecoverAliasLogsAsync(
                        this.CurrentLogFileAlias + CopySuffix,
                        this.CurrentLogFileAlias,
                        this.CurrentLogFileAlias + BackupSuffix,
                        cancellationToken).ConfigureAwait(false);

                var message =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "CreateLogFileAsync: attempt to open logical log streamId {0} alias {1}, use -- ExtractLogicalLog \"{2}\" {3} {0} outfile.log -- to extract",
                        currentLogId,
                        this.CurrentLogFileAlias,
                        this.physicalLogName,
                        this.physicalLogId);

                FabricEvents.Events.LogManager(this.Tracer.Type, message);

                log = await this.physicalLog.OpenLogicalLogAsync(currentLogId, this.Tracer.Type, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                FabricEvents.Events.LogManager(
                    this.Tracer.Type,
                    "CreateLogFileAsync: Encountered Exception either during physical log recover alias or open logical log: " + ex);

                // TODO asnegi: RDBug #10278280 Adding 0xC0000225 as it is expected HResult for exception. However, it seems that it is not being
                // translated to 0x80070490 or generated properly in dotnet_coreclr_linux.
                if ((ex.InnerException == null) ||
                    ((ex.InnerException.HResult != unchecked ((int)0x80070490)) && (ex.InnerException.HResult != unchecked ((int)0xC0000225))) ||
                    (ex.InnerException.InnerException != null && ex.InnerException.InnerException.HResult != unchecked ((int)0xC0000225)))
                {
                    // Only ERROR_NOT_FOUND is an expected result code. Any other error should be passed back up
                    throw;
                }
            }

            if (log == null)
            {
                if (!createNew)
                {
                    FabricEvents.Events.LogManager(
                        this.Tracer.Type,
                        "CreateLogFileAsync: Expected to find log file but does not exist");
                }

                // Assume open failed above - try creation of new logical log
                var newLogicalLog   = Guid.NewGuid();
                var fullLogfileName = Path.Combine(PlatformPathPrefix + this.LogFileDirectoryPath, newLogicalLog + ".SFlog");
                var trace           = "CreateLogFileAsync: Attempt to create logical log path: " + fullLogfileName + " StreamId: "
                                      + newLogicalLog + " Alias: " + this.CurrentLogFileAlias + "use -- ExtractLogicalLog \""
                                      + this.physicalLogName + "\" " + this.physicalLogId + " " + newLogicalLog
                                      + " outfile.log -- to extract";

                FabricEvents.Events.LogManager(
                    this.Tracer.Type,
                    trace);

                try
                {
                    // log created here - AMW
                    var maximumStreamSizeInBytes = this.maximumStreamSizeInMb * (long)(1024 * 1024);

                    log =
                        await
                        this.physicalLog.CreateLogicalLogAsync(
                            newLogicalLog,
                            this.CurrentLogFileAlias,
                            fullLogfileName,
                            null,
                            maximumStreamSizeInBytes,
                            checked ((uint)this.maximumRecordSizeInKb * 1024),
                            this.optimizeForLowerDiskUsage?System.Fabric.Data.Log.LogManager.LogCreationFlags.UseSparseFile : 0,
                            this.Tracer.Type,
                            cancellationToken).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    FabricEvents.Events.LogManagerExceptionError(
                        this.Tracer.Type,
                        "CreateLogFileAsync: Failed to create logical log path " + fullLogfileName + " StreamID: " + newLogicalLog + " alias: " +
                        this.CurrentLogFileAlias,
                        ex.GetType().ToString(),
                        ex.Message,
                        (ex.InnerException != null) ? ex.InnerException.HResult : ex.HResult,
                        ex.StackTrace);

                    throw;
                }
            }

            if (this.optimizeForLocalSsd)
            {
                // Only write to the dedicated log
                await log.ConfigureWritesToOnlyDedicatedLogAsync(CancellationToken.None).ConfigureAwait(false);
            }

            FabricEvents.Events.LogManager(this.Tracer.Type, "MaxWriteQueueDepth is " + this.maxWriteQueueDepthInKb);

            System.Fabric.Data.Log.LogManager.LogicalLog llog = log as System.Fabric.Data.Log.LogManager.LogicalLog;
            llog.SetWriteDelay(this.logWriteDelayParameters);

            return(log);
        }