private static void rollbackRow(HTableWrapper tableWrapper, byte[] row, long id, Integer lockId) { try { tableWrapper.rollbackRow(row, id, lockId); } catch (IOException e) { // LOG.warn("Failed to rollback row.", e); } }
private static Result getTransactionStatus(HTableInterface metaTable, long transactionId) throws IOException { byte[] row = DominoConst.long2TranscationRowKey(transactionId); return metaTable.coprocessorProxy(TMetaIface.class, row) .getTransactionStatus(transactionId); }
private static boolean isDeletedRow(List<KeyValue> statusList, List<KeyValue> versionList, long startId) { if (statusList != null && statusList.size() > 0) { if (isSelfDelete(statusList.get(0), startId)) { return true; } } if (versionList != null && versionList.size() > 0) { KeyValue version = versionList.get(0); if (DominoConst.isDeleteVersion(version.getValue())) { return true; } } return false; }
private static KeyValue commitRow(HTableWrapper tableWrapper, KeyValue statusKV, long startId, long commitId, Integer lockId) { byte[] row = statusKV.getRow(); boolean isDelete = DominoConst.isDelete(statusKV.getValue()); try { tableWrapper.commitRow(row, startId, commitId, isDelete, lockId); } catch (IOException ioe) { } byte[] value = DominoConst.versionValue(startId, isDelete); KeyValue commitKV = new KeyValue(row, DominoConst.INNER_FAMILY, DominoConst.VERSION_COL, commitId, value); return commitKV; }
private static Put deletePut(byte[] row, long startId, byte[] columnsWritten) throws IOException { Columns cols = new Columns(columnsWritten); Put ret = new Put(row); byte[] status = new byte[1 + Bytes.SIZEOF_LONG]; status[0] = DominoConst.S_DELETE_BYTE; Bytes.putLong(status, 1, startId); ret.add(DominoConst.INNER_FAMILY, DominoConst.COLUMNS_COL, startId, cols.toByteArray()); ret.add(DominoConst.INNER_FAMILY, DominoConst.STATUS_COL, startId, status); return ret; }
@Override public DResult delete(byte[] row, long startId) throws IOException { Integer lockId = region.getLock(null, row, true); try { byte[] columnsWritten = MVCC.writeCheckRowStatus(this, getTrxMetaTable(), row, false, lockId, startId); Put deletePut = deletePut(row, startId, columnsWritten); mutateRow(deletePut, lockId); return null; } catch (InvalidRowStatusException e) { return new DResult(null, e.getMessage()); } finally { region.releaseRowLock(lockId); } }
/** * Constructor with a ZooKeeper connection string. * * @param zookeeperAddress * e.g. host1:port1,host2:port2,host3:port3... * @throws IOException * when connection failure occurs. */ public Domino(String zookeeperAddress) throws IOException { init(ConfigurationHelper.config(zookeeperAddress)); }
public void add(byte[] family, byte[] qualifier) { if (family == null || qualifier == null) return; Column col = new Column(family, qualifier); if (cols.contains(col)) return; len += Bytes.SIZEOF_INT + col.length; cols.add(col); }
@Override public void commitRow(byte[] row, long startId, long commitId, boolean isDelete, Integer lockId) throws IOException { table.coprocessorProxy(DominoIface.class, row).commitRow(row, startId, commitId, isDelete); }
@Override public void rollbackRow(byte[] row, long startId, Integer lockId) throws IOException { table.coprocessorProxy(DominoIface.class, row).rollbackRow(row, startId); }
@SuppressWarnings("deprecation") private void abort(byte[] startId, Integer lockId) throws IOException { Put put = new Put(startId); long startIdLong = DominoConst.getTidFromTMetaKey(startId); put.add(DominoConst.TRANSACTION_META_FAMILY, DominoConst.TRANSACTION_STATUS, startIdLong, DominoConst.TRX_ABORTED_B); region.put(put, lockId, true); }
private void transactionMetaAbort() throws IOException { try { metaTable.coprocessorProxy(TMetaIface.class, startIdBytes) .abortTransaction(startIdBytes); } catch (IOException e) { throw e; } catch (Throwable t) { throw new IOException(t); } }
private void createTransactionMeta() throws IOException { Put put = new Put(startIdBytes); put.add(DominoConst.TRANSACTION_META_FAMILY, DominoConst.TRANSACTION_STATUS, startId, DominoConst.TRX_ACTIVE_B); put.add(DominoConst.TRANSACTION_META_FAMILY, DominoConst.TRANSACTION_TS, startId, DominoConst.tsToBytes(System.currentTimeMillis())); metaTable.put(put); // metaTable.flushCommits(); }
private static boolean conflicted(KeyValue status, long startId) { if (!DominoConst.isStatefulStatus(status.getValue())) { return false; } return status.getTimestamp() != startId; }
private static boolean isSelfDelete(KeyValue status, long startId) { return status.getTimestamp() == startId && DominoConst.isDelete(status.getValue()); }
public byte[] toByteArray() { byte[] ret = new byte[Bytes.SIZEOF_INT + len]; int pos = 0; pos = Bytes.putInt(ret, pos, cols.size()); for (Column col : cols) { pos = Bytes.putInt(ret, pos, col.length); pos = col.toBytes(ret, pos); } return ret; }
public Columns(byte[] old) { if (old == null || old.length == 0) { return; } int pos = 0; int count = Bytes.toInt(old, pos); pos += Bytes.SIZEOF_INT; for (int i = 0; i < count; ++i) { int columnLen = Bytes.toInt(old, pos); pos += Bytes.SIZEOF_INT; cols.add(Column.fromBytes(old, pos, columnLen)); pos += columnLen; len += Bytes.SIZEOF_INT + columnLen; } }
@Override public DResult put(Put put, long startId, boolean locking) throws IOException { Integer lockId = region.getLock(null, put.getRow(), true); try { byte[] columnsWritten = MVCC.writeCheckRowStatus(this, getTrxMetaTable(), put.getRow(), locking, lockId, startId); Put innerPut = clonePut(put, startId, locking, columnsWritten); mutateRow(innerPut, lockId); return null; } catch (InvalidRowStatusException e) { return new DResult(null, e.getMessage()); } finally { region.releaseRowLock(lockId); } }
public boolean contains(byte[] family, byte[] qualifier) { return cols.contains(new Column(family, qualifier)); }
public static Column fromBytes(byte[] bytes, int pos, int length) { int familyLen = Bytes.toInt(bytes, pos); pos += Bytes.SIZEOF_INT; byte[] family = new byte[familyLen]; Bytes.putBytes(family, 0, bytes, pos, familyLen); pos += familyLen; int qualifierLen = length - Bytes.SIZEOF_INT - familyLen; byte[] qualifier = new byte[qualifierLen]; Bytes.putBytes(qualifier, 0, bytes, pos, qualifierLen); return new Column(family, qualifier); }