Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Add topic interfaces #4

Merged
merged 2 commits into from
Mar 29, 2018
Merged

Add topic interfaces #4

merged 2 commits into from
Mar 29, 2018

Conversation

cw9
Copy link
Contributor

@cw9 cw9 commented Mar 25, 2018

Add topic interfaces

@xichen2020 @jeromefroe @schallert

@cw9 cw9 changed the title Add topic service Add topic interfaces Mar 25, 2018
topic/service.go Outdated
return nil
}
t, err := NewTopicFromValue(value)
if err != nil {

Choose a reason for hiding this comment

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

Why do we want to ignore errors here (or rather in the Watch method on the interface)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically this happens when there is an invalid topic proto in KV and the user could probably only treat that case as if the topic was deleted from KV, so it returns a nil Topic here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we return an exported error so user can make that decision instead of the library making the decision for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure can expose error through the interface

topic/types.go Outdated
// Watch watches the updates of a topic.
type Watch interface {
C() <-chan struct{}
Get() Topic

Choose a reason for hiding this comment

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

As mentioned in a previous comment - if why shouldn't we allow for Get() to propagate errors? Especially if this interface is to be used in applications where there can be errors in retrieving values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to keep the convention as other Watches, like m3x or m3cluster, we could return Topic, error here, but user probably can't do much with the error update as well. I don't feel strongly either way.

topic/types.go Outdated

// Service provides accessibility to topics.
type Service interface {
// Get returns the topic for the given name.

Choose a reason for hiding this comment

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

Nit: Might be worth adding in the comment that the int param is version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good

ConsumerServices() []ConsumerService

// SetConsumerServices sets the consumers of the topic.
SetConsumerServices(value []ConsumerService) Topic
Copy link

Choose a reason for hiding this comment

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

Do we want to include an AddConsumerService method so that users dont have to pass in an entire list of all the existing consumer services if they just want to append one service to the end of a list.

Also presumably this topic metadata is stored in KV, however from what I can tell this function does not take a version so we can not leverage check and set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CAS is not an issue, when you do a get you will get the version and the topic, you manipulate the topic then you can check and set with old version you got. For AddConsumerService, I'm on the fence, I guess we can do it for both the add and remove cases, maybe I'll add it when I really need it. Right now I need the Set function only for tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added version anyways so the user of topic can log version if needed

topic/topic.go Outdated
SetConsumerServices(css), nil
}

func (t *topic) Name() string {
Copy link

Choose a reason for hiding this comment

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

MEGA-NIT: for the getters we could use a non-pointer receiver.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not making much difference in this case, I used to be a fan of non-pointer receiver as well but the convention in m3db repos is just using pointer receiver in many cases.

return t.name
}

func (t *topic) SetName(value string) Topic {
Copy link

Choose a reason for hiding this comment

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

NIT: this is just a naming thing. It seems like this function would set the name of the topic, however it returns a new topic with the name set, the original topic name is unchanged. I might point this out in a comment or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is a common pattern used in m3db repos, almost all set functions returns a new one unless it's too expensive to create a new one. I think your comment is valid, maybe we should point that out to the interfaces that is changing the original object.

}, nil
}

func (s *service) Get(name string) (Topic, int, error) {
Copy link

Choose a reason for hiding this comment

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

Comments on public functions? I would assume they are similar to those defined in the interface in the types.go file, but it would be nice to have those here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually we don't repeat those comments if they are not changed from the interface.

topic/service.go Outdated
return &w{w: watch}
}

type w struct {
Copy link

Choose a reason for hiding this comment

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

for consistency can we name the struct a lowercase version of the interface it implements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

@cw9 cw9 changed the base branch from chao-protocol to master March 28, 2018 22:18
return NewWatch(w), nil
}

func key(name string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to have it for now, havn't finally decided how the key should look like yet, so that I just need to change this one function if I want to change all the key usages.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case do you want to define a keyType and call this newKey(name string) keyType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feels like an overkill to create a keyType which is just an alias of string type, but can do if you feel strongly

topic/service.go Outdated
return &watch{w: w}
}

type watch struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to just embed it?

topic/service.go Outdated
return nil
}
t, err := NewTopicFromValue(value)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we return an exported error so user can make that decision instead of the library making the decision for them?

topic/topic.go Outdated
case topicpb.ConsumptionType_REPLICATED:
return Replicated, nil
}
var c ConsumptionType
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we define an Unknown consumption type? Otherwise this will just be Shared by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

topic/topic.go Outdated
@@ -92,6 +97,16 @@ func (t *topic) SetConsumerServices(value []ConsumerService) Topic {
return &newt
}

func (t *topic) Version() int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm how is the version useful? Seems this is something that shouldn't be exposed to the users of this library no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly for logging reasons, so that user can log that it's processing topic with version X

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if users of this library need to know that the topic has versions, but okay.

Copy link
Contributor

@xichen2020 xichen2020 left a comment

Choose a reason for hiding this comment

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

LGTM

@cw9 cw9 merged commit 9382e5d into master Mar 29, 2018
@cw9 cw9 deleted the chao-topic branch March 29, 2018 16:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants