Skip to content

Commit

Permalink
Hacky way to avoid block on metadata check while elastic/elasticsearc…
Browse files Browse the repository at this point in the history
…h#9203 is open
  • Loading branch information
jdeniau committed Jan 21, 2015
1 parent 4b5e827 commit 07b56f6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/Elastica/Index/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Elastica\Index;

use Elastica\Exception\NotFoundException;
use Elastica\Exception\ResponseException;
use Elastica\Index as BaseIndex;
use Elastica\Request;

Expand Down Expand Up @@ -171,15 +172,26 @@ public function setBlocksWrite($state = true)
{
$state = $state ? 1 : 0;

return $this->set(array('blocks.write' => (int) $state));
return $this->set(array('blocks.write' => $state));
}

/**
* @return bool
*/
public function getBlocksMetadata()
{
return (bool) $this->get('blocks.metadata');
// TODO will have to be replace by block.metadata.write once https://github.com/elasticsearch/elasticsearch/pull/9203 has been fixed
// the try/catch will have to be remove too
try {
return (bool) $this->get('blocks.metadata');
} catch (ResponseException $e) {
if (strpos($e->getMessage(), 'ClusterBlockException') !== false) {
// hacky way to test if the metadata is blocked since bug 9203 is not fixed
return true;
} else {
throw $e;
}
}
}

/**
Expand All @@ -188,9 +200,10 @@ public function getBlocksMetadata()
*/
public function setBlocksMetadata($state = true)
{
// TODO will have to be replace by block.metadata.write once https://github.com/elasticsearch/elasticsearch/pull/9203 has been fixed
$state = $state ? 1 : 0;

return $this->set(array('blocks.metadata' => (int) $state));
return $this->set(array('blocks.metadata' => $state));
}

/**
Expand Down

0 comments on commit 07b56f6

Please sign in to comment.