dynamoid
dynamoid copied to clipboard
changed namespacing does not work if a global secondary index is defined on a table
I've implemented a sharded scheme for our DynamoDB setup. The logic is as follows:
...figure out what shard our data is in...
Dynamoid.configure do |config| config.namespace = "shard name" end
...query tables...
This works perfectly in the development environment. On the production environment it works for any table that does not have a global secondary index and fails for the others.
Ouch. I am doing the same thing for sharding (one shard for each environment). However I only use tables with global secondary index, so I suppose I haven't seen this issue. Can you create a failing spec?
@gsampathkumar @pboling - I was facing the same problem and tried reproducing the problem by creating a failing spec, but it's not a problem in the specs with/without dummy Index.
Then I looked at my own code closer and found this:
The class method global_secondary_index must be called after namespace has been defined. Otherwise the namespace definition will not be take effect.
For my case, I simply needed to make sure of that by carefully checking and ordering my require statements (I'm creating an rails_event_store repository for dynamoid)
As for you, it is probably working in development environment and not in production because the classes are loaded eagerly in production.
I'd say this is not a bug of dynamoid (although it should be mentioned in the docs as a caveat).
@andrykonchin Additionally, I am still seeing this in the readme:
find_all_by_secondary_index(
{
dynamo_primary_key_column_name => dynamo_primary_key_value
}, # The signature of find_all_by_secondary_index is ugly, so must be an explicit hash here
:range => {
"#{range_column}.#{range_modifier}" => range_value
},
# false is the same as DESC in SQL (newest timestamp first)
# true is the same as ASC in SQL (oldest timestamp first)
scan_index_forward: false # or true
)
I was under the impression that method had been removed/deprecated in 3.0.0 just released. Have I misunderstood?
@pboling Yeah, you are right. Nice catch.
@andrykonchin That is literally the only method I use in the gem, so I need to figure out how to migrate my code.
@pboling I re-checked specs for find_all_by_secondary_index and can confirm that it could be completely replaced with where and other chained methods.
There is only one subtle difference in selecting of index because where fallbacks to Scan if cannot use Query with or without index but find_all_by_secondary_index raises exception.
You can find examples of replacing find_all_by_secondary_index with where here:
https://gist.github.com/andrykonchin/423ef436b580eede5949bf2f930af788
@fleshins You'll need this if/when you upgrade to Dynamoid v3!