SlideShare ist ein Scribd-Unternehmen logo
1 von 142
Downloaden Sie, um offline zu lesen
Welcome to OSCON 2012

       MySQL Cluster and NoSQL
                                                               <Insert Picture Here>



    • If you want to run a node in a multi-node cluster:
         • Pick a seat where there is a network cable
         • Plug in
         • Turn off your firewall (or at least allow ports 1186 & 2186)
         • Point your browser to http://uplink/


    • OR, to run a one-node cluster contained entirely on your own
     laptop, sit away from the network cables and use the conference
     wireless.



1                              Copyright © 2011 Oracle Corp.

                                                                                       1
<Insert Picture Here>




MySQL Cluster and NoSQL
John David Duncan
Craig L Russell
MySQL Cluster Engineering
Oracle Corp
                            2
Everyone needs the tutorial files!
    • From USB stick
    • From uplink
                     • oscon-2012-mysql-nosql.tar
    • From github
                    – or
                  • oscon-2012-mysql-nosql.zip
                    – or
                  • oscon-2012-mysql-nosql-MSDOS.zip


git clone
 git://github.com/jdduncan/oscon-2012-mysql-nosql.git




3

                                                        3
Platform Census Time




4

                           4
MySQL Cluster and NoSQL


    • There are 3 handouts
      – README for Java / Twitter development exercise
      – MySQL pathname reference
      – Memcache reference card (2-sided)


    • If you still need MySQL Cluster 7.2.6 and
      Cache::Memcached, they are on the USB sticks – go
      get ‘em

    • If you want to be in a multi-node cluster with other
      people, find a network cable


5

                                                             5
Big Picture Agenda


                                   <Insert Picture Here>




    • First half: deploy cluster
      – Some lectures
      – Some lab - run a cluster
    • Second half: develop apps
      – Some lectures - Memcached & Java
      – Some lab - you write the code

6

                                                           6
Presenter's "Baggage"

            J.D. Duncan


    • Former Systems
      Administrator, web
      developer, MySQL DBA
    • Joined MySQL AB in 2004




                                          Image used under a Creative Commons license from Flickr user Digiart2001



7                         Copyright © 2011 Oracle Corp.

                                                                                                                 7
Presenter's "Baggage"

             Craig L. Russell


    • Systems Architect focused
        on Enterprise Java
    •   Specification Lead for Java
        Data Objects
    •   Architect of Container-
        Managed Persistence
    •   Likes SQL well enough
    •   Likes well-designed APIs
        even more
                                      Image used under a Creative Commons license from Flickr user Digiart2001




8

                                                                                                             8
1:30 - 3:00 P.M Agenda


                                         <Insert Picture Here>




    • Seating & Introductions (10 min.)
    • MySQL Cluster Essentials (JD - 25 min.)
    • Hands-on MySQL Cluster setup (35 min.)
    • API Overviews (20 min.)
     – ClusterJ (Craig)
     – Memcache (JD)
     – Node.js Connector Project

9

                                                                 9
MySQL Cluster Essentials


                                <Insert Picture Here>




10

                                                        10
What is a database?


     • It’s a computer system that manages data ...
      in a useful way.




11

                                                      11
How do database systems make themselves useful?


     • Persistent storage
       – in “the system of record”
     • Indexed retrieval
       – the database gets big, but retrieval time remains small
     • Central enforcement of data integrity
       – Every Social Security Number has 9 digits
       – Every order has a billing address
     • Maintain an illusion of consistency
       – isolating a transcation other concurrent changes




12

                                                                   12
How is the data structured?

     • Key : Value
       – Hash table (or memcache):
          • lookups only
          • no scans
       – Ordered Index (or binary tree):
          • Lookups and scans both.
     • Key : Structured Value
       – redis: common data structures used in application code
       – mongodb: structured documents, possible secondary indexes
       – dynamo: schema-free tables
     • Relational (Tables with a schema)




13

                                                                     13
Document Databases

• Examples: MongoDB, CouchDB
• Expected lookup:
     – “Fetch this patient’s record”   ✓
• Unexepected lookup:
     – “Who took Accutane after 1990?”     x




14

                                               14
Relational Databases


• In a truly normalized relational
  schema, no table is more central
  than any other.
• “Fetch this patient’s record” ✓


• “Did more of our patients get the flu
  in 2008 or in 2009?” ✓

• “Which doctor prescribes the most
  prednisone?” ✓


15

                                          15
But what about schema changes?




16

                                      16
But what about schema changes?




      They need to be online operations.

17

                                           17
In the last few minutes we actually covered a lot of
     important theory.

     • But here’s one more bit: consistency vs. availability.
     • Look at MySQL 4.0, circa 2000




                         Slave

                                         Master


                         Slave




                         Slave


18

                                                                18
What happens when a link goes down?


     • CAP (Eric Brewer): You have to choose. You can’t
       have both. Commercial databases usually chose C,
       but MySQL replication chose A.



                       Slave

                                    Master


                      Slave




                      Slave


19

                                                          19
Now We Are Ready

                                                <Insert Picture Here>




     MySQL Cluster




20              Copyright © 2011 Oracle Corp.

                                                                    20
NDB Cluster
         Ericsson, 1997
 • Hardware Design                               • Software Design
   – Inexpensive x86 hardware                      – 99.999% availability
   – "Shared nothing" clustering                   – Guaranteed consistency
                                                   – Parallel execution
                                                   – Commit at speed of
                                                     network (rather than disk)

                Node Group 1                       Node Group 2



                               F1                                 F2
                Node 1




                                                   Node 3
                               F3                                 F4
     3




                               F3                                 F4
                Node 2




                                                   Node 4
                               F1                                 F2
                                    Data Nodes




21

                                                                                  21
NDB Cluster: Where does it fit?

     • Consistent or Available?
       – Availability is important. NDB is designed to remain running if
         one node in a node group fails.
       – But consistency is even more important. If all nodes in a
         node group fail, the database will shut itself down.
     • Relational? Yes.
       –   Hashed primary key for data distribution
       –   Secondary Unique indexes
       –   Ordered indexes for scans
       –   Online schema changes.
     • SQL? No.
       – C++ NDB API for object-relational application development.



22

                                                                           22
2003: MySQL + NDB Cluster = MySQL Cluster


     • MySQL:
       – built for cheap linux boxes
       – free, popular, revolutionary, fast, easy to use
       – proven ability to run with different back-end data stores, e.g.
         MyISAM and InnoDB.
       – MySQL replication has asynchronous, best-effort design that
         prioritizes availability


     • NDB:
       – built for cheap linux boxes
       – high performance and availability
       – had no support for SQL, or ODBC, or JDBC



23

                                                                           23
The Basics

     • Management server
       –   read the one central configuration file
       –   allow other nodes to join
       –   distribute the configuration to them
       –   get the cluster up & running
     • Data Node
       – ndbd (single-threaded) or ndbmtd (multi-threaded)
       – Stores data and indexes
       – Manage all transactions and operations for API nodes
     • API Node
       – Join the cluster as a member node with node id
       – e.g. mysqld, memcached, JVM running ClusterJ application
     • Client
       – MySQL or Memcache client; not a member of the cluster

24

                                                                    24
Big Picture
                           API Nodes




         Node Group 1                Node Group 2
                        NDB Data Nodes

25                        Copyright © 2011 Oracle Corp.

                                                          25
NOT a shared-disk architecture

            Application    Application                     Application




                 DBMS            DBMS                   DBMS
                 Server          Server                 Server
                Instance        Instance               Instance




                                   Disk




26                         Copyright © 2011 Oracle Corp.

                                                                         26
“Shared-Nothing” Architecture

           Application    Application                     Application




                DBMS            DBMS                   DBMS
                Server          Server                 Server
               Instance        Instance               Instance




                   Disk           Disk                    Disk




27                        Copyright © 2011 Oracle Corp.

                                                                        27
Synchronous data replication
     • Data changes take place on all the servers in coordination
     • The ”two-phase commit” (2PC) is the most commonly used protocol
        – The changes are only committed after they’ve been succesfully
           executed on all servers
     – TC (Transaction Coordinator) manages 2PC
     – LQH (Local Query Handler) at each data node manages local
       transaction
                                       API



                                        TC



                      Data Node 1                   Data Node 2
                         LQH                           LQH


28                                  Copyright © 2011 Oracle Corp.

                                                                          28
Heartbeat Circle



                                        Nodes organized
                               DB       in a logical circle
                              Node 2



               DB                       DB
              Node 1                   Node 3




Heartbeat messages             DB
                              Node 4
sent to next node in circle


29

                                                              29
Heartbeat Failure Example




     Node 1 fails to send
                             DB
     heartbeats three       Node 2
     consecutive times




            xDB
            Node 1
                                      DB
                                     Node 3



     It is declared as
     dead and removed        DB
     from the cluster       Node 4


30

                                              30
Network Partitioning


     • The servers are organised in a network
     • What happens if the servers lose contact to each other?

                                                    Server
                          Server


                                                    Server


                           Server
                                                    Server



                                    “Split brain”

     • Neither side can continue as this would lead to inconsistency

31

                                                                       31
Using an Arbitrator


     • In order to handle an even number of servers an
       arbitrator is added
     • When a majority is needed by a set of servers, the
       arbitrator “votes” for that set, making it a majority
     • The arbitrator must not vote for several different subsets
       and the arbitrator must be known to all servers
     • By using an arbitrator the two server system becomes
       more fault tolerant than a single server system
                             Arbitrator



                        Server            Server



32

                                                                    32
Who Uses MySQL Cluster?
     Until 2010: Telco Networks & Network Equipment Makers




33                       Copyright © 2011 Oracle Corp.

                                                             33
Who Uses MySQL Cluster?
     Since 2010: Web & Online gaming




                                                        • Session management
                                                        • Shopping carts
                                                        • Game play
                                                        • Internal site monitoring


34                      Copyright © 2011 Oracle Corp.

                                                                                     34
MySQL Cluster Today
     ACID Compliant Relational Database
      SQL & NoSQL interfaces

     Write-Scalable & Real-Time
      Distributed, auto-partitioning (sharding), multi-master

     99.999% Availability
      Shared-nothing, integrated clustering & sub-second
      recovery, local & geographic replication, on-line
      operations

     Low TCO
      Open-source, management & monitoring tools, scale-out
      on commodity hardware


35                            Copyright © 2011 Oracle Corp.

                                                                35
Online Maintenance


     • Online schema changes
       – ALTER TABLE ...
     • Online backup
       – START BACKUP ...
     • Online storage addition
       – e.g. from 4 data nodes to 6




36

                                       36
The long road to SQL JOIN performance


     • Initial integration (2004)
       – Move the data to the query
       – ... one row at a time
       – ... one loop iteration in a nested-loop join = 1 network trip
     • 2005 - 2009
       – Improve efficiency ...
       – within the existing framework of the MySQL optimizer
       – e.g. Batch Key Access, push-down filters
     • MySQL Cluster 7.2 (2011)
       – Adaptive Query Localization
       – Algorithmic changes to optimizer
       – Push the majority of the query to the data nodes


37

                                                                         37
Results: Adaptive Query Localization
         in MySQL Cluster 7.2
     mysql> SELECT COUNT(*)
            FROM residents, postcodes, towns
            WHERE residents.postcode=postcodes.postcode
            AND postcodes.town=towns.town
            AND towns.county="Berkshire";

      +----------+
      | COUNT(*) |
      +----------+
      |    40001 |
      +----------+


     Before: 48.68 sec                       • After: 2.02 sec


38                        Copyright © 2011 Oracle Corp.

                                                                 38
Tour




39

            39
Tour Stop 1: Config File


     • A single central file for the whole cluster
     • Loaded by the management server on --initial
     • And then stored in cache for future management server
       restarts
     • Sections:
       –   [MGM]
       –   [DB DEFAULT]
       –   [NDBD]
       –   [API]




40

                                                               40
Tour Stop: Management Server




      [MGM]
      NodeId=1
      datadir=/Users/jdd/sandbox/ndb
      hostname=localhost




     % ndb_mgmd -f config-file-path

41

                                       41
Tour Stop: Data Nodes




     [DB DEFAULT]
     NoOfReplicas=1
     TimeBetweenGlobalCheckpoints=12000
     HeartbeatIntervalDbApi=15000
     DataMemory=180M
     IndexMemory=60M




42

                                          42
Tour Stop: Data Nodes




     [NDBD]
     NodeId=2




% ndbd -c mgm_host:mgm_port

43

                              43
Tour Stop: API Nodes




     [API]
     [API]
     [API]
     [API]
     [API]
     [API]
     [API]




44

                            44
Tour Stop: API Nodes


     • mysqld, memcached, java, etc.
       – Java API nodes connect to clusters based on Java connection
         properties
       – mysqld connects to cluster based on my.cnf file
       – memcached connects based on command-line options




45

                                                                       45
Tour Stop: Management & Monitoring


     • From the mysql server
       – SQL for table creation, etc.
       – ndbinfo schema
          • e.g. SELECT * FROM ndbinfo.memoryusage;
       – SHOW ENGINE NDB STATUS;
     • Management Clients
       – ndb_mgm
     • Toolsets
       – From Oracle: MySQL Cluster Manager
       – Third party tools: severalnines.com




46

                                                      46
MySQL Cluster Hands-On Lab


                                  <Insert Picture Here>




47

                                                          47
MySQL Cluster Hands-On Lab


     • Solo Clusters
                                                              <Insert Picture
       – Your config file is here:
                                                              Here>
       – run-cluster/ndb/solo-cluster.ini
     • Multi-Node Clusters
       –   http://uplink/
       –   1 managment server per cluster
       –   2, 4, or 6 data nodes per cluster
       –   Others can run API nodes
       –   MGM and NDB nodes register with the web app
       –   Then the web app generates a config file for the management
           server and you (mgm server person) download it and save it in
           run-cluster/ndb/



48

                                                                           48
MySQL Cluster Hands-On Lab



                                                      <Insert Picture
                                                      Here>
     • Open 4 or more terminal windows


     • Set some pathnames
       – Check your handout!

       – export PATH=/usr/local/mysql/bin:$PATH
       – (or whatever is correct for your platform)
       – cd into oscon-2012-mysql-nosql



49

                                                                   49
Start your management servers!


• Wireless:
• cd run-cluster/ndb
• ndb_mgmd --initial -f solo-cluster.ini --configdir=.



• Wired (MGM person only!):
• save cluster.ini from uplink
• cd run-cluster/ndb
• ndb_mgmd --initial -f cluster.ini --configir=.




50

                                                     50
What’s going on with this cluster?


     • Start a management client!
     • (And leave it running in its window)
     • Wireless:
       • ndb_mgm -c localhost:1186


     • Wired:
       • Where is your management server?
       • http://uplink should tell you
       • ndb_mgm -c box-xx:1186




51

                                              51
Start your data nodes!




     • You are still in run-cluster/ndb
     • And you remember your connectstring ...
     • So:
             ndbd -c <connectstring>




52

                                                 52
What’s going on with this cluster?




 ndb_mgm> all status
 Node 2: starting (Last completed phase 2) ...



     ndb_mgm> show
     Cluster Configuration
     ---------------------


53

                                                 53
Configure a MySQL server




     • Create a my.cnf file
       – cd run-cluster/sql
       – ./create-config.sh
       – ls (you should see my.cnf)
     • Wireless: leave it as-is
     • Wired: edit the connectstring




54

                                       54
Here’s what my own my.cnf looks like




     [mysqld]
     ndbcluster
     user=jdd
     datadir=/Users/jdd/[...]/run-cluster/sql
     ndb-connectstring=localhost:1186




55

                                                55
Configure a MySQL server




     cd oscon-2012-mysql-nosql
     . pathnames.sh
     cd run-cluster/sql
     $MYSQL_INSTALL_DIR/scripts/msyql_install_db 
       --datadir=. 
       --basedir=$MYSQL_INSTALL_DIR



56

                                                     56
Configure a MySQL server




     Installing MySQL system tables...
     OK
     Filling help tables...
     OK
     ...




57

                                         57
Now start the mysqld




     mysqld_safe --defaults-file=./my.cnf




 mysqld_safe Starting mysqld daemon with
 databases from ...

58

                                            58
MySQL Client




$ mysql -u root

Welcome to the MySQL monitor.   Commands end
with ; or g.
Your MySQL connection id is 2



59

                                               59
MySQL Client




mysql> select * From ndbinfo.nodes;



+---------+--------+---------+-------------+-------------------+
| node_id | uptime | status | start_phase | config_generation |
+---------+--------+---------+-------------+-------------------+
|       2 |   3453 | STARTED |           0 |                 1 |
+---------+--------+---------+-------------+-------------------+
1 row in set (0.00 sec)



60

                                                                   60
Create some tables (from the shell)




     • We need to run two SQL scripts:
       • One called ndb_memcache_metadata.sql in
       $MYSQL_HOME/share/memcache-api/
      • Plus java/labs/schema/create.sql from
       oscon-2012-mysql-nosql


         % mysql -u root < filename


61

                                                   61
MySQL Client




      mysql> use test

      mysql> show tables ;

      +----------------+
      | Tables_in_test |
      +----------------+
      | hashtags       |
      | tweets         |
      +----------------+

62

                             62
Make a backup!




ndb_mgm> start backup




Waiting for completed, this may take several minut
Node 2: Backup 1 started from node 1
Node 2: Backup 1 started from node 1 completed
 StartGCP: 351 StopGCP: 354
 #Records: 2058 #LogRecords: 0
 Data: 51728 bytes Log: 0 bytes

63

                                                63
Things you might do if we had more time


     • Set up cluster-to-cluster replication
       • uses a designated mysql server in each cluster
     • Online alter table operations
       • ALTER ONLINE TABLE x ADD i int NULL;
       • (note that some ALTER operations can be done
         online and some others cannot)
     • Rolling Restart
     • Expand a cluster online (add nodes)




64

                                                          64
API Overviews


                                        <Insert Picture Here>




     • ClusterJ (Craig, 10 min.)
     • Memcache (JD, 5 min.)
     • Node.JS project (JD & Craig, 10 min.)
     • Break time




65

                                                                65
<Insert Picture Here>




ClusterJ Overview
Craig L Russell
Architect, Oracle Corp.



                               66
ClusterJ
• High Performance, Light Weight, Easy to Use Direct Connection
   – In the style of Hibernate / JPA / JDO
   – Insert, delete, find by key, update, simple query
• Shared Data storage with:
   – MySQL server
   – Native C++ applications
   – Other ClusterJ, memcached applications
• Domain Object Model DataMapper pattern
   – Data is represented as domain objects
   – Domain objects are separate from business logic
   – Domain objects are mapped to database tables




                               Copyright © 2012 Oracle Corp.

                                                                  67
ClusterJ as NoSQL Store

• Key/value Store
   – Arbitrary text storage (String <=> CLOB)
   – Arbitrary data storage (byte[ ] <=> BLOB)
• Document Store
   – JSON, XML, etc.
• Session Store
   – key = session id
   – value = serialized session state
• Back end for REST plugin




                               Copyright © 2012 Oracle Corp.

                                                               68
Domain Object Model Mapping

• Tables map to Persistent Interfaces / Classes
• Columns map to Persistent Properties
   – column names default to property name
• Rows map to Persistent Instances
• Annotations on Interfaces / Classes customize mappings
• User chooses which to write:
   – User interface (ClusterJ then generates implementation class)
   – Persistent class (ClusterJ provides base implementation class)




                               Copyright © 2012 Oracle Corp.

                                                                      69
ClusterJ – Generated Class
@PersistenceCapable(table="tweets")
public interface Tweets {


    String getId();

    void setId(String id);


    String getAuthor();

    void setAuthor(String value);


    Date getTime_stamp();

    void setTime_stamp(Date value);


    String getTweet();

    void setTweet(String value);
}


                Copyright © 2012 Oracle Corp.

                                                70
ClusterJ – Dynamic Object
public class Tweets

    extends DynamicObject {


    public String table() {

    
    return "tweets";


    String getId() {

    
    return (String)get(0);

    }

    void setId(String value) {

    
    set(0, value);

    }
...
// other fields and behavior
}


                Copyright © 2012 Oracle Corp.

                                                71
Numeric Column Mapping
• Java boolean, Boolean                  • Java long, Long
   – BIT(1)                                   – BIT(1) to BIT(64)
• Java byte, Byte                             – BIGINT
   – BIT(1) to BIT(8)                         – BIGUNSIGNED
   – TINYINT                             •   Java float, Float
• Java short, Short                           – FLOAT
   – BIT(1) to BIT(16)                   •   Java double, Double
   – SMALLINT                                 – DOUBLE
   – YEAR                                •   Java BigDecimal
• Java int, Integer                           – NUMERIC
   – BIT(1) to BIT(32)                        – DECIMAL
   – INT                                 •   Java BigInteger
                                              – NUMERIC
                                              – DECIMAL
                          Copyright © 2012 Oracle Corp.

                                                                    72
Date Column Mapping

• Java util Date
   – DATETIME
   – TIMESTAMP
   – TIME
   – DATE
• Java sql Date
   – DATE
• Java sql Time
   – TIME
• Java sql Timestamp
   – DATETIME
   – TIMESTAMP


                       Copyright © 2012 Oracle Corp.

                                                       73
Variable Size Column Mapping

• Java String
   – CHAR
   – VARCHAR
   – TEXT
• Java byte[ ]
   – BINARY
   – VARBINARY
   – BLOB




                 Copyright © 2012 Oracle Corp.

                                                 74
ClusterJ Features

• Character Set Translation (all MySQL charsets)
• Automatic detection of primary keys, indexes
• Compound Primary Keys
• Ordered (btree) indexes
• Unique (hash) indexes
• Automatic use of partition key
• Multi-threaded applications




                                Copyright © 2012 Oracle Corp.

                                                                75
ClusterJ Interfaces

• SessionFactory
   – Instance per connection to cluster
• Session
   – Instance per "user"
• Transaction
   – Instance per Session
• Query
   – Multiple instances per Session




                               Copyright © 2012 Oracle Corp.

                                                               76
ClusterJ User View
                           Domain
                           Object   Domain
                          Domain    Object
 Domain                   Object  Domain
 Object  Domain                   Object                     Domain
Domain    Object                                             Object  Domain
Object Domain                                               Domain    Object
        Object                                              Object Domain
                                                                    Object

                              Session and
                              Transaction
   Session and
                                                               Session and
   Transaction
                                                               Transaction




         SessionFactory                    Configuration Properties



                           Copyright © 2012 Oracle Corp.

                                                                               77
ClusterJ Limitations
• No Relationships
   – primitive types only
• No Multi-table inheritance
   – single table per persistent interface or class
• No joins in queries
   – column comparisons and boolean operators
• No Table creation
   – user needs to create tables and indexes
• No Lazy Loading
   – entire record is loaded at one time, including LOBs




                                   Copyright © 2012 Oracle Corp.

                                                                   78
ClusterJ Requirements

• Java 1.5 or 1.6
   – Compile-time jar:
      • clusterj-api
   – Run-time jar:
      • clusterj
   – Java Native Library
      • ndbclient
• MySQL Cluster 7.1 or higher
   – includes jars and native libraries as above




                                  Copyright © 2012 Oracle Corp.

                                                                  79
<Insert Picture Here>




NDB Memcache API Overview


                            80
Memcached Overview:
        Two levels of hashing

                                                                    memcached
       httpd

                                                                                 hash key
     PHP/Perl                                 ve        r           memcached
                                     ic k ser                                   to find data
                           ke y to p
     Memcache         hash
                friends:12389                                       memcached
               memcache key




81                                  Copyright © 2011 Oracle Corp.

                                                                                          81
Expected Latency & Throughput


       httpd                               c.
                                  t ions/se
                        o f opera
                10,000s       nd trip
                            u
     PHP/Perl   ~2 00 µs ro                                 memcached

     memcache

      mysql
                  1,000s of
                            operatio
                  ~ 2 ms ro          ns/sec.                       MySQL
                            und trip                               Slave


82                          Copyright © 2011 Oracle Corp.

                                                                           82
Goals
• Access stored data directly from memcache clients

     – Memcached perspective:
          • MySQL Cluster is a write-scalable, replicated data store
                – with reliable in-memory storage,
                – plus on-disk storage when data is too big for
                    memory.
     – MySQL Cluster perspective:
          • memcache is a high performance API
                – providing easy access to in-memory data,
                – plus an extra layer of caching when data is on disk.



83                          Copyright © 2011 Oracle Corp.

                                                                         83
Memcache Protocol & Commands




               see handout!




84              Copyright © 2011 Oracle Corp.

                                                84
Anatomy of a Memcache key




                     user:1248

        the prefix                                     the database key




85                     Copyright © 2011 Oracle Corp.

                                                                          85
A key-prefix mapping




     Memcache
                                                            Cache
        key            Cluster                  Container
                                                            Policy
       prefix




86                  Copyright © 2011 Oracle Corp.

                                                                     86
A memcache server role

                                key                               Con-    Cache
                                                       Cluster
                               prefix                            tainer   Policy



                                key                               Con-    Cache
                                                       Cluster
                               prefix                            tainer   Policy
      Server
       Role
        ID
                                key                               Con-    Cache
                                                       Cluster
                               prefix                            tainer   Policy



                                key                               Con-    Cache
                                                       Cluster
                               prefix                            tainer   Policy



87                     Copyright © 2011 Oracle Corp.

                                                                                   87
<Insert Picture Here>




Mynode Preview
Craig L Russell
Architect, Oracle Corp.



                               88
The following is intended to outline our general
     product direction. It is intended for information
     purposes only, and may not be incorporated into any
     contract. It is not a commitment to deliver any
     material, code, or functionality, and should not be
     relied upon in making purchasing decisions.
     The development, release, and timing of any features
     or functionality described for Oracle’s products
     remains at the sole discretion of Oracle.




89

                                                            89
Mynode: Node.js module
          for MySQL
• Advance Planning – availability not announced
• Domain Object Model DataMapper pattern
  – Domain objects are mapped to database tables
• High Performance, Light Weight, Easy to Use Direct Connection
  – Asynchronous API
  – Insert, delete, find by key, update, simple query
• Shared Data storage with:
  – MySQL server
  – Native C++ applications
  – Other Mynode, ClusterJ, memcached applications




                                 Copyright © 2012 Oracle Corp.

                                                                  90
Domain Object Model Mapping

• Tables map to Persistent Classes
• Columns map to Persistent Properties
   – column names default to property name
• Rows map to Persistent Instances
• Annotations customize mappings
   – column names
   – table names
   – null value handling




                            Copyright © 2012 Oracle Corp.

                                                            91
Mynode – Mapped Class

function Tweets(author, tweet) {


    this.id = randomUUID();


    this.author = author;


    this.tweet = tweet;


    this.time_stamp = new Date();

};




                Copyright © 2012 Oracle Corp.

                                                92
Mynode – Insert

var tweet = new Tweet('clr',

    'having a great #oscon');

insertTweet(tweet, function()...);

function insertTweet(tweet, callback) {


    session.insert('tweets', tweet,

    
    function(err) {

    
    
    if (err) throw …

    
    
    callback();

    
    }

};

                Copyright © 2012 Oracle Corp.

                                                93
Mynode – Find by Primary Key

function getTweet(id, callback) {


    session.find('tweets', id,

    
    function(err, tweet) {

    
    
    if (err) throw …

    
    
    callback(tweet);

    
    }

};




                Copyright © 2012 Oracle Corp.

                                                94
Mynode Features

• Character Set Translation (all MySQL charsets)
• Automatic detection of primary keys, indexes
• Compound Primary Keys
• Automatic use of partition key
• Multi-threaded applications




                                Copyright © 2012 Oracle Corp.

                                                                95
Mynode Classes

• Mynode
   – SessionFactory factory
   – Establishes connection to database
• SessionFactory
   – Instance per connection to database
• Session
   – Instance per "user"




                             Copyright © 2012 Oracle Corp.

                                                             96
Mynode User View
                           Domain
                           Object   Domain
                          Domain    Object
 Domain                   Object  Domain
 Object  Domain                   Object                     Domain
Domain    Object                                             Object  Domain
Object Domain                                               Domain    Object
        Object                                              Object Domain
                                                                    Object

                              Session and
                              Transaction
   Session and
                                                               Session and
   Transaction
                                                               Transaction




         SessionFactory                    Configuration Properties



                           Copyright © 2012 Oracle Corp.

                                                                               97
Mynode Requirements

• JavaScript
• Node.js
   – Run-time module:
      • mynode
   – Java Native Library
      • ndbclient
• MySQL Cluster 7.2 or higher




                           Copyright © 2012 Oracle Corp.

                                                           98
One more thing before the break ...




                               DB
                              Node 2



               DB                            DB
              Node 1                        Node 3




Heartbeat messages             DB
                              Node 4
sent to next node in circle


99

                                                     99
You want to shut down?



  MySQL Servers:
    mysqladmin -u root shutdown




      Management and Data Nodes:

       ndb_mgm>   shutdown




100

                                   100
<Insert Picture Here>




MySQL Cluster and NoSQL
                          Mid-Session Break



                                              101
3:30 - 5:00 P.M Agenda

      – SQL DDL Lecture
      – Restart your clusters    <Insert Picture Here>


      – Labs
        – Java Insert
        – Time for Coding
        – Memcache Insert
        – Time for Coding
        – Java Query
        – Time for Coding
      – Wrap-up with Q&A


102

                                                    102
<Insert Picture Here>




      Data Definition,
      SQL,
      and NDB Indexes




103

                                            103
Data Definition: Distribution Keys


• Every table has a distribution key. The
                                               <Insert Picture Here>
  MD5 hash of the distribution key
  determines which fragment a row
  belongs to.

• When an API node knows the
  distribution key of an interesting row, it
  can take advantage of this by choosing
  the primary fragment as TC. (ClusterJ,
  MySQL, and Memcached all do this
  automatically).


104

                                                                  104
Data Definition: Ordered Indexes

      • An ordered index is an in-memory T-Tree index

      • It is partitioned in exactly the same way as the main
        table.
         – i.e.: each data node has its own ordered index
           covering its own fragments of the table

      • This in-memory T-Tree contains direct pointers to
        the in-memory rows of the main table.

      • The index is not stored on disk between restarts; it
        is rebuilt during node startup.
105

                                                                105
Data Definition: The SQL primary key

      • By default, MySQL Cluster does two things with the
        primary key of a table:
         – Uses it as the distribution key
         – Creates an ordered index named PRIMARY.
      • This means a table’s primary key can be used both
        for lookups and for scans
      • You can override the default behavior:
         – PARTITION BY HASH (col1, col2) to get a
           different distribution key
         – PRIMARY KEY USING HASH to skip building the
           ordered index


106

                                                             106
Data Definition: Unique Indexes



• A unique index is a secondary hash index. <Insert Picture
• Used to enforce a unique constraint       Here>

• Used for lookups, but not scans
• Implemented as a hidden table:
      – key: the unique index =>
      – value: the primary key of the main table
• Because it’s really an independent table, it
  has its own independent distribution across
  fragments.


107

                                                         107
Data Definition: Indexes




 • Data rows can be stored either in-memory, or on disk
   (in a tablespace).
 • Data stored in memory is still durable, because the
   data nodes checkpoint it to disk
 • Indexes, however, are always in memory. Never on
   disk.
 • Therefore, a cluster must have enough memory for all
   its indexes.


108

                                                          108
Data Definition: Tweets



  CREATE TABLE tweets (
    id varchar(36) primary key,
    tweet varchar(140),
    time_stamp timestamp,
    author varchar(15),
    index(time_stamp),
    index(author))
  ENGINE=ndb;




109

                                  109
Data Definition: Hashtags



  CREATE TABLE hashtags (
    hashtag varchar(20),
    tweet_id varchar(36),
    time_stamp timestamp,
    author varchar(15),
    primary key(hashtag, tweet_id))
  ENGINE=ndb;




110

                                      110
<Insert Picture Here>



      Restart clusters!



      ndb_mgmd --configdir=.
         ndbd -c <connectstring>
      ndb_mgm -c <connectstring>




111

                                                      111
<Insert Picture Here>




ClusterJ API
Craig L Russell
Architect, Oracle Corp.



                               112
ClusterJ – Generated Class
@PersistenceCapable(table="tweets")
public interface Tweets {


    String getId();

    void setId(String id);


    String getAuthor();

    void setAuthor(String value);


    Date getTime_stamp();

    void setTime_stamp(Date value);


    String getTweet();

    void setTweet(String value);
}


                Copyright © 2012 Oracle Corp.

                                                113
ClusterJ – Dynamic Object
public class Tweets

    extends DynamicObject {


    public String table() {

    
    return "tweets";


    String getId() {

    
    return (String)get(0);

    }

    void setId(String value) {

    
    set(0, value);

    }
...
// other fields and behavior
}


                Copyright © 2012 Oracle Corp.

                                                114
Numeric Column Mapping
• Java boolean, Boolean                  • Java long, Long
   – BIT(1)                                   – BIT(1) to BIT(64)
• Java byte, Byte                             – BIGINT
   – BIT(1) to BIT(8)                         – BIGUNSIGNED
   – TINYINT                             •   Java float, Float
• Java short, Short                           – FLOAT
   – BIT(1) to BIT(16)                   •   Java double, Double
   – SMALLINT                                 – DOUBLE
   – YEAR                                •   Java BigDecimal
• Java int, Integer                           – NUMERIC
   – BIT(1) to BIT(32)                        – DECIMAL
   – INT                                 •   Java BigInteger
                                              – NUMERIC
                                              – DECIMAL
                          Copyright © 2012 Oracle Corp.

                                                                    115
Date Column Mapping

• Java util Date
   – DATETIME
   – TIMESTAMP
   – TIME
   – DATE
• Java sql Date
   – DATE
• Java sql Time
   – TIME
• Java sql Timestamp
   – DATETIME
   – TIMESTAMP


                       Copyright © 2012 Oracle Corp.

                                                       116
Variable Size Column Mapping

• Java String
   – CHAR
   – VARCHAR
   – TEXT
• Java byte[ ]
   – BINARY
   – VARBINARY
   – BLOB




                 Copyright © 2012 Oracle Corp.

                                                 117
ClusterJ Interfaces

• SessionFactory
   – Instance per connection to cluster
• Session
   – Instance per "user"
• Transaction
   – Instance per Session
• Query
   – Multiple instances per Session




                               Copyright © 2012 Oracle Corp.

                                                               118
ClusterJ User View
                           Domain
                           Object   Domain
                          Domain    Object
 Domain                   Object  Domain
 Object  Domain                   Object                     Domain
Domain    Object                                             Object  Domain
Object Domain                                               Domain    Object
        Object                                              Object Domain
                                                                    Object

                              Session and
                              Transaction
   Session and
                                                               Session and
   Transaction
                                                               Transaction




         SessionFactory                    Configuration Properties



                           Copyright © 2012 Oracle Corp.

                                                                               119
SessionFactory
• Configured by properties
   –   com.mysql.clusterj.connectstring (the only really important property)
   –   com.mysql.clusterj.connect.retries
   –   com.mysql.clusterj.connect.delay
   –   com.mysql.clusterj.connect.timeout.before
   –   com.mysql.clusterj.connect.timeout.after
   –   com.mysql.clusterj.max.transactions
• One SessionFactory per cluster per JVM
   – Connection poooling (multiple TCP connections per SessionFactory)




                                Copyright © 2012 Oracle Corp.

                                                                               120
Example
SessionFactory sessionFactory;
Properties props = new Properties();

void initProps() {
props.put(PROPERTY_CLUSTER_CONNECTSTRING,

    "localhost:1186");
props.put(PROPERTY_CLUSTER_DATABASE,

    "personnel");
}
public init(Properties props) {

    initProps();

    sessionFactory = ClusterJHelper

    
    .getSessionFactory(props);
}

                 Copyright © 2012 Oracle Corp.

                                                 121
Session

• Persistent Instance Factory
• Lifecycle Management
   – persist() // record must not already exist
   – remove() // record must already exist
• Update Management
   – update() // no need to read first
   – write() // record will be overwritten if already exists
• Find by ID
• Query Factory




                                 Copyright © 2012 Oracle Corp.

                                                                 122
Example Insert
Session session;
void getSession() {

     session = sessionFactory.getSession();
}
Tweets createTweet(String author,

    
      String message) {

     Tweets tweet =

         session.newInstance(Tweets.class);

     tweet.setId(UUID.randomUUID().toString();

     tweet.setAuthor(author);

     tweet.setTweet(message);

     tweet.setTime_stamp(new Date());

     session.persist(tweet);

     return tweet;
}


                  Copyright © 2012 Oracle Corp.

                                                  123
Example Find
Tweets findTweet(String id) {

    Tweets tweet =

    
    session.find(Tweets.class, id);

    return tweet;
}




                  Copyright © 2012 Oracle Corp.

                                                  124
Transaction

• Optionally used to delimit transactions
   – begin()
   – commit()
   – rollback()
• Optionally mark a transaction for rollback
   – setRollbackOnly()
   – getRollbackOnly()
• If not used, every operation is in its own transaction




                            Copyright © 2012 Oracle Corp.

                                                            125
Example
Transaction transaction;

void getTransaction() {

     transaction = session.getTransaction();
}

void   createTweets() {

       getTransaction();

       transaction.begin();

       createTweet("amos", "#oscon rocks");

       createTweet("barb", "sw33t tutorial");

       createTweet("chuck", "lets #partay");

       createTweet("dave", "just one mo hour");

       transaction.commit();
}

                     Copyright © 2012 Oracle Corp.

                                                     126
ClusterJ Exercises

• Create schema for tweets, hashtags
   – create.sql in labs/schema
• Write domain models for Tweets, Hashtags
  – skeletons in labs/model
• Write Insert.java program
  – skeleton in labs/test/Insert.java
• Compile-time jar: clusterj-api-7.2.6.jar
• Run-time jar: clusterj-7.2.6.jar
• Java Native Library: ndbclient




                                  Copyright © 2012 Oracle Corp.

                                                                  127
ClusterJ Exercises

• Create schema for tweets, hashtags
   – create.sql in labs/schema
• Write domain models for Tweets, Hashtags
  – skeletons in labs/model
• Write Insert.java program
  – skeleton in labs/test/Insert.java
• Compile-time jar: clusterj-api-7.2.6.jar
• Run-time jar: clusterj-7.2.6.jar
• Java Native Library: ndbclient




                                  Copyright © 2012 Oracle Corp.

                                                                  128
<Insert Picture Here>




Memcache Insert


                          129
A key-prefix mapping




      Memcache
                                                             Cache
         key            Cluster                  Container
                                                             Policy
        prefix




130                  Copyright © 2011 Oracle Corp.

                                                                      130
Memcache Config
      • Generate a containers record for the tweets table
        • value columns in the containers record are
          separated by commas

      • Generate a key-prefix mapping for role 0

      • Start a memcached server

              cd run-cluster/ndb
              ./start-memcached.sh



131                         Copyright © 2011 Oracle Corp.

                                                            131
Start Memcached
      $ memcached -E /usr/local/mysql/lib/ndb_engine.so -e
      connectstring="localhost:1186"

      15-Jul-2012 23:51:46 PDT NDB Memcache 5.5.22-ndb-7.2.6 started [NDB
      7.2.6; MySQL 5.5.22]
      Contacting primary management server (localhost:1186) ...
      Connected to "localhost:1186" as node id 4.
      Retrieved 4 key prefixes for server role "default_role".
      The default behavior is that:
          GET uses NDB only
          SET uses NDB only
          DELETE uses NDB only.
      The 3 explicitly defined key prefixes are "b:" (demo_table_large),
      "mc:" () and "t:" (demo_table_tabs)
      Server started with 4 threads.
      Priming the pump ...
      Connected to "localhost:1186" as node id 5.
      Scheduler: using 2 connections to cluster 0
      Scheduler: starting for 1 cluster; c0,f0,g1,t1
      done [0.656 sec].

132                                Copyright © 2011 Oracle Corp.

                                                                            132
Memcache Exercises



      • In perl/labs/
      • 1. config.sql: create metadata for app.
      • 2. tweets.pl: insert tweets using memcached
      • 3. counter.sql: revise app to count tweets per user




133                         Copyright © 2011 Oracle Corp.

                                                              133
Memcache tips



      • perldoc Cache::Memcached
      • The file in labs/ already connects to a server for you.
      • In an actual Memcache command, the 3 fields of the
        value should be separated by tab characters (“t”)




134                          Copyright © 2011 Oracle Corp.

                                                                  134
<Insert Picture Here>




ClusterJ Query
Craig L Russell
Architect, Oracle Corp.



                               135
ClusterJ Query

• Builder pattern
• Similar to JPA criteria query
• Predicates compare column values to parameters:
   – equal, lessEqual, greaterEqual, lessThan, greaterThan, between, in
   – comparison with null
• Combine predicates using binary and unary operators:
   – or, and, not
• Execution is optimized to use indexes
   – primary or unique key lookup
   – ordered scan for complete or partial keys
   – table scan if no index can be used


                               Copyright © 2012 Oracle Corp.

                                                                          136
ClusterJ Query Interfaces
• Query
   – the "executable" part
   – Parameters and limits are bound to this instance
• QueryBuilder
   – used to build queries
• QueryDomainType
   – represents the user's domain type for queries
• PredicateOperand
   – represents either a query parameter or a query property
• Predicate
   – represents a comparison between a property and a parameter
   – can be combined using "and", "or", and "not" operators



                                 Copyright © 2012 Oracle Corp.

                                                                  137
ClusterJ Query Optimizer

•   Optimizer looks for indexes
•   PRIMARY key all columns equal
•   PRIMARY key leading columns equal
•   Unique (hash) key equal
•   Ordered (btree) key equal, greater, less
•   Table scan if no indexes are usable
•   All terms used for filter
•   After parameters are bound, ask for query plan:
    – Query.explain()
    – Keys: Query.SCAN_TYPE, Query.INDEX_USED


                            Copyright © 2012 Oracle Corp.

                                                            138
Query Example
QueryDomainType<Tweets> qdtTweets =
   builder.createQueryDefinition(Tweets.class) ;

Predicate eqAuthor = qdtTweets.get("author")

     
    .eq(qemp.param("pauthor"));
Predicate gtTime_stamp = qdtTweets.get("time_stamp")

     
    .greaterEqual(qemp.param("ptime_stamp"));

qdtTweets.where(eqAuthor.and(gtTime_stamp));

Query query = session.createQuery(qdtTweets) ;

query.setParameter("pauthor", getAuthor());
query.setParameter("ptime_stamp", getTime());

List<Tweets> results = query.getResultList() ;

                     Copyright © 2012 Oracle Corp.

                                                       139
ClusterJ Query Exercises

• Write Find.java program
  – Skeleton in labs/test/Find.java
  – Query by author
  – Query by hashtag
  – Query by date range
  – Query by combining above criteria




                               Copyright © 2012 Oracle Corp.

                                                               140
ClusterJ Query Extra Credit

• Write Delete.java program
  – skeleton in labs/test/Delete.java
  – Delete by author
  – Delete by hashtag
  – Delete by date range
  – Delete by combining above criteria




                                Copyright © 2012 Oracle Corp.

                                                                141
<Insert Picture Here>




Final Questions & Answers

                            142

Weitere ähnliche Inhalte

Was ist angesagt?

Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational databaseDave Stokes
 
Second Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON FunctionsSecond Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON FunctionsSveta Smirnova
 
Hibernate
HibernateHibernate
Hibernateksain
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Antony T Curtis
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Librarydoughellmann
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring DataArturs Drozdovs
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBAntony T Curtis
 
Create custom looping procedures in sql server 2005 tech republic
Create custom looping procedures in sql server 2005   tech republicCreate custom looping procedures in sql server 2005   tech republic
Create custom looping procedures in sql server 2005 tech republicKaing Menglieng
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group ReplicationDave Stokes
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of SlickKnoldus Inc.
 
Java FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's GuideJava FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's GuideStephen Chin
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Scott Leberknight
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLPadraig O'Sullivan
 

Was ist angesagt? (20)

Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational database
 
Second Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON FunctionsSecond Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON Functions
 
Persistences
PersistencesPersistences
Persistences
 
Spring 4 - A&BP CC
Spring 4 - A&BP CCSpring 4 - A&BP CC
Spring 4 - A&BP CC
 
Hibernate
HibernateHibernate
Hibernate
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Library
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
 
Create custom looping procedures in sql server 2005 tech republic
Create custom looping procedures in sql server 2005   tech republicCreate custom looping procedures in sql server 2005   tech republic
Create custom looping procedures in sql server 2005 tech republic
 
4.3 MySQL + PHP
4.3 MySQL + PHP4.3 MySQL + PHP
4.3 MySQL + PHP
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Jdbc
JdbcJdbc
Jdbc
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
 
Mysql
MysqlMysql
Mysql
 
Java FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's GuideJava FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's Guide
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQL
 

Andere mochten auch

American revolution
American revolutionAmerican revolution
American revolutionHTStewart
 
Prezentacija nhb
Prezentacija nhbPrezentacija nhb
Prezentacija nhbpixi00004
 
MongoDB Drivers And High Availability: Deep Dive
MongoDB Drivers And High Availability: Deep DiveMongoDB Drivers And High Availability: Deep Dive
MongoDB Drivers And High Availability: Deep Diveemptysquare
 
Prezentacija nhb
Prezentacija nhbPrezentacija nhb
Prezentacija nhbpixi00004
 
Les typologies des Réseaux informatiques
Les  typologies des Réseaux informatiquesLes  typologies des Réseaux informatiques
Les typologies des Réseaux informatiquesFatima Zohra BENHACINE
 

Andere mochten auch (6)

P&e pt. 2
P&e pt. 2P&e pt. 2
P&e pt. 2
 
American revolution
American revolutionAmerican revolution
American revolution
 
Prezentacija nhb
Prezentacija nhbPrezentacija nhb
Prezentacija nhb
 
MongoDB Drivers And High Availability: Deep Dive
MongoDB Drivers And High Availability: Deep DiveMongoDB Drivers And High Availability: Deep Dive
MongoDB Drivers And High Availability: Deep Dive
 
Prezentacija nhb
Prezentacija nhbPrezentacija nhb
Prezentacija nhb
 
Les typologies des Réseaux informatiques
Les  typologies des Réseaux informatiquesLes  typologies des Réseaux informatiques
Les typologies des Réseaux informatiques
 

Ähnlich wie MySQL Cluster and NoSQL Overview

Life After Sharding: Monitoring and Management of a Complex Data Cloud
Life After Sharding: Monitoring and Management of a Complex Data CloudLife After Sharding: Monitoring and Management of a Complex Data Cloud
Life After Sharding: Monitoring and Management of a Complex Data CloudOSCON Byrum
 
Yes sql08 inmemorydb
Yes sql08 inmemorydbYes sql08 inmemorydb
Yes sql08 inmemorydbDaniel Austin
 
DataStax C*ollege Credit: What and Why NoSQL?
DataStax C*ollege Credit: What and Why NoSQL?DataStax C*ollege Credit: What and Why NoSQL?
DataStax C*ollege Credit: What and Why NoSQL?DataStax
 
A Global In-memory Data System for MySQL
A Global In-memory Data System for MySQLA Global In-memory Data System for MySQL
A Global In-memory Data System for MySQLDaniel Austin
 
PayPal Big Data and MySQL Cluster
PayPal Big Data and MySQL ClusterPayPal Big Data and MySQL Cluster
PayPal Big Data and MySQL ClusterMat Keep
 
Database as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance PlatformDatabase as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance PlatformMaris Elsins
 
Technology Day 2011 MySQL & MariaDB
Technology Day 2011 MySQL & MariaDBTechnology Day 2011 MySQL & MariaDB
Technology Day 2011 MySQL & MariaDBDan-Claudiu Dragoș
 
Oracle strategy for_information_management
Oracle strategy for_information_managementOracle strategy for_information_management
Oracle strategy for_information_managementInSync Conference
 
Managing Exadata in the Real World
Managing Exadata in the Real WorldManaging Exadata in the Real World
Managing Exadata in the Real WorldEnkitec
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQLDon Demcsak
 
Rails infrastructure
Rails infrastructureRails infrastructure
Rails infrastructurequreshiomar
 
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...Equnix Business Solutions
 
OpenStack Days East -- MySQL Options in OpenStack
OpenStack Days East -- MySQL Options in OpenStackOpenStack Days East -- MySQL Options in OpenStack
OpenStack Days East -- MySQL Options in OpenStackMatt Lord
 
MySQL Options in OpenStack
MySQL Options in OpenStackMySQL Options in OpenStack
MySQL Options in OpenStackTesora
 
MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0Ted Wennmark
 
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013Christopher Curtin
 
Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...DataWorks Summit
 
Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Saltmarch Media
 
Severalnines Self-Training: MySQL® Cluster - Part V
Severalnines Self-Training: MySQL® Cluster - Part VSeveralnines Self-Training: MySQL® Cluster - Part V
Severalnines Self-Training: MySQL® Cluster - Part VSeveralnines
 

Ähnlich wie MySQL Cluster and NoSQL Overview (20)

Life After Sharding: Monitoring and Management of a Complex Data Cloud
Life After Sharding: Monitoring and Management of a Complex Data CloudLife After Sharding: Monitoring and Management of a Complex Data Cloud
Life After Sharding: Monitoring and Management of a Complex Data Cloud
 
Yes sql08 inmemorydb
Yes sql08 inmemorydbYes sql08 inmemorydb
Yes sql08 inmemorydb
 
DataStax C*ollege Credit: What and Why NoSQL?
DataStax C*ollege Credit: What and Why NoSQL?DataStax C*ollege Credit: What and Why NoSQL?
DataStax C*ollege Credit: What and Why NoSQL?
 
A Global In-memory Data System for MySQL
A Global In-memory Data System for MySQLA Global In-memory Data System for MySQL
A Global In-memory Data System for MySQL
 
PayPal Big Data and MySQL Cluster
PayPal Big Data and MySQL ClusterPayPal Big Data and MySQL Cluster
PayPal Big Data and MySQL Cluster
 
Database as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance PlatformDatabase as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance Platform
 
Technology Day 2011 MySQL & MariaDB
Technology Day 2011 MySQL & MariaDBTechnology Day 2011 MySQL & MariaDB
Technology Day 2011 MySQL & MariaDB
 
NoSQL
NoSQLNoSQL
NoSQL
 
Oracle strategy for_information_management
Oracle strategy for_information_managementOracle strategy for_information_management
Oracle strategy for_information_management
 
Managing Exadata in the Real World
Managing Exadata in the Real WorldManaging Exadata in the Real World
Managing Exadata in the Real World
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
Rails infrastructure
Rails infrastructureRails infrastructure
Rails infrastructure
 
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
 
OpenStack Days East -- MySQL Options in OpenStack
OpenStack Days East -- MySQL Options in OpenStackOpenStack Days East -- MySQL Options in OpenStack
OpenStack Days East -- MySQL Options in OpenStack
 
MySQL Options in OpenStack
MySQL Options in OpenStackMySQL Options in OpenStack
MySQL Options in OpenStack
 
MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0
 
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
 
Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...
 
Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?
 
Severalnines Self-Training: MySQL® Cluster - Part V
Severalnines Self-Training: MySQL® Cluster - Part VSeveralnines Self-Training: MySQL® Cluster - Part V
Severalnines Self-Training: MySQL® Cluster - Part V
 

Kürzlich hochgeladen

QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Kürzlich hochgeladen (20)

QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

MySQL Cluster and NoSQL Overview

  • 1. Welcome to OSCON 2012 MySQL Cluster and NoSQL <Insert Picture Here> • If you want to run a node in a multi-node cluster: • Pick a seat where there is a network cable • Plug in • Turn off your firewall (or at least allow ports 1186 & 2186) • Point your browser to http://uplink/ • OR, to run a one-node cluster contained entirely on your own laptop, sit away from the network cables and use the conference wireless. 1 Copyright © 2011 Oracle Corp. 1
  • 2. <Insert Picture Here> MySQL Cluster and NoSQL John David Duncan Craig L Russell MySQL Cluster Engineering Oracle Corp 2
  • 3. Everyone needs the tutorial files! • From USB stick • From uplink • oscon-2012-mysql-nosql.tar • From github – or • oscon-2012-mysql-nosql.zip – or • oscon-2012-mysql-nosql-MSDOS.zip git clone git://github.com/jdduncan/oscon-2012-mysql-nosql.git 3 3
  • 5. MySQL Cluster and NoSQL • There are 3 handouts – README for Java / Twitter development exercise – MySQL pathname reference – Memcache reference card (2-sided) • If you still need MySQL Cluster 7.2.6 and Cache::Memcached, they are on the USB sticks – go get ‘em • If you want to be in a multi-node cluster with other people, find a network cable 5 5
  • 6. Big Picture Agenda <Insert Picture Here> • First half: deploy cluster – Some lectures – Some lab - run a cluster • Second half: develop apps – Some lectures - Memcached & Java – Some lab - you write the code 6 6
  • 7. Presenter's "Baggage" J.D. Duncan • Former Systems Administrator, web developer, MySQL DBA • Joined MySQL AB in 2004 Image used under a Creative Commons license from Flickr user Digiart2001 7 Copyright © 2011 Oracle Corp. 7
  • 8. Presenter's "Baggage" Craig L. Russell • Systems Architect focused on Enterprise Java • Specification Lead for Java Data Objects • Architect of Container- Managed Persistence • Likes SQL well enough • Likes well-designed APIs even more Image used under a Creative Commons license from Flickr user Digiart2001 8 8
  • 9. 1:30 - 3:00 P.M Agenda <Insert Picture Here> • Seating & Introductions (10 min.) • MySQL Cluster Essentials (JD - 25 min.) • Hands-on MySQL Cluster setup (35 min.) • API Overviews (20 min.) – ClusterJ (Craig) – Memcache (JD) – Node.js Connector Project 9 9
  • 10. MySQL Cluster Essentials <Insert Picture Here> 10 10
  • 11. What is a database? • It’s a computer system that manages data ... in a useful way. 11 11
  • 12. How do database systems make themselves useful? • Persistent storage – in “the system of record” • Indexed retrieval – the database gets big, but retrieval time remains small • Central enforcement of data integrity – Every Social Security Number has 9 digits – Every order has a billing address • Maintain an illusion of consistency – isolating a transcation other concurrent changes 12 12
  • 13. How is the data structured? • Key : Value – Hash table (or memcache): • lookups only • no scans – Ordered Index (or binary tree): • Lookups and scans both. • Key : Structured Value – redis: common data structures used in application code – mongodb: structured documents, possible secondary indexes – dynamo: schema-free tables • Relational (Tables with a schema) 13 13
  • 14. Document Databases • Examples: MongoDB, CouchDB • Expected lookup: – “Fetch this patient’s record” ✓ • Unexepected lookup: – “Who took Accutane after 1990?” x 14 14
  • 15. Relational Databases • In a truly normalized relational schema, no table is more central than any other. • “Fetch this patient’s record” ✓ • “Did more of our patients get the flu in 2008 or in 2009?” ✓ • “Which doctor prescribes the most prednisone?” ✓ 15 15
  • 16. But what about schema changes? 16 16
  • 17. But what about schema changes? They need to be online operations. 17 17
  • 18. In the last few minutes we actually covered a lot of important theory. • But here’s one more bit: consistency vs. availability. • Look at MySQL 4.0, circa 2000 Slave Master Slave Slave 18 18
  • 19. What happens when a link goes down? • CAP (Eric Brewer): You have to choose. You can’t have both. Commercial databases usually chose C, but MySQL replication chose A. Slave Master Slave Slave 19 19
  • 20. Now We Are Ready <Insert Picture Here> MySQL Cluster 20 Copyright © 2011 Oracle Corp. 20
  • 21. NDB Cluster Ericsson, 1997 • Hardware Design • Software Design – Inexpensive x86 hardware – 99.999% availability – "Shared nothing" clustering – Guaranteed consistency – Parallel execution – Commit at speed of network (rather than disk) Node Group 1 Node Group 2 F1 F2 Node 1 Node 3 F3 F4 3 F3 F4 Node 2 Node 4 F1 F2 Data Nodes 21 21
  • 22. NDB Cluster: Where does it fit? • Consistent or Available? – Availability is important. NDB is designed to remain running if one node in a node group fails. – But consistency is even more important. If all nodes in a node group fail, the database will shut itself down. • Relational? Yes. – Hashed primary key for data distribution – Secondary Unique indexes – Ordered indexes for scans – Online schema changes. • SQL? No. – C++ NDB API for object-relational application development. 22 22
  • 23. 2003: MySQL + NDB Cluster = MySQL Cluster • MySQL: – built for cheap linux boxes – free, popular, revolutionary, fast, easy to use – proven ability to run with different back-end data stores, e.g. MyISAM and InnoDB. – MySQL replication has asynchronous, best-effort design that prioritizes availability • NDB: – built for cheap linux boxes – high performance and availability – had no support for SQL, or ODBC, or JDBC 23 23
  • 24. The Basics • Management server – read the one central configuration file – allow other nodes to join – distribute the configuration to them – get the cluster up & running • Data Node – ndbd (single-threaded) or ndbmtd (multi-threaded) – Stores data and indexes – Manage all transactions and operations for API nodes • API Node – Join the cluster as a member node with node id – e.g. mysqld, memcached, JVM running ClusterJ application • Client – MySQL or Memcache client; not a member of the cluster 24 24
  • 25. Big Picture API Nodes Node Group 1 Node Group 2 NDB Data Nodes 25 Copyright © 2011 Oracle Corp. 25
  • 26. NOT a shared-disk architecture Application Application Application DBMS DBMS DBMS Server Server Server Instance Instance Instance Disk 26 Copyright © 2011 Oracle Corp. 26
  • 27. “Shared-Nothing” Architecture Application Application Application DBMS DBMS DBMS Server Server Server Instance Instance Instance Disk Disk Disk 27 Copyright © 2011 Oracle Corp. 27
  • 28. Synchronous data replication • Data changes take place on all the servers in coordination • The ”two-phase commit” (2PC) is the most commonly used protocol – The changes are only committed after they’ve been succesfully executed on all servers – TC (Transaction Coordinator) manages 2PC – LQH (Local Query Handler) at each data node manages local transaction API TC Data Node 1 Data Node 2 LQH LQH 28 Copyright © 2011 Oracle Corp. 28
  • 29. Heartbeat Circle Nodes organized DB in a logical circle Node 2 DB DB Node 1 Node 3 Heartbeat messages DB Node 4 sent to next node in circle 29 29
  • 30. Heartbeat Failure Example Node 1 fails to send DB heartbeats three Node 2 consecutive times xDB Node 1 DB Node 3 It is declared as dead and removed DB from the cluster Node 4 30 30
  • 31. Network Partitioning • The servers are organised in a network • What happens if the servers lose contact to each other? Server Server Server Server Server “Split brain” • Neither side can continue as this would lead to inconsistency 31 31
  • 32. Using an Arbitrator • In order to handle an even number of servers an arbitrator is added • When a majority is needed by a set of servers, the arbitrator “votes” for that set, making it a majority • The arbitrator must not vote for several different subsets and the arbitrator must be known to all servers • By using an arbitrator the two server system becomes more fault tolerant than a single server system Arbitrator Server Server 32 32
  • 33. Who Uses MySQL Cluster? Until 2010: Telco Networks & Network Equipment Makers 33 Copyright © 2011 Oracle Corp. 33
  • 34. Who Uses MySQL Cluster? Since 2010: Web & Online gaming • Session management • Shopping carts • Game play • Internal site monitoring 34 Copyright © 2011 Oracle Corp. 34
  • 35. MySQL Cluster Today ACID Compliant Relational Database SQL & NoSQL interfaces Write-Scalable & Real-Time Distributed, auto-partitioning (sharding), multi-master 99.999% Availability Shared-nothing, integrated clustering & sub-second recovery, local & geographic replication, on-line operations Low TCO Open-source, management & monitoring tools, scale-out on commodity hardware 35 Copyright © 2011 Oracle Corp. 35
  • 36. Online Maintenance • Online schema changes – ALTER TABLE ... • Online backup – START BACKUP ... • Online storage addition – e.g. from 4 data nodes to 6 36 36
  • 37. The long road to SQL JOIN performance • Initial integration (2004) – Move the data to the query – ... one row at a time – ... one loop iteration in a nested-loop join = 1 network trip • 2005 - 2009 – Improve efficiency ... – within the existing framework of the MySQL optimizer – e.g. Batch Key Access, push-down filters • MySQL Cluster 7.2 (2011) – Adaptive Query Localization – Algorithmic changes to optimizer – Push the majority of the query to the data nodes 37 37
  • 38. Results: Adaptive Query Localization in MySQL Cluster 7.2 mysql> SELECT COUNT(*) FROM residents, postcodes, towns WHERE residents.postcode=postcodes.postcode AND postcodes.town=towns.town AND towns.county="Berkshire"; +----------+ | COUNT(*) | +----------+ | 40001 | +----------+ Before: 48.68 sec • After: 2.02 sec 38 Copyright © 2011 Oracle Corp. 38
  • 39. Tour 39 39
  • 40. Tour Stop 1: Config File • A single central file for the whole cluster • Loaded by the management server on --initial • And then stored in cache for future management server restarts • Sections: – [MGM] – [DB DEFAULT] – [NDBD] – [API] 40 40
  • 41. Tour Stop: Management Server [MGM] NodeId=1 datadir=/Users/jdd/sandbox/ndb hostname=localhost % ndb_mgmd -f config-file-path 41 41
  • 42. Tour Stop: Data Nodes [DB DEFAULT] NoOfReplicas=1 TimeBetweenGlobalCheckpoints=12000 HeartbeatIntervalDbApi=15000 DataMemory=180M IndexMemory=60M 42 42
  • 43. Tour Stop: Data Nodes [NDBD] NodeId=2 % ndbd -c mgm_host:mgm_port 43 43
  • 44. Tour Stop: API Nodes [API] [API] [API] [API] [API] [API] [API] 44 44
  • 45. Tour Stop: API Nodes • mysqld, memcached, java, etc. – Java API nodes connect to clusters based on Java connection properties – mysqld connects to cluster based on my.cnf file – memcached connects based on command-line options 45 45
  • 46. Tour Stop: Management & Monitoring • From the mysql server – SQL for table creation, etc. – ndbinfo schema • e.g. SELECT * FROM ndbinfo.memoryusage; – SHOW ENGINE NDB STATUS; • Management Clients – ndb_mgm • Toolsets – From Oracle: MySQL Cluster Manager – Third party tools: severalnines.com 46 46
  • 47. MySQL Cluster Hands-On Lab <Insert Picture Here> 47 47
  • 48. MySQL Cluster Hands-On Lab • Solo Clusters <Insert Picture – Your config file is here: Here> – run-cluster/ndb/solo-cluster.ini • Multi-Node Clusters – http://uplink/ – 1 managment server per cluster – 2, 4, or 6 data nodes per cluster – Others can run API nodes – MGM and NDB nodes register with the web app – Then the web app generates a config file for the management server and you (mgm server person) download it and save it in run-cluster/ndb/ 48 48
  • 49. MySQL Cluster Hands-On Lab <Insert Picture Here> • Open 4 or more terminal windows • Set some pathnames – Check your handout! – export PATH=/usr/local/mysql/bin:$PATH – (or whatever is correct for your platform) – cd into oscon-2012-mysql-nosql 49 49
  • 50. Start your management servers! • Wireless: • cd run-cluster/ndb • ndb_mgmd --initial -f solo-cluster.ini --configdir=. • Wired (MGM person only!): • save cluster.ini from uplink • cd run-cluster/ndb • ndb_mgmd --initial -f cluster.ini --configir=. 50 50
  • 51. What’s going on with this cluster? • Start a management client! • (And leave it running in its window) • Wireless: • ndb_mgm -c localhost:1186 • Wired: • Where is your management server? • http://uplink should tell you • ndb_mgm -c box-xx:1186 51 51
  • 52. Start your data nodes! • You are still in run-cluster/ndb • And you remember your connectstring ... • So: ndbd -c <connectstring> 52 52
  • 53. What’s going on with this cluster? ndb_mgm> all status Node 2: starting (Last completed phase 2) ... ndb_mgm> show Cluster Configuration --------------------- 53 53
  • 54. Configure a MySQL server • Create a my.cnf file – cd run-cluster/sql – ./create-config.sh – ls (you should see my.cnf) • Wireless: leave it as-is • Wired: edit the connectstring 54 54
  • 55. Here’s what my own my.cnf looks like [mysqld] ndbcluster user=jdd datadir=/Users/jdd/[...]/run-cluster/sql ndb-connectstring=localhost:1186 55 55
  • 56. Configure a MySQL server cd oscon-2012-mysql-nosql . pathnames.sh cd run-cluster/sql $MYSQL_INSTALL_DIR/scripts/msyql_install_db --datadir=. --basedir=$MYSQL_INSTALL_DIR 56 56
  • 57. Configure a MySQL server Installing MySQL system tables... OK Filling help tables... OK ... 57 57
  • 58. Now start the mysqld mysqld_safe --defaults-file=./my.cnf mysqld_safe Starting mysqld daemon with databases from ... 58 58
  • 59. MySQL Client $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 59 59
  • 60. MySQL Client mysql> select * From ndbinfo.nodes; +---------+--------+---------+-------------+-------------------+ | node_id | uptime | status | start_phase | config_generation | +---------+--------+---------+-------------+-------------------+ | 2 | 3453 | STARTED | 0 | 1 | +---------+--------+---------+-------------+-------------------+ 1 row in set (0.00 sec) 60 60
  • 61. Create some tables (from the shell) • We need to run two SQL scripts: • One called ndb_memcache_metadata.sql in $MYSQL_HOME/share/memcache-api/ • Plus java/labs/schema/create.sql from oscon-2012-mysql-nosql % mysql -u root < filename 61 61
  • 62. MySQL Client mysql> use test mysql> show tables ; +----------------+ | Tables_in_test | +----------------+ | hashtags | | tweets | +----------------+ 62 62
  • 63. Make a backup! ndb_mgm> start backup Waiting for completed, this may take several minut Node 2: Backup 1 started from node 1 Node 2: Backup 1 started from node 1 completed StartGCP: 351 StopGCP: 354 #Records: 2058 #LogRecords: 0 Data: 51728 bytes Log: 0 bytes 63 63
  • 64. Things you might do if we had more time • Set up cluster-to-cluster replication • uses a designated mysql server in each cluster • Online alter table operations • ALTER ONLINE TABLE x ADD i int NULL; • (note that some ALTER operations can be done online and some others cannot) • Rolling Restart • Expand a cluster online (add nodes) 64 64
  • 65. API Overviews <Insert Picture Here> • ClusterJ (Craig, 10 min.) • Memcache (JD, 5 min.) • Node.JS project (JD & Craig, 10 min.) • Break time 65 65
  • 66. <Insert Picture Here> ClusterJ Overview Craig L Russell Architect, Oracle Corp. 66
  • 67. ClusterJ • High Performance, Light Weight, Easy to Use Direct Connection – In the style of Hibernate / JPA / JDO – Insert, delete, find by key, update, simple query • Shared Data storage with: – MySQL server – Native C++ applications – Other ClusterJ, memcached applications • Domain Object Model DataMapper pattern – Data is represented as domain objects – Domain objects are separate from business logic – Domain objects are mapped to database tables Copyright © 2012 Oracle Corp. 67
  • 68. ClusterJ as NoSQL Store • Key/value Store – Arbitrary text storage (String <=> CLOB) – Arbitrary data storage (byte[ ] <=> BLOB) • Document Store – JSON, XML, etc. • Session Store – key = session id – value = serialized session state • Back end for REST plugin Copyright © 2012 Oracle Corp. 68
  • 69. Domain Object Model Mapping • Tables map to Persistent Interfaces / Classes • Columns map to Persistent Properties – column names default to property name • Rows map to Persistent Instances • Annotations on Interfaces / Classes customize mappings • User chooses which to write: – User interface (ClusterJ then generates implementation class) – Persistent class (ClusterJ provides base implementation class) Copyright © 2012 Oracle Corp. 69
  • 70. ClusterJ – Generated Class @PersistenceCapable(table="tweets") public interface Tweets { String getId(); void setId(String id); String getAuthor(); void setAuthor(String value); Date getTime_stamp(); void setTime_stamp(Date value); String getTweet(); void setTweet(String value); } Copyright © 2012 Oracle Corp. 70
  • 71. ClusterJ – Dynamic Object public class Tweets extends DynamicObject { public String table() { return "tweets"; String getId() { return (String)get(0); } void setId(String value) { set(0, value); } ... // other fields and behavior } Copyright © 2012 Oracle Corp. 71
  • 72. Numeric Column Mapping • Java boolean, Boolean • Java long, Long – BIT(1) – BIT(1) to BIT(64) • Java byte, Byte – BIGINT – BIT(1) to BIT(8) – BIGUNSIGNED – TINYINT • Java float, Float • Java short, Short – FLOAT – BIT(1) to BIT(16) • Java double, Double – SMALLINT – DOUBLE – YEAR • Java BigDecimal • Java int, Integer – NUMERIC – BIT(1) to BIT(32) – DECIMAL – INT • Java BigInteger – NUMERIC – DECIMAL Copyright © 2012 Oracle Corp. 72
  • 73. Date Column Mapping • Java util Date – DATETIME – TIMESTAMP – TIME – DATE • Java sql Date – DATE • Java sql Time – TIME • Java sql Timestamp – DATETIME – TIMESTAMP Copyright © 2012 Oracle Corp. 73
  • 74. Variable Size Column Mapping • Java String – CHAR – VARCHAR – TEXT • Java byte[ ] – BINARY – VARBINARY – BLOB Copyright © 2012 Oracle Corp. 74
  • 75. ClusterJ Features • Character Set Translation (all MySQL charsets) • Automatic detection of primary keys, indexes • Compound Primary Keys • Ordered (btree) indexes • Unique (hash) indexes • Automatic use of partition key • Multi-threaded applications Copyright © 2012 Oracle Corp. 75
  • 76. ClusterJ Interfaces • SessionFactory – Instance per connection to cluster • Session – Instance per "user" • Transaction – Instance per Session • Query – Multiple instances per Session Copyright © 2012 Oracle Corp. 76
  • 77. ClusterJ User View Domain Object Domain Domain Object Domain Object Domain Object Domain Object Domain Domain Object Object Domain Object Domain Domain Object Object Object Domain Object Session and Transaction Session and Session and Transaction Transaction SessionFactory Configuration Properties Copyright © 2012 Oracle Corp. 77
  • 78. ClusterJ Limitations • No Relationships – primitive types only • No Multi-table inheritance – single table per persistent interface or class • No joins in queries – column comparisons and boolean operators • No Table creation – user needs to create tables and indexes • No Lazy Loading – entire record is loaded at one time, including LOBs Copyright © 2012 Oracle Corp. 78
  • 79. ClusterJ Requirements • Java 1.5 or 1.6 – Compile-time jar: • clusterj-api – Run-time jar: • clusterj – Java Native Library • ndbclient • MySQL Cluster 7.1 or higher – includes jars and native libraries as above Copyright © 2012 Oracle Corp. 79
  • 80. <Insert Picture Here> NDB Memcache API Overview 80
  • 81. Memcached Overview: Two levels of hashing memcached httpd hash key PHP/Perl ve r memcached ic k ser to find data ke y to p Memcache hash friends:12389 memcached memcache key 81 Copyright © 2011 Oracle Corp. 81
  • 82. Expected Latency & Throughput httpd c. t ions/se o f opera 10,000s nd trip u PHP/Perl ~2 00 µs ro memcached memcache mysql 1,000s of operatio ~ 2 ms ro ns/sec. MySQL und trip Slave 82 Copyright © 2011 Oracle Corp. 82
  • 83. Goals • Access stored data directly from memcache clients – Memcached perspective: • MySQL Cluster is a write-scalable, replicated data store – with reliable in-memory storage, – plus on-disk storage when data is too big for memory. – MySQL Cluster perspective: • memcache is a high performance API – providing easy access to in-memory data, – plus an extra layer of caching when data is on disk. 83 Copyright © 2011 Oracle Corp. 83
  • 84. Memcache Protocol & Commands see handout! 84 Copyright © 2011 Oracle Corp. 84
  • 85. Anatomy of a Memcache key user:1248 the prefix the database key 85 Copyright © 2011 Oracle Corp. 85
  • 86. A key-prefix mapping Memcache Cache key Cluster Container Policy prefix 86 Copyright © 2011 Oracle Corp. 86
  • 87. A memcache server role key Con- Cache Cluster prefix tainer Policy key Con- Cache Cluster prefix tainer Policy Server Role ID key Con- Cache Cluster prefix tainer Policy key Con- Cache Cluster prefix tainer Policy 87 Copyright © 2011 Oracle Corp. 87
  • 88. <Insert Picture Here> Mynode Preview Craig L Russell Architect, Oracle Corp. 88
  • 89. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 89 89
  • 90. Mynode: Node.js module for MySQL • Advance Planning – availability not announced • Domain Object Model DataMapper pattern – Domain objects are mapped to database tables • High Performance, Light Weight, Easy to Use Direct Connection – Asynchronous API – Insert, delete, find by key, update, simple query • Shared Data storage with: – MySQL server – Native C++ applications – Other Mynode, ClusterJ, memcached applications Copyright © 2012 Oracle Corp. 90
  • 91. Domain Object Model Mapping • Tables map to Persistent Classes • Columns map to Persistent Properties – column names default to property name • Rows map to Persistent Instances • Annotations customize mappings – column names – table names – null value handling Copyright © 2012 Oracle Corp. 91
  • 92. Mynode – Mapped Class function Tweets(author, tweet) { this.id = randomUUID(); this.author = author; this.tweet = tweet; this.time_stamp = new Date(); }; Copyright © 2012 Oracle Corp. 92
  • 93. Mynode – Insert var tweet = new Tweet('clr', 'having a great #oscon'); insertTweet(tweet, function()...); function insertTweet(tweet, callback) { session.insert('tweets', tweet, function(err) { if (err) throw … callback(); } }; Copyright © 2012 Oracle Corp. 93
  • 94. Mynode – Find by Primary Key function getTweet(id, callback) { session.find('tweets', id, function(err, tweet) { if (err) throw … callback(tweet); } }; Copyright © 2012 Oracle Corp. 94
  • 95. Mynode Features • Character Set Translation (all MySQL charsets) • Automatic detection of primary keys, indexes • Compound Primary Keys • Automatic use of partition key • Multi-threaded applications Copyright © 2012 Oracle Corp. 95
  • 96. Mynode Classes • Mynode – SessionFactory factory – Establishes connection to database • SessionFactory – Instance per connection to database • Session – Instance per "user" Copyright © 2012 Oracle Corp. 96
  • 97. Mynode User View Domain Object Domain Domain Object Domain Object Domain Object Domain Object Domain Domain Object Object Domain Object Domain Domain Object Object Object Domain Object Session and Transaction Session and Session and Transaction Transaction SessionFactory Configuration Properties Copyright © 2012 Oracle Corp. 97
  • 98. Mynode Requirements • JavaScript • Node.js – Run-time module: • mynode – Java Native Library • ndbclient • MySQL Cluster 7.2 or higher Copyright © 2012 Oracle Corp. 98
  • 99. One more thing before the break ... DB Node 2 DB DB Node 1 Node 3 Heartbeat messages DB Node 4 sent to next node in circle 99 99
  • 100. You want to shut down? MySQL Servers: mysqladmin -u root shutdown Management and Data Nodes: ndb_mgm> shutdown 100 100
  • 101. <Insert Picture Here> MySQL Cluster and NoSQL Mid-Session Break 101
  • 102. 3:30 - 5:00 P.M Agenda – SQL DDL Lecture – Restart your clusters <Insert Picture Here> – Labs – Java Insert – Time for Coding – Memcache Insert – Time for Coding – Java Query – Time for Coding – Wrap-up with Q&A 102 102
  • 103. <Insert Picture Here> Data Definition, SQL, and NDB Indexes 103 103
  • 104. Data Definition: Distribution Keys • Every table has a distribution key. The <Insert Picture Here> MD5 hash of the distribution key determines which fragment a row belongs to. • When an API node knows the distribution key of an interesting row, it can take advantage of this by choosing the primary fragment as TC. (ClusterJ, MySQL, and Memcached all do this automatically). 104 104
  • 105. Data Definition: Ordered Indexes • An ordered index is an in-memory T-Tree index • It is partitioned in exactly the same way as the main table. – i.e.: each data node has its own ordered index covering its own fragments of the table • This in-memory T-Tree contains direct pointers to the in-memory rows of the main table. • The index is not stored on disk between restarts; it is rebuilt during node startup. 105 105
  • 106. Data Definition: The SQL primary key • By default, MySQL Cluster does two things with the primary key of a table: – Uses it as the distribution key – Creates an ordered index named PRIMARY. • This means a table’s primary key can be used both for lookups and for scans • You can override the default behavior: – PARTITION BY HASH (col1, col2) to get a different distribution key – PRIMARY KEY USING HASH to skip building the ordered index 106 106
  • 107. Data Definition: Unique Indexes • A unique index is a secondary hash index. <Insert Picture • Used to enforce a unique constraint Here> • Used for lookups, but not scans • Implemented as a hidden table: – key: the unique index => – value: the primary key of the main table • Because it’s really an independent table, it has its own independent distribution across fragments. 107 107
  • 108. Data Definition: Indexes • Data rows can be stored either in-memory, or on disk (in a tablespace). • Data stored in memory is still durable, because the data nodes checkpoint it to disk • Indexes, however, are always in memory. Never on disk. • Therefore, a cluster must have enough memory for all its indexes. 108 108
  • 109. Data Definition: Tweets CREATE TABLE tweets ( id varchar(36) primary key, tweet varchar(140), time_stamp timestamp, author varchar(15), index(time_stamp), index(author)) ENGINE=ndb; 109 109
  • 110. Data Definition: Hashtags CREATE TABLE hashtags ( hashtag varchar(20), tweet_id varchar(36), time_stamp timestamp, author varchar(15), primary key(hashtag, tweet_id)) ENGINE=ndb; 110 110
  • 111. <Insert Picture Here> Restart clusters! ndb_mgmd --configdir=. ndbd -c <connectstring> ndb_mgm -c <connectstring> 111 111
  • 112. <Insert Picture Here> ClusterJ API Craig L Russell Architect, Oracle Corp. 112
  • 113. ClusterJ – Generated Class @PersistenceCapable(table="tweets") public interface Tweets { String getId(); void setId(String id); String getAuthor(); void setAuthor(String value); Date getTime_stamp(); void setTime_stamp(Date value); String getTweet(); void setTweet(String value); } Copyright © 2012 Oracle Corp. 113
  • 114. ClusterJ – Dynamic Object public class Tweets extends DynamicObject { public String table() { return "tweets"; String getId() { return (String)get(0); } void setId(String value) { set(0, value); } ... // other fields and behavior } Copyright © 2012 Oracle Corp. 114
  • 115. Numeric Column Mapping • Java boolean, Boolean • Java long, Long – BIT(1) – BIT(1) to BIT(64) • Java byte, Byte – BIGINT – BIT(1) to BIT(8) – BIGUNSIGNED – TINYINT • Java float, Float • Java short, Short – FLOAT – BIT(1) to BIT(16) • Java double, Double – SMALLINT – DOUBLE – YEAR • Java BigDecimal • Java int, Integer – NUMERIC – BIT(1) to BIT(32) – DECIMAL – INT • Java BigInteger – NUMERIC – DECIMAL Copyright © 2012 Oracle Corp. 115
  • 116. Date Column Mapping • Java util Date – DATETIME – TIMESTAMP – TIME – DATE • Java sql Date – DATE • Java sql Time – TIME • Java sql Timestamp – DATETIME – TIMESTAMP Copyright © 2012 Oracle Corp. 116
  • 117. Variable Size Column Mapping • Java String – CHAR – VARCHAR – TEXT • Java byte[ ] – BINARY – VARBINARY – BLOB Copyright © 2012 Oracle Corp. 117
  • 118. ClusterJ Interfaces • SessionFactory – Instance per connection to cluster • Session – Instance per "user" • Transaction – Instance per Session • Query – Multiple instances per Session Copyright © 2012 Oracle Corp. 118
  • 119. ClusterJ User View Domain Object Domain Domain Object Domain Object Domain Object Domain Object Domain Domain Object Object Domain Object Domain Domain Object Object Object Domain Object Session and Transaction Session and Session and Transaction Transaction SessionFactory Configuration Properties Copyright © 2012 Oracle Corp. 119
  • 120. SessionFactory • Configured by properties – com.mysql.clusterj.connectstring (the only really important property) – com.mysql.clusterj.connect.retries – com.mysql.clusterj.connect.delay – com.mysql.clusterj.connect.timeout.before – com.mysql.clusterj.connect.timeout.after – com.mysql.clusterj.max.transactions • One SessionFactory per cluster per JVM – Connection poooling (multiple TCP connections per SessionFactory) Copyright © 2012 Oracle Corp. 120
  • 121. Example SessionFactory sessionFactory; Properties props = new Properties(); void initProps() { props.put(PROPERTY_CLUSTER_CONNECTSTRING, "localhost:1186"); props.put(PROPERTY_CLUSTER_DATABASE, "personnel"); } public init(Properties props) { initProps(); sessionFactory = ClusterJHelper .getSessionFactory(props); } Copyright © 2012 Oracle Corp. 121
  • 122. Session • Persistent Instance Factory • Lifecycle Management – persist() // record must not already exist – remove() // record must already exist • Update Management – update() // no need to read first – write() // record will be overwritten if already exists • Find by ID • Query Factory Copyright © 2012 Oracle Corp. 122
  • 123. Example Insert Session session; void getSession() { session = sessionFactory.getSession(); } Tweets createTweet(String author, String message) { Tweets tweet = session.newInstance(Tweets.class); tweet.setId(UUID.randomUUID().toString(); tweet.setAuthor(author); tweet.setTweet(message); tweet.setTime_stamp(new Date()); session.persist(tweet); return tweet; } Copyright © 2012 Oracle Corp. 123
  • 124. Example Find Tweets findTweet(String id) { Tweets tweet = session.find(Tweets.class, id); return tweet; } Copyright © 2012 Oracle Corp. 124
  • 125. Transaction • Optionally used to delimit transactions – begin() – commit() – rollback() • Optionally mark a transaction for rollback – setRollbackOnly() – getRollbackOnly() • If not used, every operation is in its own transaction Copyright © 2012 Oracle Corp. 125
  • 126. Example Transaction transaction; void getTransaction() { transaction = session.getTransaction(); } void createTweets() { getTransaction(); transaction.begin(); createTweet("amos", "#oscon rocks"); createTweet("barb", "sw33t tutorial"); createTweet("chuck", "lets #partay"); createTweet("dave", "just one mo hour"); transaction.commit(); } Copyright © 2012 Oracle Corp. 126
  • 127. ClusterJ Exercises • Create schema for tweets, hashtags – create.sql in labs/schema • Write domain models for Tweets, Hashtags – skeletons in labs/model • Write Insert.java program – skeleton in labs/test/Insert.java • Compile-time jar: clusterj-api-7.2.6.jar • Run-time jar: clusterj-7.2.6.jar • Java Native Library: ndbclient Copyright © 2012 Oracle Corp. 127
  • 128. ClusterJ Exercises • Create schema for tweets, hashtags – create.sql in labs/schema • Write domain models for Tweets, Hashtags – skeletons in labs/model • Write Insert.java program – skeleton in labs/test/Insert.java • Compile-time jar: clusterj-api-7.2.6.jar • Run-time jar: clusterj-7.2.6.jar • Java Native Library: ndbclient Copyright © 2012 Oracle Corp. 128
  • 130. A key-prefix mapping Memcache Cache key Cluster Container Policy prefix 130 Copyright © 2011 Oracle Corp. 130
  • 131. Memcache Config • Generate a containers record for the tweets table • value columns in the containers record are separated by commas • Generate a key-prefix mapping for role 0 • Start a memcached server cd run-cluster/ndb ./start-memcached.sh 131 Copyright © 2011 Oracle Corp. 131
  • 132. Start Memcached $ memcached -E /usr/local/mysql/lib/ndb_engine.so -e connectstring="localhost:1186" 15-Jul-2012 23:51:46 PDT NDB Memcache 5.5.22-ndb-7.2.6 started [NDB 7.2.6; MySQL 5.5.22] Contacting primary management server (localhost:1186) ... Connected to "localhost:1186" as node id 4. Retrieved 4 key prefixes for server role "default_role". The default behavior is that: GET uses NDB only SET uses NDB only DELETE uses NDB only. The 3 explicitly defined key prefixes are "b:" (demo_table_large), "mc:" () and "t:" (demo_table_tabs) Server started with 4 threads. Priming the pump ... Connected to "localhost:1186" as node id 5. Scheduler: using 2 connections to cluster 0 Scheduler: starting for 1 cluster; c0,f0,g1,t1 done [0.656 sec]. 132 Copyright © 2011 Oracle Corp. 132
  • 133. Memcache Exercises • In perl/labs/ • 1. config.sql: create metadata for app. • 2. tweets.pl: insert tweets using memcached • 3. counter.sql: revise app to count tweets per user 133 Copyright © 2011 Oracle Corp. 133
  • 134. Memcache tips • perldoc Cache::Memcached • The file in labs/ already connects to a server for you. • In an actual Memcache command, the 3 fields of the value should be separated by tab characters (“t”) 134 Copyright © 2011 Oracle Corp. 134
  • 135. <Insert Picture Here> ClusterJ Query Craig L Russell Architect, Oracle Corp. 135
  • 136. ClusterJ Query • Builder pattern • Similar to JPA criteria query • Predicates compare column values to parameters: – equal, lessEqual, greaterEqual, lessThan, greaterThan, between, in – comparison with null • Combine predicates using binary and unary operators: – or, and, not • Execution is optimized to use indexes – primary or unique key lookup – ordered scan for complete or partial keys – table scan if no index can be used Copyright © 2012 Oracle Corp. 136
  • 137. ClusterJ Query Interfaces • Query – the "executable" part – Parameters and limits are bound to this instance • QueryBuilder – used to build queries • QueryDomainType – represents the user's domain type for queries • PredicateOperand – represents either a query parameter or a query property • Predicate – represents a comparison between a property and a parameter – can be combined using "and", "or", and "not" operators Copyright © 2012 Oracle Corp. 137
  • 138. ClusterJ Query Optimizer • Optimizer looks for indexes • PRIMARY key all columns equal • PRIMARY key leading columns equal • Unique (hash) key equal • Ordered (btree) key equal, greater, less • Table scan if no indexes are usable • All terms used for filter • After parameters are bound, ask for query plan: – Query.explain() – Keys: Query.SCAN_TYPE, Query.INDEX_USED Copyright © 2012 Oracle Corp. 138
  • 139. Query Example QueryDomainType<Tweets> qdtTweets = builder.createQueryDefinition(Tweets.class) ; Predicate eqAuthor = qdtTweets.get("author") .eq(qemp.param("pauthor")); Predicate gtTime_stamp = qdtTweets.get("time_stamp") .greaterEqual(qemp.param("ptime_stamp")); qdtTweets.where(eqAuthor.and(gtTime_stamp)); Query query = session.createQuery(qdtTweets) ; query.setParameter("pauthor", getAuthor()); query.setParameter("ptime_stamp", getTime()); List<Tweets> results = query.getResultList() ; Copyright © 2012 Oracle Corp. 139
  • 140. ClusterJ Query Exercises • Write Find.java program – Skeleton in labs/test/Find.java – Query by author – Query by hashtag – Query by date range – Query by combining above criteria Copyright © 2012 Oracle Corp. 140
  • 141. ClusterJ Query Extra Credit • Write Delete.java program – skeleton in labs/test/Delete.java – Delete by author – Delete by hashtag – Delete by date range – Delete by combining above criteria Copyright © 2012 Oracle Corp. 141
  • 142. <Insert Picture Here> Final Questions & Answers 142