/** * Returns the start time of this marker if such has been defined or the current time if not * @return */ public synchronized Instant getStartTime(TimestampProvider times) { if (startTime==null) { startTime = times.getTime(); } return startTime; }
@Override public synchronized Instant getCommitTime() { if (commitTime==null) { //set commit time to current time commitTime = times.getTime(); } return commitTime; }
public Timer stop() { Preconditions.checkState(null != start, "Timer stopped before it was started"); stop = times.getTime(); return this; }
public Timer start() { Preconditions.checkState(null == start, "Timer can only be started once"); start = times.getTime(); return this; }
public Duration elapsed() { if (null == start) { return Duration.ZERO; } final Instant stopTime = (null==stop? times.getTime() : stop); return Duration.between(start, stopTime); }
/** * ################################### * Message Serialization & Utility * ################################### */ private int getTimeSlice(Instant timestamp) { long value = times.getTime(timestamp) / TIMESLICE_INTERVAL; if (value>Integer.MAX_VALUE || value<0) throw new IllegalArgumentException("Timestamp overflow detected: " + timestamp); return (int)value; }
public RowIterator(Token minimum, Token maximum, SliceQuery sliceQuery, int pageSize, StoreTransaction txh) throws BackendException { this.pageSize = pageSize; this.sliceQuery = sliceQuery; this.maximumToken = maximum; this.txh = txh; this.nowMillis = times.getTime().toEpochMilli(); this.keys = getRowsIterator(getKeySlice(minimum, maximum, sliceQuery, pageSize, nowMillis)); }
@Override protected void action() { lastInvocation = times.getTime(); txCache.cleanUp(); }
public Instant getAdditionTimeInstant(TimestampProvider times) { return times.getTime(getAdditionTime(times)); } }
private void initializeTimepoint() { Preconditions.checkState(null == this.messageTimeStart); if (!readMarker.hasIdentifier()) { this.messageTimeStart = readMarker.getStartTime(times); log.info("Loaded unidentified ReadMarker start time {} into {}", messageTimeStart, this); } else { long savedTimestamp = readSetting(readMarker.getIdentifier(),getMarkerColumn(partitionId,bucketId),times.getTime(readMarker.getStartTime(times))); this.messageTimeStart = times.getTime(savedTimestamp); log.info("Loaded indentified ReadMarker start time {} into {}", messageTimeStart, this); } }
private void sleepAndConvertInterrupts(Duration d) throws BackendException { try { times.sleepPast(times.getTime().plus(d)); } catch (InterruptedException e) { throw new PermanentBackendException(e); } }
private Duration timeSinceFirstMsg() { Duration sinceFirst = Duration.ZERO; if (!toSend.isEmpty()) { Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp(); Instant nowTimestamp = times.getTime(); if (firstTimestamp.compareTo(nowTimestamp) < 0) { sinceFirst = Duration.between(firstTimestamp, nowTimestamp); } } return sinceFirst; }
private void setReadMarker() { if (readMarker.hasIdentifier()) { try { log.debug("Attempting to persist read marker with identifier {}", readMarker.getIdentifier()); writeSetting(readMarker.getIdentifier(), getMarkerColumn(partitionId, bucketId), times.getTime(messageTimeStart)); log.debug("Persisted read marker: identifier={} partitionId={} buckedId={} nextTimepoint={}", readMarker.getIdentifier(), partitionId, bucketId, messageTimeStart); } catch (Throwable e) { log.error("Could not persist read marker [" + readMarker.getIdentifier() + "] on bucket ["+bucketId+"] + partition ["+partitionId+"]",e); } } }
private Entry writeMessage(KCVSMessage msg) { StaticBuffer content = msg.getContent(); DataOutput out = manager.serializer.getDataOutput(8 + 8 + manager.senderId.length() + 2 + content.length()); Instant rawTimestamp = msg.getTimestamp(); Preconditions.checkArgument(rawTimestamp.isAfter(Instant.EPOCH)); out.putLong(times.getTime(rawTimestamp)); out.writeObjectNotNull(manager.senderId); out.putLong(numMsgCounter.incrementAndGet()); final int valuePos = out.getPosition(); out.putBytes(content); return new StaticArrayEntry(out.getStaticBuffer(),valuePos); }
public StaticBuffer toLockCol(Instant ts, StaticBuffer rid, TimestampProvider provider) { WriteBuffer b = new WriteByteBuffer(rid.length() + 8); b.putLong(provider.getTime(ts)); WriteBufferUtil.put(b, rid); return b.getStaticBuffer(); }
private final StaticBuffer getBlockApplication(long blockValue, Instant timestamp) { WriteByteBuffer bb = new WriteByteBuffer( 8 // counter long + 8 // time in ms + uidBytes.length); bb.putLong(-blockValue).putLong(times.getTime(timestamp)); WriteBufferUtil.put(bb, uidBytes); return bb.getStaticBuffer(); }
private KCVSMessage parseMessage(Entry msg) { ReadBuffer r = msg.asReadBuffer(); Instant timestamp = times.getTime(r.getLong()); String senderId = manager.serializer.readObjectNotNull(r,String.class); return new KCVSMessage(msg.getValue(),timestamp,senderId); }
private StandardScanner.Builder buildStoreIndexScanJob(String storeName) { TimestampProvider provider = configuration.get(TIMESTAMP_PROVIDER); ModifiableConfiguration jobConfig = GraphDatabaseConfiguration.buildJobConfiguration(); jobConfig.set(JOB_START_TIME,provider.getTime().toEpochMilli()); return scanner.build() .setStoreName(storeName) .setTimestampProvider(provider) .setJobConfiguration(jobConfig) .setGraphConfiguration(configuration) .setNumProcessingThreads(1) .setWorkBlockSize(10000); }