|
|
@ -28,6 +28,14 @@ import org.redisson.client.protocol.decoder.ScanObjectEntry;
|
|
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @author Nikita Koksharov
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param <K> key type
|
|
|
|
|
|
|
|
* @param <V> value type
|
|
|
|
|
|
|
|
* @param <M> loaded value type
|
|
|
|
|
|
|
|
*/
|
|
|
|
public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
|
|
|
|
|
|
|
|
private Map<ByteBuf, ByteBuf> firstValues;
|
|
|
|
private Map<ByteBuf, ByteBuf> firstValues;
|
|
|
@ -38,7 +46,6 @@ public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
|
|
|
|
|
|
|
|
private boolean finished;
|
|
|
|
private boolean finished;
|
|
|
|
private boolean currentElementRemoved;
|
|
|
|
private boolean currentElementRemoved;
|
|
|
|
private boolean removeExecuted;
|
|
|
|
|
|
|
|
protected Map.Entry<ScanObjectEntry, ScanObjectEntry> entry;
|
|
|
|
protected Map.Entry<ScanObjectEntry, ScanObjectEntry> entry;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -49,7 +56,6 @@ public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
free(lastValues);
|
|
|
|
free(lastValues);
|
|
|
|
|
|
|
|
|
|
|
|
currentElementRemoved = false;
|
|
|
|
currentElementRemoved = false;
|
|
|
|
removeExecuted = false;
|
|
|
|
|
|
|
|
client = null;
|
|
|
|
client = null;
|
|
|
|
firstValues = null;
|
|
|
|
firstValues = null;
|
|
|
|
lastValues = null;
|
|
|
|
lastValues = null;
|
|
|
@ -60,15 +66,15 @@ public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finished = false;
|
|
|
|
finished = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
long prevIterPos;
|
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
prevIterPos = nextIterPos;
|
|
|
|
|
|
|
|
MapScanResult<ScanObjectEntry, ScanObjectEntry> res = iterator();
|
|
|
|
MapScanResult<ScanObjectEntry, ScanObjectEntry> res = iterator();
|
|
|
|
if (lastValues != null) {
|
|
|
|
if (lastValues != null) {
|
|
|
|
free(lastValues);
|
|
|
|
free(lastValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lastValues = convert(res.getMap());
|
|
|
|
lastValues = convert(res.getMap());
|
|
|
|
client = res.getRedisClient();
|
|
|
|
client = res.getRedisClient();
|
|
|
|
|
|
|
|
|
|
|
|
if (nextIterPos == 0 && firstValues == null) {
|
|
|
|
if (nextIterPos == 0 && firstValues == null) {
|
|
|
|
firstValues = lastValues;
|
|
|
|
firstValues = lastValues;
|
|
|
|
lastValues = null;
|
|
|
|
lastValues = null;
|
|
|
@ -76,7 +82,6 @@ public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
client = null;
|
|
|
|
client = null;
|
|
|
|
firstValues = null;
|
|
|
|
firstValues = null;
|
|
|
|
nextIterPos = 0;
|
|
|
|
nextIterPos = 0;
|
|
|
|
prevIterPos = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (firstValues.isEmpty()) {
|
|
|
|
if (firstValues.isEmpty()) {
|
|
|
@ -87,38 +92,38 @@ public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
client = null;
|
|
|
|
client = null;
|
|
|
|
firstValues = null;
|
|
|
|
firstValues = null;
|
|
|
|
nextIterPos = 0;
|
|
|
|
nextIterPos = 0;
|
|
|
|
prevIterPos = -1;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res.getPos() == 0) {
|
|
|
|
if (res.getPos() == 0) {
|
|
|
|
|
|
|
|
free(firstValues);
|
|
|
|
|
|
|
|
free(lastValues);
|
|
|
|
|
|
|
|
|
|
|
|
finished = true;
|
|
|
|
finished = true;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (lastValues.keySet().removeAll(firstValues.keySet())) {
|
|
|
|
} else if (lastValues.keySet().removeAll(firstValues.keySet())
|
|
|
|
|
|
|
|
|| (lastValues.isEmpty() && nextIterPos == 0)) {
|
|
|
|
free(firstValues);
|
|
|
|
free(firstValues);
|
|
|
|
free(lastValues);
|
|
|
|
free(lastValues);
|
|
|
|
|
|
|
|
|
|
|
|
currentElementRemoved = false;
|
|
|
|
currentElementRemoved = false;
|
|
|
|
removeExecuted = false;
|
|
|
|
|
|
|
|
client = null;
|
|
|
|
client = null;
|
|
|
|
firstValues = null;
|
|
|
|
firstValues = null;
|
|
|
|
lastValues = null;
|
|
|
|
lastValues = null;
|
|
|
|
nextIterPos = 0;
|
|
|
|
nextIterPos = 0;
|
|
|
|
prevIterPos = -1;
|
|
|
|
|
|
|
|
if (tryAgain()) {
|
|
|
|
if (tryAgain()) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
finished = true;
|
|
|
|
finished = true;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastIter = res.getMap().entrySet().iterator();
|
|
|
|
lastIter = res.getMap().entrySet().iterator();
|
|
|
|
nextIterPos = res.getPos();
|
|
|
|
nextIterPos = res.getPos();
|
|
|
|
} while (!lastIter.hasNext() && nextIterPos != prevIterPos);
|
|
|
|
} while (!lastIter.hasNext());
|
|
|
|
if (prevIterPos == nextIterPos && !removeExecuted) {
|
|
|
|
|
|
|
|
finished = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lastIter.hasNext();
|
|
|
|
return lastIter.hasNext();
|
|
|
|
|
|
|
|
|
|
|
@ -184,7 +189,6 @@ public abstract class RedissonBaseMapIterator<K, V, M> implements Iterator<M> {
|
|
|
|
lastIter.remove();
|
|
|
|
lastIter.remove();
|
|
|
|
removeKey();
|
|
|
|
removeKey();
|
|
|
|
currentElementRemoved = true;
|
|
|
|
currentElementRemoved = true;
|
|
|
|
removeExecuted = true;
|
|
|
|
|
|
|
|
entry = null;
|
|
|
|
entry = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|