20140518 jjug mysql clsuter as nosql

Download 20140518 JJUG MySQL Clsuter as NoSQL

If you can't read please download the document

Upload: ryusuke-kajiyama

Post on 08-May-2015

1.313 views

Category:

Data & Analytics


0 download

DESCRIPTION

(in Japanese)2014年5月18日のJJUG CCCにて「R2-3 Cluster/J で MySQL Cluster をトランザクション対応 NoSQL として使う」で利用したプレゼンテーションです。

TRANSCRIPT

  • 1.Copyright 2014, Oracle and/or its affiliates. All rights reserved.1 Using MySQL Cluster as NoSQL with Java Ryusuke Kajiyama MySQL Sales Consulting Manager

2. Copyright 2014, Oracle and/or its affiliates. All rights reserved.2 ORACLE DRIVES MySQL INNOVATION DELIVERING MORE AND BETTER PRODUCTS FASTER 3. Copyright 2014, Oracle and/or its affiliates. All rights reserved.3 MySQL Enterprise Monitor 2.2 MySQL Cluster 7.1 MySQL Cluster Manager 1.0 MySQL Workbench 5.2 MySQL Database 5.5 MySQL Enterprise Backup 3.5 MySQL Enterprise Monitor 2.3 MySQL Cluster Manager 1.1 MySQL Enterprise Backup 3.7 All GA! Oracle VM Template for MySQL Oracle Products Certifications MySQL Windows Installer MySQL Enterprise Security MySQL Enterprise Scalability MySQL Cluster 7.2 MySQL Cluster Manager 1.3 MySQL Utilities 1.0.6 MySQL Workbench 6.0 All GA! MySQL Enterprise Backup 3.10 MySQL Enterprise Audit MySQL Windows Tools MySQL Database 5.6 MySQL Cluster 7.3 MySQL Workbench 6.1 MySQL Fabric 1.4 RC MySQL Database 5.7 DMR *Development Milestone Release All GA! Available Now! MySQL: 2010 - 2014 4. Copyright 2014, Oracle and/or its affiliates. All rights reserved.4 Oracle Database and MySQL Complementary on the Web and in The Cloud Web and Cloud computing is not a one size fits all model Together Servicing Broader User Needs MySQL Well Suited for Web-based & Custom Departmental apps Users can Benefit by Running MySQL and Oracle Together For both on-premise and Cloud computing 5. Copyright 2014, Oracle and/or its affiliates. All rights reserved.5 MySQL Web NoSQL (HTTP, JSON, JavaScript ) InnoDB // InnoDB ()GIS () 6. Copyright 2014, Oracle and/or its affiliates. All rights reserved.6 MySQL Cluster 7. Copyright 2014, Oracle and/or its affiliates. All rights reserved.7 MySQL MySQL Cluster MySQL Cluster / AP MySQL Cluster MySQL Server MySQL+DRBD Linux / AP MySQL Server / AP HA MySQL Server MySQL Server / AP & MySQL Server MySQL Server 8. Copyright 2014, Oracle and/or its affiliates. All rights reserved.8 Whos Using MySQL Cluster? 9. Copyright 2014, Oracle and/or its affiliates. All rights reserved.9 MySQL Cluster Active-Active RDBMS & NoSQL MySQL Cluster Data Nodes Data Layer Clients Management Nodes Management Nodes Application Layer 10. Copyright 2014, Oracle and/or its affiliates. All rights reserved.10 AZ(availability zones) & Geographic Replication 11. Copyright 2014, Oracle and/or its affiliates. All rights reserved.11 SQL & NoSQL ACID MySQL Cluster Data Nodes Data Layer Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps JPA Cluster JPA PHP Perl Python Ruby JDBC Cluster J JS Apache Memcache d MySQL JNI Node.JS mod_ndb ndb_eng NDB API (C++) 12. Copyright 2014, Oracle and/or its affiliates. All rights reserved.12 12UPDATE 30 x Intel E5-2600 NoSQL C++ API, flexaSynch benchmark ACID 0 5 10 15 20 25 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 MillionsofUPDATEsperSecond MySQL Cluster Data Nodes 13. Copyright 2014, Oracle and/or its affiliates. All rights reserved.13 RDBMS? NoSQL RDBMS JOIN ACID SQL/Joins ACID 14. Copyright 2014, Oracle and/or its affiliates. All rights reserved.14 Cluster & Memcached key value key value Key Value town:maidenhead SL6 generic table Application view SQL view 15. Copyright 2014, Oracle and/or its affiliates. All rights reserved.15 Cluster & Memcached prefix key value key value Prefix Table Key-col Val-col policy town: address town code cluster Config tables town ... code ... maidenhead ... SL6 ... address Table Application view SQL view 16. Copyright 2014, Oracle and/or its affiliates. All rights reserved.16 MySQL MySQL 5.6 Oracle VM Template Solaris Cluster Windows Cluster DRBD MySQL Cluster Semi-Sync OS All Linux Solaris Windows Linux All Master + Slaves Active/ Passive Active/ Passive Active/ Passive Active/ Passive Multi- Master 99.9% 99.99% 99.99% 99.95% 99.99% 99.999% 17. Copyright 2014, Oracle and/or its affiliates. All rights reserved.17 Connector/J JDBC Driver of MySQL 18. Copyright 2014, Oracle and/or its affiliates. All rights reserved.18 GA http://www.mysql.com/downloads/connector/j/ tar.gz zip JARCLASSPATH export set CLASSPATH=/opt/java/mysql-connector-java-5.1.18-bin.jar:$CLASSPATH 19. Copyright 2014, Oracle and/or its affiliates. All rights reserved.21 / jdbc:mysql://primary,failover - 3.0.2 (2002!!) jdbc:mysql:replication:// - 3.1.11 (2005) jdbc:mysql:loadbalance:// - 5.0.5 (2007) 20. Copyright 2014, Oracle and/or its affiliates. All rights reserved.22 / jdbc:mysql://primary,failover-1,failover-2... jdbc:mysql:replication:// jdbc:mysql:loadbalance:// MySQL Cluster(NDB) 21. Copyright 2014, Oracle and/or its affiliates. All rights reserved.23 JMX loadBalanceConnectionGroup= JMX loadBalanceEnableJMX=true com.mysql.jdbc.ConnectionGroupManager (gracefully or forcefully) : https://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee- concepts-managing-load-balanced-connections.html 22. Copyright 2014, Oracle and/or its affiliates. All rights reserved.24 / Exception SQLState 08 SQLState Class LoadBalanceExceptionChecker 23. Copyright 2014, Oracle and/or its affiliates. All rights reserved.25 StandardLoadBalanceExceptionChecker loadBalanceSQLStateFailover SQLState 08 08000 08S01 loadBalanceSQLExceptionSubclassFailover SQLExceptionFCQN Class.isInstance(Exception) 24. Copyright 2014, Oracle and/or its affiliates. All rights reserved.26 Custom Exception Checker LoadBalanceExceptionChecker shouldExceptionTriggerFailover(SQLException ex) NDBLoadBalanceExceptionChecker public class NdbLoadBalanceExceptionChecker extends StandardLoadBalanceExceptionChecker { public boolean shouldExceptionTriggerFailover(SQLException ex) { return super.shouldExceptionTriggerFailover(ex) || checkNdbException(ex); } private boolean checkNdbException(SQLException ex) { // Have to parse the message since most NDB errors are mapped to the same DEMC, sadly. return (ex.getMessage().startsWith("Lock wait timeout exceeded") || (ex.getMessage().startsWith("Got temporary error") && ex.getMessage().endsWith("from NDB"))); } } 25. Copyright 2014, Oracle and/or its affiliates. All rights reserved.27 ClusterJ & ClusterJPA 26. Copyright 2014, Oracle and/or its affiliates. All rights reserved.28 MySQL Cluster : ClusterJ/JPA API (ClusterJ) : Java API ClusterJJPA JPA OpenJPA ClusterJ JDBC JDBC Java WebMySQL Cluster MySQL Cluster Data Nodes Data Layer Apps Apps Apps Apps JPA Cluster JPA JDBC Cluster J MySQL JNI NDB API (C++) 27. Copyright 2014, Oracle and/or its affiliates. All rights reserved.29 ClusterJ Hibernate / JPA / JDO Domain Object Model DataMapper ndbjtie JNI MySQL Cluster API (NDB API)Java JOIN 28. Copyright 2014, Oracle and/or its affiliates. All rights reserved.30 ClusterJNoSQL (String CLOB) (byte[ ] BLOB) JSON, XML, etc. key = ID value = REST pluginnode.js API 29. Copyright 2014, Oracle and/or its affiliates. All rights reserved.31 Domain Object Model Mapping : (ClusterJ) (ClusterJ) 30. Copyright 2014, Oracle and/or its affiliates. All rights reserved.32 ClusterJ @PersistenceCapable(table="employee") public interface Employee { long getId(); void setId(int id); @Column(name="full_name") String getName(); void setName(String value); int getSalary(); void setSalary(int value); Integer getAge(); void setAge(Integer value); } 31. Copyright 2014, Oracle and/or its affiliates. All rights reserved.33 ClusterJ public class Employee extends DynamicObject { public String table() { return "employee"; long getId() { return (Long)get(0); } void setId(long value) { set(0, value); } ... // other fields and behavior } 32. Copyright 2014, Oracle and/or its affiliates. All rights reserved.34 ClusterJ API SessionFactory MySQL Cluster Session () Transaction Query 33. Copyright 2014, Oracle and/or its affiliates. All rights reserved.35 ClusterJ Example Session session; void getSession() { session = sessionFactory.getSession(); } Employee createEmployee(long id, String name, int salary, int age) { Employee employee = session.newInstance(Employee.class); employee.setId(id); employee.setName(name); employee.setSalary(salary); employee.setAge(age); session.persist(employee); return employee; } 34. Copyright 2014, Oracle and/or its affiliates. All rights reserved.36 Cluster Example Employee findEmployee(long id) { Employee employee = session.find(Employee.class, id); return employee; } void updateSalary(long id, int salary) { Employee employee = findEmployee(id); employee.setSalary(salary); session.updatePersistent(employee); } 35. Copyright 2014, Oracle and/or its affiliates. All rights reserved.37 ClusterJ Query Builder JPACriteria API : equal, lessEqual, greaterEqual, lessThan, greaterThan, in, between null : OR, AND, NOT (limit) 36. Copyright 2014, Oracle and/or its affiliates. All rights reserved.38 ClusterJ Query Example QueryDomainType qemp = builder.createQueryDefinition(Employee.class) ; Predicate geAge = qemp.get("age") .greaterEqual(qemp.param("ageFloor")); Predicate leSalary = qemp.get("salary") .lessEqual(qemp.param("salaryCap")); qemp.where(geAge.and(leSalary)); Query query = session.createQuery(qemp) ; query.setOrdering(Query.DESCENDING, "age"); query.setParameter("ageFloor",33); query.setParameter("salaryCap", 44000); List results = query.getResultList() ; 37. Copyright 2014, Oracle and/or its affiliates. All rights reserved.39 ClusterJ begin() commit() rollback() setRollbackOnly() getRollbackOnly() 38. Copyright 2014, Oracle and/or its affiliates. All rights reserved.40 ClusterJPA OpenJPA openjpa-1.2.0.jarConnector/J http://dev.mysql.com/doc/ndbapi/en/mccj-using-jpa.html ClusterJ JOINJDBC SQLNDB API 11 39. Copyright 2014, Oracle and/or its affiliates. All rights reserved.41 SQL and NoSQL Best of both world with ACID Transactions MySQL Cluster Data Nodes Data Layer Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps JPA Cluster JPA PHP Perl Python Ruby JDBC Cluster J JS Apache Memcache d MySQL JNI Node.JS mod_ndb ndb_eng NDB API (C++) 40. Copyright 2014, Oracle and/or its affiliates. All rights reserved.42 5.6 MySQL Server GA InnoDB& & NoSQL MySQL Cluster - GA MySQL 5.6 Node.jp API 7.3 5.7 MySQL Server DMR & NoSQL 41. Copyright 2014, Oracle and/or its affiliates. All rights reserved.43 The world's most popular open source database