Skip to content

Commit

Permalink
new restore logic added, changed persisting approached
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Oct 1, 2023
1 parent 3d1d970 commit eb59ab2
Show file tree
Hide file tree
Showing 67 changed files with 677 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ public void removeAdapter( long adapterId ) {
/**
* Restores adapters from catalog
*/
public void restoreAdapters() {
public void restoreAdapters( List<CatalogAdapter> adapters ) {
try {
List<CatalogAdapter> adapters = Catalog.getInstance().getSnapshot().getAdapters();
for ( CatalogAdapter adapter : adapters ) {
Constructor<?> ctor = AdapterTemplate.fromString( adapter.adapterName, adapter.type ).getClazz().getConstructor( long.class, String.class, Map.class );
Adapter<?> instance = (Adapter<?>) ctor.newInstance( adapter.id, adapter.uniqueName, adapter.settings );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.polypheny.db.catalog.catalogs.DocStoreCatalog;
import org.polypheny.db.catalog.entity.allocation.AllocationCollection;
import org.polypheny.db.catalog.entity.allocation.AllocationGraph;
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper;
import org.polypheny.db.catalog.entity.logical.LogicalCollection;
import org.polypheny.db.catalog.entity.logical.LogicalGraph;
Expand Down Expand Up @@ -49,24 +50,38 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio


@Override
public void refreshTable( long allocId ) {
scannable.refreshTable( allocId );
public List<PhysicalEntity> refreshTable( long allocId ) {
return scannable.refreshTable( allocId );
}


@Override
public void refreshGraph( long allocId ) {
List<PhysicalEntity> physicals = catalog.getPhysicalsFromAllocs( allocId );
scannable.refreshTable( physicals.get( 0 ).allocationId );
scannable.refreshTable( physicals.get( 1 ).allocationId );
scannable.refreshTable( physicals.get( 2 ).allocationId );
scannable.refreshTable( physicals.get( 3 ).allocationId );
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public void refreshCollection( long allocId ) {
scannable.refreshCollection( allocId );
public List<PhysicalEntity> refreshGraph( long allocId ) {
return Scannable.refreshGraphSubstitute( scannable, allocId );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
Scannable.restoreGraphSubstitute( scannable, alloc, entities );
}


@Override
public List<PhysicalEntity> refreshCollection( long allocId ) {
return scannable.refreshCollection( allocId );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {

}


Expand All @@ -90,7 +105,7 @@ public void dropGraph( Context context, AllocationGraph allocation ) {

@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
Scannable.createCollectionSubstitute( scannable, context, logical, allocation );
scannable.createCollection( context, logical, allocation );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

package org.polypheny.db.adapter;

import java.util.List;
import org.polypheny.db.catalog.catalogs.GraphStoreCatalog;
import org.polypheny.db.catalog.entity.allocation.AllocationCollection;
import org.polypheny.db.catalog.entity.allocation.AllocationGraph;
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
import org.polypheny.db.catalog.entity.logical.LogicalColumn;
import org.polypheny.db.catalog.entity.logical.LogicalIndex;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.prepare.Context;

Expand Down Expand Up @@ -64,4 +68,22 @@ public void updateColumnType( Context context, long allocId, LogicalColumn colum
throw new GenericRuntimeException( "Should be overwritten." );
}


@Override
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
scannable.restoreGraph( alloc, entities );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Scannable.restoreCollectionSubstitute( scannable, alloc, entities );
}

}
33 changes: 27 additions & 6 deletions core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

package org.polypheny.db.adapter;

import java.util.List;
import lombok.Getter;
import org.polypheny.db.catalog.catalogs.GraphStoreCatalog;
import org.polypheny.db.catalog.entity.allocation.AllocationCollection;
import org.polypheny.db.catalog.entity.allocation.AllocationGraph;
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper;
import org.polypheny.db.catalog.entity.logical.LogicalCollection;
import org.polypheny.db.catalog.entity.logical.LogicalGraph;
import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.prepare.Context;

public class GraphScanDelegate implements Scannable {
Expand All @@ -46,20 +49,38 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio


@Override
public void refreshTable( long allocId ) {
scannable.refreshTable( allocId );
public List<PhysicalEntity> refreshTable( long allocId ) {
return scannable.refreshTable( allocId );
}


@Override
public void refreshGraph( long allocId ) {
scannable.refreshGraph( allocId );
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public void refreshCollection( long allocId ) {
Scannable.refreshCollectionSubstitution( scannable, allocId );
public List<PhysicalEntity> refreshGraph( long allocId ) {
return scannable.refreshGraph( allocId );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
scannable.restoreGraph( alloc, entities );
}


@Override
public List<PhysicalEntity> refreshCollection( long allocId ) {
return Scannable.refreshCollectionSubstitution( scannable, allocId );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Scannable.restoreCollectionSubstitute( scannable, alloc, entities );
}


Expand Down
59 changes: 0 additions & 59 deletions core/src/main/java/org/polypheny/db/adapter/Modifiable.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,15 @@
import org.polypheny.db.algebra.type.DocumentType;
import org.polypheny.db.algebra.type.GraphType;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.IdBuilder;
import org.polypheny.db.catalog.entity.CatalogEntity;
import org.polypheny.db.catalog.entity.allocation.AllocationCollection;
import org.polypheny.db.catalog.entity.allocation.AllocationColumn;
import org.polypheny.db.catalog.entity.allocation.AllocationEntity;
import org.polypheny.db.catalog.entity.allocation.AllocationGraph;
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper;
import org.polypheny.db.catalog.entity.logical.LogicalColumn;
import org.polypheny.db.catalog.entity.logical.LogicalEntity;
import org.polypheny.db.catalog.entity.logical.LogicalGraph;
import org.polypheny.db.catalog.entity.logical.LogicalIndex;
import org.polypheny.db.catalog.entity.logical.LogicalTable;
import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.catalog.logistic.Collation;
import org.polypheny.db.catalog.logistic.PlacementType;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.volcano.AlgSubset;
import org.polypheny.db.prepare.Context;
Expand All @@ -79,7 +69,6 @@
import org.polypheny.db.tools.AlgBuilder;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.util.Pair;
import org.polypheny.db.util.Triple;

public interface Modifiable extends Scannable {

Expand Down Expand Up @@ -263,54 +252,6 @@ static Modify<?> getModify( CatalogEntity table, AlgNode input, Operation operat
return table.unwrap( ModifiableTable.class ).toModificationTable( input.getCluster(), input.getTraitSet(), table, input, operation, updateList, sourceList );
}

static void createGraphSubstitute( Modifiable modifiable, Context context, LogicalGraph logical, AllocationGraph allocation ) {
PhysicalTable node = createSubstitution( modifiable, context, logical, allocation, "_node_", List.of(
Triple.of( "id", GraphType.ID_SIZE, PolyType.VARCHAR ),
Triple.of( "label", GraphType.LABEL_SIZE, PolyType.VARCHAR ) ) );

PhysicalTable nProperties = createSubstitution( modifiable, context, logical, allocation, "_nProperties_", List.of(
Triple.of( "id", GraphType.ID_SIZE, PolyType.VARCHAR ),
Triple.of( "key", GraphType.KEY_SIZE, PolyType.VARCHAR ),
Triple.of( "value", GraphType.VALUE_SIZE, PolyType.VARCHAR ) ) );

PhysicalTable edge = createSubstitution( modifiable, context, logical, allocation, "_edge_", List.of(
Triple.of( "id", GraphType.ID_SIZE, PolyType.VARCHAR ),
Triple.of( "label", GraphType.LABEL_SIZE, PolyType.VARCHAR ),
Triple.of( "_l_id_", GraphType.ID_SIZE, PolyType.VARCHAR ),
Triple.of( "_r_id_", GraphType.ID_SIZE, PolyType.VARCHAR ) ) );

PhysicalTable eProperties = createSubstitution( modifiable, context, logical, allocation, "_eProperties_", List.of(
Triple.of( "id", GraphType.ID_SIZE, PolyType.VARCHAR ),
Triple.of( "key", GraphType.KEY_SIZE, PolyType.VARCHAR ),
Triple.of( "value", GraphType.VALUE_SIZE, PolyType.VARCHAR ) ) );

modifiable.getCatalog().addPhysical( allocation, node, nProperties, edge, eProperties );
}

static PhysicalTable createSubstitution( Modifiable modifiable, Context context, LogicalEntity logical, AllocationEntity allocation, String name, List<Triple<String, Integer, PolyType>> nameLength ) {
IdBuilder builder = IdBuilder.getInstance();
LogicalTable table = new LogicalTable( builder.getNewLogicalId(), name + logical.id, logical.namespaceId, logical.entityType, null, logical.modifiable );
List<LogicalColumn> columns = new ArrayList<>();

int i = 0;
for ( Triple<String, Integer, PolyType> col : nameLength ) {
LogicalColumn column = new LogicalColumn( builder.getNewFieldId(), col.getLeft(), table.id, table.namespaceId, i, col.getRight(), null, col.getMiddle(), null, null, null, false, Collation.getDefaultCollation(), null );
columns.add( column );
i++;
}
AllocationTable allocTable = new AllocationTable( builder.getNewAllocId(), allocation.placementId, allocation.partitionId, table.id, table.namespaceId, allocation.adapterId );

List<AllocationColumn> allocColumns = new ArrayList<>();
i = 1;
for ( LogicalColumn column : columns ) {
AllocationColumn alloc = new AllocationColumn( logical.namespaceId, allocTable.placementId, allocTable.logicalId, column.id, PlacementType.AUTOMATIC, i++, allocation.adapterId );
allocColumns.add( alloc );
}

modifiable.createTable( context, LogicalTableWrapper.of( table, columns ), AllocationTableWrapper.of( allocTable, allocColumns ) );
return modifiable.getCatalog().getPhysicalsFromAllocs( allocation.id ).get( 0 ).unwrap( PhysicalTable.class );
}

static void dropGraphSubstitute( Modifiable modifiable, long allocation ) {
modifiable.getCatalog().removePhysical( allocation );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio

@Override
public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
Modifiable.createGraphSubstitute( modifiable, context, logical, allocation );
Scannable.createGraphSubstitute( modifiable, context, logical, allocation );
}


Expand All @@ -111,7 +111,7 @@ public void dropGraph( Context context, AllocationGraph allocation ) {

@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
PhysicalTable physical = Modifiable.createSubstitution( modifiable, context, logical, allocation, "_doc_", List.of( Triple.of( DocumentType.DOCUMENT_ID, DocumentType.ID_SIZE, PolyType.VARBINARY ), Triple.of( DocumentType.DOCUMENT_DATA, DocumentType.DATA_SIZE, PolyType.VARBINARY ) ) );
PhysicalTable physical = Scannable.createSubstitutionTable( modifiable, context, logical, allocation, "_doc_", List.of( Triple.of( DocumentType.DOCUMENT_ID, DocumentType.ID_SIZE, PolyType.VARBINARY ), Triple.of( DocumentType.DOCUMENT_DATA, DocumentType.DATA_SIZE, PolyType.VARBINARY ) ) );
catalog.addPhysical( allocation, physical );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

package org.polypheny.db.adapter;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.catalog.catalogs.RelStoreCatalog;
import org.polypheny.db.catalog.entity.allocation.AllocationCollection;
import org.polypheny.db.catalog.entity.allocation.AllocationGraph;
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper;
import org.polypheny.db.catalog.entity.logical.LogicalCollection;
import org.polypheny.db.catalog.entity.logical.LogicalGraph;
import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.prepare.Context;
import org.polypheny.db.tools.AlgBuilder;

Expand Down Expand Up @@ -57,20 +60,38 @@ public void createTable( Context context, LogicalTableWrapper logical, Allocatio


@Override
public void refreshTable( long allocId ) {
scannable.refreshTable( allocId );
public List<PhysicalEntity> refreshTable( long allocId ) {
return scannable.refreshTable( allocId );
}


@Override
public void refreshGraph( long allocId ) {
Scannable.refreshGraphSubstitute( scannable, allocId );
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public void refreshCollection( long allocId ) {
Scannable.refreshCollectionSubstitution( scannable, allocId );
public List<PhysicalEntity> refreshGraph( long allocId ) {
return Scannable.refreshGraphSubstitute( scannable, allocId );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
Scannable.restoreGraphSubstitute( scannable, alloc, entities );
}


@Override
public List<PhysicalEntity> refreshCollection( long allocId ) {
return Scannable.refreshCollectionSubstitution( scannable, allocId );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Scannable.restoreCollectionSubstitute( scannable, alloc, entities );
}


Expand Down
Loading

0 comments on commit eb59ab2

Please sign in to comment.