public static NodeConfiguration TranslateNodeInfo(ExtendedNodeInfo nodeInfo)
 {
     return new NodeConfiguration
     {
         PublicAddress = nodeInfo.PublicAddress,
         InternalAddress = nodeInfo.InternalAddress,
         ServerId = nodeInfo.ServerId,
         IsMaster = nodeInfo.IsMaster,
         IsSelf = false
     };
 }
        public void IntroduceNewNode(ExtendedNodeInfo nodeInfo)
        {
            if (nodeInfo.IsMaster)
                throw new InvalidOperationException("New node cannot be introduced as Master");

            Core.Server.Log.Debug("Introducing new node into system... id={0}",nodeInfo.ServerId);

            var newNode = ProxyHelper.TranslateNodeInfo(nodeInfo);
            Core.Server.Configuration.Nodes.AddNewNode(newNode);

            ProxyHelper.EnsureNodesConfigurationIsValid();

            newNode.CreateProxy();
            newNode.Proxy.Open();

            Core.Server.Log.Info("New node introduced in system. Id = {0}, internal address = {1}",
                nodeInfo.ServerId, nodeInfo.InternalAddress);
        }
Exemple #3
0
        private static bool ProcessGroupByOpWithNoAggregates(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node n,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            Command          command          = context.Command;
            GroupByOp        op               = (GroupByOp)n.Op;
            ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(n.Child0);
            ProjectOp        projectOp        = command.CreateProjectOp(op.Keys);
            VarDefListOp     varDefListOp     = command.CreateVarDefListOp();

            command.CreateNode((Op)varDefListOp);
            newNode = command.CreateNode((Op)projectOp, n.Child0, n.Child1);
            if (extendedNodeInfo.Keys.NoKeys || !op.Keys.Subsumes(extendedNodeInfo.Keys.KeyVars))
            {
                newNode = command.CreateNode((Op)command.CreateDistinctOp(command.CreateVarVec(op.Keys)), newNode);
            }
            return(true);
        }
Exemple #4
0
        private static bool ProcessDistinctOpOfKeys(
            RuleProcessingContext context,
            Node n,
            out Node newNode)
        {
            Command          command          = context.Command;
            ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(n.Child0);
            DistinctOp       op = (DistinctOp)n.Op;

            if (!extendedNodeInfo.Keys.NoKeys && op.Keys.Subsumes(extendedNodeInfo.Keys.KeyVars))
            {
                ProjectOp    projectOp    = command.CreateProjectOp(op.Keys);
                VarDefListOp varDefListOp = command.CreateVarDefListOp();
                Node         node         = command.CreateNode((Op)varDefListOp);
                newNode = command.CreateNode((Op)projectOp, n.Child0, node);
                return(true);
            }
            newNode = n;
            return(false);
        }
        private static bool ProcessCrossApplyOverProject(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node applyNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = applyNode;
            System.Data.Entity.Core.Query.InternalTrees.Node child1 = applyNode.Child1;
            ProjectOp        op               = (ProjectOp)child1.Op;
            Command          command          = context.Command;
            ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(applyNode);
            VarVec           varVec           = command.CreateVarVec(op.Outputs);

            varVec.Or(extendedNodeInfo.Definitions);
            op.Outputs.InitFrom(varVec);
            applyNode.Child1 = child1.Child0;
            context.Command.RecomputeNodeInfo(applyNode);
            child1.Child0 = applyNode;
            newNode       = child1;
            return(true);
        }
        private static bool ProcessApplyOverAnything(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node applyNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = applyNode;
            System.Data.Entity.Core.Query.InternalTrees.Node child0 = applyNode.Child0;
            System.Data.Entity.Core.Query.InternalTrees.Node child1 = applyNode.Child1;
            ApplyBaseOp      applyBaseOp       = (ApplyBaseOp)applyNode.Op;
            Command          command           = context.Command;
            ExtendedNodeInfo extendedNodeInfo1 = command.GetExtendedNodeInfo(child1);
            ExtendedNodeInfo extendedNodeInfo2 = command.GetExtendedNodeInfo(child0);
            bool             flag = false;

            if (applyBaseOp.OpType == OpType.OuterApply && extendedNodeInfo1.MinRows >= RowCount.One)
            {
                applyBaseOp = (ApplyBaseOp)command.CreateCrossApplyOp();
                flag        = true;
            }
            if (extendedNodeInfo1.ExternalReferences.Overlaps(extendedNodeInfo2.Definitions))
            {
                if (!flag)
                {
                    return(false);
                }
                newNode = command.CreateNode((Op)applyBaseOp, child0, child1);
                return(true);
            }
            if (applyBaseOp.OpType == OpType.CrossApply)
            {
                newNode = command.CreateNode((Op)command.CreateCrossJoinOp(), child0, child1);
            }
            else
            {
                LeftOuterJoinOp     leftOuterJoinOp = command.CreateLeftOuterJoinOp();
                ConstantPredicateOp trueOp          = command.CreateTrueOp();
                System.Data.Entity.Core.Query.InternalTrees.Node node = command.CreateNode((Op)trueOp);
                newNode = command.CreateNode((Op)leftOuterJoinOp, child0, child1, node);
            }
            return(true);
        }
Exemple #7
0
 internal bool IsNonNullable(Var variable)
 {
     if (variable.VarType == VarType.Parameter && !TypeSemantics.IsNullable(variable.Type))
     {
         return(true);
     }
     foreach (System.Data.Entity.Core.Query.InternalTrees.Node relOpAncestor in this.m_relOpAncestors)
     {
         this.Command.RecomputeNodeInfo(relOpAncestor);
         ExtendedNodeInfo extendedNodeInfo = this.Command.GetExtendedNodeInfo(relOpAncestor);
         if (extendedNodeInfo.NonNullableVisibleDefinitions.IsSet(variable))
         {
             return(true);
         }
         if (extendedNodeInfo.LocalDefinitions.IsSet(variable))
         {
             return(false);
         }
     }
     return(false);
 }
Exemple #8
0
        private static bool ProcessSingleRowOpOverAnything(
            RuleProcessingContext context,
            Node singleRowNode,
            out Node newNode)
        {
            newNode = singleRowNode;
            ExtendedNodeInfo extendedNodeInfo = context.Command.GetExtendedNodeInfo(singleRowNode.Child0);

            if (extendedNodeInfo.MaxRows <= RowCount.One)
            {
                newNode = singleRowNode.Child0;
                return(true);
            }
            if (singleRowNode.Child0.Op.OpType != OpType.Filter || !new Predicate(context.Command, singleRowNode.Child0.Child1).SatisfiesKey(extendedNodeInfo.Keys.KeyVars, extendedNodeInfo.Definitions))
            {
                return(false);
            }
            extendedNodeInfo.MaxRows = RowCount.One;
            newNode = singleRowNode.Child0;
            return(true);
        }
Exemple #9
0
        private static bool ProcessProjectOpWithNullSentinel(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node n,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = n;
            ProjectOp op = (ProjectOp)n.Op;

            if (n.Child1.Children.Where <System.Data.Entity.Core.Query.InternalTrees.Node>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, bool>)(c => c.Child0.Op.OpType == OpType.NullSentinel)).Count <System.Data.Entity.Core.Query.InternalTrees.Node>() == 0)
            {
                return(false);
            }
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;
            Command          command           = transformationRulesContext.Command;
            ExtendedNodeInfo extendedNodeInfo  = command.GetExtendedNodeInfo(n.Child0);
            bool             flag1             = false;
            bool             nullSentinelValue = transformationRulesContext.CanChangeNullSentinelValue;
            Var int32Var;

            if (!nullSentinelValue || !TransformationRulesContext.TryGetInt32Var((IEnumerable <Var>)extendedNodeInfo.NonNullableDefinitions, out int32Var))
            {
                flag1 = true;
                if (!nullSentinelValue || !TransformationRulesContext.TryGetInt32Var(n.Child1.Children.Where <System.Data.Entity.Core.Query.InternalTrees.Node>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, bool>)(child =>
                {
                    if (child.Child0.Op.OpType != OpType.Constant)
                    {
                        return(child.Child0.Op.OpType == OpType.InternalConstant);
                    }
                    return(true);
                })).Select <System.Data.Entity.Core.Query.InternalTrees.Node, Var>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, Var>)(child => ((VarDefOp)child.Op).Var)), out int32Var))
                {
                    int32Var = n.Child1.Children.Where <System.Data.Entity.Core.Query.InternalTrees.Node>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, bool>)(child => child.Child0.Op.OpType == OpType.NullSentinel)).Select <System.Data.Entity.Core.Query.InternalTrees.Node, Var>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, Var>)(child => ((VarDefOp)child.Op).Var)).FirstOrDefault <Var>();
                    if (int32Var == null)
                    {
                        return(false);
                    }
                }
            }
            bool flag2 = false;

            for (int index = n.Child1.Children.Count - 1; index >= 0; --index)
            {
                System.Data.Entity.Core.Query.InternalTrees.Node child = n.Child1.Children[index];
                if (child.Child0.Op.OpType == OpType.NullSentinel)
                {
                    if (!flag1)
                    {
                        VarRefOp varRefOp = command.CreateVarRefOp(int32Var);
                        child.Child0 = command.CreateNode((Op)varRefOp);
                        command.RecomputeNodeInfo(child);
                        flag2 = true;
                    }
                    else if (!int32Var.Equals((object)((VarDefOp)child.Op).Var))
                    {
                        op.Outputs.Clear(((VarDefOp)child.Op).Var);
                        n.Child1.Children.RemoveAt(index);
                        transformationRulesContext.AddVarMapping(((VarDefOp)child.Op).Var, int32Var);
                        flag2 = true;
                    }
                }
            }
            if (flag2)
            {
                command.RecomputeNodeInfo(n.Child1);
            }
            return(flag2);
        }
Exemple #10
0
        /// <summary>
        /// Comments from Murali:
        ///
        ///   There are several cases to consider here.
        ///
        ///   Case 0:
        ///     Let’s assume that K1 is the set of keys ({k1, k2, ..., kn}) for the
        ///     first input, and K2 ({l1, l2, …}) is the set of keys for the second
        ///     input.
        ///
        ///     The best case is when both K1 and K2 have the same cardinality (hopefully
        ///     greater than 0), and the keys are in the same locations (ie) the corresponding
        ///     positions in the select-list.  Even in this case, its not enough to take
        ///     the keys, and treat them as the keys of the union-all. What we’ll need to
        ///     do is to add a “branch” discriminator constant for each branch of the
        ///     union-all, and use this as the prefix for the keys.
        ///
        ///     For example, if I had:
        ///
        ///         Select c1, c2, c3... from ...
        ///         Union all
        ///         Select d1, d2, d3... from ...
        ///
        ///     And for the sake of argument, lets say that {c2} and {d2} are the keys of
        ///     each of the branches. What you’ll need to do is to translate this into
        ///
        ///         Select 0 as bd, c1, c2, c3... from ...
        ///         Union all
        ///         Select 1 as bd, d1, d2, d3... from ...
        ///
        ///     And then treat {bd, c2/d2} as the key of the union-all
        ///
        ///   Case 1:  (actually, a subcase of Case 0):
        ///     Now, if the keys don’t align, then we can simply take the union of the
        ///     corresponding positions, and make them all the keys (we would still need
        ///     the branch discriminator)
        ///
        ///   Case 2:
        ///     Finally, if you need to “pull” up keys from either of the branches, it is
        ///     possible that the branches get out of whack.  We will then need to push up
        ///     the keys (with nulls if the other branch doesn’t have the corresponding key)
        ///     into the union-all. (We still need the branch discriminator).
        ///
        /// Now, unfortunately, whenever we've got polymorphic entity types, we'll end up
        /// in case 2 way more often than we really want to, because when we're pulling up
        /// keys, we don't want to reason about a caseop (which is how polymorphic types
        /// wrap their key value).
        ///
        /// To simplify all of this, we:
        ///
        /// (1) Pulling up the keys for both branches of the UnionAll, and computing which
        ///     keys are in the outputs and which are missing from the outputs.
        ///
        /// (2) Accumulate all the missing keys.
        ///
        /// (3) Slap a projectOp around each branch, adding a branch discriminator
        ///     var and all the missing keys.  When keys are missing from a different
        ///     branch, we'll construct null ops for them on the other branches.  If
        ///     a branch already has a branch descriminator, we'll re-use it instead
        ///     of constructing a new one.  (Of course, if there aren't any keys to
        ///     add and it's already including the branch discriminator we won't
        ///     need the projectOp)
        ///
        /// </summary>
        /// <param name="op">the UnionAllOp</param>
        /// <param name="n">current subtree</param>
        public override void Visit(UnionAllOp op, Node n)
        {
#if DEBUG
            string input = Dump.ToXml(m_command, n);
#endif //DEBUG

            // Ensure we have keys pulled up on each branch of the union all.
            VisitChildren(n);

            // Create the setOp var we'll use to output the branch discriminator value; if
            // any of the branches are already surfacing a branchDiscriminator var to the
            // output of this operation then we won't need to use this but we construct it
            // early to simplify logic.
            Var outputBranchDiscriminatorVar = m_command.CreateSetOpVar(m_command.IntegerType);

            // Now ensure that we're outputting the key vars from this op as well.
            VarList  allKeyVarsMissingFromOutput = Command.CreateVarList();
            VarVec[] keyVarsMissingFromOutput    = new VarVec[n.Children.Count];

            for (int i = 0; i < n.Children.Count; i++)
            {
                Node             branchNode     = n.Children[i];
                ExtendedNodeInfo branchNodeInfo = m_command.GetExtendedNodeInfo(branchNode);

                // Identify keys that aren't in the output list of this operation. We
                // determine these by remapping the keys that are found through the node's
                // VarMap, which gives us the keys in the same "varspace" as the outputs
                // of the UnionAll, then we subtract out the outputs of this UnionAll op,
                // leaving things that are not in the output vars.  Of course, if they're
                // not in the output vars, then we didn't really remap.
                VarVec existingKeyVars = branchNodeInfo.Keys.KeyVars.Remap(op.VarMap[i]);

                keyVarsMissingFromOutput[i] = m_command.CreateVarVec(existingKeyVars);
                keyVarsMissingFromOutput[i].Minus(op.Outputs);

                // Special Case: if the branch is a UnionAll, it will already have it's
                // branch discriminator var added in the keys; we don't want to add that
                // a second time...
                if (OpType.UnionAll == branchNode.Op.OpType)
                {
                    UnionAllOp branchUnionAllOp = (UnionAllOp)branchNode.Op;

                    keyVarsMissingFromOutput[i].Clear(branchUnionAllOp.BranchDiscriminator);
                }

                allKeyVarsMissingFromOutput.AddRange(keyVarsMissingFromOutput[i]);
            }

            // Construct the setOp vars we're going to map to output.
            VarList allKeyVarsToAddToOutput = Command.CreateVarList();

            foreach (Var v in allKeyVarsMissingFromOutput)
            {
                Var newKeyVar = m_command.CreateSetOpVar(v.Type);
                allKeyVarsToAddToOutput.Add(newKeyVar);
            }

            // Now that we've identified all the keys we need to add, ensure that each branch
            // has both the branch discrimination var and the all the keys in them, even when
            // the keys are just going to null (which we construct, as needed)
            for (int i = 0; i < n.Children.Count; i++)
            {
                Node             branchNode     = n.Children[i];
                ExtendedNodeInfo branchNodeInfo = m_command.GetExtendedNodeInfo(branchNode);

                VarVec      branchOutputVars = m_command.CreateVarVec();
                List <Node> varDefNodes      = new List <Node>();

                // If the branch is a UnionAllOp that has a branch discriminator var then we can
                // use it, otherwise we'll construct a new integer constant with the next value
                // of the branch discriminator value from the command object.
                Var branchDiscriminatorVar;

                if (OpType.UnionAll == branchNode.Op.OpType && null != ((UnionAllOp)branchNode.Op).BranchDiscriminator)
                {
                    branchDiscriminatorVar = ((UnionAllOp)branchNode.Op).BranchDiscriminator;

                    // If the branch has a discriminator var, but we haven't added it to the
                    // varmap yet, then we do so now.
                    if (!op.VarMap[i].ContainsValue(branchDiscriminatorVar))
                    {
                        op.VarMap[i].Add(outputBranchDiscriminatorVar, branchDiscriminatorVar);
                        // We don't need to add this to the branch outputs, because it's already there,
                        // otherwise we wouln't have gotten here, yes?
                    }
                    else
                    {
                        // In this case, we're already outputting the branch discriminator var -- we'll
                        // just use it for both sides.  We should never have a case where only one of the
                        // two branches are outputting the branch discriminator var, because it can only
                        // be constructed in this method, and we wouldn't need it for any other purpose.
                        PlanCompiler.Assert(0 == i, "right branch has a discriminator var that the left branch doesn't have?");
                        VarMap reverseVarMap = op.VarMap[i].GetReverseMap();
                        outputBranchDiscriminatorVar = reverseVarMap[branchDiscriminatorVar];
                    }
                }
                else
                {
                    // Not a unionAll -- we have to add a BranchDiscriminator var.
                    varDefNodes.Add(
                        m_command.CreateVarDefNode(
                            m_command.CreateNode(
                                m_command.CreateConstantOp(m_command.IntegerType, m_command.NextBranchDiscriminatorValue)), out branchDiscriminatorVar));

                    branchOutputVars.Set(branchDiscriminatorVar);
                    op.VarMap[i].Add(outputBranchDiscriminatorVar, branchDiscriminatorVar);
                }

                // Append all the missing keys to the branch outputs.  If the missing key
                // is not from this branch then create a null.
                for (int j = 0; j < allKeyVarsMissingFromOutput.Count; j++)
                {
                    Var keyVar = allKeyVarsMissingFromOutput[j];

                    if (!keyVarsMissingFromOutput[i].IsSet(keyVar))
                    {
                        varDefNodes.Add(
                            m_command.CreateVarDefNode(
                                m_command.CreateNode(
                                    m_command.CreateNullOp(keyVar.Type)), out keyVar));

                        branchOutputVars.Set(keyVar);
                    }

                    // In all cases, we're adding a key to the output so we need to update the
                    // varmap.
                    op.VarMap[i].Add(allKeyVarsToAddToOutput[j], keyVar);
                }

                // If we got this far and didn't add anything to the branch, then we're done.
                // Otherwise we'll have to construct the new projectOp around the input branch
                // to add the stuff we've added.
                if (branchOutputVars.IsEmpty)
                {
                    // Actually, we're not quite done -- we need to update the key vars for the
                    // branch to include the branch discriminator var we
                    branchNodeInfo.Keys.KeyVars.Set(branchDiscriminatorVar);
                }
                else
                {
                    PlanCompiler.Assert(varDefNodes.Count != 0, "no new nodes?");

                    // Start by ensuring all the existing outputs from the branch are in the list.
                    foreach (Var v in op.VarMap[i].Values)
                    {
                        branchOutputVars.Set(v);
                    }

                    // Now construct a project op to project out everything we've added, and
                    // replace the branchNode with it in the flattened ladder.
                    n.Children[i] = m_command.CreateNode(m_command.CreateProjectOp(branchOutputVars),
                                                         branchNode,
                                                         m_command.CreateNode(m_command.CreateVarDefListOp(), varDefNodes));

                    // Finally, ensure that we update the Key info for the projectOp to include
                    // the original branch's keys, along with the branch discriminator var.
                    m_command.RecomputeNodeInfo(n.Children[i]);
                    ExtendedNodeInfo projectNodeInfo = m_command.GetExtendedNodeInfo(n.Children[i]);
                    projectNodeInfo.Keys.KeyVars.InitFrom(branchNodeInfo.Keys.KeyVars);
                    projectNodeInfo.Keys.KeyVars.Set(branchDiscriminatorVar);
                }
            }

            // All done with the branches, now it's time to update the UnionAll op to indicate
            // that we've got a branch discriminator var.
            n.Op = m_command.CreateUnionAllOp(op.VarMap[0], op.VarMap[1], outputBranchDiscriminatorVar);

            // Finally, the thing we've all been waiting for -- computing the keys.  We cheat here and let
            // nodeInfo do it so we don't have to duplicate the logic...
            m_command.RecomputeNodeInfo(n);

#if DEBUG
            input = input.Trim();
            string output = Dump.ToXml(m_command, n);
#endif //DEBUG
        }
        private static bool ProcessOuterApplyOverDummyProjectOverFilter(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node applyNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = applyNode;
            System.Data.Entity.Core.Query.InternalTrees.Node child1 = applyNode.Child1;
            ProjectOp op = (ProjectOp)child1.Op;

            System.Data.Entity.Core.Query.InternalTrees.Node child0_1 = child1.Child0;
            System.Data.Entity.Core.Query.InternalTrees.Node child0_2 = child0_1.Child0;
            Command          command           = context.Command;
            ExtendedNodeInfo extendedNodeInfo1 = command.GetExtendedNodeInfo(child0_2);
            ExtendedNodeInfo extendedNodeInfo2 = command.GetExtendedNodeInfo(applyNode.Child0);

            if (op.Outputs.Overlaps(extendedNodeInfo2.Definitions) || extendedNodeInfo1.ExternalReferences.Overlaps(extendedNodeInfo2.Definitions))
            {
                return(false);
            }
            bool flag1 = false;
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;
            Var  int32Var;
            bool flag2;

            if (TransformationRulesContext.TryGetInt32Var((IEnumerable <Var>)extendedNodeInfo1.NonNullableDefinitions, out int32Var))
            {
                flag2 = true;
            }
            else
            {
                int32Var = extendedNodeInfo1.NonNullableDefinitions.First;
                flag2    = false;
            }
            System.Data.Entity.Core.Query.InternalTrees.Node node1;
            if (int32Var != null)
            {
                flag1 = true;
                System.Data.Entity.Core.Query.InternalTrees.Node child0_3 = child1.Child1.Child0;
                child0_3.Child0 = child0_3.Child0.Op.OpType != OpType.NullSentinel || !flag2 || !transformationRulesContext.CanChangeNullSentinelValue ? transformationRulesContext.BuildNullIfExpression(int32Var, child0_3.Child0) : context.Command.CreateNode((Op)context.Command.CreateVarRefOp(int32Var));
                command.RecomputeNodeInfo(child0_3);
                command.RecomputeNodeInfo(child1.Child1);
                node1 = child0_2;
            }
            else
            {
                node1 = child1;
                foreach (Var externalReference in command.GetNodeInfo(child0_1.Child1).ExternalReferences)
                {
                    if (extendedNodeInfo1.Definitions.IsSet(externalReference))
                    {
                        op.Outputs.Set(externalReference);
                    }
                }
                child1.Child0 = child0_2;
            }
            context.Command.RecomputeNodeInfo(child1);
            System.Data.Entity.Core.Query.InternalTrees.Node node2 = command.CreateNode((Op)command.CreateLeftOuterJoinOp(), applyNode.Child0, node1, child0_1.Child1);
            if (flag1)
            {
                ExtendedNodeInfo extendedNodeInfo3 = command.GetExtendedNodeInfo(node2);
                child1.Child0 = node2;
                op.Outputs.Or(extendedNodeInfo3.Definitions);
                newNode = child1;
            }
            else
            {
                newNode = node2;
            }
            return(true);
        }
        public void RequestSynchronization(ExtendedNodeInfo nodeInfo, Dictionary<string, int> aggregateVersions)
        {
            Core.Server.Log.Info("Request for synchronization arrived from {0}", nodeInfo.InternalAddress);

            var sync = Core.Server.Resolve<INodeSynchronizer>();
            sync.StartBackgroundSync(nodeInfo, aggregateVersions);
        }
Exemple #13
0
        private static bool ProcessJoinOverProject(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node joinNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = joinNode;
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;
            Command command = transformationRulesContext.Command;

            System.Data.Entity.Core.Query.InternalTrees.Node node1 = joinNode.HasChild2 ? joinNode.Child2 : (System.Data.Entity.Core.Query.InternalTrees.Node)null;
            Dictionary <Var, int> varRefMap = new Dictionary <Var, int>();

            if (node1 != null && !transformationRulesContext.IsScalarOpTree(node1, varRefMap))
            {
                return(false);
            }
            VarVec varVec1 = command.CreateVarVec();
            List <System.Data.Entity.Core.Query.InternalTrees.Node> args = new List <System.Data.Entity.Core.Query.InternalTrees.Node>();

            if (joinNode.Op.OpType != OpType.LeftOuterJoin && joinNode.Child0.Op.OpType == OpType.Project && joinNode.Child1.Op.OpType == OpType.Project)
            {
                ProjectOp op1 = (ProjectOp)joinNode.Child0.Op;
                ProjectOp op2 = (ProjectOp)joinNode.Child1.Op;
                Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap1 = transformationRulesContext.GetVarMap(joinNode.Child0.Child1, varRefMap);
                Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap2 = transformationRulesContext.GetVarMap(joinNode.Child1.Child1, varRefMap);
                if (varMap1 == null || varMap2 == null)
                {
                    return(false);
                }
                System.Data.Entity.Core.Query.InternalTrees.Node node2;
                if (node1 != null)
                {
                    System.Data.Entity.Core.Query.InternalTrees.Node node3 = transformationRulesContext.ReMap(node1, varMap1);
                    System.Data.Entity.Core.Query.InternalTrees.Node node4 = transformationRulesContext.ReMap(node3, varMap2);
                    node2 = context.Command.CreateNode(joinNode.Op, joinNode.Child0.Child0, joinNode.Child1.Child0, node4);
                }
                else
                {
                    node2 = context.Command.CreateNode(joinNode.Op, joinNode.Child0.Child0, joinNode.Child1.Child0);
                }
                varVec1.InitFrom(op1.Outputs);
                foreach (Var output in op2.Outputs)
                {
                    varVec1.Set(output);
                }
                ProjectOp projectOp = command.CreateProjectOp(varVec1);
                args.AddRange((IEnumerable <System.Data.Entity.Core.Query.InternalTrees.Node>)joinNode.Child0.Child1.Children);
                args.AddRange((IEnumerable <System.Data.Entity.Core.Query.InternalTrees.Node>)joinNode.Child1.Child1.Children);
                System.Data.Entity.Core.Query.InternalTrees.Node node5 = command.CreateNode((Op)command.CreateVarDefListOp(), args);
                System.Data.Entity.Core.Query.InternalTrees.Node node6 = command.CreateNode((Op)projectOp, node2, node5);
                newNode = node6;
                return(true);
            }
            int index1;
            int index2;

            if (joinNode.Child0.Op.OpType == OpType.Project)
            {
                index1 = 0;
                index2 = 1;
            }
            else
            {
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(joinNode.Op.OpType != OpType.LeftOuterJoin, "unexpected non-LeftOuterJoin");
                index1 = 1;
                index2 = 0;
            }
            System.Data.Entity.Core.Query.InternalTrees.Node child = joinNode.Children[index1];
            ProjectOp op = child.Op as ProjectOp;
            Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap = transformationRulesContext.GetVarMap(child.Child1, varRefMap);

            if (varMap == null)
            {
                return(false);
            }
            ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(joinNode.Children[index2]);
            VarVec           varVec2          = command.CreateVarVec(op.Outputs);

            varVec2.Or(extendedNodeInfo.Definitions);
            op.Outputs.InitFrom(varVec2);
            if (node1 != null)
            {
                System.Data.Entity.Core.Query.InternalTrees.Node node2 = transformationRulesContext.ReMap(node1, varMap);
                joinNode.Child2 = node2;
            }
            joinNode.Children[index1] = child.Child0;
            context.Command.RecomputeNodeInfo(joinNode);
            newNode = context.Command.CreateNode((Op)op, joinNode, child.Child1);
            return(true);
        }
Exemple #14
0
        public override void Visit(UnionAllOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            this.VisitChildren(n);
            Var     var1     = (Var)this.m_command.CreateSetOpVar(this.m_command.IntegerType);
            VarList varList1 = Command.CreateVarList();

            VarVec[] varVecArray = new VarVec[n.Children.Count];
            for (int index = 0; index < n.Children.Count; ++index)
            {
                System.Data.Entity.Core.Query.InternalTrees.Node child = n.Children[index];
                VarVec v = this.m_command.GetExtendedNodeInfo(child).Keys.KeyVars.Remap((Dictionary <Var, Var>)op.VarMap[index]);
                varVecArray[index] = this.m_command.CreateVarVec(v);
                varVecArray[index].Minus(op.Outputs);
                if (OpType.UnionAll == child.Op.OpType)
                {
                    UnionAllOp op1 = (UnionAllOp)child.Op;
                    varVecArray[index].Clear(op1.BranchDiscriminator);
                }
                varList1.AddRange((IEnumerable <Var>)varVecArray[index]);
            }
            VarList varList2 = Command.CreateVarList();

            foreach (Var var2 in (List <Var>)varList1)
            {
                Var setOpVar = (Var)this.m_command.CreateSetOpVar(var2.Type);
                varList2.Add(setOpVar);
            }
            for (int index1 = 0; index1 < n.Children.Count; ++index1)
            {
                System.Data.Entity.Core.Query.InternalTrees.Node child = n.Children[index1];
                ExtendedNodeInfo extendedNodeInfo1 = this.m_command.GetExtendedNodeInfo(child);
                VarVec           varVec            = this.m_command.CreateVarVec();
                List <System.Data.Entity.Core.Query.InternalTrees.Node> args = new List <System.Data.Entity.Core.Query.InternalTrees.Node>();
                Var computedVar1;
                if (OpType.UnionAll == child.Op.OpType && ((UnionAllOp)child.Op).BranchDiscriminator != null)
                {
                    computedVar1 = ((UnionAllOp)child.Op).BranchDiscriminator;
                    if (!op.VarMap[index1].ContainsValue(computedVar1))
                    {
                        op.VarMap[index1].Add(var1, computedVar1);
                    }
                    else
                    {
                        System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(0 == index1, "right branch has a discriminator var that the left branch doesn't have?");
                        var1 = op.VarMap[index1].GetReverseMap()[computedVar1];
                    }
                }
                else
                {
                    args.Add(this.m_command.CreateVarDefNode(this.m_command.CreateNode((Op)this.m_command.CreateConstantOp(this.m_command.IntegerType, (object)this.m_command.NextBranchDiscriminatorValue)), out computedVar1));
                    varVec.Set(computedVar1);
                    op.VarMap[index1].Add(var1, computedVar1);
                }
                for (int index2 = 0; index2 < varList1.Count; ++index2)
                {
                    Var computedVar2 = varList1[index2];
                    if (!varVecArray[index1].IsSet(computedVar2))
                    {
                        args.Add(this.m_command.CreateVarDefNode(this.m_command.CreateNode((Op)this.m_command.CreateNullOp(computedVar2.Type)), out computedVar2));
                        varVec.Set(computedVar2);
                    }
                    op.VarMap[index1].Add(varList2[index2], computedVar2);
                }
                if (varVec.IsEmpty)
                {
                    extendedNodeInfo1.Keys.KeyVars.Set(computedVar1);
                }
                else
                {
                    System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(args.Count != 0, "no new nodes?");
                    foreach (Var v in op.VarMap[index1].Values)
                    {
                        varVec.Set(v);
                    }
                    n.Children[index1] = this.m_command.CreateNode((Op)this.m_command.CreateProjectOp(varVec), child, this.m_command.CreateNode((Op)this.m_command.CreateVarDefListOp(), args));
                    this.m_command.RecomputeNodeInfo(n.Children[index1]);
                    ExtendedNodeInfo extendedNodeInfo2 = this.m_command.GetExtendedNodeInfo(n.Children[index1]);
                    extendedNodeInfo2.Keys.KeyVars.InitFrom(extendedNodeInfo1.Keys.KeyVars);
                    extendedNodeInfo2.Keys.KeyVars.Set(computedVar1);
                }
            }
            n.Op = (Op)this.m_command.CreateUnionAllOp(op.VarMap[0], op.VarMap[1], var1);
            this.m_command.RecomputeNodeInfo(n);
        }