java – 每当有任何新行或任何新更新时从Cassandra数据库中拉出来?

我正在开发一个系统,我需要在Cassandra数据库中存储Avro Schemas.所以在Cassandra,我们将存储这样的东西

SchemaId            AvroSchema

1                   some schema
2                   another schema

现在假设我在Cassandra的上表中插入另一行,现在表格就像这样 –

SchemaId            AvroSchema

1                   some schema
2                   another schema
3                   another new schema

只要我在上表中插入一个新行 – 我需要告诉我的Java程序去拉新的模式ID和相应的模式.

解决这类问题的正确方法是什么?

我知道,一种方法是每隔几分钟进行一次轮询,让我们说每5分钟我们就会从上表中提取数据,但这不是每5分钟解决这个问题的正确方法,我正在拉动是否有任何新的架构..

但除此之外还有其他解决方案吗?

我们可以使用Apache Zookeeper吗?或者Zookeeper不适合这个问题?
或任何其他解决方案?

我正在运行Apache Cassandra 1.2.9

解决方法:

一些解决方案

>使用数据库触发器:Cassandra 2.0有一些触发器支持,但看起来它不是最终的,并且根据本文可能会在2.1中稍微改变:http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-0-prototype-triggers-support.触发器是一种常见的解决方案.
>你提出了民意调查,但这并不总是一个糟糕的选择.特别是如果你有一些东西标记该行还没有被拉动,那么你可以从Cassandra中拉出新的行.如果查询费用不高,那么每5分钟拉一次对于Cassandra或任何数据库来说都不是明智之举.如果在很少的基础上插入新行,则此选项可能不太好.

Zookeeper不是一个完美的解决方案,请看这个引用:

Because watches are one time triggers and there is latency between
getting the event and sending a new request to get a watch you cannot
reliably see every change that happens to a node in ZooKeeper. Be
prepared to handle the case where the znode changes multiple times
between getting the event and setting the watch again. (You may not
care, but at least realize it may happen.)

报价来自:http://zookeeper.apache.org/doc/r3.4.2/zookeeperProgrammers.html#sc_WatchRememberThese

上一篇:如何使用链接的MySql服务器更新SQL Server中的行


下一篇:php – 触发前的MySQL,使用查询设置多个字段