1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2009 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
9 /* Interface to John McCullough's simple key/value store. */
16 #include "bluesky-private.h"
17 #include "kvservice.h"
20 using namespace boost;
21 using namespace kvstore;
24 static GThreadPool *thread_pool = NULL;
26 static void kvstore_task(gpointer a, gpointer b)
28 BlueSkyStoreAsync *async = (BlueSkyStoreAsync *)a;
29 KeyValueClient *client = (KeyValueClient *)bluesky_store_async_get_handle(async);
31 async->status = ASYNC_RUNNING;
37 if (client->Get(async->key, &value)) {
38 async->data = bluesky_string_new(g_memdup(value.c_str(),
48 string value(async->data->data, async->data->len);
49 client->Put(async->key, value);
57 bluesky_store_async_mark_complete(async);
58 bluesky_store_async_unref(async);
61 static gpointer kvstore_new()
63 static volatile gsize once = 0;
64 if (g_once_init_enter(&once)) {
65 thread_pool = g_thread_pool_new(kvstore_task, NULL, -1, FALSE, NULL);
66 g_once_init_leave(&once, 1);
69 KeyValueClient *client = new KeyValueClient("127.0.0.1", "9090");
73 static void kvstore_destroy(gpointer store)
75 KeyValueClient *client = (KeyValueClient *)store;
79 static void kvstore_submit(gpointer store, BlueSkyStoreAsync *async)
81 KeyValueClient *client = (KeyValueClient *)store;
83 g_return_if_fail(async->status == ASYNC_NEW);
84 g_return_if_fail(async->op != STORE_OP_NONE);
89 async->status = ASYNC_PENDING;
90 bluesky_store_async_ref(async);
91 g_thread_pool_push(thread_pool, async, NULL);
95 g_warning("Uknown operation type for kvstore: %d\n", async->op);
96 bluesky_store_async_mark_complete(async);
101 static void kvstore_cleanup(gpointer store, BlueSkyStoreAsync *async)
103 KeyValueClient *client = (KeyValueClient *)store;
106 static BlueSkyStoreImplementation store_impl = {
113 extern "C" void bluesky_store_init_kv(void)
115 bluesky_store_register(&store_impl, "kv");