You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by EMaher <gi...@git.apache.org> on 2016/04/22 02:07:56 UTC

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

GitHub user EMaher opened a pull request:

    https://github.com/apache/lucenenet/pull/168

    Removing Apache.NMS dependency.

    Removing dependency on Apache.NMS.  This is needed to build Lucene.Net on .NET Core.
    -Replaced AtomicReference with use of Interlocked.Exchange.
    -Replaced CountDownLatch with CountdownEvent.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/EMaher/lucenenet emaher/removeApacheNMS

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/lucenenet/pull/168.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #168
    
----
commit 7c4a1b780f4d4a52cc2e4b0659512aab6f85206f
Author: EMaher <en...@microsoft.com>
Date:   2016-04-21T23:29:01Z

    Removing Apache.NMS dependency.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by conniey <gi...@git.apache.org>.
Github user conniey commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60831857
  
    --- Diff: src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs ---
    @@ -657,7 +655,7 @@ public virtual void TestRollbackAndCommitWithThreads()
                 }
     
                 Assert.IsTrue(!failed.Get());
    -            writerRef.Value.Dispose();
    +            writerRef.Dispose();
    --- End diff --
    
    @synhershko is correct. You can box this value with a helper class like:
    
    ```csharp
    class Helper<T> where T : class
        {
            private T _value;
    
            public Helper() : this(default(T))
            { }
    
            public Helper(T initial)
            {
                _value = initial;
            }
    
            public T Value
            {
                get
                {
                    lock (_value)
                    {
                        return _value;
                    }
                }
                set
                {
                    Interlocked.Exchange(ref _value, value);
                }
            }
        }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by EMaher <gi...@git.apache.org>.
Github user EMaher commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60832185
  
    --- Diff: src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs ---
    @@ -657,7 +655,7 @@ public virtual void TestRollbackAndCommitWithThreads()
                 }
     
                 Assert.IsTrue(!failed.Get());
    -            writerRef.Value.Dispose();
    +            writerRef.Dispose();
    --- End diff --
    
    Thanks @conniey and @eladmarg.  I'll make that change and update the PR on Monday.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/lucenenet/pull/168


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by eladmarg <gi...@git.apache.org>.
Github user eladmarg commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60832114
  
    --- Diff: src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs ---
    @@ -657,7 +655,7 @@ public virtual void TestRollbackAndCommitWithThreads()
                 }
     
                 Assert.IsTrue(!failed.Get());
    -            writerRef.Value.Dispose();
    +            writerRef.Dispose();
    --- End diff --
    
    @conniey great approach,
    I would even use the ReaderWriterLockSlim in order to reduce the performance penalty of locking. (in this way for reads only 1 thread can access, and I'm not sure this is a must)
    
    https://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by synhershko <gi...@git.apache.org>.
Github user synhershko commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60711453
  
    --- Diff: src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs ---
    @@ -726,15 +724,15 @@ public override void Run()
                                     {
                                         if (Random().NextBoolean())
                                         {
    -                                        WriterRef.Value.PrepareCommit();
    +                                        WriterRef.PrepareCommit();
                                         }
    -                                    WriterRef.Value.Commit();
    +                                    WriterRef.Commit();
                                     }
    -                                catch (AlreadyClosedException ace)
    +                                catch (AlreadyClosedException)
                                     {
                                         // ok
                                     }
    -                                catch (System.NullReferenceException npe)
    +                                catch (NullReferenceException)
    --- End diff --
    
    why not just add a null check? why is this ok?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by EMaher <gi...@git.apache.org>.
Github user EMaher commented on the pull request:

    https://github.com/apache/lucenenet/pull/168#issuecomment-213839959
  
    OK.  Suggested changes have been made.  I also verified that passing tests continue to pass, especially the ones that used to use AtomicReference.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by eladmarg <gi...@git.apache.org>.
Github user eladmarg commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60835981
  
    --- Diff: src/Lucene.Net.Core/Support/AtomicObject.cs ---
    @@ -0,0 +1,39 @@
    +using System;
    +using System.Threading;
    +
    +namespace Lucene.Net.Support
    +{
    +    public class AtomicObject<T> where T : class
    +    {
    +        private T _value;
    +        private ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
    +
    +        public AtomicObject() : this(default(T))
    +        { }
    +
    +        public AtomicObject(T initial)
    +        {
    +            _value = initial;
    +        }
    +
    +        public T Value
    +        {
    +            get
    +            {
    +                try
    +                {
    +                    _lock.EnterReadLock();
    +                    return _value;
    +                }
    +                finally
    +                {
    +                    _lock.ExitReadLock();
    +                }
    +            }
    +            set
    +            {
    +                Interlocked.Exchange(ref _value, value);
    --- End diff --
    
    Great job :+1: 
    just for safety, I would add 
    `
                try
                {
                    _lock.EnterWriteLock();
                    Interlocked.Exchange(ref _value, value);
                }
                finally
                {
                    _lock.ExitWriteLock();
                }`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by EMaher <gi...@git.apache.org>.
Github user EMaher commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60832211
  
    --- Diff: src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs ---
    @@ -726,15 +724,15 @@ public override void Run()
                                     {
                                         if (Random().NextBoolean())
                                         {
    -                                        WriterRef.Value.PrepareCommit();
    +                                        WriterRef.PrepareCommit();
                                         }
    -                                    WriterRef.Value.Commit();
    +                                    WriterRef.Commit();
                                     }
    -                                catch (AlreadyClosedException ace)
    +                                catch (AlreadyClosedException)
                                     {
                                         // ok
                                     }
    -                                catch (System.NullReferenceException npe)
    +                                catch (NullReferenceException)
    --- End diff --
    
    I just removed the unnecessary 'System' and removed the unused variable declaration.  I'm not sure why it is okay, you'd have to ask the original test writer.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by synhershko <gi...@git.apache.org>.
Github user synhershko commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/168#discussion_r60711321
  
    --- Diff: src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs ---
    @@ -657,7 +655,7 @@ public virtual void TestRollbackAndCommitWithThreads()
                 }
     
                 Assert.IsTrue(!failed.Get());
    -            writerRef.Value.Dispose();
    +            writerRef.Dispose();
    --- End diff --
    
    this will try to dispose of the local reference, not the reference that may have been updated within `ThreadAnonymousInnerClassHelper`. This is why writerRef was originally boxed - so if the reference changes we dispose of the correct instance. Can you compare with the Java version to verify correctness?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by synhershko <gi...@git.apache.org>.
Github user synhershko commented on the pull request:

    https://github.com/apache/lucenenet/pull/168#issuecomment-213845719
  
    Thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] lucenenet pull request: Removing Apache.NMS dependency.

Posted by synhershko <gi...@git.apache.org>.
Github user synhershko commented on the pull request:

    https://github.com/apache/lucenenet/pull/168#issuecomment-213348397
  
    Looks great, thanks!
    
    I add a few comments around `TestIndexWriterWithThreads`, it's not a trivial test and it's worth checking on our CI whether or not it fails before and after your changes. If it fails, it probably fails sporadically.
    
    There is a high risk of introducing thread safety issues here, so I'd want us to cover our bases.
    
    Let's compare the code in this test to the Java version and make sure we are preserving the same behavior. Once we know we do, let's run the tests many times, and strengthen them where possible, to make sure this is air tight.
    
    WDYT?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---