Holds all the configuration used by IndexWriter with few setters for settings that can be changed on an IndexWriter instance "live". @since 4.0
        public DocumentsWriterPerThread(string segmentName, Directory directory, LiveIndexWriterConfig indexWriterConfig, InfoStream infoStream, DocumentsWriterDeleteQueue deleteQueue, FieldInfos.Builder fieldInfos)
        {
            this.directoryOrig       = directory;
            this.directory           = new TrackingDirectoryWrapper(directory);
            this.fieldInfos          = fieldInfos;
            this.indexWriterConfig   = indexWriterConfig;
            this.infoStream          = infoStream;
            this.codec               = indexWriterConfig.Codec;
            this.docState            = new DocState(this, infoStream);
            this.docState.similarity = indexWriterConfig.Similarity;
            bytesUsed          = Counter.NewCounter();
            byteBlockAllocator = new DirectTrackingAllocator(bytesUsed);
            pendingUpdates     = new BufferedUpdates();
            intBlockAllocator  = new Int32BlockAllocator(bytesUsed);
            this.deleteQueue   = deleteQueue;
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(numDocsInRAM == 0, "num docs {0}", numDocsInRAM);
            }
            pendingUpdates.Clear();
            deleteSlice = deleteQueue.NewSlice();

            segmentInfo = new SegmentInfo(directoryOrig, Constants.LUCENE_MAIN_VERSION, segmentName, -1, false, codec, null);
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(numDocsInRAM == 0);
            }
            if (INFO_VERBOSE && infoStream.IsEnabled("DWPT"))
            {
                infoStream.Message("DWPT", Thread.CurrentThread.Name + " init seg=" + segmentName + " delQueue=" + deleteQueue);
            }
            // this should be the last call in the ctor
            // it really sucks that we need to pull this within the ctor and pass this ref to the chain!
            consumer = indexWriterConfig.IndexingChain.GetChain(this);
        }
示例#2
0
 public IndexThread(AtomicInt32 pendingDocs, IndexWriter writer, LineFileDocs docs, bool doRandomCommit)
 {
     this.pendingDocs = pendingDocs;
     this.writer      = writer;
     iwc                 = writer.Config;
     this.docs           = docs;
     this.doRandomCommit = doRandomCommit;
 }
示例#3
0
 /// <summary>
 /// Called by <see cref="DocumentsWriter"/> to initialize the <see cref="FlushPolicy"/>
 /// </summary>
 protected internal virtual void Init(LiveIndexWriterConfig indexWriterConfig)
 {
     lock (this)
     {
         this.m_indexWriterConfig = indexWriterConfig;
         m_infoStream             = indexWriterConfig.InfoStream;
     }
 }
示例#4
0
 public IndexThread(TestFlushByRamOrCountsPolicy outerInstance, AtomicInt32 pendingDocs, int numThreads, IndexWriter writer, LineFileDocs docs, bool doRandomCommit)
 {
     this.OuterInstance = outerInstance;
     this.PendingDocs   = pendingDocs;
     this.Writer        = writer;
     Iwc                 = writer.Config;
     this.Docs           = docs;
     this.DoRandomCommit = doRandomCommit;
 }
示例#5
0
 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;
 }
示例#6
0
 internal DocumentsWriter(IndexWriter writer, LiveIndexWriterConfig config, Directory directory)
 {
     this.directory     = directory;
     this.config        = config;
     this.infoStream    = config.InfoStream;
     this.perThreadPool = config.IndexerThreadPool;
     flushPolicy        = config.FlushPolicy;
     this.writer        = writer;
     this.events        = new ConcurrentQueue <IEvent>();
     flushControl       = new DocumentsWriterFlushControl(this, config, writer.bufferedUpdatesStream);
 }
示例#7
0
 internal DocumentsWriterFlushControl(DocumentsWriter documentsWriter, LiveIndexWriterConfig config, BufferedUpdatesStream bufferedUpdatesStream)
 {
     this.InfoStream_Renamed    = 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;
 }
示例#8
0
 internal DocumentsWriter(IndexWriter writer, LiveIndexWriterConfig config, Directory directory)
 {
     this.Directory     = directory;
     this.LIWConfig     = config;
     this.InfoStream    = config.InfoStream;
     this.PerThreadPool = config.IndexerThreadPool;
     FlushPolicy        = config.FlushPolicy;
     this.Writer        = writer;
     this.Events        = new ConcurrentQueue <Event>();
     FlushControl       = new DocumentsWriterFlushControl(this, config, writer.BufferedUpdatesStream);
 }
示例#9
0
 /// <summary>
 /// Called by <see cref="DocumentsWriter"/> to initialize the <see cref="FlushPolicy"/>
 /// </summary>
 protected internal virtual void Init(LiveIndexWriterConfig indexWriterConfig)
 {
     UninterruptableMonitor.Enter(this);
     try
     {
         this.m_indexWriterConfig = indexWriterConfig;
         m_infoStream             = indexWriterConfig.InfoStream;
     }
     finally
     {
         UninterruptableMonitor.Exit(this);
     }
 }
示例#10
0
 /// <summary>
 /// Called by DocumentsWriter to initialize the FlushPolicy
 /// </summary>
 protected internal virtual void Init(LiveIndexWriterConfig indexWriterConfig)
 {
     lock (this)
     {
         this.IWConfig = indexWriterConfig;
         InfoStream = indexWriterConfig.InfoStream;
     }
 }
示例#11
0
        internal readonly Codec Codec; // for writing new segments

        /// <summary>
        /// Constructs a new IndexWriter per the settings given in <code>conf</code>.
        /// If you want to make "live" changes to this writer instance, use
        /// <seealso cref="#getConfig()"/>.
        ///
        /// <p>
        /// <b>NOTE:</b> after ths writer is created, the given configuration instance
        /// cannot be passed to another writer. If you intend to do so, you should
        /// <seealso cref="IndexWriterConfig#clone() clone"/> it beforehand.
        /// </summary>
        /// <param name="d">
        ///          the index directory. The index is either created or appended
        ///          according <code>conf.getOpenMode()</code>. </param>
        /// <param name="conf">
        ///          the configuration settings according to which IndexWriter should
        ///          be initialized. </param>
        /// <exception cref="IOException">
        ///           if the directory cannot be read/written to, or if it does not
        ///           exist and <code>conf.getOpenMode()</code> is
        ///           <code>OpenMode.APPEND</code> or if there is any other low-level
        ///           IO error </exception>
        public IndexWriter(Directory d, IndexWriterConfig conf)
        {
            /*if (!InstanceFieldsInitialized)
            {
                InitializeInstanceFields();
                InstanceFieldsInitialized = true;
            }*/
            readerPool = new ReaderPool(this);
            conf.SetIndexWriter(this); // prevent reuse by other instances
            Config_Renamed = new LiveIndexWriterConfig(conf);
            directory = d;
            analyzer = Config_Renamed.Analyzer;
            infoStream = Config_Renamed.InfoStream;
            mergePolicy = Config_Renamed.MergePolicy;
            mergePolicy.IndexWriter = this;
            mergeScheduler = Config_Renamed.MergeScheduler;
            Codec = Config_Renamed.Codec;

            BufferedUpdatesStream = new BufferedUpdatesStream(infoStream);
            PoolReaders = Config_Renamed.ReaderPooling;

            WriteLock = directory.MakeLock(WRITE_LOCK_NAME);

            if (!WriteLock.Obtain(Config_Renamed.WriteLockTimeout)) // obtain write lock
            {
                throw new LockObtainFailedException("Index locked for write: " + WriteLock);
            }

            bool success = false;
            try
            {
                OpenMode_e? mode = Config_Renamed.OpenMode;
                bool create;
                if (mode == OpenMode_e.CREATE)
                {
                    create = true;
                }
                else if (mode == OpenMode_e.APPEND)
                {
                    create = false;
                }
                else
                {
                    // CREATE_OR_APPEND - create only if an index does not exist
                    create = !DirectoryReader.IndexExists(directory);
                }

                // If index is too old, reading the segments will throw
                // IndexFormatTooOldException.
                segmentInfos = new SegmentInfos();

                bool initialIndexExists = true;

                if (create)
                {
                    // Try to read first.  this is to allow create
                    // against an index that's currently open for
                    // searching.  In this case we write the next
                    // segments_N file with no segments:
                    try
                    {
                        segmentInfos.Read(directory);
                        segmentInfos.Clear();
                    }
                    catch (IOException)
                    {
                        // Likely this means it's a fresh directory
                        initialIndexExists = false;
                    }

                    // Record that we have a change (zero out all
                    // segments) pending:
                    Changed();
                }
                else
                {
                    segmentInfos.Read(directory);

                    IndexCommit commit = Config_Renamed.IndexCommit;
                    if (commit != null)
                    {
                        // Swap out all segments, but, keep metadata in
                        // SegmentInfos, like version & generation, to
                        // preserve write-once.  this is important if
                        // readers are open against the future commit
                        // points.
                        if (commit.Directory != directory)
                        {
                            throw new System.ArgumentException("IndexCommit's directory doesn't match my directory");
                        }
                        SegmentInfos oldInfos = new SegmentInfos();
                        oldInfos.Read(directory, commit.SegmentsFileName);
                        segmentInfos.Replace(oldInfos);
                        Changed();
                        if (infoStream.IsEnabled("IW"))
                        {
                            infoStream.Message("IW", "init: loaded commit \"" + commit.SegmentsFileName + "\"");
                        }
                    }
                }

                RollbackSegments = segmentInfos.CreateBackupSegmentInfos();

                // start with previous field numbers, but new FieldInfos
                GlobalFieldNumberMap = FieldNumberMap;
                Config_Renamed.FlushPolicy.Init(Config_Renamed);
                DocWriter = new DocumentsWriter(this, Config_Renamed, directory);
                eventQueue = DocWriter.EventQueue();

                // Default deleter (for backwards compatibility) is
                // KeepOnlyLastCommitDeleter:
                lock (this)
                {
                    Deleter = new IndexFileDeleter(directory, Config_Renamed.DelPolicy, segmentInfos, infoStream, this, initialIndexExists);
                }

                if (Deleter.StartingCommitDeleted)
                {
                    // Deletion policy deleted the "head" commit point.
                    // We have to mark ourself as changed so that if we
                    // are closed w/o any further changes we write a new
                    // segments_N file.
                    Changed();
                }

                if (infoStream.IsEnabled("IW"))
                {
                    infoStream.Message("IW", "init: create=" + create);
                    MessageState();
                }

                success = true;
            }
            finally
            {
                if (!success)
                {
                    if (infoStream.IsEnabled("IW"))
                    {
                        infoStream.Message("IW", "init: hit exception on init; releasing write lock");
                    }
                    WriteLock.Release();
                    IOUtils.CloseWhileHandlingException(WriteLock);
                    WriteLock = null;
                }
            }
        }
 public IndexThread(TestFlushByRamOrCountsPolicy outerInstance, AtomicInteger pendingDocs, int numThreads, IndexWriter writer, LineFileDocs docs, bool doRandomCommit)
 {
     this.OuterInstance = outerInstance;
     this.PendingDocs = pendingDocs;
     this.Writer = writer;
     Iwc = writer.Config;
     this.Docs = docs;
     this.DoRandomCommit = doRandomCommit;
 }
        public DocumentsWriterPerThread(string segmentName, Directory directory, LiveIndexWriterConfig indexWriterConfig, InfoStream infoStream, DocumentsWriterDeleteQueue deleteQueue, FieldInfos.Builder fieldInfos)
        {
            this.DirectoryOrig = directory;
            this.Directory = new TrackingDirectoryWrapper(directory);
            this.FieldInfos = fieldInfos;
            this.IndexWriterConfig = indexWriterConfig;
            this.InfoStream = infoStream;
            this.Codec = indexWriterConfig.Codec;
            this.docState = new DocState(this, infoStream);
            this.docState.Similarity = indexWriterConfig.Similarity;
            bytesUsed = Counter.NewCounter();
            ByteBlockAllocator = new DirectTrackingAllocator(bytesUsed);
            PendingUpdates = new BufferedUpdates();
            intBlockAllocator = new IntBlockAllocator(bytesUsed);
            this.DeleteQueue = deleteQueue;
            Debug.Assert(numDocsInRAM == 0, "num docs " + numDocsInRAM);
            PendingUpdates.Clear();
            DeleteSlice = deleteQueue.NewSlice();

            SegmentInfo_Renamed = new SegmentInfo(DirectoryOrig, Constants.LUCENE_MAIN_VERSION, segmentName, -1, false, Codec, null);
            Debug.Assert(numDocsInRAM == 0);
            if (INFO_VERBOSE && infoStream.IsEnabled("DWPT"))
            {
                infoStream.Message("DWPT", Thread.CurrentThread.Name + " init seg=" + segmentName + " delQueue=" + deleteQueue);
            }
            // this should be the last call in the ctor
            // it really sucks that we need to pull this within the ctor and pass this ref to the chain!
            Consumer = indexWriterConfig.IndexingChain.GetChain(this);
        }
示例#14
0
 internal DocumentsWriter(IndexWriter writer, LiveIndexWriterConfig config, Directory directory)
 {
     this.Directory = directory;
     this.LIWConfig = config;
     this.InfoStream = config.InfoStream;
     this.PerThreadPool = config.IndexerThreadPool;
     FlushPolicy = config.FlushPolicy;
     this.Writer = writer;
     this.Events = new ConcurrentQueue<Event>();
     FlushControl = new DocumentsWriterFlushControl(this, config, writer.BufferedUpdatesStream);
 }