subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r1174388 - in /subversion/trunk/subversion: include/private/svn_subr_private.h libsvn_subr/spillbuf.c tests/libsvn_subr/spillbuf-test.c
Date Thu, 22 Sep 2011 21:00:24 GMT
Author: gstein
Date: Thu Sep 22 21:00:24 2011
New Revision: 1174388

URL: http://svn.apache.org/viewvc?rev=1174388&view=rev
Log:
Change the spillbuf to remember how much content it has written to the
spill file. This removes the false-positive from the is_empty() function.
However, for some upcoming work, we need the size... so get_size() now
takes over for is_empty() and uses that file size.

* subversion/include/private/svn_subr_private.h:
  (svn_spillbuf__is_empty): removed in favor of ...
  (svn_spillbuf__get_size): ... this. note the use of svn_filesize_t since
    we are storing (potentially-large) content into a file.

* subversion/libsvn_subr/spillbuf.c:
  (struct svn_spillbuf_t): add SPILL_SIZE member
  (svn_spillbuf__is_empty): renamed to ...
  (svn_spillbuf__get_size): ... this, and logic altered
  (svn_spillbuf__write): add to the new SPILL_SIZE member
  (read_data): limit the amount read from the file to only what we stored
    into the file. if the file empties, then close it.

* subversion/tests/libsvn_subr/spillbuf-test.c:
  (test_spillbuf_basic, test_spillbuf_file): track rename

Modified:
    subversion/trunk/subversion/include/private/svn_subr_private.h
    subversion/trunk/subversion/libsvn_subr/spillbuf.c
    subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c

Modified: subversion/trunk/subversion/include/private/svn_subr_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_subr_private.h?rev=1174388&r1=1174387&r2=1174388&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_subr_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_subr_private.h Thu Sep 22 21:00:24 2011
@@ -94,15 +94,9 @@ svn_spillbuf__create(apr_size_t blocksiz
                      apr_pool_t *result_pool);
 
 
-/* Determine whether the spill buffer has any content.
-
-   Note: there is an edge case for a false positive. If the spill file was
-   read *just* to the end of the file, but not past... then the spill
-   buffer will not realize that no further content exists in the spill file.
-   In this situation, svn_spillbuf_is_empty() will return TRUE, but an
-   attempt to read content will detect that it has been exhausted.  */
-svn_boolean_t
-svn_spillbuf__is_empty(const svn_spillbuf_t *buf);
+/* Determine how much content is stored in the spill buffer.  */
+svn_filesize_t
+svn_spillbuf__get_size(const svn_spillbuf_t *buf);
 
 
 /* Write some data into the spill buffer.  */

Modified: subversion/trunk/subversion/libsvn_subr/spillbuf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/spillbuf.c?rev=1174388&r1=1174387&r2=1174388&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/spillbuf.c (original)
+++ subversion/trunk/subversion/libsvn_subr/spillbuf.c Thu Sep 22 21:00:24 2011
@@ -70,6 +70,9 @@ struct svn_spillbuf_t {
   /* As we consume content from SPILL, this value indicates where we
      will begin reading.  */
   apr_off_t spill_start;
+
+  /* How much content remains in SPILL.  */
+  svn_filesize_t spill_size;
 };
 
 
@@ -112,10 +115,10 @@ svn_spillbuf__create(apr_size_t blocksiz
 }
 
 
-svn_boolean_t
-svn_spillbuf__is_empty(const svn_spillbuf_t *buf)
+svn_filesize_t
+svn_spillbuf__get_size(const svn_spillbuf_t *buf)
 {
-  return buf->head == NULL && buf->spill == NULL;
+  return buf->memory_size + buf->spill_size;
 }
 
 
@@ -185,6 +188,8 @@ svn_spillbuf__write(svn_spillbuf_t *buf,
          ensure this, so that we will append.  */
       SVN_ERR(svn_io_file_write_full(buf->spill, data, len,
                                      NULL, scratch_pool));
+      buf->spill_size += len;
+
       return SVN_NO_ERROR;
     }
 
@@ -279,38 +284,31 @@ read_data(struct memblock_t **mem,
   *mem = get_buffer(buf);
   /* NOTE: mem's size/next are uninitialized.  */
 
-  (*mem)->size = buf->blocksize;  /* The size of (*mem)->data  */
+  if (buf->spill_size < buf->blocksize)
+    (*mem)->size = buf->spill_size;
+  else
+    (*mem)->size = buf->blocksize;  /* The size of (*mem)->data  */
   (*mem)->next = NULL;
 
   /* Read some data from the spill file into the memblock.  */
   err = svn_io_file_read(buf->spill, (*mem)->data, &(*mem)->size,
                          scratch_pool);
-  if (err != NULL && APR_STATUS_IS_EOF(err->apr_err))
-    {
-      /* We've exhausted the file. Close it, so any new content will go
-         into memory rather than the file.  */
-      svn_error_clear(err);
-      SVN_ERR(svn_io_file_close(buf->spill, scratch_pool));
-      buf->spill = NULL;
-    }
-  else if (err)
+  if (err)
     {
       return_buffer(buf, *mem);
       return svn_error_trace(err);
     }
 
-  /* If we didn't read anything from the file, then avoid returning a
-     memblock (ie. just like running out of content).  */
-  if ((*mem)->size == 0)
-    {
-      return_buffer(buf, *mem);
-      *mem = NULL;
-      return SVN_NO_ERROR;
-    }
-
   /* Mark the data that we consumed from the spill file.  */
   buf->spill_start += (*mem)->size;
 
+  /* Did we consume all the data from the spill file?  */
+  if ((buf->spill_size -= (*mem)->size) == 0)
+    {
+      SVN_ERR(svn_io_file_close(buf->spill, scratch_pool));
+      buf->spill = NULL;
+    }
+
   /* *mem has been initialized. Done.  */
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c?rev=1174388&r1=1174387&r2=1174388&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c Thu Sep 22 21:00:24 2011
@@ -43,14 +43,14 @@ test_spillbuf_basic(apr_pool_t *pool)
   int i;
 
   /* It starts empty.  */
-  SVN_TEST_ASSERT(svn_spillbuf__is_empty(buf));
+  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);
 
   /* Place enough data into the buffer to cause a spill to disk.  */
   for (i = 20; i--; )
     SVN_ERR(svn_spillbuf__write(buf, basic_data, sizeof(basic_data), pool));
 
   /* And now has content.  */
-  SVN_TEST_ASSERT(!svn_spillbuf__is_empty(buf));
+  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) > 0);
 
   while (TRUE)
     {
@@ -69,7 +69,7 @@ test_spillbuf_basic(apr_pool_t *pool)
       SVN_TEST_ASSERT(memcmp(readptr, basic_data, readlen) == 0);
     }
 
-  SVN_TEST_ASSERT(svn_spillbuf__is_empty(buf));
+  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);
 
   return SVN_NO_ERROR;
 }
@@ -185,7 +185,7 @@ test_spillbuf_file(apr_pool_t *pool)
         }
     }
 
-  SVN_TEST_ASSERT(svn_spillbuf__is_empty(buf));
+  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);
 
   return SVN_NO_ERROR;
 }



Mime
View raw message