b923 commented on a change in pull request #9759: [FLINK-14169][history-server]
Cleanup expired jobs from history server
URL: https://github.com/apache/flink/pull/9759#discussion_r337106179
##########
File path:
flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/HistoryServerTest.java
##########
@@ -117,45 +124,145 @@ public void testHistoryServerIntegration() throws
Exception {
for (int x = 0; x < numJobs; x++) {
runJob();
}
+ final int numLegacyJobs = 1;
createLegacyArchive(jmDirectory.toPath());
- CountDownLatch numExpectedArchivedJobs = new
CountDownLatch(numJobs + 1);
+ waitForArchivesCreation(numJobs + numLegacyJobs);
- Configuration historyServerConfig = new Configuration();
-
historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_ARCHIVE_DIRS,
jmDirectory.toURI().toString());
-
historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_WEB_DIR,
hsDirectory.getAbsolutePath());
-
historyServerConfig.setLong(HistoryServerOptions.HISTORY_SERVER_ARCHIVE_REFRESH_INTERVAL,
100L);
+ CountDownLatch numExpectedArchivedJobs = new
CountDownLatch(numJobs + numLegacyJobs);
-
historyServerConfig.setInteger(HistoryServerOptions.HISTORY_SERVER_WEB_PORT, 0);
+ Configuration historyServerConfig =
createTestConfiguration(false);
- // the job is archived asynchronously after env.execute()
returns
- File[] archives = jmDirectory.listFiles();
- while (archives == null || archives.length != numJobs + 1) {
- Thread.sleep(50);
- archives = jmDirectory.listFiles();
+ HistoryServer hs =
+ new HistoryServer(
+ historyServerConfig,
+ (event) -> {
+ if (event.getType() ==
HistoryServerArchiveFetcher.ArchiveEventType.CREATED) {
+ numExpectedArchivedJobs.countDown();
+ }
+ });
+
+ try {
+ hs.start();
+ String baseUrl = "http://localhost:" + hs.getWebPort();
+ numExpectedArchivedJobs.await(10L, TimeUnit.SECONDS);
+
+ ObjectMapper mapper = new ObjectMapper();
+ Assert.assertEquals(numJobs + numLegacyJobs,
getJobsOverview(baseUrl, mapper).getJobs().size());
+
+ } finally {
+ hs.stop();
+ }
+ }
+
+ @Test
+ public void testCleanExpiredJob() throws Exception {
+ runArchiveExpirationTest(true);
+ }
+
+ @Test
+ public void testRemainExpiredJob() throws Exception {
+ runArchiveExpirationTest(false);
+ }
+
+ private void runArchiveExpirationTest(boolean cleanupExpiredJobs)
throws Exception {
+ int numExpiredJobs = cleanupExpiredJobs ? 1 : 0;
+ int numJobs = 3;
+ List<String> jobIDs = new ArrayList<>();
+ for (int x = 0; x < numJobs; x++) {
+ jobIDs.add(runJob());
}
+ waitForArchivesCreation(numJobs);
+
+ CountDownLatch numExpectedArchivedJobs = new
CountDownLatch(numJobs);
+ CountDownLatch numExpectedExpiredJobs = new
CountDownLatch(numExpiredJobs);
+
+ Configuration historyServerConfig =
createTestConfiguration(cleanupExpiredJobs);
+
+ HistoryServer hs =
+ new HistoryServer(
+ historyServerConfig,
+ (event) -> {
+ switch (event.getType()){
+ case CREATED:
+
numExpectedArchivedJobs.countDown();
+ break;
+ case DELETED:
+
numExpectedExpiredJobs.countDown();
+ break;
+ }
+ });
- HistoryServer hs = new HistoryServer(historyServerConfig,
numExpectedArchivedJobs);
try {
hs.start();
+ // check that expected count of archives exists
String baseUrl = "http://localhost:" + hs.getWebPort();
numExpectedArchivedJobs.await(10L, TimeUnit.SECONDS);
ObjectMapper mapper = new ObjectMapper();
- String response = getFromHTTP(baseUrl +
JobsOverviewHeaders.URL);
- MultipleJobsDetails overview =
mapper.readValue(response, MultipleJobsDetails.class);
+ Assert.assertEquals(numJobs, getJobsOverview(baseUrl,
mapper).getJobs().size());
+
+ String jobIDToDelete = jobIDs.get(0);
+ verifyArchiveFilesExistence(jobIDToDelete, true);
+
+ // delete one archive from jm
+ URI resolve =
jmDirectory.toURI().resolve(jobIDToDelete);
+ new File(resolve).delete();
+
+ numExpectedExpiredJobs.await(10L, TimeUnit.SECONDS);
+
+ // check that archive presence in hs
Review comment:
Fixed, thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services