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

Factor out task queue name mangling into new package #3549

Merged
merged 6 commits into from
Jan 26, 2023
Merged

Conversation

dnr
Copy link
Member

@dnr dnr commented Nov 1, 2022

What changed?
Add package with task queue name mangling.
Add support for version set ids in mangled task queue names.

Why?
This logic is getting more complicated with versioning so we need to encapsulate it.

How did you test it?
unit tests

Potential risks

@dnr dnr requested a review from a team as a code owner November 1, 2022 22:18
func MustFromBaseName(name string) Name {
n, err := FromBaseName(name)
if err != nil {
return Name{baseName: "__INVALID__"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to use a value that makes it obvious that there is a bug, and not cover it up

return mangledTaskQueuePrefix + tn.baseName + suffixDelimiter + strconv.Itoa(tn.partition)
}
// versioned always use prefix
return mangledTaskQueuePrefix + tn.baseName + suffixDelimiter + tn.versionSet + versionSetDelimiter + strconv.Itoa(tn.partition)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Sprintf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it. Not sure it's any clearer 🤷

// Parent returns a Name for the parent partition, using the given branching degree.
func (tn Name) Parent(degree int) Name {
if tn.IsRoot() || degree == 0 {
return Name{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it return itself or an error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do want to return an error, not itself. I changed it to use a shared error value

// this should never happen when forwardedFrom is empty
return taskQueue.GetName()
}
tqName, err := tqname.FromBaseName(taskQueue.GetName())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it use MustFromBaseName?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to leave that for tests only. In other contexts I want an explicit error when the name is not a base name.

// mangled name.
func FromBaseName(name string) (Name, error) {
if strings.HasPrefix(name, mangledTaskQueuePrefix) {
return Name{}, fmt.Errorf("base name %q must not have prefix %q", name, mangledTaskQueuePrefix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return InvalidName?

// Parent returns a Name for the parent partition, using the given branching degree.
func (tn Name) Parent(degree int) Name {
if tn.IsRoot() || degree == 0 {
return InvalidName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any code checking against the InvalidName sentinel value, and it's not obvious from the API that it should be checked. So I think (Name, bool) or (Name, error) with a sentinel error are better return types here. I also think we should get rid of InvalidName because this is the only non-test use case, and we can panic in other cases because they're initiated by tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's a good idea.. the callers check IsRoot() || degree == 0 themselves already, but it makes the callers simpler if we just do it once. Actually I'll just get rid of MustFromBaseName and move it into test files. No reason to clutter the api

@dnr dnr merged commit 391ed61 into temporalio:master Jan 26, 2023
@dnr dnr deleted the ver3 branch January 26, 2023 23:47
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.

3 participants