Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis queue: fix loading old jobs from the database #27

Merged
merged 2 commits into from Oct 21, 2016

Conversation

flavio
Copy link

@flavio flavio commented Oct 18, 2016

The old code wasn't able to restore the jobs stored into a redis
database because of different issues:

  • The code to find all the gearman-related keys into Redis was wrong, it didn't use globbing, causing zero keys to be found.
  • Each key is made by three parts: gearman identifier (never changes), name of the function and unique id. The old code wasn't able to associate the correct value to the function and the unique id becase the scan code was using a wrong pattern (the - was not ignored).
  • The code stored the keys as binary data instead of strings. That caused the keys to have null terminators as part of their name, hence making the retrieval of the job data fail (an empty data was
    always returned).
  • The code created the job representation in memory without making a duplicate of the data attribute. The char* holding the data was freed by the hiredis code and later, as soon as a worker tried to access it caused a segmentation fault on the server side.

With these changes everything is working as expected.

Signed-off-by: Flavio Castelli fcastelli@suse.com

The old code wasn't able to restore the jobs stored into a redis
database because of different issues:

  * The code to find all the gearman-related keys into Redis was wrong,
    it didn't use globbing, causing zero keys to be found.
  * Each key is made by three parts: gearman identifier (never changes),
    name of the function and unique id. The old code wasn't able to
    associate the correct value to the function and the unique id becase
    the scan code was using a wrong pattern (the `-` was not ignored).
  * The code stored the keys as binary data instead of strings. That
    caused the keys to have null terminators as part of their name,
    hence making the retrieval of the job data fail (an empty data was
    always returned).
  * The code created the job representation in memory without making a
    duplicate of the data attribute. The char* holding the data was
    freed by the hiredis code and later, as soon as a worker tried to
    access it caused a segmentation fault on the server side.

With these changes everything is working as expected.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@@ -202,7 +202,7 @@ static gearmand_error_t _hiredis_add(gearman_server_st *, void *context,
build_key(key, unique, unique_size, function_name, function_name_size);
gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, "hires key: %u", (uint32_t)key.size());

redisReply *reply= (redisReply*)redisCommand(queue->redis(), "SET %b %b", &key[0], key.size(), data, data_size);
redisReply *reply= (redisReply*)redisCommand(queue->redis(), "SET %s %b", &key[0], data, data_size);
Copy link
Member

Choose a reason for hiding this comment

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

I'm a wee bit concerned that we're trading a nice safe fixed length string for a hopefully null terminated string. Is there some reason for that?

Copy link
Author

Choose a reason for hiding this comment

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

I had to change that because this GET request would have always returned an empty result. The key searched would not have been null terminated. We could change that to GET %b...

Also inside of Redis the key would be stored as _gear_-foo-123\00\00\00\00 which is not so nice :)

We are in full control over the key generation, hence there should not be relatively safe

Copy link
Member

Choose a reason for hiding this comment

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

ah Ok, I didn't really grasp what the vector had in it. Makes sense.

@SpamapS SpamapS merged commit 43f9bc4 into gearman:master Oct 21, 2016
esabol pushed a commit to esabol/gearmand that referenced this pull request Mar 23, 2017
redis queue: fix loading old jobs from the database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants