-
Notifications
You must be signed in to change notification settings - Fork 5
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
Use the common etcd client in etos-iut #83
base: main
Are you sure you want to change the base?
Use the common etcd client in etos-iut #83
Conversation
internal/database/etcd/etcd.go
Outdated
if p == nil { | ||
_, err := etcd.client.Delete(etcd.ctx, key) | ||
if err != nil { | ||
return 0, fmt.Errorf("Failed to delete key %s: %s", key, err.Error()) | ||
} | ||
return 0, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this added? and why in the write function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This client shall implement the io.ReadWriter interface. The ETOS API applications are designed in a way that a database client shall be easily swapped with any other client which implements this common interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the question is why are we adding delete in the write function. A question I also have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all potential database clients are supposed to conform to io.ReadWriter interface and be swappable, we have no other choice.
The io.ReadWriter interface seems to be more-suitable for a storage like a binary file, but here it requires workarounds to fit it into a key-value pair storage like etcd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather we write a null value into the database rather than having this function do things that it shouldn't do.
If deletion is required then we should have a separate interface for that and in the Stop function cast the database to that interface to see if it is possible to delete.
client := h.database.Open(r.Context(), identifier)
c, canDelete := client.(database.Deleter)
if canDelete {
err := c.Delete()
} else {
_, err = client.Write(nil)
}
} | ||
if len(dbResp.Kvs) == 0 { | ||
err = fmt.Errorf("No key found: %s", key) | ||
logger.Errorf("Failed to look up status request id: %s, %s", identifier, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we really doing a lookup here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line 190 we do a look up by reading from the database.
@@ -22,7 +22,12 @@ import ( | |||
"github.com/google/uuid" | |||
) | |||
|
|||
type DatabaseReadWriter interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only function that needs Delete
is the stop
function which only needs a struct implementing Delete.
Why not just do a DatabaseDelete
interface (or Deleter
) and then do a simple type-case to that interface in the only case we need it?
var err error
client, ok := h.database.Open(r.Context(), identifier).(Deleter)
if !ok {
logger.Warning("the database does not support delete, writing nil")
err = client.Write(nil) // Write a nil value to the database, don't delete.
} else {
err = client.Delete()
}
if err != nil {
// blabla
}
This way our databases don't need to support Delete all the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is better than the suggested interface solution. Your code includes an if-statement in the client, a cast and a warning.
Delete() is reasonable to have for any database as an extension on top of io.ReadWriter which is originally for binary fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct that we add more code with my suggestion.
The casting is not really a problem because it is a check to see whether 'Delete' exists in this database implementation. The warning is not necessary.
The reason I don't want to force all databases to have Delete is because I can see us adding a "FileDatabase" for testing which does not necessarily have the delete capability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one implementation does not support deleting, the Delete() method can be left empty. But generally databases will have some kind of deleting.
Co-authored-by: Fredrik Fristedt <[email protected]>
4525627
to
75a1252
Compare
Applicable Issues
Description of the Change
This change migrates the generic ETOS IUT Provider to the common etcd client of ETOS API.
Alternate Designs
Possible Drawbacks
Sign-off
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Signed-off-by: Andrei Matveyeu, [email protected]