Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLFeatureStore: Fix lost updates in multi-part transactions #521

Merged

Conversation

MrSnyder
Copy link
Contributor

Prior to this patch, multi-part transactions against the SQLFeatureStore could lead to lost updates. Here's an example of such a transaction (in the form of a WFS 2.0 transaction):

<?xml version="1.0"?>
<wfs:Transaction xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:aixm="http://www.aixm.aero/schema/5.1" xmlns:gml="http://www.opengis.net/gml/3.2" version="2.0.0" service="WFS">
  <wfs:Update typeName="aixm:Airspace">
    <wfs:Property>
      <wfs:ValueReference action="insertBefore">aixm:timeSlice[1]</wfs:ValueReference>
      <wfs:Value>
        <aixm:AirportHeliportTimeSlice gml:id="TEST_11111111-1111-1111-1111-111111111111_3">
          <gml:validTime>
            <gml:TimePeriod gml:id="TEST_11111111-1111-1111-1111-111111111111_4">
              <gml:beginPosition>2015-01-02T00:00:00Z</gml:beginPosition>
              <gml:endPosition>2015-01-03T00:00:00Z</gml:endPosition>
            </gml:TimePeriod>
          </gml:validTime>
          <aixm:interpretation>TEMPDELTA</aixm:interpretation>
          <aixm:sequenceNumber>1</aixm:sequenceNumber>
        </aixm:AirportHeliportTimeSlice>
      </wfs:Value>
    </wfs:Property>
    <fes:Filter>
      <fes:ResourceId rid="uuid.11111111-1111-1111-1111-111111111111"/>
    </fes:Filter>
  </wfs:Update>
  <wfs:Update typeName="aixm:Airspace">
    <wfs:Property>
      <wfs:ValueReference action="insertBefore">aixm:timeSlice[1]</wfs:ValueReference>
      <wfs:Value>
        <aixm:AirportHeliportTimeSlice gml:id="TEST_11111111-1111-1111-1111-111111111111_5">
          <gml:validTime>
            <gml:TimePeriod gml:id="TEST_11111111-1111-1111-1111-111111111111_6">
              <gml:beginPosition>2015-01-06T00:00:00Z</gml:beginPosition>
              <gml:endPosition>2015-01-07T00:00:00Z</gml:endPosition>
            </gml:TimePeriod>
          </gml:validTime>
          <aixm:interpretation>TEMPDELTA</aixm:interpretation>
          <aixm:sequenceNumber>2</aixm:sequenceNumber>
        </aixm:AirportHeliportTimeSlice>
      </wfs:Value>
    </wfs:Property>
    <fes:Filter>
      <fes:ResourceId rid="uuid.11111111-1111-1111-1111-111111111111"/>
    </fes:Filter>
  </wfs:Update>
</wfs:Transaction>

For this example, the first update was lost and only the second one was applied. This has been observed for BLOB mode.

The cause for the problem was that the SQLFeatureStore always acquired a new JDBC connection, even when being used by an SQLFeatureStoreTransaction object as part of the transaction. After the patch, the SQLFeatureStore uses a ThreadLocal object to determine if the current thread has an active transaction and uses it, if this is the case.

It may not be ideal to limit the use of an SQLFeatureStoreTransaction instance to a single thread, but IMHO, there is no realistic use case for using it from multiple threads. Therefore, I consider the patch to be "good enough", unless somebody wants to fully correct and refactor the design of SQLFeatureStore and SQLFeatureStoreTransaction (which would involve a lot of changes).

@MrSnyder MrSnyder added this to the 3.4 milestone Mar 25, 2015
@MrSnyder MrSnyder added the bug error issue and bug (fix) label Mar 25, 2015
@MrSnyder MrSnyder self-assigned this Mar 25, 2015
@MrSnyder MrSnyder force-pushed the bugfix/sqlfeaturestore/lost-updates branch from 7e88c75 to e327d57 Compare March 25, 2015 18:58
MrSnyder added a commit that referenced this pull request Apr 30, 2015
SQLFeatureStore: Fix lost updates in multi-part transactions
@MrSnyder MrSnyder merged commit a9af1fc into deegree:master Apr 30, 2015
@MrSnyder MrSnyder removed the ready label Apr 30, 2015
@MrSnyder MrSnyder deleted the bugfix/sqlfeaturestore/lost-updates branch April 30, 2015 15:44
@tfr42
Copy link
Member

tfr42 commented Apr 30, 2015

Thank you for your contribution. Your pull requests has been accepted by the TMC.
This pull request will be part of the 3.4-pre18 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug error issue and bug (fix)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants