<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/2041/1/7/_/styles/combined.css?spaceKey=TOP&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/TOP/State+Replicator+Persistence+Options">State Replicator Persistence Options</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://wiki.asterisk.org/wiki/display/~khunt">Ken Hunt</a>
    </h4>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >*License:* Sleepycat License  <br>*General Notes:*  <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">-</span> <span class="diff-added-words"style="background-color: #dfd;">**</span> APIs:Available in almost all programming languages including ANSI-C, C++, Java, C#, Perl, Python, Ruby and Erlang. <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">-</span> <span class="diff-added-words"style="background-color: #dfd;">**</span> Replication: <span class="diff-added-words"style="background-color: #dfd;">Kay/value database.</span> A replication group consists of a one master and one or more read-only replicas. Write operations, such as key/value insert, update, or delete, are processed transactionally at the master. The master sends log records to all replicas. Replicas apply log records only when they receive a commit record. If a master fails, a replica takes over as master. <br></td></tr>
            <tr><td class="diff-changed-lines" >*Final <span class="diff-changed-words">Assessment:<span class="diff-added-chars"style="background-color: #dfd;">*</span></span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* _Kyoto Cabinet_ <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>&lt;DRAFT... Work in progress&gt;</p>

<h4><a name="StateReplicatorPersistenceOptions-Introduction"></a>Introduction</h4>

<p>Each major component of an Asterisk SCF system has a corresponding State Replicator component. This State Replicator component is a sink for current state changes from an active component, and a source of state changes for standby components. Initial implementations of the State Replicator components are based on a simple C++ template which uses an in-memory store of the replicated state. The state store is required to be able to provide the current state to late-joining backup components which may not have been online when the state updates were originally generated. </p>



<map name='GLIFFY_MAP_12550532_Basic_State_Replication'></map>
<table width="100%">
    <tr>
        <td align="left">
            <table>
                <caption align="bottom">
                                    </caption>
                <tr>
                    <td>
                        <img style="border: none; width: 400px; height: 200px;"
                                                          usemap="#GLIFFY_MAP_12550532_Basic_State_Replication"
                                                          src="/wiki/download/attachments/12550532/Basic+State+Replication.png?version=13&amp;modificationDate=1299872325217"
                             alt="A&amp;#32;Gliffy&amp;#32;Diagram&amp;#32;named&amp;#58;&amp;#32;Basic&amp;#32;State&amp;#32;Replication"/>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>




<p>Each state replication component, in its current implementation, represents a single point of failure in that the State Replicators themselves are not replicated. All of the State Replicators are, however, built to operate against well-defined APIs. This allows us to address the robustness of the state replication mechanisms in the abstract. In other words, as we look to increase the robustness of the system, we can focus on replicating generic state, independent of the particular components involved. To provide a complete replication platform, we desire to exploit a general purpose, off-the-shelf solution for persisting data and replicating that data across systems. (Note: As with all Asterisk SCF components, we fully expect 3rd parties will have reasons to build alternative implementations using different technologies than the persistence platforms that we choose to use.)</p>

<h4><a name="StateReplicatorPersistenceOptions-CandidateTechnologies"></a>Candidate Technologies</h4>

<p>To build component State Replicators that are not single points of failure, we want to identify an open-source solution that can do the following:</p>
<ul class="alternate" type="square">
        <li>Replicate the state store across servers in near-real-time. The low-latency requirement is driven by the highly dynamic nature of the state being replicated.</li>
        <li>Persist the state store (or provide the appearance of persistence, in that another process can take over in the event of failure of an Asterisk SCF State Replicator.)</li>
</ul>


<p>In addition, we want the solution to have the following characteristics: </p>
<ul class="alternate" type="square">
        <li>Simple to deploy</li>
        <li>Simple to program to</li>
        <li>Lightweight installation.</li>
        <li>Compatibility with GPL V2</li>
        <li>Available on all of our target platforms</li>
</ul>


<p>We've examined several database technologies with these goals in mind. Note that the assessments below are strictly related to our particular requirements! Selecting a database / data store solution is complex, and there is no single "best answer" for all cases. </p>

<h5><a name="StateReplicatorPersistenceOptions-TheRelationalDatabaseQuestion"></a>The Relational Database Question </h5>
<p>The first choice is to decide if the solution would benefit from a relational database. While it's common for relational database systems to include a replication capability, there are no other compelling reasons to consider such a solution. Typical relational databases are accessed (from a programming POV) using SQL, and thus require additional programming expertise for the Asterisk SCF developer. These applications are often fairly large installations due to their inherent complexity, requiring significant disk storage requirements, services to manage connections to the database, tools for administering the databse, etc. While relational databases excel when the requirements include such things as the ability to make fast queries on large datasets, or the ability to manage massive volumes of information, they don't offer much for our purposes other than the ability to replicate across servers. Even that feature is not based on standards, nor universally available across the various implementations. </p>

<p>For our needs, the installation overhead of a relational database and the added complexity for the developer seems to be a poor fit. Our state data is a simple set of keyed values, which are added to and removed over time. The State Replicator is pushing updates to all standby listeners in real-time, so when the data store is needed (for late joiners), it's needed in its entirety. The query engine of a relation database doesn't appear to be any benefit. </p>

<h5><a name="StateReplicatorPersistenceOptions-NonRelationalalternatives"></a>Non-Relational alternatives</h5>
<p>There is an ever growing field of non-relational data storage solutions. These include Object Oriented databases, document-oriented databases, graph-oriented, and others. Besides the persistence / structure mechanisms, we are also interested in how each of the technologies approach replication. With our stated need of near-real-time replication due to the highly dynamic nature of the data, many database replication schemes that work fine for other purposes will not provide the solution we are looking for. </p>

<p>Some that we have looked at:</p>

<ul>
        <li><em>CouchDB</em><br/>
<b>License:</b> Apache 2.0 <br/>
<b>General Notes:</b> RESTful HTML API, plugins for JavaScript/PHP/Ruby/Python/Erlang. <br/>
Accessible from C++ using cURLpp (MIT License), a C++ wrapper for libcURL (MIT License)<br/>
Replication: A peer-based distributed system that allows peers to access and update shared data while disconnected, and then perform bi-directional replication of updates. (This is not unlike git repository approach!) While convenient for things like synchronizing with a laptop that is offline for a lot of the time, it is not designed to be particularly fast at replication. <br/>
<b>Final Assessment:</b> Replication approach isn't suitable for our application. </li>
</ul>


<ul>
        <li><em>MongoDB</em><br/>
<b>License:</b> GNU AGPL v3.0.<br/>
<b>General Notes:</b> We could enumerate all the cool features of MongoDB, such as it's C++, C#, Java, Erlan, Python APIs, it's cool binary JSON-like serialization format, fast replication, and so forth... but it's license is far from ideal. <br/>
<b>Final Assessment:</b> Incompatible with our license requirements.</li>
</ul>


<ul>
        <li><em>Voldemort</em><br/>
<b>License:</b> Apache 2.0 <br/>
<b>General Notes:</b> Relatively new project, somewhat lacking in documentation. Written in Java, and there is a C++ client demo that only runs on Linux. Provides automatic replication. Keys and values can be complex objects such as maps or lists. <br/>
<b>Final Assessment:</b> Immature platform support</li>
</ul>


<ul>
        <li><em>Tokyo Cabinet</em><br/>
<b>License:</b> LGPL<br/>
General Notes: Simple C API for adding, deleting and accessing key-value pairs. <br/>
<b>Final Assessment:</b> </li>
</ul>


<ul>
        <li><em>Berkeley DB High Availability</em><br/>
<b>License:</b> Sleepycat License <br/>
<b>General Notes:</b> 
        <ul>
                <li>APIs:Available in almost all programming languages including ANSI-C, C++, Java, C#, Perl, Python, Ruby and Erlang.</li>
                <li>Replication: Kay/value database. A replication group consists of a one master and one or more read-only replicas. Write operations, such as key/value insert, update, or delete, are processed transactionally at the master. The master sends log records to all replicas. Replicas apply log records only when they receive a commit record. If a master fails, a replica takes over as master.<br/>
<b>Final Assessment:</b> </li>
        </ul>
        </li>
</ul>


<ul>
        <li><em>Kyoto Cabinet</em><br/>
<b>License:</b> GPL3  <br/>
API: Callable from C+<ins>, C, Java, Python, Ruby, Perl, and Lua. Written in C</ins>+. <br/>
<b>General Notes:</b> Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. Each key must be unique within a database.  <br/>
<b>Final Assessment:</b>  GPL3... sadness.</li>
</ul>


<ul>
        <li><em>Constant Database (CDB)</em><br/>
<b>License:</b> CDB Library is public domain. The rest of the package is <a href="http://en.wikipedia.org/wiki/License-free_software" class="external-link" rel="nofollow">license-free software</a>. <br/>
<b>General Notes:</b> A CDB instance can only be rebuilt, not modified. (Hence, the "constant" in the name). Not applicable, since we need to be able to add/remove keys from the database. <br/>
<b>Final Assessment:</b> "Constant" not applicable to our problem. </li>
</ul>


<ul>
        <li><em>Cassandra</em><br/>
<b>License:</b>: Apache 2.0.<br/>
<b>General Notes:</b> highly scalable, eventually consistent, distributed, structured key-value store. Supports synchronous / asynchronous replication. Provides a ColumnFamily-based data model richer than typical key/value systems.  On the contrary to the strong consistency used in typical relational databases (ACID for Atomicity Consistency Isolation Durability) Cassandra's at the other end of the spectrum (BASE for Basically Available Soft-state Eventual consistency). <br/>
<b>Final Assessment:</b> Replication model doesn't suit our highly-dynamic data. </li>
</ul>



    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://wiki.asterisk.org/wiki/display/TOP/State+Replicator+Persistence+Options">View Online</a>
        |
        <a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=12550532&revisedVersion=32&originalVersion=31">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/TOP/State+Replicator+Persistence+Options?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>