Reverbrain wiki

Site Tools


elliptics:architecture-design

Elliptics client API architecture design

Main ideas

  • It's believed that asynchronious API is needed to build really high-perfomance client-side applications.
  • Some users still want to use synchronious API due to limits of other frameworks and libraries.
  • Sometimes it's needed to process results from server as each entry is received, processing only final aggregated results is not possible for such commands as data iteratators.
  • Some data can be processed only by several calls to server with the same arguments, so there should be a argument's container in the API.

Session

elliptics::session is short-live container for commands' configuration. So it's possible to make several sequentially by seting properties only once. Session stores not only the parameters/flags which should be sent to the server but also some logic for client-side processing of this data. By configuring the session user can filter result entries by different criteria like command execution status.

But it should be noticed that session is not thread-safe object, so accessing it from different threads must be avoided.

Async results

elliptics::async_result is generic result future returned by any request to server. It's possible to access result entries in both synchronious and asynchronious ways.

iterator_async_result result = sess.start_iterator(...);

Synchornious accessing to data is possible by two ways - waiting for all results to be ready or accessing result entries as soon as they are received:

for (auto it = result.begin(); it != result.end(); ++it) {
    iterator_result_entry entry = *it;
    /*!
     * Do whatever you want with entry
     * Entry is destroyed as soon as it's proccessed by this body
     * It makes possible to process huge amount of data without huge amount of memory
     */
}

// OR

result.wait();
std::vector<iterator_result_entry> results = result.get();

Accessing results in asynchronious is also possible by the same two ways.

result.connect([...] (const std::vector<iterator_result_entry> &results, const error_info &error) {
    if (error) {
        std::cerr << "Error while processing the request: " << error.message() << std::endl;
        return;
    }
    
    // Process the results
});

// OR

result.connect([...] (const iterator_result_entry &entry) {
    // Process the entry
}, [...] (const error_info &error) {
    if (error) {
        std::cerr << "Error while processing the request: " << error.message() << std::endl;
    }
    // Handle command execution end
});
elliptics/architecture-design.txt ยท Last modified: 2013/06/24 19:10 by elessar