Skip to content

Commit

Permalink
Finished up.
Browse files Browse the repository at this point in the history
Local doc copying and copying of the purged_docs object
from the header both now work (as of latest couchstore)
  • Loading branch information
apage43 committed Feb 24, 2012
1 parent 92d5991 commit d3de3f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -2,7 +2,7 @@ all:
cd build && make cd build && make


check: all check: all
rm build/*.compact rm build/*.compact || true
cp packthis.couch build/packthis.couch cp packthis.couch build/packthis.couch
cd build && ./compactor packthis.couch cd build && ./compactor packthis.couch
cd build && couch_dbinfo packthis.couch* cd build && couch_dbinfo packthis.couch*
Expand Down
3 changes: 3 additions & 0 deletions src/btree_copy.hh
Expand Up @@ -83,6 +83,9 @@ class NodePointer {
void makeByIdRoot(DBHandle &db) { void makeByIdRoot(DBHandle &db) {
setAsRoot(&(db.get()->header.by_id_root)); setAsRoot(&(db.get()->header.by_id_root));
} }
void makeLocalDocsRoot(DBHandle &db) {
setAsRoot(&(db.get()->header.local_docs_root));
}
protected: protected:
friend class NodeBuilder; friend class NodeBuilder;
uint64_t pointer_; uint64_t pointer_;
Expand Down
13 changes: 12 additions & 1 deletion src/compactor.cc
Expand Up @@ -112,7 +112,9 @@ int build_id_index(DBHandle& new_db, FILE* tempfile)
int local_doc_copy(couchfile_lookup_request* rq, void* k, sized_buf *v) int local_doc_copy(couchfile_lookup_request* rq, void* k, sized_buf *v)
{ {
sized_buf *key = static_cast<sized_buf*>(k); sized_buf *key = static_cast<sized_buf*>(k);
printf("%.*s\n", (int) key->size, key->buf); NodeBuilder *output = static_cast<NodeBuilder*>(rq->callback_ctx);
output->addItem(KVPair(BufPtr(new Buffer(key->buf, key->size)),
BufPtr(new Buffer(v->buf, v->size))));
return 0; return 0;
} }


Expand All @@ -133,7 +135,11 @@ int copy_local_docs(DBHandle& original_db, DBHandle& new_db)
rq.num_keys = 1; rq.num_keys = 1;
rq.fold = 1; rq.fold = 1;
rq.fd = original_db.get()->fd; rq.fd = original_db.get()->fd;
rq.fetch_callback = local_doc_copy;
rq.callback_ctx = &output;
btree_lookup(&rq, original_db.get()->header.local_docs_root->pointer); btree_lookup(&rq, original_db.get()->header.local_docs_root->pointer);
output.flush();
shared_ptr<NodePointer> local_docs_root = build_pointers(output);
return 0; return 0;
} }


Expand All @@ -147,6 +153,11 @@ int finish_compact(DBHandle& original_db, DBHandle& new_db)
if(error) return error; if(error) return error;
new_db->header.update_seq = original_db->header.update_seq; new_db->header.update_seq = original_db->header.update_seq;
new_db->header.purge_seq = original_db->header.purge_seq; new_db->header.purge_seq = original_db->header.purge_seq;
new_db->header.purged_docs = original_db->header.purged_docs;
//**_Hackish_**! -Move- the purged docs object onto to the new db's header.
//We have to clear it from the original so it isn't double free()'d.
//Important we don't actually write a new header for the original DB.
original_db->header.purged_docs = NULL;
new_db.commit(); new_db.commit();
return 0; return 0;
} }
Expand Down

0 comments on commit d3de3f3

Please sign in to comment.