ATLAS-1675: type-registry re-initialization failure when instance goes from passive to active state
(cherry picked from commit 1cc40fd9eff4827aa4507e78b274829511a2acb7) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/c81597ed Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/c81597ed Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/c81597ed Branch: refs/heads/0.8-incubating Commit: c81597edf7095a6405fba6c240a6152d8ee5e568 Parents: b066a07 Author: Madhan Neethiraj <[email protected]> Authored: Tue Mar 21 01:39:30 2017 -0700 Committer: Madhan Neethiraj <[email protected]> Committed: Tue Mar 21 11:26:09 2017 -0700 ---------------------------------------------------------------------- .../apache/atlas/type/AtlasTypeRegistry.java | 31 ++++++++++++++++++++ .../store/graph/AtlasTypeDefGraphStore.java | 2 ++ 2 files changed, 33 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c81597ed/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java b/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java index ddb6c71..d40eb51 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java @@ -231,6 +231,10 @@ public class AtlasTypeRegistry { entityDefs = new TypeDefCache<>(allTypes); allDefCaches = new TypeDefCache[] { enumDefs, structDefs, classificationDefs, entityDefs }; + init(); + } + + void init() { allTypes.addType(new AtlasBuiltInTypes.AtlasBooleanType()); allTypes.addType(new AtlasBuiltInTypes.AtlasByteType()); allTypes.addType(new AtlasBuiltInTypes.AtlasShortType()); @@ -303,6 +307,16 @@ public class AtlasTypeRegistry { entityDefs.removeTypeDefByName(typeName); } } + + void clear() { + allTypes.clear(); + enumDefs.clear(); + structDefs.clear(); + classificationDefs.clear(); + entityDefs.clear(); + + init(); + } } public static class AtlasTransientTypeRegistry extends AtlasTypeRegistry { @@ -334,6 +348,10 @@ public class AtlasTypeRegistry { } } + public void clear() { + registryData.clear(); + } + public void addType(AtlasBaseTypeDef typeDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasTypeRegistry.addType({})", typeDef); @@ -863,10 +881,16 @@ class TypeCache { typeNameMap.get(name); } } + + public void clear() { + typeGuidMap.clear(); + typeNameMap.clear(); + } } class TypeDefCache<T1 extends AtlasBaseTypeDef, T2 extends AtlasType> { private static final Logger LOG = LoggerFactory.getLogger(TypeDefCache.class); + private final TypeCache typeCache; private final Map<String, T1> typeDefGuidMap; private final Map<String, T1> typeDefNameMap; @@ -985,4 +1009,11 @@ class TypeDefCache<T1 extends AtlasBaseTypeDef, T2 extends AtlasType> { } } } + + public void clear() { + typeCache.clear(); + typeDefGuidMap.clear(); + typeDefNameMap.clear(); + typeNameMap.clear(); + } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c81597ed/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java index c3b6d20..2f43e9b 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java @@ -93,6 +93,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ try { ttr = typeRegistry.lockTypeRegistryForUpdate(typeUpdateLockMaxWaitTimeSeconds); + ttr.clear(); + AtlasTypesDef typesDef = new AtlasTypesDef(getEnumDefStore(ttr).getAll(), getStructDefStore(ttr).getAll(), getClassificationDefStore(ttr).getAll(),
