Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2123 for trunk/sources


Ignore:
Timestamp:
06/28/09 16:15:10 (15 years ago)
Author:
svonolfe
Message:

Avoided possible race conditions when streaming data from/into the DB (#680)

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/Session.cs

    r2117 r2123  
    8484    }
    8585
    86     public ITransaction BeginTransaction() {
     86    public ITransaction BeginTransaction(TransactionIsolationLevel isolationLevel) {
    8787      CheckThread();
    8888
    8989      if (transaction == null) {
    90          transaction = new Transaction(this);
    91          transaction.Connection = Connection;
     90        transaction = new Transaction(this, isolationLevel);
     91        transaction.Connection = Connection;
    9292      }
    9393
     
    9595
    9696      return transaction;
     97    }
     98
     99    public ITransaction BeginTransaction() {
     100      return BeginTransaction(TransactionIsolationLevel.Default);
    97101    }
    98102
  • trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/Transaction.cs

    r2117 r2123  
    3636    private int usageCounter = 0;
    3737
    38     public Transaction(Session session) {
     38    private TransactionIsolationLevel isolationLevel;
     39
     40    public Transaction(Session session, TransactionIsolationLevel isolationLevel) {
    3941      this.session = session;
     42      this.isolationLevel = isolationLevel;
    4043    }
    4144
     
    5356            value.Open();
    5457
    55           transaction = value.BeginTransaction(IsolationLevel.ReadCommitted);
     58          if (isolationLevel == TransactionIsolationLevel.Default)
     59            transaction = value.BeginTransaction(IsolationLevel.ReadCommitted);
     60          else if (isolationLevel == TransactionIsolationLevel.ReadUncommitted)
     61            transaction = value.BeginTransaction(IsolationLevel.ReadUncommitted);
     62          else if (isolationLevel == TransactionIsolationLevel.ReadCommitted)
     63            transaction = value.BeginTransaction(IsolationLevel.ReadCommitted);
     64          else if (isolationLevel == TransactionIsolationLevel.RepeatableRead)
     65            transaction = value.BeginTransaction(IsolationLevel.RepeatableRead);
     66          else if (isolationLevel == TransactionIsolationLevel.Serializable)
     67            transaction = value.BeginTransaction(IsolationLevel.Serializable);
     68          else
     69            transaction = value.BeginTransaction(IsolationLevel.ReadCommitted);
    5670        }
    5771      }
  • trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/VarBinaryStream.cs

    r2117 r2123  
    168168      } else {
    169169        _ownedConnection = false;
    170         _ownedTransaction = false;
    171170
    172171        if (transaction != null) {
    173172          _transaction = transaction;
     173
     174          _ownedTransaction = false;
     175
     176          if (_transaction.IsolationLevel != IsolationLevel.RepeatableRead &&
     177              _transaction.IsolationLevel != IsolationLevel.Serializable) {
     178            throw new ArgumentException("Transaction level must be at least repeatable read");
     179          }
     180        } else {
     181          _transaction =
     182            _connection.BeginTransaction(
     183          IsolationLevel.RepeatableRead)
     184            as SqlTransaction;
     185
     186          _ownedTransaction = true;
    174187        }
    175188      }
  • trunk/sources/HeuristicLab.DataAccess/3.2/Interfaces/ISession.cs

    r2117 r2123  
    2525
    2626namespace HeuristicLab.DataAccess.Interfaces {
     27  public enum TransactionIsolationLevel {
     28    Default, ReadUncommitted, ReadCommitted, RepeatableRead, Serializable
     29  };
     30
    2731  public interface ISession {
    2832    ISessionFactory Factory { get; }
    29    
     33
     34    ITransaction BeginTransaction(TransactionIsolationLevel isolationLevel);
     35
    3036    ITransaction BeginTransaction();
    3137
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r2122 r2123  
    480480          (JobResult)formatter.Deserialize(stream);
    481481
    482         tx = session.BeginTransaction();
     482        //important - repeatable read isolation level is required here,
     483        //otherwise race conditions could occur when writing the stream into the DB
     484        tx = session.BeginTransaction(
     485          TransactionIsolationLevel.RepeatableRead);
    483486
    484487        ResponseResultReceived response =
Note: See TracChangeset for help on using the changeset viewer.