Skip to content

Update NextIndex function.#11

Open
KAZYPinkSaurus wants to merge 1 commit intokasvith:masterfrom
KAZYPinkSaurus:master
Open

Update NextIndex function.#11
KAZYPinkSaurus wants to merge 1 commit intokasvith:masterfrom
KAZYPinkSaurus:master

Conversation

@KAZYPinkSaurus
Copy link

I came across your article while reading this post. Thank you for the wonderful article!

I have made changes to ensure consistency with the current value.

Previously, the current value would continuously increase if there were no errors. However, if a problem occurred with the backend selected by GetNextPeer func, the current value would fall within the range of 0 <= current < len(s.backends).

		idx := i % len(s.backends)     // take an index by modding
		if s.backends[idx].IsAlive() { // if we have an alive backend, use it and store if its not the original one
			if i != next {
				atomic.StoreUint64(&s.current, uint64(idx)) // Forces the value to be in the range `0 <= current < 
			}
			return s.backends[idx]
		}

I believe current should not continuously increase but should rather stay within the range of 0 <= current < len(s.backends), which is why I made this change.

I hope my PR is helpful to you.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

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

Successfully merging this pull request may close these issues.

1 participant