From 605d2ad539c8962454b3ec35874b3222326eabb0 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 4 Jul 2014 09:28:18 +0200 Subject: [PATCH] SONAR-5007 - Fix date-synch for ES Synchronizer when date == null (initial start) --- .../src/main/java/org/sonar/server/rule/db/RuleDao.java | 2 +- .../src/main/java/org/sonar/server/search/BaseIndex.java | 7 ++++--- .../java/org/sonar/server/search/IndexSynchronizer.java | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java b/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java index c7cd45ef14a..f1476dafc5b 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java @@ -35,7 +35,6 @@ import org.sonar.server.search.action.IndexAction; import org.sonar.server.search.action.KeyIndexAction; import javax.annotation.CheckForNull; - import java.sql.Timestamp; import java.util.Date; import java.util.List; @@ -103,6 +102,7 @@ public class RuleDao extends BaseDao { RuleKey.of(map.get("repoField"), map.get("ruleField")))); } }); + session.commit(); } /** diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java index fda4682574a..abd9c742e70 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java @@ -211,10 +211,11 @@ public abstract class BaseIndex, KEY extends Serial SearchResponse response = request.get(); Max max = (Max) response.getAggregations().get("latest"); - if (Double.isNaN(max.getValue())) { - date = new Date(0L); - } else { + + if (max.getValue() > 0) { date = new DateTime(Double.valueOf(max.getValue()).longValue()).toDate(); + } else { + date = new Date(0L); } LOG.info("Index {}:{} has last update of {}", this.getIndexName(), this.getIndexType(), date); diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java b/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java index 0bb354aa314..18c0490a438 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java +++ b/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java @@ -52,7 +52,7 @@ public class IndexSynchronizer { synchronize(session, db.activeRuleDao(), index.get(ActiveRuleIndex.class)); synchronize(session, db.activityDao(), index.get(ActivityIndex.class)); session.commit(); - LOG.info("Synchronization done in {}ms...", System.currentTimeMillis()-start); + LOG.info("Synchronization done in {}ms...", System.currentTimeMillis() - start); session.close(); } @@ -60,6 +60,5 @@ public class IndexSynchronizer { long start = System.currentTimeMillis(); dao.synchronizeAfter(session, index.getLastSynchronization()); - LOG.info("-- Synchronized {} in {}ms", index.getIndexType(), System.currentTimeMillis() - start); } } -- 2.39.5