From 9c4bf252a16414fb6c4bef9518303ff8508e3a13 Mon Sep 17 00:00:00 2001 From: HwangRock Date: Mon, 13 Jul 2026 22:28:32 +0900 Subject: [PATCH] [ZEPPELIN-6529] Evict note cache entries when removing a folder NoteManager.removeFolder removed the deleted notes from notesInfo and the in-memory folder tree, but did not call noteCache.removeNote for each note, so the note objects stayed in the NoteCache until the LRU threshold naturally evicted them. removeNote(String, AuthenticationInfo) already evicts the cache. Evict each removed note from noteCache in the same loop that clears notesInfo, mirroring the single-note removal path. This frees the heap held by deleted notes immediately and stops them from occupying cache slots that live notes could use, which matters most for large folder deletions such as emptying the trash. Added NoteManagerTest#testRemoveFolderEvictsNoteCache: adds two notes under a folder, asserts they are cached, removes the folder, and asserts the cache is emptied. Fails before the change (cache size stays 2), passes after. --- .../org/apache/zeppelin/notebook/NoteManager.java | 3 ++- .../apache/zeppelin/notebook/NoteManagerTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/notebook/NoteManager.java b/zeppelin-server/src/main/java/org/apache/zeppelin/notebook/NoteManager.java index e0469a825a9..20e04a866ba 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/notebook/NoteManager.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/notebook/NoteManager.java @@ -305,9 +305,10 @@ public List removeFolder(String folderPath, AuthenticationInfo subject Folder folder = getFolder(folderPath); List noteInfos = folder.getParent().removeFolder(folder.getName(), subject); - // update notesInfo + // update notesInfo and evict the deleted notes from the cache, mirroring removeNote for (NoteInfo noteInfo : noteInfos) { this.notesInfo.remove(noteInfo.getId()); + this.noteCache.removeNote(noteInfo.getId()); } return noteInfos; diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/notebook/NoteManagerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/notebook/NoteManagerTest.java index 4c5235dd2d7..cb23ea8f167 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/notebook/NoteManagerTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/notebook/NoteManagerTest.java @@ -174,6 +174,20 @@ void testLruCache() throws IOException { assertTrue(noteManager.containsNote(noteNew3.getPath())); } + @Test + void testRemoveFolderEvictsNoteCache() throws IOException { + // add 2 notes under the same folder + Note note1 = createNote("/folder1/note1"); + Note note2 = createNote("/folder1/note2"); + noteManager.addNote(note1, AuthenticationInfo.ANONYMOUS); + noteManager.addNote(note2, AuthenticationInfo.ANONYMOUS); + assertEquals(2, noteManager.getCacheSize()); + + // remove folder should evict its notes from the cache as well + noteManager.removeFolder("/folder1", AuthenticationInfo.ANONYMOUS); + assertEquals(0, noteManager.getCacheSize()); + } + @Test void testConcurrentOperation() throws Exception { int threshold = 10, noteNum = 150;