You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 19:43:53 UTC
svn commit: r1181951 [3/3] - in /hbase/branches/0.89/src:
main/java/org/apache/hadoop/hbase/client/
main/java/org/apache/hadoop/hbase/ipc/
main/java/org/apache/hadoop/hbase/regionserver/
main/java/org/apache/hadoop/hbase/thrift/ main/java/org/apache/ha...
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IOError.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IOError.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IOError.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IOError.java Tue Oct 11 17:43:52 2011
@@ -1,19 +1,7 @@
/**
- * 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
+ * Autogenerated by Thrift
*
- * 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.
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.hadoop.hbase.thrift.generated;
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IllegalArgument.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IllegalArgument.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IllegalArgument.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/IllegalArgument.java Tue Oct 11 17:43:52 2011
@@ -1,19 +1,7 @@
/**
- * 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
+ * Autogenerated by Thrift
*
- * 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.
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.hadoop.hbase.thrift.generated;
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/Mutation.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/Mutation.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/Mutation.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/Mutation.java Tue Oct 11 17:43:52 2011
@@ -1,19 +1,7 @@
/**
- * 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
+ * Autogenerated by Thrift
*
- * 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.
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.hadoop.hbase.thrift.generated;
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TCell.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TCell.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TCell.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TCell.java Tue Oct 11 17:43:52 2011
@@ -1,19 +1,7 @@
/**
- * 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
+ * Autogenerated by Thrift
*
- * 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.
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.hadoop.hbase.thrift.generated;
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRegionInfo.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRegionInfo.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRegionInfo.java Tue Oct 11 17:43:52 2011
@@ -1,19 +1,7 @@
/**
- * 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
+ * Autogenerated by Thrift
*
- * 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.
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.hadoop.hbase.thrift.generated;
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRowResult.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRowResult.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRowResult.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/thrift/generated/TRowResult.java Tue Oct 11 17:43:52 2011
@@ -1,19 +1,7 @@
/**
- * 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
+ * Autogenerated by Thrift
*
- * 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.
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package org.apache.hadoop.hbase.thrift.generated;
Modified: hbase/branches/0.89/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift (original)
+++ hbase/branches/0.89/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift Tue Oct 11 17:43:52 2011
@@ -377,6 +377,52 @@ service Hbase {
) throws (1:IOError io)
/**
+ * Get multiple rows with the same columns or timestamps for all.
+ * This returns latest entries, all columns and cfs.
+ *
+ * @return TRowResult containing the row and map of columns to TCells
+ */
+ list<TRowResult> getRows(
+ 1:Text tableName,
+ 2:list<Text> rows,
+ ) throws (1:IOError io)
+
+ /**
+ * Get multiple rows only up to a certain timestamp
+ *
+ * @return TRowResult containing the row and map of columns to TCells
+ */
+ list<TRowResult> getRowsTs(
+ 1:Text tableName,
+ 2:list<Text> rows,
+ 3:i64 timestamp
+ ) throws (1:IOError io)
+
+ /**
+ * Get multiple rows only with particular cf:qualifier pairs on all rows
+ *
+ * @return TRowResult containing the row and map of columns to TCells
+ */
+ list<TRowResult> getRowsWithColumns(
+ 1:Text tableName,
+ 2:list<Text> rows,
+ 3:list<Text> families
+ ) throws (1:IOError io)
+
+ /**
+ * Get multiple rows only with particular cf:qualifier pairs on all rows
+ * and only up to a particular timestamp.
+ *
+ * @return TRowResult containing the row and map of columns to TCells
+ */
+ list<TRowResult> getRowsWithColumnsTs(
+ 1:Text tableName,
+ 2:list<Text> rows,
+ 3:list<Text> families
+ 4:i64 timestamp
+ ) throws (1:IOError io)
+
+ /**
* Apply a series of mutations (updates/deletes) to a row in a
* single transaction. If an exception is thrown, then the
* transaction is aborted. Default current timestamp is used, and
@@ -445,6 +491,50 @@ service Hbase {
) throws (1:IOError io, 2:IllegalArgument ia)
/**
+ * Applies a list of mutations to a single row only if the value for
+ * row, cf[:qualifier] equals valueCheck
+ *
+ * Accepts null or '' for valueCheck, in which case entry for
+ * row, cf[:qualifier] must not exist.
+ *
+ * @return bool whether the check passed and mutations were applied
+ */
+ bool checkAndMutateRow(
+ /** name of table */
+ 1:Text tableName,
+
+ /** row key */
+ 2:Text row,
+
+ 3:Text columnCheck,
+ 4:Text valueCheck,
+ /** list of mutation commands */
+ 5:list<Mutation> mutations,
+ ) throws (1:IOError io, 2:IllegalArgument ia)
+
+ /**
+ * Same as above, but the puts and deletes are added at specified timestamp.
+ *
+ * NOTE: No way to specify what timerange to query for the checked value;
+ * it will look for most recent entry (the default Get behavior).
+ */
+ bool checkAndMutateRowTs(
+ /** name of table */
+ 1:Text tableName,
+
+ /** row key */
+ 2:Text row,
+
+ 3:Text columnCheck,
+ 4:Text valueCheck,
+ /** list of mutation commands */
+ 5:list<Mutation> mutations,
+
+ /** timestamp */
+ 6:i64 timestamp
+ ) throws (1:IOError io, 2:IllegalArgument ia)
+
+ /**
* Atomically increment the column value specified. Returns the next value post increment.
*/
i64 atomicIncrement(
Modified: hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Tue Oct 11 17:43:52 2011
@@ -32,8 +32,10 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
@@ -3376,19 +3378,24 @@ public class TestFromClientSide {
}
@Test
- public void testRowsPut() throws IOException {
+ public void testRowsPutMultiGet() throws IOException {
final byte[] CONTENTS_FAMILY = Bytes.toBytes("contents");
final byte[] SMALL_FAMILY = Bytes.toBytes("smallfam");
final int NB_BATCH_ROWS = 10;
- final byte[] value = Bytes.toBytes("abcd");
+ final String value = "abcd";
HTable table = TEST_UTIL.createTable(Bytes.toBytes("testRowsPut"),
new byte[][] {CONTENTS_FAMILY, SMALL_FAMILY });
ArrayList<Put> rowsUpdate = new ArrayList<Put>();
+ ArrayList<Get> rowsGets = new ArrayList<Get>();
for (int i = 0; i < NB_BATCH_ROWS; i++) {
byte[] row = Bytes.toBytes("row" + i);
Put put = new Put(row);
- put.add(CONTENTS_FAMILY, null, value);
+ put.add(CONTENTS_FAMILY, null, Bytes.toBytes(value + i));
rowsUpdate.add(put);
+
+ Get get = new Get(row);
+ get.addFamily(CONTENTS_FAMILY);
+ rowsGets.add(get);
}
table.put(rowsUpdate);
Scan scan = new Scan();
@@ -3399,6 +3406,28 @@ public class TestFromClientSide {
Result row : scanner)
nbRows++;
assertEquals(NB_BATCH_ROWS, nbRows);
+
+ // now multi get!!
+ Result[] reses = table.get(rowsGets);
+ assertEquals(NB_BATCH_ROWS, reses.length);
+ int i = 0;
+ for (Result r : reses) {
+ assertEquals(r.getValue(CONTENTS_FAMILY, null).length, 5);
+ assertEquals(new String(r.getValue(CONTENTS_FAMILY, null)), value + i);
+ i++;
+ }
+
+ // make sure order is preserved by multi get!
+ Collections.reverse(rowsGets);
+ reses = table.get(rowsGets);
+ assertEquals(NB_BATCH_ROWS, reses.length);
+ i = 1;
+ for (Result r : reses) {
+ assertEquals(r.getValue(CONTENTS_FAMILY, null).length, 5);
+ assertEquals(new String(r.getValue(CONTENTS_FAMILY, null)), value
+ + (NB_BATCH_ROWS - i));
+ i++;
+ }
}
@Test
Modified: hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java?rev=1181951&r1=1181950&r2=1181951&view=diff
==============================================================================
--- hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java (original)
+++ hbase/branches/0.89/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java Tue Oct 11 17:43:52 2011
@@ -62,6 +62,8 @@ public class TestThriftServer extends HB
doTestTableMutations();
doTestTableTimestampsAndColumns();
doTestTableScanners();
+ doTestTableMultiGet();
+ doTestTableCheckAndMutate();
}
/**
@@ -306,9 +308,113 @@ public class TestThriftServer extends HB
}
/**
+ * Tests some of the getRows*() calls.
*
- * @return a List of ColumnDescriptors for use in creating a table. Has one
- * default ColumnDescriptor and one ColumnDescriptor with fewer versions
+ * @throws Exception
+ */
+ public void doTestTableMultiGet() throws Exception {
+ // Setup
+ ThriftServer.HBaseHandler handler = new ThriftServer.HBaseHandler();
+ handler.createTable(tableAname, getColumnDescriptors());
+
+ // Apply timestamped Mutations to rowA
+ long time1 = System.currentTimeMillis();
+ handler.mutateRowTs(tableAname, rowAname, getMutations(), time1);
+
+ // Sleep to assure that 'time1' and 'time2' will be different even with a
+ // coarse grained system timer.
+ Thread.sleep(1000);
+
+ // Apply timestamped BatchMutations for rowA and rowB
+ long time2 = System.currentTimeMillis();
+ handler.mutateRowsTs(tableAname, getBatchMutations(), time2);
+
+ time1 += 1;
+
+ // test getting the two rows with a multiget
+ List<byte[]> rows = new ArrayList<byte[]>();
+ rows.add(rowAname);
+ rows.add(rowBname);
+
+ List<TRowResult> results = handler.getRows(tableAname, rows);
+ assertEquals(results.get(0).row, rowAname);
+ assertEquals(results.get(1).row, rowBname);
+
+ assertEquals(results.get(0).columns.get(columnBname).value, valueCname);
+ assertEquals(results.get(1).columns.get(columnAname).value, valueCname);
+ assertEquals(results.get(1).columns.get(columnBname).value, valueDname);
+
+ // Teardown
+ handler.disableTable(tableAname);
+ handler.deleteTable(tableAname);
+ }
+
+ /**
+ * Test some of the checkAndMutate calls
+ *
+ * @throws Exception
+ */
+ public void doTestTableCheckAndMutate() throws Exception {
+ // Setup
+ ThriftServer.HBaseHandler handler = new ThriftServer.HBaseHandler();
+ handler.createTable(tableAname, getColumnDescriptors());
+
+ // Apply timestamped Mutations to rowA
+ long time1 = System.currentTimeMillis();
+ handler.checkAndMutateRowTs(tableAname, rowAname, columnAname, null,
+ getMutations(), time1);
+
+ List<TRowResult> res1 = handler.getRow(tableAname, rowAname);
+ // Check that all went according to plan
+ assertEquals(res1.get(0).columns.get(columnAname).value, valueAname);
+ assertEquals(res1.get(0).columns.get(columnBname).value, valueBname);
+
+ // Sleep to assure that 'time1' and 'time2' will be different even with a
+ // coarse grained system timer.
+ Thread.sleep(1000);
+
+ // Apply later timestamped mutations to rowA
+ long time2 = System.currentTimeMillis();
+
+ // Mess stuff up; shouldn't pass, null check value
+ handler.checkAndMutateRowTs(tableAname, rowAname, columnAname, null,
+ getMutations2(), time2);
+ handler.checkAndMutateRowTs(tableAname, rowAname, columnBname, null,
+ getMutations2(), time2);
+
+ // Check that all still the same!
+ assertEquals(res1.get(0).columns.get(columnAname).value, valueAname);
+ assertEquals(res1.get(0).columns.get(columnBname).value, valueBname);
+
+ // Mess stuff up; shouldn't pass, wrong check value
+ handler.checkAndMutateRowTs(tableAname, rowAname, columnAname,
+ Bytes.toBytes("randovalue1"), getMutations2(), time2);
+ handler.checkAndMutateRowTs(tableAname, rowAname, columnBname,
+ Bytes.toBytes("randovalue2"), getMutations2(), time2);
+
+ // Check that all still the same!
+ assertEquals(res1.get(0).columns.get(columnAname).value, valueAname);
+ assertEquals(res1.get(0).columns.get(columnBname).value, valueBname);
+
+ // Now actually change things
+ handler.checkAndMutateRowTs(tableAname, rowAname, columnAname, valueAname,
+ getMutations2(), time2);
+
+ res1 = handler.getRow(tableAname, rowAname);
+
+ // Check that actually changed!
+ assertEquals(res1.get(0).columns.get(columnAname).value, valueCname);
+ assertEquals(res1.get(0).columns.get(columnBname).value, valueDname);
+ // Teardown
+ handler.disableTable(tableAname);
+ handler.deleteTable(tableAname);
+ }
+
+ /**
+ *
+ * @return a List of ColumnDescriptors for use in creating a table. Has one
+ * default ColumnDescriptor and one ColumnDescriptor with fewer
+ * versions
*/
private List<ColumnDescriptor> getColumnDescriptors() {
ArrayList<ColumnDescriptor> cDescriptors = new ArrayList<ColumnDescriptor>();
@@ -353,11 +459,21 @@ public class TestThriftServer extends HB
/**
*
- * @return a List of BatchMutations with the following effects:
- * (rowA, columnA): delete
- * (rowA, columnB): place valueC
- * (rowB, columnA): place valueC
- * (rowB, columnB): place valueD
+ * @return a List of Mutations for a row, with columnA having valueC and
+ * columnB having valueD
+ */
+ private List<Mutation> getMutations2() {
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(new Mutation(false, columnAname, valueCname));
+ mutations.add(new Mutation(false, columnBname, valueDname));
+ return mutations;
+ }
+
+ /**
+ *
+ * @return a List of BatchMutations with the following effects: (rowA,
+ * columnA): delete (rowA, columnB): place valueC (rowB, columnA):
+ * place valueC (rowB, columnB): place valueD
*/
private List<BatchMutation> getBatchMutations() {
List<BatchMutation> batchMutations = new ArrayList<BatchMutation>();