Skip to content

Commit

Permalink
Issue with index reload was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Nov 4, 2015
1 parent 42cb968 commit e393f42
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 75 deletions.
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -107,20 +100,13 @@ public OIndex<?> createIndex(final String iName, final String iType, final OInde
* <p>
* 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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -276,8 +261,7 @@ public ODocument toStream() {
}
}

@Override
public void recreateIndexes() {
@Override public void recreateIndexes() {
acquireExclusiveLock();
try {
if (recreateIndexesThread != null && recreateIndexesThread.isAlive())
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -338,8 +321,7 @@ public boolean autoRecreateIndexesAfterCrash() {
return false;
}

@Override
protected void fromStream() {
@Override protected void fromStream() {
acquireExclusiveLock();
try {
final Map<String, OIndex<?>> oldIndexes = new HashMap<String, OIndex<?>>(indexes);
Expand All @@ -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.<String> field(OIndexInternal.VALUE_CONTAINER_ALGORITHM));
OIndexInternal.IndexMetadata newIndexMetadata = OIndexAbstract
.loadMetadataInternal(d, (String) d.field(OIndexInternal.CONFIG_TYPE), (String) d.field(OIndexInternal.ALGORITHM),
d.<String>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)) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}

Expand Down
Expand Up @@ -266,4 +266,4 @@ public interface OrientSqlTreeConstants
"BothPathItemOpt",
};
}
/* JavaCC - OriginalChecksum=c5338e42d6f24a56a0a9087a4d005721 (do not edit this line) */
/* JavaCC - OriginalChecksum=a3e0cc7fab0bee6c2c464e2f30420e63 (do not edit this line) */

0 comments on commit e393f42

Please sign in to comment.