@TimeDepend
  @Test
  public void testGetWith_Ts() throws Exception {
    recreateTable();
    fillData();

    Get get = new Get(rowKey_ForTest);
    get.addColumn(ColumnFamilyNameBytes, QName1);
    get.setMaxVersions(3);

    get.setTimeStamp(3L);
    Result result = table.get(get);
    Assert.assertEquals(1, result.raw().length);

    get.setTimeStamp(2L);
    result = table.get(get);
    Assert.assertEquals(1, result.raw().length);

    get.setTimeStamp(1L);
    result = table.get(get);
    Assert.assertEquals(1, result.raw().length);

    get.setTimeStamp(0L);
    result = table.get(get);
    Assert.assertEquals(0, result.raw().length);

    get.setTimeRange(1, 4);
    result = table.get(get);
    Assert.assertEquals(3, result.raw().length);

    recreateTable();
  }
Beispiel #2
0
  public static String get(String keyspace, String rowKey, String column, long timestamp)
      throws Exception {
    String columnValue = null;

    HTable htable = new HTable(keyspace);
    Get get = new Get(rowKey.getBytes());
    get = get.setTimeStamp(timestamp);
    get = get.setMaxVersions();

    Result res = htable.get(get);

    KeyValue[] data = res.raw();

    for (int i = 0; i < data.length; i++) {
      KeyValue d = data[i];
      String family = new String(data[i].getFamily());
      String qualifier = new String(data[i].getQualifier());
      if (qualifier.toLowerCase().equals(column.toLowerCase())) {
        columnValue = new String(d.getValue());
        System.out.println(
            data[i].toString()
                + " Family:"
                + family
                + " Qualifier:"
                + qualifier
                + " Value:"
                + columnValue);
        break;
      }
    }

    return columnValue;
  }
Beispiel #3
0
 @SuppressWarnings("deprecation")
 @Override
 public void rollbackRow(byte[] row, long startId, Integer lockId) throws IOException {
   byte[] family = DominoConst.INNER_FAMILY;
   Get get = new Get(row);
   get.setTimeStamp(startId);
   get.addFamily(family);
   Result r = region.get(get, lockId);
   if (r == null || r.isEmpty()) return;
   byte[] colBytes = r.getValue(family, DominoConst.COLUMNS_COL);
   if (colBytes == null || colBytes.length == 0) return;
   Delete del = new Delete(row);
   Columns cols = new Columns(colBytes);
   for (Column col : cols.cols) {
     del.deleteColumn(col.family, col.qualifier, startId);
   }
   del.deleteColumn(family, DominoConst.COLUMNS_COL, startId);
   del.deleteColumn(family, DominoConst.STATUS_COL, startId);
   mutateRow(del, lockId);
 }
 @Override
 public Row get() {
   if (row == null) {
     if (searchRow != null) {
       Result r;
       try {
         Get get = new Get(HBaseUtils.toBytes(searchRow.getRowKey()));
         get.setTimeStamp(searchTimestamp);
         if (columns != null) {
           for (Column c : columns) {
             if (c.isRowKeyColumn()) continue;
             else if (c.getColumnFamilyName() != null)
               get.addColumn(c.getColumnFamilyNameAsBytes(), c.getNameAsBytes());
             else get.addColumn(defaultColumnFamilyName, c.getNameAsBytes());
           }
         }
         r = secondaryIndex.dataTable.get(get);
       } catch (IOException e) {
         throw DbException.convert(e);
       }
       if (r != null) {
         Value[] data = new Value[columns.size()];
         Value rowKey = ValueString.get(Bytes.toString(r.getRow()));
         if (columns != null) {
           int i = 0;
           for (Column c : columns) {
             i = c.getColumnId();
             if (c.isRowKeyColumn()) data[i] = rowKey;
             else
               data[i] =
                   HBaseUtils.toValue( //
                       r.getValue(c.getColumnFamilyNameAsBytes(), c.getNameAsBytes()),
                       c.getType());
           }
         }
         row = new HBaseRow(null, rowKey, data, Row.MEMORY_CALCULATE, r);
       }
     }
   }
   return row;
 }
Beispiel #5
0
 @Override
 public GetBuilder setTimeStamp(long timestamp) throws IOException {
   get.setTimeStamp(timestamp);
   return this;
 }
Beispiel #6
0
 /**
  * Clear the data out of version window & write them to the second lowest version.
  *
  * @param commit
  * @param versions
  * @param r
  * @param row
  * @param isDelete
  * @param commitId
  * @param startId
  * @param lockId
  * @return
  * @throws IOException
  */
 @SuppressWarnings("deprecation")
 private boolean addClearColumns(
     Put commit,
     List<KeyValue> versions,
     Result r,
     byte[] row,
     boolean isDelete,
     long commitId,
     long startId,
     Integer lockId)
     throws IOException {
   KeyValue commitKV =
       new KeyValue(
           row,
           DominoConst.INNER_FAMILY,
           DominoConst.VERSION_COL,
           commitId,
           DominoConst.versionValue(startId, isDelete));
   NavigableSet<KeyValue> orderedVersions = new TreeSet<KeyValue>(MVCC.VERSION_KV_COMPARATOR);
   orderedVersions.add(versions.get(versions.size() - 1));
   if (versions.size() >= 2) {
     orderedVersions.add(versions.get(versions.size() - 2));
   }
   orderedVersions.add(commitKV);
   Iterator<KeyValue> it = orderedVersions.descendingIterator();
   KeyValue remove = it.next();
   KeyValue prev = it.next();
   byte[] removeValue = remove.getValue();
   byte[] prevValue = prev.getValue();
   long removeCommitId = remove.getTimestamp();
   long removeStartId = DominoConst.getVersion(removeValue);
   long prevStartId = DominoConst.getVersion(prevValue);
   boolean isFresh = (removeCommitId != commitId);
   Columns removeCols = new Columns(DominoConst.getColumnsAt(r, removeStartId));
   if (!DominoConst.isDeleteVersion(removeValue) && !DominoConst.isDeleteVersion(prevValue)) {
     Columns prevCols = new Columns(DominoConst.getColumnsAt(r, prevStartId));
     Get get = new Get(row);
     get.setTimeStamp(removeStartId);
     Result res = region.get(get, lockId);
     for (Column col : removeCols.cols) {
       if (prevCols.contains(col.family, col.qualifier)) {
         continue; // a newer value
       }
       // merge it
       byte[] value = res.getValue(col.family, col.qualifier);
       prevCols.add(col.family, col.qualifier);
       commit.add(col.family, col.qualifier, prevStartId, value);
     }
     commit.add(
         DominoConst.INNER_FAMILY, DominoConst.COLUMNS_COL, prevStartId, prevCols.toByteArray());
   }
   if (isFresh) {
     commit.add(
         new KeyValue(
             row,
             DominoConst.INNER_FAMILY,
             DominoConst.VERSION_COL,
             removeCommitId,
             KeyValue.Type.Delete));
   }
   commit.add(
       new KeyValue(
           row,
           DominoConst.INNER_FAMILY,
           DominoConst.COLUMNS_COL,
           removeStartId,
           KeyValue.Type.Delete));
   for (Column col : removeCols.cols) {
     commit.add(new KeyValue(row, col.family, col.qualifier, removeStartId, KeyValue.Type.Delete));
   }
   return isFresh;
 }