[SERVER-37938] removeTagRange returns {ok: 1} even as it ignores matching range Created: 06/Nov/18  Updated: 27/Oct/23  Resolved: 17/May/23

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 3.4.18, 4.0.3
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Nic Cottrell Assignee: Pol Pinol
Resolution: Works as Designed Votes: 0
Labels: ShardingRoughEdges, neweng, sharding-common-backlog, sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File steps-2-to-3.js    
Issue Links:
Related
is related to SERVER-77216 sh.removeTagRange ignores the tagName... Closed
Assigned Teams:
Sharding EMEA
Sprint: Sharding EMEA 2023-05-15, Sharding EMEA 2023-05-29
Participants:
Case:

 Description   

I have attached a reproduction of a 3.4 sharded cluster moving from 2 to three shards with ranges in place.

This has a compound shard key:

sh.shardCollection("trev.historicTrackingEvent", {platformVehicleIdentifier: 1, triggerTime: 1})

This works:

sh.addTagRange("trev.historicTrackingEvent",
      { platformVehicleIdentifier: MinKey},
      { platformVehicleIdentifier: "8" },
      "A" // Zone A
);

and defaults triggerTime to MinKey

However,

sh.removeTagRange("trev.historicTrackingEvent",
   { platformVehicleIdentifier: MinKey},
    { platformVehicleIdentifier: "8" },
     "A"  
 );

gives

{ok:1}

but leaves the config in config.tags.

It needs to be changed to the following with explicit triggerTime values:

sh.removeTagRange("trev.historicTrackingEvent",
 		{ platformVehicleIdentifier: MinKey, triggerTime: MinKey},
    { platformVehicleIdentifier: "8" , triggerTime: MinKey},
     "A" // Zone A
 );

This was quite confusing and hard to troubleshoot. Perhaps sh.removeTagRange should return ok:0 when no tags match, and/or include a message? And/or use the same logic as in sh.addTagRange to default the second field to MinKey?



 Comments   
Comment by Pol Pinol [ 12/May/23 ]

Investigating the description of the ticket, we can identify three different issues:

  • If we have a compound shard key, removeTagRange is not removing correctly the tag from config.tags.
    • Since v4.4, it does not apply. We can check the correct behaviour with this simplified reproducible.

      (function() {
      'use strict';
      // Configure initial sharding cluster
      const st = new ShardingTest({});
       
      // Shard collection
      const db = st.s.getDB("test");
      st.shardColl(db.coll, {skey1: 1, skey2: 1});
       
      // Add tag range
      st.addShardTag(st.shard1.shardName, 'A');
      assert.commandWorked(st.addTagRange(db.coll.getFullName(), {skey1: MinKey}, {skey1: 10}, "A"));
       
      // Make sure that tag range has been added
      assert.eq(1, st.s.getDB("config").tags.find({}).itcount());
       
      // Remove tag range
      assert.commandWorked(st.removeTagRange(db.coll.getFullName(), {skey1: MinKey}, {skey1: 10}, "A"));
       
      // Make sure that tag range has been removed
      assert.eq(0, st.s.getDB("config").tags.find({}).itcount());
       
      st.stop();
      })();
      

  • When we use removeTagRange with a non-existent range, the command will return ok: 1.
    • This is a correct behaviour because the command has succeeded but it has not removed entries.
  • Finally, removeTagRange(nss, min, max, tagName) ignores the tagName. It will remove the range independently of the tag name associated.
    • This command (removeTagRange) is an alias of removeRangeFromZone. As we can see in the docs, removeRangeFromZone(nss, min, max) removes the range from the tag without passing this as a parameter. It can be done this way because there is a 1:N relation between tags - ranges. One range can only belong to one tag, thus there is no need to have the tag name to remove a range.
Generated at Thu Feb 08 04:47:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.