Stelio
Stelio

Reputation: 681

Hot Swappable Index in Sitecore 7.2 with Lucene

I was experimenting about the new Sitecore 7.2 functionality SwitchOnRebuildLuceneIndex

Apparently, this functionality allow me to access in a readonly mode my Index meanwhile I am rebuilding the index.

Is there any way to have a full operational index (not read-only) meanwhile I am rebuilding the index?

The test that I am performing is the following one:

1) Rebuild a custom index with 30k items (it takes 30 sec)

2) meanwhile the index is rebuilding: Add a Sitecore Items (via code)

3) meanwhile the index rebuilding: access the custom index (via code) to get the count of items

4) after the index completed the rebuild: access the custom index (via code) to get the count of items

In step 3 it returns the original item counts 30000 In step 4 it returns the updated item counts 30001

thanks for the help Stelio

Upvotes: 3

Views: 927

Answers (2)

Tamas Molnar
Tamas Molnar

Reputation: 827

If you want to keep track of the changes, which happened during the index rebuild you could use the IntervalAsynchronousStrategy as your index rebuild strategy.

    <strategies hint="list:AddStrategy">
      <intervalAsyncMaster type="Sitecore.ContentSearch.Maintenance.Strategies.IntervalAsynchronousStrategy, Sitecore.ContentSearch">
        <param desc="database">master</param>
        <param desc="interval">00:00:05</param>
        <!-- whether full index rebuild should be triggered if the number of items in history engine exceeds ContentSearch.FullRebuildItemCountThreshold -->
        <CheckForThreshold>true</CheckForThreshold>
      </intervalAsyncMaster>
    </strategies>

This reads through the History table and updates your index accordingly. If you check the Sitecore implementation of this class, you can see that it handles the rebuilding event. If rebuilding is running it doesn't do anything and waits for the next time it is scheduled, and if the rebuild has finished it collects the entries from History table and applies them to the index. See Run method of the class:

...
    if (IndexCustodian.IsIndexingPaused(this.index))
    {
        CrawlingLog.Log.Debug(string.Format("[Index={0}] IntervalAsynchronousUpdateStrategy triggered but muted. Indexing is paused.", this.index.Name), null);
    }
    else if (IndexCustodian.IsRebuilding(this.index))
    {
        CrawlingLog.Log.Debug(string.Format("[Index={0}] IntervalAsynchronousUpdateStrategy triggered but muted. Index is being built at the moment.", this.index.Name), null);
    }
    else
    {
        CrawlingLog.Log.Debug(string.Format("[Index={0}] IntervalAsynchronousUpdateStrategy executing.", this.index.Name), null);
        HistoryEntry[] history = HistoryReader.GetHistory(this.Database, this.index.Summary.LastUpdated); 

...

Upvotes: 0

Zachary Kniebel
Zachary Kniebel

Reputation: 4794

I do not believe that this will be possible. Conceptually speaking, Sitecore is essentially a software that makes databases more user-friendly and defines a structure that both technical and non-technical persons can understand and follow. What you are talking about goes against the concept of ACID, database locks and transactions. I have commented with more technical (database) annotations on your steps, inline, below:

  1. Rebuild a custom index... - Place a lock on the items in the database and start transaction
  2. meanwhile ...: add a sitecore item... - A separate transaction running against the items, though not affecting the locked set that the transaction started in step 1 is using
  3. meanwhile ...: access the custom... - Another transaction runs after the transaction in step 2, thus including the count of all items (including the locked set and the newly added item)
  4. after the index completed... - Transaction 1 completed and lock released; Get count of items from custom index returns a different count than count of items if not counted from the index (the latter is greater, as a new item was added)

As such, step 3 returns the new count of items and step 4 returns the original.

Upvotes: 1

Related Questions