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

Counter init value is never used #74

Closed
vjuranek opened this issue May 6, 2020 · 0 comments
Closed

Counter init value is never used #74

vjuranek opened this issue May 6, 2020 · 0 comments

Comments

@vjuranek
Copy link
Contributor

vjuranek commented May 6, 2020

Counter init value is never used as CounterService.getOrCreateCounter() calls get() to find out if there's already exists any value for given counter and eventually use this value. However, get() always returns a value. In case counter doesn't exist, it returns 0 and thus init value is actually never used.

Example from CounterServiceDemo which initialize counter to 1
(Counter counter=counter_service.getOrCreateCounter("counter", 1);):

-- view: [A(raft-id=A)|0] (1) [A(raft-id=A)]
[1] Increment [2] Decrement [3] Compare and set [4] Dump log
[8] Snapshot [9] Increment N times [x] Exit
first-applied=0, last-applied=0, commit-index=0, log size=0b

-- view: [A(raft-id=A)|1] (2) [A(raft-id=A), C(raft-id=C)]
-- changed role to Candidate
-- changed role to Leader
-- view: [A(raft-id=A)|2] (3) [A(raft-id=A), C(raft-id=C), B(raft-id=B)]
4

index (term): command
---------------------

[1] Increment [2] Decrement [3] Compare and set [4] Dump log
[8] Snapshot [9] Increment N times [x] Exit
first-applied=0, last-applied=0, commit-index=0, log size=0b

3
expected value: 1
update: 5
failed setting counter "counter" from 1 to 5, current value is 0
@belaban belaban closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants