/** * Return a view of the portion of this map whose keys are strictly * less than the specified key. * * @param key Key higher than any in the returned map * @return a head map */ public SortedMap headMap(Object key) { if (fast) { return (map.headMap(key)); } else { synchronized (map) { return (map.headMap(key)); } } }
/** * Return a view of the portion of this map whose keys are strictly * less than the specified key. * * @param key Key higher than any in the returned map * @return a head map */ public SortedMap headMap(Object key) { if (fast) { return (map.headMap(key)); } else { synchronized (map) { return (map.headMap(key)); } } }
/** * Splits the range set at the given timestamp (if it hasn't been split yet) */ private void splitAt(long t) { if (data.containsKey(t)) return; // already split at this timestamp SortedMap<Long, int[]> head = data.headMap(t); int v = head.isEmpty() ? 0 : data.get(head.lastKey())[0]; data.put(t, new int[]{v}); }
public Object getPreviousState(long txid) { SortedMap<Long, Object> prevMap = _curr.headMap(txid); if(prevMap.isEmpty()) return null; else return prevMap.get(prevMap.lastKey()); }
public Object getPreviousState(long txid) { final SortedMap<Long, Object> prevMap = _curr.headMap(txid); Object state; if (prevMap.isEmpty()) { state = null; } else { state = prevMap.get(prevMap.lastKey()); } LOG.debug("Getting previous [state = {}], [txid = {}]", state, txid); LOG.trace("[{}]", this); return state; }
public void cleanupBefore(BigInteger txid) { Set<BigInteger> toDelete = new HashSet<>(); toDelete.addAll(_curr.headMap(txid).keySet()); for (BigInteger tx : toDelete) { _curr.remove(tx); _state.delete(txPath(tx)); } }
public MutableSortedMap<K, V> headMap(K toKey) { return SortedMapAdapter.adapt(this.treeMap.headMap(toKey)); }
@Override public MutableSortedMap<K, V> headMap(K toKey) { return SortedMapAdapter.adapt(this.treeMap.headMap(toKey)); }
@Override public MutableSortedMap<K, V> headMap(K toKey) { return SortedMapAdapter.adapt(this.treeMap.headMap(toKey)); }
private TreeMap<Long, Integer> getStoredCurrAttempts(long currTransaction, int maxBatches) { TreeMap<Long, Integer> ret = new TreeMap<Long, Integer>(); for (TransactionalState state : _states) { Map<Object, Number> attempts = (Map) state.getData(CURRENT_ATTEMPTS); if (attempts == null) { attempts = new HashMap(); } for (Entry<Object, Number> e : attempts.entrySet()) { // this is because json doesn't allow numbers as keys... // TODO: replace json with a better form of encoding Number txidObj; if (e.getKey() instanceof String) { txidObj = Long.parseLong((String) e.getKey()); } else { txidObj = (Number) e.getKey(); } long txid = ((Number) txidObj).longValue(); int attemptId = ((Number) e.getValue()).intValue(); Integer curr = ret.get(txid); if (curr == null || attemptId > curr) { ret.put(txid, attemptId); } } } ret.headMap(currTransaction).clear(); ret.tailMap(currTransaction + maxBatches - 1).clear(); return ret; }
public void cleanupBefore(BigInteger txid) { SortedMap<BigInteger, Object> toDelete = _curr.headMap(txid); for(BigInteger tx: new HashSet<BigInteger>(toDelete.keySet())) { _curr.remove(tx); _state.delete(txPath(tx)); } }
public void cleanupBefore(long txid) { SortedMap<Long, Object> toDelete = _curr.headMap(txid); for (long tx : new HashSet<Long>(toDelete.keySet())) { _curr.remove(tx); try { _state.delete(txPath(tx)); } catch (RuntimeException e) { // Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since // zookeeper reads are eventually consistent. if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } }
/** * Get all shards <= this one in descending order */ public Iterator<ShardEntryGroup> getShards( final Long maxShard ) { final Long firstKey = shards.floorKey( maxShard ); return Collections.unmodifiableCollection( shards.headMap( firstKey, true ).descendingMap().values()).iterator(); }
public Object getState(long txid, StateInitializer init) { if (!_curr.containsKey(txid)) { SortedMap<Long, Object> prevMap = _curr.headMap(txid); SortedMap<Long, Object> afterMap = _curr.tailMap(txid); Long prev = null; if (!prevMap.isEmpty()) { prev = prevMap.lastKey(); } Object data; if (afterMap.isEmpty()) { Object prevData; if (prev != null) { prevData = _curr.get(prev); } else { prevData = null; } data = init.init(txid, prevData); } else { data = null; } _curr.put(txid, data); _state.setData(txPath(txid), data); } Object state = _curr.get(txid); LOG.debug("Getting or initializing state. [txid = {}] => [state = {}]", txid, state); LOG.trace("[{}]", this); return state; }
public void cleanupBefore(long txid) { SortedMap<Long, Object> toDelete = _curr.headMap(txid); for(long tx: new HashSet<>(toDelete.keySet())) { _curr.remove(tx); try { _state.delete(txPath(tx)); } catch(RuntimeException e) { // Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since // zookeeper reads are eventually consistent. if(!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } }
public Object getState(long txid, StateInitializer init) { if(!_curr.containsKey(txid)) { SortedMap<Long, Object> prevMap = _curr.headMap(txid); SortedMap<Long, Object> afterMap = _curr.tailMap(txid); Long prev = null; if(!prevMap.isEmpty()) prev = prevMap.lastKey(); Object data; if(afterMap.isEmpty()) { Object prevData; if(prev!=null) { prevData = _curr.get(prev); } else { prevData = null; } data = init.init(txid, prevData); } else { data = null; } _curr.put(txid, data); _state.setData(txPath(txid), data); } return _curr.get(txid); }
/** * {@inheritDoc} */ public int named(String name) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.headMap(name).values()); }
/** * {@inheritDoc} */ public int named(String name) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.headMap(name).values()); }
@Override public void execute(BatchInfo info, Tuple input) { // there won't be a BatchInfo for the success stream TransactionAttempt attempt = (TransactionAttempt) input.getValue(0); if (input.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) { if (attempt.equals(_activeBatches.get(attempt.getTransactionId()))) { ((ICommitterTridentSpout.Emitter) _emitter).commit(attempt); _activeBatches.remove(attempt.getTransactionId()); } else { throw new FailedException("Received commit for different transaction attempt"); } } else if (input.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) { // valid to delete before what's been committed since // those batches will never be accessed again _activeBatches.headMap(attempt.getTransactionId()).clear(); _emitter.success(attempt); } else { _collector.setBatch(info.batchId); _emitter.emitBatch(attempt, input.getValue(1), _collector); _activeBatches.put(attempt.getTransactionId(), attempt); } }
@Override public void execute(BatchInfo info, Tuple input) { // there won't be a BatchInfo for the success stream TransactionAttempt attempt = (TransactionAttempt) input.getValue(0); if (input.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) { if (attempt.equals(_activeBatches.get(attempt.getTransactionId()))) { ((ICommitterTridentSpout.Emitter) _emitter).commit(attempt); _activeBatches.remove(attempt.getTransactionId()); } else { throw new FailedException("Received commit for different transaction attempt"); } } else if (input.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) { // valid to delete before what's been committed since // those batches will never be accessed again _activeBatches.headMap(attempt.getTransactionId()).clear(); _emitter.success(attempt); } else { _collector.setBatch(info.batchId); _emitter.emitBatch(attempt, input.getValue(1), _collector); _activeBatches.put(attempt.getTransactionId(), attempt); } }