couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Kocoloski <>
Subject deleting the .compact file when we delete a DB
Date Sun, 17 May 2009 18:43:49 GMT
Hi devs, Dan Larkin brought up a problem on IRC today.  Deleting a DB  
during compaction orphans a .compact file, and subsequent requests for  
that DB will try to recover the DB using the .compact.

There's a good reason for the recovery procedure (it prevents data  
loss if the server crashes during a switch to the new .compact file),  
but it seems to me that when we delete a database we ought to make  
sure it's really deleted by explicitly removing the .compact file  
too.  Here's my proposed patch; Paul and figured it made sense to run  
this by the list before committing.  Best,


diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index c190862..3bf5972 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -303,6 +303,11 @@ handle_call({delete, DbName, _Options}, _From,  
Server) ->
              true = ets:delete(couch_dbs_by_lru, LruTime),
              Server#server{dbs_open=Server#server.dbs_open - 1}
+        %% Delete any leftover .compact file.  If we don't do this a  
+        %% request for this DB will try to open the .compact file and  
use it.
+        file:delete(FullFilepath ++ ".compact"),
          case file:delete(FullFilepath) of
          ok ->
              couch_db_update_notifier:notify({deleted, DbName}),

View raw message