yiisoft / yii2-elasticsearch

Yii 2 Elasticsearch extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
427 stars 253 forks source link

ElasticSearch Connection fallback #58

Open yii-bot opened 8 years ago

yii-bot commented 8 years ago

This issue has originally been reported by @chuntley at https://github.com/yiisoft/yii2/issues/6377. Moved here by @cebe.


With ElasticSearch you can connect to any query against any node on the cluster. The way the Yii's ElasticSearch connection is setup you set an array of IP addresses of the nodes in your cluster, then Yii randomly chooses a server to connect to then begins running commands against it.

          'nodes' => [
                ['http_address' => '10.111.55.50:9200'],
                ['http_address' => '10.111.55.51:9200'],
                ['http_address' => '10.111.55.52:9200'],
                ['http_address' => '10.111.55.53:9200'],
                ['http_address' => '10.111.55.54:9200'],
                ['http_address' => '10.111.55.55:9200'],
                ['http_address' => '10.111.55.56:9200'],
            ]

This is great, however ElasticSearch is designed to allow servers to fail on the cluster gracefully while others take over that server's responsibilities. Yii could randomly select a failed server, then report back that it is unable to connect to ElasticSearch. However this is not true, as any of the other servers in the connection string would be alive and active.

It would be a great addition to have Yii continue to try all nodes in the connection string before sending back a failure.

beowulfenator commented 8 years ago

This is not the typical use case.

Generally, a new node is set up at localhost. This node is part of the cluster, but does not store any data and never appoints itself master (the so-called client node). This local node forwards all requests to the cluster. The cluster is smart enough to handle failures of its data nodes.

chuntley commented 8 years ago

Default Elasticsearch nodes are setup to act as data, master-eligible, and client nodes. Smaller clusters are not likely to dedicate a machine as a client node, that generally happens when traffic and data needs get much larger. Even at that point, it is likely that several client nodes will be setup to handle the incoming traffic / result parsing. which this enhancement would solve for.

beowulfenator commented 8 years ago

This will hopefully be fixed by PR #104