Skip to content

Commit

Permalink
Modify versioned identifiers to include entity id
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Hafner committed Dec 26, 2024
1 parent 754daa5 commit 483c52f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public LogicalEntity(
DataModel dataModel,
boolean modifiable ) {
super( id, name, namespaceId, type, dataModel, modifiable );
this.entryIdentifiers = new EntryIdentifierRegistry();
this.entryIdentifiers = new EntryIdentifierRegistry(id);
this.entryCommitInstantsLog = new CommitInstantsLog();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public List<ImplementationContext> anyPrepareQuery( QueryContext context, Statem
}

AlgRoot root = processor.translate( statement, parsed );
root = AlgTreeRewriter.process( root );
root = new AlgTreeRewriter( transaction ).process( root );

if ( transaction.isAnalyze() ) {
statement.getOverviewDuration().stop( "Translation" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.polypheny.db.processing.DataMigrator;
import org.polypheny.db.processing.Processor;
import org.polypheny.db.transaction.locking.Lockable;
import org.polypheny.db.transaction.locking.VersionedEntryIdentifier;
import org.polypheny.db.util.Wrapper;


Expand Down Expand Up @@ -109,6 +110,8 @@ public interface Transaction {

void acquireLockable( Lockable lockable, Lockable.LockType lockType );

void addReadEntity(VersionedEntryIdentifier entryIdentifier);

/**
* Flavor, how multimedia results should be returned from a store.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@
import org.polypheny.db.rex.RexIndexRef;
import org.polypheny.db.rex.RexLiteral;
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.transaction.Transaction;

public class AlgTreeRewriter extends AlgShuttleImpl {
private final Transaction transaction;

public AlgTreeRewriter( Transaction transaction) {
this.transaction = transaction;
}

public static AlgRoot process( AlgRoot root ) {
return root.withAlg( root.alg.accept( new AlgTreeRewriter() ) );
public AlgRoot process( AlgRoot root ) {
return root.withAlg( root.alg.accept( this ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ public class EntryIdentifierRegistry {
private static final Long MAX_IDENTIFIER_VALUE = Long.MAX_VALUE;
private final TreeSet<IdentifierInterval> availableIdentifiers;

private final long entityId;

public EntryIdentifierRegistry() {

public EntryIdentifierRegistry(long entityId) {
this.availableIdentifiers = new TreeSet<>();
this.availableIdentifiers.add( new IdentifierInterval( IdentifierUtils.MISSING_IDENTIFIER + 1, MAX_IDENTIFIER_VALUE ) );
this.entityId = entityId;
}


public EntryIdentifierRegistry( long maxIdentifierValue ) {
public EntryIdentifierRegistry(long entityId, long maxIdentifierValue ) {
this.availableIdentifiers = new TreeSet<>();
this.availableIdentifiers.add( new IdentifierInterval( IdentifierUtils.MISSING_IDENTIFIER + 1, maxIdentifierValue ) );
this.entityId = entityId;
}


Expand All @@ -29,7 +33,7 @@ public VersionedEntryIdentifier getNextEntryIdentifier() {
}
}
long nextIdentifier = availableIdentifiers.first().getNextIdentifier();
return new VersionedEntryIdentifier( nextIdentifier );
return new VersionedEntryIdentifier(entityId, nextIdentifier );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
@Getter
public class VersionedEntryIdentifier {

private final long entityId;
private final long entryIdentifier;
private final long version;


public VersionedEntryIdentifier( long entryIdentifier, long version ) {
public VersionedEntryIdentifier(long entityId, long entryIdentifier, long version ) {
this.entityId = entityId;
this.entryIdentifier = entryIdentifier;
this.version = version;
}


public VersionedEntryIdentifier( long entryIdentifier ) {
public VersionedEntryIdentifier(long entityId, long entryIdentifier ) {
this.entityId = entityId;
this.entryIdentifier = entryIdentifier;
this.version = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class EntryIdentifierRegistryTest {

@BeforeEach
void setUp() {
registry = new EntryIdentifierRegistry( 100 );
registry = new EntryIdentifierRegistry(0, 100 );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public class TransactionImpl implements Transaction, Comparable<Object> {
@Getter
private Set<Lockable> lockedEntities = new HashSet<>();

@Getter
private Set<VersionedEntryIdentifier> readSet = new HashSet<>(); // This only contains entries if the transaction involves entities in MVCC mode


Expand Down Expand Up @@ -393,6 +392,11 @@ public void acquireLockable( Lockable lockable, Lockable.LockType lockType ) {
lockable.acquire( this, lockType );
lockedEntities.add( lockable );
}

@Override
public void addReadEntity( VersionedEntryIdentifier identifier ) {
readSet.add( identifier );
}


@Override
Expand Down

0 comments on commit 483c52f

Please sign in to comment.