예제 #1
0
        public override void AddTask(IDatabaseTask task)
        {
            ClassicVersionTask script = new ClassicVersionTask(this, task.FileName);

            script.ExecutionOrder = task.ExecutionOrder;
            this.Tasks.Add(script);
        }
예제 #2
0
 public TaskSuggestion(IDatabaseTask task)
 {
     TaskId       = task.Id;
     Name         = task.Name;
     ProjectId    = task.ProjectId;
     ProjectName  = task.Project?.Name ?? "";
     ProjectColor = task.Project?.Color ?? "";
 }
예제 #3
0
        public string WhoseTaskIsIt(
            RachisState state,
            IDatabaseTask task,
            Func <string> getLastResponsibleNode)
        {
            if (state == RachisState.Candidate || state == RachisState.Passive)
            {
                return(null);
            }

            var mentorNode = task.GetMentorNode();

            if (mentorNode != null)
            {
                if (Members.Contains(mentorNode))
                {
                    return(mentorNode);
                }
            }

            var lastResponsibleNode = getLastResponsibleNode?.Invoke();

            if (lastResponsibleNode != null)
            {
                return(lastResponsibleNode);
            }

            var topology = new List <string>(Members);

            topology.AddRange(Promotables);
            topology.AddRange(Rehabs);
            topology.Sort();

            if (topology.Count == 0)
            {
                return(null); // this is probably being deleted now, no one is able to run tasks
            }
            var key = task.GetTaskKey();

            while (true)
            {
                var index = (int)Hashing.JumpConsistentHash.Calculate(key, topology.Count);
                var entry = topology[index];
                if (Members.Contains(entry))
                {
                    return(entry);
                }

                topology.RemoveAt(index);
                if (topology.Count == 0)
                {
                    return(null); // all nodes in the topology are probably in rehab
                }
                // rehash so it will likely go to a different member in the cluster
                key = Hashing.Mix(key);
            }
        }
예제 #4
0
 private Task(IDatabaseTask entity)
     : this(entity as ITask, entity.SyncStatus, entity.LastSyncErrorMessage, entity.IsDeleted)
 {
     User                 = entity.User == null ? null : Models.User.From(entity.User);
     Project              = entity.Project == null ? null : Models.Project.From(entity.Project);
     Workspace            = entity.Workspace == null ? null : Models.Workspace.From(entity.Workspace);
     SyncStatus           = entity.SyncStatus;
     LastSyncErrorMessage = entity.LastSyncErrorMessage;
     IsDeleted            = entity.IsDeleted;
 }
예제 #5
0
        public void ExecuteTasks(ISession session)
        {
            int count = this.tasks.Count;

            for (int i = 1; i < count + 1; i++)
            {
                IDatabaseTask task = this.tasks.Dequeue();
                task.Execute(session, i, count);
            }
        }
예제 #6
0
        public void ShouldSetExecutionOrderOfTask()
        {
            // Arrange
            XElement element = new XElement(
                XName.Get("script"),
                new XAttribute(XName.Get("file"), "path/file.sql"));

            // Act
            IDatabaseTask task = this.factory.Create(element, 25, null);

            // Assert
            Assert.Equal(25, task.ExecutionOrder);
        }
예제 #7
0
        public void ShouldSetFileNameOfScript()
        {
            // Arrange
            XElement element = new XElement(
                XName.Get("script"),
                new XAttribute(XName.Get("file"), "path/file.sql"));

            // Act
            IDatabaseTask task = this.factory.Create(element, 0, null);

            // Assert
            Assert.Equal("path/file.sql", ((ScriptTask)task).FileName);
        }
예제 #8
0
        public void ShouldCreateScriptTask()
        {
            // Arrange
            XElement element = new XElement(
                XName.Get("script"),
                new XAttribute(XName.Get("file"), "path/file.sql"));

            // Act
            IDatabaseTask task = this.factory.Create(element, 0, null);

            // Assert
            Assert.IsType <ScriptTask>(task);
        }
예제 #9
0
        public string WhoseTaskIsIt(
            RachisState state,
            IDatabaseTask task,
            Func <string> getLastResponsibleNode)
        {
            if (state == RachisState.Candidate || state == RachisState.Passive)
            {
                return(null);
            }

            var mentorNode = task.GetMentorNode();

            if (mentorNode != null)
            {
                if (Members.Contains(mentorNode))
                {
                    return(mentorNode);
                }
            }

            var lastResponsibleNode = getLastResponsibleNode?.Invoke();

            if (lastResponsibleNode != null)
            {
                return(lastResponsibleNode);
            }

            var topology = new List <string>(Members);

            topology.AddRange(Promotables);
            topology.AddRange(Rehabs);
            topology.Sort();

            if (task.IsResourceIntensive() && Members.Count > 1)
            {
                // if resource intensive operation, we don't want to have it on the first node of the database topology
                return(FindNodeForIntensiveOperation(task.GetTaskKey(), topology));
            }

            return(FindNode(task.GetTaskKey(), topology));
        }
예제 #10
0
        public string WhoseTaskIsIt(
            DatabaseTopology databaseTopology,
            IDatabaseTask configuration,
            IDatabaseTaskStatus taskStatus,
            bool useLastResponsibleNodeIfNoAvailableNodes = false)
        {
            var whoseTaskIsIt = databaseTopology.WhoseTaskIsIt(
                ServerStore.Engine.CurrentState, configuration,
                getLastReponsibleNode:
                () => ServerStore.LicenseManager.GetLastResponsibleNodeForTask(
                    taskStatus,
                    databaseTopology,
                    configuration,
                    NotificationCenter));

            if (whoseTaskIsIt == null && useLastResponsibleNodeIfNoAvailableNodes)
            {
                return(taskStatus.NodeTag);
            }

            return(whoseTaskIsIt);
        }
예제 #11
0
        public string WhoseTaskIsIt(IDatabaseTask task, bool inPassiveState)
        {
            if (inPassiveState)
            {
                return(null);
            }

            var topology = new List <string>(Members);

            topology.AddRange(Promotables);
            topology.AddRange(Rehabs);
            topology.Sort();

            if (topology.Count == 0)
            {
                return(null); // this is probably being deleted now, no one is able to run tasks
            }
            var key = task.GetTaskKey();

            while (true)
            {
                var index = (int)Hashing.JumpConsistentHash.Calculate(key, topology.Count);
                var entry = topology[index];
                if (Members.Contains(entry))
                {
                    return(entry);
                }

                topology.RemoveAt(index);
                if (topology.Count == 0)
                {
                    return(null); // all nodes in the topology are probably in rehab
                }
                // rehash so it will likely go to a different member in the cluster
                key = Hashing.Mix(key);
            }
        }
예제 #12
0
 public RealmTask(IDatabaseTask entity, Realms.Realm realm)
     : this(entity as ITask, realm)
 {
     IsDirty = entity.IsDirty;
 }
예제 #13
0
 public static Task From(IDatabaseTask entity)
 => new Task(entity);
        public bool HasExecutedScript(VersionBase currentVersion, VersionBase targetVersion, IDatabaseTask task)
        {
            if (currentVersion != null)
            {
                NumericVersion currentNumericVersion = currentVersion as NumericVersion;
                NumericVersion targetNumericVersion  = targetVersion as NumericVersion;
                if (currentNumericVersion.Version.Equals(targetNumericVersion.Version))
                {
                    return(currentNumericVersion.HasExecutedTask(task));
                }
            }

            return(false);
        }
        /// <summary>
        /// Returns whether a script belongs to the current version and if so whether it has already been executed
        /// </summary>
        /// <param name="currentVersion"></param>
        /// <param name="targetVersion"></param>
        /// <param name="task"></param>
        /// <returns></returns>
        public bool HasExecutedScript(VersionBase currentVersion, VersionBase targetVersion, IDatabaseTask task)
        {
            if (currentVersion != null)
            {
                ClassicVersion currentClassicVersion = currentVersion as ClassicVersion;
                ClassicVersion targetClassicVersion  = targetVersion as ClassicVersion;
                if (currentClassicVersion.SystemVersion.Equals(targetClassicVersion.SystemVersion))
                {
                    return(currentClassicVersion.HasExecutedTask(task));
                }
            }

            return(false);
        }
예제 #16
0
 public abstract bool HasExecutedTask(IDatabaseTask task);
예제 #17
0
 public abstract void AddTask(IDatabaseTask task);
예제 #18
0
 public override bool HasExecutedTask(IDatabaseTask task)
 {
     return(this.Tasks.Contains(new ClassicVersionTask(this, task.FileName)));
 }
예제 #19
0
 public void AddTask(IDatabaseTask task)
 {
     this.tasks.Enqueue(task);
 }