Github user maryannxue commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/171#discussion_r65294376
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/iterate/DeferredByteBufferSegmentQueue.java
---
@@ -0,0 +1,123 @@
+package org.apache.phoenix.iterate;
+
+import org.apache.commons.io.output.DeferredFileOutputStream;
+import org.apache.phoenix.memory.MemoryManager;
+import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
+
+import java.io.*;
+import java.util.*;
+
+public abstract class DeferredByteBufferSegmentQueue<T> extends
BufferSegmentQueue<T> {
+
+ final MemoryChunk chunk;
+
+ public DeferredByteBufferSegmentQueue(int index, int thresholdBytes,
+ boolean hasMaxQueueSize,
MemoryManager memoryManager) {
+ super(index, thresholdBytes, hasMaxQueueSize);
+ chunk = memoryManager.allocate(thresholdBytes);
+ }
+
+ abstract protected void writeToBuffer(OutputStream outputStream, T e);
+ abstract protected T readFromBuffer(DataInput dataInput);
+
+
+ @Override
+ protected SegmentQueueFileIterator
createSegmentQueueFileIterator(SegmentQueueFileIterator iterator){
+ return new DeferredSegmentQueueFileIterator(iterator);
+ }
+
+ @Override
+ protected SegmentQueueFileIterator createSegmentQueueFileIterator(){
+ return new DeferredSegmentQueueFileIterator();
+ }
+
+ @Override
+ protected void flush(T entry) throws IOException {
+ Queue<T> inMemQueue = getInMemoryQueue();
+ int resultSize = sizeOf(entry);
+ maxResultSize = Math.max(maxResultSize, resultSize);
+ totalResultSize = hasMaxQueueSize ? maxResultSize *
inMemQueue.size() : (totalResultSize + resultSize);
+ if (totalResultSize >= thresholdBytes) {
+ this.file = File.createTempFile(UUID.randomUUID().toString(),
null);
+
+ DeferredFileOutputStream spoolTo = new
DeferredFileOutputStream(thresholdBytes, file) {
+ @Override
+ protected void thresholdReached() throws IOException {
+ try {
+ super.thresholdReached();
+ } finally {
+ chunk.close();
--- End diff --
There's an indent problem here. You might not need these lines after the
suggested change, but would you mind double checking other places for code
indent?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---