Skip to content

Commit

Permalink
Issue #4089 is fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed May 21, 2015
1 parent eda3685 commit c44bbca
Show file tree
Hide file tree
Showing 27 changed files with 322 additions and 352 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,17 @@

/**
* Abstract index definiton implementation.
*
*
* @author Luca Garulli (l.garulli--at--orientechnologies.com)
*
*/
public abstract class OAbstractIndexDefinition extends ODocumentWrapperNoClass implements OIndexDefinition {
protected OCollate collate = new ODefaultCollate();
private boolean nullValuesIgnored = true;
private int version = -1;
protected OCollate collate = new ODefaultCollate();
private boolean nullValuesIgnored = true;

protected OAbstractIndexDefinition() {
super(new ODocument());
}

public OAbstractIndexDefinition(int version) {
super(new ODocument());

this.version = version;
}

public OCollate getCollate() {
return collate;
}
Expand Down Expand Up @@ -98,18 +90,10 @@ public void setNullValuesIgnored(boolean value) {
nullValuesIgnored = value;
}

@Override
public int getVersion() {
return version;
}

protected void serializeToStream() {
document.field("version", version);
}

protected void serializeFromStream() {
final Integer ver = document.field("version");
if (ver != null)
version = ver;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public abstract class OAbstractIndexDefinitionMultiValue extends OPropertyIndexD
protected OAbstractIndexDefinitionMultiValue() {
}

protected OAbstractIndexDefinitionMultiValue(final String iClassName, final String iField, final OType iType, int version) {
super(iClassName, iField, iType, version);
protected OAbstractIndexDefinitionMultiValue(final String iClassName, final String iField, final OType iType) {
super(iClassName, iField, iType);
}

protected void processAdd(final Object value, final Map<Object, Integer> keysToAdd, final Map<Object, Integer> keysToRemove) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public OCompositeIndexDefinition() {
* - name of class which is owner of this index
*/
public OCompositeIndexDefinition(final String iClassName, int version) {
super(version);
super();

indexDefinitions = new ArrayList<OIndexDefinition>(5);
className = iClassName;
Expand All @@ -72,7 +72,7 @@ public OCompositeIndexDefinition(final String iClassName, int version) {
* List of indexDefinitions to add in given index.
*/
public OCompositeIndexDefinition(final String iClassName, final List<? extends OIndexDefinition> iIndexes, int version) {
super(version);
super();

indexDefinitions = new ArrayList<OIndexDefinition>(5);
for (OIndexDefinition indexDefinition : iIndexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import java.util.HashSet;
import java.util.Set;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.engine.OSBTreeIndexEngine;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage;

/**
* Default OrientDB index factory for indexes based on MVRBTree.<br>
Expand Down Expand Up @@ -94,19 +92,21 @@ public Set<String> getAlgorithms() {
}

public OIndexInternal<?> createIndex(ODatabaseDocumentInternal database, String indexType, String algorithm,
String valueContainerAlgorithm, ODocument metadata) throws OConfigurationException {
String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException {
if (valueContainerAlgorithm == null)
valueContainerAlgorithm = NONE_VALUE_CONTAINER;
if (version < 0)
version = getLastVersion();

if (SBTREE_ALGORITHM.equals(algorithm))
return createSBTreeIndex(indexType, valueContainerAlgorithm, metadata, (OAbstractPaginatedStorage) database.getStorage()
.getUnderlying());
.getUnderlying(), version);

throw new OConfigurationException("Unsupported type : " + indexType);
}

private OIndexInternal<?> createSBTreeIndex(String indexType, String valueContainerAlgorithm, ODocument metadata,
OAbstractPaginatedStorage storage) {
OAbstractPaginatedStorage storage, int version) {
Boolean durableInNonTxMode;

Object durable = null;
Expand All @@ -122,16 +122,16 @@ private OIndexInternal<?> createSBTreeIndex(String indexType, String valueContai

if (OClass.INDEX_TYPE.UNIQUE.toString().equals(indexType)) {
return new OIndexUnique(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine<OIdentifiable>(durableInNonTxMode, storage,
getLastVersion()), valueContainerAlgorithm, metadata);
version), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.NOTUNIQUE.toString().equals(indexType)) {
return new OIndexNotUnique(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine<Set<OIdentifiable>>(durableInNonTxMode,
storage, getLastVersion()), valueContainerAlgorithm, metadata);
storage, version), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.FULLTEXT.toString().equals(indexType)) {
return new OIndexFullText(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine<Set<OIdentifiable>>(durableInNonTxMode,
storage, getLastVersion()), valueContainerAlgorithm, metadata);
storage, version), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.DICTIONARY.toString().equals(indexType)) {
return new OIndexDictionary(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine<OIdentifiable>(durableInNonTxMode, storage,
getLastVersion()), valueContainerAlgorithm, metadata);
version), valueContainerAlgorithm, metadata);
}

throw new OConfigurationException("Unsupported type : " + indexType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@

import com.orientechnologies.common.concur.lock.OModificationLock;
import com.orientechnologies.common.concur.lock.ONewLockManager;
import com.orientechnologies.common.concur.resource.OSharedResourceAdaptiveExternal;
import com.orientechnologies.common.listener.OProgressListener;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.serialization.types.OLongSerializer;
import com.orientechnologies.orient.core.annotation.ODocumentInstance;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
Expand Down Expand Up @@ -61,46 +58,45 @@

/**
* Handles indexing when records change.
*
*
* @author Luca Garulli
*
*/
public abstract class OIndexAbstract<T> implements OIndexInternal<T> {
protected static final String CONFIG_MAP_RID = "mapRid";
protected static final String CONFIG_CLUSTERS = "clusters";
protected final OModificationLock modificationLock = new OModificationLock();
protected final OIndexEngine<T> indexEngine;
private final String databaseName;
protected String type;
protected String valueContainerAlgorithm;
protected final ONewLockManager<Object> keyLockManager = new ONewLockManager<Object>();
protected static final String CONFIG_MAP_RID = "mapRid";
protected static final String CONFIG_CLUSTERS = "clusters";
protected final OModificationLock modificationLock = new OModificationLock();
protected final OIndexEngine<T> indexEngine;
private final String databaseName;
protected String type;
protected String valueContainerAlgorithm;
protected final ONewLockManager<Object> keyLockManager = new ONewLockManager<Object>();

@ODocumentInstance
protected ODocument configuration;
protected ODocument metadata;
private String name;
private String algorithm;
private Set<String> clustersToIndex = new HashSet<String>();
protected ODocument configuration;
protected ODocument metadata;
private String name;
private String algorithm;
private Set<String> clustersToIndex = new HashSet<String>();

private volatile OIndexDefinition indexDefinition;
private volatile boolean rebuilding = false;
private volatile OIndexDefinition indexDefinition;
private volatile boolean rebuilding = false;

private Thread rebuildThread = null;
private Thread rebuildThread = null;

private final ThreadLocal<IndexTxSnapshot> txSnapshot = new IndexTxSnapshotThreadLocal();
private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
private final ThreadLocal<IndexTxSnapshot> txSnapshot = new IndexTxSnapshotThreadLocal();
private final ReadWriteLock rwLock = new ReentrantReadWriteLock();

protected static final class RemovedValue {
public static final RemovedValue INSTANCE = new RemovedValue();
}

protected static final class IndexTxSnapshot {
public Map<Object, Object> indexSnapshot = new HashMap<Object, Object>();
public boolean clear = false;
public boolean clear = false;
}

public OIndexAbstract(final String type, String algorithm, final OIndexEngine<T> indexEngine, String valueContainerAlgorithm,
ODocument metadata) {
ODocument metadata) {
acquireExclusiveLock();
try {
databaseName = ODatabaseRecordThreadLocal.INSTANCE.get().getName();
Expand All @@ -117,7 +113,7 @@ public OIndexAbstract(final String type, String algorithm, final OIndexEngine<T>
}

public static IndexMetadata loadMetadataInternal(final ODocument config, final String type, final String algorithm,
final String valueContainerAlgorithm) {
final String valueContainerAlgorithm) {
String indexName = config.field(OIndexInternal.CONFIG_NAME);

final ODocument indexDefinitionDoc = config.field(OIndexInternal.INDEX_DEFINITION);
Expand Down Expand Up @@ -157,7 +153,7 @@ public static IndexMetadata loadMetadataInternal(final ODocument config, final S
throw new OIndexException("Can not convert from old index model to new one. " + "Index key type is absent.");
final OType keyType = OType.valueOf(keyTypeStr.toUpperCase(Locale.ENGLISH));

loadedIndexDefinition = new OPropertyIndexDefinition(className, propertyName, keyType, factory.getLastVersion());
loadedIndexDefinition = new OPropertyIndexDefinition(className, propertyName, keyType);

config.removeField(OIndexInternal.CONFIG_AUTOMATIC);
config.removeField(OIndexInternal.CONFIG_KEYTYPE);
Expand Down Expand Up @@ -197,16 +193,15 @@ public boolean hasRangeQuerySupport() {

/**
* Creates the index.
*
* @param clusterIndexName
* Cluster name where to place the TreeMap
*
* @param clusterIndexName Cluster name where to place the TreeMap
* @param clustersToIndex
* @param rebuild
* @param progressListener
*/
public OIndexInternal<?> create(final String name, final OIndexDefinition indexDefinition, final String clusterIndexName,
final Set<String> clustersToIndex, boolean rebuild, final OProgressListener progressListener,
final OStreamSerializer valueSerializer) {
final Set<String> clustersToIndex, boolean rebuild, final OProgressListener progressListener,
final OStreamSerializer valueSerializer) {
acquireExclusiveLock();
try {
this.name = name;
Expand Down Expand Up @@ -636,8 +631,12 @@ public ODocument updateConfiguration() {
try {
configuration.field(OIndexInternal.CONFIG_TYPE, type);
configuration.field(OIndexInternal.CONFIG_NAME, name);
assert indexEngine.getVersion() > 0;
configuration.field(OIndexInternal.INDEX_VERSION, indexEngine.getVersion());

if (indexDefinition != null) {


final ODocument indexDefDocument = indexDefinition.toStream();
if (!indexDefDocument.hasOwners())
ODocumentInternal.addOwner(indexDefDocument, configuration);
Expand Down Expand Up @@ -916,7 +915,7 @@ protected void checkForRebuild() {
}

protected long[] indexCluster(final String clusterName, final OProgressListener iProgressListener, long documentNum,
long documentIndexed, long documentTotal) {
long documentIndexed, long documentTotal) {
try {
for (final ORecord record : getDatabase().browseCluster(clusterName)) {
if (Thread.interrupted())
Expand Down Expand Up @@ -953,7 +952,7 @@ protected long[] indexCluster(final String clusterName, final OProgressListener
// END OF CLUSTER REACHED, IGNORE IT
}

return new long[] { documentNum, documentIndexed };
return new long[]{documentNum, documentIndexed};
}

private OAbstractPaginatedStorage getStorage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,4 @@ public interface OIndexDefinition extends OIndexCallback {
boolean isNullValuesIgnored();

void setNullValuesIgnored(boolean value);

int getVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static OIndexDefinition createSingleFieldIndexDefinition(OClass oClass,

}

indexDefinition = new OPropertyMapIndexDefinition(oClass.getName(), fieldName, indexType, indexBy, factory.getLastVersion());
indexDefinition = new OPropertyMapIndexDefinition(oClass.getName(), fieldName, indexType, indexBy);
} else if (type.equals(OType.EMBEDDEDLIST) || type.equals(OType.EMBEDDEDSET) || type.equals(OType.LINKLIST)
|| type.equals(OType.LINKSET)) {
if (type.equals(OType.LINKSET))
Expand All @@ -157,11 +157,11 @@ else if (type.equals(OType.LINKLIST)) {
+ " You should provide linked type for embedded collections that are going to be indexed.");
}

indexDefinition = new OPropertyListIndexDefinition(oClass.getName(), fieldName, indexType, factory.getLastVersion());
indexDefinition = new OPropertyListIndexDefinition(oClass.getName(), fieldName, indexType);
} else if (type.equals(OType.LINKBAG)) {
indexDefinition = new OPropertyRidBagIndexDefinition(oClass.getName(), fieldName, factory.getLastVersion());
indexDefinition = new OPropertyRidBagIndexDefinition(oClass.getName(), fieldName);
} else
indexDefinition = new OPropertyIndexDefinition(oClass.getName(), fieldName, type, factory.getLastVersion());
indexDefinition = new OPropertyIndexDefinition(oClass.getName(), fieldName, type);

if (collate == null && propertyToIndex != null)
collate = propertyToIndex.getCollate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public interface OIndexFactory {
Set<String> getAlgorithms();

/**
*
*
*
*
*
*
*
*
*
*
* @param database
* @param indexType
* index type
Expand All @@ -55,6 +55,6 @@ public interface OIndexFactory {
* if index creation failed
*/
OIndexInternal<?> createIndex(ODatabaseDocumentInternal database, String indexType, String algorithm,
String valueContainerAlgorithm, ODocument metadata) throws OConfigurationException;
String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public interface OIndexInternal<T> extends OIndex<T> {
public static final String CONFIG_NAME = "name";
public static final String INDEX_DEFINITION = "indexDefinition";
public static final String INDEX_DEFINITION_CLASS = "indexDefinitionClass";
public static final String INDEX_VERSION = "indexVersion";
public static final String METADATA = "metadata";

/**
Expand Down Expand Up @@ -181,22 +182,22 @@ public interface OIndexInternal<T> extends OIndex<T> {
*/
void releaseKeysForUpdate(Object... key);

/**
* Release exclusive lock on keys which prevents read/modification of this keys in following methods:
*
* <ol>
* <li>{@link #put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)}</li>
* <li>{@link #checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)}</li>
* <li>{@link #remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)}</li>
* <li>{@link #remove(Object)}</li>
* </ol>
*
* This is internal method and can not be used by end users.
*
* @param keys
* Keys to unlock.
*/
void releaseKeysForUpdate(Collection<Object> keys);
/**
* Release exclusive lock on keys which prevents read/modification of this keys in following methods:
*
* <ol>
* <li>{@link #put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)}</li>
* <li>{@link #checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)}</li>
* <li>{@link #remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)}</li>
* <li>{@link #remove(Object)}</li>
* </ol>
*
* This is internal method and can not be used by end users.
*
* @param keys
* Keys to unlock.
*/
void releaseKeysForUpdate(Collection<Object> keys);

public IndexMetadata loadMetadata(ODocument iConfig);

Expand Down
Loading

0 comments on commit c44bbca

Please sign in to comment.