SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Spanner: Google’s Globally- 
Distributed Database 
J. C. Corbett, J. Dean, M. Epstein, A. Fikes, C. Frost, J. J. Furman, S. Ghemawat, A. Gubarev, C. Heiser, P. 
Hochschild, and others, “Spanner: Google’s globally distributed database,” ACM Transactions on Computer 
Systems (TOCS), vol. 31, no. 3, p. 8, 2013.
Helpful Definitions 
Sharding: is a type of database partitioning that separates very large 
databases the into smaller, faster, more easily managed parts called 
data shards. The word shard means a small part of a whole. 
Replication: Sharing of information to improve availability, durability 
1. Transactional replication. This is the model for replicating transactional 
data, for example a database or some other form of transactional storage 
structure with one-copy serializability. 
2. State machine replication. This model assumes that replicated process is a 
deterministic finite automaton and that atomic broadcast of every event is 
possible, usually implemented by a replicated log consisting of multiple 
subsequent rounds of the Paxos algorithm. 
3. Virtual synchrony. This computational model is used when a group of 
processes cooperate to replicate in-memory data or to coordinate actions.
Helpful Definitions 
Clock drift: several related phenomena where a clock does not run at 
the exact right speed compared to another clock. That is, after some 
time the clock "drifts apart" from the other clock. 
- Everyday clocks such as wristwatches have finite precision. 
Eventually they require correction to remain accurate. The rate of 
drift depends on the clock's quality, sometimes the stability of the 
power source, the ambient temperature, and other subtle 
environmental variables. Thus the same clock can have different 
drift rates at different occasions. 
- Atomic clocks are very precise and have nearly no clock drift. Even 
the Earth's rotation rate has more drift and variation in drift than an 
atomic clock. 
- As Einstein predicted, relativistic effects can also cause clock drift 
due to time dilation or gravitational distortions.
Wilson Hsieh, Google Inc presents Spanner at OSDI 2012 
https://www.usenix.org/conference/osdi12/technical-sessions/presentation/corbett
Spanner in a Nutshell 
1. Lock-Free distributed read only transactions 
2. External consistency of writes 
3. Temporal multiple versioning 
4. Schematized, semi-relational database with 
associated structured query language 
5. Applications control replication and placement 
6. All of this because of TrueTime
Implementation 
Spanner “Universe” 
Zones 
DataCenters
Zone Server Organization 
- zonemaster (1 per zone) assigns 
data to the span servers (similar 
to NameNode in GFS) 
- spanserver (100 - 3000 per 
zone) serves data to the clients 
- Proxies are used by clients to 
locate span servers with the 
correct data (shard lookup) these 
are used to prevent bottleneck at 
zonemaster 
1 per universe: 
- universemaster has a console 
with status information 
- placement driver handles data 
movement for replication or load 
balancing purposes
Storage Data Model 
(key:string, timestamp:int64) → 
string 
- Tablet: a bag of timestamped key,val pairs as above 
- Tablet’s state is tracked and stored with B-tree-like files and a 
write-ahead log. Data storage is on a distributed filesystem 
(Colossus, the successor to GFS at Google). 
Tablets are optimized data structures first implemented by BigTable to 
track data by row/column position (the keys) and their locations on 
GFS. In BigTable (and presumably Spanner as well) Tablets are 
compressed using Snappy to keep them approximately 200 MB in size. 
Tablets (for now) can be seen as the basic unit of replication/sharding.
Zone Software Stack 
- each tablet gets a Paxos 
state machine that maintains 
its log and state in the tablet 
(Paxos writes twice) 
- Paxos has long lived leaders 
(10 seconds) and is pipelined 
to improve for WAN latencies 
- Paxos is used to maintain 
consistency among replicas; 
every write must initiate at the 
Paxos leader. 
- The set of replicas is 
collectively a Paxos group.
Zone Software Stack Continued 
- Each leader maintains a lock 
table with state for two phase 
locking, mapping range of 
keys to lock states. 
- Long lived leader and is 
critical, design for long-lived 
transactions (reports). 
- Transaction manager is used 
to implement distributed 
transactions and to select a 
participant leader, which 
coordinates Paxos between 
participant groups.
Buckets* and Data Locality 
- Directories: collection of contiguous keys that share a prefix. 
- Prefixes allow applications to control the locality of their data. 
- All data in a directory has same replica configuration; movement of 
data between Paxos groups is via directory, in order to store data in 
a group closer to its accessors. 
- Spanner Tablet != BigTable Tablet, Spanner containers 
encapsulate multiple partitions of row space. 
- Smallest unit of geographic replication properties (placement)
Application Data Model 
- schematized, semi-relational 
tables and a structured query 
language + general purpose 
transactions. 
- Is 2PC too expensive? Leave 
it to the application to deal 
with performance. 
- On top of Buckets an 
application creates a 
database in the universe, 
composed of tables. 
- But not actually relational; all 
rows must have primary keys.
TrueTime 
- Time is an interval with timestamp endpoints 
- TT.now() → returns a TTinterval: [earliest, latest] 
- TT.after(t) → returns True iff t > latest 
- TT.before(t) → returns True iff t < earliest 
-  is the instantaneous error bound (half the intervals width) 
- Clients poll TimeMasters (GPS and Atomic Clocks) and use 
Marzullo’s algorithm to detect and reject liars. Also detect bad local 
times or clocks. 
- Between polls,  gets increasingly larger until the next poll and 
this increase is derived from worst-case local clock drift 
(significantly larger than expected).
Marzullo’s Algorithm 
- An agreement algorithm used to select sources for estimating 
accurate time from a number of noisy time sources. 
- A refined version of it, renamed the intersection algorithm, forms 
part of the modern NTP. 
- Usually the best estimate is taken to be the smallest interval 
consistent with the largest number of sources.
Concurrency Control 
- read-only transactions 
- Not simply read-write transactions w/o writes 
- execute at a system chosen timestamp 
- non-blocking (incoming writes aren’t locked) 
- proceeds on any replica sufficiently up to date 
- snapshot-reads 
- client specified timestamp 
- proceeds on any replica sufficiently up to date 
- commit is inevitable once timestamp is 
chosen so clients can avoid buffering.
scope LastTS() 
sread slates 
Read Only Transactions 
t 
searlies 
t 
Paxos Group Leader 
Up to date replica
2PC and RW Transactions 
- timestamps assigned anytime when locks have been 
acquired but before lock is released. 
- within each Paxos group, Spanner assigns timestamps in 
monotonically increasing order, even across leaders. 
- A leader must only assign timestamps within its leader lease 
External consistency for T1 and T2: tabs(e1 
commit)  tabs(e2 
start) 
- The coordinator leader for a write Ti assigns a commit 
timestamp si no less than the value of TT.now().latest 
- Coordinator ensures clients see no data committed by Ti until 
TT.after(si) is true using a commit wait.
RW Transactions - Other Details 
- Writes are buffered until a commit; reads in a transaction do 
not see the effects of the transaction’s writes. 
- Uncommitted data is not assigned a timestamp 
- Reads in RWX use wound-wait to avoid deadlocks 
(preference given to older transaction) 
Client: 
1. Acquire locks, read most recent data 
2. Send keep alive messages to avoid timeouts 
3. Begin two phase commit 
4. Choose coordinator group, send commit to each leader 
Having client drive 2PC avoids sending data twice
Acquired 
Locks 
Compute s 
Read-Write Transactions 
Tc 
TP1 
Release 
Locks 
Committed 
Release 
Locks 
Compute s Prepared 
send s
Schema Change Transactions 
- The number of groups in the database could be in the 
millions, how do you make an atomic schema change? 
(BigTable only supports changes in one data center, but 
locks everything) 
- Spanner has a non-blocking variant of standard transactions 
for schema changes: 
1. Assign a timestamp in the future (registered during prepare) 
2. Reads and Writes synchronize with any registered schema at 
the future timestamp, but not before 
3. If they have reached the timestamp, they must block if their 
schemas are after timestamp t
Performance
F1 Case Study 
- Spanner started being experimentally evaluated under 
production workloads in early 2011, as part of a rewrite of 
Google’s advertising backend called F1. 
- Replaced a MySQL database that was manually sharded. 
- The uncompressed dataset is tens of terabytes. 
- Spanner removes need to manually reshard 
- Spanner provides synchronous replication and auto failover 
- F1 requires strong transactional semantics 
- Fairly invisible transfer from MySQL to Spanner; data center 
loss and swapping required only an update to schema to 
move leaders to closer front ends.
An Overview of Spanner: Google's Globally Distributed Database

Más contenido relacionado

La actualidad más candente

management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
Nilu Desai
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
Mohd Tousif
 
Foult Tolerence In Distributed System
Foult Tolerence In Distributed SystemFoult Tolerence In Distributed System
Foult Tolerence In Distributed System
Rajan Kumar
 

La actualidad más candente (20)

Load balancing
Load balancingLoad balancing
Load balancing
 
Memory management
Memory managementMemory management
Memory management
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
 
Fault tolerance
Fault toleranceFault tolerance
Fault tolerance
 
Cs8493 unit 2
Cs8493 unit 2Cs8493 unit 2
Cs8493 unit 2
 
Parallelism
ParallelismParallelism
Parallelism
 
Distributed Operating System
Distributed Operating SystemDistributed Operating System
Distributed Operating System
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Data-Intensive Technologies for Cloud Computing
Data-Intensive Technologies for CloudComputingData-Intensive Technologies for CloudComputing
Data-Intensive Technologies for Cloud Computing
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
IBM general parallel file system - introduction
IBM general parallel file system - introductionIBM general parallel file system - introduction
IBM general parallel file system - introduction
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Foult Tolerence In Distributed System
Foult Tolerence In Distributed SystemFoult Tolerence In Distributed System
Foult Tolerence In Distributed System
 
parallel language and compiler
parallel language and compilerparallel language and compiler
parallel language and compiler
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Applications of paralleL processing
Applications of paralleL processingApplications of paralleL processing
Applications of paralleL processing
 
Distributed shared memory ch 5
Distributed shared memory ch 5Distributed shared memory ch 5
Distributed shared memory ch 5
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
 
Fault tolerance
Fault toleranceFault tolerance
Fault tolerance
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
 

Similar a An Overview of Spanner: Google's Globally Distributed Database

Moving Towards a Streaming Architecture
Moving Towards a Streaming ArchitectureMoving Towards a Streaming Architecture
Moving Towards a Streaming Architecture
Gabriele Modena
 
Spanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docx
Spanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docxSpanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docx
Spanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docx
rafbolet0
 
Real Time OS For Embedded Systems
Real Time OS For Embedded SystemsReal Time OS For Embedded Systems
Real Time OS For Embedded Systems
Himanshu Ghetia
 

Similar a An Overview of Spanner: Google's Globally Distributed Database (20)

Os Concepts
Os ConceptsOs Concepts
Os Concepts
 
Moving Towards a Streaming Architecture
Moving Towards a Streaming ArchitectureMoving Towards a Streaming Architecture
Moving Towards a Streaming Architecture
 
Cloud Spanner
Cloud SpannerCloud Spanner
Cloud Spanner
 
Spanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docx
Spanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docxSpanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docx
Spanner Google’s Globally-Distributed DatabaseJames C. Corbett,.docx
 
Cassandra admin
Cassandra adminCassandra admin
Cassandra admin
 
Embedded os
Embedded osEmbedded os
Embedded os
 
Rtos Concepts
Rtos ConceptsRtos Concepts
Rtos Concepts
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05
 
Real Time OS For Embedded Systems
Real Time OS For Embedded SystemsReal Time OS For Embedded Systems
Real Time OS For Embedded Systems
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Storage for next-generation sequencing
Storage for next-generation sequencingStorage for next-generation sequencing
Storage for next-generation sequencing
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?
 
Bab 4
Bab 4Bab 4
Bab 4
 
An Optics Life
An Optics LifeAn Optics Life
An Optics Life
 
Software architecture for data applications
Software architecture for data applicationsSoftware architecture for data applications
Software architecture for data applications
 
Spanner (may 19)
Spanner (may 19)Spanner (may 19)
Spanner (may 19)
 
Interpreting the Data:Parallel Analysis with Sawzall
Interpreting the Data:Parallel Analysis with SawzallInterpreting the Data:Parallel Analysis with Sawzall
Interpreting the Data:Parallel Analysis with Sawzall
 
Salesforce enabling real time scenarios at scale using kafka
Salesforce enabling real time scenarios at scale using kafkaSalesforce enabling real time scenarios at scale using kafka
Salesforce enabling real time scenarios at scale using kafka
 
Lecture1
Lecture1Lecture1
Lecture1
 

Más de Benjamin Bengfort

Visual diagnostics for more effective machine learning
Visual diagnostics for more effective machine learningVisual diagnostics for more effective machine learning
Visual diagnostics for more effective machine learning
Benjamin Bengfort
 
Graph Based Machine Learning on Relational Data
Graph Based Machine Learning on Relational DataGraph Based Machine Learning on Relational Data
Graph Based Machine Learning on Relational Data
Benjamin Bengfort
 

Más de Benjamin Bengfort (19)

Getting Started with TRISA
Getting Started with TRISAGetting Started with TRISA
Getting Started with TRISA
 
Visual diagnostics for more effective machine learning
Visual diagnostics for more effective machine learningVisual diagnostics for more effective machine learning
Visual diagnostics for more effective machine learning
 
Visualizing Model Selection with Scikit-Yellowbrick: An Introduction to Devel...
Visualizing Model Selection with Scikit-Yellowbrick: An Introduction to Devel...Visualizing Model Selection with Scikit-Yellowbrick: An Introduction to Devel...
Visualizing Model Selection with Scikit-Yellowbrick: An Introduction to Devel...
 
Dynamics in graph analysis (PyData Carolinas 2016)
Dynamics in graph analysis (PyData Carolinas 2016)Dynamics in graph analysis (PyData Carolinas 2016)
Dynamics in graph analysis (PyData Carolinas 2016)
 
Visualizing the Model Selection Process
Visualizing the Model Selection ProcessVisualizing the Model Selection Process
Visualizing the Model Selection Process
 
Data Product Architectures
Data Product ArchitecturesData Product Architectures
Data Product Architectures
 
A Primer on Entity Resolution
A Primer on Entity ResolutionA Primer on Entity Resolution
A Primer on Entity Resolution
 
An Interactive Visual Analytics Dashboard for the Employment Situation Report
An Interactive Visual Analytics Dashboard for the Employment Situation ReportAn Interactive Visual Analytics Dashboard for the Employment Situation Report
An Interactive Visual Analytics Dashboard for the Employment Situation Report
 
Graph Based Machine Learning on Relational Data
Graph Based Machine Learning on Relational DataGraph Based Machine Learning on Relational Data
Graph Based Machine Learning on Relational Data
 
Introduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-Learn
 
Fast Data Analytics with Spark and Python
Fast Data Analytics with Spark and PythonFast Data Analytics with Spark and Python
Fast Data Analytics with Spark and Python
 
Evolutionary Design of Swarms (SSCI 2014)
Evolutionary Design of Swarms (SSCI 2014)Evolutionary Design of Swarms (SSCI 2014)
Evolutionary Design of Swarms (SSCI 2014)
 
Graph Analyses with Python and NetworkX
Graph Analyses with Python and NetworkXGraph Analyses with Python and NetworkX
Graph Analyses with Python and NetworkX
 
Natural Language Processing with Python
Natural Language Processing with PythonNatural Language Processing with Python
Natural Language Processing with Python
 
Beginners Guide to Non-Negative Matrix Factorization
Beginners Guide to Non-Negative Matrix FactorizationBeginners Guide to Non-Negative Matrix Factorization
Beginners Guide to Non-Negative Matrix Factorization
 
Building Data Products with Python (Georgetown)
Building Data Products with Python (Georgetown)Building Data Products with Python (Georgetown)
Building Data Products with Python (Georgetown)
 
Annotation with Redfox
Annotation with RedfoxAnnotation with Redfox
Annotation with Redfox
 
Rasta processing of speech
Rasta processing of speechRasta processing of speech
Rasta processing of speech
 
Building Data Apps with Python
Building Data Apps with PythonBuilding Data Apps with Python
Building Data Apps with Python
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

An Overview of Spanner: Google's Globally Distributed Database

  • 1. Spanner: Google’s Globally- Distributed Database J. C. Corbett, J. Dean, M. Epstein, A. Fikes, C. Frost, J. J. Furman, S. Ghemawat, A. Gubarev, C. Heiser, P. Hochschild, and others, “Spanner: Google’s globally distributed database,” ACM Transactions on Computer Systems (TOCS), vol. 31, no. 3, p. 8, 2013.
  • 2. Helpful Definitions Sharding: is a type of database partitioning that separates very large databases the into smaller, faster, more easily managed parts called data shards. The word shard means a small part of a whole. Replication: Sharing of information to improve availability, durability 1. Transactional replication. This is the model for replicating transactional data, for example a database or some other form of transactional storage structure with one-copy serializability. 2. State machine replication. This model assumes that replicated process is a deterministic finite automaton and that atomic broadcast of every event is possible, usually implemented by a replicated log consisting of multiple subsequent rounds of the Paxos algorithm. 3. Virtual synchrony. This computational model is used when a group of processes cooperate to replicate in-memory data or to coordinate actions.
  • 3. Helpful Definitions Clock drift: several related phenomena where a clock does not run at the exact right speed compared to another clock. That is, after some time the clock "drifts apart" from the other clock. - Everyday clocks such as wristwatches have finite precision. Eventually they require correction to remain accurate. The rate of drift depends on the clock's quality, sometimes the stability of the power source, the ambient temperature, and other subtle environmental variables. Thus the same clock can have different drift rates at different occasions. - Atomic clocks are very precise and have nearly no clock drift. Even the Earth's rotation rate has more drift and variation in drift than an atomic clock. - As Einstein predicted, relativistic effects can also cause clock drift due to time dilation or gravitational distortions.
  • 4. Wilson Hsieh, Google Inc presents Spanner at OSDI 2012 https://www.usenix.org/conference/osdi12/technical-sessions/presentation/corbett
  • 5. Spanner in a Nutshell 1. Lock-Free distributed read only transactions 2. External consistency of writes 3. Temporal multiple versioning 4. Schematized, semi-relational database with associated structured query language 5. Applications control replication and placement 6. All of this because of TrueTime
  • 7. Zone Server Organization - zonemaster (1 per zone) assigns data to the span servers (similar to NameNode in GFS) - spanserver (100 - 3000 per zone) serves data to the clients - Proxies are used by clients to locate span servers with the correct data (shard lookup) these are used to prevent bottleneck at zonemaster 1 per universe: - universemaster has a console with status information - placement driver handles data movement for replication or load balancing purposes
  • 8. Storage Data Model (key:string, timestamp:int64) → string - Tablet: a bag of timestamped key,val pairs as above - Tablet’s state is tracked and stored with B-tree-like files and a write-ahead log. Data storage is on a distributed filesystem (Colossus, the successor to GFS at Google). Tablets are optimized data structures first implemented by BigTable to track data by row/column position (the keys) and their locations on GFS. In BigTable (and presumably Spanner as well) Tablets are compressed using Snappy to keep them approximately 200 MB in size. Tablets (for now) can be seen as the basic unit of replication/sharding.
  • 9. Zone Software Stack - each tablet gets a Paxos state machine that maintains its log and state in the tablet (Paxos writes twice) - Paxos has long lived leaders (10 seconds) and is pipelined to improve for WAN latencies - Paxos is used to maintain consistency among replicas; every write must initiate at the Paxos leader. - The set of replicas is collectively a Paxos group.
  • 10. Zone Software Stack Continued - Each leader maintains a lock table with state for two phase locking, mapping range of keys to lock states. - Long lived leader and is critical, design for long-lived transactions (reports). - Transaction manager is used to implement distributed transactions and to select a participant leader, which coordinates Paxos between participant groups.
  • 11. Buckets* and Data Locality - Directories: collection of contiguous keys that share a prefix. - Prefixes allow applications to control the locality of their data. - All data in a directory has same replica configuration; movement of data between Paxos groups is via directory, in order to store data in a group closer to its accessors. - Spanner Tablet != BigTable Tablet, Spanner containers encapsulate multiple partitions of row space. - Smallest unit of geographic replication properties (placement)
  • 12. Application Data Model - schematized, semi-relational tables and a structured query language + general purpose transactions. - Is 2PC too expensive? Leave it to the application to deal with performance. - On top of Buckets an application creates a database in the universe, composed of tables. - But not actually relational; all rows must have primary keys.
  • 13. TrueTime - Time is an interval with timestamp endpoints - TT.now() → returns a TTinterval: [earliest, latest] - TT.after(t) → returns True iff t > latest - TT.before(t) → returns True iff t < earliest - is the instantaneous error bound (half the intervals width) - Clients poll TimeMasters (GPS and Atomic Clocks) and use Marzullo’s algorithm to detect and reject liars. Also detect bad local times or clocks. - Between polls, gets increasingly larger until the next poll and this increase is derived from worst-case local clock drift (significantly larger than expected).
  • 14. Marzullo’s Algorithm - An agreement algorithm used to select sources for estimating accurate time from a number of noisy time sources. - A refined version of it, renamed the intersection algorithm, forms part of the modern NTP. - Usually the best estimate is taken to be the smallest interval consistent with the largest number of sources.
  • 15. Concurrency Control - read-only transactions - Not simply read-write transactions w/o writes - execute at a system chosen timestamp - non-blocking (incoming writes aren’t locked) - proceeds on any replica sufficiently up to date - snapshot-reads - client specified timestamp - proceeds on any replica sufficiently up to date - commit is inevitable once timestamp is chosen so clients can avoid buffering.
  • 16. scope LastTS() sread slates Read Only Transactions t searlies t Paxos Group Leader Up to date replica
  • 17. 2PC and RW Transactions - timestamps assigned anytime when locks have been acquired but before lock is released. - within each Paxos group, Spanner assigns timestamps in monotonically increasing order, even across leaders. - A leader must only assign timestamps within its leader lease External consistency for T1 and T2: tabs(e1 commit) tabs(e2 start) - The coordinator leader for a write Ti assigns a commit timestamp si no less than the value of TT.now().latest - Coordinator ensures clients see no data committed by Ti until TT.after(si) is true using a commit wait.
  • 18. RW Transactions - Other Details - Writes are buffered until a commit; reads in a transaction do not see the effects of the transaction’s writes. - Uncommitted data is not assigned a timestamp - Reads in RWX use wound-wait to avoid deadlocks (preference given to older transaction) Client: 1. Acquire locks, read most recent data 2. Send keep alive messages to avoid timeouts 3. Begin two phase commit 4. Choose coordinator group, send commit to each leader Having client drive 2PC avoids sending data twice
  • 19. Acquired Locks Compute s Read-Write Transactions Tc TP1 Release Locks Committed Release Locks Compute s Prepared send s
  • 20. Schema Change Transactions - The number of groups in the database could be in the millions, how do you make an atomic schema change? (BigTable only supports changes in one data center, but locks everything) - Spanner has a non-blocking variant of standard transactions for schema changes: 1. Assign a timestamp in the future (registered during prepare) 2. Reads and Writes synchronize with any registered schema at the future timestamp, but not before 3. If they have reached the timestamp, they must block if their schemas are after timestamp t
  • 22. F1 Case Study - Spanner started being experimentally evaluated under production workloads in early 2011, as part of a rewrite of Google’s advertising backend called F1. - Replaced a MySQL database that was manually sharded. - The uncompressed dataset is tens of terabytes. - Spanner removes need to manually reshard - Spanner provides synchronous replication and auto failover - F1 requires strong transactional semantics - Fairly invisible transfer from MySQL to Spanner; data center loss and swapping required only an update to schema to move leaders to closer front ends.