Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSANDRA storage: cursor performance #312

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
Expand Down Expand Up @@ -311,6 +310,8 @@ private final class CursorImpl implements Cursor<ByteString, ByteString> {
public CursorImpl(TransactionImpl tx,TreeName treeName) {
this.treeName=treeName;
this.tx=tx;
rc=full();
iterator=rc.iterator();
}

ResultSet full(){
Expand All @@ -322,10 +323,6 @@ ResultSet full(){

@Override
public boolean next() {
if (iterator==null) {
rc=full();
iterator=rc.iterator();
}
try {
current=iterator.next();
return true;
Expand Down Expand Up @@ -371,56 +368,55 @@ public void close() {
rc=null;
}

ResultSet full(ByteSequence key){
return execute(
prepared.getUnchecked("SELECT key,value FROM "+getTableName()+" WHERE baseDN=:baseDN and indexId=:indexId and key>=:key ORDER BY key").bind()
.setString("baseDN", treeName.getBaseDN()).setString("indexId", treeName.getIndexId())
.setByteBuffer("key", ByteBuffer.wrap(key.toByteArray()))
);
}

@Override
public boolean positionToKeyOrNext(ByteSequence key) {
rc=full(key); // start iterator from key key>=:key
iterator=rc.iterator();
if (iterator.hasNext()) {
if (!isDefined() || key.compareTo(getKey())<0) { //restart iterator
iterator=rc.iterator();
}
while (iterator.hasNext()) {
current=iterator.next();
return true;
if (key.compareTo(getKey())<=0) {
return true;
}
}
current=null;
return false;
}

@Override
public boolean positionToKey(ByteSequence key) {
if (positionToKeyOrNext(key) && key.equals(getKey())){
if (!isDefined() || key.compareTo(getKey())<0) { //restart iterator
iterator=rc.iterator();
}
if (isDefined() && key.compareTo(getKey())==0) {
return true;
}
while (iterator.hasNext()) {
current=iterator.next();
if (key.compareTo(getKey())==0) {
return true;
}
}
current=null;
return false;
}

ResultSet last(){
return execute(
prepared.getUnchecked("SELECT key,value FROM "+getTableName()+" WHERE baseDN=:baseDN and indexId=:indexId ORDER BY key DESC LIMIT 1").bind()
.setString("baseDN", treeName.getBaseDN()).setString("indexId", treeName.getIndexId())
);
}

@Override
public boolean positionToLastKey() {
rc=last();
iterator=rc.iterator();
if (iterator.hasNext()) {
while (iterator.hasNext()) {
current=iterator.next();
}
if (current!=null) {
return true;
}
current=null;
return false;
}

@Override
public boolean positionToIndex(int index) {
iterator=rc.iterator(); //reset position
iterator=rc.iterator(); //restart iterator
int ct=0;
while(iterator.hasNext()){
current=iterator.next();
Expand Down