/** * {@inheritDoc} */ @Override public void put(Put put) throws IOException { byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()) { if (columnFamilies.contains(new String(family, StandardCharsets.UTF_8)) == false) { throw new RuntimeException("Not Exists columnFamily : " + new String(family, StandardCharsets.UTF_8)); } NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)) { kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
/** * Tests that getTimestamp() does always return the proper timestamp, even after updating it. * See HBASE-6265. */ @Test public void testGetTimestamp() { KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"), Bytes.toBytes("myQualifier"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes("myValue")); long time1 = kv.getTimestamp(); kv.updateLatestStamp(Bytes.toBytes(12345L)); long time2 = kv.getTimestamp(); assertEquals(HConstants.LATEST_TIMESTAMP, time1); assertEquals(12345L, time2); }
/** * Batch all the {@link KeyValue}s in a collection of kvs by timestamp. Updates any * {@link KeyValue} with a timestamp == {@link HConstants#LATEST_TIMESTAMP} to the timestamp at * the time the method is called. * @param kvs {@link KeyValue}s to break into batches * @param batches to update with the given kvs */ protected void createTimestampBatchesFromKeyValues(Collection<KeyValue> kvs, Map<Long, Batch> batches) { long now = EnvironmentEdgeManager.currentTimeMillis(); byte[] nowBytes = Bytes.toBytes(now); // batch kvs by timestamp for (KeyValue kv : kvs) { long ts = kv.getTimestamp(); // override the timestamp to the current time, so the index and primary tables match // all the keys with LATEST_TIMESTAMP will then be put into the same batch if (kv.updateLatestStamp(nowBytes)) { ts = now; } Batch batch = batches.get(ts); if (batch == null) { batch = new Batch(ts); batches.put(ts, batch); } batch.add(kv); } }
@Override public void put(Put put) throws IOException { addToPutLog(put); byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()){ NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)){ kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
/** * Sets the timestamp that should be used if the KeyValue is using * HConstants.LATEST_TIMESTAMP. * * @param now The timestamp as a byte array. * @return Whether the timestamp of the KeyValue was modified. * @see org.apache.hadoop.hbase.KeyValue */ public boolean updateLatestStamp(byte[] now) { return mKeyValue.updateLatestStamp(now); }
/** * Replaces any KV timestamps set to {@link HConstants#LATEST_TIMESTAMP} with the provided current * timestamp. */ private void updateKVTimestamps( final Iterable<List<KeyValue>> keyLists, final byte[] now) { for (List<KeyValue> keys: keyLists) { if (keys == null) continue; for (KeyValue key : keys) { key.updateLatestStamp(now); } } }
for (List<KeyValue> kvs : m.getFamilyMap().values()) { for (KeyValue kv : kvs) { kv.updateLatestStamp(clientTimestampBuf);
@Override public void write(Object row, Cell cell) throws IOException { KeyValue copy = KeyValue.cloneAndAddTags(cell, ImmutableList.<Tag>of()); if (copy.getTimestamp() == HConstants.LATEST_TIMESTAMP) { copy.updateLatestStamp(now); } writer.append(copy); trt.includeTimestamp(copy); }
/** * {@inheritDoc} */ @Override public void put(Put put) throws IOException { this.sleeper(); byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()) { if (columnFamilies.contains(new String(family)) == false) { throw new RuntimeException("Not Exists columnFamily : " + new String(family)); } NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)) { kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
kv.updateLatestStamp(byteNow); continue; getkv.getBuffer(), getkv.getTimestampOffset(), Bytes.SIZEOF_LONG); } else { kv.updateLatestStamp(byteNow);
@Override public void write(Object row, Cell cell) throws IOException { KeyValue copy = KeyValueUtil.copyToNewKeyValue(cell); if (copy.getTimestamp() == HConstants.LATEST_TIMESTAMP) { copy.updateLatestStamp(now); } writer.append(copy); long seqId = cell.getSequenceId(); if (seqId > maxSeqId) { maxSeqId = seqId; } }
kv.updateLatestStamp(this.now); wl.writer.append(kv); wl.written += length;
/** * Tests that getTimestamp() does always return the proper timestamp, even after updating it. * See HBASE-6265. */ public void testGetTimestamp() { KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"), Bytes.toBytes("myQualifier"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes("myValue")); long time1 = kv.getTimestamp(); kv.updateLatestStamp(Bytes.toBytes(12345L)); long time2 = kv.getTimestamp(); assertEquals(HConstants.LATEST_TIMESTAMP, time1); assertEquals(12345L, time2); }
/** {@inheritDoc} */ @Override public void write(HFileKeyValue entry, NullWritable unused) throws IOException { final KeyValue kv = entry.getKeyValue(); kv.updateLatestStamp(mLatestTimestampBytes); final long recordLength = kv.getLength(); if (mCurrentHFileSize + recordLength >= mMaxFileSizeBytes) { // We can't fit this record in the current HFile without exceeding the max file size. if (Arrays.equals(mCurrentRow, kv.getRow())) { // But we're still adding data for a single row, so we can't close this HFile yet. LOG.debug("Reached max HFile size, but waiting to finish this row before closing."); } else { // Close it and open a new one. closeWriter(mWriter); mWriter = openNewWriter(); } } mWriter.append(kv); mTimeRangeTracker.includeTimestamp(kv); mCurrentHFileSize += recordLength; // Remember the row so we know when we are transitioning. mCurrentRow = kv.getRow(); }
/** * Tests that getTimestamp() does always return the proper timestamp, even after updating it. * See HBASE-6265. */ @Test public void testGetTimestamp() { KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"), Bytes.toBytes("myQualifier"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes("myValue")); long time1 = kv.getTimestamp(); kv.updateLatestStamp(Bytes.toBytes(12345L)); long time2 = kv.getTimestamp(); assertEquals(HConstants.LATEST_TIMESTAMP, time1); assertEquals(12345L, time2); }