/// <summary> /// Initialises a new instance of the <see cref="PartitionNodeCollection"/> class. /// </summary> /// <param name="subscriberId">The subscriber identifier.</param> public PartitionNodeCollection(int subscriberId) { // Obtain the table's max Id var tableSize = new TableSize(subscriberId); long maxId = tableSize.MaxId; // Set privates SubscriberId = subscriberId; nodeEndList = new List<long>(); // Create starting node for this subscriber, between zero and max replicated Id StartingNode = new PartitionNode(subscriberId, 0L, maxId); }
/// <summary> /// Creates the child nodes recursively, and adds missing Table IDs /// if it is a final node. /// </summary> /// <param name="parentNode">The parent node.</param> private void CreateChildNodes(PartitionNode parentNode) { // Ignore intervals with no difference between publisher and subscriber if (parentNode.NodePartitionPair.DifferenceCount > 0) { // If the interval size > 0 if (parentNode.MaxId != parentNode.MinId) { // Get the interval and divide it in two long intervalSize = parentNode.MaxId - parentNode.MinId + 1; long midpoint = parentNode.MinId + (intervalSize / 2); // Assign each half of the interval to a new child node parentNode.LeftNode = new PartitionNode(SubscriberId, parentNode.MinId, midpoint - 1); parentNode.RightNode = new PartitionNode(SubscriberId, midpoint, parentNode.MaxId); // Create new child nodes for each child node CreateChildNodes(parentNode.LeftNode); CreateChildNodes(parentNode.RightNode); } else { // If it's the final node which can't be split further, it's a single value. // Add it to the list of missing IDs nodeEndList.Add(parentNode.MinId); } } }