diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/RollingLevelDBTimelineStore.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/RollingLevelDBTimelineStore.java index 8b6a51b..54ffe3d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/RollingLevelDBTimelineStore.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/RollingLevelDBTimelineStore.java @@ -343,7 +343,7 @@ protected void serviceStart() throws Exception { deletionThread.start(); } super.serviceStart(); - } + } @Override protected void serviceStop() throws Exception { @@ -996,21 +996,18 @@ private long putEntities(TreeMap entityUpdates, // The timeline data created by the server before 2.6 won't have // the domain field. We assume this timeline data is in the // default timeline domain. - String domainId = null; - if (relatedDomainIdBytes == null) { - domainId = TimelineDataManager.DEFAULT_DOMAIN_ID; - } else { - domainId = new String(relatedDomainIdBytes, UTF_8); - } - if (!domainId.equals(entity.getDomainId())) { - // in this case the entity will be put, but the relation will be - // ignored - TimelinePutError error = new TimelinePutError(); - error.setEntityId(entity.getEntityId()); - error.setEntityType(entity.getEntityType()); - error.setErrorCode(TimelinePutError.FORBIDDEN_RELATION); - response.addError(error); - continue; + if (relatedDomainIdBytes != null) { + String domainId = new String(relatedDomainIdBytes, UTF_8); + if (!domainId.equals(entity.getDomainId())) { + // in this case the entity will be put, but the relation will be + // ignored + TimelinePutError error = new TimelinePutError(); + error.setEntityId(entity.getEntityId()); + error.setEntityType(entity.getEntityType()); + error.setErrorCode(TimelinePutError.FORBIDDEN_RELATION); + response.addError(error); + continue; + } } // write "forward" entry (related entity -> entity) byte[] key = createRelatedEntityKey(relatedEntityId, diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/TestRollingLevelDBTimelineStore.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/TestRollingLevelDBTimelineStore.java index 956e9e9..5baa88f 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/TestRollingLevelDBTimelineStore.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/TestRollingLevelDBTimelineStore.java @@ -294,6 +294,32 @@ public void testRelatingToEntityInSamePut() throws IOException { entityToStore.setDomainId("TEST_DOMAIN"); entityToStore.addRelatedEntity("TEST_ENTITY_TYPE_2", "TEST_ENTITY_ID_2"); TimelineEntities entities = new TimelineEntities(); + entities.addEntity(entityToRelate); + entities.addEntity(entityToStore); + store.put(entities); + TimelineEntity entityToGet = + store.getEntity("TEST_ENTITY_ID_2", "TEST_ENTITY_TYPE_2", null); + Assert.assertNotNull(entityToGet); + Assert.assertEquals("TEST_DOMAIN", entityToGet.getDomainId()); + Assert.assertEquals("TEST_ENTITY_TYPE_1", + entityToGet.getRelatedEntities().keySet().iterator().next()); + Assert.assertEquals("TEST_ENTITY_ID_1", + entityToGet.getRelatedEntities().values().iterator().next() + .iterator().next()); + } + + @Test + public void testOutOfOrderRelatingToEntityInSamePut() throws IOException { + TimelineEntity entityToRelate = new TimelineEntity(); + entityToRelate.setEntityType("TEST_ENTITY_TYPE_2"); + entityToRelate.setEntityId("TEST_ENTITY_ID_2"); + entityToRelate.setDomainId("TEST_DOMAIN"); + TimelineEntity entityToStore = new TimelineEntity(); + entityToStore.setEntityType("TEST_ENTITY_TYPE_1"); + entityToStore.setEntityId("TEST_ENTITY_ID_1"); + entityToStore.setDomainId("TEST_DOMAIN"); + entityToStore.addRelatedEntity("TEST_ENTITY_TYPE_2", "TEST_ENTITY_ID_2"); + TimelineEntities entities = new TimelineEntities(); entities.addEntity(entityToStore); entities.addEntity(entityToRelate); store.put(entities);