Welcome to JCache

Copyright © 2013-2015 Jim Rosenblum

Version: v0.9.5

Authors: Jim Rosenblum (jrosenblum@carelogistics.com).

JC

Erlang, Distributable, In-Memory Cache

JSON-Query; Consistency Assist; and Simple, TCP Interoperability Protocol

Features

Cache Functions (jc)

Consistency Supported Functions (jc_s)

Identical to the Create and Evict family of functions of the jc module (see above), except:

Eviction Manager Functions (jc_eviction_manager)

Pub/Sub Functions (jc_psub)

{jc_node_events, {nodedown, DownedNode, [ActiveNodes],[ConfiguredNodes]}}

{jc_node_events, {nodeup, UppedNode, [ActiveNodes],[ConfiguredNodes]}}

Indexing Functions (jc_store)

Bridge Functions (jc_bridge)

{From, {Fn, P1, P2,...}}

for each paramater, as in

jc_bridge ! {Pid, {put, Map, Key, Value}}

{From, {node_topic_sub}} -> ok | {error, badarg}, client will recieve:

{jc_node_events, {nodedown, DownedNode, [ActiveNodes],[ConfiguredNodes]}}

or

{jc_node_events, {nodeup, UppedNode, [ActiveNodes],[ConfiguredNodes]}}

{From, {node_topic_unsub}} -> ok.

Interoperability: String protocol

This is a binary-encoded, string protocol used to provide socket-based interoperability with JC.

All messages to the cache system are string representations of a tuple, All messages form the caching system to the client are JSON

The protocol defines three message types: CONNECT, CLOSE and COMMAND all of which are binary strings consisting of an 8-byte size followed by the actual command messages.

Responses are also binary strings with an 8-byte size prefix.

The CONNECT command initiates a session,

M = <<"{connect,{version,\"1.0\"}}">>

Size is 25, so the CONNECT message is:

<<25:8, M/binary>> = 
<<25,40,58,99,111,110,110,101,99,116,32,123,58,118,101,
  114,115,105,111,110,32,49,46,48,125,41>>

The server will respond to a CONNECT command with either an error or the encoded version of {"version":" "1.0""}

<<15:8, <<"{\"version\":1.0}">> = 
<<15,123,34,118,101,114,115,105,111,110,34,58,49,46,48,125>>

The CLOSE command closes the socket, ending the session

M = <<"{close}">>

 Size is 7 so the CLOSE message is:
 <<7,123,99,108,111,115,101,125>>

COMMAND messages are string versions of the tuple-messages which jc_bridge uses only without the self() parameter. For example

{self(), {put, Map, Key, Value}} becomes 
{put, Map, Key, Value}

The return will be an encoded version of a JSON string. A client session might look as follows:

client:send("{put, evs, \"1\", \"{\\\"value:\\\":true}\"}")
<<"{\"ok\":1}">>

client:send("{get, evs, \"1\"}"),
    <<"{\"ok\":"{\\\"value\\\":true}\"}">>

Configuration

Application Modules

Net Split/Join Strategy

Mnesia does not merge on its own when a node joins (returns) to a mesh of nodes. There are two situations where this is relevant:

* j_cache nodes start in a disconnected state so more than one initiates a new cluster and then, subsequently, those nodes join into one cluster; * A node drops out of the cluster due to some network glitch and then rejoins.

To handle these situations, whenever a cluster is created by a Node (node@123.45.67, for example), it creates a ClusterId - its Node name (node@123.45.67), for that cluster.

Given this ClusterId, we have the following strategy:

1. _Cluster Creation_: creates an initial ClusterId; 2. _Nodedown_: If the Node that created the cluster dissapears, a surviving Node changes the ClusterId such that ClusterId is now this new Node's name. In the case of a disconnected newtwork, one of the islands will have the original ClusterId Node dissapear, and it will create a new one as described. 3. _Nodeup_ Whenever a Node appears, an arbitary Node ensures that any Nodes that report a different ClusterId (different than the arbitrary Node's ClusterId) are killed to be restarted by the hearbeat application. If any Nodes required restarting, the entire cache is flushed or not per policy in config.sys.

Build Instructions

[root@db01] git clone https://github.com/jr0senblum/jc.git

Documentation

[root@dbo1] ./rebar3 edoc


Generated by EDoc