From 483c52f77e66052746d9beeab31808f53cf96bdf Mon Sep 17 00:00:00 2001 From: Tobias Hafner Date: Thu, 26 Dec 2024 10:56:32 +0100 Subject: [PATCH] Modify versioned identifiers to include entity id --- .../db/catalog/entity/logical/LogicalEntity.java | 2 +- .../org/polypheny/db/languages/LanguageManager.java | 2 +- .../java/org/polypheny/db/transaction/Transaction.java | 3 +++ .../db/transaction/locking/AlgTreeRewriter.java | 9 +++++++-- .../transaction/locking/EntryIdentifierRegistry.java | 10 +++++++--- .../transaction/locking/VersionedEntryIdentifier.java | 7 +++++-- .../locking/EntryIdentifierRegistryTest.java | 2 +- .../org/polypheny/db/transaction/TransactionImpl.java | 6 +++++- 8 files changed, 30 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java index 807d262e91..f8b4106cf2 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java @@ -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(); } diff --git a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java index c250e2ac32..18569b37db 100644 --- a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java +++ b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java @@ -185,7 +185,7 @@ public List 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" ); diff --git a/core/src/main/java/org/polypheny/db/transaction/Transaction.java b/core/src/main/java/org/polypheny/db/transaction/Transaction.java index 8464813318..7ab3eec80c 100644 --- a/core/src/main/java/org/polypheny/db/transaction/Transaction.java +++ b/core/src/main/java/org/polypheny/db/transaction/Transaction.java @@ -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; @@ -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. */ diff --git a/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java b/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java index 6fdb42b511..6f501128c4 100644 --- a/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java +++ b/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java @@ -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 ) ); } diff --git a/core/src/main/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistry.java b/core/src/main/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistry.java index 1ca6530884..0d5d25469d 100644 --- a/core/src/main/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistry.java +++ b/core/src/main/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistry.java @@ -8,16 +8,20 @@ public class EntryIdentifierRegistry { private static final Long MAX_IDENTIFIER_VALUE = Long.MAX_VALUE; private final TreeSet 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; } @@ -29,7 +33,7 @@ public VersionedEntryIdentifier getNextEntryIdentifier() { } } long nextIdentifier = availableIdentifiers.first().getNextIdentifier(); - return new VersionedEntryIdentifier( nextIdentifier ); + return new VersionedEntryIdentifier(entityId, nextIdentifier ); } diff --git a/core/src/main/java/org/polypheny/db/transaction/locking/VersionedEntryIdentifier.java b/core/src/main/java/org/polypheny/db/transaction/locking/VersionedEntryIdentifier.java index 48548e2564..add6be3ae3 100644 --- a/core/src/main/java/org/polypheny/db/transaction/locking/VersionedEntryIdentifier.java +++ b/core/src/main/java/org/polypheny/db/transaction/locking/VersionedEntryIdentifier.java @@ -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; } diff --git a/core/src/test/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistryTest.java b/core/src/test/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistryTest.java index 3484cf9e79..e30ee51cfe 100644 --- a/core/src/test/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistryTest.java +++ b/core/src/test/java/org/polypheny/db/transaction/locking/EntryIdentifierRegistryTest.java @@ -31,7 +31,7 @@ public class EntryIdentifierRegistryTest { @BeforeEach void setUp() { - registry = new EntryIdentifierRegistry( 100 ); + registry = new EntryIdentifierRegistry(0, 100 ); } diff --git a/dbms/src/main/java/org/polypheny/db/transaction/TransactionImpl.java b/dbms/src/main/java/org/polypheny/db/transaction/TransactionImpl.java index c487c161ba..799d2efc77 100644 --- a/dbms/src/main/java/org/polypheny/db/transaction/TransactionImpl.java +++ b/dbms/src/main/java/org/polypheny/db/transaction/TransactionImpl.java @@ -125,7 +125,6 @@ public class TransactionImpl implements Transaction, Comparable { @Getter private Set lockedEntities = new HashSet<>(); - @Getter private Set readSet = new HashSet<>(); // This only contains entries if the transaction involves entities in MVCC mode @@ -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