Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 46A59200B26 for ; Mon, 27 Jun 2016 11:07:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 451D7160A5B; Mon, 27 Jun 2016 09:07:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 61943160A3C for ; Mon, 27 Jun 2016 11:07:29 +0200 (CEST) Received: (qmail 48259 invoked by uid 500); 27 Jun 2016 09:07:28 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 48247 invoked by uid 99); 27 Jun 2016 09:07:27 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jun 2016 09:07:27 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4B8E1180651 for ; Mon, 27 Jun 2016 09:07:27 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.179 X-Spam-Level: * X-Spam-Status: No, score=1.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id ddHyQFnfURwB for ; Mon, 27 Jun 2016 09:07:23 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTPS id C32A85FC06 for ; Mon, 27 Jun 2016 09:07:22 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id v199so91194812wmv.0 for ; Mon, 27 Jun 2016 02:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=rgqwmFRxzwOdfVWLFNi4wPd71Kn9Ch3kbz5vzqYXZHk=; b=VZ8qNxIy4oRknpxPLKLxub9a8xsVWAny/Gd3Bfs98Rg+jZ9vYDlLniqqBCKaLgSC0U ityi1/TBawhQs8vGw4RcmnqD5c0FvmCG4Jn+OoT8bLsVoKG5N1bYA+qoE72+7Zsr7WlL PuWvGP//wLqoNfqTnNztgN5u1BSCFG0QB+shRXIoMt3YexPLhNKFbqcYVaahKUIfsHcs K8tYTH+IxQp1Mb69jpSJKQMpq2h7c/6+X+Al8je6QBzOdN1bxs7rNYdiINmwgROStF8L ZF/MODRArnbm+BrCUgQiX4HYQznvPacpVCLEQf5uFrxncOc7o7QH3GdmhXzfw94oe6HP JJyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=rgqwmFRxzwOdfVWLFNi4wPd71Kn9Ch3kbz5vzqYXZHk=; b=VSv2YjtPE0Fri4j9reKQlGqDtZxI9zGE4mMjP65BjDq3m2Ix+3OvtBvro68MVJzyY+ tj7p4qRBqE19CIvtvvy1PICWLYKWwQ7/eIWgmHyGegUbWi/a+xM3gWRR1zxN75THH8xN wUZFas8LboH6ZZx4Y9MDVY+PqwmF8KCwX+kxtQRPDm8rBOF86fUyCJtPmUbp5mAc07MW v6bsOfSvyZk2SKHCPL1yAYzyH9aWeR3qgXH4myR/ED8Bp/0aUb3WD3W6IwE8hLlR5FOH g19t8lWw+/gjkl7nhoKifdqPWi4bqFl0ZW4VG145L+owUdva4v0UA0xGhFEm2P91bolC qP+g== X-Gm-Message-State: ALyK8tI5GsSbYEo+JyH88GBjlrL+ZdaWNZ6D20n+YSLE421ok/HCAbRdvuZBewP2gd/fAX4IY+2k+8OvpcahLQ== X-Received: by 10.194.157.10 with SMTP id wi10mr14325465wjb.159.1467018441417; Mon, 27 Jun 2016 02:07:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Baskakov Daniel Date: Mon, 27 Jun 2016 09:07:11 +0000 Message-ID: Subject: Re: Synchronous Lucene index update tests occasionally fail To: Lucene Users Content-Type: multipart/alternative; boundary=089e0122ebe2146a7305363ed9d6 archived-at: Mon, 27 Jun 2016 09:07:30 -0000 --089e0122ebe2146a7305363ed9d6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I've just noticed that not only dynamic adding/removing entities tests fail, but also a simple indexing. Here is a boiled down structure of the test: @BeforeClass public static void beforeClass() throws Exception { // ContextManager is a domain model contextManager =3D createContextManager(); searcher =3D new ServerSearcher(Collections.singletonList(indexingSettings), false); searcher.openRamDirectory(); // Context is a domain model item, it has variables. One of the contexts has "variableWithHelpString" variable. // searcher.createContextDocument(aContext) creates a Lucene document with a field: new TextField(field, value, Field.Store.YES) for (Context aContext : contextManager) { Document doc =3D searcher.createContextDocument(aContext); final Term idTerm =3D new Term(ID_FIELD, doc.get(ID_FIELD)); // using updateDocument here because the domain model is dynamic searcher.getIndexWriter().updateDocument(idTerm, doc); } } @Test public void testVariableName() throws Exception { searcher.commitNow(); String text =3D "variableWithHelpString"; final MultiFieldQueryParser queryParser =3D new MultiFieldQueryParser(ServerSearcher.ALL_SEARCH_FIELDS, searcher.analyzer); queryParser.setDefaultOperator(QueryParser.Operator.AND); text =3D text.replaceAll("(\\w+)", "$1\\*"); final Query query =3D queryParser.parse(text); final IndexSearcher searcher =3D searcher.acquireIndexSearcher(); TopScoreDocCollector docCollector =3D TopScoreDocCollector.create(5000)= ; searcher.search(query, docCollector); final ScoreDoc[] scoreDocs =3D docCollector.topDocs().scoreDocs; assertThat(scoreDocs.length(), is(1)); } Also there is a comprehensive logging during the test invocation. And it can be seen that document for the context with 'variableWithHelpString' is properly created and added to IW: 12:34:23,499 DEBUG ag.context.search Variable Definition document added to index: Document stored,indexed,tokenized,omitNorms,indexOptions=3DDOCS,numericType=3DINT,nu= mericPrecisionStep=3D8 stored,indexed,indexOptions=3DDOCS stored,indexed,tokenized stored,indexed,tokenized stored,indexed,tokenized stored,indexed,tokenized stored,indexed,tokenized stored,indexed,tokenized> - - - - - - - - - - [main] Here is the later log output for search operation that returns no document: 12:34:23,796 DEBUG ag.context.search Search 'name:variablewithhelpstring* type:variablewithhelpstring* description:variablewithhelpstring* help:variablewithhelpstring* fields:variablewithhelpstring* outputFields:variablewithhelpstring* value:variablewithhelpstring*' took '0' seconds and returned 0 hits - - - - - - - - - - [main] Daniel. =D0=BF=D0=BD, 27 =D0=B8=D1=8E=D0=BD. 2016 =D0=B3. =D0=B2 11:12, Michael McC= andless : > Can you boil this down to a small standalone test case showing the issue? > > Mike McCandless > > http://blog.mikemccandless.com > > On Mon, Jun 27, 2016 at 4:03 AM, Baskakov Daniel wrote= : > >> Thank you Mike. >> >> Commit is performed after each indexing op in unit tests only: >> >> public void commitNow() throws IOException >> { >> if (getIndexWriter().hasUncommittedChanges()) >> { >> getIndexWriter().commit(); >> } >> } >> >> In production environment I have a timer that performs commit periodical= ly >> if required. >> >> I do reopen near-real-time IR before every test search (thanks to your >> blog!): >> >> private IndexSearcher acquireIndexSearcher() throws IOException >> { >> if (searcherManager =3D=3D null) >> { >> searcherManager =3D new SearcherManager(getIndexWriter(), true, nu= ll); >> } >> searcherManager.maybeRefreshBlocking(); >> return searcherManager.acquire(); >> } >> >> But the problem is still there. >> >> Daniel. >> >> =D1=87=D1=82, 23 =D0=B8=D1=8E=D0=BD. 2016 =D0=B3. =D0=B2 17:19, Michael = McCandless < >> lucene@mikemccandless.com>: >> >> > You must reopen your IndexReader to see recent changes to the index. >> > >> > But, IW.commit after each indexing op is very costly. >> > >> > It's much better to get near-real-time readers, e.g. from a >> > SearcherManager that you pass your IW instance too, after each set of >> > changes that you now need to search. >> > >> > As long as you call SearcherManager.maybeRefreshBlocking after changes >> to >> > the IW, the resulting reopened reader will reflect your index changes. >> > >> > Mike McCandless >> > >> > http://blog.mikemccandless.com >> > >> > On Thu, Jun 23, 2016 at 7:47 AM, Baskakov Daniel >> wrote: >> > >> >> Originally i've posted the question at stackoverflow.com but without >> any >> >> reply. So I hope someone can help me in the official list. >> >> >> >> I'm testing that dynamic changes of the domain model reflects at the >> >> Lucene >> >> index. Special event listeners (synchronous, no multithreading here) >> are >> >> executed when the domain model components change. Listeners update th= e >> >> Lucene index: >> >> >> >> Document doc =3D createDocumentForComponent(domainModelComponent); >> >> indexWriter.updateDocument(docTerm, doc); >> >> indexWriter.commit(); >> >> >> >> Then I perform searching by a query that contains recently added >> changes. >> >> Most of the time tests work perfect, but sometimes they fail >> (especially >> >> in >> >> automated builds). >> >> >> >> I've tried to acquire an IndexSearcher by different ways: create a ne= w >> >> searcher on the same Directory or obtain it via SearcherManager. >> >> >> >> Is there a way to made recent index changes available to index search= er >> >> with 100% confidence? >> >> >> > >> > >> > > --089e0122ebe2146a7305363ed9d6--