[tracker/dbus-fd-experiment: 7/13] Steroids server: add large rows support



commit d01194a8ec07893170eeca552b037a5f82c766c3
Author: Adrien Bustany <abustany gnome org>
Date:   Fri May 21 18:24:23 2010 -0400

    Steroids server: add large rows support
    
    This commit modifies the protocol slightly to handle the case where a
    row would be larger than the buffer size. In that case, the return code
    will be STEROIDS_RC_LARGEROW, and it will be followed by an integer
    which is the size of the row.
    Note that sending large rows is less efficient, because it implies more
    memory copies.

 src/tracker-store/tracker-steroids.c |   38 +++++++++++++++++++++++++++++++--
 src/tracker-store/tracker-steroids.h |    1 +
 2 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/src/tracker-store/tracker-steroids.c b/src/tracker-store/tracker-steroids.c
index 2523fad..06c323b 100644
--- a/src/tracker-store/tracker-steroids.c
+++ b/src/tracker-store/tracker-steroids.c
@@ -234,8 +234,37 @@ query_inthread (TrackerDBCursor *cursor,
 		         + n_columns * sizeof (char);  /* trailing \0 for each column */
 
 		if (row_size > SEND_BUFFER_SIZE) {
-			g_critical ("Rows larger than %d are not supported, skipping",
-			            SEND_BUFFER_SIZE);
+			char *buffer = g_malloc (sizeof (char) * row_size + sizeof (int));
+			char *dst = buffer;
+
+			/* Flush the current page, if there was something in it */
+			if (info->send_buffer_index) {
+				page_flush (info);
+			}
+
+			buffer_write_int (dst, STEROIDS_RC_LARGEROW);
+			dst += sizeof (int);
+			buffer_write_int (dst, row_size);
+			dst += sizeof (int);
+			buffer_write_int (dst, n_columns);
+			dst += sizeof (int);
+			memcpy (dst,
+			        column_offsets,
+			        n_columns * sizeof (int));
+			dst += n_columns * sizeof (int);
+
+			for (i = 0; i < n_columns; i++) {
+				memcpy (dst,
+				        column_data[i],
+				        column_sizes[i]);
+				dst += column_sizes[i];
+				memset (dst, 0, 1);
+				dst ++;
+			}
+
+			buffer_send (info->fd, buffer, row_size);
+
+			g_free (buffer);
 			continue;
 		}
 
@@ -260,7 +289,10 @@ query_inthread (TrackerDBCursor *cursor,
 		}
 	}
 
-	page_flush (info);
+	/* We flush to ensure we'll have enough space to write the DONE code */
+	if (info->send_buffer_index) {
+		page_flush (info);
+	}
 	client_write_int (info, STEROIDS_RC_DONE);
 	page_flush (info);
 
diff --git a/src/tracker-store/tracker-steroids.h b/src/tracker-store/tracker-steroids.h
index 3de8bef..750dafe 100644
--- a/src/tracker-store/tracker-steroids.h
+++ b/src/tracker-store/tracker-steroids.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 #define STEROIDS_RC_ERROR 0
 #define STEROIDS_RC_ROW   1
 #define STEROIDS_RC_DONE  2
+#define STEROIDS_RC_LARGEROW 3
 
 #define STEROIDS_EOP      0xFF
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]