Commit 8e4ddf42 by Suma Shivaprasad

Fixed types rollback on index creation exception

parent 33e4de48
......@@ -170,10 +170,13 @@ public class DefaultMetadataService implements MetadataService {
final Map<String, IDataType> typesAdded = typeSystem.defineTypes(typesDef);
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);
typeStore.store(typeSystem, ImmutableList.copyOf(typesAdded.keySet()));
} catch (Throwable t) {
typeSystem.removeTypes(typesAdded);
typeSystem.removeTypes(typesAdded.keySet());
throw new MetadataException("Unable to persist types ", t);
}
......
......@@ -29,15 +29,7 @@ import org.apache.atlas.typesystem.TypesDef;
import javax.inject.Singleton;
import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
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.*;
import java.util.concurrent.ConcurrentHashMap;
@Singleton
......@@ -307,12 +299,12 @@ public class TypeSystem {
return false;
}
public void removeTypes(Map<String, IDataType> typeNames) {
for(String typeName : typeNames.keySet()) {
types.remove(typeName);
IDataType dataType = typeNames.get(typeName);
public void removeTypes(Collection<String> typeNames) {
for(String typeName : typeNames) {
IDataType dataType = types.get(typeName);
final DataTypes.TypeCategory typeCategory = dataType.getTypeCategory();
typeCategoriesToTypeNamesMap.get(typeCategory).remove(typeName);
types.remove(typeName);
}
}
......@@ -573,9 +565,10 @@ public class TypeSystem {
}
Map<String, IDataType> defineTypes() throws MetadataException {
step1();
step2();
try {
step1();
step2();
step3();
step4();
} 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