yiisoft / yii2-elasticsearch

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

the cluster does not work alway get first node。。 #303

Closed fuzongtang closed 3 years ago

fuzongtang commented 3 years ago

always get first node。。。

What steps will reproduce the problem?

What's expected?

What do you get instead?

Additional info

Q A
Yii version
PHP version
Operating system
yii-bot commented 3 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

fuzongtang commented 3 years ago
'elasticsearch' => [
            'class' => 'yii\\elasticsearch\\Connection',
            'nodes' => [
                ['http_address' => '172.17.129.190:9200'],
                ['http_address' => '172.17.129.179:9200'],

                // configure more hosts if you have a cluster
            ],
            // set autodetectCluster to false if you don't want to auto detect nodes
            'autodetectCluster' => true,
            'dslVersion' => 5, // default is 5
        ],

When the first node hangs up, the system reports an error。

Elasticsearch Database Exception – yii\elasticsearch\Exception
Elasticsearch request failed: 7 - Failed to connect to 172.17.129.190 port 9200: Connection refused
Error Info: Array
(
    [requestMethod] => GET
    [requestUrl] => http://172.17.129.190:9200/_nodes/_all/http
    [requestBody] => 
    [responseHeaders] => Array
        (
        )

    [responseBody] => 
)

So have to make sure that the first node works ? Won't the cluster switch automatically?

fuzongtang commented 3 years ago
'elasticsearch' => [
            'class' => 'yii\\elasticsearch\\Connection',
            'nodes' => [
                ['http_address' => '172.17.129.190:9200'],
                ['http_address' => '172.17.129.179:9200'],

                // configure more hosts if you have a cluster
            ],
            // set autodetectCluster to false if you don't want to auto detect nodes
            'autodetectCluster' => true,
            'dslVersion' => 5, // default is 5
        ],

When the first node hangs up, the system reports an error。

Elasticsearch Database Exception – yii\elasticsearch\Exception
Elasticsearch request failed: 7 - Failed to connect to 172.17.129.190 port 9200: Connection refused
Error Info: Array
(
    [requestMethod] => GET
    [requestUrl] => http://172.17.129.190:9200/_nodes/_all/http
    [requestBody] => 
    [responseHeaders] => Array
        (
        )

    [responseBody] => 
)

So have to make sure that the first node works ? Won't the cluster switch automatically?

@knut @samdark @yii-bot @nergal

bizley commented 3 years ago

Please don't call out people like that, it's not Twitter. As far as I can see in the code node must reply with non-500 status to switch to a different one. I'm not sure why it's like that since it would be logical to skip it as well. I'm not expert in ES though.

beowulfenator commented 3 years ago

This is the expected behavior. If the extension retried connections to different nodes, this would be a debugging nightmare. If you need that kind of behavior, set up a coordinator node in your cluster:

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#coordinating-only-node

fuzongtang commented 3 years ago

This is the expected behavior. If the extension retried connections to different nodes, this would be a debugging nightmare. If you need that kind of behavior, set up a coordinator node in your cluster:

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#coordinating-only-node

If so, what is the point of cluster configuration?

'nodes' => [
                ['http_address' => '172.17.129.190:9200'],
                ['http_address' => '172.17.129.179:9200'],

                // configure more hosts if you have a cluster
            ],