ribaraka commented on code in PR #1793:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1793#discussion_r1939552755


##########
session.go:
##########
@@ -949,6 +950,10 @@ type Query struct {
 
        // routingInfo is a pointer because Query can be copied and copyable 
struct can't hold a mutex.
        routingInfo *queryRoutingInfo
+
+       // hostID specifies the host on which the query should be executed.
+       // If it is empty, then the host is picked by HostSelectionPolicy
+       hostID string

Review Comment:
   how about `queryTargetHostId` or `targetHostID`?



##########
session.go:
##########
@@ -1442,6 +1447,23 @@ 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.
+// Setting hostID to empty restores behavior to default.
+func (q *Query) SetHostID(hostID string) *Query {
+       q.hostID = hostID
+       return q
+}
+
+// GetHostID returns id of the host on which query should be executed.
+func (q *Query) GetHostID() string {

Review Comment:
   I'd name this method `GetTargetHostId` to make it more specific.



##########
cassandra_test.go:
##########
@@ -3347,3 +3346,53 @@ func TestQuery_NamedValues(t *testing.T) {
                t.Fatal(err)
        }
 }
+
+func TestQuery_SetHostID(t *testing.T) {
+       // This test ensures that queries are sent to the specified host only

Review Comment:
   nitpick: It might be better to keep comments above the test function to 
clearly describe its overall purpose.



##########
session.go:
##########
@@ -1442,6 +1447,23 @@ 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.
+// Setting hostID to empty restores behavior to default.
+func (q *Query) SetHostID(hostID string) *Query {
+       q.hostID = hostID
+       return q
+}
+
+// GetHostID returns id of the host on which query should be executed.
+func (q *Query) GetHostID() string {

Review Comment:
   If you like it, then `SetTargetHostID` might be changed as well :smile: 



##########
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:
   If `HostFilter` is causing issues, consider mentioning it in the 
documentation. For example: '`SetHostID` will not work on filtered nodes (i.e., 
nodes excluded by `ClusterConfig.HostFilter`)



-- 
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]

Reply via email to