public void DeleteDocuments(string documentType, string[] documentIds,
                                    IndexingPriority priority = IndexingPriority.Default)
        {
            if (priority != IndexingPriority.NearRealTime)
            {
                ThrottleByQueueCount(priority, ThrottleQueueCount);
            }

            IndexingJobs.EnqueueDeleteDocuments(documentType, documentIds, IndexingPriorityToJobPriority(priority));
        }
Exemple #2
0
        public void SetIndexPriority(string index, IndexingPriority priority)
        {
            var readResult = storage.IndexingStats.Read(index);

            if (readResult == null)
            {
                throw new ArgumentException(string.Format("There is no index with the name: '{0}'", index));
            }
            var key = (RavenJObject)readResult.Key.CloneToken();

            key["priority"] = (int)priority;
            storage.IndexingStats.UpdateKey(key);
        }
        protected virtual string IndexingPriorityToJobPriority(IndexingPriority priority)
        {
            switch (priority)
            {
            case IndexingPriority.NearRealTime:
                return(JobPriority.High);

            case IndexingPriority.Background:
                return(JobPriority.Low);

            default:
                throw new ArgumentException($"Unkown priority: {priority}");
            }
        }
Exemple #4
0
        public void SetIndexPriority(int id, IndexingPriority priority)
        {
            Api.JetSetCurrentIndex(session, IndexesStats, "by_key");
            Api.MakeKey(session, IndexesStats, id, MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, IndexesStats, SeekGrbit.SeekEQ) == false)
            {
                throw new IndexDoesNotExistsException(message: "There is no index with id: " + id.ToString());
            }

            using (var update = new Update(session, IndexesStats, JET_prep.Replace))
            {
                Api.SetColumn(session, IndexesStats,
                              tableColumnsCache.IndexesStatsColumns["priority"],
                              (int)priority);
                update.Save();
            }
        }
        protected virtual void ThrottleByQueueCount(IndexingPriority priority, int maxQueueCount)
        {
            var  queue         = IndexingPriorityToJobPriority(priority);
            var  monitoringApi = JobStorage.Current.GetMonitoringApi();
            long queued        = 0;

            while (true)
            {
                queued = monitoringApi.EnqueuedCount(queue);
                if (queued <= maxQueueCount)
                {
                    return;
                }

                Thread.Sleep(SleepTimeMs);
            }
        }
 public void SetIndexPriority(int id, IndexingPriority priority)
 {
     tableStorage.IndexingMetadata.Add(writeBatch.Value, CreateKey(id, "priority"), BitConverter.GetBytes((int)priority));
 }
Exemple #7
0
		public string[] PutIndexes(string[] names, IndexDefinition[] definitions, IndexingPriority[] priorities)
		{
			var createdIndexes = new List<string>();
			var prioritiesList = new List<IndexingPriority>();
			try
			{
				for (int i = 0; i < names.Length; i++)
				{
					var name = names[i];
					var definition = definitions[i];
					var priority = priorities[i];
					if (name == null)
						throw new ArgumentNullException("names","Names cannot contain null values");

					IsIndexNameValid(name);

					var existingIndex = IndexDefinitionStorage.GetIndexDefinition(name);

					if (existingIndex != null)
					{
						switch (existingIndex.LockMode)
						{
							case IndexLockMode.SideBySide:
								Log.Info("Index {0} not saved because it might be only updated by side-by-side index");
								throw new InvalidOperationException("Can not overwrite locked index: " + name + ". This index can be only updated by side-by-side index.");

							case IndexLockMode.LockedIgnore:
								Log.Info("Index {0} not saved because it was lock (with ignore)", name);
								continue;

							case IndexLockMode.LockedError:
								throw new InvalidOperationException("Can not overwrite locked index: " + name);
						}
					}

					name = name.Trim();

					if (name.Equals("dynamic", StringComparison.OrdinalIgnoreCase) ||
					    name.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase))
					{
						throw new ArgumentException("Cannot use index name " + name + " because it clashes with reserved dynamic index names", "name");
					}

					if (name.Contains("//"))
					{
						throw new ArgumentException("Cannot use an index with // in the name, but got: " + name, "name");
					}

					AssertAnalyzersValid(definition);

					switch (FindIndexCreationOptions(definition, ref name))
					{
						case IndexCreationOptions.Noop:
							continue;
						case IndexCreationOptions.UpdateWithoutUpdatingCompiledIndex:
							// ensure that the code can compile
							new DynamicViewCompiler(definition.Name, definition, Database.Extensions, IndexDefinitionStorage.IndexDefinitionsPath, Database.Configuration).GenerateInstance();
							IndexDefinitionStorage.UpdateIndexDefinitionWithoutUpdatingCompiledIndex(definition);							
							break;
						case IndexCreationOptions.Update:
							// ensure that the code can compile
							new DynamicViewCompiler(definition.Name, definition, Database.Extensions, IndexDefinitionStorage.IndexDefinitionsPath, Database.Configuration).GenerateInstance();
							DeleteIndex(name);
							break;
					}

					PutNewIndexIntoStorage(name, definition,true);

					WorkContext.ClearErrorsFor(name);

					TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new IndexChangeNotification
					{
						Name = name,
						Type = IndexChangeTypes.IndexAdded,
					}));

					createdIndexes.Add(name);
					prioritiesList.Add(priority);
				}

                var indexesIds = createdIndexes.Select(x => Database.IndexStorage.GetIndexInstance(x).indexId).ToArray();
                Database.TransactionalStorage.Batch(accessor => accessor.Indexing.SetIndexesPriority(indexesIds, prioritiesList.ToArray()));
			
				return createdIndexes.ToArray();
			}
			catch (Exception e)
			{
			    Log.WarnException("Could not create index batch", e);
                foreach (var index in createdIndexes)
                {
                    DeleteIndex(index);
                }
				throw;
			}
		}
Exemple #8
0
		public void SetIndexesPriority(int[] ids, IndexingPriority[] priorities)
		{
			for (int i = 0; i < ids.Length; i++)
			{
				var id = ids[i];
				var priority = priorities[i];
				Api.JetSetCurrentIndex(session, IndexesStats, "by_key");
				Api.MakeKey(session, IndexesStats, id, MakeKeyGrbit.NewKey);
				if (Api.TrySeek(session, IndexesStats, SeekGrbit.SeekEQ) == false)
				{
					throw new IndexDoesNotExistsException(message: "There is no index with id: " + id.ToString());
				}

				using (var update = new Update(session, IndexesStats, JET_prep.Replace))
				{
					Api.SetColumn(session, IndexesStats,
						tableColumnsCache.IndexesStatsColumns["priority"],
						(int)priority);
					update.Save();
				}
			}
		}
Exemple #9
0
 public void SetIndexPriority(string name, IndexingPriority priority)
 {
     AsyncHelpers.RunSync(() => asyncServerClient.SetIndexPriorityAsync(name, priority));
 }
		public void SetIndexPriority(int id, IndexingPriority priority)
		{
			tableStorage.IndexingMetadata.Add(writeBatch.Value, CreateKey(id, "priority"), BitConverter.GetBytes((int)priority));
		}
Exemple #11
0
        public void SetIndexPriority(string index, IndexingPriority priority)
        {
            Api.JetSetCurrentIndex(session, IndexesStats, "by_key");
            Api.MakeKey(session, IndexesStats, index, Encoding.Unicode, MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, IndexesStats, SeekGrbit.SeekEQ) == false)
                throw new IndexDoesNotExistsException("There is no index named: " + index);

            using (var update = new Update(session, IndexesStats, JET_prep.Replace))
            {
                Api.SetColumn(session, IndexesStats,
                              tableColumnsCache.IndexesStatsColumns["priority"],
                              (int)priority);
                update.Save();
            }
        }
		public void SetIndexPriority(string index, IndexingPriority priority)
        {
            var readResult = storage.IndexingStats.Read(index);
            if (readResult == null)
                throw new ArgumentException(string.Format("There is no index with the name: '{0}'", index));
            var key = (RavenJObject)readResult.Key.CloneToken();
            key["priority"] = (int) priority;
            storage.IndexingStats.UpdateKey(key);
        }
Exemple #13
0
 public void SetIndexPriority(string name, IndexingPriority priority)
 {
     asyncServerClient.SetIndexPriorityAsync(name, priority).WaitUnwrap();
 }
		public void SetIndexPriority(int id, IndexingPriority priority)
		{
			var key = CreateKey(id);

			ushort version;
			var index = Load(tableStorage.IndexingStats, key, out version);

			index["priority"] = (int)priority;

			tableStorage.IndexingStats.Add(writeBatch.Value, key, index, version);
		}