Skip to content

Allow PFCOUNT in replicas #2137

Closed
Closed

Description

@antirez

PFCOUNT currently can't be executed in read only slaves since it's marked as a write command because of the caching performed.

Quoting myself from the mailing list:

I believe we should simply remove the
write flag from the PFCOUNT command, declaring it as a read-only
command. What do you think?
I checked all the code paths where we check if a command is a write
command, and basically I can't find a single one where it is a problem
if PFCOUNT alters the flag.

If we want to stay super correct and guarantee that HLLs are the same
string exactly both in the master and slave side, we can still do this
by checking inside the command if we are executing in the context of a
read-only slave and prevent the caching, but this would trash
performances when people need to scale PFCOUNT using replication, so I
would not mind that there is this one-bit desync in HLLs between
slaves and masters.

Activity

  1. joshula commented on Nov 13, 2014

    @joshula

    Agree. This is the only read op that I can't scale right now - you have my full support.

  2. mattsta commented on Nov 13, 2014

    @mattsta
    Contributor

    If you need it now, it's just a one character change:

    diff --git a/src/redis.c b/src/redis.c
    index 09b8103..d00af4f 100644
    --- a/src/redis.c
    +++ b/src/redis.c
    @@ -279,7 +279,7 @@ struct redisCommand redisCommandTable[] = {
         {"command",commandCommand,0,"rlt",0,NULL,0,0,0,0,0},
         {"pfselftest",pfselftestCommand,1,"r",0,NULL,0,0,0,0,0},
         {"pfadd",pfaddCommand,-2,"wmF",0,NULL,1,1,1,0,0},
    -    {"pfcount",pfcountCommand,-2,"w",0,NULL,1,1,1,0,0},
    +    {"pfcount",pfcountCommand,-2,"r",0,NULL,1,1,1,0,0},
         {"pfmerge",pfmergeCommand,-2,"wm",0,NULL,1,-1,1,0,0},
         {"pfdebug",pfdebugCommand,-3,"w",0,NULL,0,0,0,0,0},
         {"latency",latencyCommand,-2,"arslt",0,NULL,0,0,0,0,0}
  3. joshula commented on Nov 13, 2014

    @joshula

    @ mattsta, thanks. Any thoughts on when it'll get merged into stable?

  4. antirez commented on Nov 13, 2014

    @antirez
    ContributorAuthor

    @joshula I need a few seconds to consider better the full implications of this.

    Right now, the reason why I don't commit the above one char change is that it sounds odd that a sequence of commands like PFADD + APPEND will create a non valid HyperLogLog which is so, basically, just a string, that is desynchronized between masters and slaves. Probably it's not a great issue, and probably the right approach, but I'm still not convinced. Another issue is with DEBUG DIGEST that will report two different hashes.

    The problem is that there is a design error here. A cached value is exposed... instead it should be handed as a dual-ported object, with a pointer in the robj structure being NULL or having a type-defined cache. However for the sake of memory efficiency, this was not done.

    I think I'll end doing the one char change at, let's say, 90% of probability. But probably I'll also modify DEBUG DIGEST to don't hash the final part of a string that has the HLL prefix.

  5. antirez commented on Dec 2, 2014

    @antirez
    ContributorAuthor

    Fixed in 8a7ccc5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions