# Corrupted index preventing save

**URL:** <https://www.ruby-forum.com/t/corrupted-index-preventing-save/74162>\
**Category:** Ferret\
**Created:** [October 31, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/corrupted-index-preventing-save/74162 "2006-10-31T18:02:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [October 31, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/corrupted-index-preventing-save/74162/1 "2006-10-31T18:02:25Z")

</div>

Hi, I’m using Rails/AAF with Ferret 0.10.11, and my index occasionally  
(every few weeks, roughly) becomes corrupted.

If the index is busted, until I rebuild it our users are unable to save  
anything. I get errors like the one below, and the save rolls back.

My question is, is there any way to catch the error, and continue with  
the save even if the model isn’t indexed? What would be ideal is if i  
could have a catch the error, and have it send me a notification, which  
would solve two problems: the save would still happen so our users  
wouldn’t be impacted, and I would know exactly when the index had become  
corrupted, and could rebuild it.

TIA for any help,  
John

here’s the error i’m getting:

Processing UserController#signup (for 72.227.101.170 at 2006-10-31  
11:23:06) [POST]  
Session ID: 7f854fa9eaf95becbb9723a9bd48f9c2  
Parameters: {“user”=\>{“subscribe\_to\_newsletter”=\>“0”,  
“password\_confirmation”=\>"[FILTERED]", “terms”=\>“1”,  
“password”=\>"[FILTERED]", “login”=\>“jmcgrath”,  
“email”=\>“removed\_email\_address@domain.invalid”}, “commit”=\>“Sign Up”, “action”=\>“signup”,  
“controller”=\>“user”}  
Unable to send confirmation E-Mail:  
Lock Error occured at \<except.c\>:103 in xpop\_context  
Error occured in index.c:5371 - iw\_open  
Couldn’t obtain write lock when opening IndexWriter

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/corrupted-index-preventing-save/74162/2 "2006-11-07T10:49:42Z")

</div>

On 31.10.2006, at 18:02, John Mcgrath wrote:

> Hi, I’m using Rails/AAF with Ferret 0.10.11, and my index occasionally  
> (every few weeks, roughly) becomes corrupted.
> 
> If the index is busted, until I rebuild it our users are unable to  
> save  
> anything. I get errors like the one below, and the save rolls back.

The acts\_as\_ferret plugin employs ActiveRecord callbacks such as  
after\_update to index the models. If an exception is thrown inside a  
callback method, the action is rolled back.

> My question is, is there any way to catch the error, and continue with  
> the save even if the model isn’t indexed?

Several ways. You could overwrite the save mehtod (either on a per-  
model-basis or for ActiveRecord::Base) to read:

def save  
begin  
create\_or\_update  
rescue =\> any\_exception  
# deal with exceptions you can handle or re-raise  
end  
end

Or, even better, you could patch the acts\_as\_ferret code to resort to  
a callback such as “rescue\_error\_in\_ferret”. See the ‘ferret\_create’  
method of ‘acts\_as\_ferret/lib/instance\_methods.rb’. You’d basically  
wrap the method in a begin/rescue block and see if the model  
respond\_to? :rescue\_error\_in\_ferret. If it does, call that method or  
else re-raise the exception.

Cheers,  
Andy

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [November 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/corrupted-index-preventing-save/74162/3 "2006-11-07T10:51:24Z")

</div>

On Tue, Oct 31, 2006 at 07:47:30PM +0100, Andreas K. wrote:

> The acts\_as\_ferret plugin employs ActiveRecord callbacks such as  
> begin  
> respond\_to? :rescue\_error\_in\_ferret. If it does, call that method or  
> else re-raise the exception.

overwriting the callback handlers in your model would be another  
possibility:

class MyModel \< AR::Base

acts\_as\_ferret …

# ferret\_create is declared by aaf, and used for before\_update and

# before\_create events.

alias :old\_ferret\_create :ferret\_create  
def ferret\_create  
old\_ferret\_create  
rescue  
# handle the error…  
true # tell AR everything is fine  
end

end

Jens

–  
webit! Gesellschaft für neue Medien mbH [www.webit.de](http://www.webit.de)  
Dipl.-Wirtschaftsingenieur Jens Krämer removed\_email\_address@domain.invalid  
Schnorrstraße 76 Tel +49 351 46766 0  
D-01069 Dresden Fax +49 351 46766 66
