-
Notifications
You must be signed in to change notification settings - Fork 26
Conversation
5739f11
to
50b6144
Compare
@Stebalien This is a rough sketch of my proposal in #38, could you take a look at it please and tell me what you think please? This patch doesn't guarantee that different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/LGTM
|
||
valueLock sync.Mutex | ||
valueToPublish cid.Cid | ||
lastValuePublished cid.Cid | ||
valueToPublish *cid.Cid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a pointer ? Can the CID be modified (elsewhere) while we are waiting to publish ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think I see how this handled in PublishNow()
with the extractedValue == nil
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the CID be modified (elsewhere) while we are waiting to publish ?
It shouldn't be, the Update
API hasn't changed, we still make a local copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be a cid.Cid
and should be set to cid.Undef
when "nil". (probably should have been cid.Nil
but I didn't win that argument).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought of that at first but we do cid.Undef
to issue publish orders, at least in some tests,
Lines 43 to 45 in 4fb6dc4
go func() { | |
for { | |
rp.Update(cid.Undef) |
so I think it violates the semantics I would expect of a nil
value.
I agree that we should fix that and provide a cid.Nil
but in the meanwhile I don't see the harm in implementing the nil
with a pointer for an internal variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pointer is fine but shouldn't be necessary. Really, we should fix that test, passing the "Undef" CID is should be equivalent to a "nil" CID (and passing a nil CID to rp.Update
doesn't make sense).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the right approach. However, I'd expect PublishNow
to only return after the latest value has been published (even if there's a concurrent publish).
|
||
valueLock sync.Mutex | ||
valueToPublish cid.Cid | ||
lastValuePublished cid.Cid | ||
valueToPublish *cid.Cid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be a cid.Cid
and should be set to cid.Undef
when "nil". (probably should have been cid.Nil
but I didn't win that argument).
if err != nil { | ||
return err | ||
if extractedValue == nil { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A concurrent call won't actually wait. We may need a RwMutex here.
Yes, that seems fair but |
If one changes a file and then calls Here, given two commands call |
@@ -139,17 +113,20 @@ func (rp *Republisher) Run() { | |||
|
|||
// Wrapper function around the user-defined `pubfunc`. It publishes | |||
// the (last) `valueToPublish` set and registers it in `lastValuePublished`. | |||
func (rp *Republisher) publish(ctx context.Context) error { | |||
// TODO: Allow passing a value to `PublishNow` which supersedes the | |||
// internal `valueToPublish`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we want to allow this. Users shouldn't swap out the MFS root using the republisher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the comment, what do you mean by swap out?
The TODO
(that I don't think I worded correctly) was aiming at adding an optional argument that would replace the Update(newCid); PublishNow();
call pair with just a PublishNow(newCid)
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Yeah, that makes sense.
(context: I keep thinking we're exposing the republisher to the user)
Good point, actually this is just a simple (but important) mistake on my part, I should have been following the |
50b6144
to
89de69a
Compare
Are you referring to your latest change? That's going to overwrite potentially unpublished values. Also, we really shouldn't be allowing the user to invoke |
If I understand you correctly (please correct me if not) the two issues to study are:
This is actually what motivated this PR in the first place. I think the previous examples you mentioned put focus on multiple Anyway, if my appreciation in either of those points is wrong let's close this PR, my only objective at the moment, since I don't have much time left for proper fixes and redesigns, is to simplify the code for the next one to come along (hopefully not you :) to get a more clear perspective of what the code does (and doesn't do) and how could that be improved upon. Any suggestions towards that end you could propose I'll try to implement during next week. |
It's probably thread-safe (although we shouldn't assume that) however, that doesn't matter. If the user calls
Given two simultaneous calls to
Fixing #38 shouldn't require a redesign. |
I'm not sure I'm following, with this patch sequential calls to
Agreed, what I meant is that I want to diminish the technical debt that I think helps bugs like #38 go unnoticed, that requires a redesign I think. |
Ok, I think I get it, the loop in |
Holding the lock throughout |
Fixes #38.