Find the bugRavenDB HiLo implementation
The follow code is part of RavenDB HiLo implementation:
private long NextId() { long incrementedCurrentLow = Interlocked.Increment(ref currentLo); if (incrementedCurrentLow > capacity) { lock (generatorLock) { if (Thread.VolatileRead(ref currentLo) > capacity) { currentHi = GetNextHi(); currentLo = 1; incrementedCurrentLow = 1; } } } return (currentHi - 1)*capacity + (incrementedCurrentLow); }
It contains a bug, can you see it? I took a long time to figure it out, I am ashamed to say.
BTW, you can safely assume that GetNextHi is correct.
More posts in "Find the bug" series:
- (29 Feb 2016) When you can't rely on your own identity
- (05 Jan 2016) The case of the degrading system–Answer
- (04 Jan 2016) The case of the degrading system
- (11 Sep 2015) The concurrent memory buster
- (20 Apr 2011) Why do I get a Null Reference Exception?
- (25 Nov 2010) A broken tree
- (13 Aug 2010) RavenDB HiLo implementation
- (25 Jul 2010) Accidental code reviews

Comments
Comment preview