You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Adam Kocoloski (JIRA)" <ji...@apache.org> on 2011/01/11 16:59:47 UTC

[jira] Commented: (COUCHDB-1021) Compacting a database does not preserve the purge_seq

    [ https://issues.apache.org/jira/browse/COUCHDB-1021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12980152#action_12980152 ] 

Adam Kocoloski commented on COUCHDB-1021:
-----------------------------------------

Hi Mike, thanks for the bug report and the patch.  It looks like that patch is not quite right, though.  If a user purges some docs, compacts the DB, then queries an out-of-date view, the #db_header.purged_docs pointer will be nil and the view updater will probably just crash.  I think you'd need to read the purged_docs term from the old file, write it to the new file, and update #db_header.purged_docs for the compacted DB with the new pointer.

I think the decision to do this in start_copy_compact is just fine.  If a user just purged a huge block of documents it'll be nice to copy that block to the compacted file outside of the db_updater server loop.  Purging during compaction can never happen, so no worries there.

Do you have time to take a crack at updating the patch?


> Compacting a database does not preserve the purge_seq
> -----------------------------------------------------
>
>                 Key: COUCHDB-1021
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1021
>             Project: CouchDB
>          Issue Type: Bug
>          Components: Database Core
>    Affects Versions: 1.0.1
>         Environment: All platforms
>            Reporter: Mike Leddy
>            Priority: Minor
>
> On compacting a database the purge_seq becomes zero. As a result subsequently accessing any view will cause the view to be rebuilt from scratch. I resolved the issue for me by patching start_copy_compact, but this only works if you can guarantee there will be no purging done during compaction:
> --- couchdb-1.0.1/src/couchdb/couch_db_updater.erl
> +++ couchdb-1.0.1.new/src/couchdb/couch_db_updater.erl
> @@ -857,7 +857,7 @@
>  
>      commit_data(NewDb4#db{update_seq=Db#db.update_seq}).
>  
> -start_copy_compact(#db{name=Name,filepath=Filepath}=Db) ->
> +start_copy_compact(#db{name=Name,filepath=Filepath,header=#db_header{purge_seq=PurgeSeq}}=Db) ->
>      CompactFile = Filepath ++ ".compact",
>      ?LOG_DEBUG("Compaction process spawned for db \"~s\"", [Name]),
>      case couch_file:open(CompactFile) of
> @@ -869,7 +869,7 @@
>          couch_task_status:add_task(<<"Database Compaction">>, Name, <<"Starting">>),
>          {ok, Fd} = couch_file:open(CompactFile, [create]),
>          Retry = false,
> -        ok = couch_file:write_header(Fd, Header=#db_header{})
> +        ok = couch_file:write_header(Fd, Header=#db_header{purge_seq=PurgeSeq})
>      end,
>      NewDb = init_db(Name, CompactFile, Fd, Header),
>      unlink(Fd),
>  I am sure that there must be a better way of doing this.....

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.