Repository: incubator-zeppelin Updated Branches: refs/heads/master 0300a5c63 -> 458556aad
[ZEPPELIN-820] Reduce websocket communication by unicasting instead of broadcasting note list ### What is this PR for? Reducing websocket communication by unicasting instead of broadcasting notes list reduces probability of deadlock in jetty8 and also improves response time. ### What type of PR is it? Improvement ### Todos ### What is the Jira issue? [ZEPPELIN-820] (https://issues.apache.org/jira/browse/ZEPPELIN-820) ### How should this be tested? 1. Open two browser windows. 2. Check if note list shows up on home page. 3. Check if creating, removing note in one window results in updates to notes list in other windows. ### Screenshots (if appropriate) ### Questions: Author: Prasad Wagle <[email protected]> Closes #850 from prasadwagle/ZEPPELIN-820 and squashes the following commits: 2c93621 [Prasad Wagle] Add broadcastNoteList() to updateNote, needed if there are changes to title f78781d [Prasad Wagle] Remove unnecessary calls to broadcastNoteList that uses broadcastAll f249ac1 [Prasad Wagle] [ZEPPELIN-820] Reduce websocket communication by unicasting instead of broadcasting note list Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/458556aa Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/458556aa Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/458556aa Branch: refs/heads/master Commit: 458556aad5a3cdfef6c5db931aa202a73bbf4cf7 Parents: 0300a5c Author: Prasad Wagle <[email protected]> Authored: Sat Apr 30 12:20:45 2016 -0700 Committer: Lee moon soo <[email protected]> Committed: Fri May 6 09:57:27 2016 -0700 ---------------------------------------------------------------------- .../apache/zeppelin/socket/NotebookServer.java | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/458556aa/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index 3fa3d8d..09fea41 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -133,7 +133,7 @@ public class NotebookServer extends WebSocketServlet implements /** Lets be elegant here */ switch (messagereceived.op) { case LIST_NOTES: - broadcastNoteList(); + unicastNoteList(conn); break; case RELOAD_NOTES_FROM_REPO: broadcastReloadedNoteList(); @@ -201,7 +201,6 @@ public class NotebookServer extends WebSocketServlet implements checkpointNotebook(conn, notebook, messagereceived); break; default: - broadcastNoteList(); break; } } catch (Exception e) { @@ -340,6 +339,14 @@ public class NotebookServer extends WebSocketServlet implements } } + private void unicast(Message m, NotebookSocket conn) { + try { + conn.send(serializeMessage(m)); + } catch (IOException e) { + LOG.error("socket error", e); + } + } + public List<Map<String, String>> generateNotebooksInfo(boolean needsReload) { Notebook notebook = notebook(); @@ -382,6 +389,11 @@ public class NotebookServer extends WebSocketServlet implements broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo)); } + public void unicastNoteList(NotebookSocket conn) { + List<Map<String, String>> notesInfo = generateNotebooksInfo(false); + unicast(new Message(OP.NOTES_INFO).put("notes", notesInfo), conn); + } + public void broadcastReloadedNoteList() { List<Map<String, String>> notesInfo = generateNotebooksInfo(true); broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo)); @@ -415,7 +427,6 @@ public class NotebookServer extends WebSocketServlet implements if (note != null) { if (!notebookAuthorization.isReader(noteId, userAndRoles)) { permissionError(conn, "read", userAndRoles, notebookAuthorization.getReaders(noteId)); - broadcastNoteList(); return; } addConnectionToNote(note.id(), conn); @@ -437,7 +448,6 @@ public class NotebookServer extends WebSocketServlet implements NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); if (!notebookAuthorization.isReader(noteId, userAndRoles)) { permissionError(conn, "read", userAndRoles, notebookAuthorization.getReaders(noteId)); - broadcastNoteList(); return; } addConnectionToNote(note.id(), conn); @@ -463,6 +473,12 @@ public class NotebookServer extends WebSocketServlet implements return; } + NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); + if (!notebookAuthorization.isWriter(noteId, userAndRoles)) { + permissionError(conn, "update", userAndRoles, notebookAuthorization.getWriters(noteId)); + return; + } + Note note = notebook.getNote(noteId); if (note != null) { boolean cronUpdated = isCronUpdated(config, note.getConfig());
