Data blocks cache manager. None of the methods in this class are thread-safe, call only from main server thread. Data blocks are described in detail in Data Blocks article.

Methods

create (type:String, id:Int, ?attrs:Dynamic):Bool

Creates a new data block in database.

Parameters:

type

Block type.

id

Block ID.

attrs

Optional. Data block attributes object.

Returns:

True on success, false otherwise. Currently always returns true.

get (type:String, id:Int, currentVersion:Int, ?oldBlock:Block):_CacheReturnType

Gets data block from cache server, locks it and returns it.

Parameters:

type

Block type.

id

Block ID.

currentVersion

Current block version. Passed to optimize server to server traffic.

oldBlock

Old block object. Passed to properly store it in lock list in case of sameVersion error code.

Returns:

Error code and block object, if block is received.

getUnlocked (type:String, id:Int, currentVersion:Int):_CacheReturnType

Returns unlocked data block from cache server.

Note: Since the block can already be locked and written to on a different slave server, the resulting block contents from cache server can be of an earlier version. Use this method only for read operations where the immediate data freshness is not important.

Parameters:

type

Block type.

id

Block ID.

currentVersion

Current block version. If the version is the same as on cache server, will return sameVersion error code.

Returns:

Error code and block object, if block is received.

isLocked (block:Block):Bool

Returns true if data block is locked by this slave server. This operation is local.

Parameters:

block

Data block.

Returns:

True, if data block is locked. False otherwise.

unlock (type:String, id:Int):Void

Unlocks data block on cache server. This operation will succeed only if the block is locked by this slave server. If the block is not actually locked by this server, nothing bad happens.

Parameters:

type

Block type.

id

Block ID.

update (block:Block, unlock:Bool):String

Updates data block on cache server from local changes and unlocks it if unlock flag is set.

List of error codes:

ok - Operation successful.

mustBeLocked - Block must be locked by this slave server to update.

blockUpdateFailed - Reserved.

Parameters:

block

Data block.

unlock

If true, will unlock this block on cache server.

Returns:

Operation error code.