Giter Club home page Giter Club logo

unsplit's Introduction

#unsplit - A framework for resolving Mnesia netsplits#

Copyright (c) 2010 Erlang Solutions Ltd.

Version: 0.5

Unsplit is a framework for registering merge functions that will be called any time mnesia tries to heal from netsplits.

The default behaviour of mnesia is not to attempt automatic merge after a 'partitioned network' event. It detects and reports the condition, but leaves it up to the user to resolve the problem.

Mnesia itself offers a few remedies: restart from backup, or elect to unconditionally reload tables from one or more nodes - in both cases data loss is very likely.

Unsplit starts a subscription on the 'partitioned network' event, and forces Mnesia to merge the "islands" that have been separated. It inserts itself into the schema merge transaction, claiming table locks on all affected tables. It then runs user-provided merge callbacks for each table, fetching data from one side, comparing the objects, and writing back the data that should be kept.

Writing an Unsplit method

Unsplit methods are table-specific, although a default method can be set using the unsplit application environment variable

{default_method, {Module, Function, ExtraArgs}}

The given method is called with the following arguments:

apply(Module, Function, [init, Table, Attributes | ExtraArgs]) -> ret()

to set up the merge. Then, data will be fetched using a given fetch strategy, and the fetched data will be handed to the merge function as:

apply(Module, Function, [data(), state()]) -> ret()

The return value, ret() is defined as:

ret() :: stop
       | {ok, state()}
       | {ok, actions(), state()}
       | {ok, actions(), strategy(), state()}

actions() :: [action()]

action() :: {write, Objects} | {delete, Objects}

strategy() :: all_keys | {ModS, FunS}

If a custom fetch strategy function is given, it will be called as

apply(ModS, FunS, [Table, RemoteNode, state()]) -> {ok, data(), state()}

Note that state() is whatever the merge function creates. The unsplit framework treats it as an opaque object, but the fetch function needs to do the same, or be aware of its definition.

The format of data() can be anything that the merge function accepts, but if the built-in strategy all_keys is used, it will have the format:

data() :: [{[object()], [object()]}]

where each 2-tuple represents the data matching a given key on each side of the split. Thus, [{[{mytab, 1, a}], []}] would mean that the object {mytab, 1, a} only exists on the side where the merge process is running, but is not found on the other side. [{[{mytab,2,a}], [{mytab,2,b}]}] would mean that conflicting versions of the object {mytab,2} were found.

##Modules##

unsplit
unsplit_lib
unsplit_reporter
unsplit_server
unsplit_vclock

unsplit's People

Contributors

uwiger avatar spawnthink avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.