-
Notifications
You must be signed in to change notification settings - Fork 195
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
ESConfig: configurable Elasticsearch document types to allow splitting index #1296
Conversation
9a8d1f1
to
04fc747
Compare
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.
😅
@@ -0,0 +1,219 @@ | |||
use v5.20; | |||
use warnings; | |||
use experimental qw(signatures postderef); |
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.
👍🏻
mapping => 'MetaCPAN::Script::Mapping::CPAN::Release', | ||
model => 'MetaCPAN::Document::Release', | ||
}, | ||
|
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.
Stray newline. Doesn't really matter.
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.
This was an intentional separation between the "public" and "private" data. Could use a comment if it's going to remain.
{ | ||
use Moo; | ||
} |
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.
Why is this in its own block?
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.
Moo, like Moose, applies use warnings
, which re-enables experimental warnings.
3969b01
to
7917166
Compare
Centralize Elasticsearch configuration in MetaCPAN::ESConfig. Allow overridden values from the main config file. This module is not meant to have any behavior aside from holding the configuration.
ESConfig knows how to find mapping data. Use it to find the mapping data as well as index configuration. The mapping data should be able to be moved into json files rather than json wrapped in a module. This can happen in the future.
The analysis set in MetaCPAN::Model wasn't used for anything directly, generate the index deployment statements. The index settings we actually use lives in MetaCPAN::Script::Mapping::DeployStatement, so the declarations in MetaCPAN::Model were used for nothing.
Rather than searching for modules on disk, use the explicit configuration in ESConfig to configure MetaCPAN::Model.
ElasticSearchX::Model ignores all errors in a ::Set package can't be loaded, and uses a generic ElasticSearchX::Model::Document::Set object. It's fine for the module to be missing, but compilation errors should be reported.
PPI and thus Perl::Critic don't understand signatures, so the rule ends up prohibiting signatures as well
Allows getting a "type" object from a document name rather than needing to specify an index and type.
Previously when trying to refresh indices, scripts would call $self->index->refresh. This would refresh the "currently used" index. That doesn't make any sense when splitting each type into its own index. This was also using ElasticSearchX::Model, which we want to get rid of. Instead, call ->indices->refresh via the Search::Elasticsearch object. This will refresh all indices, which is fine for our purposes. In the future, we could consider being more selective about which indices we are refreshing, but this is no worse than the old behavior.
Rather than using the same index to find other types, find them via the model. This means the types don't need to be in the same index.
Many parts of the code treated the index as the parent of all data, so it was the thing being passed around. That will no be true in the future. Instead, ESConfig can give the path (index+type) of each named document type. Convert most places passing around index to use es_doc_path.
Replaces the CPAN and User model classes. Removes magic namespace creation. Just return the Search::Elasticsearch object, or the model object.
Trying to count distribution documents before creating is vulnerable to concurrency and consistency issues. Instead, use an upsert to create it.
We have two autocomplete end points. The old one is no longer used by the front end. The new one uses the suggest API. Rewrite both end points to use the suggest SPI, just returning data in different forms.
Older versions expect the key "inline", newer expect "source".
use_dis_max is the default, and isn't supported in newer versions
Updated with various tweaks, fixes, and compatibility fixes for newer Elasticsearch. This will now pass the tests using Elasticsearch 2 and Elasticsearch 5. It also works using either one index, or splitting the documents into separate indices. With some updates to the mappings, it will also pass tests on Elasticsearch 6. |
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.
😅
This adds a central module to configure all of the document types stored in Elasticsearch, allowing a config file to override values. It then adapts the rest of the code to use this module.
In the past, everything stored in Elasticsearch was stored in one index, with multiple types. Initially this was the
cpan
index, but later this was changed to usingcpan_v1_01
withcpan
being an alias. The idea was that we could have different versions of the index on the same server, and copy or switch between them. The index used would be passed around the code, acting as a single configurable value that would impact all document types. Some newer document types have been stored in separate indexes, but not all parts of the codebase accommodate this well.Going forward, we want every document type to be in a separate index. Initially this will be one type per index. Eventually, types will go away entirely. This is required to upgrade Elasticsearch. To facilitate this, this PR adds a new module
MetaCPAN::ESConfig
which lists all of the document types and which index and type they are using. These values can be overridden in the config file, meaning we can switch to a different Elasticsearch instance where the documents are stored in different places just by deploying a new config file.Everything that was previously holding a ElasticSearchX::Model index instance has been updated to instead use the ElasticSearchX::Model instance directly. The new
$model->doc($doc_type)
method is a replacement for$index->type($type)
, allowing accessing types that are in different indexes.Everything that was previously using a copied index name with a fixed type (often like
$es->search(index => $self->index->name, 'file')
) is now using the newes_doc_path
sub (like$es->search(es_doc_path('file'))
). This seemed the easiest way to integrate this throughout the codebase.There is a new
Catalyst::Model
namedESModel
. This replaces both theCPAN
andUser
models. It allows access to MetaCPAN::Model, and thus everything using ElasticSearchX::Model. TheCPAN
vsUser
split was related to the index their data was stored in, and is thus no longer relevant. The new model has less magic as well.Fixes #1297