예제 #1
0
        private static void BeforeSchemaUpgrade(StorageEnvironment storageEnvironment, ServerStore serverStore)
        {
            // doing this before the schema upgrade to allow to downgrade in case we cannot start the server

            using (var contextPool = new TransactionContextPool(storageEnvironment, serverStore.Configuration.Memory.MaxContextSizeToKeep))
            {
                var license = serverStore.LoadLicense(contextPool);
                if (license == null)
                {
                    return;
                }

                var licenseStatus = LicenseManager.GetLicenseStatus(license);
                if (licenseStatus.Expiration >= RavenVersionAttribute.Instance.ReleaseDate)
                {
                    return;
                }

                var licenseStorage = new LicenseStorage();
                licenseStorage.Initialize(storageEnvironment, contextPool);

                var errorMessage = $"Cannot start the RavenDB server because the expiration date of this license ({FormattedDateTime(licenseStatus.Expiration ?? DateTime.MinValue)}) " +
                                   $"is before the release date of this version ({FormattedDateTime(RavenVersionAttribute.Instance.ReleaseDate)})";
                var buildInfo = licenseStorage.GetBuildInfo();
                if (buildInfo != null)
                {
                    errorMessage += $" You can downgrade to the latest build that was working ({buildInfo.FullVersion})";
                }

                throw new LicenseExpiredException(errorMessage);
예제 #2
0
        private static void BeforeSchemaUpgrade(StorageEnvironment storageEnvironment, ServerStore serverStore)
        {
            // doing this before the schema upgrade to allow to downgrade in case we cannot start the server

            using (var contextPool = new TransactionContextPool(storageEnvironment, serverStore.Configuration.Memory.MaxContextSizeToKeep))
            {
                var license = serverStore.LoadLicense(contextPool);
                if (license == null)
                {
                    return;
                }

                var licenseStatus = LicenseManager.GetLicenseStatus(license);
                if (licenseStatus.Expiration >= RavenVersionAttribute.Instance.ReleaseDate)
                {
                    return;
                }

                string licenseJson = null;
                var    fromPath    = false;
                if (string.IsNullOrEmpty(serverStore.Configuration.Licensing.License) == false)
                {
                    licenseJson = serverStore.Configuration.Licensing.License;
                }
                else if (File.Exists(serverStore.Configuration.Licensing.LicensePath.FullPath))
                {
                    try
                    {
                        licenseJson = File.ReadAllText(serverStore.Configuration.Licensing.LicensePath.FullPath);
                        fromPath    = true;
                    }
                    catch
                    {
                        // expected
                    }
                }

                var errorMessage = $"Cannot start the RavenDB server because the expiration date of current license ({FormattedDateTime(licenseStatus.Expiration ?? DateTime.MinValue)}) " +
                                   $"is before the release date of this version ({FormattedDateTime(RavenVersionAttribute.Instance.ReleaseDate)})";

                string expiredLicenseMessage = "";
                if (string.IsNullOrEmpty(licenseJson) == false)
                {
                    if (LicenseHelper.TryDeserializeLicense(licenseJson, out License localLicense))
                    {
                        var localLicenseStatus = LicenseManager.GetLicenseStatus(localLicense);
                        if (localLicenseStatus.Expiration >= RavenVersionAttribute.Instance.ReleaseDate)
                        {
                            serverStore.LicenseManager.OnBeforeInitialize += () => serverStore.LicenseManager.TryActivateLicenseAsync(throwOnActivationFailure: false).Wait(serverStore.ServerShutdown);
                            return;
                        }

                        var configurationKey =
                            fromPath ? RavenConfiguration.GetKey(x => x.Licensing.LicensePath) : RavenConfiguration.GetKey(x => x.Licensing.License);
                        expiredLicenseMessage = localLicense.Id == license.Id
                            ? ". You can update current license using the setting.json file"
                            : $". The license '{localLicense.Id}' obtained from '{configurationKey}' with expiration date of '{FormattedDateTime(localLicenseStatus.Expiration ?? DateTime.MinValue)}' is also expired.";
                    }
                    else
                    {
                        errorMessage += ". Could not parse the license from setting.json file.";
                        throw new LicenseExpiredException(errorMessage);
                    }
                }

                var licenseStorage = new LicenseStorage();
                licenseStorage.Initialize(storageEnvironment, contextPool);

                var buildInfo = licenseStorage.GetBuildInfo();
                if (buildInfo != null)
                {
                    errorMessage += $" You can downgrade to the latest build that was working ({buildInfo.FullVersion})";
                }
                if (string.IsNullOrEmpty(expiredLicenseMessage) == false)
                {
                    errorMessage += expiredLicenseMessage;
                }
                throw new LicenseExpiredException(errorMessage);
예제 #3
0
        public void Initialize()
        {
            _shutdownNotification = new CancellationTokenSource();

            AbstractLowMemoryNotification.Initialize(ServerShutdown, Configuration);

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("Starting to open server store for " + (Configuration.Core.RunInMemory ? "<memory>" : Configuration.Core.DataDirectory));
            }

            var options = Configuration.Core.RunInMemory
                ? StorageEnvironmentOptions.CreateMemoryOnly(Configuration.Core.DataDirectory)
                : StorageEnvironmentOptions.ForPath(System.IO.Path.Combine(Configuration.Core.DataDirectory, "System"));

            options.SchemaVersion = 2;

            try
            {
                StorageEnvironment.MaxConcurrentFlushes = Configuration.Storage.MaxConcurrentFlushes;
                _env = new StorageEnvironment(options);
                using (var tx = _env.WriteTransaction())
                {
                    tx.DeleteTree("items");// note the different casing, we remove the old items tree
                    _itemsSchema.Create(tx, "Items", 16);
                    tx.Commit();
                }

                using (var tx = _env.ReadTransaction())
                {
                    var table = tx.OpenTable(_itemsSchema, "Items");
                    var itemsFromBackwards = table.SeekBackwardFrom(_itemsSchema.FixedSizeIndexes[EtagIndexName], long.MaxValue);
                    var reader             = itemsFromBackwards.FirstOrDefault();
                    if (reader == null)
                    {
                        _lastEtag = 0;
                    }
                    else
                    {
                        int size;
                        _lastEtag = Bits.SwapBytes(*(long *)reader.Read(3, out size));
                    }
                }
            }
            catch (Exception e)
            {
                if (_logger.IsOperationsEnabled)
                {
                    _logger.Operations(
                        "Could not open server store for " + (Configuration.Core.RunInMemory ? "<memory>" : Configuration.Core.DataDirectory), e);
                }
                options.Dispose();
                throw;
            }

            ContextPool = new TransactionContextPool(_env);
            _timer      = new Timer(IdleOperations, null, _frequencyToCheckForIdleDatabases, TimeSpan.FromDays(7));
            Alerts.Initialize(_env, ContextPool);
            DatabaseInfoCache.Initialize(_env, ContextPool);
            LicenseStorage.Initialize(_env, ContextPool);
        }