<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/2041/1/7/_/styles/combined.css?spaceKey=TOP&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 (2)</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" >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.) <br> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h4. Candidate Technologies <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">h4. Candidate Technology Requirements <br></td></tr>
<tr><td class="diff-unchanged" > <br>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: <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p><DRAFT... Work in progress></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=15&modificationDate=1300203576391"
alt="A&#32;Gliffy&#32;Diagram&#32;named&#58;&#32;Basic&#32;State&#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-CandidateTechnologyRequirements"></a>Candidate Technology Requirements</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: Database is a simple data file containing records, each is a pair of a key and a value. Simple C API for adding, deleting and accessing key-value pairs. For replication, need the more complete Tokyo Tyrant, a high-concurrency network interface. Tokyo Cabinet not available on Windows, but some ports using cygwin reported. <br/>
<b>Final Assessment:</b> Doesn't meet platform requirements.</li>
</ul>
<ul>
        <li><em>Berkeley DB High Availability</em><br/>
<b>License:</b> Sleepycat License <br/>
<b>General Notes:</b> Key/value database. APIs Available in almost all programming languages including ANSI-C, C++, Java, C#, Perl, Python, Ruby and Erlang. 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> Promising! </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>
<h5><a name="StateReplicatorPersistenceOptions-Conclusion"></a>Conclusion</h5>
<p>The most promising solution we've looked at is Berkeley DB High Availability. The Sleepycat License is compatible with GPL V2, replication is via network log records for each transaction (which should be relatively fast), APIs are available for most languages, and it's supported on all major platforms. </p>
<p>However, given our stated requirements and goals, we should also consider a simple modification to our current in-memory implementation which would allow a State Replicator instance to operate in a standby mode, where it is a listener to an active State Replicator. When in standby mode, the State Replicator would simply update it's in-memory state cache without forwarding the updates. This would provide a solution where, from the system's point-of-view, there is no longer a single point of failure. While the data would not be persisted to disk, it would be replicated and available for fast-switching to active mode, just as any other component. It is indeed debatable, with the short time frame in which component state will remain relevant, as to whether any disk-persisted scheme will meet our latency requirements. </p>
<map name='GLIFFY_MAP_12550532_standby_replicator'></map>
<table width="100%">
<tr>
<td align="left">
<table>
<caption align="bottom">
</caption>
<tr>
<td>
<img style="border: none; width: 500px; height: 400px;"
usemap="#GLIFFY_MAP_12550532_standby_replicator"
src="/wiki/download/attachments/12550532/standby+replicator.png?version=3&modificationDate=1300203541811"
alt="A&#32;Gliffy&#32;Diagram&#32;named&#58;&#32;standby&#32;replicator"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</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=39&originalVersion=38">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/TOP/State+Replicator+Persistence+Options?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>