asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject incubator-asterixdb-hyracks git commit: More Coverity Fixes
Date Thu, 25 Feb 2016 02:36:10 GMT
Repository: incubator-asterixdb-hyracks
Updated Branches:
  refs/heads/master 3c8158679 -> 5507b7529


More Coverity Fixes

- CID 68210 (#1 of 1): Check of thread-shared field evades lock
acquisition (LOCK_EVASION)
6. thread1_overwrites_value_in_field: Thread1 sets index to a new
value. Now the two threads have an inconsistent view of index and
updates to fields of index or fields correlated with index may be
lost.

- CID 68209 (#1 of 1): Check of thread-shared field evades lock
acquisition (LOCK_EVASION)
6. thread1_overwrites_value_in_field: Thread1 sets index to a new
value. Now the two threads have an inconsistent view of index and
updates to fields of index or fields correlated with index may be
lost.

- CID 68208 (#1 of 1): Check of thread-shared field evades lock
acquisition (LOCK_EVASION)
6. thread1_overwrites_value_in_field: Thread1 sets index to a new
value. Now the two threads have an inconsistent view of index and
updates to fields of index or fields correlated with index may be
lost.

- CID 68435 (#1 of 1): UR: Uninitialized read of field in constructor
(FB.UR_UNINIT_READ)
1. defect: Uninitialized read of btreeCmp.

- CID 68416 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK_EXCEPTION_PATH)
1. defect:
org.apache.hyracks.storage.am.lsm.invertedindex.inmemory.PartitionedIn
MemoryInvertedIndex.updatePartitionIndexes(short) does not release
lock on all exception paths.

- CID 68415 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK)
1. defect:
org.apache.hyracks.storage.common.buffercache.BufferCache.sweepAndFlus
h(int, boolean) does not release lock on all paths.

- CID 68414 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK)
1. defect:
org.apache.hyracks.storage.common.buffercache.BufferCache.dumpState()
does not release lock on all paths.

- CID 68412 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK)
1. defect:
org.apache.hyracks.storage.am.lsm.common.impls.VirtualBufferCache.dele
teFile(int, boolean) does not release lock on all paths.

- CID 68337 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.

- CID 68336 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.

- CID 68335 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.

- CID 68334 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.

- CID 68259 (#1 of 1): Result is not floating-point
(UNINTENDED_INTEGER_DIVISION)
integer_division: Dividing integer expressions 2147483647 and 2, and
then converting the integer quotient to type double. Any remainder,
or fractional part of the quotient, is ignored.

Change-Id: I0f63f7fb75b1ac8ffc1fc1d70e66bb19b788fe8e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/661
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/commit/5507b752
Tree: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/tree/5507b752
Diff: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/diff/5507b752

Branch: refs/heads/master
Commit: 5507b75292f90c065354d2b2bfcdddc7605c1df2
Parents: 3c81586
Author: Michael Blow <michael.blow@couchbase.com>
Authored: Wed Feb 24 14:32:52 2016 -0500
Committer: Till Westmann <tillw@apache.org>
Committed: Wed Feb 24 18:30:55 2016 -0800

----------------------------------------------------------------------
 .../dataflow/std/structures/AbstractHeap.java   |  2 +-
 .../hyracks/dataflow/std/util/MathUtil.java     | 54 ------------------
 .../hyracks/dataflow/std/util/MathTest.java     | 44 ---------------
 .../DocumentStringFieldValueGenerator.java      |  4 +-
 .../datagen/PersonNameFieldValueGenerator.java  |  8 ++-
 .../datagen/StringFieldValueGenerator.java      |  4 +-
 .../common/util/TreeIndexBufferCacheWarmup.java |  3 +-
 .../dataflow/ExternalBTreeDataflowHelper.java   | 13 +++--
 .../ExternalBTreeWithBuddyDataflowHelper.java   | 13 +++--
 .../am/lsm/common/impls/VirtualBufferCache.java |  2 +-
 .../PartitionedInMemoryInvertedIndex.java       | 15 +++--
 .../dataflow/ExternalRTreeDataflowHelper.java   | 13 +++--
 .../lsm/rtree/impls/LSMRTreeAbstractCursor.java |  2 +-
 .../am/rtree/linearize/ZCurveIntComparator.java |  3 +-
 .../storage/common/buffercache/BufferCache.java |  4 +-
 .../java/org/apache/hyracks/util/MathUtil.java  | 58 ++++++++++++++++++++
 .../java/org/apache/hyracks/util/MathTest.java  | 44 +++++++++++++++
 17 files changed, 154 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
index a0abaf7..c6ca09b 100644
--- a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
+++ b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
@@ -21,7 +21,7 @@ package org.apache.hyracks.dataflow.std.structures;
 
 import java.util.Arrays;
 
-import org.apache.hyracks.dataflow.std.util.MathUtil;
+import org.apache.hyracks.util.MathUtil;
 
 public abstract class AbstractHeap implements IHeap<IResetableComparable> {
     protected static final int NOT_EXIST = -1;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java
b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java
deleted file mode 100644
index ebdeeef..0000000
--- a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.hyracks.dataflow.std.util;
-
-public class MathUtil {
-    /**
-     * Fast way to calculate the log2(x). Note: x should be >= 1.
-     *
-     * @param n
-     * @return
-     */
-    public static int log2Floor(int n) {
-        assert n >= 1;
-        int log = 0;
-        if (n > 0xffff) {
-            n >>>= 16;
-            log = 16;
-        }
-
-        if (n > 0xff) {
-            n >>>= 8;
-            log |= 8;
-        }
-
-        if (n > 0xf) {
-            n >>>= 4;
-            log |= 4;
-        }
-
-        if (n > 0b11) {
-            n >>>= 2;
-            log |= 2;
-        }
-
-        return log + (n >>> 1);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java
b/hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java
deleted file mode 100644
index 3c8af9f..0000000
--- a/hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.hyracks.dataflow.std.util;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.Random;
-
-import org.junit.Test;
-
-public class MathTest {
-
-    @Test
-    public void testLog2() {
-        Random random = new Random(System.currentTimeMillis());
-        for (int i = 0; i < 31; i++) {
-            assertTrue(MathUtil.log2Floor((int) Math.pow(2, i)) == i);
-            for(int x = 0; x < 10; x++){
-                float extra = random.nextFloat();
-                while (extra >= 1.0){
-                    extra = random.nextFloat();
-                }
-                assertTrue(MathUtil.log2Floor((int) Math.pow(2, i + extra)) == i);
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
index cff11dc..1e8077c 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
@@ -27,6 +27,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
 
+import org.apache.hyracks.util.MathUtil;
+
 public class DocumentStringFieldValueGenerator implements IFieldValueGenerator<String>
{
     private final String FIRST_NAMES_FILE = "dist.all.first.cleaned";
     private final String LAST_NAMES_FILE = "dist.all.last.cleaned";
@@ -82,7 +84,7 @@ public class DocumentStringFieldValueGenerator implements IFieldValueGenerator<S
     @Override
     public String next() {
         StringBuilder strBuilder = new StringBuilder();
-        int numWords = Math.abs(rnd.nextInt()) % (docMaxWords - docMinWords + 1) + docMinWords;
+        int numWords = MathUtil.stripSignBit(rnd.nextInt()) % (docMaxWords - docMinWords
+ 1) + docMinWords;
         for (int i = 0; i < numWords; i++) {
             int ix = ProbabilityHelper.choose(cumulIntRanges, rnd.nextInt());
             strBuilder.append(tokenDict.get(ix));

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
index 49edafb..5af0b0f 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
@@ -27,6 +27,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
 
+import org.apache.hyracks.util.MathUtil;
+
 public class PersonNameFieldValueGenerator implements IFieldValueGenerator<String>
{
     private final String FIRST_NAMES_FILE = "dist.all.first.cleaned";
     private final String LAST_NAMES_FILE = "dist.all.last.cleaned";
@@ -76,20 +78,20 @@ public class PersonNameFieldValueGenerator implements IFieldValueGenerator<Strin
         StringBuilder strBuilder = new StringBuilder();
 
         // First name.
-        int fix = Math.abs(rnd.nextInt()) % firstNames.size();
+        int fix = MathUtil.stripSignBit(rnd.nextInt()) % firstNames.size();
         strBuilder.append(firstNames.get(fix));
         strBuilder.append(" ");
 
         // Optional middle initial.
         double d = Math.abs(rnd.nextDouble());
         if (d <= middleInitialProb) {
-            int mix = Math.abs(rnd.nextInt()) % letters.length();
+            int mix = MathUtil.stripSignBit(rnd.nextInt()) % letters.length();
             strBuilder.append(letters.charAt(mix));
             strBuilder.append(". ");
         }
 
         // Last name.
-        int lix = Math.abs(rnd.nextInt()) % lastNames.size();
+        int lix = MathUtil.stripSignBit(rnd.nextInt()) % lastNames.size();
         strBuilder.append(lastNames.get(lix));
 
         return strBuilder.toString();

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
index c337462..9418447 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
@@ -21,6 +21,8 @@ package org.apache.hyracks.storage.am.common.datagen;
 
 import java.util.Random;
 
+import org.apache.hyracks.util.MathUtil;
+
 public class StringFieldValueGenerator implements IFieldValueGenerator<String> {
     private int maxLen;
     private final Random rnd;
@@ -39,7 +41,7 @@ public class StringFieldValueGenerator implements IFieldValueGenerator<String>
{
         String s = Long.toHexString(Double.doubleToLongBits(rnd.nextDouble()));
         StringBuilder strBuilder = new StringBuilder();
         for (int i = 0; i < s.length() && i < maxLen; i++) {
-            strBuilder.append(s.charAt(Math.abs(rnd.nextInt()) % s.length()));
+            strBuilder.append(s.charAt(MathUtil.stripSignBit(rnd.nextInt()) % s.length()));
         }
         return strBuilder.toString();
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
index 398a3f3..d9013d3 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Random;
 
 import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.util.MathUtil;
 import org.apache.hyracks.storage.am.common.api.IMetaDataPageManager;
 import org.apache.hyracks.storage.am.common.api.ITreeIndexFrame;
 import org.apache.hyracks.storage.am.common.api.ITreeIndexMetaDataFrame;
@@ -84,7 +85,7 @@ public class TreeIndexBufferCacheWarmup {
 
 					int remainingLength = pageIds.size();
 					for (int j = 0; j < pageIds.size(); j++) {
-						int index = Math.abs(rnd.nextInt()) % remainingLength;
+						int index = MathUtil.stripSignBit(rnd.nextInt()) % remainingLength;
 						int pageId = remainingPageIds[index];
 
 						// pin & latch then immediately unlatch & unpin

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
index 44d81ab..c82bf28 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
@@ -56,13 +56,16 @@ public class ExternalBTreeDataflowHelper extends LSMBTreeDataflowHelper
{
 
     @Override
     public IIndex getIndexInstance() {
-        if (index != null)
+        if (index != null) {
             return index;
+        }
         synchronized (lcManager) {
-            try {
-                index = lcManager.getIndex(resourcePath);
-            } catch (HyracksDataException e) {
-                return null;
+            if (index == null) {
+                try {
+                    index = lcManager.getIndex(resourcePath);
+                } catch (HyracksDataException e) {
+                    return null;
+                }
             }
         }
         return index;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
index 81beadd..56e9014 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
@@ -57,13 +57,16 @@ public class ExternalBTreeWithBuddyDataflowHelper extends AbstractLSMIndexDatafl
 
     @Override
     public IIndex getIndexInstance() {
-        if (index != null)
+        if (index != null) {
             return index;
+        }
         synchronized (lcManager) {
-            try {
-                index = lcManager.getIndex(resourcePath);
-            } catch (HyracksDataException e) {
-                return null;
+            if (index == null) {
+                try {
+                    index = lcManager.getIndex(resourcePath);
+                } catch (HyracksDataException e) {
+                    return null;
+                }
             }
         }
         return index;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
b/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
index 272f970..6b8cf35 100644
--- a/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
+++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
@@ -96,7 +96,7 @@ public class VirtualBufferCache implements IVirtualBufferCache {
         }
 
         for (int i = 0; i < buckets.length; i++) {
-            CacheBucket bucket = buckets[i];
+            final CacheBucket bucket = buckets[i];
             bucket.bucketLock.lock();
             try {
                 VirtualPage prev = null;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
index 273aa16..39dcd4a 100644
--- a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
+++ b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
@@ -72,13 +72,16 @@ public class PartitionedInMemoryInvertedIndex extends InMemoryInvertedIndex
impl
 
     public void updatePartitionIndexes(short numTokens) {
         partitionIndexLock.writeLock().lock();
-        if (numTokens < minPartitionIndex) {
-            minPartitionIndex = numTokens;
+        try {
+            if (numTokens < minPartitionIndex) {
+                minPartitionIndex = numTokens;
+            }
+            if (numTokens > maxPartitionIndex) {
+                maxPartitionIndex = numTokens;
+            }
+        } finally {
+            partitionIndexLock.writeLock().unlock();
         }
-        if (numTokens > maxPartitionIndex) {
-            maxPartitionIndex = numTokens;
-        }
-        partitionIndexLock.writeLock().unlock();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
index 6f1c34a..48cc476 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
@@ -72,13 +72,16 @@ public class ExternalRTreeDataflowHelper extends LSMRTreeDataflowHelper
{
 
     @Override
     public IIndex getIndexInstance() {
-        if (index != null)
+        if (index != null) {
             return index;
+        }
         synchronized (lcManager) {
-            try {
-                index = lcManager.getIndex(resourcePath);
-            } catch (HyracksDataException e) {
-                return null;
+            if (index == null) {
+                try {
+                    index = lcManager.getIndex(resourcePath);
+                } catch (HyracksDataException e) {
+                    return null;
+                }
             }
         }
         return index;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
index d5257fe..c8f05c2 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
@@ -67,7 +67,7 @@ public abstract class LSMRTreeAbstractCursor implements ITreeIndexCursor
{
 
     public LSMRTreeAbstractCursor(ILSMIndexOperationContext opCtx) {
         this.opCtx = opCtx;
-        btreeRangePredicate = new RangePredicate(null, null, true, true, btreeCmp, btreeCmp);
+        btreeRangePredicate = new RangePredicate(null, null, true, true, null, null);
     }
 
     public RTreeSearchCursor getCursor(int cursorIndex) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
b/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
index f62ae27..2f372e2 100644
--- a/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
+++ b/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
@@ -21,7 +21,6 @@ package org.apache.hyracks.storage.am.rtree.linearize;
 import org.apache.hyracks.api.dataflow.value.ILinearizeComparator;
 import org.apache.hyracks.data.std.primitive.DoublePointable;
 import org.apache.hyracks.data.std.primitive.IntegerPointable;
-import org.apache.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
 import org.apache.hyracks.storage.am.common.ophelpers.DoubleArrayList;
 
 /*
@@ -48,7 +47,7 @@ public class ZCurveIntComparator implements ILinearizeComparator {
     }
 
     private void resetStateMachine() {
-        stepsize = Integer.MAX_VALUE / 2;
+        stepsize = Integer.MAX_VALUE / 2.0f;
         bounds = new double[dim];
         boundsStack.clear();
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
index 75adfc9..27d0423 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
@@ -448,7 +448,7 @@ public class BufferCache implements IBufferCacheInternal, ILifeCycleComponent
{
         buffer.append("cpid -> [fileId:pageId, pinCount, valid/invalid, confiscated/physical,
dirty/clean]");
         int nCachedPages = 0;
         for (int i = 0; i < pageMap.length; ++i) {
-            CacheBucket cb = pageMap[i];
+            final CacheBucket cb = pageMap[i];
             cb.bucketLock.lock();
             try {
                 CachedPage cp = cb.cachedPage;
@@ -786,7 +786,7 @@ public class BufferCache implements IBufferCacheInternal, ILifeCycleComponent
{
 
     private void sweepAndFlush(int fileId, boolean flushDirtyPages) throws HyracksDataException
{
         for (int i = 0; i < pageMap.length; ++i) {
-            CacheBucket bucket = pageMap[i];
+            final CacheBucket bucket = pageMap[i];
             bucket.bucketLock.lock();
             try {
                 CachedPage prev = bucket.cachedPage;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java b/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java
new file mode 100644
index 0000000..2b157e4
--- /dev/null
+++ b/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java
@@ -0,0 +1,58 @@
+/*
+ * 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.hyracks.util;
+
+public class MathUtil {
+    /**
+     * Fast way to calculate the log2(x). Note: x should be >= 1.
+     *
+     * @param n
+     * @return
+     */
+    public static int log2Floor(int n) {
+        assert n >= 1;
+        int log = 0;
+        if (n > 0xffff) {
+            n >>>= 16;
+            log = 16;
+        }
+
+        if (n > 0xff) {
+            n >>>= 8;
+            log |= 8;
+        }
+
+        if (n > 0xf) {
+            n >>>= 4;
+            log |= 4;
+        }
+
+        if (n > 0b11) {
+            n >>>= 2;
+            log |= 2;
+        }
+
+        return log + (n >>> 1);
+    }
+
+    public static int stripSignBit(int n) {
+        return n & 0x7fffffff;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/5507b752/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java
----------------------------------------------------------------------
diff --git a/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java b/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java
new file mode 100644
index 0000000..c3443c8
--- /dev/null
+++ b/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.hyracks.util;
+
+import java.util.Random;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class MathTest {
+
+    @Test
+    public void testLog2() {
+        Random random = new Random(System.currentTimeMillis());
+        for (int i = 0; i < 31; i++) {
+            assertTrue(MathUtil.log2Floor((int) Math.pow(2, i)) == i);
+            for(int x = 0; x < 10; x++){
+                float extra = random.nextFloat();
+                while (extra >= 1.0){
+                    extra = random.nextFloat();
+                }
+                assertTrue(MathUtil.log2Floor((int) Math.pow(2, i + extra)) == i);
+            }
+        }
+    }
+}


Mime
View raw message