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