Closed SwanSpouse closed 4 years ago
That's an interesting observation, thanks ...
I think that the primary user of this library, nsqd, is OK with the fact that this Depth()
call is "eventually consistent", because in nsqd it is (mostly? I think?) called from a different goroutine than the one reading or writing the diskqueue.
Changing Depth()
to use channels like this makes it significantly more expensive. It may or may not matter, depending on how frequently the program using this calls Depth()
. I came up with another solution, which I think is less expensive than your proposal (but still more expensive than just an atomic read): https://github.com/nsqio/go-diskqueue/pull/11/commits/b8887fdf997993a6be72c02ba7188af0cbcda1ee
I'll leave this for a little while, for the other maintainers to have some time to take a look and think about it. cc @mreiferson
That's an interesting observation, thanks ...
I think that the primary user of this library, nsqd, is OK with the fact that this
Depth()
call is "eventually consistent", because in nsqd it is (mostly? I think?) called from a different goroutine than the one reading or writing the diskqueue.Changing
Depth()
to use channels like this makes it significantly more expensive. It may or may not matter, depending on how frequently the program using this callsDepth()
. I came up with another solution, which I think is less expensive than your proposal (but still more expensive than just an atomic read): b8887fdI'll leave this for a little while, for the other maintainers to have some time to take a look and think about it. cc @mreiferson
I agree, but as an independent library, it may be used in somewhere else, i think it's necessary to make Depth()
return correct result even though it's more expensive.
your solution is much better and succinct. i benefit a lot! 😃
done in #11
When i run such codes above, i get result like this.
when executes at line638,
<-dq.ReadChan
will get result and continue, then we got wrong depth, becauseline641 d.moveForward()
is not reached.I send a signal to notice i want to get depth, it will run with
<-dataRead
in serial and get expected result.