Skip to content

Commit

Permalink
Issue ##4922 Issue with cache update was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Sep 23, 2015
1 parent 13c84a3 commit 3e920fd
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 76 deletions.
Expand Up @@ -47,7 +47,6 @@
import com.orientechnologies.orient.core.index.OClassIndexManager;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexAbstract;
import com.orientechnologies.orient.core.index.OIndexManager;
import com.orientechnologies.orient.core.intent.OIntent;
import com.orientechnologies.orient.core.iterator.ORecordIteratorClass;
import com.orientechnologies.orient.core.iterator.ORecordIteratorCluster;
Expand All @@ -71,9 +70,7 @@
import com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV;
import com.orientechnologies.orient.core.sql.parser.OStatement;
import com.orientechnologies.orient.core.storage.*;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import com.orientechnologies.orient.core.storage.impl.local.OFreezableStorage;
import com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage;
import com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException;
import com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext;
import com.orientechnologies.orient.core.tx.OTransaction;
Expand Down Expand Up @@ -582,7 +579,7 @@ public <REC extends ORecord> ORecordIteratorCluster<REC> browseCluster(final Str

final int clusterId = getClusterIdByName(iClusterName);

return new ORecordIteratorCluster<REC>(this, this, clusterId, true, true);
return new ORecordIteratorCluster<REC>(this, this, clusterId);
}

/**
Expand All @@ -597,7 +594,7 @@ public <REC extends ORecord> ORecordIteratorCluster<REC> browseCluster(final Str

final int clusterId = getClusterIdByName(iClusterName);

return new ORecordIteratorCluster<REC>(this, this, clusterId, startClusterPosition, endClusterPosition, true, true,
return new ORecordIteratorCluster<REC>(this, this, clusterId, startClusterPosition, endClusterPosition,
loadTombstones, OStorage.LOCKING_STRATEGY.DEFAULT);
}

Expand All @@ -609,7 +606,7 @@ public <REC extends ORecord> ORecordIteratorCluster<REC> browseCluster(String iC

final int clusterId = getClusterIdByName(iClusterName);

return new ORecordIteratorCluster<REC>(this, this, clusterId, startClusterPosition, endClusterPosition, true);
return new ORecordIteratorCluster<REC>(this, this, clusterId, startClusterPosition, endClusterPosition);
}

/**
Expand Down Expand Up @@ -2168,7 +2165,7 @@ public ORecordIteratorClass<ODocument> browseClass(final String iClassName, fina
throw new IllegalArgumentException("Class '" + iClassName + "' not found in current database");

checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_READ, iClassName);
return new ORecordIteratorClass<ODocument>(this, this, iClassName, iPolymorphic, true, true, false);
return new ORecordIteratorClass<ODocument>(this, this, iClassName, iPolymorphic, false);
}

/**
Expand All @@ -2178,7 +2175,7 @@ public ORecordIteratorClass<ODocument> browseClass(final String iClassName, fina
public ORecordIteratorCluster<ODocument> browseCluster(final String iClusterName) {
checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, iClusterName);

return new ORecordIteratorCluster<ODocument>(this, this, getClusterIdByName(iClusterName), true, true);
return new ORecordIteratorCluster<ODocument>(this, this, getClusterIdByName(iClusterName));
}

/**
Expand All @@ -2199,7 +2196,7 @@ public ORecordIteratorCluster<ODocument> browseCluster(String iClusterName, long
checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, iClusterName);

return new ORecordIteratorCluster<ODocument>(this, this, getClusterIdByName(iClusterName), startClusterPosition,
endClusterPosition, true, true, loadTombstones, OStorage.LOCKING_STRATEGY.DEFAULT);
endClusterPosition, loadTombstones, OStorage.LOCKING_STRATEGY.DEFAULT);
}

/**
Expand Down
Expand Up @@ -51,7 +51,6 @@ public abstract class OIdentifiableIterator<REC extends OIdentifiable> implement
protected final ORecordId current = new ORecordId();
private final ODatabaseDocumentInternal lowLevelDatabase;
private final OStorage dbStorage;
private final boolean useCache;
private final boolean iterateThroughTombstones;
protected boolean liveUpdated = false;
protected long limit = -1;
Expand All @@ -69,22 +68,19 @@ public abstract class OIdentifiableIterator<REC extends OIdentifiable> implement
private long currentEntry = ORID.CLUSTER_POS_INVALID;
private int currentEntryPosition = -1;
private OPhysicalPosition[] positionsToProcess = null;
protected boolean updateCache = false;

public OIdentifiableIterator(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final boolean useCache) {
this(iDatabase, iLowLevelDatabase, useCache, false, OStorage.LOCKING_STRATEGY.NONE);
public OIdentifiableIterator(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase) {
this(iDatabase, iLowLevelDatabase, false, OStorage.LOCKING_STRATEGY.NONE);
}

@Deprecated
/**
* @deprecated usage of this constructor may lead to deadlocks.
*/public OIdentifiableIterator(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final boolean useCache, final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
database = iDatabase;
lowLevelDatabase = iLowLevelDatabase;
this.iterateThroughTombstones = iterateThroughTombstones;
this.useCache = useCache;
lockingStrategy = iLockingStrategy;

dbStorage = lowLevelDatabase.getStorage();
Expand Down Expand Up @@ -287,9 +283,9 @@ protected ORecord readCurrentRecord(ORecord iRecord, final int iMovement) {
try {
if (iRecord != null) {
ORecordInternal.setIdentity(iRecord, new ORecordId(current.clusterId, current.clusterPosition));
iRecord = lowLevelDatabase.load(iRecord, fetchPlan, !useCache, updateCache, iterateThroughTombstones, lockingStrategy);
iRecord = lowLevelDatabase.load(iRecord, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
} else
iRecord = lowLevelDatabase.load(current, fetchPlan, !useCache, updateCache, iterateThroughTombstones, lockingStrategy);
iRecord = lowLevelDatabase.load(current, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
} catch (ODatabaseException e) {
if (Thread.interrupted() || lowLevelDatabase.isClosed())
// THREAD INTERRUPTED: RETURN
Expand Down
Expand Up @@ -50,40 +50,25 @@ public class ORecordIteratorClass<REC extends ORecord> extends ORecordIteratorCl
*/
public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentTx iLowLevelDatabase,
final String iClassName, final boolean iPolymorphic) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, true, false);
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, true);
}

public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final String iClassName, final boolean iPolymorphic) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, true, false);
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, true);
}

public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final String iClassName, final boolean iPolymorphic, final boolean iUseCache, final boolean iterateThroughTombstones) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iUseCache, false, iterateThroughTombstones,
OStorage.LOCKING_STRATEGY.DEFAULT);
final String iClassName, final boolean iPolymorphic, final boolean iterateThroughTombstones) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iterateThroughTombstones, OStorage.LOCKING_STRATEGY.DEFAULT);
begin();
}

public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final String iClassName, final boolean iPolymorphic, final boolean iUseCache, final boolean iUpdateCache,
final boolean iterateThroughTombstones) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iUseCache, iUpdateCache, iterateThroughTombstones,
OStorage.LOCKING_STRATEGY.DEFAULT);
begin();
}

public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final String iClassName, final boolean iPolymorphic, final boolean iUseCache) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iUseCache, false, false, OStorage.LOCKING_STRATEGY.NONE);
}

@Deprecated
public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final String iClassName, final boolean iPolymorphic, final boolean iUseCache, final boolean iUpdateCache,
final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iUseCache, iterateThroughTombstones, iLockingStrategy);
updateCache = iUpdateCache;
final String iClassName, final boolean iPolymorphic, final boolean iterateThroughTombstones,
final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iterateThroughTombstones, iLockingStrategy);

targetClass = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(iClassName);
if (targetClass == null)
Expand Down
Expand Up @@ -30,17 +30,17 @@
*/
public class ORecordIteratorClassDescendentOrder<REC extends ORecord> extends ORecordIteratorClass<REC> {
public ORecordIteratorClassDescendentOrder(ODatabaseDocumentInternal iDatabase, ODatabaseDocumentInternal iLowLevelDatabase,
String iClassName, boolean iPolymorphic, boolean iUseCache) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iUseCache, false, OStorage.LOCKING_STRATEGY.NONE);
String iClassName, boolean iPolymorphic) {
this(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, false, OStorage.LOCKING_STRATEGY.NONE);
}

@Deprecated
public ORecordIteratorClassDescendentOrder(ODatabaseDocumentInternal iDatabase, ODatabaseDocumentInternal iLowLevelDatabase,
String iClassName, boolean iPolymorphic, boolean iUseCache, boolean iterateThroughTombstones,
OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iUseCache, false, iterateThroughTombstones, iLockingStrategy);
String iClassName, boolean iPolymorphic, boolean iterateThroughTombstones, OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iClassName, iPolymorphic, iterateThroughTombstones, iLockingStrategy);

currentClusterIdx = clusterIds.length - 1; // START FROM THE LAST CLUSTER
updateClusterRange();
}

@Override
Expand Down
Expand Up @@ -37,23 +37,21 @@ public class ORecordIteratorCluster<REC extends ORecord> extends OIdentifiableIt
private ORecord currentRecord;

public ORecordIteratorCluster(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentTx iLowLevelDatabase,
final int iClusterId, final boolean iUseCache, final boolean iUpdateCache) {
this(iDatabase, iLowLevelDatabase, iClusterId, ORID.CLUSTER_POS_INVALID, ORID.CLUSTER_POS_INVALID, iUseCache, iUpdateCache,
false, OStorage.LOCKING_STRATEGY.DEFAULT);
final int iClusterId) {
this(iDatabase, iLowLevelDatabase, iClusterId, ORID.CLUSTER_POS_INVALID, ORID.CLUSTER_POS_INVALID, false,
OStorage.LOCKING_STRATEGY.DEFAULT);
}

public ORecordIteratorCluster(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentTx iLowLevelDatabase,
final int iClusterId, final long firstClusterEntry, final long lastClusterEntry, final boolean iUseCache) {
this(iDatabase, iLowLevelDatabase, iClusterId, firstClusterEntry, lastClusterEntry, iUseCache, false, false,
OStorage.LOCKING_STRATEGY.NONE);
final int iClusterId, final long firstClusterEntry, final long lastClusterEntry) {
this(iDatabase, iLowLevelDatabase, iClusterId, firstClusterEntry, lastClusterEntry, false, OStorage.LOCKING_STRATEGY.NONE);
}

@Deprecated
public ORecordIteratorCluster(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentTx iLowLevelDatabase,
final int iClusterId, final long firstClusterEntry, final long lastClusterEntry, final boolean iUseCache,
final boolean iUpdateCache, final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iUseCache, iterateThroughTombstones, iLockingStrategy);
updateCache = iUpdateCache;
final int iClusterId, final long firstClusterEntry, final long lastClusterEntry, final boolean iterateThroughTombstones,
final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iterateThroughTombstones, iLockingStrategy);

if (iClusterId == ORID.CLUSTER_ID_INVALID)
throw new IllegalArgumentException("The clusterId is invalid");
Expand Down
Expand Up @@ -45,15 +45,14 @@ public class ORecordIteratorClusters<REC extends ORecord> extends OIdentifiableI
protected ORID endRange;

public ORecordIteratorClusters(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final int[] iClusterIds, final boolean iUseCache) {
this(iDatabase, iLowLevelDatabase, iClusterIds, iUseCache, false, OStorage.LOCKING_STRATEGY.NONE);
final int[] iClusterIds) {
this(iDatabase, iLowLevelDatabase, iClusterIds, false, OStorage.LOCKING_STRATEGY.NONE);
}

@Deprecated
public ORecordIteratorClusters(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final int[] iClusterIds, final boolean iUseCache, final boolean iterateThroughTombstones,
final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iUseCache, iterateThroughTombstones, iLockingStrategy);
final int[] iClusterIds, final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iterateThroughTombstones, iLockingStrategy);

checkForSystemClusters(iDatabase, iClusterIds);

Expand All @@ -66,18 +65,24 @@ public ORecordIteratorClusters(final ODatabaseDocumentInternal iDatabase, final

@Deprecated
protected ORecordIteratorClusters(final ODatabaseDocumentInternal iDatabase, final ODatabaseDocumentInternal iLowLevelDatabase,
final boolean iUseCache, final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iUseCache, iterateThroughTombstones, iLockingStrategy);
final boolean iterateThroughTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
super(iDatabase, iLowLevelDatabase, iterateThroughTombstones, iLockingStrategy);
}

public ORecordIteratorClusters<REC> setRange(final ORID iBegin, final ORID iEnd) {
final ORID oldBegin = beginRange;
final ORID oldEnd = endRange;

beginRange = iBegin;
endRange = iEnd;

if ((oldBegin == null ? iBegin == null : oldBegin.equals(iBegin)) && (oldEnd == null ? iEnd == null : oldEnd.equals(iEnd)))
return this;

if (currentRecord != null && outsideOfTheRange(currentRecord.getIdentity())) {
currentRecord = null;
}

updateClusterRange();
begin();
return this;
}
Expand Down Expand Up @@ -115,6 +120,9 @@ public boolean hasPrevious() {
// CLUSTER EXHAUSTED, TRY WITH THE PREVIOUS ONE
currentClusterIdx--;

if (currentClusterIdx < 0)
break;

updateClusterRange();
}

Expand Down Expand Up @@ -291,8 +299,7 @@ public ORecordIteratorClusters<REC> begin() {
currentClusterIdx = 0;
current.clusterId = clusterIds[currentClusterIdx];

if (liveUpdated)
updateClusterRange();
updateClusterRange();

resetCurrentPosition();
nextPosition();
Expand Down Expand Up @@ -320,8 +327,8 @@ public ORecordIteratorClusters<REC> last() {

browsedRecords = 0;
currentClusterIdx = clusterIds.length - 1;
if (liveUpdated)
updateClusterRange();

updateClusterRange();

current.clusterId = clusterIds[currentClusterIdx];

Expand Down
Expand Up @@ -479,7 +479,7 @@ protected Iterator<? extends OIdentifiable> searchInClasses(final OClass iCls, f
return new ORecordIteratorClass<ORecord>(database, database, iCls.getName(), iPolymorphic, isUseCache()).setRange(range[0],
range[1]);
else
return new ORecordIteratorClassDescendentOrder<ORecord>(database, database, iCls.getName(), iPolymorphic, isUseCache())
return new ORecordIteratorClassDescendentOrder<ORecord>(database, database, iCls.getName(), iPolymorphic)
.setRange(range[0], range[1]);
}

Expand Down Expand Up @@ -523,7 +523,7 @@ protected void searchInClusters() {

final ORID[] range = getRange();

target = new ORecordIteratorClusters<ORecord>(database, database, clIds, !isUseCache()).setRange(range[0], range[1]);
target = new ORecordIteratorClusters<ORecord>(database, database, clIds).setRange(range[0], range[1]);
}

protected void applyLimitAndSkip() {
Expand Down
Expand Up @@ -1607,8 +1607,7 @@ public void run() {

protected void scanClusterWithIterator(final ODatabaseDocumentTx localDatabase, final OCommandContext iContext,
final int current, final List<Integer> clusterList, final boolean[] results) {
final ORecordIteratorCluster it = new ORecordIteratorCluster(localDatabase, localDatabase, clusterList.get(current), true,
false);
final ORecordIteratorCluster it = new ORecordIteratorCluster(localDatabase, localDatabase, clusterList.get(current));

while (it.hasNext()) {
final ORecord next = it.next();
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion core/src/test/java/com/orientechnologies/orient/core/iterator/ClassIteratorTest.java 100644 → 100755
Expand Up @@ -111,7 +111,8 @@ public void testDescendentOrderIteratorWithMultipleClusters() throws Exception {
// Use descending class iterator.
final ORecordIteratorClass<ODocument> personIter =
new ORecordIteratorClassDescendentOrder<ODocument>(
db, db, "Person", true, true, false, LOCKING_STRATEGY.DEFAULT);
db, db, "Person", true,
false, LOCKING_STRATEGY.DEFAULT);

personIter.setRange(null, null); // open range

Expand Down
Expand Up @@ -38,7 +38,7 @@ public OObjectIteratorClass(final OObjectDatabaseTx iDatabase, final ODatabaseDo
final String iClusterName, final boolean iPolymorphic) {
database = iDatabase;
underlying = new ORecordIteratorClass<ODocument>(iDatabase.getUnderlying(), iUnderlyingDatabase, iClusterName, iPolymorphic,
true, false);
true);
}

public boolean hasNext() {
Expand Down
Expand Up @@ -37,7 +37,7 @@ public class OObjectIteratorCluster<T> implements OObjectIteratorClusterInterfac
public OObjectIteratorCluster(final OObjectDatabaseTx iDatabase, final ODatabaseDocumentTx iUnderlyingDatabase,
final int iClusterId) {
database = iDatabase;
underlying = new ORecordIteratorCluster<ODocument>(iDatabase.getUnderlying(), iUnderlyingDatabase, iClusterId, true, true);
underlying = new ORecordIteratorCluster<ODocument>(iDatabase.getUnderlying(), iUnderlyingDatabase, iClusterId);
}

public boolean hasNext() {
Expand Down

0 comments on commit 3e920fd

Please sign in to comment.