void bluesky_store_async_wait(BlueSkyStoreAsync *async);
void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
void bluesky_store_async_submit(BlueSkyStoreAsync *async);
+void bluesky_store_sync(BlueSkyStore *store);
#ifdef __cplusplus
}
extern "C" {
#endif
+/* Various options to tweak for performance benchmarking purposes. */
+typedef struct {
+ /* Perform all get/put operations synchronously. */
+ int synchronous_stores;
+} BlueSkyOptions;
+
+extern BlueSkyOptions bluesky_options;
+
/* BlueSky status and error codes. Various frontends should translate these to
* the appropriate error code for whatever protocol they implement. */
typedef enum {
#include "bluesky-private.h"
+BlueSkyOptions bluesky_options;
+
/* BlueSky library initialization. */
void bluesky_store_init_s3(void);
g_thread_init(NULL);
bluesky_crypt_init();
+ //bluesky_options.synchronous_stores = 1;
+
bluesky_store_init();
bluesky_store_init_s3();
}
char key[64];
sprintf(key, "inode-%016"PRIx64, inode->inum);
- bluesky_store_put(fs->store, key, data);
+ BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
+ async->op = STORE_OP_PUT;
+ async->key = g_strdup(key);
+ async->data = data;
+ bluesky_store_async_submit(async);
+ bluesky_store_async_unref(async);
}
/* Fetch an inode from stable storage. */
g_print("Syncing superblock...\n");
- bluesky_store_put(fs->store, "superblock", data);
+ BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
+ async->op = STORE_OP_PUT;
+ async->key = g_strdup("superblock");
+ async->data = data;
+ bluesky_store_async_submit(async);
+ bluesky_store_async_unref(async);
+
+ bluesky_store_sync(fs->store);
}
struct _BlueSkyStore {
const BlueSkyStoreImplementation *impl;
gpointer handle;
+
+ GMutex *lock;
+ GCond *cond_idle;
+ int pending; /* Count of operations not yet complete. */
};
GHashTable *store_implementations;
BlueSkyStore *store = g_new(BlueSkyStore, 1);
store->impl = impl;
store->handle = handle;
+ store->lock = g_mutex_new();
+ store->cond_idle = g_cond_new();
+ store->pending = 0;
return store;
}
* function. */
void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async)
{
+ if (async->status != ASYNC_COMPLETE) {
+ g_mutex_lock(async->store->lock);
+ async->store->pending--;
+ if (async->store->pending == 0)
+ g_cond_broadcast(async->store->cond_idle);
+ g_mutex_unlock(async->store->lock);
+ }
+
async->status = ASYNC_COMPLETE;
g_cond_broadcast(async->completion_cond);
}
{
BlueSkyStore *store = async->store;
+ g_mutex_lock(async->store->lock);
+ async->store->pending++;
+ g_mutex_unlock(async->store->lock);
+
store->impl->submit(store->handle, async);
+
+ if (bluesky_options.synchronous_stores)
+ bluesky_store_async_wait(async);
+}
+
+void bluesky_store_sync(BlueSkyStore *store)
+{
+ g_mutex_lock(store->lock);
+ g_print("Waiting for pending store operations to complete...\n");
+ while (store->pending > 0) {
+ g_cond_wait(store->cond_idle, store->lock);
+ }
+ g_mutex_unlock(store->lock);
+ g_print("Operations are complete.\n");
}
/* Convenience wrappers that perform a single operation synchronously. */