Merkle Trees are used as an anti-entropy mechanism in several distributed, replicated key/value stores:
No doubt an anti-entropy mechanism is A Good Thing - transient failures just happen, in production. I'm just not sure I understand why Merkle Trees are the popular approach.
Sending a complete Merkle tree to a peer involves sending the local key-space to that peer, along with hashes of each key value, stored in the lowest levels of the tree.
Diffing a Merkle tree sent from a peer requires having a Merkle tree of your own.
Since both peers must already have a sorted key / value-hash space on hand, why not do a linear merge to detect discrepancies?
I'm just not convinced that the tree structure provides any kind of savings when you factor in upkeep costs, and the fact that linear passes over the tree leaves are already being done just to serialize the representation over the wire.
To ground this out, a straw-man alternative might be to have nodes exchange arrays of hash digests, which are incrementally updated and bucketed by modulo ring-position.
What am I missing?
What Is a Merkle Tree? Merkle trees, also known as Binary hash trees, are a prevalent sort of data structure in computer science. In bitcoin and other cryptocurrencies, they're used to encrypt blockchain data more efficiently and securely.
Merkle Trees are used in Dynamo to identify any inconsistencies between nodes. Individual nodes maintain separate Merkle Trees for the key ranges that they store and they can be used to quickly work out if data is consistent and if not, identify which pieces of information need to be synchronised.
In very simple terms, a Merkle Tree is a way of structuring data that allows a large body of information to be verified for accuracy both extremely efficiently and quickly. They have become a crucial component of blockchain technology and cryptocurrency, so let's take a closer look.
Merkle trees limit the amount of data transferred when synchronizing. The general assumptions are:
A Merkle Tree exchange would look like this:
In the typical case, the complexity of synchronizing the key spaces will be log(N). Yes, at the extreme, where there are no keys in common, the operation will be equivalent to sending the entire sorted list of hashes, O(N). One could amortize the expense of building Merkle trees by building them dynamically as writes come in and keeping the serialized form on disk.
I can't speak to how Dynamo or Cassandra use Merkle trees, but Riak stopped using them for intra-cluster synchronization (hinted handoff and read-repair are sufficient in most cases). We have plans to add them back later after some internal architectural bits have changed.
For more information about Riak, we encourage you to join the mailing list: http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With