@Override public void stop() { if (bulkRequest.numberOfActions() > 0) { executeBulk(); } try { if (semaphore.tryAcquire(concurrentRequests, 10, TimeUnit.MINUTES)) { semaphore.release(concurrentRequests); } } catch (InterruptedException e) { throw new IllegalStateException( "Elasticsearch bulk requests still being executed after 10 minutes", e); } progress.stop(); if (!disableRefresh) { client.prepareRefresh(indexName).get(); } if (large) { // optimize lucene segments and revert index settings // Optimization must be done before re-applying replicas: // http://www.elasticsearch.org/blog/performance-considerations-elasticsearch-indexing/ client.prepareForceMerge(indexName).get(); updateSettings(largeInitialSettings); } bulkRequest = null; }
@Override public void start() { Preconditions.checkState(bulkRequest == null, ALREADY_STARTED_MESSAGE); if (large) { largeInitialSettings = Maps.newHashMap(); Map<String, Object> bulkSettings = Maps.newHashMap(); GetSettingsResponse settingsResp = client.nativeClient().admin().indices().prepareGetSettings(indexName).get(); // deactivate replicas int initialReplicas = Integer.parseInt( settingsResp.getSetting(indexName, IndexMetaData.SETTING_NUMBER_OF_REPLICAS)); if (initialReplicas > 0) { largeInitialSettings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, initialReplicas); bulkSettings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0); } // deactivate periodical refresh String refreshInterval = settingsResp.getSetting(indexName, REFRESH_INTERVAL_SETTING); largeInitialSettings.put(REFRESH_INTERVAL_SETTING, refreshInterval); bulkSettings.put(REFRESH_INTERVAL_SETTING, "-1"); updateSettings(bulkSettings); } bulkRequest = client.prepareBulk().setRefresh(false); counter.set(0L); progress.start(); }