rebuild empty partitions.
This commit is contained in:
parent
cd48a38516
commit
99f174bd0d
|
@ -11,13 +11,15 @@ use Simba::CA;
|
||||||
use Bit::Vector::Judy;
|
use Bit::Vector::Judy;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
|
||||||
|
|
||||||
$| = 1;
|
$| = 1;
|
||||||
|
|
||||||
my $ca = Simba::CA->new({
|
my $ca = Simba::CA->new({
|
||||||
dbi_file => $ENV{SIMBA_DB_CONN} || "$ENV{HOME}/.dbi/simba",
|
dbi_file => $ENV{SIMBA_DB_CONN} || "$ENV{HOME}/.dbi/simba",
|
||||||
});
|
});
|
||||||
|
|
||||||
my $dbh = $ca->{dbh};
|
my $dbh = $ca->{dbh};
|
||||||
|
my $partition_size = $ca->{instances_part_size};
|
||||||
|
|
||||||
my %opt;
|
my %opt;
|
||||||
GetOptions(
|
GetOptions(
|
||||||
|
@ -39,8 +41,24 @@ if ($opt{age}) {
|
||||||
}
|
}
|
||||||
for my $session (@ARGV) {
|
for my $session (@ARGV) {
|
||||||
print "deleting instances of session $session\n";
|
print "deleting instances of session $session\n";
|
||||||
|
my $old_min_id = $dbh->selectrow_array("select min(id) from instances");
|
||||||
my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);
|
my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);
|
||||||
print "\t$n_instances instances deleted\n";
|
print "\t$n_instances instances deleted\n";
|
||||||
|
|
||||||
|
# Check if we just crossed into a new partition, if so, the old one is empty
|
||||||
|
# and should be shrunk to minimum size.
|
||||||
|
#
|
||||||
|
# Note: This will not shrink partitions if we delete a session somewhere
|
||||||
|
# in the middle, but I expect to do that rarely, and rebuilding a partition
|
||||||
|
# after expiring a single session isn't worthwhile anyway. If I delete lots
|
||||||
|
# of instances in the middle, I can always rebuild the affected partitions
|
||||||
|
# manually.
|
||||||
|
my $new_min_id = $dbh->selectrow_array("select min(id) from instances");
|
||||||
|
if (int($new_min_id/$partition_size) > int($old_min_id/$partition_size)) {
|
||||||
|
my $partition = sprintf("p%03d", int($new_min_id/$partition_size));
|
||||||
|
$dbh->do("alter table instances rebuild partition $partition");
|
||||||
|
print "\trebuilt partition $partition\n";
|
||||||
|
}
|
||||||
$dbh->commit();
|
$dbh->commit();
|
||||||
}
|
}
|
||||||
remove_orphaned_sessions();
|
remove_orphaned_sessions();
|
||||||
|
|
Loading…
Reference in New Issue