Skip to content

Commit 452baf9

Browse files
committed
Merge pull request #775 from im-denisenko/fix-out-of-memory
Fix out of memory
2 parents b914718 + a03fff2 commit 452baf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+209
-298
lines changed

ansible/provision.sh

+41-11
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,47 @@ fi
3939

4040
# ----------------------------------------------------------------------------
4141

42-
echo 'Waiting for elasticsearch server ready'
43-
elasticsearch_ready() {
44-
http_code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:9200")
45-
return $(test $http_code = "200")
42+
all_nodes_available() {
43+
curl -m 5 -s -o /dev/null "http://localhost:9200" &&
44+
curl -m 5 -s -o /dev/null "http://localhost:9201"
45+
return $?
4646
}
47-
while ! elasticsearch_ready; do
48-
echo -n '.'
49-
sleep 1s
50-
done
5147

52-
# ----------------------------------------------------------------------------
53-
# Say bye
48+
check_cluster() {
49+
restarts_left=$1
50+
seconds_left=$2
51+
52+
if [ $seconds_left -eq 0 ]; then
53+
if [ $restarts_left -eq 0 ]; then
54+
echo "Cluster was restarted 10 times, but still not ready for phpunit. Build failed!"
55+
return 1
56+
else
57+
echo "Restart cluster. Restarts left: $restarts_left"
58+
sudo service elasticsearch restart
59+
check_cluster $(( $restarts_left - 1 )) 30
60+
return $?
61+
fi
62+
else
63+
if all_nodes_available; then
64+
echo "All nodes available. Sleep 30 seconds and try to check them again..."
65+
if sleep 10s && all_nodes_available; then
66+
echo "All nodes still available - cluster ready."
67+
return 0
68+
else
69+
echo "Some nodes were stopped during sleep. Trying cluster restart..."
70+
check_cluster $restarts_left 0
71+
return $?
72+
fi
73+
else
74+
echo "Some nodes still unavailable. Sleep 1 second and try to check them again. Seconds to start left: $seconds_left"
75+
sleep 1s && check_cluster $restarts_left $(( $seconds_left - 1 ))
76+
return $?
77+
fi
78+
fi
79+
}
5480

55-
echo 'Done'
81+
echo "Wait cluster start..."
82+
if ! check_cluster 10 30; then
83+
cat /var/log/elasticsearch/*.log
84+
exit 1
85+
fi

ansible/roles/elasticsearch/tasks/main.yml

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
with_items:
8181
- config-0.yml
8282
- config-1.yml
83-
- config-2.yml
8483
- logging.yml
8584
notify: restart elasticsearch
8685

ansible/roles/elasticsearch/templates/config-2.yml

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
{% block default_config %}
22

3-
#################################### Index ####################################
4-
53
index.number_of_shards: 2
64
index.number_of_replicas: 0
75

8-
#################################### Plugin ###################################
6+
# Dont write data to hdd in tests
7+
index.store.type: memory
98

9+
# Required plugins
1010
plugin.mandatory: mapper-attachments, geocluster-facet, transport-thrift, transport-memcached
1111

12-
################################## UDP ########################################
13-
12+
# For bulk tests
1413
bulk.udp.enabled: true
1514
bulk.udp.bulk_actions: 5
1615

17-
################################## Scripting ##################################
18-
16+
# For script tests
1917
script.disable_dynamic: false
2018

21-
################################### Memory ####################################
22-
19+
# Disable dynamic memory allocation
2320
bootstrap.mlockall: true
2421

22+
# Dont accept connections not from localhost
23+
network.host: "127.0.0.1"
24+
25+
# Limit threadpool by set number of available processors to 1
26+
# Without this, travis builds will be failed with OutOfMemory error
27+
processors: 1
28+
2529
{% endblock %}
2630

27-
################################### Node specific #############################
2831
{% block config %}
29-
32+
# Node specific config should be overwritten in child template
3033
{% endblock %}

ansible/roles/elasticsearch/templates/elasticsearch.service

+6-11
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export ES_JAVA_OPTS
7676
MAX_OPEN_FILES="65535"
7777

7878
# Maximum amount of locked memory
79-
MAX_LOCKED_MEMORY="$ES_HEAP_SIZE"
79+
MAX_LOCKED_MEMORY="unlimited"
8080

8181
# Elasticsearch log directory
8282
LOG_DIR="/var/log/$NAME"
@@ -90,9 +90,6 @@ WORK_DIR="/tmp/$NAME"
9090
# Elasticsearch configuration directory
9191
CONF_DIR="/etc/$NAME"
9292

93-
# Maximum number of VMA (Virtual Memory Areas) a process can own
94-
MAX_MAP_COUNT="262144"
95-
9693
# Define other required variables
9794
DAEMON="$ES_HOME/bin/elasticsearch"
9895

@@ -135,11 +132,9 @@ case "$1" in
135132
ulimit -l $MAX_LOCKED_MEMORY
136133
fi
137134

138-
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ];then
139-
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
140-
fi
135+
ulimit -s 1024
141136

142-
for node in 0 1 2; do
137+
for node in 0 1; do
143138
log_daemon_msg "Starting elasticsearch node #$node"
144139

145140
PID_FILE="/var/run/$NAME-$node.pid"
@@ -184,7 +179,7 @@ case "$1" in
184179
done
185180
;;
186181
stop)
187-
for node in 0 1 2; do
182+
for node in 0 1; do
188183
log_daemon_msg "Stopping elasticsearch node #$node"
189184

190185
PID_FILE="/var/run/$NAME-$node.pid"
@@ -209,14 +204,14 @@ case "$1" in
209204
log_end_msg 0
210205
;;
211206
status)
212-
for node in 0 1 2; do
207+
for node in 0 1; do
213208
PID_FILE="/var/run/$NAME-$node.pid"
214209
status_of_proc -p $PID_FILE "Elasticsearch node #$node" "Elasticsearch node #$node"
215210
done
216211
exit 0
217212
;;
218213
restart|force-reload)
219-
for node in 0 1 2; do
214+
for node in 0 1; do
220215
PID_FILE="/var/run/$NAME-$node.pid"
221216
if [ -f "$PID_FILE" ]; then
222217
$0 stop

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2015-02-11
4+
- Fixed issue with OutOfMemory exception in travis builds
5+
36
2015-01-27
47
- Exception\ElasticsearchException now can be catched like all other exceptions as Exception\ExceptionInterface
58

test/lib/Elastica/Test/Aggregation/AvgTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AvgTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex('avg');
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document('1', array('price' => 5)),
1717
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php

-13
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,4 @@ abstract class BaseAggregationTest extends Base
1111
* @var Index
1212
*/
1313
protected $_index;
14-
15-
protected function tearDown()
16-
{
17-
parent::tearDown();
18-
if ($this->_index instanceof Index) {
19-
$this->_index->delete();
20-
}
21-
}
22-
23-
protected function _createIndex($name = 'test', $delete = true, $shards = 1)
24-
{
25-
return parent::_createIndex('test_aggregation_'.$name, $delete, $shards);
26-
}
2714
}

test/lib/Elastica/Test/Aggregation/CardinalityTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CardinalityTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex("cardinality");
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document("1", array("color" => "blue")),
1717
new Document("2", array("color" => "blue")),

test/lib/Elastica/Test/Aggregation/DateHistogramTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DateHistogramTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex("date_histogram");
15+
$this->_index = $this->_createIndex();
1616
$mapping = new Mapping();
1717
$mapping->setProperties(array(
1818
"created" => array("type" => "date"),

test/lib/Elastica/Test/Aggregation/DateRangeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DateRangeTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex("date_range");
15+
$this->_index = $this->_createIndex();
1616
$mapping = new Mapping();
1717
$mapping->setProperties(array(
1818
"created" => array("type" => "date"),

test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ExtendedStatsTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex("extended_stats");
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document("1", array("price" => 5)),
1717
new Document("2", array("price" => 8)),

test/lib/Elastica/Test/Aggregation/FilterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FilterTest extends BaseAggregationTest
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->_index = $this->_createIndex("filter");
17+
$this->_index = $this->_createIndex();
1818
$docs = array(
1919
new Document("1", array("price" => 5, "color" => "blue")),
2020
new Document("2", array("price" => 8, "color" => "blue")),

test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GeoDistanceTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex("geo_distance");
15+
$this->_index = $this->_createIndex();
1616
$mapping = new Mapping();
1717
$mapping->setProperties(array(
1818
"location" => array("type" => "geo_point"),

test/lib/Elastica/Test/Aggregation/GeohashGridTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GeohashGridTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex("geohash_grid");
15+
$this->_index = $this->_createIndex();
1616
$mapping = new Mapping();
1717
$mapping->setProperties(array(
1818
"location" => array("type" => "geo_point"),

test/lib/Elastica/Test/Aggregation/HistogramTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class HistogramTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex("histogram");
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document("1", array("price" => 5, "color" => "blue")),
1717
new Document("2", array("price" => 8, "color" => "blue")),

test/lib/Elastica/Test/Aggregation/IpRangeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class IpRangeTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex("ip_range");
15+
$this->_index = $this->_createIndex();
1616
$mapping = new Mapping();
1717
$mapping->setProperties(array(
1818
"address" => array("type" => "ip"),

test/lib/Elastica/Test/Aggregation/MaxTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MaxTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex('max');
15+
$this->_index = $this->_createIndex();
1616
$docs = array(
1717
new Document('1', array('price' => 5)),
1818
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/MinTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MinTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex('min');
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document('1', array('price' => 5)),
1717
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/MissingTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MissingTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex('missing');
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document('1', array('price' => 5, "color" => "blue")),
1717
new Document('2', array('price' => 8, "color" => "blue")),

test/lib/Elastica/Test/Aggregation/NestedTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class NestedTest extends BaseAggregationTest
1313
protected function setUp()
1414
{
1515
parent::setUp();
16-
$this->_index = $this->_createIndex("nested");
16+
$this->_index = $this->_createIndex();
1717
$mapping = new Mapping();
1818
$mapping->setProperties(array(
1919
"resellers" => array(

test/lib/Elastica/Test/Aggregation/RangeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RangeTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex('range');
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document('1', array('price' => 5)),
1717
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ReverseNestedTest extends BaseAggregationTest
1414
protected function setUp()
1515
{
1616
parent::setUp();
17-
$this->_index = $this->_createIndex("nested");
17+
$this->_index = $this->_createIndex();
1818
$mapping = new Mapping();
1919
$mapping->setProperties(array(
2020
"comments" => array(

test/lib/Elastica/Test/Aggregation/ScriptTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ScriptTest extends BaseAggregationTest
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$this->_index = $this->_createIndex('script');
15+
$this->_index = $this->_createIndex();
1616
$docs = array(
1717
new Document('1', array('price' => 5)),
1818
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/StatsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class StatsTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex('stats');
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document('1', array('price' => 5)),
1717
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/SumTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SumTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex('sum');
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document('1', array('price' => 5)),
1717
new Document('2', array('price' => 8)),

test/lib/Elastica/Test/Aggregation/TermsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TermsTest extends BaseAggregationTest
1111
protected function setUp()
1212
{
1313
parent::setUp();
14-
$this->_index = $this->_createIndex("terms");
14+
$this->_index = $this->_createIndex();
1515
$docs = array(
1616
new Document("1", array("color" => "blue")),
1717
new Document("2", array("color" => "blue")),

test/lib/Elastica/Test/Aggregation/TopHitsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TopHitsTest extends BaseAggregationTest
1818
public function setUp()
1919
{
2020
parent::setUp();
21-
$this->_index = $this->_createIndex('top_hits_test', true);
21+
$this->_index = $this->_createIndex();
2222

2323
$docs = array(
2424
new Document(1, array(

0 commit comments

Comments
 (0)