Changeset: f113412e2bfa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f113412e2bfa
Modified Files:
        sql/storage/bat/bat_logger.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: hot-snapshot
Log Message:

Cosmetic changes


diffs (147 lines):

diff --git a/sql/storage/bat/bat_logger.c b/sql/storage/bat/bat_logger.c
--- a/sql/storage/bat/bat_logger.c
+++ b/sql/storage/bat/bat_logger.c
@@ -951,17 +951,6 @@ end:
        return ret;
 }
 
-/* Like snapshot_lazy_copy_file, but takes a Heap* instead of a path */
-static void
-snapshot_lazy_copy_heap(stream *plan, Heap *heap)
-{
-       long extent = heap->free;
-       char *name = heap->filename;
-       char path[FILENAME_MAX];
-       snprintf(path, sizeof(path), "%s%c%s", BATDIR, DIR_SEP, name);
-       snapshot_lazy_copy_file(plan, path, extent);
-}
-
 /* Add plan entries for all relevant files in the Write Ahead Log */
 static gdk_return
 snapshot_wal(stream *plan, const char *db_dir)
@@ -985,8 +974,8 @@ snapshot_wal(stream *plan, const char *d
  *
  * If `mandatory` is set, it is an error for both files not to exist.
  *
- * This interface is slightly messy but of all I tried this gives the most
- * readable code.
+ * This interface is rather messy but of all I tried this ends up
+ * being most readable.
  */
 static gdk_return
 snapshot_one_heap(stream *plan, bool mandatory, const char *path, const char 
*name, const char *alt_path, const char *alt_name)
@@ -1025,7 +1014,7 @@ snapshot_one_heap(stream *plan, bool man
  * the absolute path of the heap file, for example /tmp/mydatabase/bat/07/726.
  * This function attempts to add suffixes such as .tail, .theap etc
  * and copies those files if they exist.
- * local_part_index is the number of byte to skip to get to the local
+ * local_part_index is the number of bytes to skip to get to the local
  * part of the filename, in this example skipping the "/tmp/mydatabase/"
  *
  * Note: path_buffer must have room for this function to append the suffixes
@@ -1034,6 +1023,7 @@ snapshot_one_heap(stream *plan, bool man
 static gdk_return
 snapshot_one_bat(stream *plan, char *path_buffer, char *alt_path_buffer, 
size_t local_part_index)
 {
+       // M = mandatory, O = optional
        static const char *suffixes[] = { "M.tail", "O.theap", "O.tvheap", 
"O.torderidx", "O.timprint", NULL };
        //TODO check the above
        gdk_return ret = GDK_FAIL;
@@ -1132,7 +1122,6 @@ end:
        if (cat) {
                close_stream(cat);
        }
-       (void)snapshot_lazy_copy_heap;
        return ret;
 }
 
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -314,7 +314,7 @@ typedef int (*log_tend_fptr) (void);
 typedef int (*log_sequence_fptr) (int seq, lng id);
 
 /*
--- Lists which parts of which files must be included in a hot snapshot.
+-- List which parts of which files must be included in a hot snapshot.
 -- This is written to the given stream in the following format:
 -- - The first line is the absolute path of the db dir. All other paths
 --   are relative to this.
@@ -325,7 +325,6 @@ typedef int (*log_sequence_fptr) (int se
 --   after the newline.
 -- Using a stream (buffer) instead of a list data structure simplifies 
debugging
 -- and avoids a lot of tiny allocations and pointer manipulations.
--- Returns a nonpositive number on failure.
 */
 typedef gdk_return (*logger_get_snapshot_files_fptr)(stream *plan);
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2363,7 +2363,7 @@ store_unlock(void)
 }
 
 // Helper function for tar_write_header.
-// stream.h makes sure __attribute__ exists
+// stream.h makes sure __attribute__ exists.
 static void tar_write_header_field(char **cursor_ptr, size_t size, const char 
*fmt, ...)
        __attribute__((__format__(__printf__, 3, 4)));
 static void
@@ -2375,7 +2375,11 @@ tar_write_header_field(char **cursor_ptr
        vsnprintf(*cursor_ptr, size + 1, fmt, ap);
        va_end(ap);
 
-       *cursor_ptr += size; /* regardless of bytes written */
+       /* move *cursor_ptr to the start of the next field.
+        * therefore, uncoditionally add `size` and ignore the return value
+        * of vsnprintf, which only tells us how much we wrote into the
+        * current field. */
+       *cursor_ptr += size;
 }
 
 #define TAR_BLOCK_SIZE (512)
@@ -2393,8 +2397,8 @@ tar_write_header(stream *tarfile, const 
        // owned by that user. When unpacking as root it is reasonable that
        // the resulting files are owned by root.
 
-       // The following is taken directly from the definition of the header
-       // in /usr/include/tar.h.
+       // The following is taken directly from the definition
+       // in /usr/include/tar.h on a Linux system.
        tar_write_header_field(&cursor, 100, "%s", path);   // name[100]
        tar_write_header_field(&cursor, 8, "0000644");      // mode[8]
        tar_write_header_field(&cursor, 8, "%07o", 0);      // uid[8]
@@ -2536,10 +2540,11 @@ end:
 static gdk_return
 hot_snapshot_write_tar(stream *out, const char *prefix, const char *plan)
 {
-       (void)out;
        gdk_return ret;
        const char *p = plan; // our cursor in the plan
        time_t timestamp = time(NULL);
+       // We use _path for the absolute path
+       // and _name for the corresponding local relative path
        char abs_src_path[2 * FILENAME_MAX];
        char *src_name = abs_src_path;
        char dest_path[100]; // size imposed by tar format.
@@ -2556,10 +2561,9 @@ hot_snapshot_write_tar(stream *out, cons
        src_name = abs_src_path + len - 1; // - 1 because len includes the 
trailing newline
        *src_name++ = DIR_SEP;
 
-       int scanned;
        char command;
        long size;
-       while ((scanned = sscanf(p, "%c %ld %100s\n%n", &command, &size, 
src_name, &len)) == 3) {
+       while (sscanf(p, "%c %ld %100s\n%n", &command, &size, src_name, &len) 
== 3) {
                p += len;
                strcpy(dest_name, src_name);
                if (size < 0) {
@@ -2619,7 +2623,7 @@ store_hot_snapshot(str tarfile)
        }
        plan_buf = buffer_create(64 * 1024);
        if (!plan_buf) {
-               GDKerror("Failed to allocate buffer");
+               GDKerror("Failed to allocate plan buffer");
                goto end;
        }
        plan_stream = buffer_wastream(plan_buf, "write_snapshot_plan");
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to