Exemplo n.º 1
0
		public RavenDB_2767()
		{
			store = NewDocumentStore();
			var workContext = store.SystemDatabase.WorkContext;
			prefetchingBehavior = new PrefetchingBehavior(PrefetchingUser.Indexer, workContext, new IndexBatchSizeAutoTuner(workContext));
			prefetchingBehavior.ShouldHandleUnusedDocumentsAddedAfterCommit = true;
		}
Exemplo n.º 2
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);
		}
Exemplo n.º 3
0
		public IndexingExecuter(WorkContext context, Prefetcher prefetcher)
			: base(context)
		{
			autoTuner = new IndexBatchSizeAutoTuner(context);
			this.prefetcher = prefetcher;
			defaultPrefetchingBehavior = prefetcher.CreatePrefetchingBehavior(PrefetchingUser.Indexer, autoTuner);
			prefetchingBehaviors.TryAdd(defaultPrefetchingBehavior);
		}
Exemplo n.º 4
0
 public IndexingExecuter(WorkContext context, Prefetcher prefetcher, IndexReplacer indexReplacer)
     : base(context, indexReplacer)
 {
     autoTuner = new IndexBatchSizeAutoTuner(context);
     this.prefetcher = prefetcher;
     defaultPrefetchingBehavior = prefetcher.CreatePrefetchingBehavior(PrefetchingUser.Indexer, autoTuner, "Default Prefetching behavior", true);
     defaultPrefetchingBehavior.ShouldHandleUnusedDocumentsAddedAfterCommit = true;
     prefetchingBehaviors.TryAdd(defaultPrefetchingBehavior);
 }
Exemplo n.º 5
0
		public void RemovePrefetchingBehavior(PrefetchingBehavior prefetchingBehavior)
		{
			lock (this)
			{
				prefetchingBehaviors = new List<PrefetchingBehavior>(prefetchingBehaviors.Except(new[]
				{
					prefetchingBehavior
				}));

				prefetchingBehavior.Dispose();
			}
		}
Exemplo n.º 6
0
		public PrefetchingBehavior CreatePrefetchingBehavior(PrefetchingUser user, BaseBatchSizeAutoTuner autoTuner)
		{
			lock (this)
			{
				var newPrefetcher = new PrefetchingBehavior(user, workContext, autoTuner ?? new IndependentBatchSizeAutoTuner(workContext));

				prefetchingBehaviors = new List<PrefetchingBehavior>(prefetchingBehaviors)
				{
					newPrefetcher
				};

				return newPrefetcher;
			}
		}
Exemplo n.º 7
0
		public void Execute(DocumentDatabase database)
		{
			etagSynchronizer = database.EtagSynchronizer.GetSynchronizer(EtagSynchronizerType.SqlReplicator);
			prefetchingBehavior = database.Prefetcher.GetPrefetchingBehavior(PrefetchingUser.SqlReplicator, null);

			Database = database;
			Database.OnDocumentChange += (sender, notification, metadata) =>
			{
				if (notification.Id == null)
					return;

				if (metadata == null)
					return; // this is a delete being made on an already deleted document

				if (notification.Type == DocumentChangeTypes.Delete)
				{
					RecordDelete(notification.Id, metadata);
				}

				if (!notification.Id.StartsWith("Raven/SqlReplication/Configuration/", StringComparison.InvariantCultureIgnoreCase))
					return;

				replicationConfigs = null;
				statistics.Clear();
				log.Debug(() => "Sql Replication configuration was changed.");
			};

			GetReplicationStatus();

			var task = Task.Factory.StartNew(() =>
			{
				using (LogContext.WithDatabase(database.Name))
				{
					try
					{
						BackgroundSqlReplication();
					}
					catch (Exception e)
					{
						log.ErrorException("Fatal failure when replicating to SQL. All SQL Replication activity STOPPED", e);
					}
				}
			}, TaskCreationOptions.LongRunning);
			database.ExtensionsState.GetOrAdd(typeof(SqlReplicationTask).FullName, k => new DisposableAction(task.Wait));
		}
Exemplo n.º 8
0
		public PrefetchingBehavior GetPrefetchingBehavior(PrefetchingUser user)
		{
			PrefetchingBehavior value;
			if (prefetchingBehaviors.TryGetValue(user, out value))
				return value;
			lock (this)
			{
				if (prefetchingBehaviors.TryGetValue(user, out value))
					return value;

				value = new PrefetchingBehavior(workContext, new IndexBatchSizeAutoTuner(workContext));

				prefetchingBehaviors = new Dictionary<PrefetchingUser, PrefetchingBehavior>(prefetchingBehaviors)
				{
					{user, value}
				};
				return value;
			}
		}
Exemplo n.º 9
0
		public void Execute(DocumentDatabase database)
		{
			etagSynchronizer = database.EtagSynchronizer.GetSynchronizer(EtagSynchronizerType.Replicator);
			prefetchingBehavior = database.Prefetcher.GetPrefetchingBehavior(PrefetchingUser.Replicator);

			docDb = database;
			var replicationRequestTimeoutInMs =
				docDb.Configuration.GetConfigurationValue<int>("Raven/Replication/ReplicationRequestTimeout") ??
				60 * 1000;

			httpRavenRequestFactory = new HttpRavenRequestFactory { RequestTimeoutInMs = replicationRequestTimeoutInMs };

            var task = new Task(Execute, TaskCreationOptions.LongRunning);
			var disposableAction = new DisposableAction(task.Wait);
			// make sure that the doc db waits for the replication task shutdown
			docDb.ExtensionsState.GetOrAdd(Guid.NewGuid().ToString(), s => disposableAction);
			task.Start();
            

		}
Exemplo n.º 10
0
        protected PrefetcherWithContext CreatePrefetcher(Action<InMemoryRavenConfiguration> modifyConfiguration = null, Action<WorkContext> modifyWorkContext = null)
        {
            var configuration = new InMemoryRavenConfiguration
            {
                RunInMemory = true
            };

            configuration.Initialize();

            if (modifyConfiguration != null)
                modifyConfiguration(configuration);

            var transactionalStorage = new TransactionalStorage(configuration, () => { }, () => { }, () => { }, () => { });
            transactionalStorage.Initialize(new SequentialUuidGenerator { EtagBase = 0 }, new OrderedPartCollection<AbstractDocumentCodec>());

            var workContext = new WorkContext
            {
                Configuration = configuration,
                TransactionalStorage = transactionalStorage
            };

            if (modifyWorkContext != null)
                modifyWorkContext(workContext);

            var autoTuner = new IndexBatchSizeAutoTuner(workContext);

            var prefetchingBehavior = new PrefetchingBehavior(PrefetchingUser.Indexer, workContext, autoTuner, string.Empty);

            var prefetcherWithContext = new PrefetcherWithContext
                                        {
                                            AutoTuner = autoTuner,
                                            Configuration = configuration,
                                            PrefetchingBehavior = prefetchingBehavior,
                                            TransactionalStorage = transactionalStorage,
                                            WorkContext = workContext
                                        };

            createdPrefetchers.Add(prefetcherWithContext);

            return prefetcherWithContext;
        }
Exemplo n.º 11
0
        public PrefetchingBehavior CreatePrefetchingBehavior(PrefetchingUser user, BaseBatchSizeAutoTuner autoTuner, string prefetchingUserDescription, bool isDefault = false)
        {
            lock (this)
            {
                var newPrefetcher = 
                    new PrefetchingBehavior(user, 
                                            workContext, 
                                            autoTuner ?? new IndependentBatchSizeAutoTuner(workContext, user), 
                                            prefetchingUserDescription, 
                                            isDefault,
                                            GetPrefetchintBehavioursCount,
                                            GetPrefetchingBehaviourSummary);

                prefetchingBehaviors = new List<PrefetchingBehavior>(prefetchingBehaviors)
                {
                    newPrefetcher
                };

                return newPrefetcher;
            }
        }
Exemplo n.º 12
0
		public IndexingExecuter(WorkContext context, Prefetcher prefetcher)
			: base(context)
		{
			autoTuner = new IndexBatchSizeAutoTuner(context);
			prefetchingBehavior = prefetcher.GetPrefetchingBehavior(PrefetchingUser.Indexer, autoTuner);
		}
Exemplo n.º 13
0
		public PreFetching()
		{
			store = NewDocumentStore();
			var workContext = store.DocumentDatabase.WorkContext;
			prefetchingBehavior = new PrefetchingBehavior(PrefetchingUser.Indexer, workContext, new IndexBatchSizeAutoTuner(workContext));
		}