mstate: state package replacement using mgo.
This is the first step towards replacing Zookeeper with MongoDB.
Mstate will slowly reimplement the state package while preserving the
original state API.
This change implements preliminary support for Machines.
https://code.launchpad.net/~aramh/juju-core/mstate-machine-basic/+merge/111235
(do not edit description out of merge proposal)
On 2012/06/18 21:59:18, aram wrote: > Please take a look. Looking good. On comment, and ...
12 years, 9 months ago
(2012-06-19 05:51:19 UTC)
#2
On 2012/06/18 21:59:18, aram wrote:
> Please take a look.
Looking good.
On comment, and this is just my personal taste, but I feel you are overusing
named return arguments. I think they should be used sparingly, only where it
makes sense in deeply nested loops. I say this because of their potential to
shadow variables. I have no idea what the opinion of the group is on this point
of style so please take this as a simple a small grain of salt.
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go File mstate/machine.go (right): https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go#newcode20 mstate/machine.go:20: } can we have a String() method as well ...
12 years, 9 months ago
(2012-06-19 05:51:28 UTC)
#3
> On comment, and this is just my personal taste, but I feel you are ...
12 years, 9 months ago
(2012-06-19 10:48:21 UTC)
#4
> On comment, and this is just my personal taste, but I feel you are overusing
> named return arguments.
I love named return arguments. They provide some nice things:
1) Much easier refactoring. If I need to change or rearrange code
inside a function I usually don't have to think how return
parameters change.
2) Proper usage of them forces the programmer to write code in a
top to bottom fashion making the code easier to read and
understand (Tob Duff of Duff's Device fame has a nice essey
about this: http://iq0.com/notes/deep.nesting.html )
3) They provide a nice mental model of what would be returned at
all times making the code easy to reason about. When you start
reading a function, you read the named return arguments first,
then you read the function thinking "what happens to these return
arguments and in what conditions". You always know the output, and
this helps a lot.
4) When you use named return arguments and do not return unadorned,
but construct new return values, it's a big warning sign you can't
miss. It's a mark that it should be read extra carefully.
5) They also allow for stubs like this:
func f() (s string, err error) { return }
If I'd have to write many stubs like the above, things would
get complicated for no reason (I've written a gostub command
a few days ago:
http://code.google.com/p/rbits/source/browse/gostub/gostub.go)
looks good as a start. the thing we really have to be careful about is ...
12 years, 9 months ago
(2012-06-19 13:48:45 UTC)
#5
looks good as a start.
the thing we really have to be careful about is the move away from atomicity
(for instance, AllMachines in the current state package returns an atomic
snapshot of all current machines, which doesn't look like it will be the case
here).
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go
File mstate/machine.go (right):
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go#newcode24
mstate/machine.go:24: mdoc := &machineDoc{}
On 2012/06/19 05:51:28, dfc wrote:
> var mdoc = new(machineDoc) ?
my preference would be
var doc machineDoc
and use &doc below.
Unfortunately due to some bzr troubles, I had to submit a different CL: https://codereview.appspot.com/6295103 https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go ...
12 years, 9 months ago
(2012-06-19 13:58:35 UTC)
#6
12 years, 8 months ago
(2012-06-20 14:51:18 UTC)
#9
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go
File mstate/machine.go (right):
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go#newcode24
mstate/machine.go:24: mdoc := &machineDoc{}
On 2012/06/20 13:36:34, niemeyer wrote:
> On 2012/06/19 13:58:35, aram wrote:
> > On 2012/06/19 05:51:28, dfc wrote:
> > > var mdoc = new(machineDoc) ?
> >
> > I don't know, personally I prefer new(T), but the existing code uses &T{}
> almost
> > exclusively. Maybe it's time to decide on a convention?
>
> We've discussed this convention before, and sticked to &T{} indeed.
we often use the
var buf bytes.Buffer
foo(&buf)
convention too, FWIW.
12 years, 8 months ago
(2012-06-20 16:48:40 UTC)
#11
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go
File mstate/machine.go (right):
https://codereview.appspot.com/6304099/diff/3001/mstate/machine.go#newcode27
mstate/machine.go:27: return
On 2012/06/20 13:36:34, niemeyer wrote:
> Aram, we've had some large debate about errors in the state package, and even
if
> they are not perfect we're trying to make them consistently better.
>
> Please have a look at the existing errors, and let's try to have something
> equivalent here, including equivalent messages (the messages there were
properly
> reviewed recently).
>
> The other methods should be reviewed in the same sense too.
Done.
This is looking great. Probably the last pass. https://codereview.appspot.com/6304099/diff/9002/mstate/machine.go File mstate/machine.go (right): https://codereview.appspot.com/6304099/diff/9002/mstate/machine.go#newcode38 mstate/machine.go:38: err ...
12 years, 8 months ago
(2012-06-20 19:31:55 UTC)
#15
*** Submitted: mstate: state package replacement using mgo. This is the first step towards replacing ...
12 years, 8 months ago
(2012-06-21 16:26:56 UTC)
#20
*** Submitted:
mstate: state package replacement using mgo.
This is the first step towards replacing Zookeeper with MongoDB.
Mstate will slowly reimplement the state package while preserving the
original state API.
This change implements preliminary support for Machines.
R=dfc, rog, niemeyer
CC=
https://codereview.appspot.com/6304099
Issue 6304099: mstate: state package replacement using mgo.
Created 12 years, 9 months ago by aram
Modified 12 years, 8 months ago
Reviewers: mp+111235_code.launchpad.net
Base URL:
Comments: 50