Example #1
0
		public IndexingExecuter(WorkContext context, DatabaseEtagSynchronizer synchronizer, Prefetcher prefetcher)
			: base(context)
		{
			autoTuner = new IndexBatchSizeAutoTuner(context);
			etagSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);
			prefetchingBehavior = prefetcher.GetPrefetchingBehavior(PrefetchingUser.Indexer, autoTuner);
		}
		public void InitializationShouldLoadLastSynchronizedEtagFromStorage()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			Assert.Equal(1, numberOfCalls);
		}
		public void Calculation1()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			var someEtag = EtagUtil.Increment(Etag.Empty, 1);

			Assert.Equal(someEtag, iSynchronizer.CalculateSynchronizationEtag(null, someEtag));
		}
		public void SynchronizerShouldReturnNullIfNoNewEtagsArrivedFromLastGet()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			var someEtag = EtagUtil.Increment(Etag.Empty, 1);

			iSynchronizer.UpdateSynchronizationState(someEtag);

			var etag = iSynchronizer.GetSynchronizationEtag();
			Assert.Equal(someEtag, etag);
			Assert.Null(iSynchronizer.GetSynchronizationEtag());
		}
		public void SynchronizerShouldReturnLowestEtagInEachCycle()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			var lowestEtag = EtagUtil.Increment(Etag.Empty, 1);
			var higherEtag = EtagUtil.Increment(Etag.Empty, 2);
			var highestEtag = EtagUtil.Increment(Etag.Empty, 2);

			iSynchronizer.UpdateSynchronizationState(higherEtag);
			iSynchronizer.UpdateSynchronizationState(lowestEtag);
			iSynchronizer.UpdateSynchronizationState(highestEtag);

			var etag = iSynchronizer.GetSynchronizationEtag();
			Assert.Equal(lowestEtag, etag);
		}
		public void Calculation2()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			Assert.Equal(Etag.Empty, iSynchronizer.CalculateSynchronizationEtag(null, null));
		}
		public void CalculationShouldNotPersist()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			var lowerEtag = EtagUtil.Increment(Etag.Empty, 1);
			var higherEtag = EtagUtil.Increment(Etag.Empty, 2);

			iSynchronizer.UpdateSynchronizationState(higherEtag);

			Assert.Equal(higherEtag, iSynchronizer.GetSynchronizationEtag());

			iSynchronizer.CalculateSynchronizationEtag(null, higherEtag);

			Assert.Equal(3, numberOfCalls);
		}
		public void CalculationShouldPersist1()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			var lowerEtag = EtagUtil.Increment(Etag.Empty, 1);

			Assert.Equal(lowerEtag, iSynchronizer.CalculateSynchronizationEtag(null, lowerEtag));
			Assert.Equal(2, numberOfCalls);
		}
		public void Calculation5()
		{
			var synchronizer = new DatabaseEtagSynchronizer(storage);
			var iSynchronizer = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);

			var lowerEtag = EtagUtil.Increment(Etag.Empty, 1);
			var higherEtag = EtagUtil.Increment(Etag.Empty, 2);

			Assert.Equal(lowerEtag, iSynchronizer.CalculateSynchronizationEtag(higherEtag, lowerEtag));
		}
Example #10
0
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState transportState = null)
        {
            this.configuration = configuration;
            this.transportState = transportState ?? new TransportState();

            using (LogManager.OpenMappedContext("database", configuration.DatabaseName ?? Constants.SystemDatabase))
            {
                if (configuration.IsTenantDatabase == false)
                {
                    validateLicense = new ValidateLicense();
                    validateLicense.Execute(configuration);
                }
                AppDomain.CurrentDomain.DomainUnload += DomainUnloadOrProcessExit;
                AppDomain.CurrentDomain.ProcessExit += DomainUnloadOrProcessExit;

                Name = configuration.DatabaseName;
                backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Current;

                ExtensionsState = new AtomicDictionary<object>();
                Configuration = configuration;

                ExecuteAlterConfiguration();

                configuration.Container.SatisfyImportsOnce(this);

                workContext = new WorkContext
                {
                    Database = this,
                    DatabaseName = Name,
                    IndexUpdateTriggers = IndexUpdateTriggers,
                    ReadTriggers = ReadTriggers,
                    RaiseIndexChangeNotification = RaiseNotifications,
                    TaskScheduler = backgroundTaskScheduler,
                    Configuration = configuration,
                    IndexReaderWarmers = IndexReaderWarmers
                };

                TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications);

                try
                {
                    sequentialUuidGenerator = new SequentialUuidGenerator();
                    TransactionalStorage.Initialize(sequentialUuidGenerator, DocumentCodecs);
                }
                catch (Exception)
                {
                    TransactionalStorage.Dispose();
                    throw;
                }

                try
                {

	                inFlightTransactionalState = TransactionalStorage.GetInFlightTransactionalState(Put, Delete);

                    TransactionalStorage.Batch(actions =>
                        sequentialUuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

                    // Index codecs must be initialized before we try to read an index
                    InitializeIndexCodecTriggers();

                    IndexDefinitionStorage = new IndexDefinitionStorage(
                        configuration,
                        TransactionalStorage,
                        configuration.DataDirectory,
                        configuration.Container.GetExportedValues<AbstractViewGenerator>(),
                        Extensions);
                    IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration, this);

                    CompleteWorkContextSetup();

                    etagSynchronizer = new DatabaseEtagSynchronizer(TransactionalStorage);
					prefetcher = new Prefetcher(workContext);
                    indexingExecuter = new IndexingExecuter(workContext, etagSynchronizer, prefetcher);

                    InitializeTriggersExceptIndexCodecs();
                    SecondStageInitialization();

                    ExecuteStartupTasks();
                }
                catch (Exception)
                {
                    Dispose();
                    throw;
                }
            }
        }