Files
rippled/src/ripple/rpc
Vinnie Falco d468deee12 Refactor Ledger and LedgerEntrySet:
Member functions and free functions on Ledger and LedgerEntrySet are
rewritten in terms of new abstract interfaces `BasicView` and `View`,
representing the set of non-decomposable primitives necessary to read
and write state map items in a ledger, and to overlay a discardable
view onto a Ledger that can calculate metadata during transaction
processing. const-correctness is enforced through the parameter and
return types.

The MetaView now supports multi-level stacking: A MetaView can be
stacked on top of either a Ledger or another MetaView, up to any
number of levels.

The getSLEi member function is removed. The CachedView wrapper
replaces it, wrapping a View such that any function called with a
CachedView will go through the SLECache.

* Add BasicView, View, CachedView
* Rename LedgerEntrySet to MetaView
* Factor out free functions
* Consolidate free functions in ViewAPI
* Remove unused class members and free functions
2015-06-22 18:39:33 -07:00
..
2015-06-22 18:39:33 -07:00
2015-06-13 11:55:03 -07:00
2015-05-22 11:09:50 -07:00
2015-05-22 11:09:50 -07:00
2015-02-02 17:01:17 -08:00
2015-02-25 19:46:56 -05:00
2015-02-02 17:01:17 -08:00
2014-09-16 14:15:12 -07:00
2015-06-10 15:54:07 -07:00

How to use RPC coroutines.

Introduction.

By default, an RPC handler runs as an uninterrupted task on the JobQueue. This is fine for commands that are fast to compute but might not be acceptable for tasks that require multiple parts or are large, like a full ledger.

For this purpose, the rippled RPC handler allows suspension with continuation

  • a request to suspend execution of the RPC response and to continue it after some function or job has been executed. A default continuation is supplied which simply reschedules the job on the JobQueue, or the programmer can supply their own.

The classes.

Suspension with continuation uses four std::functions in the ripple::RPC namespace:

using Callback = std::function <void ()>;
using Continuation = std::function <void (Callback const&)>;
using Suspend = std::function <void (Continuation const&)>;
using SuspendCallback = std::function <void (Suspend const&)>;

A Callback is a generic 0-argument function. A given Callback might or might not block. Unless otherwise advised, do not hold locks or any resource that would prevent any other task from making forward progress when you call a Callback.

A Continuation is a function that is given a Callback and promises to call it later. A Continuation guarantees to call the Callback exactly once at some point in the future, but it does not have to be immediately or even in the current thread.

A Suspend is a function belonging to a Coroutine. A Suspend runs a Continuation, passing it a Callback that continues execution of the Coroutine.

And finally, a SuspendCallback is a std::function which is given a Suspend. This is what the RPC handler gives to the coroutine manager, expecting to get called back with a Suspend and to be able to start execution.

The flow of control.

Given these functions, the flow of RPC control when using coroutines is straight-forward.

  1. The instance of ServerHandler receives an RPC request.

  2. It creates a SuspendCallback and gives it to the coroutine manager.

  3. The coroutine manager creates a Coroutine, starts it up, and then calls the SuspendCallback with a Suspend.

  4. Now the RPC response starts to be calculated.

  5. When the RPC handler wants to suspend, it calls the Suspend function with a Continuation.

  6. Coroutine execution is suspended.

  7. The Continuation is called with a Callback that the coroutine manager creates.

  8. The Continuation may choose to execute immediately, defer execution on the job queue, or wait for some resource to be free.

  9. When the Continuation is finished, it calls the Callback that the coroutine manager gave it, perhaps a long time ago.

  10. This Callback continues execution on the suspended Coroutine from where it left off.