Example #1
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());
            }
        }
Example #2
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 #3
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 #4
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);
        }