Monday, October 22, 2007

Bigtable

Disclaimer: I'm a Google employee now but this article was written before I joined Google and only contains information available in the OSDI 2006 paper by Fay Chang et al on Bigtable intermixed with notes on my understanding of Bigtable at that time.

Bigtable is mainly a multi-dimensional sorted map. It is not a relational database, it is not a file system. Like a sorted map it supports lookup and update operations, and given its multi-dimensional nature the creators have also provided an atomic row-update operation. However, the key innovations in Bigtable are its distributed nature, efficient operation, fault recovery, ability to scale to huge datasets, and all this while maintaining a much more structured interface than conventional file systems.

Bigtable does not support a full relational data model; instead, it provides clients with a simple data model that supports dynamic control over data layout and format, and allows clients to reason about the locality properties of the data represented in the underlying storage. Clients can control the locality of their data through careful choices in their schemas. Finally, Bigtable schema parameters let clients dynamically control whether to serve data out of memory or from disk.

Every read or write of data under a single row key is atomic (regardless of the number of different columns being read or written in the row), a design decision that makes it easier for clients to reason about the system's behavior in the presence of concurrent updates to the same row.

The row range for a table is dynamically partitioned. Each row range is called a tablet, which is the unit of distribution and load balancing. As a result, reads of short row ranges are efficient and typically require communication with only a small number of machines. Clients can exploit this property by selecting their row keys so that they get good locality for their data accesses. For example, in Webtable, pages in the same domain are grouped together into contiguous rows by reversing the hostname components of the URLs.

Column families:
  • Basic unit of access control
  • All data stored in a column family is usually of the same type (we compress data in the same column family together).
  • Every column key must belong to some column family: A column family must be created before data can be stored under any column key in that family; after a family has been created, any column key within the family can be used.
  • It is our intent that the number of distinct column families in a table be small (in the hundreds at most), and that families rarely change during operation.
  • Access control and both disk and memory accounting are performed at the column-family level.
Column families are further grouped together into locality groups which support several performance optimizations.

Each cell in a Bigtable can contain multiple versions of the same data; these versions are indexed by timestamp. Bigtable timestamps are 64-bit integers.
  • Different versions of a cell are stored in decreasing timestamp order, so that the most recent versions can be read first.
  • To make the management of versioned data less onerous, we support two per-column-family settings that tell Bigtable to garbage-collect cell versions automatically. The client can specify either that only the last n versions of a cell be kept, or that only new-enough versions be kept.

API:
  • General operations like looking up values, iterating over them, etc. using regexps for identifying rows/columns/families.
  • Single row transactions
  • Sawzall based scripts to work on bigtable servers.
  • Use cells as int counters

Data layout:

Bigtable ultimately is based on GFS. But the actual data layout of bigtable data is in sstable format which is mainly a log-structured data layout formed by appending block writes and ending with a dump of the index (sstable "open" operation results in the index being loaded into memory). So it's very much like a checkpointing based CDP log format or an LFS format. All bigtable data is immutable, so incoming writes are simply appended to the sstable "file" on gfs. Periodically, the index is dumped checkpointing the current state of the cell data, so following a crash the exact state can be derived by starting from the last checkpoint dump and replaying the redo log since then. Bigtable does some optimizations though by introducing a delay in appending fresh data to the sstable which allows for write gathering resulting in compaction of data. Memtable is mainly an optimization that stores the current state of an sstable in memory (I think). Just like in CDP, memtable rows are copy-on-write. This kind of arrangement also fairs very well for concurrent reads, writes, etc.

Architecture:
  • Split across master - tablet server - client with client contacting tablet server directly using lookup mechanism described below. Master's job is to manage tablet allocation to tablet servers.
  • Each tablet server serves several tablets, possibly for different tables. Tablets are dynamic, they are split when they grow too large - their size is bet. 100 and 200MB.

Tablet lookup: Three level
FindLocation(userTable, tableRow):
  1. chubbyOpenAndRead("file_containing_location_of_rootTable") = rootTableLocation
  2. rootTable.FindLocation(metadata(userTable,tableRow)) = metadataTableLocation
  3. metadataTablet.FindLocation(userTable,tableRow) = userTableLocation
More about Chubby at Google labs and my post on Paxos.
.


Tablet assignment to tablet servers is a classic distributed system problem since the assignment must be "consistent" between the master and the tablet servers. This is accomplished using chubby lock files associated with master sessions and tablet server sessions with one key feature: whenever a lock is lost, the owner kills itself resulting in a restart.

Tablet serving:
Requires a combination of memtable, sstable, and compaction features . The data layout really improves the performance of tablet serving even in the presence of concurrent access.

Performance enhacements:
  • Locality groups: Storing several column families together in one SSTable.
  • Compression: compressing a locality group.
  • Per locality group bloom filter: allows us to check if the sstable for a given locality group contains something for a given key or not. Avoids going to disk if the sstable index is not preloaded into memory.
  • Instead of using per-tablet commit log, a single commit-log is used per tablet-server. This reduces no. of commit log files and gives good sequential write performance. However, it complicates tablet-server recovery: when a tablet-server dies, its tablets are passed on to many other tablet-servers and each of them will try to scan the log looking for the particular tablet assigned to it. So recovery is preceded by a sorting phase where the log is sorted by tabletID using map reduce.
  • Most important optimization: immutability of sstables. Since data written to sstables is immutable, there is no synchronization overhead when reading from sstables. So concurrency control becomes trivial. Row-level transactions do require concurrency control but they are aided by the mutability of memtable which is always implemented using copy-on-write. So concurrent transactions on a row + reads are very efficient.

Most interesting related work:

The Boxwood project [24] has components that overlap in some ways with Chubby, GFS, and Bigtable, since it provides for distributed agreement, locking, distributed chunk storage, and distributed B-tree storage. In each case where there is overlap, it appears that the Boxwood's component is targeted at a somewhat lower level than the corresponding Google service. The Boxwood project's goal is to provide infrastructure for building higher-level services such as le systems or databases, while the goal of Bigtable is to directly support client applications that wish to store data.

Further reading:
  1. OSDI 2006 Bigtable paper
  2. Interesting paper on log-structured merge tree which explains how Memtable + SStable might work together.