bake-bulk-server-daemon.c 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <uuid/uuid.h>
#include <margo.h>
#include <libpmemobj.h>
#include <bake-bulk-server.h>

int main(int argc, char **argv) 
{
    int ret;
    margo_instance_id mid;
19
    struct bake_pool_info * pool_info;
20 21 22 23 24 25 26 27

    if(argc != 3)
    {
        fprintf(stderr, "Usage: bake-bulk-server <HG listening addr> <pmem pool>\n");
        fprintf(stderr, "  Example: ./bake-bulk-server tcp://localhost:1234 /dev/shm/foo.dat\n");
        return(-1);
    }

28
    pool_info = bake_server_makepool(argv[2]);
29

30 31 32
    /* start margo */
    /* use the main xstream for driving progress and executing rpc handlers */
    mid = margo_init(argv[1], MARGO_SERVER_MODE, 0, -1);
33 34
    assert(mid);

35
    /* register the bake bulk server */
36
    bake_server_register(mid, pool_info);
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

    /* NOTE: at this point this server ULT has two options.  It can wait on
     * whatever mechanism it wants to (however long the daemon should run and
     * then call margo_finalize().  Otherwise, it can call
     * margo_wait_for_finalize() on the assumption that it should block until
     * some other entity calls margo_finalize().
     *
     * This example does the latter.  Margo will be finalized by a special
     * RPC from the client.
     *
     * This approach will allow the server to idle gracefully even when
     * executed in "single" mode, in which the main thread of the server
     * daemon and the progress thread for Mercury are executing in the same
     * ABT pool.
     */
    margo_wait_for_finalize(mid);

54
    pmemobj_close(pool_info->bb_pmem_pool);
55 56 57 58

    return(0);
}