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_r275090569
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/schema/stats/GuidePostChunkBuilder.java
 ##########
 @@ -0,0 +1,170 @@
+/*
+ * 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.schema.stats;
+
+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;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * The guide post boundaries:
+ *     gp_0, gp_1, ..., gp_i0, ..., gp_i1, ..., gp_i2, ..., gp_in, ..., gp_n
+ * The guide post chunk boundaries:
+ *     gp_i0, gp_i1, ..., gp_in, ..., gp_n
+ * The key space split by the guide post chunks:
+ *     (UNBOUND, gp_i0](gp_i0, gp_i1](gp_i1, gp_i2]...(gp_in, gp_n](gp_n, 
UNBOUND)
+ * The last guide post chunk is a DUMMY chunk which contains one DUMMY guide 
post
+ * KeyRang.UNBOUND with 0 estimated rows/bytes and Long.MAX as last update 
timestamp.
+ */
+public final class GuidePostChunkBuilder {
+    private PrefixByteEncoder encoder;
+    private TrustedByteArrayOutputStream stream;
+    private DataOutputStream output;
+    private ImmutableBytesWritable lastRow;
+    private int guidePostsCount;
+    private ImmutableBytesWritable guidePosts;
+
+    /**
+     * The total count of bytes in this chunk
+     */
+    private long totalByteCount;
+
+    /**
+     * The total count of rows in this chunk
+     */
+    private long totalRowCount;
+
+    /**
+     * The least update time across all guide posts
+     */
+    private long leastUpdateTime;
+
+    /**
+     * Maximum length of a guide post key collected
+     */
+    private int maxGuidePostKeyLength;
+
+    /**
+     * The estimation info of each guide post traversed.
+     * estimations[i].rowCount is the sum of the estimated rows of  guide post 
[0, ..., i]
+     * estimations[i].byteCount is the sum of the estimated bytes of  guide 
post [0, ..., i]
+     * estimations[i].timestamp is the last update time stamp of guide post i
+     * Eventually the whole guide post chunk will maintain one least update 
timestamp, and there is
+     * no need to maintain a timestamp for every guide post, because writing 
guide posts to stats
+     * table is an atomic operation on region level.
+     */
+    private List<GuidePostEstimation> estimations;
+
+    /**
+     * lowerBound is fixed. It's always exclusive.
+     */
+    private final byte[] lowerBound;
+
+    public GuidePostChunkBuilder() {
+        this(KeyRange.UNBOUND, 1);
+    }
+
+    public GuidePostChunkBuilder(byte[] lowerBound, int 
targetedCountOfGuidePosts) {
+        this.lowerBound = lowerBound;
+        this.encoder = new PrefixByteEncoder();
+        this.stream = new TrustedByteArrayOutputStream(1);
+        this.output = new DataOutputStream(stream);
+        this.lastRow = new ImmutableBytesWritable(ByteUtil.EMPTY_BYTE_ARRAY);
+        this.guidePostsCount = 0;
+        this.guidePosts = new 
ImmutableBytesWritable(ByteUtil.EMPTY_BYTE_ARRAY);
+        this.totalRowCount = 0;
+        this.totalByteCount = 0;
+        this.leastUpdateTime = Long.MAX_VALUE;
+        this.maxGuidePostKeyLength = 0;
+        this.estimations = 
Lists.newArrayListWithExpectedSize(targetedCountOfGuidePosts);
+    }
+
+    public boolean addGuidePostOnCollection(ImmutableBytesWritable row, long 
byteCount, long rowCount) {
 
 Review comment:
   This method seems to specific to collection. Not sure this is an actual 
builder pattern it has more functionality like ethis boolean return.  Also 
shouldn't the collection classes should handle the idiosyncrasies of its 
requirements like a 0 timestamp?

----------------------------------------------------------------
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