You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by gi...@git.apache.org on 2017/10/02 14:03:07 UTC

[GitHub] eolivelli commented on a change in pull request #526: ISSUE 525 Refactor PerChannelBookieClient

eolivelli commented on a change in pull request #526: ISSUE 525 Refactor PerChannelBookieClient
URL: https://github.com/apache/bookkeeper/pull/526#discussion_r142141879
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
 ##########
 @@ -980,163 +816,72 @@ private ChannelFuture closeChannel(Channel c) {
         return c.close();
     }
 
-    void errorStartTLS(int rc) {
-        failTLS(rc);
-    }
-
-    void errorOutReadKey(final CompletionKey key) {
-        errorOutReadKey(key, BKException.Code.BookieHandleNotAvailableException);
-    }
-
-    void errorOutReadKey(final CompletionKey key, final int rc) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Removing completion key: {}", key);
-        }
-        final ReadCompletion readCompletion = (ReadCompletion)completionObjects.remove(key);
-        if (null == readCompletion) {
+    private void writeAndFlush(final Channel channel,
+                               final CompletionKey key,
+                               final Object request) {
+        if (channel == null) {
+            errorOut(key);
             return;
         }
-        executor.submitOrdered(readCompletion.ledgerId, new SafeRunnable() {
-            @Override
-            public void safeRun() {
-                String bAddress = "null";
-                Channel c = channel;
-                if (c != null && c.remoteAddress() != null) {
-                    bAddress = c.remoteAddress().toString();
-                }
 
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Could not write request for reading entry: {} ledger-id: {} bookie: {} rc: {}",
-                            new Object[] { readCompletion.entryId, readCompletion.ledgerId, bAddress, rc });
-                }
-
-                readCompletion.cb.readEntryComplete(rc, readCompletion.ledgerId, readCompletion.entryId,
-                                                    null, readCompletion.ctx);
-            }
-
-            @Override
-            public String toString() {
-                return String.format("ErrorOutReadKey(%s)", key);
-            }
-        });
+        try{
+            channel.writeAndFlush(request)
+                .addListener(new ChannelFutureListener() {
+                        @Override
+                        public void operationComplete(ChannelFuture future)
+                                throws Exception {
+                            if (future.isSuccess()) {
+                                if (LOG.isDebugEnabled()) {
+                                    LOG.debug("Successfully wrote request {} to {}",
+                                              requestToString(request),
+                                              channel.remoteAddress());
+                                }
+                            } else {
+                                if (!(future.cause()
+                                      instanceof ClosedChannelException)) {
+                                    LOG.warn("Writing request {} to {} failed : ",
+                                             requestToString(request),
+                                             channel, future.cause());
+                                }
+                                errorOut(key);
+                            }
+                        }
+                    });
+        } catch(Throwable e) {
+            LOG.warn("Operation {} failed", requestToString(request), e);
+            errorOut(key);
+        }
     }
 
-    void errorOutWriteLacKey(final CompletionKey key) {
-        errorOutWriteLacKey(key, BKException.Code.BookieHandleNotAvailableException);
+    private String requestToString(Object request) {
 
 Review comment:
   nit: static ?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services