Skip to content

Commit 48152f0

Browse files
authored
[BUG]: Fix service name extraction logic in go (#6111)
## Description of changes The logic to extract the service name in go code was wrong. The logic to generate the lock name for the sysdb service during leader election was dependent on this and was faulty as a result. Every replica ended up generating different lock names. This diff fixes that issue. - Improvements & Bug fixes - ^^ - New functionality - ... ## Test plan _How are these changes tested?_ - [ ] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Migration plan _Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?_ ## Observability plan _What is the plan to instrument and monitor this change?_ ## Documentation Changes _Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs section](https://github.com/chroma-core/chroma/tree/main/docs/docs.trychroma.com)?_
1 parent acde656 commit 48152f0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

go/pkg/leader/election.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ import (
1616
)
1717

1818
// extractServiceName extracts the service name from a pod name.
19-
// The service name is expected to be the prefix before the last hyphen in the pod name.
20-
// For example, from pod name "chroma-query-abc123", it will return "chroma-query".
19+
// The service name is expected to be the prefix before the deployment hash suffix.
20+
// For example, from pod name "sysdb-7c85f55c69-z55lm", it will return "sysdb".
2121
func extractServiceName(podName string) string {
2222
parts := strings.Split(podName, "-")
23-
if len(parts) > 1 {
24-
return strings.Join(parts[:len(parts)-1], "-")
23+
if len(parts) > 2 {
24+
// Remove the last two parts (replica set hash + pod hash)
25+
return strings.Join(parts[:len(parts)-2], "-")
2526
}
2627
return podName
2728
}
2829

2930
// AcquireLeaderLock starts leader election and runs the given function when leadership is acquired.
3031
// The context passed to onStartedLeading will be cancelled when leadership is lost.
31-
// The service name is automatically determined from the pod name by extracting the prefix before the last hyphen.
32+
// The service name is automatically determined from the pod name by extracting the base service name.
3233
// The lock name will be formatted as "{service-name}-leader".
3334
func AcquireLeaderLock(ctx context.Context, onStartedLeading func(context.Context)) {
3435
podName, _ := os.LookupEnv("POD_NAME")

0 commit comments

Comments
 (0)