Commit 6ad08536 by skoritala Committed by Sarath Subramanian

ATLAS-3417 Improve Atlas Initialization Performance for fresh installation.

After recent changes in atlas quick search improvements, Atlas is taking long time to start on fresh installations. This checkin tries to improve initialization time for fresh installations. Signed-off-by: 's avatarSarath Subramanian <sarath@apache.org>
parent 14a6b65d
...@@ -126,6 +126,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -126,6 +126,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
if (!HAConfiguration.isHAEnabled(configuration)) { if (!HAConfiguration.isHAEnabled(configuration)) {
initialize(provider.get()); initialize(provider.get());
} }
notifyInitializationStart();
} }
public void addIndexListener(IndexChangeListener listener) { public void addIndexListener(IndexChangeListener listener) {
...@@ -221,7 +222,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -221,7 +222,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
//Commit indexes //Commit indexes
commit(management); commit(management);
notifyChangeListeners(changedTypeDefs); notifyInitializationCompletion(changedTypeDefs);
} catch (RepositoryException | IndexException e) { } catch (RepositoryException | IndexException e) {
LOG.error("Failed to update indexes for changed typedefs", e); LOG.error("Failed to update indexes for changed typedefs", e);
attemptRollback(changedTypeDefs, management); attemptRollback(changedTypeDefs, management);
...@@ -967,4 +968,28 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -967,4 +968,28 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
} }
} }
private void notifyInitializationStart() {
for (IndexChangeListener indexChangeListener : indexChangeListeners) {
try {
indexChangeListener.onInitStart();
} catch (Throwable t) {
LOG.error("Error encountered in notifying the index change listener {}.", indexChangeListener.getClass().getName(), t);
//we need to throw exception if any of the listeners throw execption.
throw new RuntimeException("Error encountered in notifying the index change listener " + indexChangeListener.getClass().getName(), t);
}
}
}
private void notifyInitializationCompletion(ChangedTypeDefs changedTypeDefs) {
for (IndexChangeListener indexChangeListener : indexChangeListeners) {
try {
indexChangeListener.onInitCompletion(changedTypeDefs);
} catch (Throwable t) {
LOG.error("Error encountered in notifying the index change listener {}.", indexChangeListener.getClass().getName(), t);
//we need to throw exception if any of the listeners throw execption.
throw new RuntimeException("Error encountered in notifying the index change listener " + indexChangeListener.getClass().getName(), t);
}
}
}
} }
...@@ -21,4 +21,6 @@ import org.apache.atlas.listener.ChangedTypeDefs; ...@@ -21,4 +21,6 @@ import org.apache.atlas.listener.ChangedTypeDefs;
public interface IndexChangeListener { public interface IndexChangeListener {
void onChange(ChangedTypeDefs changedTypeDefs); void onChange(ChangedTypeDefs changedTypeDefs);
void onInitStart();
void onInitCompletion(ChangedTypeDefs changedTypeDefs);
} }
...@@ -58,6 +58,7 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -58,6 +58,7 @@ public class SolrIndexHelper implements IndexChangeListener {
public SolrIndexHelper(AtlasTypeRegistry typeRegistry) { public SolrIndexHelper(AtlasTypeRegistry typeRegistry) {
this.typeRegistry = typeRegistry; this.typeRegistry = typeRegistry;
} }
public boolean initializationCompleted = false;
@Override @Override
public void onChange(ChangedTypeDefs changedTypeDefs) { public void onChange(ChangedTypeDefs changedTypeDefs) {
...@@ -65,7 +66,7 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -65,7 +66,7 @@ public class SolrIndexHelper implements IndexChangeListener {
changedTypeDefs == null || !changedTypeDefs.hasEntityDef()) { // nothing to do if there are no changes to entity-defs changedTypeDefs == null || !changedTypeDefs.hasEntityDef()) { // nothing to do if there are no changes to entity-defs
return; return;
} }
if(initializationCompleted) {
try { try {
AtlasGraph graph = AtlasGraphProvider.getGraphInstance(); AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
AtlasGraphIndexClient graphIndexClient = graph.getGraphIndexClient(); AtlasGraphIndexClient graphIndexClient = graph.getGraphIndexClient();
...@@ -78,6 +79,20 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -78,6 +79,20 @@ public class SolrIndexHelper implements IndexChangeListener {
throw new RuntimeException("Error encountered in handling type system change notification.", e); throw new RuntimeException("Error encountered in handling type system change notification.", e);
} }
} }
}
@Override
public void onInitStart() {
LOG.info("SolrIndexHelper Initialization started.");
initializationCompleted = false;
}
@Override
public void onInitCompletion(ChangedTypeDefs changedTypeDefs) {
LOG.info("SolrIndexHelper Initialization completed.");
initializationCompleted = true;
onChange(changedTypeDefs);
}
private List<String> getIndexFieldNamesForSuggestions(Map<String, Integer> indexFieldName2SearchWeightMap) { private List<String> getIndexFieldNamesForSuggestions(Map<String, Integer> indexFieldName2SearchWeightMap) {
List<String> ret = new ArrayList<>(); List<String> ret = new ArrayList<>();
......
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