phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [1/7] phoenix git commit: PHOENIX-4074 Race condition in LazyValueGetter (Samarth Jain)
Date Tue, 08 Aug 2017 05:08:46 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 27170bd78 -> 29b766359


PHOENIX-4074 Race condition in LazyValueGetter (Samarth Jain)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/29b76635
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/29b76635
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/29b76635

Branch: refs/heads/master
Commit: 29b76635944c717a5226e001abd85c045287344a
Parents: 30224d3
Author: James Taylor <jamestaylor@apache.org>
Authored: Mon Aug 7 19:18:20 2017 -0700
Committer: James Taylor <jamestaylor@apache.org>
Committed: Mon Aug 7 22:08:36 2017 -0700

----------------------------------------------------------------------
 .../index/covered/data/LazyValueGetter.java     | 112 ++++++++++---------
 1 file changed, 58 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/29b76635/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/LazyValueGetter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/LazyValueGetter.java
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/LazyValueGetter.java
index bafefce..1049c89 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/LazyValueGetter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/LazyValueGetter.java
@@ -38,66 +38,70 @@ import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
  */
 public class LazyValueGetter implements ValueGetter {
 
-  private CoveredDeleteScanner scan;
-  private volatile Map<ColumnReference, ImmutableBytesWritable> values;
-  private byte[] row;
-  
-  /**
-   * Back the getter with a {@link Scanner} to actually access the local data.
-   * @param scan backing scanner
-   * @param currentRow row key for the row to seek in the scanner
-   */
-  public LazyValueGetter(CoveredDeleteScanner scan, byte[] currentRow) {
-    this.scan = scan;
-    this.row = currentRow;
-  }
+    private CoveredDeleteScanner scan;
+    private volatile Map<ColumnReference, ImmutableBytesWritable> values;
+    private byte[] row;
 
-  @Override
-  public ImmutableBytesWritable getLatestValue(ColumnReference ref, long ts) throws IOException
{
-    // ensure we have a backing map
-    if (values == null) {
-      synchronized (this) {
-        values = Collections.synchronizedMap(new HashMap<ColumnReference, ImmutableBytesWritable>());
-      }
+    /**
+     * Back the getter with a {@link Scanner} to actually access the local data.
+     * @param scan backing scanner
+     * @param currentRow row key for the row to seek in the scanner
+     */
+    public LazyValueGetter(CoveredDeleteScanner scan, byte[] currentRow) {
+        this.scan = scan;
+        this.row = currentRow;
     }
 
-    // check the value in the map
-    ImmutableBytesWritable value = values.get(ref);
-    if (value == null) {
-      value = get(ref);
-      DeleteTracker deleteTracker = scan.getDeleteTracker();
-      if (value == null) {
-          // Delete family is used for row deletion. Family won't necessarily match as we'll
be at
-          // the delete family marker on the last column family if there is one.
-          if (deleteTracker.deleteFamily != null && deleteTracker.deleteFamily.getTimestamp()
== ts) {
-              value = HIDDEN_BY_DELETE;
-          }
-      }
-      values.put(ref, value);
-    }
+    @Override
+    public ImmutableBytesWritable getLatestValue(ColumnReference ref, long ts) throws IOException
{
+        Map<ColumnReference, ImmutableBytesWritable> v = values;
+        // ensure we have a backing map
+        if (v == null) {
+            synchronized (this) {
+                v = values;
+                if (v == null) {
+                    v = values = Collections.synchronizedMap(new HashMap<ColumnReference,
ImmutableBytesWritable>());
+                }
+            }
+        }
 
-    return value;
-  }
+        // check the value in the map
+        ImmutableBytesWritable value = v.get(ref);
+        if (value == null) {
+            value = get(ref);
+            DeleteTracker deleteTracker = scan.getDeleteTracker();
+            if (value == null) {
+                // Delete family is used for row deletion. Family won't necessarily match
as we'll be at
+                // the delete family marker on the last column family if there is one.
+                if (deleteTracker.deleteFamily != null && deleteTracker.deleteFamily.getTimestamp()
== ts) {
+                    value = HIDDEN_BY_DELETE;
+                }
+            }
+            v.put(ref, value);
+        }
 
-  /**
-   * @param ref
-   * @return the first value on the scanner for the given column
-   */
-  private ImmutableBytesPtr get(ColumnReference ref) throws IOException {
-    KeyValue first = ref.getFirstKeyValueForRow(row);
-    if (!scan.seek(first)) {
-      return null;
+        return value;
     }
-    // there is a next value - we only care about the current value, so we can just snag
that
-    Cell next = scan.next();
-    if (ref.matches(next)) {
-      return new ImmutableBytesPtr(next.getValueArray(), next.getValueOffset(), next.getValueLength());
+
+    /**
+     * @param ref
+     * @return the first value on the scanner for the given column
+     */
+    private ImmutableBytesPtr get(ColumnReference ref) throws IOException {
+        KeyValue first = ref.getFirstKeyValueForRow(row);
+        if (!scan.seek(first)) {
+            return null;
+        }
+        // there is a next value - we only care about the current value, so we can just snag
that
+        Cell next = scan.next();
+        if (ref.matches(next)) {
+            return new ImmutableBytesPtr(next.getValueArray(), next.getValueOffset(), next.getValueLength());
+        }
+        return null;
     }
-    return null;
-  }
 
-  @Override
-  public byte[] getRowKey() {
-	return this.row; 
-  }
+    @Override
+    public byte[] getRowKey() {
+        return this.row; 
+    }
 }
\ No newline at end of file


Mime
View raw message