dbwong commented on a change in pull request #482: PHOENIX-4925 Use Segment 
tree to organize Guide Post Info
URL: https://github.com/apache/phoenix/pull/482#discussion_r275094308
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/schema/stats/GuidePostsInfoBuilder.java
 ##########
 @@ -17,124 +17,112 @@
  */
 package org.apache.phoenix.schema.stats;
 
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
+import com.google.common.collect.Lists;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.util.ByteUtil;
-import org.apache.phoenix.util.PrefixByteEncoder;
-import org.apache.phoenix.util.TrustedByteArrayOutputStream;
 
-/*
- * Builder to help in adding guidePosts and building guidePostInfo. This is 
used when we are collecting stats or reading stats for a table.
+/**
+ * Builder to help in adding guidePosts and building guidePostInfo.
+ * This is used when we are collecting stats or reading stats for a table.
  */
-
 public class GuidePostsInfoBuilder {
-    private PrefixByteEncoder encoder;
-    private ImmutableBytesWritable lastRow;
-    private ImmutableBytesWritable guidePosts=new 
ImmutableBytesWritable(ByteUtil.EMPTY_BYTE_ARRAY);
-    private int guidePostsCount;
-    
     /**
-     * The rowCount that is flattened across the total number of guide posts.
+     * The targeted size of the guide post chunk measured in the number of 
guide posts.
      */
-    private long rowCount = 0;
+    private final int targetedChunkSize;
 
     /**
-     * Maximum length of a guidePost collected
+     * Guide posts organized in chunks
      */
-    private int maxLength;
-    private DataOutputStream output;
-    private TrustedByteArrayOutputStream stream;
-    private List<Long> rowCounts = new ArrayList<Long>();
-    private List<Long> byteCounts = new ArrayList<Long>();
-    private List<Long> guidePostsTimestamps = new ArrayList<Long>();
-
-    public boolean isEmpty() {
-        return rowCounts.size() == 0;
-    }
-    
-    public List<Long> getRowCounts() {
-        return rowCounts;
-    }
+    private List<GuidePostChunk> guidePostChunks;
 
-    public List<Long> getByteCounts() {
-        return byteCounts;
-    }
+    /**
+     * Builder for the guide post chunk
+     */
+    private GuidePostChunkBuilder chunkBuilder;
 
-    public List<Long> getGuidePostsTimestamps() {
-        return guidePostsTimestamps;
-    }
+    /**
+     * The index of the guide post chunk in the chunk array
+     */
+    private int guidePostChunkIndex;
 
-    public int getMaxLength() {
-        return maxLength;
-    }
-    public GuidePostsInfoBuilder(){
-        this.stream = new TrustedByteArrayOutputStream(1);
-        this.output = new DataOutputStream(stream);
-        this.encoder=new PrefixByteEncoder();
-        lastRow = new ImmutableBytesWritable(ByteUtil.EMPTY_BYTE_ARRAY);
+    /**
+     * Use to track the lower bound of generated guide post chunks.
+     * It's always exclusive.
+     */
+    private ImmutableBytesWritable lastRow;
+
+    /**
+     * The total count of guide posts collected
+     */
+    private int guidePostsCount;
+
+    public GuidePostsInfoBuilder() {
+        this(1);
     }
 
-    public boolean addGuidePostOnCollection(ImmutableBytesWritable row, long 
byteCount,
-            long rowCount) {
-        /*
-         * When collecting guideposts, we don't care about the time at which 
guide post is being
-         * created/updated at. So passing it as 0 here. The update/create 
timestamp is important
-         * when we are reading guideposts out of the SYSTEM.STATS table.
-         */
-        return trackGuidePost(row, byteCount, rowCount, 0);
+    public GuidePostsInfoBuilder(int targetedChunkSize){
+        this.targetedChunkSize = targetedChunkSize;
+        this.guidePostChunks = Lists.newArrayListWithExpectedSize(1);
+        this.guidePostChunkIndex = 0;
+        this.lastRow = new ImmutableBytesWritable(KeyRange.UNBOUND);
+        this.guidePostsCount = 0;
     }
 
     /**
      * Track a new guide post
      * @param row number of rows in the guidepost
      * @param byteCount number of bytes in the guidepost
      * @param updateTimestamp time at which guidepost was created/updated.
-     * @throws IOException
      */
-    public boolean trackGuidePost(ImmutableBytesWritable row, long byteCount, 
long rowCount,
-            long updateTimestamp) {
+    public boolean trackGuidePost(ImmutableBytesWritable row, long byteCount, 
long rowCount, long updateTimestamp) {
 
 Review comment:
   This isn't really following the builder pattern.  consider rename or 
handling through exceptions or changing the caller.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to