You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zeppelin.apache.org by GitBox <gi...@apache.org> on 2022/01/07 02:15:30 UTC

[GitHub] [zeppelin] zjffdu commented on a change in pull request #4252: [ZEPPELIN-5559] Add note cache

zjffdu commented on a change in pull request #4252:
URL: https://github.com/apache/zeppelin/pull/4252#discussion_r779985593



##########
File path: zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
##########
@@ -352,43 +355,64 @@ public void removeCorruptedNote(String noteId, AuthenticationInfo subject) throw
     authorizationService.removeNoteAuth(noteId);
   }
 
+  /**
+   * Removes the Note with the NoteId.
+   * @param noteId
+   * @param subject
+   * @throws IOException when fail to get it from NotebookRepo
+   */
   public void removeNote(String noteId, AuthenticationInfo subject) throws IOException {
-    Note note = getNote(noteId);
-    removeNote(note, subject);
+    processNote(noteId,
+      note -> {
+        if (note != null) {
+          removeNote(note, subject);
+        }
+        return null;
+    });
   }
 
   /**
-   * Get note from NotebookRepo and also initialize it with other properties that is not
-   * persistent in NotebookRepo, such as paragraphJobListener.
+   * Process a note in an eviction aware manner. It initializes the note
+   * with other properties that is not persistent in NotebookRepo, such as paragraphJobListener.
+   * <p>
+   * Use {@link #processNote(String, boolean, NoteProcessor)} in case you want to force
+   * a note reload from the {@link #NotebookRepo}.
+   * </p>
    * @param noteId
-   * @return null if note not found.
-   * @throws IOException when fail to get it from NotebookRepo.
+   * @param noteProcessor
+   * @return result of the noteProcessor
+   * @throws IOException when fail to get it from {@link NotebookRepo}
    */
-  public Note getNote(String noteId) throws IOException {
-    return getNote(noteId, false);
+  public <T> T processNote(String noteId, NoteProcessor<T> noteProcessor) throws IOException {
+    return processNote(noteId, false, noteProcessor);
   }
 
   /**
-   * Get note from NotebookRepo and also initialize it with other properties that is not
-   * persistent in NotebookRepo, such as paragraphJobListener.
+   * Process a note in an eviction aware manner. It initializes the note
+   * with other properties that is not persistent in NotebookRepo, such as paragraphJobListener.
+   *
    * @param noteId
-   * @return null if note not found.
-   * @throws IOException when fail to get it from NotebookRepo.
+   * @param reload
+   * @param noteProcessor
+   * @return result of the noteProcessor
+   * @throws IOException when fail to get it from {@link NotebookRepo}
    */
-  public Note getNote(String noteId, boolean reload) throws IOException {
-    Note note = noteManager.getNote(noteId, reload);
-    if (note == null) {
-      return null;
-    }
-    note.setInterpreterFactory(replFactory);
-    note.setInterpreterSettingManager(interpreterSettingManager);
-    note.setParagraphJobListener(paragraphJobListener);
-    note.setNoteEventListeners(noteEventListeners);
-    note.setCredentials(credentials);
-    for (Paragraph p : note.getParagraphs()) {
-      p.setNote(note);
-    }
-    return note;
+  public <T> T processNote(String noteId, boolean reload, NoteProcessor<T> noteProcessor) throws IOException {
+    return noteManager.processNote(noteId, reload, note -> {
+      if (note == null) {
+        return noteProcessor.process(note);

Review comment:
       Is it necessary to process a note when it is null?




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org