Exemplo n.º 1
1
 private static Put clonePut(Put put, long startId, boolean locking, byte[] columnsWritten) {
   Put ret = new Put(put.getRow());
   Map<byte[], List<KeyValue>> families = put.getFamilyMap();
   Columns cols = new Columns(columnsWritten);
   for (byte[] family : families.keySet()) {
     List<KeyValue> columns = families.get(family);
     Iterator<KeyValue> it = columns.iterator();
     while (it.hasNext()) {
       KeyValue kv = it.next();
       // byte[] column = DominoConst.getColumnKey(kv.getQualifier(), startId);
       byte[] qualifier = kv.getQualifier();
       ret.add(family, qualifier, startId, kv.getValue());
       cols.add(family, qualifier);
     }
   }
   Map<String, byte[]> attributes = put.getAttributesMap();
   for (String key : attributes.keySet()) {
     ret.setAttribute(key, attributes.get(key));
   }
   byte[] state = new byte[1 + Bytes.SIZEOF_LONG];
   state[0] = locking ? DominoConst.S_STATEFUL_BYTE : DominoConst.S_STATELESS_BYTE;
   Bytes.putLong(state, 1, startId);
   ret.add(DominoConst.INNER_FAMILY, DominoConst.COLUMNS_COL, startId, cols.toByteArray());
   ret.add(DominoConst.INNER_FAMILY, DominoConst.STATUS_COL, startId, state);
   return ret;
 }
Exemplo n.º 2
0
  /**
   * Transactional version of {@link HTable#put(Put)}
   *
   * @param transactionState Identifier of the transaction
   * @see HTable#put(Put)
   * @throws IOException
   */
  public void put(TransactionState transactionState, Put put)
      throws IOException, IllegalArgumentException {
    final long startTimestamp = transactionState.getStartTimestamp();
    //      byte[] startTSBytes = Bytes.toBytes(startTimestamp);
    // create put with correct ts
    final Put tsput = new Put(put.getRow(), startTimestamp);
    Map<byte[], List<KeyValue>> kvs = put.getFamilyMap();
    for (List<KeyValue> kvl : kvs.values()) {
      for (KeyValue kv : kvl) {
        //            int tsOffset = kv.getTimestampOffset();
        //            System.arraycopy(startTSBytes, 0, kv.getBuffer(), tsOffset,
        // Bytes.SIZEOF_LONG);
        tsput.add(
            new KeyValue(
                kv.getRow(), kv.getFamily(), kv.getQualifier(), startTimestamp, kv.getValue()));
      }
    }

    // should add the table as well
    transactionState.addRow(new RowKeyFamily(put.getRow(), getTableName(), put.getFamilyMap()));

    put(tsput);
    //      super.getConnection().getRegionServerWithRetries(
    //            new ServerCallable<Boolean>(super.getConnection(), super.getTableName(),
    // put.getRow()) {
    //               public Boolean call() throws IOException {
    //                  server.put(location.getRegionInfo().getRegionName(), tsput);
    //                  return true;
    //               }
    //            });
  }
Exemplo n.º 3
0
  /**
   * Transactional version of {@link HTable#delete(Delete)}
   *
   * @param transactionState Identifier of the transaction
   * @see HTable#delete(Delete)
   * @throws IOException
   */
  public void delete(TransactionState transactionState, Delete delete) throws IOException {
    final long startTimestamp = transactionState.getStartTimestamp();
    boolean issueGet = false;

    final Put deleteP = new Put(delete.getRow(), startTimestamp);
    final Get deleteG = new Get(delete.getRow());
    Map<byte[], List<KeyValue>> fmap = delete.getFamilyMap();
    if (fmap.isEmpty()) {
      issueGet = true;
    }
    for (List<KeyValue> kvl : fmap.values()) {
      for (KeyValue kv : kvl) {
        switch (KeyValue.Type.codeToType(kv.getType())) {
          case DeleteColumn:
            deleteP.add(kv.getFamily(), kv.getQualifier(), startTimestamp, null);
            break;
          case DeleteFamily:
            deleteG.addFamily(kv.getFamily());
            issueGet = true;
            break;
          case Delete:
            if (kv.getTimestamp() == HConstants.LATEST_TIMESTAMP) {
              deleteP.add(kv.getFamily(), kv.getQualifier(), startTimestamp, null);
              break;
            } else {
              throw new UnsupportedOperationException(
                  "Cannot delete specific versions on Snapshot Isolation.");
            }
        }
      }
    }
    if (issueGet) {
      Result result = this.get(deleteG);
      for (Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> entryF :
          result.getMap().entrySet()) {
        byte[] family = entryF.getKey();
        for (Entry<byte[], NavigableMap<Long, byte[]>> entryQ : entryF.getValue().entrySet()) {
          byte[] qualifier = entryQ.getKey();
          deleteP.add(family, qualifier, null);
        }
      }
    }

    transactionState.addRow(
        new RowKeyFamily(delete.getRow(), getTableName(), deleteP.getFamilyMap()));

    put(deleteP);
  }