Automatically create a new partition if the current one doesn't have
enough free space.
This commit is contained in:
parent
d360ae4722
commit
2bc5967e10
|
@ -104,6 +104,8 @@ sub new {
|
|||
RaiseError => 1
|
||||
}
|
||||
);
|
||||
$self->{instances_part_size} = 10_000_000;
|
||||
$self->adjust_partitions;
|
||||
} elsif ($opt->{tokyocabinet}) {
|
||||
my $tdb = $self->{tdb} = TokyoCabinet::TDB->new();
|
||||
$tdb->open($opt->{tokyocabinet}, $tdb->WRITER, $tdb->OCREAT)
|
||||
|
@ -799,6 +801,27 @@ sub store_file {
|
|||
return $success;
|
||||
}
|
||||
|
||||
sub adjust_partitions {
|
||||
my ($self) = @_;
|
||||
my $dbh = $self->{dbh};
|
||||
my $database = $dbh->selectrow_array("select database()");
|
||||
my $max_id = $dbh->selectrow_array("select max(id) from instances");
|
||||
my ($max_part, $limit)
|
||||
= $dbh->selectrow_array(
|
||||
"select partition_ordinal_position, partition_description
|
||||
from information_schema.partitions
|
||||
where table_schema='$database' and table_name='instances'
|
||||
order by partition_ordinal_position desc
|
||||
limit 1");
|
||||
while ($max_id + $self->{instances_part_size} > $limit) {
|
||||
$max_part++;
|
||||
$limit += $self->{instances_part_size};
|
||||
my $partition_name = sprintf("p%03d", $max_part);
|
||||
$dbh->do("alter table instances add partition (partition $partition_name values less than ($limit))");
|
||||
$self->log(3, "added partition $partition_name < $limit");
|
||||
}
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
$self->{dbh}->disconnect();
|
||||
|
|
Loading…
Reference in New Issue