Skip to content

Tracking: disabling call BCAST mode again when BCAST already enabled#8135

Closed
hwware wants to merge 1 commit into
redis:unstablefrom
hwware:tracking_bcast_dupmsg_fix
Closed

Tracking: disabling call BCAST mode again when BCAST already enabled#8135
hwware wants to merge 1 commit into
redis:unstablefrom
hwware:tracking_bcast_dupmsg_fix

Conversation

@hwware

@hwware hwware commented Dec 3, 2020

Copy link
Copy Markdown
Contributor

This PR fixes #8003 . The cause of this issue is if we did not specify any prefixes, "" will be used as the default prefix since an empty string is a prefix for all other string. However if we call the CLIENT TRACKING ON BCAST with prefixes again both "" and other prefixes will be registered in the prefixes radix tree for bcast tracking, this will cause same client receive duplicate invalidation messages.

For a side note regarding my comment if user specifying one prefix is a subset of another in the same call: #8003 (comment) . There are two ways we handle this:

  1. Do a brute force check for each prefixes.
  2. Provide the Radix tree API for checking if a key's path has other keys.

The first one has O(n^2) performance and we are trying to avoid, the second is optimal but we may not doing it for now since it need to change the lower level Radix tree code for providing this API, maybe we can do this later, but for now since we don't want to bring much complexity, we can just simply solving the original issue now first..

@hwware hwware changed the title disabling call BCAST mode again when BCAST already enabled Tracking: disabling call BCAST mode again when BCAST already enabled Dec 3, 2020
@madolson

madolson commented Dec 4, 2020

Copy link
Copy Markdown
Contributor

I would vote for option 1. Yes it's O(N^2), but how many prefixes are people really using? This is really an enabling configuration.

@madolson

madolson commented Dec 4, 2020

Copy link
Copy Markdown
Contributor

Also technically backwards breaking, so @redis/core-team

@hwware

hwware commented Dec 4, 2020

Copy link
Copy Markdown
Contributor Author

Hi @madolson , thank you for your optionion, actually I also think application or user shouldn't have many prefixes for the BCAST tracking call , so option 1 should be good to handle... But just not sure if it is ok for us to assume something in the application even though we did not see that. Maybe we can wait for some other comments?

@oranagra oranagra added release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten labels Dec 4, 2020
@oranagra

oranagra commented Dec 9, 2020

Copy link
Copy Markdown
Member

@hwware @madolson on my way to merge it and edit the commit message i have doubts.
better late then sorry... right?

i don't recall our previous discussions about the matter and what state i had in my brain at the time (volatile memory).

this change actually prevents users that wants to enable two different BCAST prefixes using two consecutive calls from achieving their purpose, and is of course a braking change (evident by the test that had to be modified).

i'm afraid that when we roll this out we'll break some applications.
so thinking of it again, i think i prefer users that enabled two similar prefixes to receive duplicate invalidation messages, rather than disallowing two different prefixes to be added in consecutive calls to the TRACKING command.
it may have been an acceptable limitation (require a single TRACKING command) if it had existed since the get go, but i don't think wanna do this now.

looking again at the discussion, maybe at the time i belied that this is a partial (non hermetic) solution to the problem, which we can later improve to be more hermetic. but now i realize (correct me if i'm wrong) that if we implement the O(N^2) search later on, this limitation will be lifted.
considering that, i think i rather keep the duplicate invalidation messages for now.

[i'll downvote this till we finish the discussion, so that we don't risk accidentally merging it before then]

@oranagra oranagra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change and i have doubts (see message above)

@hwware

hwware commented Dec 9, 2020

Copy link
Copy Markdown
Contributor Author

thanks @oranagra for the concern, it is better we clearify everything before we merge it.

We discussed this issue in #8003 and our chat. I was actually had same concern before if we disabled te second BCAST call, which will disable the ability to register new prefixes. Since currently there is no APIs for managing BCAST prefixes separatelly, this is the way how we can register prefix in a accumulating way. but as @madolson mentioned, clients can still do a disable/enable approach for registering the new prefixes(but not a accumulating way) and this might be the most common way client manage this. In some stateless application I am not sure if the incremental way might be the case client side choosed, but we maybe can leave the discussion and implementsion for prefix add/delete functionality after client opened this request? but for now I think fixing this bug is necessary. How do you think on this? thanks

@madolson

Copy link
Copy Markdown
Contributor

I guess that's fair, I was in the mindset that most of the client tracking APIs are setting the state, not adding to the state. So in this case, calling this function twice was basically a bug. But, if instead we think of this as an add prefix API, like you are suggesting, then this use case is perfectly valid.

We can just solve the deduplication bug, it shouldn't be that hard to to loop over all the already registered prefixes and see if either are a substring of another one.

CLIENT TRACKING BCAST ON PREFIX foo PREFIX bar
CLIENT TRACKING BCAST ON PREFIX f

Would deduplicate to having two prefixes, 'bar' and 'f'. @hwware We should be able to do that easily right?

@hwware

hwware commented Dec 10, 2020

Copy link
Copy Markdown
Contributor Author

@madolson i felt this might introduce some level of complexity, if we doing deduplicate. since the prefixes will be saved in two places: the global PrefixTable for all clients prefixes and for each client itself which is in client_tracking_prefixes .. If we do deduplicates we need to search and delete in these two rax trees, for client rax itself i would't consider much, but for the global Prefix, since it contains all the client registered prefix, it maybe inefficient for searching and operating in some scenario. Therefore i would vote for fail early before actually insert the prefix... Please let me know if i miss anything. thanks

@madolson

madolson commented Dec 13, 2020

Copy link
Copy Markdown
Contributor

@hwware @oranagra I posted an implementation for deduplication: #8176

I don't think it's that complex, and it's more backwards compatible.

@hwware

hwware commented Dec 13, 2020

Copy link
Copy Markdown
Contributor Author

Hi @madolson @oranagra , i am thinking this dupicate invalidation message issue could have another way to solve. I think we put too much complexity in managing the prefixes but maybe when we doing the invalidate we can do something.
how about we do this?

  1. the idea is we can setup a nested rax tree for tracking whether a key has been invalidated already for a client in every round . this is like a lookup table from key to clients..
  2. when we do the invalidation in https://github.com/redis/redis/blob/unstable/src/tracking.c#L494, we additionally check whether the key has been set in the rax tree for this client. If so we skip and if not we set it.

I think this way we can also avoid the duplicate invalidation message issue, also since the invalidation happens in beforeSleep call, this rax tree shouldn't grow big. not sure if that make sense to your guys or is there anything that I was missing? thanks!

Sorry about the previous notification, i made a mistake :(

@madolson

Copy link
Copy Markdown
Contributor

@hwware I don't like the idea of adding complexity on the hot path. The deduplication work is harder, but we don't expect people to be updating them very often.

@hwware

hwware commented Dec 14, 2020

Copy link
Copy Markdown
Contributor Author

Hi @madolson , for the deduplication work, I have one concern regarding this: it may potentically close the door for us to implement some other prefix APIs, if user request and we need to extend in the future: such as show registered prefixes, or delete prefixes.. Not sure for now we have a valid use case or not, but just want to leave a note here. otherwise this idea seems ok to me..

@oranagra oranagra removed the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Dec 21, 2020
@hwware

hwware commented Dec 23, 2020

Copy link
Copy Markdown
Contributor Author

closing this PR since we agree to use #8176 for this fix.

@hwware hwware closed this Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Duplicate invalidation message when turning tracking with BCAST option on with and without prefixes

6 participants