internal DocumentsWriterFlushControl(DocumentsWriter documentsWriter, LiveIndexWriterConfig config, BufferedUpdatesStream bufferedUpdatesStream)
 {
     this.infoStream            = config.InfoStream;
     this.stallControl          = new DocumentsWriterStallControl();
     this.perThreadPool         = documentsWriter.perThreadPool;
     this.flushPolicy           = documentsWriter.flushPolicy;
     this.config                = config;
     this.hardMaxBytesPerDWPT   = config.RAMPerThreadHardLimitMB * 1024 * 1024;
     this.documentsWriter       = documentsWriter;
     this.bufferedUpdatesStream = bufferedUpdatesStream;
 }
        public override ThreadState GetAndLock(Thread requestingThread, DocumentsWriter documentsWriter)
        {
            if (threadBindings.TryGetValue(requestingThread, out ThreadState threadState) && threadState.TryLock())
            {
                return(threadState);
            }
            ThreadState minThreadState = null;

            /* TODO -- another thread could lock the minThreadState we just got while
             * we should somehow prevent this. */
            // Find the state that has minimum number of threads waiting
            minThreadState = MinContendedThreadState();
            if (minThreadState == null || minThreadState.HasQueuedThreads)
            {
                ThreadState newState = NewThreadState(); // state is already locked if non-null
                if (newState != null)
                {
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(newState.IsHeldByCurrentThread);
                    }
                    threadBindings[requestingThread] = newState;
                    return(newState);
                }
                else if (minThreadState == null)
                {
                    /*
                     * no new threadState available we just take the minContented one
                     * this must return a valid thread state since we accessed the
                     * synced context in newThreadState() above.
                     */
                    minThreadState = MinContendedThreadState();
                }
            }
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(minThreadState != null, () => "ThreadState is null");
            }

            minThreadState.@Lock();
            return(minThreadState);
        }
Exemple #3
0
 // you cannot subclass this without being in o.a.l.index package anyway, so
 // the class is already pkg-private... fix me: see LUCENE-4013
 public abstract ThreadState GetAndLock(Thread requestingThread, DocumentsWriter documentsWriter); // LUCENENET NOTE: Made public rather than internal