worryg0d commented on code in PR #1793:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1793#discussion_r1937157549
##########
session.go:
##########
@@ -1430,6 +1435,22 @@ func (q *Query) releaseAfterExecution() {
q.decRefCount()
}
+// SetHostID allows to define on which host the query should be executed.
+// If hostID is not set, then the HostSelectionPolicy will be used to pick a
host.
+// It is recommended to get host id from HostInfo.HostID(), but it is not
required.
+// It is strongly recommended to use WithContext() with this option because
+// if the specified host goes down during execution, the driver will try to
send the query to this host until it succeeds
+// which may lead to an endless execution.
+func (q *Query) SetHostID(hostID string) *Query {
+ q.hostID = hostID
Review Comment:
I spent some time thinking about this more and I'm +1 on what @jameshartig
says. We at least should have a way to restore `Query.hostID` to default.
If `SetHostID` takes `*string` it is available, but this makes UX of this
API way worse IMO. I don't like the idea of creating vars to hold some strings
and pass a pointer to them. However, if API is `SetHostID(string)` there is no
way to restore its behavior to default. Once `SetHostID()` is used, it can't be
changed. Ofc we can expose API `Query.Default()` to restore this behavior, but
this becomes something very odd to me.
All of this is based on the case when we want to copy the existing `Query`
and somehow modify it, but I'm unsure how this matches query immutability. By
this do we understand that once the `Query` obj is created it can't be
modified? Either it means that the driver doesn't modify `Query` internally
during its execution? As far as I know, gocql writes some metrics to the query
obj.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]