Skip to content

Instantly share code, notes, and snippets.

@eiri
Last active December 9, 2016 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiri/c436914e4115651c78d1eef9de68c70e to your computer and use it in GitHub Desktop.
Save eiri/c436914e4115651c78d1eef9de68c70e to your computer and use it in GitHub Desktop.
Sequence diagram of CouchDB 2.0 compaction
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js"></script>
</head>
<body>
<div id="diagram"></div>
<script>
var request = new XMLHttpRequest();
request.open('GET', 'sequence.txt', false);
request.send();
var sequence = request.responseText;
var diagram = Diagram.parse(sequence);
diagram.drawSVG("diagram", {theme: 'simple'});
</script>
</html>
Title: CouchDB 2.0 view compaction
participant caller
participant couch_index
participant couch_index_updater
participant update/3
participant couch_index_compactor
participant compact/2
participant couch_mrview_compactor
participant couch_file
participant couch_file (old)
participant couch_btree
caller->couch_index: monitor
caller->couch_index: compact
couch_index->couch_index_compactor: compact
couch_index_compactor->compact/2: spawn_link
Note right of compact/2: through\n couch_mrview_index
compact/2->couch_mrview_compactor: compact
couch_mrview_compactor->couch_file: start_link
couch_mrview_compactor->couch_file: truncate
couch_mrview_compactor->couch_file: write_header
couch_mrview_compactor->couch_btree: foldl
couch_mrview_compactor->couch_mrview_compactor: compact_views
couch_mrview_compactor->couch_file: unlink
couch_mrview_compactor->compact/2: EmptyState
compact/2->couch_file: write_header
compact/2->couch_index: compacted
Note right of couch_index: through\n couch_mrview_index
couch_index->couch_mrview_compactor: swap_compacted
couch_mrview_compactor->couch_file: link
couch_mrview_compactor->couch_file: monitor
Note right of couch_mrview_compactor: Old index file
couch_mrview_compactor->couch_file: delete
Note right of couch_mrview_compactor: Compaction file
couch_mrview_compactor->couch_file: rename
couch_mrview_compactor->couch_file (old): unlink
couch_mrview_compactor->couch_file (old): demonitor
couch_mrview_compactor->couch_index: NewState
couch_index->couch_index_updater: restart
couch_index_updater->couch_file (old): monitor
couch_index_updater->couch_file (old): unlink
couch_index_updater->couch_file (old): exit
couch_index_updater->couch_file (old): demonitor
couch_index_updater->update/3: spawn_link
Note over update/3: couch_mrview_updater:start_update
Note over update/3: couch_mrview_updater:finish_update
update/3->couch_index_updater: exit (with updated)
Note over couch_index_updater: cast event updated
Note over couch_index: send_after\n with default\n delay 5 sec
couch_index->couch_index: commit
Note over couch_index: couch_mrview_index:commit/1
couch_index->couch_file: write_header
couch_index-->compact/2: recompact
compact/2-->compact/2: compact [recompact]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment