/** * Return the values that were recorded before or during the supplied time. * * @param time Last time recorded * @return Iterator over table values */ @Override public Map<String, StreamIterator<TableValue>> getCollapsed(final long time) { Map<String, StreamIterator<TableValue>> fm = new HashMap<>(1); for (String branch : entries.keySet()) { TableValueHistory history = entries.get(branch); // Go through the branch and prune off all // the values with higher vector clocks. TableValueHistory pruned = new UnsafeTableValueHistory(); for (Iterator<? extends TableValue> iter = history.iterator(); iter.hasNext(); ) { TableValue v = iter.next(); long c = v.getClock().getLocalTime(); // Only include items that were recorded before // the supplied time. if (c <= time) { pruned.add(v); } } // Then collapse the remaining values and place // into its own history. TableValue v = pruned.getCollapsedValue(); TableValueHistory singleton = new UnsafeTableValueHistory(); singleton.add(v); // Save the new branch. fm.put(branch, singleton.iterator()); } return fm; }
/** * Add a new value to this bucket to a specific branch. This means that the vector clock * associated with the value should be appended to the branch vector clock. * * @param value Table value to add to bucket * @param branch Specific branch where the value resides (optional) */ @Override public void add(final TableValue value, final String branch) { // Find the latest vector clock associated with the branch, // and then the latest value history. TableValueHistory history = null; history = entries.get(branch); if (history == null) { if (value.getFlags() != TableValue.TENTATIVE) { // This must be a new branch. history = new UnsafeTableValueHistory(); history.setBranchName(branch); entries.put(branch, history); } } // Add the value to our history. history.add(value); // Increase our committed count if (value.getFlags() != TableValue.TENTATIVE) { num++; } }