コード例 #1
0
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Enter RunAsync");
            FabricEvents.Events.BackupRestoreEnabled(this.Context.TraceId);

            // TODO: Ensure that the requests dont come in before we do the necessary initializations which are being done below
            await WorkItemHandler.StartAndScheduleWorkItemHandler(this);

            BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Registering config update handlers now");

            var configUpdateHandler = new ConfigUpdateHandler();

            configStore = NativeConfigStore.FabricGetConfigStore(configUpdateHandler);

            var certConfigHandler = new EncryptionCertConfigHandler(this.EncryptionCertUpdateCallbackAsync, this, cancellationToken);

            encryptionCertConfigStore = NativeConfigStore.FabricGetConfigStore(certConfigHandler);

            await certConfigHandler.InitializeAsync();

            Task <RetentionManager> retentionManagerTask = RetentionManager.CreateOrGetRetentionManager(this);

            BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Config update handlers registered");

            try
            {
                while (!configUpdateHandler.ProcessRecycleRequired)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (this.retentionManager == null && retentionManagerTask.IsCompleted)
                    {
                        this.retentionManager = retentionManagerTask.Result;
                    }
                    await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
                }

                // Process recycle is required, throwing exception from RunAsync
                throw new Exception("Process recycle needed.");
            }
            finally
            {
                this.retentionManager?.StopRetentionManager();
                BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Exit RunAsync");
            }
        }
コード例 #2
0
        // PartititonCleanUpList is required.

        internal static async Task <RetentionManager> CreateOrGetRetentionManager(StatefulService statefulService)
        {
            if (RManager == null)
            {
                await RManagerSemaphore.WaitAsync();

                if (RManager == null)
                {
                    try
                    {
                        RetentionManager retentionManager = new RetentionManager(statefulService);
                        await retentionManager.InitialiseRetentionManager();

                        RManager = retentionManager;
                    }
                    finally
                    {
                        RManagerSemaphore.Release();
                    }
                }
            }
            return(RManager);
        }