Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8258510D9F for ; Thu, 7 Nov 2013 17:18:46 +0000 (UTC) Received: (qmail 34493 invoked by uid 500); 7 Nov 2013 17:18:43 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 34391 invoked by uid 500); 7 Nov 2013 17:18:38 -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 34383 invoked by uid 99); 7 Nov 2013 17:18:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 17:18:36 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ravikumar.govindarajan@gmail.com designates 209.85.214.48 as permitted sender) Received: from [209.85.214.48] (HELO mail-bk0-f48.google.com) (209.85.214.48) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 17:18:30 +0000 Received: by mail-bk0-f48.google.com with SMTP id u10so356351bkz.21 for ; Thu, 07 Nov 2013 09:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=798e53uHt738iFJnT6/AdxkF/4QcAR80Qb7t9qmUCO8=; b=duZq3nbxqzSfI5jTUrWi5bXiHBQguDYTWeAQSa7vqoPgJnob7dsSw8kSOLIkvU0RN7 5vOE7ntwoVQRKWDZAf7LPZeDHnm8AJK9yvqi/7B/RJ3aK/1fH+b/YhrYMmnH7x3qWqxF 8+42Z+R4MzDcsAkiwLlJ6Q5QUe0a1bnjluDgwsFzkYaDVwWRL51jx1VLMPzuYKpuhUg6 3DZCTaB1ZkOHl61UDKg0cgRtGYG9wsLGRqT0pHtjH0kLhNALSa/GG5YMxnFMWjYA5Y8B U0JjLUhREwGRuG/1+d4A02CN2QodmIOq/zvwOQ37sshLSd6z/uHZ7Wd4uWPdaTF9eRsn vf7g== MIME-Version: 1.0 X-Received: by 10.204.101.9 with SMTP id a9mr52271bko.106.1383844689706; Thu, 07 Nov 2013 09:18:09 -0800 (PST) Received: by 10.205.102.198 with HTTP; Thu, 7 Nov 2013 09:18:09 -0800 (PST) In-Reply-To: References: Date: Thu, 7 Nov 2013 22:48:09 +0530 Message-ID: Subject: Re: IndexReader close listeners and NRT From: Ravikumar Govindarajan To: "java-user@lucene.apache.org" Content-Type: multipart/alternative; boundary=001a113337a427b19c04ea9973e2 X-Virus-Checked: Checked by ClamAV on apache.org --001a113337a427b19c04ea9973e2 Content-Type: text/plain; charset=ISO-8859-1 Thanks Mike. If you look at my impl, I am using the getCoreCacheKey() only, but keyed on a ReaderClosedListener and purging it onClose(). When NRT does reopens, will it invoke the onClose() method for the expired-reader?. I saw that FieldCacheImpl is using a CoreClosedListener, whereas I am using a ReaderClosedListener. What is the difference between these two? I will surely look at the FBS replacement you have pointed out. BTW, this method actually runs during opening of an index for the first-time. May be for clarity and organisation, I will refactor this code as you have suggested On Thursday, November 7, 2013, Michael McCandless wrote: > Hi, a few comments on quickly looking at the code... > > It's sort of strange, inside the Weight.scorer() method, to go and > build an IndexSearcher and run a whole new search, if the cache entry > is missing. Could you instead just do a top-level search, which then > populates the cache per-segment? > > Also, FixedBitSet is better here than OpenBitSet: it should be a bit > faster, because OpenBitSet is "elastic". > > When you use the core cache key, it does not change for a > SegmentReader that was reopened with new deletes; this is the whole > point of the core cache key. So, if deletes changed for a segment and > you reopened, your cache entry will reuse whatever was created the > first time for that segment. If deletes matter, then it's usually > best to look at liveDocs "live" and fold them in, instead of > regenerating the whole cache entry. > > > Mike McCandless > > http://blog.mikemccandless.com > > > On Thu, Nov 7, 2013 at 8:04 AM, Ravikumar Govindarajan > > wrote: > > Thanks Mike. Can you help me out with one more question? > > > > I have a sample impl as below, where I am adding a ReaderClosedListener > to > > purge the BitSet. > > > > When using NRT with applyAllDeletes, old-reader will get closed and > > new-reader will open. In such a case, will the below impl-cache also be > > purged and re-built? > > > > I also saw that FieldCache uses a CoreClosedListener, instead of > > ReaderClosedListener and I need such a functionality. It will be great to > > maintain the BitSet cache at the cost of taking extra hit for testing > > deletes. > > > > @Override > > > > public Scorer scorer(AtomicReaderContext context, boolean > scoreDocsInOrder, > > boolean topScorer, Bits acceptDocs) { > > > > Object key = context.getReader().getCoreCacheKey(); > > > > OpenBitSet bitSet = cacheMap.get(key); > > > > if (bitSet == null) { > > > > reader.addReaderClosedListener(new ReaderClosedListener() { > > > > @Override > > > > public void onClose(IndexReader reader) { > > > > Object key = reader.getCoreCacheKey(); > > > > cacheMap.remove(key); > > > > } > > > > }); > > > > final OpenBitSet bs = new OpenBitSet(reader.maxDoc()); > > > > //Add the empty bit-set first > > > > cacheMap.put(key, bs); > > > > IndexSearcher searcher = new IndexSearcher(reader); > > > > //Do a search and populate the bitset > > > > return bs; > > > > } > > > > //Proceed with scoring logic > > > > } > > > > -- > > > > Ravi > > > > > > On Thu, Nov 7, 2013 at 4:28 PM, Michael McCandless < > > lucene@mikemccandless.com > wrote: > > > >> You need to call .getCoreCacheKey() on each of the sub-readers > >> (returned by IndexReader.leaves()), to play well with NRT. > >> > >> Typically you'd do so in a context that already sees each leaf, like a > >> custom Filter or a Collector. > >> > >> Mike McCandless > >> > >> http://blog.mikemccandless.com > >> > >> > >> On Thu, Nov 7, 2013 at 1:33 AM, Ravikumar Govindarajan > >> > wrote: > >> > I am trying to cache a BitSet by attaching to > >> IndexReader.addCloseListener, > >> > using the getCoreCacheKey() > >> > > >> > But, I find that getCoreCacheKey() returns the IndexReader object > itself > >> as > >> > the key. > >> > > >> > Whenever the IndexReader re-opens via NRT because of deletes, will it > >> mean > >> > that my cache will be purged, because a new IndexReader is opened? > >> > > >> > Are there ways to avoid this purging? > >> > > >> > -- > >> > Ravi > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > >> For additional commands, e-mail: java-user-help@lucene.apache.org > >> > >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > > --001a113337a427b19c04ea9973e2--