Interface CoordinationService<T>


  • public interface CoordinationService<T>
    A CoordinationService is used to agree on values being relevant or correct at a given timestamp. The sequence of values being agreed should evolve in a backwards consistent manner. This means that one should avoid changes that may affect behaviour for decisions taken at timestamps below the validity bound. More formally, suppose we read a value for some timestamp TS. (In relation to AtlasDB transactions, this may be a start or commit timestamp, as long as we are consistent.) All future values written to the CoordinationService must then ensure that decisions made at TS would be done in a way consistent with our initial read. It is the responsibility of the caller to provide transforms that preserve the above property; the addition of a value at a given timestamp implies that it is OK for readers at all previous timestamps to read that value.
    • Method Detail

      • getValueForTimestamp

        Optional<ValueAndBound<T>> getValueForTimestamp​(long timestamp)
        Returns a value that the coordination service has agreed is appropriate at the provided timestamp. The value returned by this method may change over time. However, values returned by this method would be consistent at this timestamp - that is, the service should never return values for the same timestamp that would be contradictory or result in different operation for uses at this timestamp. This operation will return an empty Optional if no value has been agreed upon yet, or if the current value agreed by the coordination service is not valid at the provided timestamp.
        Parameters:
        timestamp - timestamp to retrieve the coordinated value for
        Returns:
        value associated with that timestamp
      • tryTransformCurrentValue

        TransformResult<ValueAndBound<T>> tryTransformCurrentValue​(Function<ValueAndBound<T>,​T> transform)
        Attempts to update the value stored in the CoordinationService by applying the provided transform to the existing ValueAndBound that is stored in this coordination service. Evolutions of the value must be compatible in terms of backwards consistency as defined in the class docs.
        Parameters:
        transform - transformation to apply to the existing value and bound the coordination service agrees on
        Returns:
        a TransformResult indicating whether the transform was applied and the current value
        Throws:
        IllegalStateException - if we fail to apply the transform, but no current value exists
      • getLastKnownLocalValue

        Optional<ValueAndBound<T>> getLastKnownLocalValue()
        Returns the most recent value that this coordination service knows about locally. This method should be cheap to compute, and is not expected to make calls to remote services. Consequently, it is possible that the value returned is not actually the last known local value globally (or, for that matter, it is possible that it bears little or no degree of recency). This should only be used for metrics and monitoring of the system; product decisions must not be taken based on any values this returns.
        Returns:
        the last locally known value and bound agreed by this coordination service