Exemple #1
0
        internal DocumentsWriterPerThread NextPendingFlush()
        {
            int  numPending;
            bool fullFlush;

            lock (this)
            {
                DocumentsWriterPerThread poll;
                if (flushQueue.Count > 0 && (poll = flushQueue.Dequeue()) != null)
                {
                    UpdateStallState();
                    return(poll);
                }
                fullFlush  = this.fullFlush;
                numPending = this.numPending;
            }
            if (numPending > 0 && !fullFlush) // don't check if we are doing a full flush
            {
                int limit = perThreadPool.NumThreadStatesActive;
                for (int i = 0; i < limit && numPending > 0; i++)
                {
                    ThreadState next = perThreadPool.GetThreadState(i);
                    if (next.flushPending)
                    {
                        DocumentsWriterPerThread dwpt = TryCheckoutForFlush(next);
                        if (dwpt != null)
                        {
                            return(dwpt);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #2
0
 internal void Abort(IndexWriter writer)
 {
     UninterruptableMonitor.Enter(this);
     try
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(!UninterruptableMonitor.IsEntered(writer), "IndexWriter lock should never be hold when aborting");
         }
         bool success = false;
         JCG.HashSet <string> newFilesSet = new JCG.HashSet <string>();
         try
         {
             deleteQueue.Clear();
             if (infoStream.IsEnabled("DW"))
             {
                 infoStream.Message("DW", "abort");
             }
             int limit = perThreadPool.NumThreadStatesActive;
             for (int i = 0; i < limit; i++)
             {
                 ThreadState perThread = perThreadPool.GetThreadState(i);
                 perThread.@Lock();
                 try
                 {
                     AbortThreadState(perThread, newFilesSet);
                 }
                 finally
                 {
                     perThread.Unlock();
                 }
             }
             flushControl.AbortPendingFlushes(newFilesSet);
             PutEvent(new DeleteNewFilesEvent(newFilesSet));
             flushControl.WaitForFlush();
             success = true;
         }
         finally
         {
             if (infoStream.IsEnabled("DW"))
             {
                 infoStream.Message("DW", "done abort; abortedFiles=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", newFilesSet) + " success=" + success);
             }
         }
     }
     finally
     {
         UninterruptableMonitor.Exit(this);
     }
 }
        internal DocumentsWriterPerThread NextPendingFlush()
        {
            int  numPending;
            bool fullFlush;

            UninterruptableMonitor.Enter(this);
            try
            {
                DocumentsWriterPerThread poll;
                if (flushQueue.Count > 0 && (poll = flushQueue.Dequeue()) != null)
                {
                    UpdateStallState();
                    return(poll);
                }
                fullFlush  = this.fullFlush;
                numPending = this.numPending;
            }
            finally
            {
                UninterruptableMonitor.Exit(this);
            }
            if (numPending > 0 && !fullFlush) // don't check if we are doing a full flush
            {
                int limit = perThreadPool.NumThreadStatesActive;
                for (int i = 0; i < limit && numPending > 0; i++)
                {
                    ThreadState next = perThreadPool.GetThreadState(i);
                    if (next.flushPending && next.TryLock()) // LUCENENET specific: Since .NET Core 2+ uses fair locking, we need to ensure we have a lock before calling InternalTryCheckoutForFlush. See #
                    {
                        try
                        {
                            DocumentsWriterPerThread dwpt = TryCheckoutForFlush(next);
                            if (dwpt != null)
                            {
                                return(dwpt);
                            }
                        }
                        finally
                        {
                            next.Unlock();
                        }
                    }
                }
            }
            return(null);
        }
Exemple #4
0
 internal void Abort(IndexWriter writer)
 {
     lock (this)
     {
         //Debug.Assert(!Thread.HoldsLock(writer), "IndexWriter lock should never be hold when aborting");
         bool             success     = false;
         HashSet <string> newFilesSet = new HashSet <string>();
         try
         {
             deleteQueue.Clear();
             if (infoStream.IsEnabled("DW"))
             {
                 infoStream.Message("DW", "abort");
             }
             int limit = perThreadPool.NumThreadStatesActive;
             for (int i = 0; i < limit; i++)
             {
                 ThreadState perThread = perThreadPool.GetThreadState(i);
                 perThread.@Lock();
                 try
                 {
                     AbortThreadState(perThread, newFilesSet);
                 }
                 finally
                 {
                     perThread.Unlock();
                 }
             }
             flushControl.AbortPendingFlushes(newFilesSet);
             PutEvent(new DeleteNewFilesEvent(newFilesSet));
             flushControl.WaitForFlush();
             success = true;
         }
         finally
         {
             if (infoStream.IsEnabled("DW"))
             {
                 infoStream.Message("DW", "done abort; abortedFiles=" + Arrays.ToString(newFilesSet) + " success=" + success);
             }
         }
     }
 }