Пример #1
0
        CreateContainerBeginWrapper(
            string FullyQualifiedLogFilePath,
            Guid PhysicalLogId,
            Int64 PhysicalLogSize,
            UInt32 MaxAllowedStreams,
            UInt32 MaxRecordSize,
            LogManager.LogCreationFlags CreationFlags,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            using (var pin = new PinCollection())
            {
                this._NativeManager.BeginCreateLogContainer(
                    pin.AddBlittable(FullyQualifiedLogFilePath),
                    PhysicalLogId,
                    pin.AddBlittable(""),
                    PhysicalLogSize,
                    MaxAllowedStreams,
                    MaxRecordSize,
                    CreationFlags,
                    Callback,
                    out context);
            }

            return(context);
        }
                IPhysicalLog.CreateLogicalLogAsync(
                    Guid logicalLogId,
                    string optionalLogStreamAlias,
                    string Path,
                    FileSecurity optionalSecurityInfo,
                    Int64 maximumSize,
                    UInt32 maximumBlockSize,
                    LogManager.LogCreationFlags creationFlags,
                    string traceType,
                    CancellationToken cancellationToken)
                {
                    if (!this.IsOpen)
                    {
                        throw new FabricObjectClosedException();
                    }

                    return(this._Owner.OnCreateLogicalLogAsync(
                               this,
                               logicalLogId,
                               optionalLogStreamAlias,
                               Path,
                               optionalSecurityInfo,
                               maximumSize,
                               maximumBlockSize,
                               creationFlags,
                               traceType,
                               cancellationToken));
                }
Пример #3
0
 CreatePhysicalLogStreamAsync(
     Guid PhysicalLogStreamId,
     Guid PhysicalLogStreamTypeId,
     string OptionalLogStreamAlias,
     string OptionalPath,
     FileSecurity OptionalSecurityInfo,
     Int64 MaximumSize,
     UInt32 MaximumBlockSize,
     LogManager.LogCreationFlags CreationFlags,
     CancellationToken Token)
 {
     return(Utility.WrapNativeAsyncInvokeInMTA <IPhysicalLogStream>(
                (Callback) => this.CreatePhysicalLogStreamBeginWrapper(
                    PhysicalLogStreamId,
                    PhysicalLogStreamTypeId,
                    OptionalLogStreamAlias,
                    OptionalPath,
                    OptionalSecurityInfo,
                    MaximumSize,
                    MaximumBlockSize,
                    CreationFlags,
                    Callback),
                (Context) => this.CreatePhysicalLogStreamEndWrapper(Context),
                Token,
                "NativeLog.CreateLogicalLog"));
 }
Пример #4
0
        CreatePhysicalLogStreamBeginWrapper(
            Guid PhysicalLogStreamId,
            Guid PhysicalLogStreamTypeId,
            string OptionalLogStreamAlias,
            string OptionalPath,
            FileSecurity OptionalSecurityInfo,
            Int64 MaximumSize,
            UInt32 MaximumBlockSize,
            LogManager.LogCreationFlags CreationFlags,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeLog.IKBuffer secInfo = null;

            if (OptionalSecurityInfo != null)
            {
                var secDesc = OptionalSecurityInfo.GetSecurityDescriptorBinaryForm();
                NativeLog.CreateKBuffer((UInt32)secDesc.GetLength(0), out secInfo);
            }

            NativeCommon.IFabricAsyncOperationContext context;

            using (var pin = new PinCollection())
            {
                this._NativeContainer.BeginCreateLogStream(
                    PhysicalLogStreamId,
                    PhysicalLogStreamTypeId,
                    pin.AddBlittable(OptionalLogStreamAlias),
                    // CONSIDER: what about NULL Alias ?
                    pin.AddBlittable(OptionalPath),
                    secInfo,
                    // CONSIDER: does native code need to AddRef() ?
                    MaximumSize,
                    MaximumBlockSize,
                    CreationFlags,
                    Callback,
                    out context);
            }

            return(context);
        }
Пример #5
0
 CreateContainerAsync(
     string FullyQualifiedLogFilePath,
     Guid PhysicalLogId,
     Int64 PhysicalLogSize,
     UInt32 MaxAllowedStreams,
     UInt32 MaxRecordSize,
     LogManager.LogCreationFlags CreationFlags,
     CancellationToken Token)
 {
     return(Utility.WrapNativeAsyncInvokeInMTA <IPhysicalLogContainer>(
                (Callback) => this.CreateContainerBeginWrapper(
                    FullyQualifiedLogFilePath,
                    PhysicalLogId,
                    PhysicalLogSize,
                    MaxAllowedStreams,
                    MaxRecordSize,
                    CreationFlags,
                    Callback),
                (Context) => this.CreateContainerEndWrapper(Context),
                Token,
                "NativeLog.CreateContainer"));
 }
Пример #6
0
            ILogManager.CreatePhysicalLogAsync(
                string pathToCommonContainer,
                Guid physicalLogId,
                long containerSize,
                uint maximumNumberStreams,
                uint maximumLogicalLogBlockSize,
                LogManager.LogCreationFlags CreationFlags,
                CancellationToken cancellationToken)
            {
                if (!this.IsOpen)
                {
                    throw new FabricObjectClosedException();
                }

                return(OnCreatePhysicalLogAsync(
                           pathToCommonContainer,
                           physicalLogId,
                           containerSize,
                           maximumNumberStreams,
                           maximumLogicalLogBlockSize,
                           CreationFlags,
                           cancellationToken));
            }
Пример #7
0
        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);
        }
            OnCreateLogicalLogAsync(
                Handle owningHandle,
                Guid logicalLogId,
                string optionalLogStreamAlias,
                string path,
                FileSecurity optionalSecurityInfo,
                Int64 maximumSize,
                UInt32 maximumBlockSize,
                LogManager.LogCreationFlags creationFlags,
                string traceType,
                CancellationToken cancellationToken)
            {
                Requires.Argument("path", path).NotNull();

                await this._PhysicalLogLock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false);

                try
                {
                    LogicalLog     logicalLog = null;
                    LogicalLogInfo llInfo;

                    if ((this._LogicalLogs.TryGetValue(logicalLogId, out llInfo) == false) ||
                        (llInfo.LogicalLog.TryGetTarget(out logicalLog) == false))
                    {
                        // LLog has not been opened or created or has gone away - attempt to create it

                        var underlyingStream = await this._Container.CreatePhysicalLogStreamAsync(
                            logicalLogId,
                            KLogicalLogInformation.GetLogicalLogStreamType(),
                            optionalLogStreamAlias,
                            path,
                            optionalSecurityInfo,
                            maximumSize,
                            maximumBlockSize,
                            creationFlags,
                            cancellationToken).ConfigureAwait(false);

                        Exception caughtException = null;
                        try
                        {
                            var newLogicalLog = new LogicalLog(this, owningHandle.Id, logicalLogId, underlyingStream, traceType);

                            if (logicalLog == null)
                            {
                                this._LogicalLogs.Add(logicalLogId, new LogicalLogInfo(newLogicalLog, underlyingStream));
                            }
                            else
                            {
                                // The LLog was indexed but had gone away - just update the index with the new LLog
                                llInfo.LogicalLog.SetTarget(newLogicalLog);
                            }

                            newLogicalLog.IsOpen = true;

                            await newLogicalLog.OnCreated(cancellationToken).ConfigureAwait(false);

                            return(newLogicalLog);
                        }
                        catch (Exception ex)
                        {
                            // Cause clean up failed create
                            caughtException = ex;
                        }

                        System.Diagnostics.Debug.Assert(caughtException != null);

                        // clean up failed create and forward the causing exception
                        if (logicalLog != null)
                        {
                            this._LogicalLogs.Remove(logicalLogId);
                        }

                        // TODO: Consider adding trace output when secondary exceptions occur
                        try
                        {
                            await underlyingStream.CloseAsync(cancellationToken).ConfigureAwait(false);
                        }
                        catch
                        {
                        }

                        try
                        {
                            await this._Container.DeletePhysicalLogStreamAsync(logicalLogId, cancellationToken).ConfigureAwait(false);
                        }
                        catch
                        {
                        }

                        throw caughtException;
                    }
                    else
                    {
                        // Already open - fault - only exclusive opens supported
                        throw new UnauthorizedAccessException();
                    }
                }
                finally
                {
                    this._PhysicalLogLock.Set();
                }
            }