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

config: export & list defaults #52

Merged
merged 1 commit into from
Jun 16, 2014
Merged

Conversation

jehiah
Copy link
Member

@jehiah jehiah commented Jun 15, 2014

@mreiferson this is a continuation of conversation in #47

This makes all config values exported, but copies them into a separate config object in Consumer and Producer so they can only be modified before you pass to a Consumer and Producer. This should mitigate the previous need to unexport fields.

I've also added a new way to denote defaults by marking them with struct tags. I like how this comes out by avoiding comments that might stray from the code values actually defaulting. I took a slightly different approach to just panic if an uninitialized config object is ever encountered.

thoughts?

@mreiferson mreiferson changed the title config udpates: export & list defaults config: export & list defaults Jun 16, 2014
@mreiferson
Copy link
Member

I like it, and I think it'll work... just a few comments

@@ -16,112 +16,87 @@ import (

// Config is a struct of NSQ options
//
// (see Config.Set() for available parameters)
// Use Config.Set(key string, value) as an alternate way to set parameters
type Config struct {
sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

we probably don't need this lock anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it important for Set() itself to be goroutine safe? The uses in consumer can easily be switched to the consumer mutex.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so... I had only added this mutex so that if (certain) values were changed the producer's goroutines could read them safely, which is no longer necessary since we copy values in at instantiation time.

Copy link
Member Author

Choose a reason for hiding this comment

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

k. i'll remove it

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved

@mreiferson
Copy link
Member

Since they raised the initial issue, I'm curious to hear your thoughts @kjk @shurcooL

MaxInFlight int `opt:"max_in_flight" min:"0" default:"1"`

// Maximum amount of time to backoff when processing fails 0 == no backoff
MaxBackoffDuration time.Duration `opt:"max_backoff_duration" min:"0" max:"60m" default:2m`
Copy link
Member

Choose a reason for hiding this comment

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

test is failing because this default value needs to be a string - so it's not actually being set in setDefaults

@jehiah
Copy link
Member Author

jehiah commented Jun 16, 2014

@mreiferson ready for final review pass.

r.config.RLock()
mif := r.config.maxInFlight
r.config.RUnlock()
r.mtx.RLock()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can use the existing mutex to cover this value (I'm pretty sure this was intentional, see #29 etc.).

Do you want to just make those few small "adjust max in flight interface" renames/doc updates here? We could switch the Consumer owned variable for current max in flight to an atomically updated/read variable (no locks, fewer LOC)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated.

* export config variables so they can be set directly (restore type safety)
* move defaults to struct tags (and considate docs)
* add Config.Valdate() and panic when NewConfig() is not used
* copy Config into Consumer and Producer so it's immutable
* rename SetMaxInFlight to ChangeMaxInFlight to more appropriately describe functionality
@mreiferson
Copy link
Member

nice work 👍

@mreiferson
Copy link
Member

💣s away

mreiferson added a commit that referenced this pull request Jun 16, 2014
@mreiferson mreiferson merged commit 23d7999 into nsqio:master Jun 16, 2014
@dmitshur
Copy link

This looks like a nice solution.

I like how this comes out by avoiding comments that might stray from the code values actually defaulting.

That's awesome! 👍

@jehiah jehiah deleted the exported_config_52 branch June 27, 2014 17:28
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.

3 participants