Dynamo 2.0 – Apache Cassandra

ㄚ琪最近讀Slashdot這一篇How Twitter Is Moving To the Cassandra Database,我特地查一下華文的新聞也看到有關碎碎念Twitter,這一則來自部落格MyNoSQL新的消息:Twitter用戶暴增20倍 計劃棄用MySQL,原來Twitter是用MySQL資料庫的,感覺就很親切,不過現在聽說要改用Cassandra資料庫,這個資料庫就真的很陌生了,進去Cassandra的網頁看看,它的slogan這樣寫:『A highly scalable, eventually consistent, distributed, structured key-value store. 』,這是一個高延展性的第二代分散式資料庫,Wiki上查到的應該是第一代的吧!至於第二代的分散式資料庫我就沒有sense了。Cassandra網站上說明它的由來,Dynamo的完整分散式設計跟Bigtable的欄位家族基礎的資料模式。

Dynamo跟Facebook又很有淵源,因為Cassandra是2008年由Facebook開放原始碼來的,它是由Avinash Lakshman跟Prashant Malik設計的,而Avinash Lakshman就是Amazon’s Dynamo的作者之一,在很多方面我們可以把Cassandra看成是Dynamo 2.0。

Bigtable就較熟悉了,之前的Google 應用服務引擎的筆記有提到這個資料庫的使用,因為太習慣用MySQL了,所以在用Bigtbale時可能就會稍微有點不習慣,不過這個問題應該很容易可以解決!

在MyNoSQL與Ryan King的對話中,有一些很有趣的地方,一個就是Ryan King曾經評估過的方案有哪些?『Various databases: HBase, Voldemort, MongoDB, MemcacheDB, Redis, Cassandra, HyperTable and probably some others I’m forgetting.』,裡面未曾提過我們所熟知的Oracle、MSSQL、DB2之類的,就覺得他的思維很奇特!

另外一個就是『How do you plan to migrate existing data?』,你如何計畫合併現有的資料,這可是很大的問題喔,就像ㄚ琪以前要把nuke的資料轉到drupal中,又或是在公司要作不同資料庫的資料轉移,這真的是很大的工程。

Ryan King提出的作法:

Write code that can write to Cassandra in parallel to Mysql, but keep it disabled by the tool I mentioned above

Slowly turn up the writes to Cassandra (we can do this by user groups “turn this feature on for employees only” or by percentages “turn this feature on for 1.2% of users”)

Find a bug 🙂

Turn the feature off

Fix the bug and deploy

GOTO #2

然後:

  1. Take a backup from the mysql databases
  2. Run an importer that imports the data to cassandraSome side notes here about importing. We were originally trying to use the BinaryMemtable[2] interface, but we actually found it to be too fast — it would saturate the backplane of our network. We’ve switched back to using the Thrift interface for bulk loading (and we still have to throttle it). The whole process takes about a week now. With infinite network bandwidth we could do it in about 7 hours on our current cluster.
  3. Once the data is imported we start turning on real read traffic to Cassandra (in parallel to the mysql traffic), again by user groups and percentages.
  4. Once we’re satisfied with the new system (we’re using the real production traffic with instrumentation in our application to QA the new datastore) we can start turning down traffic to the mysql databases.

只是聽聽人家在說Cassandra有多好,那沒什麼用,到不如實作一次看看,up and running with cassandra有提到怎麼安裝,我也來試試看!

用安裝CassandraCassandram 需有Java 6的環境才能跑!現在可以下載的版本是0.5.1
操作可以參考Cassandra Installation and Configuration這一篇,不過在Windows下跑有些另外要注意的是cassandra.bat這個檔,還有設定CASSANDRA_HOME的環境變數為D:cassandra,cassandra.bat這個檔裡有

subst P: “%CASSANDRA_HOME%lib”
P:
set CLASSPATH=P:

for %%i in (*.jar) do call :append %%i
goto okClasspath

:append
set CLASSPATH=%CLASSPATH%;P:%*

SUBSET是建立路徑與磁碟機代號之間的關連。

所以要注意P槽是否正在使用中,如果使用中,就改成別的吧!還有-Dcom.sun.management.jmxremote.port=8080^這一行看來會使用8080 port,所以你有在用這個服務,需要把這服務關掉,或將這個port號改掉,不過我沒這樣試!

執行情形像這樣:
2010-03-02_175714

先擺著明天再繼續來玩玩看!

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *