@Override public void put(K key, V val, long timestamp) { // For append mode, values are differentiated by an unique sequence number. For overwrite mode, the sequence // number is always zero. This ensures that only the most recent value is retained. if (appendMode) { seqNum.getAndIncrement(); } TimeSeriesKey<K> timeSeriesKey = new TimeSeriesKey<>(key, timestamp, seqNum.get()); LOG.trace("Inserting {} -> {} into the store", timeSeriesKey, val); kvStore.put(timeSeriesKey, val); }
@Override public void put(K key, V val, long timestamp) { // For append mode, values are differentiated by an unique sequence number. For overwrite mode, the sequence // number is always zero. This ensures that only the most recent value is retained. if (appendMode) { seqNum.getAndIncrement(); } TimeSeriesKey<K> timeSeriesKey = new TimeSeriesKey<>(key, timestamp, seqNum.get()); LOG.trace("Inserting {} -> {} into the store", timeSeriesKey, val); kvStore.put(timeSeriesKey, val); }
@Override public void put(K key, V val, long timestamp) { // For append mode, values are differentiated by an unique sequence number. For overwrite mode, the sequence // number is always zero. This ensures that only the most recent value is retained. if (appendMode) { seqNum.getAndIncrement(); } TimeSeriesKey<K> timeSeriesKey = new TimeSeriesKey<>(key, timestamp, seqNum.get()); LOG.trace("Inserting {} -> {} into the store", timeSeriesKey, val); kvStore.put(timeSeriesKey, val); }
@Override public void put(K key, V val, long timestamp) { // For append mode, values are differentiated by an unique sequence number. For overwrite mode, the sequence // number is always zero. This ensures that only the most recent value is retained. if (appendMode) { seqNum.getAndIncrement(); } TimeSeriesKey<K> timeSeriesKey = new TimeSeriesKey<>(key, timestamp, seqNum.get()); LOG.trace("Inserting {} -> {} into the store", timeSeriesKey, val); kvStore.put(timeSeriesKey, val); }
@Override public void put(K key, V val, long timestamp) { // For append mode, values are differentiated by an unique sequence number. For overwrite mode, the sequence // number is always zero. This ensures that only the most recent value is retained. if (appendMode) { seqNum.getAndIncrement(); } TimeSeriesKey<K> timeSeriesKey = new TimeSeriesKey<>(key, timestamp, seqNum.get()); LOG.trace("Inserting {} -> {} into the store", timeSeriesKey, val); kvStore.put(timeSeriesKey, val); }
@Override public void put(K key, V value) { if (value != null) { instrument(metrics.numPuts, metrics.putNs, () -> kvStore.put(key, value)); } else { delete(key); } }
@Override public void put(K key, V value) { if (value != null) { writeMetrics.numPuts.inc(); long startNs = System.nanoTime(); kvStore.put(key, value); writeMetrics.putNs.update(System.nanoTime() - startNs); } else { delete(key); } }
@Override public void put(K key, V value) { if (value != null) { writeMetrics.numPuts.inc(); long startNs = System.nanoTime(); kvStore.put(key, value); writeMetrics.putNs.update(System.nanoTime() - startNs); } else { delete(key); } }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Override public Collection<JM> handleMessage(M message, MessageCollector collector, TaskCoordinator coordinator) { try { KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState(); KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState(); K key = thisPartialJoinFn.getKey(message); thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis())); TimestampedValue<OM> otherMessage = otherState.get(key); long now = clock.currentTimeMillis(); if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) { JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue()); return Collections.singletonList(joinResult); } } catch (Exception e) { throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e); } return Collections.emptyList(); }
@Test public void testPut() throws Exception { ReadWriteTable table = createTable(false); table.put("k1", "v1"); table.putAsync("k2", "v2").get(); table.putAsync("k3", null).get(); verify(kvStore, times(2)).put(any(), any()); verify(kvStore, times(1)).delete(any()); Assert.assertEquals(2, numPuts.getCount()); Assert.assertEquals(1, numDeletes.getCount()); Assert.assertTrue(putNs.getSnapshot().getAverage() > 0); Assert.assertTrue(deleteNs.getSnapshot().getAverage() > 0); Assert.assertEquals(0, putAllNs.getSnapshot().getAverage(), 0.001); Assert.assertEquals(0, deleteAllNs.getSnapshot().getAverage(), 0.001); Assert.assertEquals(0, flushNs.getSnapshot().getAverage(), 0.001); Assert.assertEquals(0, numPutAlls.getCount()); Assert.assertEquals(0, numDeleteAlls.getCount()); Assert.assertEquals(0, numFlushes.getCount()); Assert.assertEquals(0, putCallbackNs.getSnapshot().getAverage(), 0.001); Assert.assertEquals(0, deleteCallbackNs.getSnapshot().getAverage(), 0.001); }