@Override public int compareTo(Duration o) { if (o.getLength(TimeUnit.NANOSECONDS) == 0) { return 0; } else { return -1; } }
@Override public void sleepFor(Duration duration) throws InterruptedException { if (duration.isZeroLength()) return; TimeUnit unit = duration.getNativeUnit(); unit.sleep(duration.getLength(unit)); }
public static Duration min(Duration x, Duration y) { return x.compareTo(y) <= 0 ? x : y; }
private static final Duration pertubateTime(Duration duration) { Duration newDuration = duration.multiply(1 + (random.nextDouble() * 2 - 1.0) * PERTURBATION_PERCENTAGE); assert !duration.isZeroLength() : duration; return newDuration; }
@Override public int compareTo(Duration o) { return Durations.compare(length,unit,o.getLength(o.getNativeUnit()),o.getNativeUnit()); }
public static final int getTTLSeconds(Duration duration) { Preconditions.checkArgument(duration!=null && !duration.isZeroLength(),"Must provide non-zero TTL"); long ttlSeconds = Math.max(1,duration.getLength(TimeUnit.SECONDS)); assert ttlSeconds>0; Preconditions.checkArgument(ttlSeconds<=Integer.MAX_VALUE, "tll value is too large [%s] - value overflow",duration); return (int)ttlSeconds; }
Preconditions.checkArgument(graph.getConfiguration().hasLogTransactions(),"Transaction logging must be enabled for recovery to work"); Duration maxTxLength = graph.getConfiguration().getMaxCommitTime(); if (maxTxLength.compareTo(MIN_TX_LENGTH)<0) maxTxLength= MIN_TX_LENGTH; Preconditions.checkArgument(maxTxLength != null && !maxTxLength.isZeroLength(), "Max transaction time cannot be 0"); this.graph = graph; this.serializer = graph.getDataSerializer(); .concurrencyLevel(2) .initialCapacity(100) .expireAfterWrite(maxTxLength.getLength(maxTxLength.getNativeUnit()), maxTxLength.getNativeUnit()) .removalListener(new RemovalListener<StandardTransactionId, TxEntry>() { @Override
public static final<V> V executeDirect(Callable<V> exe, Duration totalWaitTime) throws BackendException { Preconditions.checkArgument(!totalWaitTime.isZeroLength(),"Need to specify a positive waitTime: %s",totalWaitTime); long maxTime = System.currentTimeMillis()+totalWaitTime.getLength(TimeUnit.MILLISECONDS); Duration waitTime = pertubateTime(BASE_REATTEMPT_TIME); BackendException lastException; if (System.currentTimeMillis()+waitTime.getLength(TimeUnit.MILLISECONDS)<maxTime) { log.info("Temporary exception during backend operation ["+exe.toString()+"]. Attempting backoff retry.",lastException); try { Thread.sleep(waitTime.getLength(TimeUnit.MILLISECONDS)); } catch (InterruptedException r) { throw new PermanentBackendException("Interrupted while waiting to retry failed backend operation", r); break; waitTime = pertubateTime(waitTime.multiply(2.0));
"Block size [%s] is larger than upper bound [%s] for bit width [%s]",blockSize,idBlockUpperBound,uniqueIdBitWidth); while (methodTime.elapsed().compareTo(timeout) < 0) { final int uniquePID = getUniquePartitionID(); final StaticBuffer partitionKey = getPartitionKey(partition,idNamespace,uniquePID); if (idApplicationWaitMS.compareTo(writeElapsed) < 0) { throw new TemporaryBackendException("Wrote claim for id block [" + nextStart + ", " + nextEnd + ") in " + (writeElapsed) + " => too slow, threshold is: " + idApplicationWaitMS); } else { sleepAndConvertInterrupts(idApplicationWaitMS.add(waitGracePeriod)); } catch (BackendException e) { log.warn("Storage exception while deleting old block application - retrying in {}", rollbackWaitTime, e); if (!rollbackWaitTime.isZeroLength()) sleepAndConvertInterrupts(rollbackWaitTime); backoffMS = Durations.min(backoffMS.multiply(2), idApplicationWaitMS.multiply(32)); log.warn("Temporary storage exception while acquiring id block - retrying in {}: {}", backoffMS, e); sleepAndConvertInterrupts(backoffMS);
@Override public boolean apply(@Nullable Duration duration) { if (duration==null || duration.isZeroLength()) return false; return true; } });
maxReadMsg = config.get(LOG_READ_BATCH_SIZE); readPollingInterval = config.get(LOG_READ_INTERVAL); readLagTime = config.get(LOG_READ_LAG_TIME).add(maxSendDelay); maxReadTime = config.get(LOG_MAX_READ_TIME); if (MIN_DELIVERY_DELAY.compareTo(maxSendDelay) <= 0) { // No need to locally queue messages since they will be sent immediately outgoingMsg = new ArrayBlockingQueue<MessageEnvelope>(sendBatchSize*BATCH_SIZE_MULTIPLIER); sendThread = new SendThread();
this.idStore = idStore; this.times = config.get(TIMESTAMP_PROVIDER); this.waitGracePeriod = idApplicationWaitMS.multiply(0.1D); Preconditions.checkNotNull(times);
assertEquals(0l,d.getLength(unit)); assertTrue(d.isZeroLength());
public synchronized void shutdown() throws TitanException { cleaner.close(CLEAN_SLEEP_TIME.getLength(CLEAN_SLEEP_TIME.getNativeUnit()),CLEAN_SLEEP_TIME.getNativeUnit()); }
public StandardIDPool(IDAuthority idAuthority, int partition, int idNamespace, long idUpperBound, Duration renewTimeout, double renewBufferPercentage) { Preconditions.checkArgument(idUpperBound > 0); this.idAuthority = idAuthority; Preconditions.checkArgument(partition>=0); this.partition = partition; Preconditions.checkArgument(idNamespace>=0); this.idNamespace = idNamespace; this.idUpperBound = idUpperBound; Preconditions.checkArgument(!renewTimeout.isZeroLength(), "Renew-timeout must be positive"); this.renewTimeout = renewTimeout; Preconditions.checkArgument(renewBufferPercentage>0.0 && renewBufferPercentage<=1.0,"Renew-buffer percentage must be in (0.0,1.0]"); this.renewBufferPercentage = renewBufferPercentage; currentBlock = UNINITIALIZED_BLOCK; currentIndex = 0; renewBlockIndex = 0; nextBlock = null; // daemon=true would probably be fine too exec = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("TitanID(" + partition + ")("+idNamespace+")[%d]") .build()); //exec.allowCoreThreadTimeOut(false); //exec.prestartCoreThread(); idBlockFuture = null; initialized = false; closed = false; }
private String getStringForDefaultValue(ConfigOption<?> c) { Object o = c.getDefaultValue(); if (null == o) { return "(no default value)"; } else if (o instanceof Duration) { Duration d = (Duration)o; return d.getLength(TimeUnit.MILLISECONDS) + " ms"; } else if (o instanceof String[]) { return Joiner.on(",").join((String[])o); } return o.toString(); } }
"Must use default log backend for transaction log"); Preconditions.checkArgument(!combinedConfig.has(LOG_SEND_DELAY,TRANSACTION_LOG) || combinedConfig.get(LOG_SEND_DELAY, TRANSACTION_LOG).isZeroLength(),"Send delay must be 0 for transaction log."); overwrite.set(LOG_SEND_DELAY, ZeroDuration.INSTANCE,TRANSACTION_LOG); if (!combinedConfig.has(LOG_STORE_TTL,TRANSACTION_LOG) && TTLKVCSManager.supportsStoreTTL(storeFeatures)) { "Must use default log backend for system log"); Preconditions.checkArgument(!combinedConfig.has(LOG_SEND_DELAY,MANAGEMENT_LOG) || combinedConfig.get(LOG_SEND_DELAY,MANAGEMENT_LOG).isZeroLength(),"Send delay must be 0 for system log."); overwrite.set(LOG_SEND_DELAY, ZeroDuration.INSTANCE, MANAGEMENT_LOG); Preconditions.checkArgument(!combinedConfig.has(KCVSLog.LOG_KEY_CONSISTENT, MANAGEMENT_LOG) ||
public void setMaxOperationWaitTime(Duration waitTime) { Preconditions.checkArgument(ZeroDuration.INSTANCE.compareTo(waitTime) < 0, "Wait time must be nonnegative: %s", waitTime); this.maxOperationWaitTime = waitTime; }
@Override protected void waitCondition() throws InterruptedException { final TimeUnit schedulingTimeUnit = TimeUnit.MICROSECONDS; MessageEnvelope msg = outgoingMsg.poll(maxWaitTime().getLength(schedulingTimeUnit), schedulingTimeUnit); if (msg!=null) toSend.add(msg); }
@Override protected void action() { MessageEnvelope msg; //Opportunistically drain the queue for up to the batch-send-size number of messages before evaluating condition while (toSend.size()<sendBatchSize && (msg=outgoingMsg.poll())!=null) { toSend.add(msg); } //Evaluate send condition: 1) Is the oldest message waiting longer than the delay? or 2) Do we have enough messages to send? if (!toSend.isEmpty() && (maxSendDelay.compareTo(timeSinceFirstMsg()) <= 0 || toSend.size() >= sendBatchSize)) { try { sendMessages(toSend); } finally { toSend.clear(); } } }