]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5531 - Reverted broken fix for refresh
authorStephane Gamard <stephane.gamard@sonarsource.com>
Mon, 22 Sep 2014 15:08:42 +0000 (17:08 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Mon, 22 Sep 2014 15:08:42 +0000 (17:08 +0200)
17 files changed:
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java
server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
server/sonar-server/src/main/java/org/sonar/server/search/Index.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java
server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
server/sonar-server/src/main/java/org/sonar/server/search/action/IndexActionRequest.java
server/sonar-server/src/main/java/org/sonar/server/search/action/IndexWorker.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshActionRequest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueAuthorizationDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/search/IndexSynchronizerMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/tester/BackendCleanup.java
server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
sonar-core/src/main/java/org/sonar/core/cluster/ClusterAction.java
sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java

index c1b3bb4c1507d552682ca794c3913da670654039..1433bd71b6e709f86f50656c6eaa466bc2f9c407 100644 (file)
@@ -88,14 +88,9 @@ public class SearchServer implements Monitored {
       .put("discovery.zen.ping.multicast.enabled", "false")
 
       // Index storage policies
-      .put("index.refresh_interval", "30")
       .put("index.number_of_shards", "1")
       .put("index.number_of_replicas", MINIMUM_INDEX_REPLICATION)
       .put("index.store.type", "mmapfs")
-//      .put("indices.store.throttle.type", "merge")
-//      .put("indices.store.throttle.max_bytes_per_sec", "500mb")
-      .put("index.merge.scheduler.max_thread_count",
-        Math.max(1, Math.min(3, Runtime.getRuntime().availableProcessors() / 2)))
 
       // Install our own listUpdate scripts
       .put("script.default_lang", "native")
index 37cf02a20340de3ebd16578658238120a2b70d29..a87021146bb99efc9a7e4b499cbdb491a6d90b7f 100644 (file)
@@ -34,20 +34,15 @@ import org.sonar.server.search.DbSynchronizationHandler;
 import org.sonar.server.search.IndexDefinition;
 import org.sonar.server.search.action.DeleteKey;
 import org.sonar.server.search.action.DeleteNestedItem;
-import org.sonar.server.search.action.RefreshActionRequest;
 import org.sonar.server.search.action.UpsertDto;
 import org.sonar.server.search.action.UpsertNestedItem;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+
 import java.io.Serializable;
 import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import static com.google.common.collect.Maps.newHashMap;
 
@@ -328,7 +323,7 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
       @Override
       public void handleResult(ResultContext resultContext) {
         DTO dto = (DTO) resultContext.getResultObject();
-        session.enqueue(new UpsertDto<DTO>(getIndexType(), dto, false));
+        session.enqueue(new UpsertDto<DTO>(getIndexType(), dto, true));
         count++;
         if (count % 100000 == 0) {
           LOGGER.info(" - synchronized {} {}", count, getIndexType());
@@ -363,7 +358,6 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
       DbSynchronizationHandler handler = getSynchronizationResultHandler(session);
       session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date, params), handler);
       handler.enqueueCollected();
-      session.enqueue(new RefreshActionRequest(this.getIndexType()));
     } catch (Exception e) {
       throw new IllegalStateException(e);
     }
index 65c73da1ffa240e2289d0418d61a3dc3b99c0beb..6faafd538df6eda512dfbde9fffddb3b130bd51f 100644 (file)
@@ -359,6 +359,16 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
     return mapping;
   }
 
+  @Override
+  public void refresh() {
+    client.execute(client
+      .admin()
+      .indices()
+      .prepareRefresh(this.getIndexName())
+      .setForce(false)
+      .setIndices(this.getIndexName()));
+  }
+
   /* Base CRUD methods */
 
   protected abstract DOMAIN toDoc(Map<String, Object> fields);
index 13acb6a633292bb2885e77337534bc2ebe7710bf..13a7a935c4e78ceebe04b1d6218abdfed42b4bdb 100644 (file)
@@ -38,6 +38,8 @@ public interface Index<DOMAIN, DTO extends Dto<KEY>, KEY extends Serializable> e
 
   String getIndexName();
 
+  void refresh();
+
   Date getLastSynchronization();
 
   IndexStat getIndexStat();
index d548648af5c705fe88abcc8c68828a76eed3ce10..de7636d8596774ab18ec12311927f838e303fa61 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.search;
 
 import org.elasticsearch.action.ActionRequest;
-import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
 import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
 import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
@@ -32,12 +31,9 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.ComponentContainer;
-import org.sonar.core.cluster.ClusterAction;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.profiling.Profiling;
 import org.sonar.server.search.action.IndexActionRequest;
-import org.sonar.server.search.action.IndexWorker;
-import org.sonar.server.search.action.RefreshActionRequest;
 
 import java.util.HashMap;
 import java.util.HashSet;
@@ -73,28 +69,13 @@ public class IndexQueue implements ServerComponent, WorkQueue<IndexActionRequest
     }
     try {
 
-      boolean refreshRequired = false;
-
       Map<String, Index> indexes = getIndexMap();
       Set<String> indices = new HashSet<String>();
-      for (ClusterAction action : actions) {
-        if (IndexActionRequest.class.isAssignableFrom(action.getClass())) {
-          IndexActionRequest worker = (IndexActionRequest) action;
-          if (worker.needsRefresh()) {
-            refreshRequired = true;
-            indices.add(indexes.get(worker.getIndexType()).getIndexName());
-          }
-        }
-
-        if (IndexWorker.class.isAssignableFrom(action.getClass())) {
-          IndexWorker worker = (IndexWorker) action;
-          Index index = indexes.get(worker.getIndexType());
-          worker.setIndex(index);
-        }
-
-        if (RefreshActionRequest.class.isAssignableFrom(action.getClass())) {
-          refreshRequired = true;
-          indices.add(indexes.get(((RefreshActionRequest) action).getIndexType()).getIndexName());
+      for (IndexActionRequest action : actions) {
+        Index index = indexes.get(action.getIndexType());
+        action.setIndex(index);
+        if (action.needsRefresh()) {
+          indices.add(index.getIndexName());
         }
       }
 
@@ -102,30 +83,26 @@ public class IndexQueue implements ServerComponent, WorkQueue<IndexActionRequest
 
       long normTime = executeNormalization(bulkRequestBuilder, actions);
 
-      if (bulkRequestBuilder.numberOfActions() > 0) {
-        // execute the request
-        long indexTime = System.currentTimeMillis();
-        BulkResponse response = searchClient.execute(bulkRequestBuilder.setRefresh(false));
+      //execute the request
+      long indexTime = System.currentTimeMillis();
+      BulkResponse response = searchClient.execute(bulkRequestBuilder.setRefresh(false));
+      indexTime = System.currentTimeMillis() - indexTime;
 
-        indexTime = System.currentTimeMillis() - indexTime;
+      long refreshTime = this.refreshRequiredIndex(indices);
 
-        long refreshTime = 0;
-        if (refreshRequired) {
-          refreshTime = this.refreshRequiredIndex(indices);
-        }
-
-        LOGGER.debug("-- submitted {} items with {}ms in normalization, {}ms indexing and {}ms refresh({}). Total: {}ms",
-          bulkRequestBuilder.numberOfActions(), normTime, indexTime, refreshTime, indices, (normTime + indexTime + refreshTime));
+      LOGGER.debug("-- submitted {} items with {}ms in normalization, {}ms indexing and {}ms refresh({}). Total: {}ms",
+        bulkRequestBuilder.numberOfActions(), normTime, indexTime, refreshTime, indices, (normTime + indexTime + refreshTime));
 
-        if (response.hasFailures()) {
-          throw new IllegalStateException("Errors while indexing stack: " + response.buildFailureMessage());
-        }
+      if (response.hasFailures()) {
+        throw new IllegalStateException("Errors while indexing stack: " + response.buildFailureMessage());
       }
+
     } catch (Exception e) {
       LOGGER.error("Could not commit to ElasticSearch", e);
     }
   }
 
+
   private long refreshRequiredIndex(Set<String> indices) {
 
     long refreshTime = System.currentTimeMillis();
@@ -146,24 +123,20 @@ public class IndexQueue implements ServerComponent, WorkQueue<IndexActionRequest
   private long executeNormalization(BulkRequestBuilder bulkRequestBuilder, List<IndexActionRequest> actions) {
     long normTime = System.currentTimeMillis();
     try {
-      boolean hasInlineRefreshRequest = false;
       ExecutorService executorService = Executors.newFixedThreadPool(CONCURRENT_NORMALIZATION_FACTOR);
-      // invokeAll() blocks until ALL tasks submitted to executor complete
+      //invokeAll() blocks until ALL tasks submitted to executor complete
       for (Future<List<ActionRequest>> updateRequests : executorService.invokeAll(actions)) {
         for (ActionRequest update : updateRequests.get()) {
           if (UpdateRequest.class.isAssignableFrom(update.getClass())) {
-            bulkRequestBuilder.add(((UpdateRequest) update));
+            bulkRequestBuilder.add(((UpdateRequest) update).refresh(false));
           } else if (DeleteRequest.class.isAssignableFrom(update.getClass())) {
-            bulkRequestBuilder.add(((DeleteRequest) update));
-          } else if (RefreshRequest.class.isAssignableFrom(update.getClass())) {
-            hasInlineRefreshRequest = true;
+            bulkRequestBuilder.add(((DeleteRequest) update).refresh(false));
           } else {
             throw new IllegalStateException("Un-managed request type: " + update.getClass());
           }
         }
       }
       executorService.shutdown();
-      bulkRequestBuilder.setRefresh(hasInlineRefreshRequest);
     } catch (Exception e) {
       throw new IllegalStateException("Could not execute normalization for stack", e);
     }
index 6cea28ad8d554d6065d063da5a375da91634ccba..4c8b26f4baea47fa32aa45140c70b693e45c8c2f 100644 (file)
@@ -41,8 +41,6 @@ import org.sonar.core.profiling.Profiling;
 import org.sonar.core.profiling.StopWatch;
 import org.sonar.process.LoopbackAddress;
 
-import java.io.File;
-
 /**
  * ElasticSearch Node used to connect to index.
  */
@@ -128,9 +126,4 @@ public class SearchClient extends TransportClient implements Startable {
   public void stop() {
     close();
   }
-
-  public File executePayload(File f) {
-
-    return new File("payload");
-  }
 }
index 940316d82d86e9a96ccd2e3d5a04f0cfb2767b77..8eb540df4a62331eb3ef60e95aa2cc639bf5184a 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.search.action;
 
+
 import org.elasticsearch.action.ActionRequest;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.core.cluster.ClusterAction;
@@ -27,7 +28,7 @@ import org.sonar.server.search.Index;
 import java.util.ArrayList;
 import java.util.List;
 
-public abstract class IndexActionRequest implements IndexWorker, ClusterAction<ActionRequest> {
+public abstract class IndexActionRequest implements ClusterAction<List<ActionRequest>> {
 
   protected final String indexType;
   private final boolean requiresRefresh;
@@ -38,6 +39,7 @@ public abstract class IndexActionRequest implements IndexWorker, ClusterAction<A
   }
 
   protected IndexActionRequest(String indexType, boolean requiresRefresh) {
+    super();
     this.indexType = indexType;
     this.requiresRefresh = requiresRefresh;
   }
@@ -50,6 +52,7 @@ public abstract class IndexActionRequest implements IndexWorker, ClusterAction<A
     return indexType;
   }
 
+
   public void setIndex(Index index) {
     this.index = index;
   }
@@ -65,7 +68,7 @@ public abstract class IndexActionRequest implements IndexWorker, ClusterAction<A
         ((UpdateRequest) request)
           .type(index.getIndexType())
           .index(index.getIndexName())
-          .refresh(requiresRefresh);
+          .refresh(false);
       }
       finalRequests.add(request);
     }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexWorker.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexWorker.java
deleted file mode 100644 (file)
index 42989b6..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.search.action;
-
-import org.sonar.server.search.Index;
-
-public interface IndexWorker {
-
-  public String getIndexType();
-
-  public void setIndex(Index index);
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshActionRequest.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshActionRequest.java
deleted file mode 100644 (file)
index 0fa0393..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.search.action;
-
-import com.google.common.collect.ImmutableList;
-import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
-import org.sonar.core.cluster.ClusterAction;
-import org.sonar.server.search.Index;
-
-import java.util.List;
-
-public class RefreshActionRequest implements IndexWorker, ClusterAction<RefreshRequest> {
-
-  private Index<?, ?, ?> index;
-  private final String indexType;
-
-  public RefreshActionRequest(String indexType) {
-    this.indexType = indexType;
-  }
-
-  @Override
-  public List<RefreshRequest> call() throws Exception {
-    return ImmutableList.<RefreshRequest>of(
-      new RefreshRequest()
-        .force(false)
-        .indices(index.getIndexName()));
-  }
-
-  @Override
-  public String getIndexType() {
-    return indexType;
-  }
-
-  @Override
-  public void setIndex(Index index) {
-    this.index = index;
-  }
-}
index 5c760965c2a3066262628d8f0a2a54477a133155..e20aea655835b047f118c54b54e06f095adc515b 100644 (file)
@@ -115,12 +115,9 @@ public class ActivityBackendMediumTest {
   @Test
   public void massive_insert() {
 
-    // Set qeue's implicit commit size to 10
-    dbSession.setImplicitCommitSize(20);
-
     // 0 Assert no logs in DB
     assertThat(dao.findAll(dbSession)).hasSize(0);
-    int max = 35;
+    int max = 400;
     final String testValue = "hello world";
     for (int i = 0; i < max; i++) {
 
@@ -159,12 +156,9 @@ public class ActivityBackendMediumTest {
   @Test
   public void massive_log_insert() {
 
-    // Set qeue's implicit commit size to 10
-    dbSession.setImplicitCommitSize(10);
-
     // 0 Assert no logs in DB
     assertThat(dao.findAll(dbSession)).hasSize(0);
-    int max = 40;
+    int max = 400;
     final String testValue = "hello world";
     for (int i = 0; i < max; i++) {
       TestActivityLog log = new TestActivityLog(testValue + "_" + i, Activity.Type.QPROFILE.toString());
index c4b354193b7f0c208b532f643a1475ebfe936018..5ee795cb6e60e649d75a9d61451d09d843dc3ab7 100644 (file)
@@ -117,7 +117,6 @@ public class BaseDaoTest {
     assertThat(session.getActionCount()).isEqualTo(1);
 
     dao.synchronizeAfter(session, new Date(t0));
-    // Synchronize adds an implicit action to the queue before finishing.
-    assertThat(session.getActionCount()).isEqualTo(3);
+    assertThat(session.getActionCount()).isEqualTo(2);
   }
 }
index aedf757c64f53cc4e03b2e49f45c8535667850c4..0b8a8c988c4ad5f654475e0f6a150859c4e02da3 100644 (file)
@@ -61,8 +61,8 @@ public class IssueAuthorizationDaoTest extends AbstractDaoTestCase {
     assertThat(session.getActionCount()).isEqualTo(0);
 
     dao.synchronizeAfter(session, new Date(0));
-    // SynchronizeAfter adds an implicit action (refresh) after execution of synchronization
-    assertThat(session.getActionCount()).isEqualTo(2);
+
+    assertThat(session.getActionCount()).isEqualTo(1);
   }
 
   @Test
@@ -70,8 +70,7 @@ public class IssueAuthorizationDaoTest extends AbstractDaoTestCase {
     setupData("synchronize_after_since_given_date");
 
     dao.synchronizeAfter(session, DateUtils.parseDate("2014-09-01"));
-    // SynchronizeAfter adds an implicit action (refresh) after execution of synchronization
-    assertThat(session.getActionCount()).isEqualTo(2);
+    assertThat(session.getActionCount()).isEqualTo(1);
   }
 
   @Test
@@ -79,8 +78,7 @@ public class IssueAuthorizationDaoTest extends AbstractDaoTestCase {
     setupData("synchronize_after_with_project");
 
     dao.synchronizeAfter(session, DateUtils.parseDate("2014-01-01"), ImmutableMap.of(IssueAuthorizationDao.PROJECT_KEY, "org.sonar:sample"));
-    // SynchronizeAfter adds an implicit action (refresh) after execution of synchronization
-    assertThat(session.getActionCount()).isEqualTo(2);
+    assertThat(session.getActionCount()).isEqualTo(1);
   }
 
 }
index 7c95432a00cff4f6c957659b245b99fe93edf21a..1e31323634384c4c5f01492ef14c1927c39c5a39 100644 (file)
@@ -78,7 +78,6 @@ public class IndexSynchronizerMediumTest {
 
     synchronizer.synchronize(dbSession, dbClient.ruleDao(), indexClient.get(RuleIndex.class));
     dbSession.commit();
-    Thread.sleep(1000);
     assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(numberOfRules);
   }
 }
index cfb22cb7eb41ac79857e5b1754ba785022bf2325..cb79ed6d56952d8c3e8cef3977ebf3b68f81026b 100644 (file)
@@ -67,12 +67,6 @@ public class BackendCleanup implements ServerComponent {
       .getState().getMetaData().concreteAllIndices())
       .setQuery(QueryBuilders.matchAllQuery())
       .get();
-    searchClient.admin().indices().prepareRefresh(searchClient.admin().cluster().prepareState().get()
-      .getState().getMetaData().concreteAllIndices())
-      .setForce(true)
-      .get();
-    searchClient.admin().indices().prepareFlush(searchClient.admin().cluster().prepareState().get()
-      .getState().getMetaData().concreteAllIndices())
-      .get();
+
   }
 }
index 9f884aea4658d4bf26c81bcab52200140d1072f9..43ef301e1f678b2abbd12c2f1c897699bbb32b69 100644 (file)
@@ -192,7 +192,6 @@ public class ServerTester extends ExternalResource {
   public void clearIndexes() {
     checkStarted();
     get(BackendCleanup.class).clearIndexes();
-
   }
 
   /**
index 13aac68b2e13f8a4d4d47067af20dfe0513a1940..bac9518865f8c2a357b4bfcc196769108e18179a 100644 (file)
  */
 package org.sonar.core.cluster;
 
-import java.util.List;
 import java.util.concurrent.Callable;
 
-public interface ClusterAction<K> extends Callable<List<K>> {
+public interface ClusterAction<K> extends Callable<K> {
 
   @Override
-  public List<K> call() throws Exception;
+  public K call() throws Exception;
 }
index 2bca0acee02b4df2e6455581af0529455d266f8e..3ca049d44eec88186d02e66951e257779cf79a6c 100644 (file)
@@ -41,8 +41,6 @@ public class DbSession implements SqlSession {
   private SqlSession session;
   private int actionCount;
 
-  private Integer implicitCommitSize = IMPLICIT_COMMIT_SIZE;
-
   DbSession(WorkQueue queue, SqlSession session) {
     this.actionCount = 0;
     this.session = session;
@@ -50,18 +48,10 @@ public class DbSession implements SqlSession {
     this.actions = new ArrayList<ClusterAction>();
   }
 
-  public Integer getImplicitCommitSize() {
-    return implicitCommitSize;
-  }
-
-  public void setImplicitCommitSize(Integer implicitCommitSize) {
-    this.implicitCommitSize = implicitCommitSize;
-  }
-
   public void enqueue(ClusterAction action) {
     actionCount++;
     this.actions.add(action);
-    if (this.actions.size() > getImplicitCommitSize()) {
+    if (this.actions.size() > IMPLICIT_COMMIT_SIZE) {
       this.commit();
     }
   }