Hadoop: the Definitive Guide

Hadoop: the Definitive Guide

Hadoop: The Definitive Guide Tom White foreword by Doug Cutting Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo Hadoop: The Definitive Guide by Tom White Copyright © 2009 Tom White. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: Mike Loukides Indexer: Ellen Troutman Zaig Production Editor: Loranah Dimant Cover Designer: Karen Montgomery Proofreader: Nancy Kotary Interior Designer: David Futato Illustrator: Robert Romano Printing History: June 2009: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Hadoop: The Definitive Guide, the image of an African elephant, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. TM This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 978-0-596-52197-4 [M] 1243455573 For Eliane, Emilia, and Lottie Table of Contents Foreword . ................................................................. xiii Preface . xv 1. Meet Hadoop . .......................................................... 1 Data! 1 Data Storage and Analysis 3 Comparison with Other Systems 4 RDBMS 4 Grid Computing 6 Volunteer Computing 8 A Brief History of Hadoop 9 The Apache Hadoop Project 12 2. MapReduce . .......................................................... 15 A Weather Dataset 15 Data Format 15 Analyzing the Data with Unix Tools 17 Analyzing the Data with Hadoop 18 Map and Reduce 18 Java MapReduce 20 Scaling Out 27 Data Flow 27 Combiner Functions 29 Running a Distributed MapReduce Job 32 Hadoop Streaming 32 Ruby 33 Python 35 Hadoop Pipes 36 Compiling and Running 38 v 3. The Hadoop Distributed Filesystem . ...................................... 41 The Design of HDFS 41 HDFS Concepts 42 Blocks 42 Namenodes and Datanodes 44 The Command-Line Interface 45 Basic Filesystem Operations 45 Hadoop Filesystems 47 Interfaces 49 The Java Interface 51 Reading Data from a Hadoop URL 51 Reading Data Using the FileSystem API 52 Writing Data 56 Directories 57 Querying the Filesystem 58 Deleting Data 62 Data Flow 63 Anatomy of a File Read 63 Anatomy of a File Write 66 Coherency Model 68 Parallel Copying with distcp 70 Keeping an HDFS Cluster Balanced 71 Hadoop Archives 71 Using Hadoop Archives 72 Limitations 73 4. Hadoop I/O . .......................................................... 75 Data Integrity 75 Data Integrity in HDFS 75 LocalFileSystem 76 ChecksumFileSystem 77 Compression 77 Codecs 79 Compression and Input Splits 83 Using Compression in MapReduce 84 Serialization 86 The Writable Interface 87 Writable Classes 89 Implementing a Custom Writable 96 Serialization Frameworks 101 File-Based Data Structures 103 SequenceFile 103 MapFile 110 vi | Table of Contents 5. Developing a MapReduce Application . 115 The Configuration API 116 Combining Resources 117 Variable Expansion 117 Configuring the Development Environment 118 Managing Configuration 118 GenericOptionsParser, Tool, and ToolRunner 121 Writing a Unit Test 123 Mapper 124 Reducer 126 Running Locally on Test Data 127 Running a Job in a Local Job Runner 127 Testing the Driver 130 Running on a Cluster 132 Packaging 132 Launching a Job 132 The MapReduce Web UI 134 Retrieving the Results 136 Debugging a Job 138 Using a Remote Debugger 144 Tuning a Job 145 Profiling Tasks 146 MapReduce Workflows 149 Decomposing a Problem into MapReduce Jobs 149 Running Dependent Jobs 151 6. How MapReduce Works . ............................................... 153 Anatomy of a MapReduce Job Run 153 Job Submission 153 Job Initialization 155 Task Assignment 155 Task Execution 156 Progress and Status Updates 156 Job Completion 158 Failures 159 Task Failure 159 Tasktracker Failure 161 Jobtracker Failure 161 Job Scheduling 161 The Fair Scheduler 162 Shuffle and Sort 163 The Map Side 163 The Reduce Side 164 Table of Contents | vii Configuration Tuning 166 Task Execution 168 Speculative Execution 169 Task JVM Reuse 170 Skipping Bad Records 171 The Task Execution Environment 172 7. MapReduce Types and Formats . ......................................... 175 MapReduce Types 175 The Default MapReduce Job 178 Input Formats 184 Input Splits and Records 185 Text Input 196 Binary Input 199 Multiple Inputs 200 Database Input (and Output) 201 Output Formats 202 Text Output 202 Binary Output 203 Multiple Outputs 203 Lazy Output 210 Database Output 210 8. MapReduce Features . ................................................. 211 Counters 211 Built-in Counters 211 User-Defined Java Counters 213 User-Defined Streaming Counters 218 Sorting 218 Preparation 218 Partial Sort 219 Total Sort 223 Secondary Sort 227 Joins 233 Map-Side Joins 233 Reduce-Side Joins 235 Side Data Distribution 238 Using the Job Configuration 238 Distributed Cache 239 MapReduce Library Classes 243 9. Setting Up a Hadoop Cluster . ........................................... 245 Cluster Specification 245 viii | Table of Contents Network Topology 247 Cluster Setup and Installation 249 Installing Java 249 Creating a Hadoop User 250 Installing Hadoop 250 Testing the Installation 250 SSH Configuration 251 Hadoop Configuration 251 Configuration Management 252 Environment Settings 254 Important Hadoop Daemon Properties 258 Hadoop Daemon Addresses and Ports 263 Other Hadoop Properties 264 Post Install 266 Benchmarking a Hadoop Cluster 266 Hadoop Benchmarks 267 User Jobs 269 Hadoop in the Cloud 269 Hadoop on Amazon EC2 269 10. Administering Hadoop . ................................................ 273 HDFS 273 Persistent Data Structures 273 Safe Mode 278 Audit Logging 280 Tools 280 Monitoring 285 Logging 285 Metrics 286 Java Management Extensions 289 Maintenance 292 Routine Administration Procedures 292 Commissioning and Decommissioning Nodes 293 Upgrades 296 11.Pig . ................................................................ 301 Installing and Running Pig 302 Execution Types 302 Running Pig Programs 304 Grunt 304 Pig Latin Editors 305 An Example 305 Generating Examples 307 Table of Contents | ix Comparison with Databases 308 Pig Latin 309 Structure 310 Statements 311 Expressions 314 Types 315 Schemas 317 Functions 320 User-Defined Functions 322 A Filter UDF 322 An Eval UDF 325 A Load UDF 327 Data Processing Operators 331 Loading and Storing Data 331 Filtering Data 331 Grouping and Joining Data 334 Sorting Data 338 Combining and Splitting Data 339 Pig in Practice 340 Parallelism 340 Parameter Substitution 341 12. HBase . .............................................................. 343 HBasics 343 Backdrop 344 Concepts 344 Whirlwind Tour of the Data Model 344 Implementation 345 Installation 348 Test Drive 349 Clients 350 Java 351 REST and Thrift 353 Example 354 Schemas 354 Loading Data 355 Web Queries 358 HBase Versus RDBMS 361 Successful Service 362 HBase 363 Use Case: HBase at streamy.com 363 Praxis 365 Versions 365 x | Table of Contents Love and Hate: HBase and HDFS 366 UI 367 Metrics 367 Schema Design 367 13.ZooKeeper . .......................................................... 369 Installing and Running ZooKeeper 370 An Example 371 Group Membership in ZooKeeper 372 Creating the Group 372 Joining a Group 374 Listing Members in a Group 376 Deleting a Group 378 The ZooKeeper Service 378 Data Model 379 Operations 380 Implementation 384 Consistency 386 Sessions 388 States 389 Building Applications with ZooKeeper 391 A Configuration Service 391 The Resilient ZooKeeper Application 394 A Lock Service 398 More Distributed Data Structures and Protocols 400 ZooKeeper in Production 401 Resilience and Performance 401 Configuration 402 14.Case Studies . ........................................................ 405 Hadoop Usage at Last.fm 405 Last.fm: The Social Music Revolution 405 Hadoop at Last.fm 405 Generating Charts with Hadoop 406 The Track Statistics Program 407 Summary 414 Hadoop and Hive at Facebook 414 Introduction 414 Hadoop at Facebook 414 Hypothetical Use Case Studies 417 Hive 420 Problems and Future Work 424 Nutch Search Engine 425 Table of Contents | xi Background 425 Data Structures 426 Selected Examples of Hadoop Data Processing in Nutch 429 Summary 438 Log Processing at Rackspace 439 Requirements/The Problem 439 Brief History 440 Choosing Hadoop 440 Collection and Storage 440 MapReduce for Logs 442 Cascading 447 Fields, Tuples, and Pipes 448 Operations 451 Taps, Schemes, and Flows 452 Cascading in Practice 454 Flexibility 456 Hadoop and Cascading at ShareThis 457 Summary 461 TeraByte Sort on Apache Hadoop 461 A. Installing Apache Hadoop . ............................................. 465 B. Cloudera’s Distribution for Hadoop . ..................................... 471 C. Preparing the NCDC Weather Data . .....................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    526 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us