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

HC k8s patches #130

Closed
wants to merge 10 commits into from
Closed

HC k8s patches #130

wants to merge 10 commits into from

Conversation

jacobat
Copy link
Contributor

@jacobat jacobat commented Oct 5, 2017

This set of patches tighten up what the possible states are for the shard selection. This is done according to the fail-fast principle where we would rather know immediately if something is in a weird state.

Warning: This is a breaking change so we may want a new major release for this

@jacobat jacobat requested review from grosser and bquorning October 5, 2017 11:13
Copy link
Contributor

@grosser grosser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable :)

if options.key?(:shard)
unless config = configurations[shard_env]
raise "Did not find #{shard_env} in configurations, did you forget to add it to your database.yml ? (configurations: #{configurations.inspect})"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe say database config instead of database.yml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the wording in 2 places.

@bquorning
Copy link
Member

We need to at least make the tests pass.

unless config = configurations[shard_env]
raise "Did not find #{shard_env} in configurations, did you forget to add it to your database config ? (configurations: #{configurations.inspect})"
end
unless shard = config['shard_names'].include?(options[:shard])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shard variable is not being used, is it?

@bquorning
Copy link
Member

I can only get the migrations to run if I change ActiveRecordShards::Model.is_sharded? to return false for ActiveRecord::Base. @jacobat could you try running rake test locally and see if you can reproduce this problem?

The problem is that #connection_specification_name returns e.g. "test_shard_0" instead of "primary" for ActiveRecord::Base.

else
@shard || self.class.default_shard
end
if klass.nil? || klass.is_sharded?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don’t like klass being nil, perhaps we should change the method signature?

Copy link
Member

@bquorning bquorning Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah… as long as @shard is set, it works fine.

Also, this is Rails 4 code. Let’s just leave it…

It does not make sense to have a default shard so we're removing this
We don't want to have a "selection" where nothing is selected as that may cause
weird issues. For instance it may result in not being able to get the schema of
sharded tables.
If we're using ARS we expect shards to be configured. We don't want to silently
fail in case the configuration is missing.
If we're missing configuration we raise an exception at the point we discover
the missing configuration. This is to avoid accidentally calling .shard= with
nil.
We move the state manipulating on_slave= call to after we check that we're
actually able to perform the shard switch. Otherwise we may accidentally update
state and then see an exception leaving us in an inconsistent state.
When selecting a new shard the user should always select a shard. It does not
make sense to select NO_SHARD. With this change we only allow integer names for
shards.
When we ask for the shard we must ensure that we do have a shard selected.
We are no longer exclusively using yml for config. Update the wording of the
error message to reflect this.
@jacobat
Copy link
Contributor Author

jacobat commented Oct 12, 2017

Superceded by #136

@jacobat jacobat closed this Oct 12, 2017
@jacobat jacobat deleted the jacobat/hc-k8s branch October 12, 2017 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants