Skip to content

Commit

Permalink
Stop leaking state-lock when journal is closed
Browse files Browse the repository at this point in the history
Fix #13904

pr-link: #13913
change-id: cid-1be5b010ccefac8e741652e0ea21a25f3c1bf44a
  • Loading branch information
Göktürk Gezer committed Aug 11, 2021
1 parent d5abfd0 commit fef2d38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ public JournalContext createJournalContext() throws UnavailableException {
"Failed to acquire state-lock due to ongoing backup activity.");
}

return new StateChangeJournalContext(mJournal.createJournalContext(), sharedLockResource);
try {
return new StateChangeJournalContext(mJournal.createJournalContext(), sharedLockResource);
} catch (UnavailableException e) {
sharedLockResource.close();
throw e;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package alluxio.master.journal;

import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -174,6 +175,22 @@ public void pauseBlocksJournalContext() throws Exception {
}
}

// See https://github.com/Alluxio/alluxio/issues/13904
@Test
public void journalClosedTest() throws Exception {
// Secondary journals will be closed for operation.
mJournalSystem.losePrimacy();
// Validate that createJournalContext fails for secondary journals.
try {
mBlockMaster.createJournalContext();
fail("journal context creation should fail in secondary journal.");
} catch (UnavailableException e) {
// expected.
}
// Validate that we haven't leaked state lock while creating journal context.
assertEquals(0, mMasterContext.getStateLockManager().getSharedWaitersAndHolders().size());
}

@Test
public void stateChangeFairness() throws Exception {
JournalContext journalContext = mBlockMaster.createJournalContext();
Expand Down

0 comments on commit fef2d38

Please sign in to comment.