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

[Feature]: Introduce factory method CreateDependencyWriter for backend storage #6498

Closed
zzzk1 opened this issue Jan 7, 2025 · 3 comments
Closed
Labels

Comments

@zzzk1
Copy link
Contributor

zzzk1 commented Jan 7, 2025

Requirement

Introduce factory method CreateDependencyWriter for backend storage

Problem

Based on the discussion in this GitHub pull request, I believe that instead of using type assertion to create StorageIntegration.DependencyWriter through dependencystore.Writer, a more effective approach would be to introduce a CreateDependencyWriter() function.

Proposal

  1. Introduce CreateDependencyWriter in storage/factory.go of the BaseFactory.

  2. storage factory Implement this function(just ES & Cassandra now, the others ignore).

es/factory.go
func (f *Factory) CreateDependencyWriter() (dependencystore.Writer, error) {
// TODO: Implement this feature
return "The Writer Instance", nil
}
es/grpc.go
func (f *Factory) CreateDependencyWriter() (dependencystore.Writer, error) {
return nil, nil
}

3.Add unit tests.

Open questions

No response

@dosubot dosubot bot added area/storage changelog:new-feature Change that should be called out as new feature in CHANGELOG storage/cassandra storage/elasticsearch labels Jan 7, 2025
@zzzk1
Copy link
Contributor Author

zzzk1 commented Jan 7, 2025

Hello @yurishkuro I’d love to hear your thoughts on this 😊

@yurishkuro
Copy link
Member

Is it going to solve any specific problem? I have two reservations about such change:

  1. You're suggesting to introduce it in v1 storage factories, which we are trying to deprecate.
  2. By adding it to a factory interface you create the impression that it is a required function, vs the current approach of an optional interface. It's unclean design having a method in an interface which you don't actually need to support. The compiler will require it to be implemented so where it's not possible the option is only either to panic or return not-implemented error. In both cases the caller is required to check if the backend actually supports writing deps, despite implementing said method, so you are not making the caller's life any easier. Thus back to my lead question.

@zzzk1
Copy link
Contributor Author

zzzk1 commented Jan 8, 2025

Is it going to solve any specific problem? I have two reservations about such change:

  1. You're suggesting to introduce it in v1 storage factories, which we are trying to deprecate.
  2. By adding it to a factory interface you create the impression that it is a required function, vs the current approach of an optional interface. It's unclean design having a method in an interface which you don't actually need to support. The compiler will require it to be implemented so where it's not possible the option is only either to panic or return not-implemented error. In both cases the caller is required to check if the backend actually supports writing deps, despite implementing said method, so you are not making the caller's life any easier. Thus back to my lead question.

Thanks!

@zzzk1 zzzk1 closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants