You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The notion of a VersionedStore would make it easy to create a distributed read-only database backed by storehaus stores that loaded themselves off of disk.
importcom.twitter.util.{ Duration, Future, Timer }
/** * ReadableStore with some notion of versioning.*/traitVersionedStore[-K, +V] extendsReadableStore[K, (Long, V)] {
defcurrentVersion:Option[Long]
}
/** * Fired when an updating versioned store is not yet loaded.*/classStoreNotLoadedExceptionextendsRuntimeException/** * The typical not-yet-loaded versioned store. This store returns * exceptions for every get and multiGet.*/objectExceptionalStoreextendsVersionedStore[Any, Nothing] {
overridedefget(k: Any) =Future.exception(newStoreNotLoadedException)
overridevalcurrentVersion=None
}
classConstantVersionedStore[-K, +V](store: ReadableStore[K, V], version: Long) extendsVersionedStore[K, V] {
overridevalcurrentVersion=Some(version)
protecteddefprependVersion(f: Future[Option[V]], version: Long) =
f.map { _.map { (version, _) } }
overridedefget(k: K) = prependVersion(store.get(k), version)
overridedefmultiGet[K1<:K](ks: Set[K1]):Map[K1, Future[Option[(Long, V)]]] =
store.multiGet(ks).mapValues { prependVersion(_, version) }
}
/** * Versioned store implementation capable of updating itself to some * new version, potentially asynchronously. One use case here would a * store that loads its backing dataset across the network from * HDFS. Every time a new version appeared on HDFS the watcher * process would switch the backing store behind the scenes.*/classUpdatingVersionedStore[-K, +V](updateInterval: Duration)(watcherProcess: Option[Long] =>Future[Option[VersionedStore[K, V]]])
(implicittimer: Timer)
extendsVersionedStore[K, V] {
protectedvarinnerStore:Future[VersionedStore[K, V]] =Future.value(ExceptionalStore)
timer.schedule(updateInterval) {
innerStore = innerStore
.join(watcherProcess(currentVersion))
.map { case (oldStore, optNewStore) => optNewStore.getOrElse(oldStore) }
}
overridedefget(k: K) = innerStore.flatMap { _.get(k) }
overridedefmultiGet(ks: Set[K]) =FutureOps.liftFutureValues(ks, innerStore.map { _.multiGet(ks) })
}
The text was updated successfully, but these errors were encountered:
Yes, it's well defined for a given versionedstore (which is a readablestore[K, (Long, V)]. The usual ReadableStore combinators would allow you combine multiple versioned stores.
The notion of a VersionedStore would make it easy to create a distributed read-only database backed by storehaus stores that loaded themselves off of disk.
The text was updated successfully, but these errors were encountered: