Module: caf_redis/plug_checkpoint

A plug to access an external checkpointing service that supports LUA scripting (Redis version >= 2.6).

The goal is to enable full pipelining of requests while still guaranteeing ownership of leases during operations.

Lua scripts are executed atomically by the server, and therefore, we can combine the check and the update in the same script.

We also implement coalescing of state updates across different CAs in a single script, to amortize the setup cost of LUA with several updates.

This improves dramatically Redis throughput, and also reduces client overhead.

The drawback is an increase in latency when the system is not under heavy load, and we need a cron to bound that increase.

Typical coalescing config values for a fast server are a maximum of 10 requests or 10 extra msec. Note that cron scheduling is not very accurate under load, and we also need a limit on the number of pending requests.

Source:

Extends

Methods

checkBits(bitfieldName, bits, cb0)

Check bits in a bitfield. If any is not set it returns false.

Parameters:
Name Type Description
bitfieldName string

The name of the bitfield.

bits Array.<number>

The index of bits to be checked.

cb0 cbType

A callback to return true if all set or null otherwise (or an error).

Source:

clearBits(bitfieldName, cb0)

Clear all bits in a bitfield.

Parameters:
Name Type Description
bitfieldName string

The name of the bitfield.

cb0 cbType

A callback to notify an error.

Source:

createMap(mapName, cb0)

Creates a Map or returns the contents of an existing one.

Parameters:
Name Type Description
mapName string

The name of the map.

cb0 cbType

A callback with the contents of the map.

Source:

deleteMap(mapName, cb0)

Deletes a Map.

Parameters:
Name Type Description
mapName string

The name of the map.

cb0 cbType

A callback with an error or null.

Source:

deleteState(id, cb0)

Removes the state of a CA in the checkpointing service.

Parameters:
Name Type Description
id string

An identifier for the CA.

cb0 cbType

A callback to notify an error deleting or its succesful completion if the argument is a falsy.

Source:

getCache(key, cb0)

Looks up a cache entry.

Parameters:
Name Type Description
key string

The cache entry key.

cb0 cbType

A callback returning the value (or null).

Source:

getState(id, cb0)

Gets the state of a CA from the checkpointing service.

Note that only the current (lease) owner can read this state.

Parameters:
Name Type Description
id string

An identifier for the CA.

cb0 function

A callback to notify an error getting the state or (in a second argument) the serialized state of that CA.

Source:

grabLease(id, leaseTimeout, cb0)

Grabs a lease that guarantees exclusive ownership of a CA by this node.

Parameters:
Name Type Description
id string

An identifier for the CA.

leaseTimeout number

Duration of the lease in seconds.

cb0 cbType

A callback with optional (error) argument containing the current owner in a remoteNode:string error field, if we failed to acquire the lease. Null error argument if we succeeded.

Source:

grabNodeLease(allPublicNodeIds, privateNodeId, leaseTimeout, cb0)

Picks an available public nodeId for this process and binds it with a lease to the private node identifier.

Parameters:
Name Type Description
allPublicNodeIds Array.<string>

A list of candidates for a public nodeId for this process.

privateNodeId string

A private unique identifier for the current node.js process.

leaseTimeout number

Duration of the lease in seconds.

cb0 function

A callback with an error if we cannot renew lease or the new external nodeId.

Source:

listNodes(allPublicNodeIds, cb0)

Lists status of nodes registered with this redis instance.

Parameters:
Name Type Description
allPublicNodeIds Array.<string> | null

A list of public nodeIds that we are interested on, or null if we want them all.

cb0 function

A callback with an error or an object with external nodeIds to private nodeIds (containing only the ones in use).

Source:

publishPubSub(topic, message, cb0)

Publishes a message to a channel using the PubSub service.

Parameters:
Name Type Description
topic string

The channel name.

message string

The message to be published.

cb0 cbType

A callback to return a publish error.

Source:

readMap(mapName, cb0)

Reads all the contents of a map.

Parameters:
Name Type Description
mapName string

The name of the map.

cb0 cbType

A callback with an error if it does not exist or an object (second argument) of type caf.changes : {version:number, remove:[], add:Array (i.e., flattened key value pairs)}

Source:

renewLeases(ids, leaseTimeout, cb0)

Renews a list of leases currently owned by this node.

Parameters:
Name Type Description
ids Array.<string>

A list of identifiers for local CAs.

leaseTimeout number

Duration of the lease in seconds.

cb0 function

A callback with either an error (first) argument or a (second) argument with a list of CA Ids that we failed to renew.

Source:

renewNodeLease(privateNodeId, leaseTimeout, cb0)

Renews a lease associated with this node.js process.

Parameters:
Name Type Description
privateNodeId string

A private unique identifier for the current node.js process.

leaseTimeout number

Duration of the lease in seconds.

cb0 function

A callback with an error if we cannot renew lease.

Source:

setBits(bitfieldName, bits, cb0)

Sets bits in a bitfield.

Parameters:
Name Type Description
bitfieldName string

The name of the bitfield.

bits Array.<number>

The index of bits to be set.

cb0 cbType

A callback to notify an error.

Source:

subscribeMap(mapName, handler, cb0)

Listens to Map updates.

Parameters:
Name Type Description
mapName string

The name of the map.

handler cbType

A handler to listen to updates or errors.

cb0 cbType

A callback with an error or null.

Source:

subscribePubSub(topic, deliverMsgF, cb0)

Subscribes to a channel in the PubSub service.

Parameters:
Name Type Description
topic string

The channel name.

deliverMsgF function

Handler of received messages. First argument is the topic, second the message.

cb0 cbType

A callback to return a subscription error.

Source:

unsubscribeMap(mapName, cb0)

Unregisters a Map update listener.

Parameters:
Name Type Description
mapName string

The name of the map.

cb0 cbType

A callback with an error or null.

Source:

unsubscribePubSub(topic, cb0)

Unsubscribes to a channel in the PubSub service.

Parameters:
Name Type Description
topic string

The channel name.

cb0 cbType

A callback to return a subscription error.

Source:

updateCache(key, value, timeout, cb0)

Updates a cache entry.

Parameters:
Name Type Description
key string

The cache entry key.

value string

The cache entry value.

timeout number

An expire time in seconds.

cb0 cbType

A callback to return an error.

Source:

updateMap(mapName, changes, cb0)

Updates a Map.

The type changesType is a normalized update (no duplicated keys) of the form:

{version: number, remove : Array.<string>, add : Array<Object>}

It publishes in a channel with id mapName the JSON-encoded changes contents.

Parameters:
Name Type Description
mapName string

The name of the map.

changes changesType

A delta with changes.

cb0 cbType

A callback with an error if it does not exist or the number of subscribed clients.

Source:

updateState(id, newValue, cb0)

Updates the state of a CA in the checkpointing service.

Parameters:
Name Type Description
id string

An identifier for the CA.

newValue string

A serialized new state for this CA.

cb0 cbType

A callback to notify of an error updating or succesful completion if falsy argument.

Source: