Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-1551

Multi Upsert using dictionary incorrectly sets the TTL

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.0, 2.5.1
    • Fix Version/s: 2.5.2
    • Component/s: None
    • Labels:
      None

      Description

      NCBC-1206 allows per-operation timeouts to be specified.

      However, as part of this change, the code for dictionary-based multi upserts incorrectly sets the timeout value as the expiration value instead:

      public IDictionary<string, IOperationResult<T>> Upsert<T>(IDictionary<string, T> items, TimeSpan timeout)
              {
                  CheckDisposed();
                  var results = new ConcurrentDictionary<string, IOperationResult<T>>();
                  if (items != null && items.Count > 0)
                  {
                      var keys = items.Keys.ToList();
                      var partitionar = Partitioner.Create(0, items.Count());
                      Parallel.ForEach(partitionar, (range, loopstate) =>
                      {
                          for (var i = range.Item1; i < range.Item2; i++)
                          {
                              var key = keys[i];
                              var value = items[key];
                              var result = Upsert(key, value, timeout);
                              results.TryAdd(key, result);
                          }
                      });
                  }
                  return results;
      }
      

      Which maps to the method signature:

      public IOperationResult<T> Upsert<T>(string key, T value, TimeSpan expiration)
              {
                  return Upsert(key, value, expiration.ToTtl());
      }
      

      Instead it needs to use the method which accepts an expiration (which has to be 0 anyway) AND a timeout.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

          Hide
          jmorris Jeff Morris added a comment -

          Matt Carabine -

          Definitely a bug, but I would advise not to use those overloads which use Parallel.For loops and instead use the async equivalent:

                  public Task<IDocumentResult<T>[]> UpsertAsync<T>(List<IDocument<T>> documents, TimeSpan timeout)
                  {
                      var tasks = new List<Task<IDocumentResult<T>>>();
                      documents.ForEach(doc => tasks.Add(UpsertAsync(doc, timeout)));
                      return Task.WhenAll(tasks);
                  }
          

          The Parallel.For implementation should be flagged as obsolete in 2.5.0: NCBC-1497

          Show
          jmorris Jeff Morris added a comment - Matt Carabine - Definitely a bug, but I would advise not to use those overloads which use Parallel.For loops and instead use the async equivalent: public Task<IDocumentResult<T>[]> UpsertAsync<T>(List<IDocument<T>> documents, TimeSpan timeout) { var tasks = new List<Task<IDocumentResult<T>>>(); documents.ForEach(doc => tasks.Add(UpsertAsync(doc, timeout))); return Task.WhenAll(tasks); } The Parallel.For implementation should be flagged as obsolete in 2.5.0: NCBC-1497
          Hide
          matt.carabine Matt Carabine added a comment -

          I understand that and using the Async methods are a suitable workaround (as well as general good practice) for anyone who does hit this issue in the meantime.

          Show
          matt.carabine Matt Carabine added a comment - I understand that and using the Async methods are a suitable workaround (as well as general good practice) for anyone who does hit this issue in the meantime.

            People

            • Assignee:
              matt.carabine Matt Carabine
              Reporter:
              matt.carabine Matt Carabine
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes

                  PagerDuty

                  Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.