Work on reducing memory pinned by the inode map.
[bluesky.git] / bluesky / store-s3.c
index ccf0878..d5f06e8 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)
 {
@@ -83,6 +89,7 @@ static void s3store_task(gpointer a, gpointer s)
     S3Store *store = (S3Store *)s;
 
     async->status = ASYNC_RUNNING;
+    async->exec_time = bluesky_now_hires();
 
     if (async->op == STORE_OP_GET) {
         struct get_info info;
@@ -98,22 +105,15 @@ static void s3store_task(gpointer a, gpointer s)
                       &handler, &info);
 
         if (info.success) {
-            BlueSkyRCStr *raw, *decrypted;
-            raw = bluesky_string_new_from_gstring(info.buf);
-            decrypted = bluesky_crypt_decrypt(raw, store->encryption_key);
-            bluesky_string_unref(raw);
-            async->data = decrypted;
+            async->data = bluesky_string_new_from_gstring(info.buf);
             async->result = 0;
         } else {
             g_string_free(info.buf, TRUE);
         }
 
     } else if (async->op == STORE_OP_PUT) {
-        BlueSkyRCStr *encrypted = bluesky_crypt_encrypt(async->data,
-                                                        store->encryption_key);
-
         struct put_info info;
-        info.val = encrypted;
+        info.val = async->data;
         info.offset = 0;
 
         struct S3PutObjectHandler handler;
@@ -122,11 +122,9 @@ static void s3store_task(gpointer a, gpointer s)
         handler.responseHandler.completeCallback = s3store_response_callback;
         handler.putObjectDataCallback = s3store_put_handler;
 
-        S3_put_object(&store->bucket, async->key, encrypted->len, NULL, NULL,
+        S3_put_object(&store->bucket, async->key, async->data->len, NULL, NULL,
                       &handler, &info);
 
-        bluesky_string_unref(encrypted);
-
         async->result = 0;
     }
 
@@ -134,7 +132,43 @@ static void s3store_task(gpointer a, gpointer s)
     bluesky_store_async_unref(async);
 }
 
-static gpointer s3store_new()
+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 info.last_entry;
+}
+
+static gpointer s3store_new(const gchar *path)
 {
     S3Store *store = g_new(S3Store, 1);
     store->thread_pool = g_thread_pool_new(s3store_task, store, -1, FALSE,
@@ -200,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)