Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Data Partitioning"

Line 16: Line 16:
  
  
 +
With data partitioning, you can subdivide a database table, index or index-organized table into smaller units. That makes it possible to manage and access those objects at a finer level of granularity, thereby improving manageability, performance, and availability. For example, data partitioning facilitates load-balancing and replicating data across multiple different databases or across a database cluster.
  
 
+
You configure data partitioning using partitioning policies. The different kinds of policies are:
The different kinds of policies are:
+
  
 
* RoundRobinPolicy - Cycles through a list of connection pools to distribute the load evenly. There is an option to load balance read queries only and an option to replicate write queries.
 
* RoundRobinPolicy - Cycles through a list of connection pools to distribute the load evenly. There is an option to load balance read queries only and an option to replicate write queries.

Revision as of 16:31, 25 January 2011

EclipseLink JPA


Data Partitioning

This section is in progress...


With data partitioning, you can subdivide a database table, index or index-organized table into smaller units. That makes it possible to manage and access those objects at a finer level of granularity, thereby improving manageability, performance, and availability. For example, data partitioning facilitates load-balancing and replicating data across multiple different databases or across a database cluster.

You configure data partitioning using partitioning policies. The different kinds of policies are:

  • RoundRobinPolicy - Cycles through a list of connection pools to distribute the load evenly. There is an option to load balance read queries only and an option to replicate write queries.
  • RangePartitionPolicy - Maps a query parameter name to a node, based on its value and a set of ranges. If the query does not define the parameter, the policy either uses the session default behavior or, based on the XXXXXXX option setting, sends the query to all pools and unions the result.
  • ValuePartitionPolicy - Behaves the same as the range policy, but maps value to a pool instead of a range. It also defines a default pool to use for any unmapped values.
  • HashPartitionPolicy - Hashes the parameter value into a list of connection pools.
  • ReplicationPolicy - Sends write queries to a set of connection pools.
  • UnionPartitionPolicy - Sends read queries to a set of connection pools and has an option to replicate wrties.


Configuration Files

orm.xml

<partitioning-policy class="org.acme.MyPolicy"/>
<round-robin-policy replicate-writes="true">
  <connection-pool>node1</connection-pool>
  <connection-pool>node2</connection-pool>
</round-robin-policy>
<random-policy replicate-writes="true">
  <connection-pool>node1</connection-pool>
  <connection-pool>node2</connection-pool>
</random-policy>
<replication-policy>
  <connection-pool>node1</connection-pool>
  <connection-pool>node2</connection-pool>
</replication-policy>
<range-partitioning-policy parameter-name="id" exclusive-connection="true" union-unpartitionable-queries="true">
  <range-partition connection-pool="node1" start-value="0" end-value="100000" value-type="java.lang.Integer"/>
  <range-partition connection-pool="node2" start-value="100001" end-value="200000" value-type="java.lang.Integer"/>
  <range-partition connection-pool="node3" start-value="200001" value-type="java.lang.Integer"/>
</range-partitioning-policy>

persistence.xml

 

Examples

@Entity
@IdClass(EmployeePK.class)
@UnionPartitioning(
        name="UnionPartitioningAllNodes",
        replicateWrites=true)
@ValuePartitioning(
        name="ValuePartitioningByLOCATION",
        partitionColumn=@Column(name="LOCATION"),
        unionUnpartitionableQueries=true,
        defaultConnectionPool="default",
        partitions={
            @ValuePartition(connectionPool="node2", value="Ottawa"),
            @ValuePartition(connectionPool="node3", value="Toronto")
        })
@Partitioned("ValuePartitioningByLOCATION")
public class Employee {
    @Id
    @Column(name = "EMP_ID")
    private Integer id;
 
    @Id
    private String location;
    ...
 
    @ManyToMany(cascade = { PERSIST, MERGE })
    @Partitioned("UnionPartitioningAllNodes")
    private Collection<Project> projects;
    ...
}
@Entity
@RangePartitioning(
        name="RangePartitioningByPROJ_ID",
        partitionColumn=@Column(name="PROJ_ID"),
        partitionValueType=Integer.class,
        unionUnpartitionableQueries=true,
        partitions={
            @RangePartition(connectionPool="default", startValue="0", endValue="1000"),
            @RangePartition(connectionPool="node2", startValue="1000", endValue="2000"),
            @RangePartition(connectionPool="node3", startValue="2000")
        })
@Partitioned("RangePartitioningByPROJ_ID")
public class Project {
    @Id
    @Column(name="PROJ_ID")
    private Integer id;
    ...
}

Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...

Back to the top