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

Re-work connections and connection pool in favor of Node Pool #2188

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `Elastica\Search::setOptionsAndQuery()`
* `Elastica\Index::search()`
* `Elastica\Index::createSearch()`
* Removed classes [#2188](https://github.com/ruflin/Elastica/pull/2188)
* `Elastica\Connection`
* `Elastica\Connection\ConnectionPool`
* `Elastica\Connection\Strategy\CallbackStrategy`
* `Elastica\Connection\Strategy\RoundRobin`
* `Elastica\Connection\Strategy\Simple`
* `Elastica\Connection\Strategy\StrategyFactory`
* `Elastica\Connection\Strategy\StrategyInterface`

### Added
* Added support for PHP 8.2 [#2136](https://github.com/ruflin/Elastica/pull/2136)
Expand All @@ -79,6 +87,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
* Removed the JSONParseException class, which is replaced by \JsonException
* Removed the JSONParseException test class
* Removed `nyholm/dsn` as no longer needed.
* Removed `symfony/deprecation-contracts` as no longer needed.
### Fixed
* Fix types order in `Elastica\Query` to work with psalm & expand the `aggs` type to include raw arrays
### Security
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-json": "*",
"elastic/transport": "^8.4",
"elastic/transport": "^8.8",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since 8.8 elastic/transport supports basic authentication per node. see elastic/elastic-transport-php#22

Copy link
Owner

Choose a reason for hiding this comment

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

I assume even if we use 8.8, Elastica will still be compatible with older versions of Elasticsearch 8.x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

"elasticsearch/elasticsearch": "^8.4.1",
"guzzlehttp/psr7": "^2.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no longer used directly

"nyholm/dsn": "^2.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer needed as we rely on elastic/transport.

"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^3.0"
"psr/log": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.2",
Expand All @@ -31,9 +28,11 @@
"phpunit/phpunit": "^9.5",
"symfony/phpunit-bridge": "^6.0"
},
"conflict": {
"guzzlehttp/psr7": "<2.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have direct dependency to guzzlehttp/psr7 but without this hack --prefer-lowest installs 1.4.0 which doesn't have psr/http-factory and official transport is not able to establish connection (see https://github.com/elastic/elastic-transport-php/blob/main/src/NodePool/Node.php#L33)

Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if there is a way we could add a note around this to the code somewhere. I'm worried someone comes along eventually and removes it and we don't see the side effects immediately. The good news is, that now if someone goes back to where it was introduced, they see these comments.

},
"suggest": {
"aws/aws-sdk-php": "Allow using IAM authentication with Amazon ElasticSearch Service",
"guzzlehttp/guzzle": "Allow using guzzle as transport",
"monolog/monolog": "Logging request"
},
"autoload": {
Expand All @@ -49,11 +48,12 @@
"config": {
"allow-plugins": {
"php-http/discovery": true
}
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "7.0.x-dev"
"dev-master": "8.0.x-dev"
}
}
}
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ parameters:
count: 1
path: tests/ClientFunctionalTest.php

-
message: "#^Parameter \\#1 \\$params of static method Elastica\\\\Connection\\:\\:create\\(\\) expects array\\|Elastica\\\\Connection, string given\\.$#"
count: 1
path: tests/ConnectionTest.php

-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$field1\\.$#"
count: 1
Expand Down
16 changes: 12 additions & 4 deletions src/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ public function getActions(): array
*/
public function addDocument(Document $document, ?string $opType = null): self
{
if (!$document->hasRetryOnConflict() && $this->_client->hasConnection() && $this->_client->getConnection()->hasParam('retryOnConflict') && ($retry = $this->_client->getConnection()->getParam('retryOnConflict')) > 0) {
$document->setRetryOnConflict($retry);
if (!$document->hasRetryOnConflict()) {
$retry = $this->_client->getConfigValue('retryOnConflict', 0);
Copy link
Owner

Choose a reason for hiding this comment

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

Is this directly related to the change? Maybe make it a quick second PR if not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. because Client class doesn't have getConnection method so I had to find another way to get configuration value


if ($retry > 0) {
$document->setRetryOnConflict($retry);
}
}

$action = AbstractDocumentAction::create($document, $opType);
Expand All @@ -161,8 +165,12 @@ public function addDocuments(array $documents, ?string $opType = null): self
*/
public function addScript(AbstractScript $script, ?string $opType = null): self
{
if (!$script->hasRetryOnConflict() && $this->_client->hasConnection() && $this->_client->getConnection()->hasParam('retryOnConflict') && ($retry = $this->_client->getConnection()->getParam('retryOnConflict')) > 0) {
$script->setRetryOnConflict($retry);
if (!$script->hasRetryOnConflict()) {
$retry = $this->_client->getConfigValue('retryOnConflict', 0);

if ($retry > 0) {
$script->setRetryOnConflict($retry);
}
}

$action = AbstractDocumentAction::create($script, $opType);
Expand Down
Loading
Loading