예제 #1
0
        /// <inheritdoc />
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            if (!FileSystem.DirectoryExists(Config.DataRootPath))
            {
                FileSystem.CreateDirectory(Config.DataRootPath);
            }

            await StartupStoresAsync(context).ThrowIfFailure();

            await LoadHibernatedSessionsAsync(context);

            InitializeAndStartGrpcServer(Config.GrpcPort, BindServices(), Config.RequestCallTokensPerCompletionQueue);

            _serviceReadinessChecker.Ready(context);

            _sessionExpirationCheckTimer = new IntervalTimer(
                () => CheckForExpiredSessionsAsync(context),
                MinTimeSpan(Config.UnusedSessionHeartbeatTimeout, TimeSpan.FromMinutes(CheckForExpiredSessionsPeriodMinutes)),
                message => Tracer.Debug(context, $"[{CheckForExpiredSessionsName}] message"));

            _logIncrementalStatsTimer = new IntervalTimer(
                () => LogIncrementalStatsAsync(context),
                Config.LogIncrementalStatsInterval);

            return(BoolResult.Success);
        }
예제 #2
0
        /// <inheritdoc />
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            // Splitting initialization into two pieces:
            // Normal startup procedure and post-initialization step that notifies all
            // the special stores that the initialization has finished.
            // This is a workaround to make sure hibernated sessions are fully restored
            // before FileSystemContentStore can evict the content.
            var result = await tryStartupCoreAsync();

            foreach (var store in StoresByName.Values)
            {
                if (store is IContentStore contentStore)
                {
                    contentStore.PostInitializationCompleted(context, result);
                }
            }

            return(result);

            async Task <BoolResult> tryStartupCoreAsync()
            {
                try
                {
                    if (!FileSystem.DirectoryExists(Config.DataRootPath))
                    {
                        FileSystem.CreateDirectory(Config.DataRootPath);
                    }

                    await StartupStoresAsync(context).ThrowIfFailure();

                    await LoadHibernatedSessionsAsync(context);

                    InitializeAndStartGrpcServer(Config.GrpcPort, BindServices(), Config.RequestCallTokensPerCompletionQueue, Config.GrpcThreadPoolSize ?? DefaultGrpcThreadPoolSize);

                    _serviceReadinessChecker.Ready(context);

                    _sessionExpirationCheckTimer = new IntervalTimer(
                        () => CheckForExpiredSessionsAsync(context),
                        MinTimeSpan(Config.UnusedSessionHeartbeatTimeout, TimeSpan.FromMinutes(CheckForExpiredSessionsPeriodMinutes)),
                        message => Tracer.Debug(context, $"[{CheckForExpiredSessionsName}] message"));

                    _logIncrementalStatsTimer = new IntervalTimer(
                        () => LogIncrementalStatsAsync(context),
                        Config.LogIncrementalStatsInterval);

                    _logMachineStatsTimer = new IntervalTimer(
                        () => LogMachinePerformanceStatistics(context),
                        Config.LogMachineStatsInterval);

                    return(BoolResult.Success);
                }
                catch (Exception e)
                {
                    return(new BoolResult(e));
                }
            }
        }
예제 #3
0
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            // Splitting initialization into two pieces:
            // Normal startup procedure and post-initialization step that notifies all
            // the special stores that the initialization has finished.
            // This is a workaround to make sure hibernated sessions are fully restored
            // before FileSystemContentStore can evict the content.
            var result = await tryStartupCoreAsync();

            if (!result)
            {
                // We should not be running post initialization operation if the startup operation failed.
                return(result);
            }

            foreach (var store in StoresByName.Values)
            {
                if (store is IContentStore contentStore)
                {
                    contentStore.PostInitializationCompleted(context, result);
                }
            }

            return(result);

            async Task <BoolResult> tryStartupCoreAsync()
            {
                try
                {
                    if (!FileSystem.DirectoryExists(Config.DataRootPath))
                    {
                        FileSystem.CreateDirectory(Config.DataRootPath);
                    }

                    await StartupStoresAsync(context).ThrowIfFailure();

                    foreach (var endpoint in GrpcEndpoints)
                    {
                        await endpoint.StartupAsync(context).ThrowIfFailure();
                    }

                    await LoadHibernatedSessionsAsync(context);

                    if (!Config.DisableGrpcServer)
                    {
                        InitializeAndStartGrpcServer(context, Config);
                    }

                    _serviceReadinessChecker.Ready(context);

                    _sessionExpirationCheckTimer = new IntervalTimer(
                        () => CheckForExpiredSessionsAsync(context),
                        MinTimeSpan(Config.UnusedSessionHeartbeatTimeout, TimeSpan.FromMinutes(CheckForExpiredSessionsPeriodMinutes)),
                        logAction: message => Tracer.Debug(context, $"{CheckForExpiredSessionsName}: {message}"));

                    _logIncrementalStatsTimer = new IntervalTimer(
                        () => LogIncrementalStatsAsync(context, logAtShutdown: false),
                        Config.LogIncrementalStatsInterval);

                    _logMachineStatsTimer = new IntervalTimer(
                        () => LogMachinePerformanceStatistics(context),
                        Config.LogMachineStatsInterval);

                    return(BoolResult.Success);
                }
                catch (Exception e)
                {
                    return(new BoolResult(e));
                }
            }
        }