内容简介
如果不用考虑可伸缩性,想象一下你能做些什么?在这本实践指南中,你将会了解到Cassandra数据库管理系统是如何在为多个数据中心提供高可用服务的同时处理上百TB的数据。扩充后的第二版已经更新到了Cassandra 3.0,书中给出了各种技术细节以及实例,当你将Cassandra投入实际生产环境时,这些内容都是必不可少的。
作者Jeff Carpenter和Eben Hewitt阐述了Cassandra非关系型设计的优势,着重介绍了其数据模型。
《Cassandra**指南(第2版 影印版)》向开发者、DBA、正在寻找数据库的可扩展性解决方案的应用架构师展示了Cassandra的速度和灵活性。
作者简介
Jeff Carpenter,精品国际酒店集团(Choice Hotels International)的一名系统架构师,在服务业和国防工业有着20年的从业经验。他的兴趣包括SOA/微服务、大规模系统架构设计以及数据架构。
EbenHewitt是精品国际酒店集团(世界大酒店之一)的首席技术官。
他还是好几本书籍的作者,题材涉及系统架构、分布式系统以及编程。
内页插图
目录
Foreword
Foreword
Preface
1.Beyond Relational Databases
What's Wrong with Relational Databases?
A Quick Review of Relational Databases
RDBMSs: The Awesome and the Not-So-Much
Web Scale
The Rise of NoSQL
Summary
2.Introducing Cassandra
The Cassandra Elevator Pitch
Cassandra in 50 Words or Less
Distributed and Decentralized
Elastic Scalability
High Availability and Fault Tolerance
Tuneable Consistency
Brewer's CAP Theorem
Row-Oriented
High Performance
Where Did Cassandra Come From?
Release History
Is Cassandra a Good Fit for My Project?
Large Deployments
Lots of Writes, Statistics, and Analysis
Geographical Distribution
Evolving Applications
Getting Involved
Summary
3.Installing Cassandra
Installing the Apache Distribution
Extracting the Download
What's In There?
Building from Source
Additional Build Targets
Running Cassandra
On Windows
On Linux
Starting the Server
Stopping Cassandra
Other Cassandra Distributioaas
Running the CQL Shell
Basic cqlsh Commands
cqlsh Help
Describing the Environment in cqlsh
Creating a Keyspace and Table in cqlsh
Writing and Reading Data in cqlsh
Summary
4.The Cassandra Query Language
The Relational Data Model
Cassandra's Data Model
Clusters
Keyspaces
Tables
Columns
CQL Types
Numeric Data Types
Textual Data Types
Time and Identity Data Types
Other Simple Data Types
Collections
User-Defined Types
Secondary Indexes
Summary
……
前言/序言
Cassandra was open-sourced by Facebook in July 2008. This original version of Cassandra was written primarily by an ex-employee from Amazon and one from Microsoft. It was strongly influenceyd by Dynamo, Amazon's pioneering distributed key/value database. Cassandra implements a Dynamo-style replication model with no single point of failure, but adds a more powerful "column family" data model.
I became involved in December of that year, when Rackspace asked me to build them a scalable database. This was good timing, because all of today's important open source scalable databases were available for evaluation, Despite initially having only a single major use case, Cassandra's underlying architecture was the strongest, and I
directed my efforts toward improving the code and building a community.
Cassandra was accepted into the Apache Incubator, and by the time it graduated in March 2010, it had become a true open source success story, with committers from Rackspace, Digg, Twitter, and other companies that wouldn't have written their own
database from scratch, but together built something important.
Today's Cassandra is much more than the early system that powered (and still powers) Facebook's inbox search; it has become "the hands-down winner for transaction
processing performance:' to quote Tony Bain, with a deserved reputation for reliability and performance at scale.
As Cassandra matured and began attracting more mainstream users, it became clear that there was a need for commeraal support; thus, Matt Pfeil and I cofounded Riptano in April 2010. Helping drive Cassandra adoption has been very rewarding, espeaally seeing the uses that don't get discussed in public.
Another need has been a book like this one. Like many open source projects, Cassandra's documentation has historically been weak. And even when the documentation
ultimately improves, a book-length treatment like this will remain useful.
数据库的未来:分布式、可扩展、高性能的基石 在当今数据爆炸式增长的时代,传统的关系型数据库已经难以满足日益增长的业务需求。海量数据的存储、高并发的读写、全球范围的可用性,这些挑战迫使我们寻找更强大的解决方案。分布式数据库应运而生,而 Cassandra,作为其中的佼佼者,正以前所未有的姿态改变着我们处理和利用数据的方式。 Cassandra:一个时代的开端 Apache Cassandra 是一个开源的、分布式、宽列存储数据库,它由 Facebook 开发并于 2008 年开源,随后成为 Apache 顶级项目。Cassandra 的设计初衷是为了解决大规模数据存储和高可用性问题,其卓越的性能和可扩展性使其迅速在业界获得了广泛的应用,成为许多全球性互联网公司和企业的首选数据库解决方案。 核心设计理念:去中心化与最终一致性 Cassandra 的核心魅力在于其去中心化的架构。不同于传统的单点故障的集中式数据库,Cassandra 采用了一种无主节点(masterless)的设计。这意味着集群中的所有节点都扮演着相同的角色,没有一个中心服务器来协调所有操作。这种设计带来了极高的可用性,即使部分节点发生故障,整个集群仍然能够对外提供服务。 另一个关键的设计理念是最终一致性(eventual consistency)。在分布式系统中,要实现强一致性(strong consistency)往往会牺牲可用性和性能。Cassandra 为了追求极致的可用性和性能,选择了最终一致性模型。这意味着在某个写操作完成后,系统会尽力将数据同步到所有副本,但在某些短暂的时间窗口内,不同的节点可能查询到稍有延迟的数据。然而,随着时间的推移,所有副本最终会达到一致。对于许多需要高吞吐量和低延迟的应用场景,例如实时数据流、IoT 设备数据收集等,最终一致性是完全可以接受的,甚至是一种优势。 为何选择 Cassandra? 卓越的可扩展性 (Scalability): Cassandra 的架构天生支持水平扩展。当数据量增长或流量增加时,只需简单地向集群中添加更多的节点,系统就能自动地将数据分布到新节点上,并无缝地接管流量。这种线性的可扩展性使得 Cassandra 能够应对 TB 甚至 PB 级别的数据,以及每秒百万级别的读写请求。 高可用性 (High Availability): Cassandra 的去中心化架构消除了单点故障。数据会在集群中被复制到多个节点上,并分布在不同的机架甚至不同的数据中心。即使某个节点、机架甚至整个数据中心发生故障,系统仍然能够正常运行,保证数据的可用性。 高性能 (Performance): Cassandra 针对写密集型负载进行了优化。其 LSM-tree (Log-Structured Merge-tree) 的存储引擎能够以极高的效率处理写入操作,并将后续的读取操作推迟到内存中或者优化后的磁盘结构中。这使得 Cassandra 在写入吞吐量方面表现出色,特别适合那些需要快速吞吐大量数据的应用。 灵活性 (Flexibility): Cassandra 采用宽列存储(wide-column store)模型。与传统的行式存储或文档存储不同,宽列存储允许每一行拥有不同的列,且列的数量可以非常多。这种动态的模式(schema-less 或 schema-on-read)为开发提供了极大的灵活性,特别是在数据结构经常变化的场景下,能够快速适应需求变化。 多数据中心部署 (Multi-Data Center Deployment): Cassandra 原生支持跨多个数据中心的部署,这使得企业可以在全球范围内建立具有容灾能力的分布式数据库系统。用户可以通过配置副本策略,将数据同步到不同的地理位置,从而在主数据中心不可用时,仍然能够保证服务的连续性。 Cassandra 的技术亮点 Gossip 协议: Cassandra 使用 Gossip 协议来维护集群节点之间的状态信息。每个节点定期与其他节点交换信息,从而快速传播集群的变化,如节点上线、下线等,确保集群状态的一致性。 Hinted Handoff: 当一个节点暂时无法响应时,其他节点会为它存储写入的提示(hints),待该节点恢复后,再将这些写入传递给它。这进一步增强了写操作的成功率和可用性。 Read Repair: Cassandra 会在读取数据时主动检查副本的一致性。如果发现不同副本上的数据不一致,它会在后台进行修复,从而确保数据的最终一致性。 Tunable Consistency (可调一致性): Cassandra 允许开发者在每次读写操作时,根据业务需求选择不同的一致性级别 (Consistency Level)。例如,可以选择 QUORUM(需要大多数副本确认写入或读取成功),或 ONE(只需要一个副本确认),这样可以在性能、可用性和一致性之间进行权衡。 CQL (Cassandra Query Language): Cassandra 提供了一种类似 SQL 的查询语言,称为 CQL。这使得熟悉 SQL 的开发者能够更容易地上传 Cassandra,降低了学习门槛。CQL 提供了丰富的数据操作和查询功能,支持索引、分页等特性。 Cassandra 的应用场景 Cassandra 的强大能力使其在众多领域有着广泛的应用: 大规模用户数据管理: 社交媒体平台、游戏平台等需要存储海量用户画像、社交关系、游戏进度等信息。 实时分析与监控: 物联网设备数据、日志数据、点击流数据等需要被实时采集、存储和分析。 推荐系统: 存储和查询用户偏好、商品信息,以支持个性化推荐。 时序数据存储: 存储传感器数据、股票行情、系统性能指标等随时间变化的数据。 内容管理系统: 存储和管理大量的媒体文件、文档等。 物联网 (IoT) 数据平台: 收集和处理来自海量物联网设备的海量传感器数据。 支付与交易系统: 处理高并发的交易请求,要求高可用性和低延迟。 Cassandra 生态系统 Cassandra 拥有一个活跃且不断壮大的生态系统。除了核心的数据库本身,还有一系列相关的工具和技术: 数据迁移工具: 帮助用户将现有数据迁移到 Cassandra。 监控和管理工具: 提供集群性能监控、故障诊断、性能调优等功能。 驱动程序: 支持多种编程语言,方便开发者集成 Cassandra 到应用程序中。 与大数据生态的集成: Cassandra 可以与 Hadoop、Spark、Kafka 等大数据处理框架无缝集成,构建完整的数据解决方案。 未来的展望 随着企业数字化转型的深入,以及对数据价值挖掘需求的不断增长,分布式数据库的重要性将愈发凸显。Cassandra 以其独特的设计理念、强大的性能和灵活的扩展性,已经证明了其在应对海量数据和高并发挑战方面的能力。无论是初创企业还是大型机构,在构建下一代数据平台时,Cassandra 都将是一个值得深入研究和选择的解决方案。它代表着数据库领域的一种未来趋势,一种能够支撑起现代互联网应用和数字经济的坚实基石。