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 /* A stacked storage implementation which tries to improve performance by
10 * duplicating GET requests. Create using a name like "multi:s3" and each GET
11 * request will be translated into two GET requests to the "s3" backend. The
12 * first to complete will have its results returned. */
19 #include "bluesky-private.h"
24 static gpointer multistore_new(const gchar *path)
26 BlueSkyStore *base = bluesky_store_new(path);
28 g_warning("Unable to create base store %s for multirequest stacking.",
35 static void multistore_destroy(gpointer store)
37 bluesky_store_free(store);
40 static void multistore_completion_handler(BlueSkyStoreAsync *async,
41 BlueSkyStoreAsync *top_async)
43 g_mutex_lock(top_async->lock);
45 g_print("Completed a subrequest for %s\n", async->key);
47 /* This might be the second request to finish; in that case we don't do
49 if (top_async->status == ASYNC_RUNNING) {
50 if (top_async->op == STORE_OP_GET) {
51 bluesky_string_unref(top_async->data);
52 top_async->data = async->data;
53 bluesky_string_ref(top_async->data);
55 top_async->result = async->result;
56 bluesky_store_async_mark_complete(top_async);
59 g_mutex_unlock(top_async->lock);
60 bluesky_store_async_unref(top_async);
63 static void multistore_submit(gpointer store, BlueSkyStoreAsync *async)
65 BlueSkyStore *base = (BlueSkyStore *)store;
67 g_return_if_fail(async->status == ASYNC_NEW);
68 g_return_if_fail(async->op != STORE_OP_NONE);
72 g_print("Received multirequest for %s\n", async->key);
73 async->status = ASYNC_RUNNING;
74 async->exec_time = bluesky_now_hires();
75 for (int i = 0; i < 2; i++) {
76 BlueSkyStoreAsync *a = bluesky_store_async_new(base);
78 a->key = g_strdup(async->key);
79 bluesky_store_async_ref(async);
80 bluesky_store_async_add_notifier(a, (GFunc)multistore_completion_handler, async);
81 bluesky_store_async_submit(a);
82 bluesky_store_async_unref(a);
88 async->status = ASYNC_RUNNING;
89 async->exec_time = bluesky_now_hires();
91 bluesky_store_async_ref(async);
92 BlueSkyStoreAsync *a = bluesky_store_async_new(base);
94 a->key = g_strdup(async->key);
95 a->data = async->data;
96 bluesky_string_ref(a->data);
97 bluesky_store_async_add_notifier(a, (GFunc)multistore_completion_handler, async);
98 bluesky_store_async_submit(a);
99 bluesky_store_async_unref(a);
104 g_warning("Uknown operation type for multistore: %d\n", async->op);
105 bluesky_store_async_mark_complete(async);
110 static void multistore_cleanup(gpointer store, BlueSkyStoreAsync *async)
114 static BlueSkyStoreImplementation store_impl = {
115 .create = multistore_new,
116 .destroy = multistore_destroy,
117 .submit = multistore_submit,
118 .cleanup = multistore_cleanup,
121 void bluesky_store_init_multi(void)
123 bluesky_store_register(&store_impl, "multi");