本書先從NoSQL的核心概念開始介紹:無模式的數據模型、新的分布式模型、CAP理論等,然后介紹了在實現NoSQL會遇到的體系結構和設計方面的問題,并以很有代表性的幾種數據庫:Riak、MongoDB、Cassandra和Neo4j為例,展示了NoSQL數據庫的使用。
目 錄
前言
**部分 概念
第1章 為什么使用NoSQL3
1.1 關系型數據庫的價值3
1.1.1 獲取持久化數據3
1.1.2 并發4
1.1.3 集成4
1.1.4 近乎標準的模型4
1.2 阻抗失諧5
1.3 “應用程序數據庫”與“集成數據庫”6
1.4 蜂擁而來的集群8
1.5 NoSQL登場9
1.6 要點12
第2章 聚合數據模型13
2.1 聚合14
2.1.1 關系模型與聚合模型示例14
2.1.2 面向聚合的影響19
2.2 鍵值數據模型與文檔數據模型20
2.3 列族存儲21
2.4 面向聚合數據庫總結23
2.5 延伸閱讀24
2.6 要點24
第3章 數據模型詳解25
3.1 關系25
3.2 圖數據庫26
3.3 無模式數據庫28
3.4 物化視圖30
3.5 構建數據存取模型31
3.6 要點36
第4章 分布式模型37
4.1 單一服務器37
4.2 分片38
4.3 主從復制40
4.4 對等復制42
4.5 結合“分片”與“復制”技術43
4.6 要點44
第5章 一致性47
5.1 更新一致性47
5.2 讀取一致性49
5.3 放寬“一致性”約束52
5.4 放寬“持久性”約束56
5.5 仲裁57
5.6 延伸閱讀59
5.7 要點59
第6章 版本戳61
6.1 “商業事務”與“系統事務”61
6.2 在多節點環境中生成版本戳63
6.3 要點65
第7章 映射-化簡67
7.1 基本“映射-化簡”68
7.2 分區與歸并69
7.3 組合“映射-化簡”計算72
7.3.1 舉例說明兩階段“映射-化簡”73
7.3.2 增量式“映射-化簡”76
7.4 延伸閱讀77
7.5 要點77
第二部分 實現
第8章 鍵值數據庫81
8.1 何謂“鍵值數據庫”81
8.2 鍵值數據庫特性83
8.2.1 一致性83
8.2.2 事務84
8.2.3 查詢功能84
8.2.4 數據結構86
8.2.5 可擴展性86
8.3 適用案例87
8.3.1 存放會話信息87
8.3.2 用戶配置信息87
8.3.3 購物車數據87
8.4 不適用場合87
8.4.1 數據間關系87
8.4.2 含有多項操作的事務88
8.4.3 查詢數據88
8.4.4 操作關鍵字集合88
第9章 文檔數據庫89
9.1 何謂文檔數據庫90
9.2 特性91
9.2.1 一致性91
9.2.2 事務92
9.2.3 可用性93
9.2.4 查詢功能94
9.2.5 可擴展性95
9.3 適用案例97
9.3.1 事件記錄97
9.3.2 內容管理系統及博客平臺98
9.3.3 網站分析與實時分析98
9.3.4 電子商務應用程序98
9.4 不適用場合98
9.4.1 包含多項操作的復雜事務98
9.4.2 查詢持續變化的聚合結構98
第10章 列族數據庫99
10.1 何謂列族數據庫99
10.2 特性100
10.2.1 一致性103
10.2.2 事務104
10.2.3 可用性104
10.2.4 查詢功能105
10.2.5 可擴展性107
10.3 適用案例107
10.3.1 事件記錄107
10.3.2 內容管理系統與博客平臺108
10.3.3 計數器108
10.3.4 限期使用108
10.4 不適用場合109
第11章 圖數據庫111
11.1 何謂圖數據庫111
11.2 特性113
11.2.1 一致性114
11.2.2 事務114
11.2.3 可用性115
11.2.4 查詢功能115
11.2.5 可擴展性119
11.3 適用案例120
11.3.1 互聯數據120
11.3.2 安排運輸路線、分派貨物和基于位置的服務120
11.3.3 推薦引擎121
11.4 不適用場合121
第12章 模式遷移123
12.1 模式變更123
12.2 變更關系型數據庫的模式123
12.2.1 遷移全新項目124
12.2.2 遷移既有項目126
12.3 變更NoSQL數據庫的模式128
12.3.1 增量遷移130
12.3.2 遷移圖數據庫的模式131
12.3.3 改變聚合結構132
12.4 延伸閱讀132
12.5 要點132
第13章 混合持久化133
13.1 各異的數據存儲需求133
13.2 混用各類數據庫134
13.3 將直接數據庫操作封裝為服務136
13.4 擴展數據庫以增強其功能136
13.5 選用合適的數據庫技術138
13.6 企業使用混合持久化技術時的考量138
13.7 部署復雜度139
13.8 要點140
第14章 超越NoSQL141
14.1 文件系統141
14.2 事件溯源142
14.3 內存映像144
14.4 版本控制145
14.5 XML數據庫145
14.6 對象數據庫146
14.7 要點146
第15章 選擇合適的數據庫147
15.1 程序員的工作效率149
15.2 數據訪問性能150
15.3 繼續沿用默認的關系型數據庫150
15.4 抽離數據庫策略以降低風險151
15.5 要點152
15.6 結語153
參考資料157
Contents
Part I: Understand . 1
Chapter 1: Why NoSQL? 3
1.1 The Value of Relational Databases 3
1.1.1 Getting at Persistent Data 3
1.1.2 Concurrency 4
1.1.3 Integration . 4
1.1.4 A (Mostly) Standard Model 4
1.2 Impedance Mismatch 5
1.3 Application and Integration Databases 6
1.4 Attack of the Clusters 8
1.5 The Emergence of NoSQL . 9
1.6 Key Points 12
Chapter 2: Aggregate Data Models 13
2.1 Aggregates . 14
2.1.1 Example of Relations and Aggregates 14
2.1.2 Consequences of Aggregate Orientation 19
2.2 Key-Value and Document Data Models . 20
2.3 Column-Family Stores . 21
2.4 Summarizing Aggregate-Oriented Databases . 23
2.5 Further Reading . 24
2.6 Key Points 24
Chapter 3: More Details on Data Models . 25
3.1 Relationships . 25
3.2 Graph Databases . 26
3.3 Schemaless Databases 28
3.4 Materialized Views 30
3.5 Modeling for Data Access 31
3.6 Key Points 36
Chapter 4: Distribution Models . 37
4.1 Single Server 37
4.2 Sharding 38
4.3 Master-Slave Replication . 40
4.4 Peer-to-Peer Replication . 42
4.5 Combining Sharding and Replication 43
4.6 Key Points 44
Chapter 5: Consistency 47
5.1 Update Consistency . 47
5.2 Read Consistency . 49
5.3 Relaxing Consistency . 52
5.3.1 The CAP Theorem 53
5.4 Relaxing Durability . 56
5.5 Quorums . 57
5.6 Further Reading . 59
5.7 Key Points 59
Chapter 6: Version Stamps . 61
6.1 Business and System Transactions 61
6.2 Version Stamps on Multiple Nodes 63
6.3 Key Points 65
Chapter 7: Map-Reduce . 67
7.1 Basic Map-Reduce . 68
7.2 Partitioning and Combining . 69
7.3 Composing Map-Reduce Calculations . 72
7.3.1 A Two Stage Map-Reduce Example 73
7.3.2 Incremental Map-Reduce . 76
7.4 Further Reading . 77
7.5 Key Points 77
Part II: Implement 79
Chapter 8: Key-Value Databases 81
8.1 What Is a Key-Value Store . 81
8.2 Key-Value Store Features . 83
8.2.1 Consistency . 83
8.2.2 Transactions 84
8.2.3 Query Features . 84
8.2.4 Structure of Data 86
8.2.5 Scaling 86
8.3 Suitable Use Cases . 87
8.3.1 Storing Session Information . 87
8.3.2 User Pro.les, Preferences . 87
8.3.3 Shopping Cart Data 87
8.4 When Not to Use . 87
8.4.1 Relationships among Data . 87
8.4.2 Multioperation Transactions 88
8.4.3 Query by Data . 88
8.4.4 Operations by Sets 88
Chapter 9: Document Databases 89
9.1 What Is a Document Database? . 90
9.2 Features . 91
9.2.1 Consistency . 91
9.2.2 Transactions 92
9.2.3 Availability 93
9.2.4 Query Features . 94
9.2.5 Scaling 95
9.3 Suitable Use Cases . 97
9.3.1 Event Logging 97
9.3.2 Content Management Systems, Blogging Platforms . 98
9.3.3 Web Analytics or Real-Time Analytics . 98
9.3.4 E-Commerce Applications . 98
9.4 When Not to Use . 98
9.4.1 Complex Transactions Spanning Different Operations 98
9.4.2 Queries against Varying Aggregate Structure 98
Chapter 10: Column-Family Stores 99
10.1 What Is a Column-Family Data Store? . 99
10.2 Features . 100
10.2.1 Consistency 103
10.2.2 Transactions 104
10.2.3 Availability 104
10.2.4 Query Features . 105
10.2.5 Scaling 107
10.3 Suitable Use Cases 107
10.3.1 Event Logging 107
10.3.2 Content Management Systems, Blogging Platforms . 108
10.3.3 Counters 108
10.3.4 Expiring Usage . 108
10.4 When Not to Use . 109
Chapter 11: Graph Databases . 111
11.1 What Is a Graph Database? . 111
11.2 Features . 113
11.2.1 Consistency 114
11.2.2 Transactions 114
11.2.3 Availability 115
11.2.4 Query Features . 115
11.2.5 Scaling 119
11.3 Suitable Use Cases 120
11.3.1 Connected Data 120
11.3.2 Routing, Dispatch, and Location-Based Services . 120
11.3.3 Recommendation Engines 121
11.4 When Not to Use . 121
Chapter 12: Schema Migrations . 123
12.1 Schema Changes 123
12.2 Schema Changes in RDBMS 123
12.2.1 Migrations for Green Field Projects . 124
12.2.2 Migrations in Legacy Projects . 126
12.3 Schema Changes in a NoSQL Data Store . 128
12.3.1 Incremental Migration . 130
12.3.2 Migrations in Graph Databases 131
12.3.3 Changing Aggregate Structure 132
12.4 Further Reading . 132
12.5 Key Points 132
Chapter 13: Polyglot Persistence . 133
13.1 Disparate Data Storage Needs 133
13.2 Polyglot Data Store Usage 134
13.3 Service Usage over Direct Data Store Usage . 136
13.4 Expanding for Better Functionality 136
13.5 Choosing the Right Technology . 138
13.6 Enterprise Concerns with Polyglot Persistence . 138
13.7 Deployment Complexity 139
13.8 Key Points 140
Chapter 14: Beyond NoSQL 141
14.1 File Systems 141
14.2 Event Sourcing . 142
14.3 Memory Image . 144
14.4 Version Control . 145
14.5 XML Databases . 145
14.6 Object Databases . 146
14.7 Key Points 146
Chapter 15: Choosing Your Database 147
15.1 Programmer Productivity . 147
15.2 Data-Access Performance . 149
15.3 Sticking with the Default 150
15.4 Hedging Your Bets . 150
15.5 Key Points 151
15.6 Final Thoughts . 152
Bibliography . 153