core-write-op.cpp 5.19 KB
Newer Older
1 2 3
#include <map>
#include <string>
#include <iostream>
4
#include <bake-bulk-client.h>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include "src/server/visitor-args.h"
#include "src/io-chain/write-op-visitor.h"

static void write_op_exec_begin(void*);
static void write_op_exec_end(void*);
static void write_op_exec_create(void*, int);
static void write_op_exec_write(void*, buffer_u, size_t, uint64_t);
static void write_op_exec_write_full(void*, buffer_u, size_t);
static void write_op_exec_writesame(void*, buffer_u, size_t, size_t, uint64_t);
static void write_op_exec_append(void*, buffer_u, size_t);
static void write_op_exec_remove(void*);
static void write_op_exec_truncate(void*, uint64_t);
static void write_op_exec_zero(void*, uint64_t, uint64_t);
static void write_op_exec_omap_set(void*, char const* const*, char const* const*, const size_t*, size_t);
static void write_op_exec_omap_rm_keys(void*, char const* const*, size_t);

static struct write_op_visitor write_op_exec = {
	.visit_begin        = write_op_exec_begin,
	.visit_create       = write_op_exec_create,
	.visit_write        = write_op_exec_write,
	.visit_write_full   = write_op_exec_write_full,
	.visit_writesame    = write_op_exec_writesame,
	.visit_append       = write_op_exec_append,
	.visit_remove       = write_op_exec_remove,
	.visit_truncate     = write_op_exec_truncate,
	.visit_zero         = write_op_exec_zero,
	.visit_omap_set     = write_op_exec_omap_set,
	.visit_omap_rm_keys = write_op_exec_omap_rm_keys,
	.visit_end          = write_op_exec_end
};

extern "C" void core_write_op(mobject_store_write_op_t write_op, server_visitor_args_t vargs)
{
	/* Execute the operation chain */
	execute_write_op_visitor(&write_op_exec, write_op, (void*)vargs);
}

void write_op_exec_begin(void* u)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_end(void* u)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_create(void* u, int exclusive)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_write(void* u, buffer_u buf, size_t len, uint64_t offset)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
60 61 62
    bake_target_id_t bti = vargs->srv_ctx->bake_id;
    bake_bulk_region_id_t rid;
    hg_bulk_t remote_bulk = vargs->bulk_handle;
Matthieu Dorier's avatar
Matthieu Dorier committed
63
    const char* remote_addr = vargs->client_addr.as_string;
64 65 66 67 68 69 70 71
    int ret;

    // TODO: check return values of those calls
    ret = bake_bulk_create(bti, len, &rid);
    ret = bake_bulk_proxy_write(bti, rid, 0, remote_bulk, buf.as_offset, remote_addr, len);
    ret = bake_bulk_persist(bti, rid);
   
    // TODO: write [offset,len,rid] in sds-keyval for the specified object
72 73 74 75 76
}

void write_op_exec_write_full(void* u, buffer_u buf, size_t len)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
77 78 79
    bake_target_id_t bti = vargs->srv_ctx->bake_id;
    bake_bulk_region_id_t rid;
    hg_bulk_t remote_bulk = vargs->bulk_handle;
Matthieu Dorier's avatar
Matthieu Dorier committed
80
    const char* remote_addr = vargs->client_addr.as_string;
81 82 83 84 85 86 87 88
    int ret;

    // TODO: check return values of those calls
    ret = bake_bulk_create(bti, len, &rid);
    ret = bake_bulk_proxy_write(bti, rid, 0, remote_bulk, buf.as_offset, remote_addr, len);
    ret = bake_bulk_persist(bti, rid);

    // TODO: write [offset,len,rid] in sds-keyval for the specified object
89 90 91 92 93
}

void write_op_exec_writesame(void* u, buffer_u buf, size_t data_len, size_t write_len, uint64_t offset)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
94 95 96
    bake_target_id_t bti = vargs->srv_ctx->bake_id;
    bake_bulk_region_id_t rid;
    hg_bulk_t remote_bulk = vargs->bulk_handle;
Matthieu Dorier's avatar
Matthieu Dorier committed
97
    const char* remote_addr = vargs->client_addr.as_string;
98 99 100 101 102 103 104 105
    int ret;

    // TODO: check return values of those calls
    ret = bake_bulk_create(bti, data_len, &rid);
    ret = bake_bulk_proxy_write(bti, rid, 0, remote_bulk, buf.as_offset, remote_addr, data_len);
    ret = bake_bulk_persist(bti, rid);

    // TODO: write [offset,len,rid] in sds-keyval for the specified object
106 107 108 109 110
}

void write_op_exec_append(void* u, buffer_u buf, size_t len)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
111 112 113
    bake_target_id_t bti = vargs->srv_ctx->bake_id;
    bake_bulk_region_id_t rid;
    hg_bulk_t remote_bulk = vargs->bulk_handle;
Matthieu Dorier's avatar
Matthieu Dorier committed
114
    const char* remote_addr = vargs->client_addr.as_string;
115 116 117 118 119 120 121 122
    int ret;

    // TODO: check return values of those calls
    ret = bake_bulk_create(bti, len, &rid);
    ret = bake_bulk_proxy_write(bti, rid, 0, remote_bulk, buf.as_offset, remote_addr, len);
    ret = bake_bulk_persist(bti, rid);

    // TODO: write [offset,len,rid] in sds-keyval for the specified object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
}

void write_op_exec_remove(void* u)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_truncate(void* u, uint64_t offset)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_zero(void* u, uint64_t offset, uint64_t len)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_omap_set(void* u, char const* const* keys,
                                     char const* const* vals,
                                     const size_t *lens,
                                     size_t num)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}

void write_op_exec_omap_rm_keys(void* u, char const* const* keys, size_t num_keys)
{
	auto vargs = static_cast<server_visitor_args_t>(u);
}