accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [53/61] [abbrv] accumulo git commit: ACCUMULO-722 merge fix to RFile from trunk
Date Thu, 03 Mar 2016 22:00:18 GMT
ACCUMULO-722 merge fix to RFile from trunk

git-svn-id: https://svn.apache.org/repos/asf/accumulo/branches/ACCUMULO-722@1376579 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/76337f2a
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/76337f2a
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/76337f2a

Branch: refs/heads/ACCUMULO-722
Commit: 76337f2aa09ececc05db56adb4372660f316eb03
Parents: 1b36435
Author: Eric C. Newton <ecn@apache.org>
Authored: Thu Aug 23 16:32:43 2012 +0000
Committer: Eric C. Newton <ecn@apache.org>
Committed: Thu Aug 23 16:32:43 2012 +0000

----------------------------------------------------------------------
 .../accumulo/core/file/rfile/RelativeKey.java   | 38 ++++++++++++----
 .../core/file/rfile/RelativeKeyTest.java        | 47 ++++++++++++++++++++
 .../apache/accumulo/server/util/Initialize.java |  2 +-
 3 files changed, 78 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/76337f2a/1.5/core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java b/1.5/core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java
index 1711765..976bac2 100644
--- a/1.5/core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java
@@ -47,7 +47,7 @@ public class RelativeKey implements WritableComparable<RelativeKey>
{
   private static final byte CV_SAME = 0x08;
   private static final byte TS_SAME = 0x10;
   private static final byte DELETED = 0x20;
-  
+
   private static HashMap<Text,Integer> colFams = new HashMap<Text,Integer>();
   
   private static long bytesWritten = 0;
@@ -361,15 +361,37 @@ public class RelativeKey implements WritableComparable<RelativeKey>
{
     read(in, mbseq, len);
   }
   
+  /**
+   * Determines what next array size should be by rounding up to next power of two.
+   * 
+   */
+  static int nextArraySize(int i) {
+    if (i < 0)
+      throw new IllegalArgumentException();
+    
+    if (i > (1 << 30))
+      return Integer.MAX_VALUE; // this is the next power of 2 minus one... a special case
+
+    if (i == 0) {
+      return 1;
+    }
+    
+    // round up to next power of two
+    int ret = i;
+    ret--;
+    ret |= ret >> 1;
+    ret |= ret >> 2;
+    ret |= ret >> 4;
+    ret |= ret >> 8;
+    ret |= ret >> 16;
+    ret++;
+    
+    return ret;
+  }
+
   private void read(DataInput in, MByteSequence mbseq, int len) throws IOException {
     if (mbseq.getBackingArray().length < len) {
-      int newLen = mbseq.getBackingArray().length;
-      
-      while (newLen < len) {
-        newLen = newLen * 2;
-      }
-      
-      mbseq.setArray(new byte[newLen]);
+      mbseq.setArray(new byte[nextArraySize(len)]);
     }
     
     in.readFully(mbseq.getBackingArray(), 0, len);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/76337f2a/1.5/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java
b/1.5/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java
new file mode 100644
index 0000000..25eae25
--- /dev/null
+++ b/1.5/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java
@@ -0,0 +1,47 @@
+/**
+ * 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.accumulo.core.file.rfile;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public class RelativeKeyTest extends TestCase {
+  public void test1() {
+    assertEquals(1, RelativeKey.nextArraySize(0));
+    assertEquals(1, RelativeKey.nextArraySize(1));
+    assertEquals(2, RelativeKey.nextArraySize(2));
+    assertEquals(4, RelativeKey.nextArraySize(3));
+    assertEquals(4, RelativeKey.nextArraySize(4));
+    assertEquals(8, RelativeKey.nextArraySize(5));
+    assertEquals(8, RelativeKey.nextArraySize(8));
+    assertEquals(16, RelativeKey.nextArraySize(9));
+    
+    assertEquals(1 << 16, RelativeKey.nextArraySize((1 << 16) - 1));
+    assertEquals(1 << 16, RelativeKey.nextArraySize(1 << 16));
+    assertEquals(1 << 17, RelativeKey.nextArraySize((1 << 16) + 1));
+    
+    assertEquals(1 << 30, RelativeKey.nextArraySize((1 << 30) - 1));
+
+    assertEquals(1 << 30, RelativeKey.nextArraySize(1 << 30));
+
+    assertEquals(Integer.MAX_VALUE, RelativeKey.nextArraySize(Integer.MAX_VALUE - 1));
+    assertEquals(Integer.MAX_VALUE, RelativeKey.nextArraySize(Integer.MAX_VALUE));
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/76337f2a/1.5/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
----------------------------------------------------------------------
diff --git a/1.5/server/src/main/java/org/apache/accumulo/server/util/Initialize.java b/1.5/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
index 6ecbab2..d7a7ad7 100644
--- a/1.5/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
+++ b/1.5/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
@@ -417,7 +417,7 @@ public class Initialize {
     for (String tableId  :"0,1,2".split(",")) {
       String configPath = zkInstanceRoot + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_CONF
+ "/";
       ZooReaderWriter.getInstance().putPersistentData(configPath + Property.TABLE_MAJC_RATIO.getKey(),
"1".getBytes(), NodeExistsPolicy.FAIL);
-      //ZooReaderWriter.getInstance().putPersistentData(configPath + Property.TABLE_BLOCKCACHE_ENABLED,
"true".getBytes(), NodeExistsPolicy.FAIL);
+      ZooReaderWriter.getInstance().putPersistentData(configPath + Property.TABLE_BLOCKCACHE_ENABLED,
"true".getBytes(), NodeExistsPolicy.FAIL);
     }
     ZooReaderWriter zoo = ZooReaderWriter.getInstance();
     zoo.putPersistentData(zkInstanceRoot + Constants.ZTSERVERS, new byte[0], NodeExistsPolicy.FAIL);


Mime
View raw message