Problem/Motivation

In the \Drupal\sparql_entity_storage\SparqlEntityStorage::doSave there is the following code:

    if (!$entity->isNew()) {
      $this->deleteBeforeInsert($id, $graph_uri);
    }
    try {
      $this->insert($graph, $graph_uri);
      return $entity->isNew() ? SAVED_NEW : SAVED_UPDATED;
    }

The ::insert contains the serialization sequence of the strings. EasyRdf library is quite slow in encoding the strings and can result in a failure. This means that if there is a failure in the insert, the data are lost from the database since Sparql/Virtuoso does not support transactions.

Proposed resolution

Replace the code in ::insert to perform a DELETE .. INSERT if the entity is not new which does not perform any changes if any part of the query fails.

Note that the DELETE..INSERT contains a WHERE clause and has to match entries to delete in order to insert. That means, that in case the entity is new, it should be a simple INSERT query because otherwise, no matches will occur from the WHERE clause and there will be no action performed.

Move the query AFTER the serialization of the data.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idimopoulos created an issue. See original summary.

claudiu.cristea’s picture

Priority: Normal » Critical
claudiu.cristea’s picture

Status: Active » Reviewed & tested by the community
Issue tags: -Possible data loss on large strings +data loss, +data integrity

idimopoulos’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.