You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/03/18 12:39:59 UTC
[GitHub] [lucene-solr] s1monw opened a new pull request #1361: LUCENE-8118:
Throw exception if DWPT grows beyond it's maximum ram limit
s1monw opened a new pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361
Today if you add documents that cause a single DWPT to grow beyond its maximum ram buffer size we just keep on indexing. If a user misuses our IndexWriter#addDocuments API and provides a very very large iterable we will run into `ArrayIndexOutOfBoundsException` down the road and abort the IndexWriter. This change is not bulletproof but best effort to ensure that we fail with a better exception message and don't abort the IndexWriter.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] s1monw commented on a change in pull request #1361:
LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
s1monw commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399181159
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
+ boolean shouldRetry = perThread.dwpt == null && numDocsBefore > 0;
+ if (shouldRetry) {
+ try {
+ // we retry into a brand new DWPT, if it doesn't fit in here we can't index the document
Review comment:
no that's a correct comment. We flush the old one and then initialize the ThreadState again with a brand new DWPT
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1361:
LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
dnhatn commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r395423835
##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -3941,4 +3943,108 @@ public void testRandomOperationsWithSoftDeletes() throws Exception {
}
}
}
+
+ public void testAbortDocWhenHardLimitExceeds() throws IOException {
+ Directory dir = newDirectory();
+ IndexWriterConfig indexWriterConfig = new IndexWriterConfig();
+ IndexWriter w = new IndexWriter(dir, indexWriterConfig);
+ indexWriterConfig.setRAMPerThreadHardLimitMB(1);
+ w.addDocument(new Document()); // no problem
+ w.flush();
+ assertEquals(1, w.getFlushCount());
+ final long seed = random().nextLong();
+ int numDocs = 1;
+ try (LineFileDocs docs = new LineFileDocs(new Random(seed))) {
+ while (w.getFlushCount() == 1) {
+ w.addDocument(docs.nextDoc());
+ numDocs++;
+ }
+ }
+ try (LineFileDocs docs = new LineFileDocs(new Random(seed))) {
+ if (random().nextBoolean()) {
+ w.addDocument(new Document());
+ numDocs++;
+ }
+ w.addDocuments(() -> new Iterator<>() {
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @Override
+ public Iterable<? extends IndexableField> next() {
+ try {
+ return docs.nextDoc();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+ });
+ } catch (IllegalArgumentException e) {
+ assertEquals("RAM used by a single DocumentsWriterPerThread can't exceed: 1MB", e.getMessage());
+ assertNull(w.getTragicException());
+ }
+ w.addDocument(new Document());
+ numDocs++;
+ try (LineFileDocs docs = new LineFileDocs(new Random(seed))) {
+ final int currentNumDocs = numDocs;
+ for (int i = 0; i < currentNumDocs; i++) {
+ w.addDocument(docs.nextDoc());
+ numDocs++;
+ }
+ }
+ w.addDocument(new Document());
+ numDocs++;
+ w.forceMergeDeletes(true);
+ w.commit();
+
+ try (IndexReader reader = DirectoryReader.open(dir)) {
+ assertEquals(numDocs, reader.numDocs());
+ }
+
+
+ w.close();
+ dir.close();
+ }
+
+ @Nightly
+ public void testAddDocumentsMassive() throws Exception {
+ Directory dir = newFSDirectory(createTempDir("addDocumentsMassive"));
+ IndexWriter w = new IndexWriter(dir, new IndexWriterConfig());
+ StringBuilder sb = new StringBuilder();
+ // same doc with lots of duplicated terms to put pressure on FreqProxTermsWriter instead of terms dict.
+ for (int i = 0; i < 1024; i++) {
+ sb.append(i);
+ sb.append(' ');
+ }
+ final AtomicInteger count = new AtomicInteger(0);
+ Document doc = new Document();
+ try {
+ doc.add(new TextField("text", sb.toString(), Field.Store.NO));
+ w.addDocument(doc);
+ w.addDocuments((Iterable<Document>) () -> new Iterator<>() {
+
+ @Override
+ public boolean hasNext() {
+ return count.get() < 100_000_000;
+ }
+
+ @Override
+ public Document next() {
+ if (!hasNext()) {
+ throw new AssertionError();
+ }
+ count.incrementAndGet();
+ return doc;
+ }
+ });
+ } catch (IllegalArgumentException ex) {
+ assertEquals("RAM used by a single DocumentsWriterPerThread can exceed: 1945MB", ex.getMessage());
Review comment:
can -> can't
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399168190
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
Review comment:
s/`we the`/`the`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] s1monw commented on issue #1361: LUCENE-8118: Throw
exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
s1monw commented on issue #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#issuecomment-601407553
> 2) fixing exception handling in DW.updateDocuments to handle this exception gracefully (non-aborting).
the problem in this method was that we need to flush the DWPT to disk even if we hit an non-aborting exception. Otherwise the next doc would hit the same exception or we would violate the assumption that we never receive a flush pending DWPT.
One thing that I keep thinking about is what happens if we index documents close to the limit and then the next batch of documents would exceed that limit. That would mean that we reject docs event though we could index them into a different DWPT. Should we at least try to index it again in a fresh DWPT unless the DWPT that rejected it was empty? I mean that would prevent the issue and should be straight forward to implement. I can work on this in a followup.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399689324
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
+ boolean shouldRetry = perThread.dwpt == null && numDocsBefore > 0;
+ if (shouldRetry) {
+ try {
+ // we retry into a brand new DWPT, if it doesn't fit in here we can't index the document
Review comment:
Oh, I see: we create a new DWPT and send the doc there, ok.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1361:
LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
dnhatn commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r395425026
##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -3941,4 +3943,108 @@ public void testRandomOperationsWithSoftDeletes() throws Exception {
}
}
}
+
+ public void testAbortDocWhenHardLimitExceeds() throws IOException {
+ Directory dir = newDirectory();
+ IndexWriterConfig indexWriterConfig = new IndexWriterConfig();
+ IndexWriter w = new IndexWriter(dir, indexWriterConfig);
+ indexWriterConfig.setRAMPerThreadHardLimitMB(1);
+ w.addDocument(new Document()); // no problem
+ w.flush();
+ assertEquals(1, w.getFlushCount());
+ final long seed = random().nextLong();
+ int numDocs = 1;
+ try (LineFileDocs docs = new LineFileDocs(new Random(seed))) {
+ while (w.getFlushCount() == 1) {
+ w.addDocument(docs.nextDoc());
+ numDocs++;
+ }
+ }
+ try (LineFileDocs docs = new LineFileDocs(new Random(seed))) {
+ if (random().nextBoolean()) {
+ w.addDocument(new Document());
+ numDocs++;
+ }
+ w.addDocuments(() -> new Iterator<>() {
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @Override
+ public Iterable<? extends IndexableField> next() {
+ try {
+ return docs.nextDoc();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+ });
+ } catch (IllegalArgumentException e) {
+ assertEquals("RAM used by a single DocumentsWriterPerThread can't exceed: 1MB", e.getMessage());
+ assertNull(w.getTragicException());
+ }
+ w.addDocument(new Document());
+ numDocs++;
+ try (LineFileDocs docs = new LineFileDocs(new Random(seed))) {
+ final int currentNumDocs = numDocs;
+ for (int i = 0; i < currentNumDocs; i++) {
+ w.addDocument(docs.nextDoc());
+ numDocs++;
+ }
+ }
+ w.addDocument(new Document());
+ numDocs++;
+ w.forceMergeDeletes(true);
+ w.commit();
+
+ try (IndexReader reader = DirectoryReader.open(dir)) {
+ assertEquals(numDocs, reader.numDocs());
+ }
+
+
+ w.close();
+ dir.close();
+ }
+
+ @Nightly
+ public void testAddDocumentsMassive() throws Exception {
+ Directory dir = newFSDirectory(createTempDir("addDocumentsMassive"));
+ IndexWriter w = new IndexWriter(dir, new IndexWriterConfig());
+ StringBuilder sb = new StringBuilder();
+ // same doc with lots of duplicated terms to put pressure on FreqProxTermsWriter instead of terms dict.
+ for (int i = 0; i < 1024; i++) {
+ sb.append(i);
+ sb.append(' ');
+ }
+ final AtomicInteger count = new AtomicInteger(0);
+ Document doc = new Document();
+ try {
+ doc.add(new TextField("text", sb.toString(), Field.Store.NO));
+ w.addDocument(doc);
+ w.addDocuments((Iterable<Document>) () -> new Iterator<>() {
+
+ @Override
+ public boolean hasNext() {
+ return count.get() < 100_000_000;
+ }
+
+ @Override
+ public Document next() {
+ if (!hasNext()) {
+ throw new AssertionError();
Review comment:
I think we should throw an error in `hasNext` instead?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] s1monw commented on issue #1361: LUCENE-8118: Throw
exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
s1monw commented on issue #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#issuecomment-606555768
> Another thing we could consider is changing DWPT's postings addressing from int to long so we don't need retry logic.
I will look into this. My biggest fear is that we miss places where we exceed limits and testing will be difficult. Yet, there is no rush with this and I have time to explore fixing IntBlockPool addressing.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on issue #1361: LUCENE-8118:
Throw exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on issue #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#issuecomment-605494944
Another thing we could consider is changing DWPT's postings addressing from `int` to `long` so we don't need retry logic.
We could do it, always, increasing the per-unique-term memory cost. Or we could maybe find a way to do it conditionally, when a given DWPT wants to exceed the 2.1 GB limit, but that'd be trickier.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r395006886
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
##########
@@ -219,6 +222,9 @@ final void testPoint(String message) {
/** Anything that will add N docs to the index should reserve first to
* make sure it's allowed. */
private void reserveOneDoc() {
+ if (numDocsInRAM != 0 && hardMaxBytesPerDWPT < bytesUsed()) { // TODO should we check this after each field as well to also preempt within one doc?
Review comment:
Or even per-token while inverting? I think we already detect this today and throw aborting exception? But we could fix that to instead throw a non-aborting exception, so the one document is deleted, but IW/DWPT are not aborted. But we should do that later ...
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399689335
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
+ boolean shouldRetry = perThread.dwpt == null && numDocsBefore > 0;
+ if (shouldRetry) {
Review comment:
Got it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] s1monw commented on issue #1361: LUCENE-8118: Throw
exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
s1monw commented on issue #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#issuecomment-604922114
@dnhatn that's a good question. One option here would be to fix Lucene's `Field` to accept a `Supplier<Reader>` instead of a reader instance. That way we can consume it multiple times and for back-compat we can keep the reader ctor. This is something that we could benefit from in multiple other places too I guess. @mikemccand WDYT?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on issue #1361: LUCENE-8118:
Throw exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on issue #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#issuecomment-602027021
> > 1. fixing exception handling in DW.updateDocuments to handle this exception gracefully (non-aborting).
>
> the problem in this method was that we need to flush the DWPT to disk even if we hit an non-aborting exception. Otherwise the next doc would hit the same exception or we would violate the assumption that we never receive a flush pending DWPT.
Thanks for the explanation; make sense.
> One thing that I keep thinking about is what happens if we index documents close to the limit and then the next batch of documents would exceed that limit. That would mean that we reject docs event though we could index them into a different DWPT. Should we at least try to index it again in a fresh DWPT unless the DWPT that rejected it was empty? I mean that would prevent the issue and should be straight forward to implement. I can work on this in a followup.
+1, that's an awesome idea! In general when picking among the N free DWPTs when a new document arrives shouldn't we pick the DWPT that's smallest (least `.ramBytesUsed()`)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r395029178
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
##########
@@ -219,6 +222,9 @@ final void testPoint(String message) {
/** Anything that will add N docs to the index should reserve first to
* make sure it's allowed. */
private void reserveOneDoc() {
+ if (numDocsInRAM != 0 && hardMaxBytesPerDWPT < bytesUsed()) { // TODO should we check this after each field as well to also preempt within one doc?
+ throw new IllegalArgumentException("RAM used by a single DocumentsWriterPerThread can not exceed: " + hardMaxBytesPerDWPT / 1024 / 1024 + "MB");
Review comment:
s/`can not`/`cannot`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399168914
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
+ boolean shouldRetry = perThread.dwpt == null && numDocsBefore > 0;
+ if (shouldRetry) {
+ try {
+ // we retry into a brand new DWPT, if it doesn't fit in here we can't index the document
Review comment:
You mean retry into another DWPT right? Not necessarily a brand new (newly created, 0 docs) one? Maybe tweak comment?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] s1monw commented on a change in pull request #1361:
LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
s1monw commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399180850
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
+ boolean shouldRetry = perThread.dwpt == null && numDocsBefore > 0;
+ if (shouldRetry) {
Review comment:
yes this is only one DWPT not across all DWPTs
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] s1monw commented on issue #1361: LUCENE-8118: Throw
exception if DWPT grows beyond it's maximum ram limit
Posted by GitBox <gi...@apache.org>.
s1monw commented on issue #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#issuecomment-603805135
@mikemccand @dnhatn I added the retry logic, added a test and fixed some minor things. It's changed quite a bit I think it warrants another review.
>+1, that's an awesome idea! In general when picking among the N free DWPTs when a new document arrives shouldn't we pick the DWPT that's smallest (least .ramBytesUsed())?
I will address picking the smallest DWPT in a separate PR.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r395028755
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
##########
@@ -219,6 +222,9 @@ final void testPoint(String message) {
/** Anything that will add N docs to the index should reserve first to
* make sure it's allowed. */
private void reserveOneDoc() {
+ if (numDocsInRAM != 0 && hardMaxBytesPerDWPT < bytesUsed()) { // TODO should we check this after each field as well to also preempt within one doc?
Review comment:
Could you reverse the conditional to `bytesUsed() > hardMaxBytesPerDWPT`? I think it's more quickly readable in that order?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] mikemccand commented on a change in pull request
#1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram
limit
Posted by GitBox <gi...@apache.org>.
mikemccand commented on a change in pull request #1361: LUCENE-8118: Throw exception if DWPT grows beyond it's maximum ram limit
URL: https://github.com/apache/lucene-solr/pull/1361#discussion_r399169960
##########
File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
##########
@@ -435,55 +436,81 @@ private void ensureInitialized(ThreadState state) throws IOException {
long updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
final DocumentsWriterDeleteQueue.Node<?> delNode) throws IOException {
boolean hasEvents = preUpdate();
-
final ThreadState perThread = flushControl.obtainAndLock();
DocumentsWriterPerThread flushingDWPT = null;
+ final boolean isUpdate = delNode != null && delNode.isDelete();
+ final int numDocsBefore = perThread.dwpt == null ? 0 : perThread.dwpt.getNumDocsInRAM();
final long seqNo;
try {
- try {
- // This must happen after we've pulled the ThreadState because IW.close
- // waits for all ThreadStates to be released:
- ensureOpen();
- ensureInitialized(perThread);
- assert perThread.isInitialized();
- final DocumentsWriterPerThread dwpt = perThread.dwpt;
- final int dwptNumDocs = dwpt.getNumDocsInRAM();
- try {
- seqNo = dwpt.updateDocuments(docs, analyzer, delNode, flushNotifications);
- perThread.updateLastSeqNo(seqNo);
- } finally {
- // We don't know how many documents were actually
- // counted as indexed, so we must subtract here to
- // accumulate our separate counter:
- numDocsInRAM.addAndGet(dwpt.getNumDocsInRAM() - dwptNumDocs);
- if (dwpt.isAborted()) {
- flushControl.doOnAbort(perThread);
- } else if (dwpt.getNumDocsInRAM() > 0) {
- // we need to check if we have at least one doc in the DWPT. This can be 0 if we fail
- // due to exceeding total number of docs etc.
- final boolean isUpdate = delNode != null && delNode.isDelete();
+ innerUpdateDocuments(perThread, docs, analyzer, delNode);
+ flushingDWPT = flushControl.doAfterDocument(perThread, isUpdate);
+ } catch (MaxBufferSizeExceededException ex) {
+ if (perThread.dwpt.isAborted()) {
+ throw ex;
+ } else {
+ // we hit an exception but still need to flush this DWPT
+ // let's run postUpdate to make sure we flush stuff to disk
+ // in the case we exceed ram limits etc.
+ hasEvents = doAfterDocumentRejected(perThread, isUpdate, hasEvents);
+ // we retry if we the DWPT had more than one document indexed and was flushed
+ boolean shouldRetry = perThread.dwpt == null && numDocsBefore > 0;
+ if (shouldRetry) {
Review comment:
This is wild! So it means if the doc was so big it caused all RAM used across all DWPTs to be too much (> 2 X the IW's ram buffer?), causing the initially selected DWP to then flush, then we will try (just once) to pick another DWPT and process the doc?
Or, is the `MaxBufferSizeExceededException` just for one DWPT exceeding its single hard max RAM usage (1945 MB by default)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org