Вы находитесь на странице: 1из 28

Oracle Sharding Technical Deep Dive

Oracle 12.2. Sharding

Umesh Tanna
Principal Sales Consultant
Sales Consulting Centers(SCC)

Copyright 2015, Oracle and/or its affiliates. All rights reserved. |


Safe Harbor Statement
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 Oracles products remains at the sole discretion of Oracle.

Copyright 2015, Oracle and/or its affiliates. All rights reserved. |


About Me and SCC

Education : BE (Computer Engineering, 1990)


1990-1998 : India (Government, Manufacturing (Tata, MIS setup), HP)
Development, Back end programming, Foxbase/Oracle/Forms/Reports/SQL/C/Shell/Unix

1999-2002 : US (Financial Clients in NY as DBA)


Step in to Oracle Database Administration, International experience

2003-2013 : India, GE DBA & Architect, Infosys - (E-business suite)


Onsite/Offshore experience, 360 exposure of IT service company, + Apps DBA, Service Presales

Since 2014 : Oracle Presales (SCC Sales Consulting Centers)


Focus : Cloud(IaaS), Exadata, ZDLRA, Database & options
Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 4
Program Agenda

1 Introduction to Oracle Sharding


2 Concepts
3 Architecture & Capabilities
4 Summary

Copyright 2015, Oracle and/or its affiliates. All rights reserved. |


Oracle Sharding
Massive Scalability & Total Fault Isolation
A single logical DB sharded into N physical Databases
Horizontal partitioning of data across
independent databases (shards) Server A Server B Server N
Each shard has its own CPU, memory, flash & disk
Holds a portion of rows from partitioned tables
Replicated for high availability
A B E F
Linear scalability - data, workload and users
C D G H
Maximum fault isolation
Partitions Partitions Partitions
Single outage affects only 1 of N shards
Mixed database releases across shards Shard01: Shard02: Shardnn:
Table 1 Table 1 Table 1

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 6


Sharded Applications - Suitability
Custom OLTP Applications
Characteristics
Massive Scalability and HA
Large billing systems Applications must specify a sharding key
for optimal performance
Airline ticketing systems
e.g. customer_id, account_id etc
Online financial services
Primary usage pattern
Media companies Single-shard operations based on sharding
Online information services key 80% of transactions

Social media companies Ancillary usage pattern


Multi-shard queries for reporting 20% or
less of workload

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 7


Use Cases for Oracle Sharding vs. Traditional Approach
Extreme scaling of web-scale OLTP databases
Primarily performing single-shard operations
Fault Isolation
Failure of one Shard does not take down the entire service
Geo-Data Distribution
Bring data close to consumers to reduce latency
Need to satisfy regulatory requirement for storing user data in the country of citizenship

Low-cost hardware
No shared storage

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 8


Oracle Sharding
A complete platform for a Sharded Database (SDB)
Auto deployment includes replication configuration
Application
Data Guard with auto failover Server
Active/Active GoldenGate
Geo-distribution, on-premises, public or hybrid cloud
Auto partitioning via consistent-hash, range, list or Shard Directors Shard Catalog
composite methods
Centralized schema maintenance and refresh of
reference data
Data-dependent routing for single-shard and cross-
shard queries
..
Elastic scaling & auto rebalancing
Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 9
Sharded Database Physical Architecture
Region1 Shard Directors Shard Catalog
Client

Application ..
Server

Data Guard & Fast-Start Failover


Region2

..

Shard Directors Shard Catalog


Data Guard copies
Data Guard copy

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 10


DDL for Sharded Database Deployment
create shardcatalog -database <shardcat host>:1521:shardcat -user sdb_admin/passwd_sdb_admin -region
region1, region2 -shardspace cust_shardspace chunks 36
add gsm -gsm gsm1 -listener 1571 -pwd passwd_gsmcatuser -catalog <shardcat host>:1521:shardcat -region
region1

add shardgroup -shardgroup shgrp1 -deploy_as primary -region region1


add shardgroup -shardgroup shgrp2 -deploy_as standby -region region2

create shard -shardgroup shgrp1 -destination <host1> -credential oracle_cred


create shard -shardgroup shgrp2 -destination <host2> -credential oracle_cred

deploy
add service -service oltp_rw_srvc -role primary

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 11


High Availability for Individual Shards
Data Guard Replication or GoldenGate

GoldenGate chunk-level active-active replication


with Auto Conflict Detection/Resolution*
Data Guard with Fast-Start Failover - Default *

Partition_A

Partition_F Partition_F Partition_C


*Automated deployment
Optionally complement replication with Oracle RAC for server HA
Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 12
Sharded Schema
Customers Orders Line Items Sharded

Products

Duplicated

13
Copyright 2015, Oracle and/or its affiliates. All rights reserved. |
Sharded Table Family Enhanced SQL DDL
CREATE TABLESPACE SET tsp_set_1 ; CREATE SHARDED TABLE Orders (
OrderId INTEGER,
CREATE SHARDED TABLE Customers CustId VARCHAR2(60),
( CustId VARCHAR2(60) NOT NULL, OrderDate TIMESTAMP,
FirstName VARCHAR2(60),
LastName VARCHAR2(60), CONSTRAINT pk_orders
PRIMARY KEY (CustId, OrderId),
CustProfile CLOB, CONSTRAINT fk_orders_parent
CONSTRAINT pk_customers FOREIGN KEY (CustId) REFERENCES
PRIMARY KEY(CustId), Customers(CustId)
CONSTRAINT cons_json )
CHECK (CustProfile IS JSON) PARTITION BY REFERENCE (fk_orders_parent) ;
)
PARTITION BY CONSISTENT HASH (CustId) CREATE DUPLICATED TABLE Products (
PARTITIONS AUTO ProductId INTEGER PRIMARY KEY,
TABLESPACE SET tsp_set_1 ; Name VARCHAR2(128),
LastPrice NUMBER(19,4),

)
TABLESPACE products_tsp ;

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 14


Centralized Schema Management
Shard
Catalog
Master
Shard Director

connect to GDS$CATALOG service


alter session enable shard ddl;
create tablespace set
create sharded table
..
Shard 1 Shard 2 Shard n
Create duplicated table
15
Copyright 2015, Oracle and/or its affiliates. All rights reserved. |
Chunk

Chunk #1
Sharded Tables Customers_P1 (1-1000000) Orders_P1 Lineitems_P1

Group of tablespaces of related partitions of a sharded table family


Ex: Chunk#1 contains Customers_P1, Orders_P1, LineItems_P1
All data pertinent to a sharding key resides in a given chunk
No need to go to multiple shards
Unit of data movement for resharding

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 16


Contents of a Shard

Chunk #1
Sharded Tables Customers_P1 (1-1M) Orders_P1 Lineitems_P1

Chunk #6
Sharded Tables Customers_P6 (5000001-6M) Orders_P6 Lineitems_P6

Products (Duplicated Table)

17
Copyright 2015, Oracle and/or its affiliates. All rights reserved. |
Sharding Methods

Copyright 2015, Oracle and/or its affiliates. All rights reserved. |


System Managed Sharding
Based on partitioning by CONSISTENT HASH
Data is sharded / re-sharded automatically
Data is evenly distributed across shards
All shards are managed and replicated as unit
Many relatively small equally sized chunks

+ Automatic balanced data distribution


- User has no control on location of data

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 19


System Managed Sharding - Example

CREATE TABLESPACE SET tbs1;


Shard1 Shard2
CREATE SHARDED TABLE customers
( CustId VARCHAR2(60) NOT NULL, P_1 P_121
Tablespace tbs1 Tablespace tbs121
Class VARCHAR2(10), . .
Geo VARCHAR2(8),
P_120 P_240
CONSTRAINT cust_pk PRIMARY KEY(CustId)
) PARTITION BY CONSISTENT HASH (CustId) Tablespace tbs120 Tablespace tbs240
PARTITIONS AUTO
TABLESPACE SET tbs1;

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 20


Consistent Hash

1 2 5 6 9 10 13 14 17 18

3 4 7 8 11 12 15 16 19 20
Chunks Chunks Chunks Chunks Chunks

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 21


Data-dependent Routing (DDR)

Copyright 2015, Oracle and/or its affiliates. All rights reserved. |


Routing in Oracle Sharded Environments
Two Modes

Single-Shard Mode: Session-based Routing


All transactions go to a single shard (e.g. a single customer_id)
Enhancements to Mid-tier connection pools and drivers
JDBC/UCP, OCI, and ODP.NET to recognize sharding keys
PHP, Python, Perl, and Node.js will leverage OCI support for sharding

Cross-Shard Mode
Applies to reporting queries
Transactions performed in parallel across shards (e.g. aggregates on sales data)

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 23


Session-Based Routing via Shard Key
Shard keys are provided by the App Tier
applications at connection checkout Application
Server
The client specifies the sharding key
(e.g., customer_id) Routing Tier
The Shard Director looks up the key and
redirects client to shard DB containing Shard
the data Directors

The client executes SQL directly at shard


Data Tier

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 24


Non-Shard Key Access & Cross-Shard Queries
App Tier
If no sharding key, then the connection
Application
is made to the coordinator database Server
Coordinator parses SQL and will
proxy/route request to correct shard Routing Tier
Same flow for cross-shard queries
Coordinator acts as SQL proxy/router Shard Coordinator
Directors DB
Supports shard pruning and scatter-gather

For developer convenience and not for


Data Tier
high performance

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 25


Q&A
Umesh.tanna@oracle.com

Copyright 2015, Oracle and/or its affiliates. All rights reserved. | 26


Copyright 2015, Oracle and/or its affiliates. All rights reserved. |

Вам также может понравиться