apurtell commented on code in PR #2115:
URL: https://github.com/apache/phoenix/pull/2115#discussion_r2065165160


##########
phoenix-core-server/src/main/java/org/apache/phoenix/replication/log/AsyncFSDataOutput.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.replication.log;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.util.concurrent.ExecutionException;
+
+import org.apache.hadoop.hbase.io.asyncfs.AsyncFSOutput;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * SyncableDataOutput implementation that delegates to a hbase-async 
AsyncFSOutput.
+ */
[email protected](value="EI_EXPOSE_REP2",
+    justification="Intentional")
+public class AsyncFSDataOutput implements SyncableDataOutput {
+
+    private final AsyncFSOutput delegate;
+
+    public AsyncFSDataOutput(AsyncFSOutput delegate) {
+        this.delegate = delegate;
+    }
+
+    @Override
+    public void sync() throws IOException {
+        try {
+            // Our sync method is synchronous, as intended.
+            delegate.flush(true).get();
+        } catch (InterruptedException e) {
+            InterruptedIOException ioe = new InterruptedIOException();
+            ioe.initCause(e);
+            throw ioe;
+        } catch (ExecutionException e) {
+            throw new IOException(e);
+        }
+    }
+
+    @Override
+    public long getPos() throws IOException {
+        return delegate.getSyncedLength() + delegate.buffered();
+    }
+
+    @Override
+    public void close() throws IOException {
+        delegate.close();
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+        delegate.writeInt(b);
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+        delegate.write(b);
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        delegate.write(b, off, len);
+    }
+
+    // The below DataOutput interface methods must be adapted to AsyncFSOutput 
because
+    // AsyncFSOutput only implements write(byte[]), write(byte[], int, int) 
and writeInt(int).
+    // Most will never be called. We only need these so we can conform to the 
SyncableDataOutput
+    // interface contract. The methods we really care about for performance 
have been directly
+    // delegated above.
+
+    private byte[] byteBuf = new byte[1];
+
+    @Override
+    public void writeByte(int v) throws IOException {
+        byteBuf[0] = (byte) v;
+        delegate.write(byteBuf);
+    }
+
+    @Override
+    public void writeBoolean(boolean v) throws IOException {
+        writeByte(v ? 1 : 0);
+    }
+
+    @Override
+    public void writeShort(int v) throws IOException {
+        writeByte((v >>> 8) & 0xFF);
+        writeByte((v >>> 0) & 0xFF);
+    }
+
+    @Override
+    public void writeChar(int v) throws IOException {
+        writeByte((v >>> 8) & 0xFF);
+        writeByte((v >>> 0) & 0xFF);

Review Comment:
   This is what DataOutputStream does in the JRE.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to