Commit 1ff82a7e by Suma Shivaprasad

Reverted back type change listeners invocation for index creation

parent 8e4ddf42
......@@ -29,6 +29,7 @@ import com.tinkerpop.blueprints.Vertex;
import org.apache.atlas.MetadataException;
import org.apache.atlas.discovery.SearchIndexer;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.IndexCreationException;
import org.apache.atlas.repository.IndexException;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.typesystem.types.AttributeInfo;
......@@ -153,9 +154,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
LOG.info("Index creation for type {} complete", typeName);
} catch (Throwable throwable) {
// gets handle to currently open transaction
LOG.error("Error creating index for type {}", dataType, throwable);
throw new IndexException("Error while creating index for type " + dataType, throwable);
throw new IndexCreationException("Error while creating index for type " + dataType, throwable);
}
}
......@@ -351,7 +351,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
public void commit() throws IndexException {
try {
management.commit();
} catch(Exception e) {
} catch (Exception e) {
LOG.error("Index commit failed" , e);
throw new IndexException("Index commit failed " , e);
}
......@@ -361,7 +361,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
public void rollback() throws IndexException {
try {
management.rollback();
} catch(Exception e) {
} catch (Exception e) {
LOG.error("Index rollback failed " , e);
throw new IndexException("Index rollback failed " , e);
}
......
......@@ -59,6 +59,9 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
......@@ -80,16 +83,16 @@ public class DefaultMetadataService implements MetadataService {
private final TypeSystem typeSystem;
private final MetadataRepository repository;
private final ITypeStore typeStore;
private final Provider<SearchIndexer> searchIndexProvider;
private final Set<Provider<SearchIndexer>> typeChangeListeners;
@Inject
DefaultMetadataService(MetadataRepository repository,
Provider<SearchIndexer> searchIndexProvider, ITypeStore typeStore) throws MetadataException {
DefaultMetadataService(final MetadataRepository repository,
final Provider<SearchIndexer> searchIndexProvider, final ITypeStore typeStore) throws MetadataException {
this.typeStore = typeStore;
this.typeSystem = TypeSystem.getInstance();
this.repository = repository;
this.searchIndexProvider = searchIndexProvider;
this.typeChangeListeners = new LinkedHashSet<Provider<SearchIndexer>>() {{ add(searchIndexProvider); }};
restoreTypeSystem();
}
......@@ -394,18 +397,25 @@ public class DefaultMetadataService implements MetadataService {
}
private void onTypesAddedToRepo(Map<String, IDataType> typesAdded) throws MetadataException {
final SearchIndexer indexer = searchIndexProvider.get();
Map<SearchIndexer, Throwable> caughtExceptions = new HashMap<>();
for(Provider<SearchIndexer> indexerProvider : typeChangeListeners) {
final SearchIndexer indexer = indexerProvider.get();
try {
for (Map.Entry<String, IDataType> entry : typesAdded.entrySet()) {
indexer.onAdd(entry.getKey(), entry.getValue());
}
indexer.commit();
} catch(IndexCreationException ice) {
} catch (IndexCreationException ice) {
LOG.error("Index creation for listener {} failed ", indexerProvider, ice);
indexer.rollback();
throw ice;
caughtExceptions.put(indexer, ice);
}
}
if (caughtExceptions.size() > 0) {
throw new IndexCreationException("Index creation failed for types " + typesAdded.keySet() + ". Aborting");
}
}
private void onEntityAddedToRepo(ITypedReferenceableInstance typedInstance)
throws MetadataException {
......
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