Skip to content

Commit

Permalink
fixing parts of the query routing, adding version specific folders, n…
Browse files Browse the repository at this point in the history
…ew modes
  • Loading branch information
datomo committed Nov 7, 2023
1 parent 76f68cd commit f08a606
Show file tree
Hide file tree
Showing 26 changed files with 259 additions and 125 deletions.
15 changes: 5 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,20 @@ allprojects {
test.dependsOn(":plugins:assemblePlugins")
}

def getCurrentBranch() {
def branch = ""
def proc = "git rev-parse --abbrev-ref HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
branch
}


idea {
project {
settings {
runConfigurations {
"Polypheny-DB"(Gradle) {
taskNames = ["assemblePlugins", "run"]
taskNames = ["assemblePlugins", "runDev"]
}
"Polypheny-DB (reset)"(Gradle) {
taskNames = ["assemblePlugins", ":dbms:runReset"]
taskNames = ["assemblePlugins", ":dbms:runDevReset"]
}
"Polypheny-DB (production)"(Gradle) {
taskNames = ["assemblePlugins", "run"]
}
}
copyright {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,6 +37,7 @@ public class PolyphenyHomeDirManager {
private File root;
private final List<File> dirs = new ArrayList<>();
private final List<File> deleteOnExit = new ArrayList<>();
private static PolyphenyMode mode;


public static PolyphenyHomeDirManager getInstance() {
Expand All @@ -53,7 +55,7 @@ private PolyphenyHomeDirManager() {
} else {
pathVar = System.getProperty( "user.home" );
}
root = new File( pathVar, ".polypheny" );
root = Path.of( pathVar, ".polypheny", getPrefix() ).toFile();

if ( !tryCreatingFolder( root ) ) {
root = new File( "." );
Expand All @@ -72,6 +74,21 @@ private PolyphenyHomeDirManager() {
}


public static PolyphenyHomeDirManager setModeAndGetInstance( PolyphenyMode mode ) {
if ( PolyphenyHomeDirManager.mode != null ) {
throw new RuntimeException( "Could not set the mode." );
}
PolyphenyHomeDirManager.mode = mode;
return PolyphenyHomeDirManager.getInstance();
}


private String getPrefix() {
VersionCollector collector = VersionCollector.INSTANCE;
return mode == PolyphenyMode.PRODUCTION ? collector.version : collector.version + "-" + collector.branch;
}


private boolean tryCreatingFolder( File file ) {
if ( file.isFile() ) {
return false;
Expand Down
24 changes: 24 additions & 0 deletions config/src/main/java/org/polypheny/db/util/PolyphenyMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2019-2023 The Polypheny Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.util;

public enum PolyphenyMode {
PRODUCTION,
DEVELOPMENT,
TEST,
BENCHMARK
}
69 changes: 69 additions & 0 deletions config/src/main/java/org/polypheny/db/util/VersionCollector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2019-2023 The Polypheny Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.util;


import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class VersionCollector {


public static final String VERSION = "version";
public static final String BRANCH = "branch";
public static VersionCollector INSTANCE = new VersionCollector();

private final Properties versionProperties = new Properties();

final String version;

final String branch;

public boolean inJar = false;


private VersionCollector() {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream( "classpath:/version.properties" );

try {
if ( inputStream == null ) {
inJar = true;
// When running unit tests, no jar is built, so we load a copy of the file that we saved during build.gradle.
// Possibly this also is the case during debugging, therefore we save in bin/main instead of bin/test.
inputStream = new FileInputStream( "bin/main/version.properties" );
}

versionProperties.load( inputStream );
} catch ( Exception e ) {
useDefaults();
}
version = versionProperties.getProperty( VERSION );
branch = versionProperties.getProperty( BRANCH );

}


private void useDefaults() {
log.warn( "Using default version." );
versionProperties.put( VERSION, "default" );
versionProperties.put( BRANCH, "default" );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeField;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.Catalog.PolyphenyMode;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;
import org.polypheny.db.interpreter.Row;
Expand All @@ -53,6 +52,7 @@
import org.polypheny.db.schema.types.ScannableEntity;
import org.polypheny.db.schema.types.StreamableEntity;
import org.polypheny.db.util.BuiltInMethod;
import org.polypheny.db.util.PolyphenyMode;


/**
Expand Down
8 changes: 1 addition & 7 deletions core/src/main/java/org/polypheny/db/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.polypheny.db.catalog.logistic.NamespaceType;
import org.polypheny.db.catalog.snapshot.Snapshot;
import org.polypheny.db.iface.QueryInterfaceManager.QueryInterfaceTemplate;
import org.polypheny.db.util.PolyphenyMode;

public abstract class Catalog implements ExtensionPoint {

Expand Down Expand Up @@ -275,11 +276,4 @@ public static Snapshot snapshot() {
public abstract void restore();


public enum PolyphenyMode {
DEFAULT,
TEST,
BENCHMARK
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
import org.bouncycastle.tls.TlsFatalAlert;
import org.bouncycastle.tls.TlsNoCloseNotifyException;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.Catalog.PolyphenyMode;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.util.PolyphenyMode;

/**
* The container is the main interaction instance for calling classes when interacting with Docker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.Catalog.PolyphenyMode;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.config.Config.ConfigListener;
import org.polypheny.db.config.ConfigDocker;
import org.polypheny.db.config.ConfigManager;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.util.PolyphenyMode;

public final class DockerManager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.List;
import java.util.Map;
import org.polypheny.db.algebra.AlgRoot;
import org.polypheny.db.catalog.entity.allocation.AllocationColumn;
import org.polypheny.db.plan.AlgOptCost;
import org.polypheny.db.util.Pair;


public interface ProposedRoutingPlan extends RoutingPlan {
Expand Down Expand Up @@ -63,7 +63,7 @@ public interface ProposedRoutingPlan extends RoutingPlan {
* @return The physical placements of the necessary partitions: {@code AllocationId -> List<AdapterId, CatalogColumnPlacementId>}
*/
@Override
Map<Long, List<Pair<Long, Long>>> getPhysicalPlacementsOfPartitions(); // PartitionId -> List<PlacementId, ColumnId>
Map<Long, List<AllocationColumn>> getPhysicalPlacementsOfPartitions(); // PartitionId -> List<PlacementId, ColumnId>

/**
* @return Optional pre costs.
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/routing/RoutingPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.List;
import java.util.Map;
import org.polypheny.db.util.Pair;
import org.polypheny.db.catalog.entity.allocation.AllocationColumn;


/**
Expand All @@ -33,6 +33,6 @@ public interface RoutingPlan {
Class<? extends Router> getRouter();

// PartitionId -> List<AdapterId, CatalogColumnPlacementId>
Map<Long, List<Pair<Long, Long>>> getPhysicalPlacementsOfPartitions();
Map<Long, List<AllocationColumn>> getPhysicalPlacementsOfPartitions();

}
17 changes: 4 additions & 13 deletions core/src/main/java/org/polypheny/db/tools/RoutedAlgBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import lombok.Getter;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.type.AlgDataType;
Expand All @@ -34,16 +32,15 @@
import org.polypheny.db.rex.RexLiteral;
import org.polypheny.db.transaction.Statement;
import org.polypheny.db.type.entity.document.PolyDocument;
import org.polypheny.db.util.Pair;


/**
* Extension of RelBuilder for routed plans with some more information.
*/
@Getter
public class RoutedAlgBuilder extends AlgBuilder {

@Getter
protected Map<Long, List<Pair<Long, Long>>> physicalPlacementsOfPartitions = new HashMap<>(); // PartitionId -> List<PlacementId, ColumnId>
protected Map<Long, List<AllocationColumn>> physicalPlacementsOfPartitions = new HashMap<>(); // PartitionId -> List<AllocationColumn>


public RoutedAlgBuilder( Context context, AlgOptCluster cluster, Snapshot snapshot ) {
Expand Down Expand Up @@ -99,16 +96,10 @@ public RoutedAlgBuilder documents( List<PolyDocument> documents, AlgDataType row
}


public void addPhysicalInfo( Map<Long, List<AllocationColumn>> physicalPlacements ) {
final Map<Long, List<Pair<Long, Long>>> map = physicalPlacements.entrySet().stream()
.collect( Collectors.toMap( Entry::getKey, entry -> map( entry.getValue() ) ) );
physicalPlacementsOfPartitions.putAll( map );
public void addPhysicalInfo( Map<Long, List<AllocationColumn>> partitionColumns ) {
physicalPlacementsOfPartitions.putAll( partitionColumns );
}


private List<Pair<Long, Long>> map( List<AllocationColumn> columns ) {
return columns.stream().map( col -> new Pair<>( col.placementId, col.columnId ) ).collect( Collectors.toList() );
}


}
42 changes: 40 additions & 2 deletions dbms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,20 @@ application {
//applicationDefaultJvmArgs = ["-Dlog4j.configuration=config/log4j.properties"]
}

tasks.register('runReset', JavaExec) {
tasks.register('runDevReset', JavaExec) {
group = 'Execution'
description = 'Run the main class with JavaExecTask'
classpath sourceSets.main.runtimeClasspath
mainClass = 'org.polypheny.db.PolyphenyDb'
args = ['-resetCatalog', '-resetPlugins']
args = ['-resetCatalog', '-resetPlugins', '-mode', 'dev']
}

tasks.register('runDev', JavaExec) {
group = 'Execution'
description = 'Run the main class with JavaExecTask'
classpath sourceSets.main.runtimeClasspath
mainClass = 'org.polypheny.db.PolyphenyDb'
args = ['-mode', 'dev']
}

startScripts {
Expand Down Expand Up @@ -290,3 +298,33 @@ shadowDistTar {
shadowDistZip {
dependsOn(jar)
}

def getCurrentBranch() {
def branch = ""
def proc = "git rev-parse --abbrev-ref HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
branch
}

task createProperties() {
doLast {
def details = getCurrentBranch();
System.out.println("$buildDir")
new File("$buildDir/version.properties").withWriter { w ->
Properties p = new Properties()
p['version'] = version
p['branch'] = details;
p.store w, null
}
// copy needed, otherwise the bean VersionController can't load the file at startup when running complete-app tests.
copy {
from "$buildDir/version.properties"
into "bin/main/"
}
}
}
classes {
dependsOn createProperties
}
Loading

0 comments on commit f08a606

Please sign in to comment.