2015年10月5日 星期一

[tech_note] hackpad 的 unique padid 產生方式 / etherpad 與 appjet



之前一直沉迷在研究不同網站的 unique id generation 的方法,

Hackpad 是從被 Google 收購並且開源 etherpad  為基礎的一個網站,目前被 DropBox收購並且也開源了。
dropbox/hackpad
https://github.com/dropbox/hackpad


自從他們成立網站後,他們有許多改進,關於他們之前的roadmap有一篇有趣的文章,他們提到幾個Task。


hackpad looking for a some hitmen (scala, java, mysql, tdd) - hackpad.com
https://hackpad.com/hackpad-looking-for-a-some-hitmen-scala-java-mysql-tdd-LzsmytZqo1A

Task 1: Kill Scala
Etherpad is built on a thin Scala request dispatching layer. It’s about 4K lines all together, including a bunch of utility functions. This layer is hard to maintain and largely useless now that many maintained frameworks exist for Jetty with support for streaming, longpolling, websockets, etc. The goal here is to replace all this code with well-supported libraries or the most succinct, idomatic Java (or Javascript!) you can write.
Start here: https://github.com/ether/pad/tree/master/infrastructure/net.appjet.oui
Task 2: Kill Rhino
Synchronous Javascript on the server is awesome. Trivially using any Java library from Javascript is awesome. 150ms response time overhead is less awesome. Oracle has written a fast replacement for Rhino called Nashorn which will ship in Java8. It interfaces entirely through the javax.scripting API. Replace the Rhino engine in Etherpad with Nashorn.
Start here: 
http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/
https://github.com/ether/pad/blob/master/infrastructure/net.appjet.bodylock/bodylock.scala
Task 3: Kill Bad DB decisions
The DB schema we chose to inherit is, erm, bad. It does a decent job using mysql as a blob store, but everything else is a mess. Inconsistent primary keys, outdated assumptions, etc. You know the drill. The idea here is to swoop in and fix things, come up with a rollout plan that won’t break people’s data.
Get started by mailing alex@hackpad.com to ask for the DB schema. Brag about the awesomest Mysql install you’ve designed/maintained.
Task 4: Kill Our Naive Ideas about Testing
Being somewhat old-school, I opt for the Linus-style of testing and debugging. e.g. `printk("This should be 1: %d\n", reallyImportantVariable);`
This is silly in context of a modern website. The device targets too numerous, the APIs too fluid. The idea here is to bootstrap us onto the path of testing sanity: set up CI, a decent Java unit testing harness, get some basic coverage we can build on.


Get started by mailing alex@hackpad.com explaining which testing framework you prefer, and the largest website on which you’ve tested it.



-----



這篇文章可以窺探他們在沒有開源的那段時間的想法。
Hackpad 主要是就是以 appjet 把 javascript server side的一個方案。
他們的 unique id generation 方式很直觀,就是重複產生直到不重複的global pad id 出現為止。
hackpad/utils.js at master · dropbox/hackpad
https://github.com/dropbox/hackpad/blob/master/etherpad/src/etherpad/utils.js


 // returns globally-unique padId  
 var SECURE_PAD_ID_LENGTH = 11;  
 function randomUniquePadId(optDomain) {  
  var id = stringutils.randomString(SECURE_PAD_ID_LENGTH);  
  while (model.accessPadGlobal(padutils.getGlobalPadId(id, optDomain), function(p) { return p.exists(); }, "r")) {  
   id = stringutils.randomString(SECURE_PAD_ID_LENGTH);  
  }  
  return id;  
 }  













沒有留言:

張貼留言