diff --git a/CHANGES.txt b/CHANGES.txt index 6e0a785c64c..05a2612c3bd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -73,6 +73,7 @@ Release 0.20.0 - Unreleased HBASE-1298 master.jsp & table.jsp do not URI Encode table or region names in links (Lars George via Stack) HBASE-1310 Off by one error in Bytes.vintToBytes + HBASE-1202 getRow does not always work when specifying number of versions IMPROVEMENTS HBASE-1089 Add count of regions on filesystem to master UI; add percentage diff --git a/src/java/org/apache/hadoop/hbase/io/Cell.java b/src/java/org/apache/hadoop/hbase/io/Cell.java index 12d3f85c294..4e95695b7cf 100644 --- a/src/java/org/apache/hadoop/hbase/io/Cell.java +++ b/src/java/org/apache/hadoop/hbase/io/Cell.java @@ -132,25 +132,16 @@ public class Cell implements Writable, Iterable>, } /** - * Add values and timestamps of another cell into this cell - * - * @param c - * Cell - */ - public void mergeCell(Cell c) { - valueMap.putAll(c.valueMap); - } - - /** - * Add a new timestamp and value to this cell + * Add a new timestamp and value to this cell provided timestamp does not + * already exist * * @param val - * value * @param ts - * timestamp */ public void add(byte[] val, long ts) { - valueMap.put(ts, val); + if (!valueMap.containsKey(ts)) { + valueMap.put(ts, val); + } } /** diff --git a/src/test/org/apache/hadoop/hbase/client/TestGetRowVersions.java b/src/test/org/apache/hadoop/hbase/client/TestGetRowVersions.java new file mode 100644 index 00000000000..7c6c370d485 --- /dev/null +++ b/src/test/org/apache/hadoop/hbase/client/TestGetRowVersions.java @@ -0,0 +1,104 @@ +/** + * Copyright 2009 The Apache Software Foundation + * + * 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.hadoop.hbase.client; + +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseClusterTestCase; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.io.BatchUpdate; +import org.apache.hadoop.hbase.io.Cell; +import org.apache.hadoop.hbase.io.RowResult; +import org.apache.hadoop.hbase.util.Bytes; + +/** + * + */ +public class TestGetRowVersions extends HBaseClusterTestCase { + private static final Log LOG = LogFactory.getLog(TestGetRowVersions.class); + private static final String TABLE_NAME = "test"; + private static final String CONTENTS_STR = "contents:"; + private static final String ROW = "row"; + private static final String COLUMN = "contents:contents"; + private static final long TIMESTAMP = System.currentTimeMillis(); + private static final String VALUE1 = "value1"; + private static final String VALUE2 = "value2"; + private HBaseAdmin admin = null; + private HTable table = null; + + @Override + public void setUp() throws Exception { + super.setUp(); + HTableDescriptor desc = new HTableDescriptor(TABLE_NAME); + desc.addFamily(new HColumnDescriptor(CONTENTS_STR)); + this.admin = new HBaseAdmin(conf); + this.admin.createTable(desc); + this.table = new HTable(conf, TABLE_NAME); + } + + /** @throws Exception */ + public void testGetRowMultipleVersions() throws Exception { + BatchUpdate b = new BatchUpdate(ROW, TIMESTAMP); + b.put(COLUMN, Bytes.toBytes(VALUE1)); + this.table.commit(b); + // Shut down and restart the HBase cluster + this.cluster.shutdown(); + this.zooKeeperCluster.shutdown(); + LOG.debug("HBase cluster shut down -- restarting"); + this.hBaseClusterSetup(); + // Make a new connection + this.table = new HTable(conf, TABLE_NAME); + // Overwrite previous value + b = new BatchUpdate(ROW, TIMESTAMP); + b.put(COLUMN, Bytes.toBytes(VALUE2)); + this.table.commit(b); + // Now verify that getRow(row, column, latest) works + RowResult r = table.getRow(ROW); + assertNotNull(r); + assertTrue(r.size() != 0); + Cell c = r.get(COLUMN); + assertNotNull(c); + assertTrue(c.getValue().length != 0); + String value = Bytes.toString(c.getValue()); + assertTrue(value.compareTo(VALUE2) == 0); + // Now check getRow with multiple versions + r = table.getRow(ROW, HConstants.ALL_VERSIONS); + for (Map.Entry e: r.entrySet()) { + // Column name +// System.err.print(" " + Bytes.toString(e.getKey())); + c = e.getValue(); + + // Need to iterate since there may be multiple versions + for (Iterator> it = c.iterator(); + it.hasNext(); ) { + Map.Entry v = it.next(); + value = Bytes.toString(v.getValue()); +// System.err.println(" = " + value); + assertTrue(VALUE2.compareTo(Bytes.toString(v.getValue())) == 0); + } + } + } +}