Commit 5ac07070 authored by Andy Yates's avatar Andy Yates Committed by Magali Ruffier
Browse files

Switching to a tied hash instance versus blessed hash.

Seems that calling external code could assume the sequence cache is, in
fact, a hash. If the cache is replaced with the wrong data structure
(say a normal hash) then a memory leak will appear as seen in the xref
pipeline whilst dumping sequences.
parent 6cbd4b54
......@@ -505,8 +505,7 @@ sub fetch_and_dump_seq_via_toplevel{
%{ $slice_adaptor->{'sr_id_cache'} } = ();
$ama->delete_cache();
%{ $seqa->{'seq_cache'} } = ();
$seqa->clear_cache();
}
close $dnah || die "unable to close dna file\n$!\n";
......@@ -645,7 +644,7 @@ sub fetch_and_dump_seq_via_genes{
$ama->delete_cache();
%{ $seqa->{'seq_cache'} } = ();
$seqa->clear_cache();
}
close $dnah || die "unable to close dna file\n$!\n";
close $peph || die "unable to close peptide file\n$!\n";
......
......@@ -191,12 +191,12 @@ sub _init_seq_instance {
$cache_size ||= $SEQ_CACHE_SIZE;
# use a LRU cache to limit the size
my $cache = Bio::EnsEMBL::Utils::Cache->TIEHASH($cache_size);
tie my %cache, 'Bio::EnsEMBL::Utils::Cache', $cache_size, {};
$self->{cache_size} = $cache_size;
$self->{chunk_power} = $chunk_power;
$self->{seq_cache_max} = ((2 ** $chunk_power) * $cache_size);
$self->{seq_cache} = $cache;
$self->{seq_cache} = \%cache;
return;
}
......@@ -211,7 +211,7 @@ sub _init_seq_instance {
sub clear_cache {
my ($self) = @_;
$self->{seq_cache}->CLEAR();
%{$self->{seq_cache}} = ();
return;
}
......@@ -297,7 +297,7 @@ sub _fetch_seq {
my $key = "${id}:${i}";
#If it exists within the cache then add to the string. We will trim
#down to the requested region later on
my $cached_seq_ref = $cache->FETCH($key);
my $cached_seq_ref = $cache->{$key};
if($cached_seq_ref) {
$entire_seq .= ${$cached_seq_ref};
}
......@@ -307,7 +307,7 @@ sub _fetch_seq {
my $length = 1 << $seq_chunk_pwr;
my $tmp_seq_ref = $self->_fetch_raw_seq($id, $min, $length);
$entire_seq .= ${$tmp_seq_ref};
$cache->STORE($key, $tmp_seq_ref);
$cache->{$key} = $tmp_seq_ref;
}
}
......
......@@ -72,9 +72,9 @@ my $SA = $dba->get_SliceAdaptor();
dies_ok { $dba->get_SequenceAdaptor()->store() } 'Call should die due to FASTASequenceAdaptor being in place';
# Drill into the object and look at the cache
my $cache_key = $sa->{seq_cache}->FIRSTKEY();
my ($cache_key) = keys %{$sa->{seq_cache}};
my $expected_length = 1 << $power;
is(length(${$sa->{seq_cache}->FETCH($cache_key)}), $expected_length, 'Checking length of cached sequence');
is(length(${$sa->{seq_cache}->{$cache_key}}), $expected_length, 'Checking length of cached sequence');
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment