Include storage type in container meta/hashmap replies. Minor doc updates.
authorAntony Chazapis <chazapis@gmail.com>
Tue, 31 May 2011 11:01:17 +0000 (14:01 +0300)
committerAntony Chazapis <chazapis@gmail.com>
Tue, 31 May 2011 11:01:17 +0000 (14:01 +0300)
docs/source/devguide.rst
pithos/api/functions.py
pithos/api/templates/hashes.xml
pithos/api/util.py

index dc59fef..4738793 100644 (file)
@@ -25,7 +25,8 @@ Document Revisions
 =========================  ================================
 Revision                   Description
 =========================  ================================
-0.2 (May 29, 2011)         Add object meta listing and filtering in containers.
+0.2 (May 31, 2011)         Add object meta listing and filtering in containers.
+\                          Include underlying storage characteristics in container meta.
 \                          Support for partial object updates through POST.
 \                          Expose object hashmaps through GET.
 \                          Support for multi-range object GET requests.
@@ -153,12 +154,14 @@ x_container_meta_*   Optional user defined metadata
 
 For examples of container details returned in JSON/XML formats refer to the OOS API documentation.
 
-================  =====================
-Return Code       Description
-================  =====================
-200 (OK)          The request succeeded
-204 (No Content)  The account has no containers (only for non-extended replies)
-================  =====================
+===========================  =====================
+Return Code                  Description
+===========================  =====================
+200 (OK)                     The request succeeded
+204 (No Content)             The account has no containers (only for non-extended replies)
+304 (Not Modified)           The account has not been modified
+412 (Precondition Failed)    The condition set can not be satisfied
+===========================  =====================
 
 Will use a ``200`` return code if the reply is of type json/xml.
 
@@ -211,6 +214,8 @@ X-Container-Object-Count    The total number of objects in the container
 X-Container-Bytes-Used      The total number of bytes of all objects stored
 X-Container-Meta-*          Optional user defined metadata
 X-Container-Object-Meta     A list with all meta keys used by objects
+X-Container-Block-Size      The block size used by the storage backend
+X-Container-Block-Hash      The hash algorithm used for block identifiers in object hashmaps
 Last-Modified               The last object modification date
 ==========================  ===============================
 
@@ -275,12 +280,14 @@ In case there is an object with the same name as a virtual directory marker, the
  
 For examples of object details returned in JSON/XML formats refer to the OOS API documentation.
 
-================  ===============================
-Return Code       Description
-================  ===============================
-200 (OK)          The request succeeded
-204 (No Content)  The account has no containers (only for non-extended replies)
-================  ===============================
+===========================  ===============================
+Return Code                  Description
+===========================  ===============================
+200 (OK)                     The request succeeded
+204 (No Content)             The account has no containers (only for non-extended replies)
+304 (Not Modified)           The container has not been modified
+412 (Precondition Failed)    The condition set can not be satisfied
+===========================  ===============================
 
 Will use a ``200`` return code if the reply is of type json/xml.
 
@@ -352,7 +359,7 @@ GET        Read object data
 PUT        Write object data or copy/move object
 COPY       Copy object
 MOVE       Move object
-POST       Update object metadata
+POST       Update object metadata/data
 DELETE     Delete object
 =========  =================================
 
@@ -407,24 +414,20 @@ format                  Optional extended reply type (can be ``json`` or ``xml``
 
 The reply is the object's data (or part of it), except if a hashmap is requested with the ``format`` parameter. Object headers (as in a ``HEAD`` request) are always included.
 
-Hashmaps expose the underlying storage format of the object:
-
-* Blocksize of 4MB.
-* Blocks stored indexed by SHA256 hash.
-* Hash is computed after trimming trailing null bytes.
+Hashmaps expose the underlying storage format of the object. Note that each hash is computed after trimming trailing null bytes of the corresponding block.
 
 Example ``format=json`` reply:
 
 ::
 
-  {"hashes": ["7295c41da03d7f916440b98e32c4a2a39351546c", ...], "bytes": 24223726}
+  {"block_hash": "sha1", "hashes": ["7295c41da03d7f916440b98e32c4a2a39351546c"], "block_size": 131072, "bytes": 242}
 
 Example ``format=xml`` reply:
 
 ::
 
   <?xml version="1.0" encoding="UTF-8"?>
-  <object name="file" bytes="24223726">
+  <object name="file" bytes="24223726" block_size="131072" block_hash="sha1">
     <hash>7295c41da03d7f916440b98e32c4a2a39351546c</hash>
     <hash>...</hash>
   </object>
@@ -595,6 +598,7 @@ List of differences from the OOS API:
 * Support for ``X-Account-Meta-*`` style headers at the account level. Use ``POST`` to update.
 * Support for ``X-Container-Meta-*`` style headers at the account level. Can be set when creating via ``PUT``. Use ``POST`` to update.
 * Header ``X-Container-Object-Meta`` at the container level and parameter ``meta`` in container listings.
+* Headers ``X-Container-Block-*`` at the container level, exposing the underlying storage characteristics.
 * All metadata replies, at all levels, include latest modification information.
 * At all levels, a ``GET`` request may use ``If-Modified-Since`` and ``If-Unmodified-Since`` headers.
 * Container/object lists include all associated metadata if the reply is of type json/xml. Some names are kept to their OOS API equivalents for compatibility. 
index f4958b7..91f753b 100644 (file)
@@ -113,7 +113,6 @@ def authenticate(request):
     x_auth_key = request.META.get('HTTP_X_AUTH_KEY')
     if not x_auth_user or not x_auth_key:
         raise BadRequest('Missing X-Auth-User or X-Auth-Key header')
-    
     response = HttpResponse(status=204)
     response['X-Auth-Token'] = '0000'
     response['X-Storage-Url'] = os.path.join(request.build_absolute_uri(), 'demo')
@@ -404,10 +403,12 @@ def object_read(request, v_account, v_container, v_object):
     
     # Reply with the hashmap.
     if request.serialization != 'text':
+        d = {'block_size': backend.block_size, 'block_hash': backend.hash_algorithm, 'bytes': size, 'hashes': hashmap}
         if request.serialization == 'xml':
-            data = render_to_string('hashes.xml', {'object': v_object, 'bytes': size, 'hashes': hashmap})
+            d['object'] = v_object
+            data = render_to_string('hashes.xml', d)
         elif request.serialization  == 'json':
-            data = json.dumps({'bytes': size, 'hashes': hashmap})
+            data = json.dumps(d)
         
         response = HttpResponse(data, status=200)
         put_object_meta(response, meta)
index 7d32c77..ce38a75 100644 (file)
@@ -1,7 +1,7 @@
 {% spaceless %}
 <?xml version="1.0" encoding="UTF-8"?>
 
-<object name="{{ object }}" bytes="{{ bytes }}">
+<object name="{{ object }}" bytes="{{ bytes }}" block_size="{{ block_size }}" block_hash="{{ block_hash }}">
   {% for hash in hashes %}
   <hash>{{ hash }}</hash>
   {% endfor %}
index 0c60b3a..175e1cd 100644 (file)
@@ -101,6 +101,8 @@ def put_container_meta(response, meta):
     for k in [x for x in meta.keys() if x.startswith('X-Container-Meta-')]:
         response[k.encode('utf-8')] = meta[k].encode('utf-8')
     response['X-Container-Object-Meta'] = [x[14:] for x in meta['object_meta'] if x.startswith('X-Object-Meta-')]
+    response['X-Container-Block-Size'] = backend.block_size
+    response['X-Container-Block-Hash'] = backend.hash_algorithm
 
 def get_object_meta(request):
     """Get metadata from an object request"""