diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-12 23:53:10 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-13 01:36:20 +0200 |
commit | 2b6943f1dd90a4f9457065a06b16d5ad22824625 (patch) | |
tree | abe9e21581a58642c689775c0d052be359f9b97d | |
parent | 5603bc48ca5209c93542bc51229b774c066fb346 (diff) | |
download | sonarqube-2b6943f1dd90a4f9457065a06b16d5ad22824625.tar.gz sonarqube-2b6943f1dd90a4f9457065a06b16d5ad22824625.zip |
SONAR-5007 - Updated IndexActions for compression
6 files changed, 35 insertions, 29 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java index 0c1f263f084..155214d5cc0 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java @@ -254,21 +254,21 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple protected void enqueueUpdate(Object nestedItem, K key, DbSession session) { if (hasIndex()) { session.enqueue(new EmbeddedIndexAction<K>( - this.getIndexType(), IndexAction.Method.UPSERT, nestedItem, key)); + this.getIndexType(), IndexAction.Method.UPSERT, key, nestedItem)); } } public void enqueueDelete(Object nestedItem, K key, DbSession session) { if (hasIndex()) { session.enqueue(new EmbeddedIndexAction<K>( - this.getIndexType(), IndexAction.Method.DELETE, nestedItem, key)); + this.getIndexType(), IndexAction.Method.DELETE, key, nestedItem)); } } public void enqueueInsert(Object nestedItem, K key, DbSession session) { if (hasIndex()) { session.enqueue(new EmbeddedIndexAction<K>( - this.getIndexType(), IndexAction.Method.UPSERT, nestedItem, key)); + this.getIndexType(), IndexAction.Method.UPSERT, key, nestedItem)); } } } 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 aa05a8bda44..4965e8c92e4 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 @@ -434,18 +434,18 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial @Override - public void upsert(Object obj, KEY key) throws Exception { + public void upsert(KEY key, Object object, Object... objects) throws Exception { long t0 = System.currentTimeMillis(); - List<UpdateRequest> requests = this.normalizer.normalizeNested(obj, key); + List<UpdateRequest> requests = this.normalizer.normalizeNested(object, key); long t1 = System.currentTimeMillis(); this.updateDocument(requests, key); long t2 = System.currentTimeMillis(); LOG.debug("UPSERT [object] time:{}ms ({}ms normalize, {}ms elastic)", - t2-t0, t1-t0, t2-t1); + t2 - t0, t1 - t0, t2 - t1); } @Override - public void upsertByDto(DTO item) { + public void upsertByDto(DTO item, DTO... items) { try { long t0 = System.currentTimeMillis(); List<UpdateRequest> request = normalizer.normalize(item); @@ -453,7 +453,7 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial this.updateDocument(request, item.getKey()); long t2 = System.currentTimeMillis(); LOG.debug("UPSERT [dto] time:{}ms ({}ms normalize, {}ms elastic)", - t2-t0, t1-t0, t2-t1); + t2 - t0, t1 - t0, t2 - t1); } catch (Exception e) { LOG.error("Could not update document for index {}: {}", this.getIndexName(), e.getMessage(), e); @@ -461,7 +461,7 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial } @Override - public void upsertByKey(KEY key) { + public void upsertByKey(KEY key, KEY... keys) { try { this.updateDocument(normalizer.normalize(key), key); } catch (Exception e) { @@ -481,13 +481,13 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial } @Override - public void delete(Object obj, KEY key) throws Exception { + public void delete(KEY key, Object object, Object... objects) throws Exception { LOG.debug("DELETE NESTED _id:{} in index {}", key, this.getIndexName()); - this.updateDocument(this.normalizer.deleteNested(obj, key), key); + this.updateDocument(this.normalizer.deleteNested(object, key), key); } @Override - public void deleteByKey(KEY key) { + public void deleteByKey(KEY key, KEY... keys) { try { this.deleteDocument(key); } catch (Exception e) { @@ -497,7 +497,7 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial } @Override - public void deleteByDto(DTO item) { + public void deleteByDto(DTO item, DTO... items) { try { this.deleteDocument(item.getKey()); } catch (Exception e) { diff --git a/sonar-server/src/main/java/org/sonar/server/search/Index.java b/sonar-server/src/main/java/org/sonar/server/search/Index.java index 6426da1a8b9..716cddc6158 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/Index.java +++ b/sonar-server/src/main/java/org/sonar/server/search/Index.java @@ -39,17 +39,17 @@ public interface Index<DOMAIN, DTO extends Dto<KEY>, KEY extends Serializable> e void refresh(); - void upsert(Object obj, KEY key) throws Exception; + void upsert(KEY key, Object object, Object... objects) throws Exception; - void upsertByKey(KEY key); + void upsertByKey(KEY key, KEY... keys); - void upsertByDto(DTO dto); + void upsertByDto(DTO dto, DTO... dtos); - void delete(Object obj, KEY key) throws Exception; + void delete(KEY key, Object object, Object... objects) throws Exception; - void deleteByKey(KEY key); + void deleteByKey(KEY key, KEY... keys); - void deleteByDto(DTO dto); + void deleteByDto(DTO dto, DTO... dtos); Date getLastSynchronization(); diff --git a/sonar-server/src/main/java/org/sonar/server/search/action/DtoIndexAction.java b/sonar-server/src/main/java/org/sonar/server/search/action/DtoIndexAction.java index d6d6eb2a952..7215bdd47f5 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/action/DtoIndexAction.java +++ b/sonar-server/src/main/java/org/sonar/server/search/action/DtoIndexAction.java @@ -24,10 +24,12 @@ import org.sonar.core.persistence.Dto; public class DtoIndexAction<E extends Dto> extends IndexAction { private final E item; + private final E[] items; - public DtoIndexAction(String indexType, Method method, E item) { + public DtoIndexAction(String indexType, Method method, E item, E... items) { super(indexType, method); this.item = item; + this.items = items; } @Override @@ -44,9 +46,9 @@ public class DtoIndexAction<E extends Dto> extends IndexAction { public void doExecute() { try { if (this.getMethod().equals(Method.DELETE)) { - index.deleteByDto(this.item); + index.deleteByDto(this.item, this.items); } else if (this.getMethod().equals(Method.UPSERT)) { - index.upsertByDto(this.item); + index.upsertByDto(this.item, this.items); } } catch (Exception e) { throw new IllegalStateException(this.getClass().getSimpleName() + diff --git a/sonar-server/src/main/java/org/sonar/server/search/action/EmbeddedIndexAction.java b/sonar-server/src/main/java/org/sonar/server/search/action/EmbeddedIndexAction.java index cdbccfcbd85..728ea8ece6c 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/action/EmbeddedIndexAction.java +++ b/sonar-server/src/main/java/org/sonar/server/search/action/EmbeddedIndexAction.java @@ -23,15 +23,17 @@ import java.io.Serializable; public class EmbeddedIndexAction<K extends Serializable> extends IndexAction { - private final Object item; private final K key; + private final Object item; + private final Object[] items; - public EmbeddedIndexAction(String indexType, Method method, Object item, K key) { + public EmbeddedIndexAction(String indexType, Method method, K key, Object item, Object... items) { super(indexType, method); this.indexType = indexType; this.method = method; this.key = key; this.item = item; + this.items = items; } @Override @@ -49,9 +51,9 @@ public class EmbeddedIndexAction<K extends Serializable> extends IndexAction { try { if (this.getMethod().equals(Method.DELETE)) { - index.delete(this.item, this.key); + index.delete(this.key, this.item, this.items); } else if (this.getMethod().equals(Method.UPSERT)) { - index.upsert(this.item, this.key); + index.upsert(this.key, this.item, this.items); } } catch (Exception e) { throw new IllegalStateException(this.getClass().getSimpleName() + diff --git a/sonar-server/src/main/java/org/sonar/server/search/action/KeyIndexAction.java b/sonar-server/src/main/java/org/sonar/server/search/action/KeyIndexAction.java index 69ef59caf2d..4a77140df78 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/action/KeyIndexAction.java +++ b/sonar-server/src/main/java/org/sonar/server/search/action/KeyIndexAction.java @@ -24,10 +24,12 @@ import java.io.Serializable; public class KeyIndexAction<K extends Serializable> extends IndexAction { private final K key; + private final K[] keys; - public KeyIndexAction(String indexType, Method method, K key) { + public KeyIndexAction(String indexType, Method method, K key, K... keys) { super(indexType, method); this.key = key; + this.keys = keys; } @Override @@ -44,9 +46,9 @@ public class KeyIndexAction<K extends Serializable> extends IndexAction { public void doExecute() { try { if (this.getMethod().equals(Method.DELETE)) { - index.deleteByKey(this.key); + index.deleteByKey(this.key, this.keys); } else if (this.getMethod().equals(Method.UPSERT)) { - index.upsertByKey(this.key); + index.upsertByKey(this.key, this.keys); } } catch (Exception e) { throw new IllegalStateException(this.getClass().getSimpleName() + |