Skip to content

SPOP optional count argument. (issue #1793) - #1803

Closed
advance512 wants to merge 964 commits into
redis:3.0from
advance512:spopWithCount
Closed

advance512 wants to merge 964 commits into
redis:3.0from
advance512:spopWithCount

Conversation

@advance512

Copy link
Copy Markdown
Contributor

More details of implementation in issue https://github.com/antirez/redis/issues/1793.


Commit message:

Added parameter to SPOP:

  • spopCommand() now runs spopWithCountCommand() in case the param is found.
  • Added intsetRandomMembers() to Intset: Copies N random members from the set into inputted 'values' array. Uses either the Knuth or Floyd sample algos depending on ratio count/size.
  • Added setTypeRandomElements() to SET type: Returns a number of random elements from a non empty set. This is a version of setTypeRandomElement() that is modified in order to return multiple entries, using dictGetRandomKeys() and intsetRandomMembers().
  • Added tests for SPOP with : unit/type/set, unit/scripting, integration/aof

paddybyers and others added 30 commits September 1, 2014 10:42
We can save a little work by aborting when we enter the function
if we're disconnected.
32 bit builds don't have a big enough long to capture
the same range as a 64 bit build.  If we use "long long"
we get proper size limits everywhere.

Also updates size of unsigned comparison to fit new size of `end`.

Fixes redis#1981
Previously, GETRANGE of a key containing nothing ("")
would allocate a large (size_t)-1 return value causing
crashes on 32bit builds when it tried to allocate the
4 GB return string.
Increase size of range request in getrange
The original implementation was modified in order to allow to
selectively announce a different IP or port, and to rewrite the two
options in the config file after a rewrite.
Because of the new ability to start with a truncated AOF, we need
to correctly release all the memory on EOF error. Otherwise there is a
small leak, that is not really a problem, but causes a false positive in
the tests that detect memory leaks.
When aof-load-truncated option was introduced, with a default of "yes",
the past behavior of the server to abort with trunncated AOF changed, so
we need to explicitly configure the tests to abort with truncated AOF
by setting the option to no.
*SCAN will cause redis server to hang for seconds
after millions of keys was deleted by SCAN/DEL pairs
Limit the *SCAN command `dictScan` iterations
The code to check the number of voters was never updated to follow the new
Sentinel specification, so the number of voters was computed using only
the set of Sentinels that provided a vote.

This means that there is a changing majority on partitions, even if
usually the issue is not triggered because of the configured quorum
check (what was broken was the other implicit check that requires anyway
half of the known sentinels to agree in order to start a failover).
This is a general fix (check that dirty delta is positive) but actually
should have as the only effect fixing the SAVE propagation to
AOF and slaves.
Recently we introduced the ability to load truncated AOFs, but
unfortuantely the support was broken since the server, after loading the
truncated AOF, continues appending to the file that is corrupted at the
end. The problem is fixed only in the next AOF rewrite.

This commit fixes the issue by truncating the AOF to the last valid
opcode, and aborting if it is not possible to truncate the file
correctly.
It is not clear if files open in append only mode will automatically fix
their offset after a truncate(2) operation. This commit makes sure that
we reposition the AOF file descriptor offset at the end of the file
after a truncated AOF is loaded and trimmed to the last valid command.
Now there are tests to write more data after loading a truncated AOF,
testing that the loaded data is correct, appending more, and testing
again.
This fixes a potential bug that was never observed in practice since
what happens is that the asynchronous connect returns ok (to fail later,
calling the handler) every time, so a ping is queued, and sent_ping
happens to always be populated.

Howver technically connect(2) with a non blocking socket may return an
error synchronously, so before this fix the code was not correct.
mattsta and others added 11 commits December 11, 2014 10:12
Instead of manually checking for strchr(n,':') everywhere,
we can use our new centralized IP formatting functions.
A few code style changes + consistent format: not nice for humans but
better for parsers.
Specialized single-use function. Not the best match for sds.c btw.
Also genClientPeerId() is no longer static: we need symbols.
It fixes a bad bug that crashes the server in certain conditions
as shown in issue redis#2210.
The old list did not made much sense... and the flag is currently not
used at all, so no side effects.
Otherwise there are security risks, especially when providing Redis as a
service, the user may "sniff" for admin commands renamed to an
unguessable string via rename-command in redis.conf.
@advance512

Copy link
Copy Markdown
Contributor Author

Okay. I rebased it, and updated the documentation here:
redis/redis-doc#465

Just one quick assumption that I need to verify. (Left over notes from June. Might even have verified it back then, but here goes anyways.)

There is no need to release the strings created by dupStringObject and createStringObjectFromLongLong, since _dictClear does so. Correct?

@mattsta

mattsta commented Dec 14, 2014

Copy link
Copy Markdown
Contributor

Okay. I rebased it,

Maybe? It could just be a GItHub problem, but this PR has a lot of out of place commits here (maybe because GitHub is forcing it on the 3.0 branch)?

The new commit can probably be cherry picked out okay though.

There is no need to release the strings created by dupStringObject and createStringObjectFromLongLong, since _dictClear does so. Correct?

Correct! Sets are just key-only dicts, and the dict definition is at https://github.com/antirez/redis/blob/unstable/src/redis.c#L525-L533 — it doesn't have a key duplication function, so it retains the key you pass in, and it also has a built-in key free function to destroy items automatically on delete.

Your feature looks good and even has tests and documentation!

Some minor notes on required Redis coding style:

  • no // comments allowed
  • no need to redisAssert() after zmalloc because zmalloc will exit on failure.
  • variables can't be camelCase. function names are camelCase, variables are snake_case.
  • multi-line comments start all lines with * (it's easier if your editor supports automatically doing it)
  • lines should be trimmed to 80 characters

@advance512

Copy link
Copy Markdown
Contributor Author

Thanks for the code review @mattsta, I appreciate it.
Cleaned it up as per the Redis required coding style. (Though I personally stopped following the 80 chars ruler style in all of my personal projects.)

I rebased the commit again, this time on antirez/redis/unstable, instead of advance512/redis/unstable (duh). So, less clutter.

The original Pull Request was to antirez:3.0 and not antirez:unstable, which is why we see all the extra commits on top. Unfortunately, Github doesn't allow changing the target branch of a pull request. So, I created a new Pull Request instead: #2215

@advance512
advance512 force-pushed the spopWithCount branch 2 times, most recently from 1f061dd to 57e907b Compare December 14, 2014 10:21
spopCommand() now runs spopWithCountCommand() in case the <count> param is found.
Added intsetRandomMembers() to Intset: Copies N random members from the set into inputted 'values' array. Uses either the Knuth or Floyd sample algos depending on ratio count/size.
Added setTypeRandomElements() to SET type: Returns a number of random elements from a non empty set. This is a version of setTypeRandomElement() that is modified in order to return multiple entries, using dictGetRandomKeys() and intsetRandomMembers().
Added tests for SPOP with <count>: unit/type/set, unit/scripting, integration/aof
--
Cleaned up code a bit to match with required Redis coding style
@antirez

antirez commented Dec 17, 2014

Copy link
Copy Markdown
Contributor

Hello, thanks! Closing this in favor of #2215.

@antirez antirez closed this Dec 17, 2014
antirez added a commit that referenced this pull request Dec 17, 2014
SPOP optional count argument. (issue #1793, supersedes pull request #1803)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.