Implement a list operation for the S3 storage backend.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Fri, 10 Sep 2010 20:30:52 +0000 (13:30 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Fri, 10 Sep 2010 20:30:52 +0000 (13:30 -0700)
bluesky/store-s3.c

index e34fafd..e762ebd 100644 (file)
@@ -34,10 +34,16 @@ struct get_info {
 };
 
 struct put_info {
+    int success;
     BlueSkyRCStr *val;
     gint offset;
 };
 
+struct list_info {
+    int success;
+    char *last_entry;
+};
+
 static S3Status s3store_get_handler(int bufferSize, const char *buffer,
                                     void *callbackData)
 {
@@ -126,6 +132,42 @@ static void s3store_task(gpointer a, gpointer s)
     bluesky_store_async_unref(async);
 }
 
+static S3Status s3store_list_handler(int isTruncated,
+                                     const char *nextMarker,
+                                     int contentsCount,
+                                     const S3ListBucketContent *contents,
+                                     int commonPrefixesCount,
+                                     const char **commonPrefixes,
+                                     void *callbackData)
+{
+    struct list_info *info = (struct list_info *)callbackData;
+    if (contentsCount > 0) {
+        g_free(info->last_entry);
+        info->last_entry = g_strdup(contents[contentsCount - 1].key);
+    }
+    return S3StatusOK;
+}
+
+static char *s3store_lookup_last(gpointer s, const char *prefix)
+{
+    S3Store *store = (S3Store *)s;
+    struct list_info info = {0, NULL};
+
+    struct S3ListBucketHandler handler;
+    handler.responseHandler.propertiesCallback
+        = s3store_properties_callback;
+    handler.responseHandler.completeCallback = s3store_response_callback;
+    handler.listBucketCallback = s3store_list_handler;
+
+    char *marker = NULL;
+
+    S3_list_bucket(&store->bucket, prefix, marker, NULL, 1024, NULL, &handler, &info);
+
+    g_print("Last key: %s\n", info.last_entry);
+
+    return S3StatusOK;
+}
+
 static gpointer s3store_new(const gchar *path)
 {
     S3Store *store = g_new(S3Store, 1);
@@ -192,6 +234,7 @@ static BlueSkyStoreImplementation store_impl = {
     .destroy = s3store_destroy,
     .submit = s3store_submit,
     .cleanup = s3store_cleanup,
+    .lookup_last = s3store_lookup_last,
 };
 
 void bluesky_store_init_s3(void)