HBaseCon 2013: Evolving a First-Generation Apache HBase Deployment to Second...
Tair
1. Introduction to Tair
xuyun@taobao.com
August 13, 2010
1 History
Tair is short for Taobao pair, which is a distributed data storage based on
key/value data structure. Tair 1.0 is developed in August 2008 using Java, all
the data are stored in MySQL and disaster tolerance is depended on MySQL
too. Before Tair 1.0, there is a similar key/value storage in taobao, which is
tdbm 1.0 developed by DUO Long for UIC project cache in Sep. 2007. Tdbm
1.0’s predecessor is tbstore. In March 2009, tdbm 2.0 is developed by DUO
Long referring to Memcached’s memory implementation. Tdbm 2.0 improved
distributed cluster. Use ratio and throughput of memory have been promoted
greatly.
Because, Tair and tdbm are similar, they should be combined into one pro-
duction, including tari’s persistent storage and tdbm’s cache. Tair’s persistent
engine is based file system. Tair client is developed using Java. Security strategy
is more perfect using copy- synchronization strategy not depending on MySQL.
2 Architecture
Architecture of Tair 2 is shown in Fig. 1. Architeture consists of three parts:
tari client, config server, data server cluster. Config server maintains some
gloable configuration. Tair client can fetch lookup table from config server for
synchronization. Tair client can config two config server for mutual backup.
According to config server, request from tair client can be routed to right server
in data server cluster.
3 Key Technology
3.1 Group and Namespace
Config server splits data server into several groups, one physical machine belongs
to just one group. Namespace is designed to avoid key conflict between different
application. Different data type in one application can have different namespace.
If namespace is in common cluster, it must be applied for first.
1
2. Figure 1: Architecture of Tair 2
3.2 Version
Version for key is introduced to solve the problem of updating data cocurrently.
Version is added 1 for every data update. If the version of data is not consistent
with server when it be put from tair client to data server, the result is error of
version. If version is 0 when putting data, it means update data in server with
force, but version in data server will be added 1 all the same.
3.3 Expire
Data in tair data server is not set expired by default. If data expire time is set
when using put interface, data will be expired after the setting time. In the
data server, data will not be deleted immediately when time is out. In this case,
the server will not ensure data can be get. Because, when the memory of server
is out, some data will be removed using LRU algorithm.
3.4 Invalid and Remove
Invalid and remove interface are all for deleting data. But remove just delete
data from one data cluster and invalid delete data from a couple of clusters.
Cluster to be deleted is configed in invalid server by config server. Invalid
interface requests is sent to invalid server, not cluster directly.
2
3. Figure 2: Configuration of TairManager
3.5 Counter
Counter can be implemented by incr and decr interface. Increment or decrement
is atomic. Counter doesn’t have version concept.
3.6 Lookup Table
Lookup table is routing table in fact. Traditionally, tair use key hash value mod
the number of machines for routing. This method can be implemented easily,
but if machines are added or cut down, tair routing rule can’t change quickly.
In tair 2, method of modding is improved, using key hash value mod a
constant value , not the number of machines. How to choose the value is a
trick. If the value is too small then when the number of machines exceeds it,
tair can’t map key to data server. Otherwise, if the value is too large, the lookup
table will become large too in config server. So, suitable is best. In tair 2, 10243
is chosen.
4 Sample
This article will use tstar as sample. Sample will use modelCache for short. The
configuration of tair is done by spring IOC. The configuration of tairManager
is shown in Fig. 2. In bean configuration, configServerList is the config server
setting. In sample, there are two lists for mutual backup. GroupName decides
data server is in which group. Timeout is default time for data expire.
When tairManager is configed, developers can use it in concrete business
such as modelCache shown in Fig. 3. Expire is the time for data in modelCache
dying. Area is namespace for key kown from the same key in other application.
In ModelCahe, developer can use all the interface of tair client for caching. It
is so easy.
3
4. Figure 3: Configuration of ModelCache
5 Conclusion
Tair is a high performance and strong utility for key/value data distributed
storage. It is convenient for engineers to use by simple interfaces. This article is
a introduction to tair paying more attention to tair client, not include tair server
implementation. Tair server is developed using C++. Tair is a very important
distributed storage in taobao data platform. In the future, it will support simple
structuring such as JSON, not java serialization when dealing with simple java
object. It will also support SQL-like grammar for selecting. Let’s look forward
to stronger tair.
4