From e393f426049d239366c78a12b4a8e4a46cac13c9 Mon Sep 17 00:00:00 2001 From: laa Date: Wed, 4 Nov 2015 21:57:35 +0200 Subject: [PATCH] Issue with index reload was fixed. --- .../core/index/OIndexManagerShared.java | 119 +++++++----------- .../sql/parser/OrientSqlTreeConstants.java | 2 +- 2 files changed, 46 insertions(+), 75 deletions(-) mode change 100644 => 100755 core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTreeConstants.java diff --git a/core/src/main/java/com/orientechnologies/orient/core/index/OIndexManagerShared.java b/core/src/main/java/com/orientechnologies/orient/core/index/OIndexManagerShared.java index 427e487bbc0..227bf7f4aa0 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/index/OIndexManagerShared.java +++ b/core/src/main/java/com/orientechnologies/orient/core/index/OIndexManagerShared.java @@ -59,12 +59,11 @@ * @author Luca Garulli (l.garulli--at--orientechnologies.com) * @author Artem Orobets added composite index managemement */ -@SuppressFBWarnings("EQ_DOESNT_OVERRIDE_EQUALS") -public class OIndexManagerShared extends OIndexManagerAbstract { - private static final long serialVersionUID = 1L; +@SuppressFBWarnings("EQ_DOESNT_OVERRIDE_EQUALS") public class OIndexManagerShared extends OIndexManagerAbstract { + private static final long serialVersionUID = 1L; - protected volatile transient Thread recreateIndexesThread = null; - private volatile boolean rebuildCompleted = false; + protected volatile transient Thread recreateIndexesThread = null; + private volatile boolean rebuildCompleted = false; public OIndexManagerShared(final ODatabaseDocument iDatabase) { super(iDatabase); @@ -83,18 +82,12 @@ public OIndex getIndexInternal(final String name) { /** * Create a new index with default algorithm. * - * @param iName - * - name of index - * @param iType - * - index type. Specified by plugged index factories. - * @param indexDefinition - * metadata that describes index structure - * @param clusterIdsToIndex - * ids of clusters that index should track for changes. - * @param progressListener - * listener to track task progress. - * @param metadata - * document with additional properties that can be used by index engine. + * @param iName - name of index + * @param iType - index type. Specified by plugged index factories. + * @param indexDefinition metadata that describes index structure + * @param clusterIdsToIndex ids of clusters that index should track for changes. + * @param progressListener listener to track task progress. + * @param metadata document with additional properties that can be used by index engine. * @return a newly created index instance */ public OIndex createIndex(final String iName, final String iType, final OIndexDefinition indexDefinition, @@ -107,20 +100,13 @@ public OIndex createIndex(final String iName, final String iType, final OInde *

* May require quite a long time if big amount of data should be indexed. * - * @param iName - * name of index - * @param type - * index type. Specified by plugged index factories. - * @param indexDefinition - * metadata that describes index structure - * @param clusterIdsToIndex - * ids of clusters that index should track for changes. - * @param progressListener - * listener to track task progress. - * @param metadata - * document with additional properties that can be used by index engine. - * @param algorithm - * tip to an index factory what algorithm to use + * @param iName name of index + * @param type index type. Specified by plugged index factories. + * @param indexDefinition metadata that describes index structure + * @param clusterIdsToIndex ids of clusters that index should track for changes. + * @param progressListener listener to track task progress. + * @param metadata document with additional properties that can be used by index engine. + * @param algorithm tip to an index factory what algorithm to use * @return a newly created index instance */ public OIndex createIndex(final String iName, String type, final OIndexDefinition indexDefinition, @@ -163,8 +149,8 @@ public OIndex createIndex(final String iName, String type, final OIndexDefini } // decide which cluster to use ("index" - for automatic and "manindex" for manual) - final String clusterName = indexDefinition != null && indexDefinition.getClassName() != null ? defaultClusterName - : manualClusterName; + final String clusterName = + indexDefinition != null && indexDefinition.getClassName() != null ? defaultClusterName : manualClusterName; index = OIndexes.createIndex(getDatabase(), iName, type, algorithm, valueContainerAlgorithm, metadata, -1); if (progressListener == null) @@ -251,8 +237,7 @@ public OIndexManager dropIndex(final String iIndexName) { /** * Binds POJO to ODocument. */ - @Override - public ODocument toStream() { + @Override public ODocument toStream() { acquireExclusiveLock(); try { document.setInternalStatus(ORecordElement.STATUS.UNMARSHALLING); @@ -276,8 +261,7 @@ public ODocument toStream() { } } - @Override - public void recreateIndexes() { + @Override public void recreateIndexes() { acquireExclusiveLock(); try { if (recreateIndexesThread != null && recreateIndexesThread.isAlive()) @@ -307,8 +291,7 @@ public void recreateIndexes() { } } - @Override - public void waitTillIndexRestore() { + @Override public void waitTillIndexRestore() { if (recreateIndexesThread != null && recreateIndexesThread.isAlive()) { if (Thread.currentThread().equals(recreateIndexesThread)) return; @@ -338,8 +321,7 @@ public boolean autoRecreateIndexesAfterCrash() { return false; } - @Override - protected void fromStream() { + @Override protected void fromStream() { acquireExclusiveLock(); try { final Map> oldIndexes = new HashMap>(indexes); @@ -355,40 +337,32 @@ protected void fromStream() { while (indexConfigurationIterator.hasNext()) { final ODocument d = indexConfigurationIterator.next(); try { - final int indexVersion = d.field(OIndexInternal.INDEX_VERSION) == null ? 1 : (Integer) d - .field(OIndexInternal.INDEX_VERSION); + final int indexVersion = + d.field(OIndexInternal.INDEX_VERSION) == null ? 1 : (Integer) d.field(OIndexInternal.INDEX_VERSION); - OIndexInternal.IndexMetadata newIndexMetadata = OIndexAbstract.loadMetadataInternal(d, - (String) d.field(OIndexInternal.CONFIG_TYPE), (String) d.field(OIndexInternal.ALGORITHM), - d. field(OIndexInternal.VALUE_CONTAINER_ALGORITHM)); + OIndexInternal.IndexMetadata newIndexMetadata = OIndexAbstract + .loadMetadataInternal(d, (String) d.field(OIndexInternal.CONFIG_TYPE), (String) d.field(OIndexInternal.ALGORITHM), + d.field(OIndexInternal.VALUE_CONTAINER_ALGORITHM)); - index = OIndexes.createIndex(getDatabase(), newIndexMetadata.getName(), newIndexMetadata.getType(), - newIndexMetadata.getAlgorithm(), newIndexMetadata.getValueContainerAlgorithm(), - (ODocument) d.field(OIndexInternal.METADATA), indexVersion); + index = OIndexes + .createIndex(getDatabase(), newIndexMetadata.getName(), newIndexMetadata.getType(), newIndexMetadata.getAlgorithm(), + newIndexMetadata.getValueContainerAlgorithm(), (ODocument) d.field(OIndexInternal.METADATA), indexVersion); final String normalizedName = newIndexMetadata.getName().toLowerCase(locale); - OIndex oldIndex = oldIndexes.get(normalizedName); + OIndex oldIndex = oldIndexes.remove(normalizedName); if (oldIndex != null) { OIndexInternal.IndexMetadata oldIndexMetadata = oldIndex.getInternal().loadMetadata(oldIndex.getConfiguration()); - if (oldIndexMetadata.equals(newIndexMetadata)) { - addIndexInternal(oldIndex.getInternal()); - oldIndexes.remove(normalizedName); - } else if (newIndexMetadata.getIndexDefinition() == null) { - // index is manual and index definition was just detected - addIndexInternal(oldIndex.getInternal()); - oldIndexes.remove(normalizedName); - } else { - oldIndex.delete(); - if (index.loadFromConfiguration(d)) { - addIndexInternal(index); - } else { - indexConfigurationIterator.remove(); - configUpdated = true; - } + if (!(oldIndexMetadata.equals(newIndexMetadata) || newIndexMetadata.getIndexDefinition() == null)) { + oldIndex.delete(); + } - oldIndex.remove(normalizedName); + if (index.loadFromConfiguration(d)) { + addIndexInternal(index); + } else { + indexConfigurationIterator.remove(); + configUpdated = true; } } else { if (index.loadFromConfiguration(d)) { @@ -474,16 +448,15 @@ public void removeClassPropertyIndex(final OIndex idx) { private class RecreateIndexesTask implements Runnable { private final ODatabaseDocumentTx newDb; private final ODocument doc; - private int ok; - private int errors; + private int ok; + private int errors; public RecreateIndexesTask(ODatabaseDocumentTx newDb, ODocument doc) { this.newDb = newDb; this.doc = doc; } - @Override - public void run() { + @Override public void run() { try { setUpDatabase(); @@ -557,10 +530,8 @@ private void createAutomaticIndex(ODocument idx, OIndexInternal index, OIndex OLogManager.instance().info(this, "Rebuild of '%s index was successfully finished", indexName); } else { errors++; - OLogManager.instance().error( - this, - "Information about index was restored incorrectly, following data were loaded : " - + "index name '%s', index definition '%s', clusters %s, type %s", indexName, indexDefinition, clusters, type); + OLogManager.instance().error(this, "Information about index was restored incorrectly, following data were loaded : " + + "index name '%s', index definition '%s', clusters %s, type %s", indexName, indexDefinition, clusters, type); } } diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTreeConstants.java b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTreeConstants.java old mode 100644 new mode 100755 index 92b1058a478..93e3f6e5692 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTreeConstants.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/parser/OrientSqlTreeConstants.java @@ -266,4 +266,4 @@ public interface OrientSqlTreeConstants "BothPathItemOpt", }; } -/* JavaCC - OriginalChecksum=c5338e42d6f24a56a0a9087a4d005721 (do not edit this line) */ +/* JavaCC - OriginalChecksum=a3e0cc7fab0bee6c2c464e2f30420e63 (do not edit this line) */