• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

akka-data-replication: This is an EARLY PREVIEW of a library for replication of ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

akka-data-replication

开源软件地址:

https://gitee.com/mefaso/akka-data-replication

开源软件介绍:

本项目已经成为akka实验项目 将在akka2.4支持

Akka Data Replication

This is an EARLY PREVIEW of a library for replication of data in an Akka cluster.It is a replicated in-memory data store supporting low latency and high availabilityrequirements. The data must be so called Conflict Free Replicated Data Types (CRDTs),i.e. they provide a monotonic merge function and the state changes always converge.

For good introduction to CRDTs you should watch theEventually Consistent Data Structurestalk by Sean Cribbs.

CRDTs can't be used for all types of problems, but when they can they have very nice properties:

  • low latency of both read and writes
  • high availability (partition tolerance)
  • scalable (no central coordinator)
  • strong eventual consistency (eventual consistency without conflicts)

Built in data types:

  • Counters: GCounter, PNCounter
  • Registers: LWWRegister, Flag
  • Sets: GSet, ORSet
  • Maps: ORMap, LWWMap, PNCounterMap

You can use your own custom data types by implementing the merge function of the ReplicatedDatatrait. Note that CRDTs typically compose nicely, i.e. you can use the provided data types to build richerdata structures.

The Replicator actor implements the infrastructure for replication of the data. It usesdirect replication and gossip based dissemination. The Replicator actor is started on each nodein the cluster, or group of nodes tagged with a specific role. It communicates with otherReplicator instances with the same path (without address) that are running on other nodes.For convenience it is typically used with the DataReplication Akka extension.

A short example of how to use it:

class DataBot extends Actor with ActorLogging {  import DataBot._  import Replicator._  val replicator = DataReplication(context.system).replicator  implicit val cluster = Cluster(context.system)  import context.dispatcher  val tickTask = context.system.scheduler.schedule(5.seconds, 5.seconds, self, Tick)  replicator ! Subscribe("key", self)  def receive = {    case Tick =>      val s = ThreadLocalRandom.current().nextInt(97, 123).toChar.toString      if (ThreadLocalRandom.current().nextBoolean()) {        // add        log.info("Adding: {}", s)        replicator ! Update("key", ORSet(), WriteLocal)(_ + s)      } else {        // remove        log.info("Removing: {}", s)        replicator ! Update("key", ORSet(), WriteLocal)(_ - s)      }    case _: UpdateResponse => // ignore    case Changed("key", data: ORSet) =>      log.info("Current elements: {}", data.value)  }  override def postStop(): Unit = tickTask.cancel()}

The full source code for this sample is inDataBot.scala.

More detailed documentation can be found in theScalaDocof Replicator and linked classes.

Two other examples:

Dependency

Latest version of akka-data-replication is 0.8. This version depends on Akka 2.3.6 and iscross-built against Scala 2.10.4 and 2.11.4.

Add the following lines to your build.sbt file:

resolvers += "patriknw at bintray" at "http://dl.bintray.com/patriknw/maven"libraryDependencies += "com.github.patriknw" %% "akka-data-replication" % "0.8"

More Resources


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap