ttr.updateTypesWithNoRefResolve(typesToUpdate); ttr.updateTypes(ret); } catch (AtlasBaseException e) { // this shouldn't happen, as the types were already validated LOG.error("failed to update the registry after updating the store", e);
AtlasTransientTypeRegistry lockTypeRegistryForUpdate(int lockMaxWaitTimeInSeconds) throws AtlasBaseException { LOG.debug("==> lockTypeRegistryForUpdate()"); boolean alreadyLockedByCurrentThread = typeRegistryUpdateLock.isHeldByCurrentThread(); if (!alreadyLockedByCurrentThread) { if (lockedByThread != null) { LOG.info("lockTypeRegistryForUpdate(): waiting for lock to be released by thread {}", lockedByThread); } } else { LOG.warn("lockTypeRegistryForUpdate(): already locked. currentLockCount={}", typeRegistryUpdateLock.getHoldCount()); } try { boolean isLocked = typeRegistryUpdateLock.tryLock(lockMaxWaitTimeInSeconds, TimeUnit.SECONDS); if (!isLocked) { throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK); } } catch (InterruptedException excp) { throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK, excp); } if (!alreadyLockedByCurrentThread) { if (LOG.isDebugEnabled()) { LOG.debug("lockTypeRegistryForUpdate(): wait over..got the lock"); } typeRegistryUnderUpdate = new AtlasTransientTypeRegistry(typeRegistry); lockedByThread = Thread.currentThread().getName(); } LOG.debug("<== lockTypeRegistryForUpdate()"); return typeRegistryUnderUpdate; }
private void addTypesWithNoRefResolve(Collection<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasTypeRegistry.addTypesWithNoRefResolve(length={})", (typeDefs == null ? 0 : typeDefs.size())); } if (CollectionUtils.isNotEmpty(typeDefs)) { for (AtlasBaseTypeDef typeDef : typeDefs) { addTypeWithNoRefResolve(typeDef); } } if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasTypeRegistry.addTypesWithNoRefResolve(length={})", (typeDefs == null ? 0 : typeDefs.size())); } }
ttr.updateTypesWithNoRefResolve(typesToUpdate);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
AtlasTransientTypeRegistry ttr = registry.lockTypeRegistryForUpdate(); ttr.addType(entityDefA); ttr.addType(entityDefB); ttr.addType(entityDefC); ttr.addType(entityDefD); ttr.addType(entityDefE); ttr.addType(entityDefF); ttr.addType(classifyDef1); ttr.addType(classifyDef2); ttr.addType(classifyDef3); ttr.addType(classifyDef4); ttr.addType(classifyDef5); ttr.addType(classifyDef6); ttr.addType(classifyDef9); ttr.addType(classifyDef10); registry.releaseTypeRegistryForUpdate(ttr, true); ttr.addType(classifyDef7); fail("Fail disjoined parent case"); } catch (AtlasBaseException ae) { ttr.addType(classifyDef8); fail("Fail trying to add an entity type that is not in the parent"); } catch (AtlasBaseException ae) {
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef); ttr.updateTypes(typesDef);
ttr.updateTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr.updateTypes(typesDef); } catch (AtlasBaseException e) { if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
ttr.updateTypes(typesDef); } catch (AtlasBaseException e) { if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) { ttr.updateTypes(ret); } catch (AtlasBaseException e) { // this shouldn't happen, as the types were already validated LOG.error("failed to update the registry after updating the store", e);
@Override @GraphTransaction public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()), CollectionUtils.size(typesDef.getRelationshipDefs())); } AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); tryTypeCreation(typesDef, ttr); AtlasTypesDef ret = addToGraphStore(typesDef, ttr); try { ttr.updateTypes(ret); } catch (AtlasBaseException e) { // this shouldn't happen, as the types were already validated LOG.error("failed to update the registry after updating the store", e); } if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()), CollectionUtils.size(typesDef.getRelationshipDefs())); } return ret; }
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
AtlasTransientTypeRegistry lockTypeRegistryForUpdate(int lockMaxWaitTimeInSeconds) throws AtlasBaseException { LOG.debug("==> lockTypeRegistryForUpdate()"); boolean alreadyLockedByCurrentThread = typeRegistryUpdateLock.isHeldByCurrentThread(); if (!alreadyLockedByCurrentThread) { if (LOG.isDebugEnabled()) { LOG.debug("lockTypeRegistryForUpdate(): waiting for lock to be released by thread {}", lockedByThread); } } else { LOG.warn("lockTypeRegistryForUpdate(): already locked. currentLockCount={}", typeRegistryUpdateLock.getHoldCount()); } try { boolean isLocked = typeRegistryUpdateLock.tryLock(lockMaxWaitTimeInSeconds, TimeUnit.SECONDS); if (!isLocked) { throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK); } } catch (InterruptedException excp) { throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK, excp); } if (!alreadyLockedByCurrentThread) { if (LOG.isDebugEnabled()) { LOG.debug("lockTypeRegistryForUpdate(): wait over..got the lock"); } typeRegistryUnderUpdate = new AtlasTransientTypeRegistry(typeRegistry); lockedByThread = Thread.currentThread().getName(); } LOG.debug("<== lockTypeRegistryForUpdate()"); return typeRegistryUnderUpdate; }