1Data::ObjectDriver::DriUvseerr::CPoanrttriitbiuotneD(da3tpPame:)r:lObDjoeccutmDernitvaetri:o:nDriver::Partition(3pm)
2
3
4
6 Data::ObjectDriver::Driver::Partition - base class for partitioned
7 object drivers
8
10 package SomeObject;
11
12 __PACKAGE__->install_properties({
13 ...
14 primary_key => 'id',
15 driver => Data::ObjectDriver::Driver::Partition->new(get_driver => \&find_partition),
16 });
17
18 # Say we have a list of 5 arrayrefs of the DBI driver information.
19 my @DBI_INFO;
20
21 sub find_partition {
22 my ($part_key, $args) = @_;
23
24 my $id;
25
26 if (ref $terms && ref $terms eq 'HASH') {
27 # This is a search($terms, $args) call.
28 my $terms = $part_key;
29 $id = $terms->{id}
30 or croak "Can't determine partition from a search() with no id field";
31 }
32 else {
33 # This is a lookup($id) or some method invoked on an object where we know the ID.
34 my $id = $part_key;
35 }
36
37 # "ID modulo N" is not a good partitioning strategy, but serves as an example.
38 my $partition = $id % 5;
39 return Data::ObjectDriver::Driver::DBI->new( @{ $DBI_INFO[$partition] } );
40 }
41
43 Data::ObjectDriver::Driver::Partition provides the basic structure for
44 partitioning objects into different databases. Using partitions, you
45 can horizontally scale your application by using different database
46 servers to hold sets of data.
47
48 To partition data, you need a certain criteria to determine which
49 partition data goes in. Partition drivers use a "get_driver" function
50 to find the database driver for the correct partition, given either the
51 arguments to a "search()" or the object's primary key for a "lookup()",
52 "update()", etc where the key is known.
53
55 While you can use any stable, predictable method of selecting the
56 partition for an object, the most flexible way is to keep an
57 unpartitioned table that maps object keys to their partitions. You can
58 then look up the appropriate record in your get_driver method to find
59 the partition.
60
61 For many applications, you can partition several classes of data based
62 on the ID of the user account that "owns" them. In this case, you would
63 include the user ID as the first part of a complex primary key.
64
65 Because multiple objects can use the same partitioning scheme, often
66 Data::ObjectDriver::Driver::Partition is subclassed to define the
67 "get_driver" function once and automatically specify it to the
68 Data::ObjectDriver::Driver::Partition constructor.
69
70 Note these practices are codified into the
71 Data::ObjectDriver::Driver::SimplePartition class.
72
74 "Data::ObjectDriver::Driver::Partition->new(%params)"
75 Creates a new partitioning driver. The required members of %params are:
76
77 · "get_driver"
78
79 A reference to a function to be used to retrieve for a given object
80 or set of search terms. Your function is invoked as either:
81
82 · "get_driver(\%terms, \%args)"
83
84 Return a driver based on the given "search()" parameters.
85
86 · "get_driver($id)"
87
88 Return a driver based on the given object ID. Note that $id may
89 be an arrayref, if the class was defined with a complex primary
90 key.
91
92 · "pk_generator"
93
94 A reference to a function that, given a data object, generates a
95 primary key for it. This is the same "pk_generator" given to
96 "Data::ObjectDriver"'s constructor.
97
98 "$driver->search($class, $terms, $args)"
99 "$driver->lookup($class, $id)"
100 "$driver->lookup_multi($class, @ids)"
101 "$driver->exists($obj)"
102 "$driver->insert($obj)"
103 "$driver->update($obj)"
104 "$driver->remove($obj)"
105 "$driver->fetch_data($what)"
106 Performs the named action, by passing these methods through to the
107 appropriate database driver as determined by $driver's "get_driver"
108 function.
109
111 No errors are created by Data::ObjectDriver::Driver::Partition itself.
112 Errors may come from a specific partitioning subclass or the driver for
113 a particular database.
114
116 There are no known bugs in this module.
117
119 Data::ObjectDriver::Driver::SimplePartition
120
122 Data::ObjectDriver is free software; you may redistribute it and/or
123 modify it under the same terms as Perl itself.
124
126 Except where otherwise noted, Data::ObjectDriver is Copyright 2005-2006
127 Six Apart, cpan@sixapart.com. All rights reserved.
128
129
130
131perl v5.30.0 201D9a-t0a7:-:2O6bjectDriver::Driver::Partition(3pm)