-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add option to control if remote replicas should be used #202
Add option to control if remote replicas should be used #202
Conversation
I send it as a draft to discuss it, because changing default behavior is not something to do lightly for sure. Also I went with the behavior similar to rust driver not java or python-driver, that also can be discussed. |
@sylwiaszunejko , thansk for PR, one question:
|
My intention was to specify it only at the beginning as in other drivers. I wanted to add this option to the constructor, but in golang there is no option to specify default value for an argument and I didn't want to do API breaking changes by adding extra parameter in https://github.com/scylladb/gocql/blob/master/policies.go#L960 |
Let's than implement it in a different way that won't polute
|
I wanted to do it that way initially, but I was wondering if changing |
It won't be breaking change, let me show you. |
@dkropachev What is your opinion about changing the default behavior regarding using remote hosts? |
a358d40
to
ac748fa
Compare
ac748fa
to
9724d07
Compare
@dkropachev something went wrong with your push, there are unnecessary commits, if I should fix something please let me know, I will fix it |
I would classify it as breaking change, it is better to avoid that by defaulting to old behavior. |
9724d07
to
7339ae1
Compare
I am sorry for doing it, could you please push your version of the branch again |
90add8e
to
64d83f5
Compare
v2:
|
policies.go
Outdated
type dcAwarePolicyOption func(p dcFailoverEnabledPolicy) | ||
|
||
func HostPolicyOptionEnableDCFailover(p dcFailoverEnabledPolicy) { | ||
p.setDCFailoverEnabled() |
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.
Let's change meaning of it on opposite (and name as well) to do not change default behavior.
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 already pushed code with the changes
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.
thanks, but underlying variable did not change it's name and also let's make it's value as false
by default and to be changed to true
via this option
policies.go
Outdated
} | ||
|
||
func (d *dcAwareRR) setDCFailoverDisabled() { | ||
d.permitDCFailover = false |
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.
d.permitDCFailover = false | |
d.disableDCFailover = true |
policies.go
Outdated
@@ -1067,6 +1094,10 @@ func (d *rackAwareRR) MaxHostTier() uint { | |||
return 2 | |||
} | |||
|
|||
func (d *rackAwareRR) setDCFailoverDisabled() { | |||
d.permitDCFailover = false |
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.
d.permitDCFailover = false | |
d.disableDCFailover = true |
policies.go
Outdated
if d.permitDCFailover { | ||
return roundRobbin(int(nextStartOffset), d.hosts[0].get(), d.hosts[1].get(), d.hosts[2].get()) | ||
} else { | ||
return roundRobbin(int(nextStartOffset), d.hosts[0].get(), d.hosts[1].get()) | ||
} | ||
|
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 d.permitDCFailover { | |
return roundRobbin(int(nextStartOffset), d.hosts[0].get(), d.hosts[1].get(), d.hosts[2].get()) | |
} else { | |
return roundRobbin(int(nextStartOffset), d.hosts[0].get(), d.hosts[1].get()) | |
} | |
if d.disableDCFailover { | |
return roundRobbin(int(nextStartOffset), d.hosts[0].get(), d.hosts[1].get()) | |
} | |
return roundRobbin(int(nextStartOffset), d.hosts[0].get(), d.hosts[1].get(), d.hosts[2].get()) |
policies.go
Outdated
if d.permitDCFailover { | ||
return roundRobbin(int(nextStartOffset), d.localHosts.get(), d.remoteHosts.get()) | ||
} else { | ||
return roundRobbin(int(nextStartOffset), d.localHosts.get()) | ||
} | ||
|
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 d.permitDCFailover { | |
return roundRobbin(int(nextStartOffset), d.localHosts.get(), d.remoteHosts.get()) | |
} else { | |
return roundRobbin(int(nextStartOffset), d.localHosts.get()) | |
} | |
if d.disableDCFailover { | |
return roundRobbin(int(nextStartOffset), d.localHosts.get()) | |
} | |
return roundRobbin(int(nextStartOffset), d.localHosts.get(), d.remoteHosts.get()) |
Previously the driver would always failover to use replicas in the remote datacenters if there was no replicas available in local_dc when using DC/RackAwareRoundRobinPolicy. There was no control over it. This is not how the other driver handle it. This commit adds a option to dc/rackAwareRR to control if dc failover is permitted. The default stays the same (use remote datacenter).
64d83f5
to
0241281
Compare
I added a simple test |
Please re-request review from me once it gets stable and not draft. |
The default behavior is something we should consider. On the other hand, just introducing the option "quietly", existing users won't notice it and it requires them to actively change it. I wonder what other maintainers think about it. |
This is how I see this.
Having made this decision, it will guide us in multiple similar dilemmas: to break with good intentions or to preserve old behaviour. |
My personal opinion would be to keep gocql a maintained-only driver, with no breaking changes, and instead develop the Scylla Go driver, which has good design from the very beginning (inspired by the Rust driver) and would promote good practices. |
You mean https://github.com/scylladb/scylla-go-driver ? |
I'm in favor of no. 2. |
Availability? I thought the discussion was about changing the default to prevent sending requests to other DCs, as is the default in other drivers? Isn't that decreasing availability? |
I know that upstream maintainers were also thinking of v2 and looked at scylladb/scylla-go-driver as a base for it. |
It would defnitely be good to cooperate instead of having forks. |
Previously, there was no control for it. Now there is, and we are considering what the default should be. I'm in favor of ALLOWING sending requests to other DCs. I think the default in other drivers is wrong. |
@mykaul That's exactly what the code in this PR does so far. The default behavior is the same as it was without controlling mechanism, but we have the control available. And this option is in fact in line with @wprzytula approach of not doing breaking changes. |
Just to make sure, if we leave the default as is, the user would have the exact same issue as they had when pointing the wrong DC name without ability to tell. |
True, to fail if the wrong DC is provided they would have to use |
Previously the driver would always failover to use replicas in the remote datacenters if there was no replicas available in local_dc when using
DC/RackAwareRoundRobinPolicy
. There was no control over it. This is not how the other driver handle it.In python-driver there is an additional field in the
DCAwareRoundRobinPolicy
namedused_hosts_per_remote_dc
and it is 0 by default.In java-driver 4.x there is also similar mechanism as in python-driver, there is a field
usedHostsPerRemoteDc
.In rust driver there is
permit_dc_failover
option in theDefaultPolicy
. If it is set to true driver can use replicas in dcs other than local. By default it is false.This PR adds a field to
dc/rackAwareRR
to control if dc failover is permitted. To avoid breaking changes I decided not to change the default behavior.Refs: #201 <- this issue is about wrong dc name in
DCAwareRoundRobinPolicy
, but the difference in gocql behavior in that case originates in handling remote replicas by default.