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; }
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; }
/** * 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; }