Commit 8e4ddf42 by Suma Shivaprasad

Fixed types rollback on index creation exception

parent 33e4de48
...@@ -170,10 +170,13 @@ public class DefaultMetadataService implements MetadataService { ...@@ -170,10 +170,13 @@ public class DefaultMetadataService implements MetadataService {
final Map<String, IDataType> typesAdded = typeSystem.defineTypes(typesDef); final Map<String, IDataType> typesAdded = typeSystem.defineTypes(typesDef);
try { try {
typeStore.store(typeSystem, ImmutableList.copyOf(typesAdded.keySet())); /* Create indexes first so that if index creation fails then we rollback
the typesystem and also do not persist the graph
*/
onTypesAddedToRepo(typesAdded); onTypesAddedToRepo(typesAdded);
typeStore.store(typeSystem, ImmutableList.copyOf(typesAdded.keySet()));
} catch (Throwable t) { } catch (Throwable t) {
typeSystem.removeTypes(typesAdded); typeSystem.removeTypes(typesAdded.keySet());
throw new MetadataException("Unable to persist types ", t); throw new MetadataException("Unable to persist types ", t);
} }
......
...@@ -29,15 +29,7 @@ import org.apache.atlas.typesystem.TypesDef; ...@@ -29,15 +29,7 @@ import org.apache.atlas.typesystem.TypesDef;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Singleton @Singleton
...@@ -307,12 +299,12 @@ public class TypeSystem { ...@@ -307,12 +299,12 @@ public class TypeSystem {
return false; return false;
} }
public void removeTypes(Map<String, IDataType> typeNames) { public void removeTypes(Collection<String> typeNames) {
for(String typeName : typeNames.keySet()) { for(String typeName : typeNames) {
types.remove(typeName); IDataType dataType = types.get(typeName);
IDataType dataType = typeNames.get(typeName);
final DataTypes.TypeCategory typeCategory = dataType.getTypeCategory(); final DataTypes.TypeCategory typeCategory = dataType.getTypeCategory();
typeCategoriesToTypeNamesMap.get(typeCategory).remove(typeName); typeCategoriesToTypeNamesMap.get(typeCategory).remove(typeName);
types.remove(typeName);
} }
} }
...@@ -573,9 +565,10 @@ public class TypeSystem { ...@@ -573,9 +565,10 @@ public class TypeSystem {
} }
Map<String, IDataType> defineTypes() throws MetadataException { Map<String, IDataType> defineTypes() throws MetadataException {
step1();
step2();
try { try {
step1();
step2();
step3(); step3();
step4(); step4();
} catch (MetadataException me) { } catch (MetadataException me) {
......
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