Commit 8305460a by Suma Shivaprasad

Moved GraphTransaction to DefaultMetadataService to make type, index creation atomic

parent 4f7e672c
...@@ -38,8 +38,6 @@ public class GraphTransactionInterceptor implements MethodInterceptor { ...@@ -38,8 +38,6 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
} }
try { try {
LOG.debug("graph rollback to cleanup previous state");
titanGraph.rollback(); //cleanup previous state
Object response = invocation.proceed(); Object response = invocation.proceed();
titanGraph.commit(); titanGraph.commit();
LOG.debug("graph commit"); LOG.debug("graph commit");
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.hadoop.metadata.repository.graph; package org.apache.hadoop.metadata.repository.graph;
import com.google.inject.Singleton;
import com.thinkaurelius.titan.core.Cardinality; import com.thinkaurelius.titan.core.Cardinality;
import com.thinkaurelius.titan.core.EdgeLabel; import com.thinkaurelius.titan.core.EdgeLabel;
import com.thinkaurelius.titan.core.Order; import com.thinkaurelius.titan.core.Order;
...@@ -51,6 +52,7 @@ import java.util.Map; ...@@ -51,6 +52,7 @@ import java.util.Map;
/** /**
* Adds index for properties of a given type when its added before any instances are added. * Adds index for properties of a given type when its added before any instances are added.
*/ */
@Singleton
public class GraphBackedSearchIndexer implements SearchIndexer { public class GraphBackedSearchIndexer implements SearchIndexer {
private static final Logger LOG = LoggerFactory.getLogger(GraphBackedSearchIndexer.class); private static final Logger LOG = LoggerFactory.getLogger(GraphBackedSearchIndexer.class);
......
...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.repository.typestore; ...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.repository.typestore;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Edge;
...@@ -53,6 +54,7 @@ import java.util.ArrayList; ...@@ -53,6 +54,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@Singleton
public class GraphBackedTypeStore implements ITypeStore { public class GraphBackedTypeStore implements ITypeStore {
public static final String VERTEX_TYPE = "typeSystem"; public static final String VERTEX_TYPE = "typeSystem";
private static final String PROPERTY_PREFIX = Constants.INTERNAL_PROPERTY_KEY_PREFIX + "type."; private static final String PROPERTY_PREFIX = Constants.INTERNAL_PROPERTY_KEY_PREFIX + "type.";
...@@ -73,7 +75,6 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -73,7 +75,6 @@ public class GraphBackedTypeStore implements ITypeStore {
} }
@Override @Override
@GraphTransaction
public void store(TypeSystem typeSystem, ImmutableList<String> typeNames) throws MetadataException { public void store(TypeSystem typeSystem, ImmutableList<String> typeNames) throws MetadataException {
ImmutableList<String> coreTypes = typeSystem.getCoreTypes(); ImmutableList<String> coreTypes = typeSystem.getCoreTypes();
for (String typeName : typeNames) { for (String typeName : typeNames) {
......
...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.services; ...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.services;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.apache.hadoop.metadata.GraphTransaction;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.ParamChecker; import org.apache.hadoop.metadata.ParamChecker;
...@@ -133,6 +134,7 @@ public class DefaultMetadataService implements MetadataService { ...@@ -133,6 +134,7 @@ public class DefaultMetadataService implements MetadataService {
* @return a unique id for this type * @return a unique id for this type
*/ */
@Override @Override
@GraphTransaction
public JSONObject createType(String typeDefinition) throws MetadataException { public JSONObject createType(String typeDefinition) throws MetadataException {
ParamChecker.notEmpty(typeDefinition, "type definition cannot be empty"); ParamChecker.notEmpty(typeDefinition, "type definition cannot be empty");
......
...@@ -23,6 +23,7 @@ import com.tinkerpop.blueprints.Direction; ...@@ -23,6 +23,7 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.hadoop.metadata.GraphTransaction;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.RepositoryMetadataModule; import org.apache.hadoop.metadata.RepositoryMetadataModule;
import org.apache.hadoop.metadata.TestUtils; import org.apache.hadoop.metadata.TestUtils;
...@@ -63,6 +64,7 @@ public class GraphBackedTypeStoreTest { ...@@ -63,6 +64,7 @@ public class GraphBackedTypeStoreTest {
} }
@Test @Test
@GraphTransaction
public void testStore() throws MetadataException { public void testStore() throws MetadataException {
typeStore.store(ts); typeStore.store(ts);
dumpGraph(); dumpGraph();
...@@ -79,6 +81,7 @@ public class GraphBackedTypeStoreTest { ...@@ -79,6 +81,7 @@ public class GraphBackedTypeStoreTest {
} }
@Test (dependsOnMethods = "testStore") @Test (dependsOnMethods = "testStore")
@GraphTransaction
public void testRestore() throws Exception { public void testRestore() throws Exception {
TypesDef types = typeStore.restore(); TypesDef types = typeStore.restore();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment