Skip to content

Commit

Permalink
Hook up DAGStorageProvider using SPI
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Roldan <gabriel.roldan@gmail.com>
  • Loading branch information
groldan committed Jan 9, 2019
1 parent 6984063 commit 678d942
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 25 deletions.
Expand Up @@ -13,16 +13,17 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

import java.lang.reflect.InvocationTargetException;

import org.locationtech.geogig.model.Node;
import org.locationtech.geogig.model.NodeOrdering;
import org.locationtech.geogig.model.RevObjects;
import org.locationtech.geogig.model.RevTree;
import org.locationtech.geogig.storage.ObjectStore;
import org.locationtech.jts.geom.Envelope;

import com.google.common.annotations.VisibleForTesting;

import lombok.NonNull;

public abstract class ClusteringStrategyBuilder {

protected final ObjectStore treeStore;
Expand Down Expand Up @@ -54,24 +55,19 @@ public ClusteringStrategy build() {
}
}

private static final Class<? extends DAGStorageProvider> DAGSTORECLASS = HeapDAGStorageProvider.class;
private static final DAGStorageProviderFactory DAGSTOREFACTORY = DAGStorageProviderFactory
.defaultInstance();

public @VisibleForTesting static String getDAGStoreName() {
return DAGSTORECLASS.getSimpleName();
return DAGSTOREFACTORY.getClass().getSimpleName();
}

protected DAGStorageProvider createDAGStoreageProvider() {
// return new CachingDAGStorageProvider(treeStore);
// return new LMDBDAGStorageProvider(treeStore);
// return new HeapDAGStorageProvider(treeStore);
// return new RocksdbDAGStorageProvider(treeStore);
DAGStorageProvider provider;
try {
provider = DAGSTORECLASS.getConstructor(ObjectStore.class).newInstance(treeStore);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new RuntimeException(e);
}
provider = DAGSTOREFACTORY.newInstance(treeStore);
return provider;
}

Expand All @@ -85,8 +81,8 @@ public static QuadTreeClusteringStrategyBuilder quadTree(ObjectStore treeStore)
return new QuadTreeClusteringStrategyBuilder(treeStore);
}

public static QuadTreeClusteringStrategy quadTreeOrdering(Envelope maxBounds) {
return new QuadTreeClusteringStrategyBuilder().maxBounds(maxBounds).build();
public static NodeOrdering quadTreeOrdering(Envelope maxBounds) {
return QuadTreeClusteringStrategyBuilder.buildNodeOrdering(maxBounds);
}

public static class CanonicalClusteringStrategyBuilder extends ClusteringStrategyBuilder {
Expand Down Expand Up @@ -148,6 +144,14 @@ public QuadTreeClusteringStrategy build() {
return (QuadTreeClusteringStrategy) super.build();
}

public static NodeOrdering buildNodeOrdering(@NonNull Envelope maxBounds) {
Envelope preciseBounds = RevObjects.makePrecise(maxBounds);
int maxDepth = Quadrant.findMaxDepth(preciseBounds,
QuadTreeClusteringStrategyBuilder.ABSOLUTE_MAX_DEPTH);
return new QuadTreeClusteringStrategy(RevTree.EMPTY, new HeapDAGStorageProvider(null),
preciseBounds, maxDepth);
}

@Override
protected ClusteringStrategy buildInternal(DAGStorageProvider dagStoreProvider) {
checkState(maxBounds != null, "QuadTree max bounds was not set");
Expand Down
Expand Up @@ -9,9 +9,20 @@
*/
package org.locationtech.geogig.model.internal;

interface DAGStorageProviderFactory {
import org.locationtech.geogig.model.PriorityService;
import org.locationtech.geogig.model.ServiceFinder;
import org.locationtech.geogig.storage.ObjectStore;

public DAGStorageProvider canonical();
import lombok.NonNull;

public DAGStorageProvider quadtree();
public interface DAGStorageProviderFactory extends PriorityService {

public static final String ENV_VARIABLE = "TEMP_STORAGE_FACTORY";

public DAGStorageProvider newInstance(@NonNull ObjectStore treeStore);

public static DAGStorageProviderFactory defaultInstance() {
return new ServiceFinder().environmentVariable(ENV_VARIABLE).systemProperty(ENV_VARIABLE)
.lookupDefaultService(DAGStorageProviderFactory.class);
}
}
@@ -0,0 +1,28 @@
/* Copyright (c) 2019 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Gabriel Roldan - initial implementation
*/
package org.locationtech.geogig.model.internal;

import org.locationtech.geogig.storage.ObjectStore;

import lombok.NonNull;

public class HeapDAGStorageProviderFactory implements DAGStorageProviderFactory {

/**
* @return {@code 0}, lowest priority
*/
public @Override int getPriority() {
return 0;
}

public @Override DAGStorageProvider newInstance(@NonNull ObjectStore treeStore) {
return new HeapDAGStorageProvider(treeStore);
}
}
@@ -0,0 +1 @@
org.locationtech.geogig.model.internal.HeapDAGStorageProviderFactory
5 changes: 5 additions & 0 deletions src/cli/app/pom.xml
Expand Up @@ -40,6 +40,11 @@
<artifactId>geogig-cli-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-temporary-storage-rocksdb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-cli-geotools</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions src/storage/flatbuffers/pom.xml
Expand Up @@ -81,6 +81,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Gabriel Roldan - initial implementation
*/
package org.locationtech.geogig.tempstorage.rocksdb;

import org.locationtech.geogig.model.internal.DAGStorageProvider;
import org.locationtech.geogig.model.internal.DAGStorageProviderFactory;
import org.locationtech.geogig.storage.ObjectStore;

import lombok.NonNull;

public class RocksdbDAGStorageProviderFactory implements DAGStorageProviderFactory {

/**
* @return {@code 1}, next highest priority than (heap) default one
*/
public @Override int getPriority() {
return 1;
}

public @Override DAGStorageProvider newInstance(@NonNull ObjectStore treeStore) {
return new RocksdbDAGStorageProvider(treeStore);
}
}
@@ -0,0 +1 @@
org.locationtech.geogig.tempstorage.rocksdb.RocksdbDAGStorageProviderFactory
Expand Up @@ -9,17 +9,8 @@
*/
package org.locationtech.geogig.tempstorage.rocksdb;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;
import org.locationtech.geogig.model.internal.CanonicalClusteringStrategyTest;
import org.locationtech.geogig.storage.ObjectStore;
import org.locationtech.geogig.tempstorage.rocksdb.RocksdbDAGStorageProvider;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

public class CanonicalClusteringStrategyRocksdbStorageTest extends CanonicalClusteringStrategyTest {

Expand Down
@@ -0,0 +1,26 @@
/* Copyright (c) 2019 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Gabriel Roldan - initial implementation
*/
package org.locationtech.geogig.tempstorage.rocksdb;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.locationtech.geogig.model.ServiceFinder;
import org.locationtech.geogig.model.internal.DAGStorageProviderFactory;

public class RocksdbDAGStorageProviderFactoryTest {

public final @Test void testServicePriority() {
DAGStorageProviderFactory defaultService = new ServiceFinder()
.lookupDefaultService(DAGStorageProviderFactory.class);
assertTrue(defaultService instanceof RocksdbDAGStorageProviderFactory);
}

}

0 comments on commit 678d942

Please sign in to comment.