async Task <ILogicalLog> OpenLogicalLog( IPhysicalLog phylog, Guid logicalLogId) { ILogicalLog t = await phylog.OpenLogicalLogAsync( logicalLogId, "", CancellationToken.None); return(t); }
ILogicalLog OpenLogicalLog( IPhysicalLog phylog, Guid logicalLogId) { Task <ILogicalLog> t = phylog.OpenLogicalLogAsync( logicalLogId, "", CancellationToken.None); t.Wait(); return(t.Result); }
async Task <IPhysicalLog> OpenPhysicalLog( ILogManager manager, string pathToCommonContainer, Guid physicalLogId) { IPhysicalLog t = await manager.OpenPhysicalLogAsync( pathToCommonContainer, physicalLogId, false, CancellationToken.None); return(t); }
private async Task OpenPhysicalLogAsync(CancellationToken cancellationToken) { if (this.physicalLogManager == null) { this.physicalLogManager = await System.Fabric.Data.Log.LogManager.OpenAsync(globalLogManagerType, CancellationToken.None).ConfigureAwait(false); } // Assumption: an out-of-band management behavior has created the physical log if (this.physicalLog == null) { var physicalLogPathName = PlatformPathPrefix + this.physicalLogName; try { FabricEvents.Events.LogManager( this.Tracer.Type, "OpenPhysicalLogAsync: Attempting to open physical log path " + physicalLogPathName + " logID: " + this.physicalLogId); this.physicalLog = await this.physicalLogManager.OpenPhysicalLogAsync( physicalLogPathName, this.physicalLogId, this.useStagingLog, cancellationToken).ConfigureAwait(false); FabricEvents.Events.LogManager( this.Tracer.Type, "OpenPhysicalLogAsync: Successfully opened physical log path " + physicalLogPathName + " logID: " + this.physicalLogId); } catch (Exception ex) { FabricEvents.Events.LogManagerExceptionError( this.Tracer.Type, "OpenPhysicalLogAsync: Failed to open " + physicalLogPathName + " logID: " + this.physicalLogId, ex.GetType().ToString(), ex.Message, ex.HResult, ex.StackTrace); throw; } } }
internal KtlLogManager( string baseLogFileAlias, IncomingBytesRateCounterWriter incomingBytesRateCounter, LogFlushBytesRateCounterWriter logFlushBytesRateCounter, AvgBytesPerFlushCounterWriter bytesPerFlushCounterWriter, AvgFlushLatencyCounterWriter avgFlushLatencyCounterWriter, AvgSerializationLatencyCounterWriter avgSerializationLatencyCounterWriter, LogWriteFaultInjectionParameters logWriteDelayParameters) : base( baseLogFileAlias, incomingBytesRateCounter, logFlushBytesRateCounter, bytesPerFlushCounterWriter, avgFlushLatencyCounterWriter, avgSerializationLatencyCounterWriter) { this.physicalLogManager = null; this.physicalLog = null; this.logWriteDelayParameters = logWriteDelayParameters; }
ILogicalLog CreateLogicalLog( IPhysicalLog phylog, Guid logicalLogId, string optionalLogStreamAlias, string optionalPath, FileSecurity optionalSecurityInfo, Int64 maximumSize, UInt32 maximumBlockSize) { Task <ILogicalLog> t = phylog.CreateLogicalLogAsync( logicalLogId, optionalLogStreamAlias, optionalPath, optionalSecurityInfo, maximumSize, maximumBlockSize, LogManager.LogCreationFlags.UseSparseFile, // Logical logs are sparse "", CancellationToken.None); t.Wait(); return(t.Result); }
private async Task ClosePhysicalLogAsync(CancellationToken cancellationToken) { // Close in the reverse order of open. var snapPhysicalLog = this.physicalLog; if (snapPhysicalLog != null) { this.physicalLog = null; await snapPhysicalLog.CloseAsync(cancellationToken).ConfigureAwait(false); snapPhysicalLog.Dispose(); } var snapPhysicalLogManager = this.physicalLogManager; if (snapPhysicalLogManager != null) { this.physicalLogManager = null; await snapPhysicalLogManager.CloseAsync(cancellationToken).ConfigureAwait(false); snapPhysicalLogManager.Dispose(); } }
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; } }
OnOpenPhysicalLogAsync( string pathToCommonContainer, Guid physicalLogId, bool isStagingLog, CancellationToken cancellationToken) { Requires.Argument("pathToCommonContainer", pathToCommonContainer).NotNull(); IPhysicalLog result = null; await _Lock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false); try { PhysicalLog subjectLog; if (_Logs.TryGetValue(physicalLogId, out subjectLog) == false) { // P.Log has not been opened yet- attempt to open its underpinnings var underlyingContainer = await _AppDomainPhysLogManager.OpenLogContainerAsync( pathToCommonContainer, isStagingLog?Guid.Empty : physicalLogId, cancellationToken).ConfigureAwait(false); Exception caughtException = null; try { subjectLog = new PhysicalLog(physicalLogId, underlyingContainer); _Logs.Add(physicalLogId, subjectLog); subjectLog.IsOpen = true; result = await subjectLog.OnCreateHandle(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { // Cause clean up failed create caughtException = ex; } if (caughtException != null) { // clean up failed create and forward the causing exception if (subjectLog != null) { subjectLog.IsOpen = false; _Logs.Remove(physicalLogId); } try { await underlyingContainer.CloseAsync(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { AppTrace.TraceSource.WriteInfo(TraceType, "OnOpenPhysicalLogAsync - CloseAsync: Exception {0}", ex); } throw caughtException; } } else { // Already open - just alias with another handle result = await subjectLog.OnCreateHandle(cancellationToken).ConfigureAwait(false); } } finally { _Lock.Set(); } return(result); }
OnCreatePhysicalLogAsync( string pathToCommonContainer, Guid physicalLogId, long containerSize, uint maximumNumberStreams, uint maximumLogicalLogBlockSize, LogManager.LogCreationFlags CreationFlags, CancellationToken cancellationToken) { Requires.Argument("pathToCommonContainer", pathToCommonContainer).NotNull(); IPhysicalLog result = null; await _Lock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false); try { PhysicalLog subjectLog; if (_Logs.TryGetValue(physicalLogId, out subjectLog) == false) { // P.Log has not been opened or created - attempt to create it var underlyingContainer = await _AppDomainPhysLogManager.CreateContainerAsync( pathToCommonContainer, physicalLogId, containerSize, maximumNumberStreams, maximumLogicalLogBlockSize, CreationFlags, cancellationToken).ConfigureAwait(false); Exception caughtException = null; try { // Make and "open" PhysicalLog representing the underlying IPhysicalLogContainer subjectLog = new PhysicalLog(physicalLogId, underlyingContainer); _Logs.Add(physicalLogId, subjectLog); subjectLog.IsOpen = true; result = await subjectLog.OnCreateHandle(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { // Cause clean up failed create caughtException = ex; } if (caughtException != null) { // clean up failed - create and forward the causing exception if (subjectLog != null) { subjectLog.IsOpen = false; _Logs.Remove(physicalLogId); } try { await underlyingContainer.CloseAsync(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { AppTrace.TraceSource.WriteInfo(TraceType, "OnCreatePhysicalLogAsync - CloseAsync: Exception {0}", ex); } try { await underlyingContainer.DeletePhysicalLogStreamAsync(physicalLogId, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { AppTrace.TraceSource.WriteInfo(TraceType, "OnCreatePhysicalLogAsync - DeletePhysicalLogStreamAsync: Exception {0}", ex); } throw caughtException; } } else { // Have an existing physical log with this id already - fault throw new UnauthorizedAccessException(SR.Error_PhysicalLog_Exists); } } finally { _Lock.Set(); } return(result); }