public void EnsureCommitted()
        {
            if (_metadataForNextCommit == null)
            {
                // this means no changes have been made to the index - no need to commit
                _logger.LogInformation(string.Format("SKIP COMMIT No changes. Index contains {0} documents.", _indexWriter.NumDocs()));
                return;
            }

            _indexWriter.ExpungeDeletes();
            _indexWriter.Commit(_metadataForNextCommit.ToDictionary());

            _logger.LogInformation("COMMIT index contains {0} documents. Metadata: commitTimeStamp {CommitTimeStamp}; change count {ChangeCount}; trace {CommitTrace}",
                                   _indexWriter.NumDocs(), _metadataForNextCommit.CommitTimeStamp.ToString("O"), _metadataForNextCommit.Count, _metadataForNextCommit.Trace);

            _metadataForNextCommit = null;
        }
Example #2
0
        private async Task CommitIndexAsync()
        {
            // This method commits to the index synchronously and may hang. Yield the current context to allow cancellation.
            await Task.Yield();

            using (_telemetryService.TrackIndexCommitDuration())
            {
                _logger.LogInformation("COMMITTING index contains {0} documents. Metadata: commitTimeStamp {CommitTimeStamp}; change count {ChangeCount}; trace {CommitTrace}",
                                       _indexWriter.NumDocs(), _metadataForNextCommit.CommitTimeStamp.ToString("O"), _metadataForNextCommit.Count, _metadataForNextCommit.Trace);

                _indexWriter.ExpungeDeletes();
                _indexWriter.Commit(_metadataForNextCommit.ToDictionary());

                _logger.LogInformation("COMMIT index contains {0} documents. Metadata: commitTimeStamp {CommitTimeStamp}; change count {ChangeCount}; trace {CommitTrace}",
                                       _indexWriter.NumDocs(), _metadataForNextCommit.CommitTimeStamp.ToString("O"), _metadataForNextCommit.Count, _metadataForNextCommit.Trace);

                _metadataForNextCommit = null;
            }
        }