[redland] Bug w/ remove statement under BDB storage

Chad House chadh at pobox.com
Thu May 9 16:07:15 BST 2002


(Tested with several recent 0.9.11 snapshots, including May 09, and
BDB version 3.)

Redland seems to have a bug when removing statements while using the
BDB storage. If there are multiple statements with the same subject
and predicate (but different objects), it appears that the first
occurring statement with the matching subject/predicate is removed
from the sp2o hash -- even if the object doesn't match. The correct
statement is removed from the po2s and so2p hashes.

Here's a Perl testcase:

------------------------------------------------------------------------

#!/usr/bin/perl -w

use RDF::Redland;
use strict;

my $storage =
  RDF::Redland::Storage->new('hashes', 'rmtest',
                             "new='yes',hash-type='bdb',dir='.'")
  or die "can't create storage";

my $model  = RDF::Redland::Model->new($storage);

for my $color (qw(red green blue)) {
  my $s = RDF::Redland::Statement->new_from_nodes(
    RDF::Redland::Node->new_from_uri_string("http://example.com/foo"),
    RDF::Redland::Node->new_from_uri_string("http://example.com/color"),
    RDF::Redland::Node->new_from_literal($color, "", 0, 0)
  );
  $model->add_statement($s);
}

my $rm = RDF::Redland::Statement->new_from_nodes(
  RDF::Redland::Node->new_from_uri_string("http://example.com/foo"),
  RDF::Redland::Node->new_from_uri_string("http://example.com/color"),
  RDF::Redland::Node->new_from_literal('green', "", 0, 0)
);

$model->remove_statement($rm);

my $stream = $model->serialise;
while(!$stream->end) {
  print "Statement: ", $stream->next->as_string, "\n";
}

$stream  = undef;
$storage = undef;
$model   = undef;

------------------------------------------------------------------------

When run, it prints:

  Statement: {[http://example.com/foo], [http://example.com/color], "green"}
  Statement: {[http://example.com/foo], [http://example.com/color], "blue"}

i.e., 'red' is missing, though we tried to delete green. And running
'db_dump -p' on the BDB files gives:

/---
| $ db_dump -p rmtest-sp2o.db
| VERSION=2
| format=print
| type=btree
| duplicates=1
| HEADER=END
|  xsR\00\16http://example.com/foo\00pR\00\18http://example.com/color\00
|  xoL\00\00\05\00\00green\00
|  xsR\00\16http://example.com/foo\00pR\00\18http://example.com/color\00
|  xoL\00\00\04\00\00blue\00
| DATA=END
| 
| 
| $ db_dump -p rmtest-so2p.db 
| VERSION=2
| format=print
| type=btree
| duplicates=1
| HEADER=END
|  xsR\00\16http://example.com/foo\00oL\00\00\03\00\00red\00
|  xpR\00\18http://example.com/color\00
|  xsR\00\16http://example.com/foo\00oL\00\00\04\00\00blue\00
|  xpR\00\18http://example.com/color\00
| DATA=END
| 
| 
| $ db_dump -p rmtest-po2s.db 
| VERSION=2
| format=print
| type=btree
| duplicates=1
| HEADER=END
|  xpR\00\18http://example.com/color\00oL\00\00\03\00\00red\00
|  xsR\00\16http://example.com/foo\00
|  xpR\00\18http://example.com/color\00oL\00\00\04\00\00blue\00
|  xsR\00\16http://example.com/foo\00
| DATA=END
\---

... so 'green' was deleted from so2p and po2s, but 'red' was removed
from sp2o.

This occurs with BDB storage only -- changing the type to 'memory' in
the test case produces the intended results.

Regards,

Chad






More information about the redland-dev mailing list