Tài liệu HBase in Action docx

362 5.4K 3
Tài liệu HBase in Action docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MANNING Nick Dimiduk Amandeep Khurana FOREWORD BY Michael Stack www.it-ebooks.info HBase in Action NICK DIMIDUK AMANDEEP KHURANA TECHNICAL EDITOR MARK HENRY RYAN MANNING Shelter Island www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2013 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editors: Renae Gregoire, Susanna Kline 20 Baldwin Road Technical editor: Mark Henry Ryan PO Box 261 Technical proofreaders: Jerry Kuch, Kristine Kuch Shelter Island, NY 11964 Copyeditor: Tiffany Taylor Proofreaders: Elizabeth Martin, Alyson Brener Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617290527 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 17 16 15 14 13 12 www.it-ebooks.info iii brief contents PART 1 HBASE FUNDAMENTALS. 1 1 ■ Introducing HBase 3 2 ■ Getting started 21 3 ■ Distributed HBase, HDFS, and MapReduce 51 PART 2 ADVANCED CONCEPTS 83 4 ■ HBase table design 85 5 ■ Extending HBase with coprocessors 126 6 ■ Alternative HBase clients 143 PART 3 EXAMPLE APPLICATIONS 179 7 ■ HBase by example: OpenTSDB 181 8 ■ Scaling GIS on HBase 203 PART 4 OPERATIONALIZING HBASE . 237 9 ■ Deploying HBase 239 10 ■ Operations 264 www.it-ebooks.info www.it-ebooks.info v contents foreword xiii letter to the HBase community xv preface xvii acknowledgments xix about this book xxi about the authors xxv about the cover illustration xxvi PART 1 HBASE FUNDAMENTALS . 1 1 Introducing HBase 3 1.1 Data-management systems: a crash course 5 Hello, Big Data 6 ■ Data innovation 7 ■ The rise of HBase 8 1.2 HBase use cases and success stories 8 The canonical web-search problem: the reason for Bigtable’s invention 9 ■ Capturing incremental data 10 ■ Content serving 13 ■ Information exchange 14 1.3 Hello HBase 15 Quick install 16 ■ Interacting with the HBase shell 18 Storing data 18 1.4 Summary 20 www.it-ebooks.info CONTENTS vi 2 Getting started 21 2.1 Starting from scratch 22 Create a table 22 ■ Examine table schema 23 ■ Establish a connection 24 ■ Connection management 24 2.2 Data manipulation 25 Storing data 25 ■ Modifying data 26 ■ Under the hood: the HBase write path 26 ■ Reading data 28 ■ Under the hood: the HBase read path 29 ■ Deleting data 30 ■ Compactions: HBase housekeeping 30 ■ Versioned data 31 ■ Data model recap 32 2.3 Data coordinates 33 2.4 Putting it all together 35 2.5 Data models 39 Logical model: sorted map of maps 39 ■ Physical model: column family oriented 41 2.6 Table scans 42 Designing tables for scans 43 ■ Executing a scan 45 ■ Scanner caching 45 ■ Applying filters 46 2.7 Atomic operations 47 2.8 ACID semantics 48 2.9 Summary 48 3 Distributed HBase, HDFS, and MapReduce 51 3.1 A case for MapReduce 52 Latency vs. throughput 52 ■ Serial execution has limited throughput 53 ■ Improved throughput with parallel execution 53 ■ MapReduce: maximum throughput with distributed parallelism 55 3.2 An overview of Hadoop MapReduce 56 MapReduce data flow explained 57 ■ MapReduce under the hood 61 3.3 HBase in distributed mode 62 Splitting and distributing big tables 62 ■ How do I find my region? 64 ■ How do I find the -ROOT- table? 65 3.4 HBase and MapReduce 68 HBase as a source 68 ■ HBase as a sink 70 ■ HBase as a shared resource 71 www.it-ebooks.info CONTENTS vii 3.5 Putting it all together 75 Writing a MapReduce application 76 ■ Running a MapReduce application 77 3.6 Availability and reliability at scale 78 HDFS as the underlying storage 79 3.7 Summary 81 PART 2 ADVANCED CONCEPTS 83 4 HBase table design 85 4.1 How to approach schema design 86 Modeling for the questions 86 ■ Defining requirements: more work up front always pays 89 ■ Modeling for even distribution of data and load 92 ■ Targeted data access 98 4.2 De-normalization is the word in HBase land 100 4.3 Heterogeneous data in the same table 102 4.4 Rowkey design strategies 103 4.5 I/O considerations 104 Optimized for writes 104 ■ Optimized for reads 106 Cardinality and rowkey structure 107 4.6 From relational to non-relational 108 Some basic concepts 109 ■ Nested entities 110 ■ Some things don’t map 112 4.7 Advanced column family configurations 113 Configurable block size 113 ■ Block cache 114 ■ Aggressive caching 114 ■ Bloom filters 114 ■ TTL 115 Compression 115 ■ Cell versioning 116 4.8 Filtering data 117 Implementing a filter 119 ■ Prebundled filters 121 4.9 Summary 124 5 Extending HBase with coprocessors 126 5.1 The two kinds of coprocessors 127 Observer coprocessors 127 ■ Endpoint Coprocessors 130 5.2 Implementing an observer 131 Modifying the schema 131 ■ Starting with the Base 132 Installing your observer 135 ■ Other installation options 137 www.it-ebooks.info CONTENTS viii 5.3 Implementing an endpoint 137 Defining an interface for the endpoint 138 ■ Implementing the endpoint server 138 ■ Implement the endpoint client 140 Deploying the endpoint server 142 ■ Try it! 142 5.4 Summary 142 6 Alternative HBase clients 143 6.1 Scripting the HBase shell from UNIX 144 Preparing the HBase shell 145 ■ Script table schema from the UNIX shell 145 6.2 Programming the HBase shell using JRuby 147 Preparing the HBase shell 147 ■ Interacting with the TwitBase users table 148 6.3 HBase over REST 150 Launching the HBase REST service 151 ■ Interacting with the TwitBase users table 153 6.4 Using the HBase Thrift gateway from Python 156 Generating the HBase Thrift client library for Python 157 Launching the HBase Thrift service 159 ■ Scanning the TwitBase users table 159 6.5 Asynchbase: an alternative Java HBase client 162 Creating an asynchbase project 163 ■ Changing TwitBase passwords 165 ■ Try it out 176 6.6 Summary 177 PART 3 EXAMPLE APPLICATIONS 179 7 HBase by example: OpenTSDB 181 7.1 An overview of OpenTSDB 182 Challenge: infrastructure monitoring 183 ■ Data: time series 184 Storage: HBase 185 7.2 Designing an HBase application 186 Schema design 187 ■ Application architecture 190 7.3 Implementing an HBase application 194 Storing data 194 ■ Querying data 199 7.4 Summary 202 www.it-ebooks.info CONTENTS ix 8 Scaling GIS on HBase 203 8.1 Working with geographic data 203 8.2 Designing a spatial index 206 Starting with a compound rowkey 208 ■ Introducing the geohash 209 ■ Understand the geohash 211 ■ Using the geohash as a spatially aware rowkey 212 8.3 Implementing the nearest-neighbors query 216 8.4 Pushing work server-side 222 Creating a geohash scan from a query polygon 224 ■ Within query take 1: client side 228 ■ Within query take 2: WithinFilter 231 8.5 Summary 235 PART 4 OPERATIONALIZING HBASE 237 9 Deploying HBase 239 9.1 Planning your cluster 240 Prototype cluster 241 ■ Small production cluster (10–20 servers) 242 Medium production cluster (up to ~50 servers) 243 ■ Large production cluster (>~50 servers) 243 ■ Hadoop Master nodes 243 ■ HBase Master 244 ■ Hadoop DataNodes and HBase RegionServers 245 ZooKeeper(s) 246 ■ What about the cloud? 246 9.2 Deploying software 248 Whirr: deploying in the cloud 249 9.3 Distributions 250 Using the stock Apache distribution 251 ■ Using Cloudera’s CDH distribution 252 9.4 Configuration 253 HBase configurations 253 ■ Hadoop configuration parameters relevant to HBase 260 ■ Operating system configurations 261 9.5 Managing the daemons 261 9.6 Summary 263 10 Operations 264 10.1 Monitoring your cluster 265 How HBase exposes metrics 266 ■ Collecting and graphing the metrics 266 ■ The metrics HBase exposes 268 ■ Application- side monitoring 272 www.it-ebooks.info [...]... of your HBase cluster 273 Performance testing 273 What impacts HBase s performance? Tuning dependency systems 277 Tuning HBase 278 ■ ■ 10.3 Cluster management 283 Starting and stopping HBase 283 Graceful stop and decommissioning nodes 284 Adding nodes 285 Rolling restarts and upgrading 285 bin /hbase and the HBase shell 286 Maintaining consistency—hbck 293 Viewing HFiles and HLogs 296 Presplitting tables... next generation of HBase users The single strongest component of HBase is its thriving community—we hope you’ll join us in that community and help it continue to innovate in this new era of data systems NICK DIMIDUK www.it-ebooks.info PREFACE xvii If you’re reading this, you’re presumably interested in knowing how I got involved with HBase Let me start by saying thank you for choosing this book as your... HBase behaves the way it does, and you’ll be able to ask intelligent questions This book won’t turn you into an HBase committer It will give you a practical introduction to HBase xxi www.it-ebooks.info xxii ABOUT THIS BOOK Roadmap HBase in Action is organized into four parts The first two are about using HBase In these six chapters, you’ll go from HBase novice to fluent in writing applications on HBase. .. that doesn’t constrain the kind of data you store HBase isn’t a relational database like the ones to which you’re likely accustomed It doesn’t speak SQL or enforce relationships within your data It doesn’t 3 www.it-ebooks.info 4 CHAPTER 1 Introducing HBase allow interrow transactions, and it doesn’t mind storing an integer in one row and a string in another for the same column HBase is designed to... us, you’ll want to play with HBase before going much further We’ll wrap up by walking through installing HBase on your laptop, tossing in some data, and pulling it out Context is important, so let’s start at the beginning 1 2 1 2 HBase project mailing lists: http:/ /hbase. apache.org/mail-lists.html HBase JIRA site: https://issues.apache.org/jira/browse /HBASE www.it-ebooks.info Data-management systems:... nothing less It doesn’t venture into the bowels of the internal HBase implementation It doesn’t cover the broad range of topics necessary for understanding the Hadoop ecosystem HBase in Action maintains a singular focus on using HBase It aims to educate you enough that you can build an application on top of HBase and launch that application into production Along the way, you’ll learn some of those HBase. .. of HBase Most important, you’ll learn how to think in HBase The two chapters in part 3 move beyond sample applications and give you a taste of HBase in real applications Part 4 is aimed at taking your HBase application from a development prototype to a full-fledged production system Chapter 1 introduces the origins of Hadoop, HBase, and NoSQL in general We explain what HBase is and isn’t, contrast HBase. .. becoming more reliable and performant, due in large part to the engineering effort invested by the various companies backing and using it As more commercial vendors provide support, users are increasingly confident in using the system for critical applications A technology designed to store a continuously updated copy of the internet turns out to be pretty good at other things internet-related HBase. .. MapReduce team, building the first versions of their hosted HBase offering Nick also lived in Seattle, and we met often and talked about the projects we were working on Toward the end of 2010, the idea of writing HBase in Action for Manning came up We initially scoffed at the thought of writing a book on HBase, and I remember saying to Nick, “It’s gets, puts, and scans—there’s not a lot more to HBase from the... www.manning.com/HBaseinAction In the spirit of open source, we hope you’ll find our example code useful in your applications We encourage you to play with it, modify it, fork it, and share it with others If you find bugs, please let us know in the form of issues, or, better still, pull requests As they often say in the open source community: patches welcome Author Online Purchase of HBase in Action includes . Implementing an endpoint 137 Defining an interface for the endpoint 138 ■ Implementing the endpoint server 138 ■ Implement the endpoint client 140 Deploying. Bigtable’s invention 9 ■ Capturing incremental data 10 ■ Content serving 13 ■ Information exchange 14 1.3 Hello HBase 15 Quick install 16 ■ Interacting with

Ngày đăng: 18/02/2014, 06:20

Từ khóa liên quan

Mục lục

  • HBase in Action

  • brief contents

  • contents

  • foreword

  • letter to the HBase community

  • preface

  • acknowledgments

  • about this book

    • Roadmap

    • Intended audience

    • Code conventions

    • Code downloads

    • Author Online

  • about the authors

  • about the cover illustration

  • Part 1 HBase fundamentals

    • Chapter 1 Introducing HBase

      • 1.1 Data-management systems: a crash course

        • 1.1.1 Hello, Big Data

        • 1.1.2 Data innovation

        • 1.1.3 The rise of HBase

      • 1.2 HBase use cases and success stories

        • 1.2.1 The canonical web-search problem: the reason for Bigtable’s invention

        • 1.2.2 Capturing incremental data

        • 1.2.3 Content serving

        • 1.2.4 Information exchange

      • 1.3 Hello HBase

        • 1.3.1 Quick install

        • 1.3.2 Interacting with the HBase shell

        • 1.3.3 Storing data

      • 1.4 Summary

    • Chapter 2 Getting started

      • 2.1 Starting from scratch

        • 2.1.1 Create a table

        • 2.1.2 Examine table schema

        • 2.1.3 Establish a connection

        • 2.1.4 Connection management

      • 2.2 Data manipulation

        • 2.2.1 Storing data

        • 2.2.2 Modifying data

        • 2.2.3 Under the hood: the HBase write path

        • 2.2.4 Reading data

        • 2.2.5 Under the hood: the HBase read path

        • 2.2.6 Deleting data

        • 2.2.7 Compactions: HBase housekeeping

        • 2.2.8 Versioned data

        • 2.2.9 Data model recap

      • 2.3 Data coordinates

      • 2.4 Putting it all together

      • 2.5 Data models

        • 2.5.1 Logical model: sorted map of maps

        • 2.5.2 Physical model: column family oriented

      • 2.6 Table scans

        • 2.6.1 Designing tables for scans

        • 2.6.2 Executing a scan

        • 2.6.3 Scanner caching

        • 2.6.4 Applying filters

      • 2.7 Atomic operations

      • 2.8 ACID semantics

      • 2.9 Summary

    • Chapter 3 Distributed HBase, HDFS, and MapReduce

      • 3.1 A case for MapReduce

        • 3.1.1 Latency vs. throughput

        • 3.1.2 Serial execution has limited throughput

        • 3.1.3 Improved throughput with parallel execution

        • 3.1.4 MapReduce: maximum throughput with distributed parallelism

      • 3.2 An overview of Hadoop MapReduce

        • 3.2.1 MapReduce data flow explained

        • 3.2.2 MapReduce under the hood

      • 3.3 HBase in distributed mode

        • 3.3.1 Splitting and distributing big tables

        • 3.3.2 How do I find my region?

        • 3.3.3 How do I find the -ROOT- table?

      • 3.4 HBase and MapReduce

        • 3.4.1 HBase as a source

        • 3.4.2 HBase as a sink

        • 3.4.3 HBase as a shared resource

      • 3.5 Putting it all together

        • 3.5.1 Writing a MapReduce application

        • 3.5.2 Running a MapReduce application

      • 3.6 Availability and reliability at scale

        • 3.6.1 HDFS as the underlying storage

      • 3.7 Summary

  • Part 2 Advanced concepts

    • Chapter 4 HBase table design

      • 4.1 How to approach schema design

        • 4.1.1 Modeling for the questions

        • 4.1.2 Defining requirements: more work up front always pays

        • 4.1.3 Modeling for even distribution of data and load

        • 4.1.4 Targeted data access

      • 4.2 De-normalization is the word in HBase land

      • 4.3 Heterogeneous data in the same table

      • 4.4 Rowkey design strategies

      • 4.5 I/O considerations

        • 4.5.1 Optimized for writes

        • 4.5.2 Optimized for reads

        • 4.5.3 Cardinality and rowkey structure

      • 4.6 From relational to non-relational

        • 4.6.1 Some basic concepts

        • 4.6.2 Nested entities

        • 4.6.3 Some things don’t map

      • 4.7 Advanced column family configurations

        • 4.7.1 Configurable block size

        • 4.7.2 Block cache

        • 4.7.3 Aggressive caching

        • 4.7.4 Bloom filters

        • 4.7.5 TTL

        • 4.7.6 Compression

        • 4.7.7 Cell versioning

      • 4.8 Filtering data

        • 4.8.1 Implementing a filter

        • 4.8.2 Prebundled filters

      • 4.9 Summary

    • Chapter 5 Extending HBase with coprocessors

      • 5.1 The two kinds of coprocessors

        • 5.1.1 Observer coprocessors

        • 5.1.2 Endpoint Coprocessors

      • 5.2 Implementing an observer

        • 5.2.1 Modifying the schema

        • 5.2.2 Starting with the Base

        • 5.2.3 Installing your observer

        • 5.2.4 Other installation options

      • 5.3 Implementing an endpoint

        • 5.3.1 Defining an interface for the endpoint

        • 5.3.2 Implementing the endpoint server

        • 5.3.3 Implement the endpoint client

        • 5.3.4 Deploying the endpoint server

        • 5.3.5 Try it!

      • 5.4 Summary

    • Chapter 6 Alternative HBase clients

      • 6.1 Scripting the HBase shell from UNIX

        • 6.1.1 Preparing the HBase shell

        • 6.1.2 Script table schema from the UNIX shell

      • 6.2 Programming the HBase shell using JRuby

        • 6.2.1 Preparing the HBase shell

        • 6.2.2 Interacting with the TwitBase users table

      • 6.3 HBase over REST

        • 6.3.1 Launching the HBase REST service

        • 6.3.2 Interacting with the TwitBase users table

      • 6.4 Using the HBase Thrift gateway from Python

        • 6.4.1 Generating the HBase Thrift client library for Python

        • 6.4.2 Launching the HBase Thrift service

        • 6.4.3 Scanning the TwitBase users table

      • 6.5 Asynchbase: an alternative Java HBase client

        • 6.5.1 Creating an asynchbase project

        • 6.5.2 Changing TwitBase passwords

        • 6.5.3 Try it out

      • 6.6 Summary

  • Part 3 Example applications

    • Chapter 7 HBase by example: OpenTSDB

      • 7.1 An overview of OpenTSDB

        • 7.1.1 Challenge: infrastructure monitoring

        • 7.1.2 Data: time series

        • 7.1.3 Storage: HBase

      • 7.2 Designing an HBase application

        • 7.2.1 Schema design

        • 7.2.2 Application architecture

      • 7.3 Implementing an HBase application

        • 7.3.1 Storing data

        • 7.3.2 Querying data

      • 7.4 Summary

    • Chapter 8 Scaling GIS on HBase

      • 8.1 Working with geographic data

      • 8.2 Designing a spatial index

        • 8.2.1 Starting with a compound rowkey

        • 8.2.2 Introducing the geohash

        • 8.2.3 Understand the geohash

        • 8.2.4 Using the geohash as a spatially aware rowkey

      • 8.3 Implementing the nearest-neighbors query

      • 8.4 Pushing work server-side

        • 8.4.1 Creating a geohash scan from a query polygon

        • 8.4.2 Within query take 1: client side

        • 8.4.3 Within query take 2: WithinFilter

      • 8.5 Summary

  • Part 4 Operationalizing HBase

    • Chapter 9 Deploying HBase

      • 9.1 Planning your cluster

        • 9.1.1 Prototype cluster

        • 9.1.2 Small production cluster (10–20 servers)

        • 9.1.3 Medium production cluster (up to ~50 servers)

        • 9.1.4 Large production cluster (>~50 servers)

        • 9.1.5 Hadoop Master nodes

        • 9.1.6 HBase Master

        • 9.1.7 Hadoop DataNodes and HBase RegionServers

        • 9.1.8 ZooKeeper(s)

        • 9.1.9 What about the cloud?

      • 9.2 Deploying software

        • 9.2.1 Whirr: deploying in the cloud

      • 9.3 Distributions

        • 9.3.1 Using the stock Apache distribution

        • 9.3.2 Using Cloudera’s CDH distribution

      • 9.4 Configuration

        • 9.4.1 HBase configurations

        • 9.4.2 Hadoop configuration parameters relevant to HBase

        • 9.4.3 Operating system configurations

      • 9.5 Managing the daemons

      • 9.6 Summary

    • Chapter 10 Operations

      • 10.1 Monitoring your cluster

        • 10.1.1 How HBase exposes metrics

        • 10.1.2 Collecting and graphing the metrics

        • 10.1.3 The metrics HBase exposes

        • 10.1.4 Application-side monitoring

      • 10.2 Performance of your HBase cluster

        • 10.2.1 Performance testing

        • 10.2.2 What impacts HBase’s performance?

        • 10.2.3 Tuning dependency systems

        • 10.2.4 Tuning HBase

      • 10.3 Cluster management

        • 10.3.1 Starting and stopping HBase

        • 10.3.2 Graceful stop and decommissioning nodes

        • 10.3.3 Adding nodes

        • 10.3.4 Rolling restarts and upgrading

        • 10.3.5 bin/hbase and the HBase shell

        • 10.3.6 Maintaining consistency—hbck

        • 10.3.7 Viewing HFiles and HLogs

        • 10.3.8 Presplitting tables

      • 10.4 Backup and replication

        • 10.4.1 Inter-cluster replication

        • 10.4.2 Backup using MapReduce jobs

        • 10.4.3 Backing up the root directory

      • 10.5 Summary

  • appendix A Exploring the HBase system

    • A.1 Exploring ZooKeeper

    • A.2 Exploring -ROOT-

    • A.3 Exploring .META.

  • appendix B More about the workings of HDFS

    • B.1 Distributed file systems

    • B.2 Separating metadata and data: NameNode and DataNode

    • B.3 HDFS write path

    • B.4 HDFS read path

    • B.5 Resilience to hardware failures via replication

    • B.6 Splitting files across multiple DataNodes

  • index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • Y

    • Z

Tài liệu cùng người dùng

Tài liệu liên quan