Beispiel #1
0
        private bool ExecuteTasks()
        {
            bool foundWork = false;

            transactionalStorage.Batch(actions =>
            {
                Task task = GetApplicableTask(actions);
                if (task == null)
                {
                    return;
                }

                log.Debug("Executing {0}", task);
                foundWork = true;

                try
                {
                    task.Execute(context);
                }
                catch (Exception e)
                {
                    log.WarnException(
                        string.Format("Task {0} has failed and was deleted without completing any work", task),
                        e);
                }
            });
            return(foundWork);
        }
 public void AddTask(Task task, DateTime addedAt)
 {
     storage.Tasks.Put(new JObject
     {
         {"index", task.Index},
         {"id", DocumentDatabase.CreateSequentialUuid().ToByteArray()},
         {"time", addedAt},
         {"type", task.Type},
         {"mergable", task.SupportsMerging}
     }, task.AsBytes());
 }
		public void AddTask(Task task)
		{
			var pos = Writer.Position;
			BinaryWriter.Write(task.Index);
			BinaryWriter.Write(task.Type);
			new JsonSerializer().Serialize(new BsonWriter(Writer), task);
			Mutator.IncrementTaskCount();
			task.Id = Mutator.Tasks.Enqueue(pos);
			Mutator.TasksByIndex.Add(new JObject(
			                         	new JProperty("Index", task.Index),
			                         	new JProperty("Id", task.Id)
			                         	),
			                         DateTime.UtcNow.ToBinary());
		}
Beispiel #4
0
	    public void AddTask(Task task, DateTime addedAt)
		{
			int actualBookmarkSize;
			var bookmark = new byte[SystemParameters.BookmarkMost];
			using (var update = new Update(session, Tasks, JET_prep.Insert))
			{
				Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["task"], task.AsBytes());
				Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["for_index"], task.Index, Encoding.Unicode);
				Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["task_type"], task.Type, Encoding.Unicode);
				Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["supports_merging"], task.SupportsMerging);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["added_at"], addedAt);

				update.Save(bookmark, bookmark.Length, out actualBookmarkSize);
			}
			Api.JetGotoBookmark(session, Tasks, bookmark, actualBookmarkSize);
		}
        private void MergeSimilarTasks(Task task, byte [] taskId, out int taskCount)
        {
            taskCount = 1;
            if (task.SupportsMerging == false)
                return;

            var keyForTaskToTryMergings = storage.Tasks["ByIndexAndType"].SkipTo(new RavenJObject
            {
                {"index", task.Index},
                {"type", task.Type},
            })
            .Where(x => new Guid(x.Value<byte[]>("id")) != new Guid(taskId))
                .TakeWhile(x =>
                           StringComparer.InvariantCultureIgnoreCase.Equals(x.Value<string>("index"), task.Index) &&
                           StringComparer.InvariantCultureIgnoreCase.Equals(x.Value<string>("type"), task.Type)
                );

            foreach (var keyForTaskToTryMerging in keyForTaskToTryMergings)
            {
                var readResult = storage.Tasks.Read(keyForTaskToTryMerging);
                if(readResult == null)
                    continue;
                Task existingTask;
                try
                {
                    existingTask = Task.ToTask(readResult.Key.Value<string>("type"), readResult.Data());
                }
                catch (Exception e)
                {
                    logger.ErrorException(
						string.Format("Could not create instance of a task: {0}", readResult.Key),
						e);
                    storage.Tasks.Remove(keyForTaskToTryMerging);
                    continue;
                }

                if (task.TryMerge(existingTask) == false)
                    continue;

                storage.Tasks.Remove(keyForTaskToTryMerging);

                taskCount += 1;

                if (task.SupportsMerging == false)
                    return;
            }
        }
		public override void Merge(Task task)
		{
			var t = (TouchReferenceDocumentIfChangedTask)task;

			foreach (var kvp in t.ReferencesToCheck)
			{
				Etag etag;
				if (ReferencesToCheck.TryGetValue(kvp.Key, out etag) == false)
				{
					ReferencesToCheck[kvp.Key] = kvp.Value;
				}
				else
				{
					ReferencesToCheck[kvp.Key] = etag.CompareTo(kvp.Value) < 0 ? etag : kvp.Value;
				}
			}
		}
        public override void Merge(Task task)
        {
            var t = (TouchMissingReferenceDocumentTask)task;

            foreach (var kvp in t.MissingReferences)
            {
                HashSet<string> set;
                if (MissingReferences.TryGetValue(kvp.Key, out set) == false)
                {
                    MissingReferences[kvp.Key] = kvp.Value;
                }
                else
                {
                    set.UnionWith(kvp.Value);
                }
            }
        }
Beispiel #8
0
        public void AddTask(Task task)
        {
            int actualBookmarkSize;
            var bookmark = new byte[SystemParameters.BookmarkMost];
            using (var update = new Update(session, Tasks, JET_prep.Insert))
            {
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["task"], task.AsString(), Encoding.Unicode);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["for_index"], task.Index, Encoding.Unicode);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["task_type"], task.Type, Encoding.Unicode);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["supports_merging"], task.SupportsMerging);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["added_at"], DateTime.Now);

                update.Save(bookmark, bookmark.Length, out actualBookmarkSize);
            }
            Api.JetGotoBookmark(session, Tasks, bookmark, actualBookmarkSize);
            if (logger.IsDebugEnabled)
                logger.DebugFormat("New task '{0}'", task.AsString());
        }
Beispiel #9
0
		public override bool TryMerge(Task task)
		{
			return true;
		}
		public override bool TryMerge(Task task)
		{
			var removeFromIndexTask = ((RemoveFromIndexTask)task);
			Keys.UnionWith(removeFromIndexTask.Keys);
			return true;
		}
Beispiel #11
0
		public abstract void Merge(Task task);
		public override bool TryMerge(Task task)
		{
			var indexDocumentTask = ((IndexDocumentsTask)task);
			Keys = Keys.Union(indexDocumentTask.Keys).ToArray();
			return true;
		}
		public override void Merge(Task task)
		{
			var removeFromIndexTask = ((RemoveFromIndexTask)task);
			Keys.UnionWith(removeFromIndexTask.Keys);
		}
Beispiel #14
0
 public override bool TryMerge(Task task)
 {
     var removeFromIndexTask = ((RemoveFromIndexTask)task);
     Keys = Keys.Union(removeFromIndexTask.Keys).ToArray();
     return true;
 }
Beispiel #15
0
		public abstract bool TryMerge(Task task);
        public void AddTask(Task task)
        {
            using (var update = new Update(session, Tasks, JET_prep.Insert))
            {
                Api.SetColumn(session, Tasks, tasksColumns["task"], task.AsString(), Encoding.Unicode);
                Api.SetColumn(session, Tasks, tasksColumns["for_index"], task.Index, Encoding.Unicode);

                update.Save();
            }
            if (logger.IsDebugEnabled)
                logger.DebugFormat("New task '{0}'", task.AsString());
        }
 public override void Merge(Task task)
 {
     var t = (TouchMissingReferenceDocumentTask)task;
     Keys.UnionWith(t.Keys);
 }
Beispiel #18
0
		public void MergeSimilarTasks(Task task, out int taskCount)
		{
			taskCount = 1;
			if (task.SupportsMerging == false)
				return;

			Api.JetSetCurrentIndex(session, Tasks, "mergables_by_task_type");
			Api.MakeKey(session, Tasks, true, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, Tasks, task.Index, Encoding.Unicode, MakeKeyGrbit.None);
			Api.MakeKey(session, Tasks, task.Type, Encoding.Unicode, MakeKeyGrbit.None);
			// there are no tasks matching the current one, just return
			if (Api.TrySeek(session, Tasks, SeekGrbit.SeekEQ) == false)
			{
				return;
			}

			Api.MakeKey(session, Tasks, true, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, Tasks, task.Index, Encoding.Unicode, MakeKeyGrbit.None);
			Api.MakeKey(session, Tasks, task.Type, Encoding.Unicode, MakeKeyGrbit.None);
			Api.JetSetIndexRange(session, Tasks, SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit);
			do
			{
				// esent index ranges are approximate, and we need to check them ourselves as well
				if (Api.RetrieveColumnAsBoolean(session, Tasks, tableColumnsCache.TasksColumns["supports_merging"]) == false)
					continue;
				if (Api.RetrieveColumnAsString(session, Tasks, tableColumnsCache.TasksColumns["for_index"]) != task.Index)
					continue;
				if (Api.RetrieveColumnAsString(session, Tasks, tableColumnsCache.TasksColumns["task_type"]) != task.Type)
					continue;

				try
				{
					var taskAsBytes = Api.RetrieveColumn(session, Tasks, tableColumnsCache.TasksColumns["task"]);
					var taskType = Api.RetrieveColumnAsString(session, Tasks, tableColumnsCache.TasksColumns["task_type"], Encoding.Unicode);
					Task existingTask;
					try
					{
						existingTask = Task.ToTask(taskType, taskAsBytes);
					}
					catch (Exception e)
					{
						logger.ErrorFormat(e, "Could not create instance of a task: {0}", taskAsBytes);
						Api.JetDelete(session, Tasks);
						continue;
					}
					if (task.TryMerge(existingTask) == false)
						continue;
					Api.JetDelete(session, Tasks);
					taskCount += 1;
				}
				catch (EsentErrorException e)
				{
					if (e.Error == JET_err.WriteConflict)
						continue;
					throw;
				}
			} while (
					task.SupportsMerging &&
					Api.TryMoveNext(session, Tasks)
				);
		}
Beispiel #19
0
 public override bool TryMerge(Task task)
 {
     var reduceTask = ((ReduceTask)task);
     // if the reduce key is the same, either task will have the same effect
     return reduceTask.ReduceKey == ReduceKey;
 }
Beispiel #20
0
 public override bool TryMerge(Task task)
 {
     var reduceTask = ((ReduceTask)task);
     ReduceKeys = ReduceKeys.Concat(reduceTask.ReduceKeys).Distinct().ToArray();
     return true;
 }
		public override bool TryMerge(Task task)
		{
			// we don't merge index ranges, since they are already paritioned on index creation
			return false;
		}