Changeset: 2cc02cc61378 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2cc02cc61378
Modified Files:
        sql/storage/bat/bat_logger.c
        sql/storage/store.c
        tools/mserver/mserver5.c
Branch: default
Log Message:

Merge with Jan2022 branch.


diffs (truncated from 352 to 300 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
@@ -3164,17 +3164,21 @@ bl_sequence(sqlstore *store, int seq, ln
 /* Write a plan entry to copy part of the given file.
  * That part of the file must remain unchanged until the plan is executed.
  */
-static void
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_lazy_copy_file(stream *plan, const char *name, uint64_t extent)
 {
-       mnstr_printf(plan, "c %" PRIu64 " %s\n", extent, name);
+       if (mnstr_printf(plan, "c %" PRIu64 " %s\n", extent, name) < 0) {
+               GDKerror("%s", mnstr_peek_error(plan));
+               return GDK_FAIL;
+       }
+       return GDK_SUCCEED;
 }
 
 /* Write a plan entry to write the current contents of the given file.
  * The contents are included in the plan so the source file is allowed to
  * change in the mean time.
  */
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_immediate_copy_file(stream *plan, const char *path, const char *name)
 {
        gdk_return ret = GDK_FAIL;
@@ -3202,26 +3206,25 @@ snapshot_immediate_copy_file(stream *pla
                goto end;
        }
 
-       mnstr_printf(plan, "w %zu %s\n", to_copy, name);
+       if (mnstr_printf(plan, "w %zu %s\n", to_copy, name) < 0) {
+               GDKerror("%s", mnstr_peek_error(plan));
+               goto end;
+       }
 
        while (to_copy > 0) {
                size_t chunk = (to_copy <= bufsize) ? to_copy : bufsize;
                ssize_t bytes_read = mnstr_read(s, buf, 1, chunk);
                if (bytes_read < 0) {
-                       char *err = mnstr_error(s);
-                       GDKerror("Reading bytes of component %s failed: %s", 
path, err);
-                       free(err);
+                       GDKerror("Reading bytes of component %s failed: %s", 
path, mnstr_peek_error(s));
                        goto end;
                } else if (bytes_read < (ssize_t) chunk) {
-                       char *err = mnstr_error(s);
-                       GDKerror("Read only %zu/%zu bytes of component %s: %s", 
(size_t) bytes_read, chunk, path, err);
-                       free(err);
+                       GDKerror("Read only %zu/%zu bytes of component %s: %s", 
(size_t) bytes_read, chunk, path, mnstr_peek_error(s));
                        goto end;
                }
 
                ssize_t bytes_written = mnstr_write(plan, buf, 1, chunk);
                if (bytes_written < 0) {
-                       GDKerror("Writing to plan failed");
+                       GDKerror("Writing to plan failed: %s", 
mnstr_peek_error(plan));
                        goto end;
                } else if (bytes_written < (ssize_t) chunk) {
                        GDKerror("write to plan truncated");
@@ -3239,7 +3242,7 @@ end:
 }
 
 /* Add plan entries for all relevant files in the Write Ahead Log */
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_wal(logger *bat_logger, stream *plan, const char *db_dir)
 {
        char log_file[FILENAME_MAX];
@@ -3250,7 +3253,8 @@ snapshot_wal(logger *bat_logger, stream 
                GDKerror("Could not open %s, filename is too large", log_file);
                return GDK_FAIL;
        }
-       snapshot_immediate_copy_file(plan, log_file, log_file + strlen(db_dir) 
+ 1);
+       if (snapshot_immediate_copy_file(plan, log_file, log_file + 
strlen(db_dir) + 1) != GDK_SUCCEED)
+               return GDK_FAIL;
 
        for (ulng id = bat_logger->saved_id+1; id <= bat_logger->id; id++) {
                struct stat statbuf;
@@ -3261,7 +3265,8 @@ snapshot_wal(logger *bat_logger, stream 
                        return GDK_FAIL;
                }
                if (MT_stat(log_file, &statbuf) == 0) {
-                       snapshot_lazy_copy_file(plan, log_file + strlen(db_dir) 
+ 1, statbuf.st_size);
+                       if (snapshot_lazy_copy_file(plan, log_file + 
strlen(db_dir) + 1, statbuf.st_size) != GDK_SUCCEED)
+                               return GDK_FAIL;
                } else {
                        GDKerror("Could not open %s", log_file);
                        return GDK_FAIL;
@@ -3270,7 +3275,7 @@ snapshot_wal(logger *bat_logger, stream 
        return GDK_SUCCEED;
 }
 
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_heap(stream *plan, const char *db_dir, uint64_t batid, const char 
*filename, const char *suffix, uint64_t extent)
 {
        char path1[FILENAME_MAX];
@@ -3291,8 +3296,7 @@ snapshot_heap(stream *plan, const char *
                return GDK_FAIL;
        }
        if (MT_stat(path1, &statbuf) == 0) {
-               snapshot_lazy_copy_file(plan, path1 + offset, extent);
-               return GDK_SUCCEED;
+               return snapshot_lazy_copy_file(plan, path1 + offset, extent);
        }
        if (errno != ENOENT) {
                GDKsyserror("Error stat'ing %s", path1);
@@ -3307,8 +3311,7 @@ snapshot_heap(stream *plan, const char *
                return GDK_FAIL;
        }
        if (MT_stat(path2, &statbuf) == 0) {
-               snapshot_lazy_copy_file(plan, path2 + offset, extent);
-               return GDK_SUCCEED;
+               return snapshot_lazy_copy_file(plan, path2 + offset, extent);
        }
        if (errno != ENOENT) {
                GDKsyserror("Error stat'ing %s", path2);
@@ -3322,7 +3325,7 @@ snapshot_heap(stream *plan, const char *
 /* Add plan entries for all persistent BATs by looping over the BBP.dir.
  * Also include the BBP.dir itself.
  */
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_bats(stream *plan, const char *db_dir)
 {
        char bbpdir[FILENAME_MAX];
@@ -3330,6 +3333,7 @@ snapshot_bats(stream *plan, const char *
        char line[1024];
        int gdk_version, len;
        gdk_return ret = GDK_FAIL;
+       ssize_t n = 0;
 
        len = snprintf(bbpdir, FILENAME_MAX, "%s/%s/%s", db_dir, BAKDIR, 
"BBP.dir");
        if (len == -1 || len >= FILENAME_MAX) {
@@ -3347,7 +3351,7 @@ snapshot_bats(stream *plan, const char *
                goto end;
        }
        if (mnstr_readline(cat, line, sizeof(line)) < 0) {
-               GDKerror("Could not read first line of %s", bbpdir);
+               GDKerror("Could not read first line of %s: %s", bbpdir, 
mnstr_peek_error(cat));
                goto end;
        }
        if (sscanf(line, "BBP.dir, GDKversion %d", &gdk_version) != 1) {
@@ -3365,21 +3369,21 @@ snapshot_bats(stream *plan, const char *
                goto end;
        }
        if (mnstr_readline(cat, line, sizeof(line)) < 0) {
-               GDKerror("Couldn't skip the second line of %s", bbpdir);
+               GDKerror("Couldn't skip the second line of %s: %s", bbpdir, 
mnstr_peek_error(cat));
                goto end;
        }
        if (mnstr_readline(cat, line, sizeof(line)) < 0) {
-               GDKerror("Couldn't skip the third line of %s", bbpdir);
+               GDKerror("Couldn't skip the third line of %s: %s", bbpdir, 
mnstr_peek_error(cat));
                goto end;
        }
 
        /* TODO get transaction id and last processed log file id */
        if (mnstr_readline(cat, line, sizeof(line)) < 0) {
-               GDKerror("Couldn't skip the 4th line of %s", bbpdir);
+               GDKerror("Couldn't skip the 4th line of %s: %s", bbpdir, 
mnstr_peek_error(cat));
                goto end;
        }
 
-       while (mnstr_readline(cat, line, sizeof(line)) > 0) {
+       while ((n = mnstr_readline(cat, line, sizeof(line))) > 0) {
                uint64_t batid;
                char type[16];
                uint16_t width;
@@ -3421,13 +3425,13 @@ snapshot_bats(stream *plan, const char *
                                /* fallthrough */
                        case 5:
                                // tail only
-                               snapshot_heap(plan, db_dir, batid, filename,
-                                                         strcmp(type, "str") 
== 0 ? width == 1 ? ".tail1" : width == 2 ? ".tail2" :
+                               ret = snapshot_heap(plan, db_dir, batid, 
filename,
+                                                                       
strcmp(type, "str") == 0 ? width == 1 ? ".tail1" : width == 2 ? ".tail2" :
 #if SIZEOF_VAR_T == 8
-                                                         width == 4 ? ".tail4" 
:
+                                                                       width 
== 4 ? ".tail4" :
 #endif
-                                                         ".tail" : ".tail",
-                                                         tail_free);
+                                                                       ".tail" 
: ".tail",
+                                                                       
tail_free);
                                if (ret != GDK_SUCCEED)
                                        goto end;
                                /* fallthrough */
@@ -3436,6 +3440,10 @@ snapshot_bats(stream *plan, const char *
                                break;
                }
        }
+       if (n < 0) {
+               GDKerror("%s", mnstr_peek_error(cat));
+               return GDK_FAIL;
+       }
 
 end:
        if (cat) {
@@ -3450,7 +3458,7 @@ end:
  * With this information, a replica initialized from this snapshot can
  * be configured to catch up with its master by replaying later transactions.
  */
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_wlc(stream *plan, const char *db_dir)
 {
        const char name[] = "wlr.config.in";
@@ -3468,13 +3476,16 @@ snapshot_wlc(stream *plan, const char *d
                , wlc_beat, wlc_batches
        );
 
-       mnstr_printf(plan, "w %d %s\n", len, name);
-       mnstr_write(plan, buf, 1, len);
+       if (mnstr_printf(plan, "w %d %s\n", len, name) < 0 ||
+               mnstr_write(plan, buf, 1, len) < 0) {
+               GDKerror("%s", mnstr_peek_error(plan));
+               return GDK_FAIL;
+       }
 
        return GDK_SUCCEED;
 }
 
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 snapshot_vaultkey(stream *plan, const char *db_dir)
 {
        char path[FILENAME_MAX];
@@ -3487,8 +3498,7 @@ snapshot_vaultkey(stream *plan, const ch
                return GDK_FAIL;
        }
        if (MT_stat(path, &statbuf) == 0) {
-               snapshot_lazy_copy_file(plan, ".vaultkey", statbuf.st_size);
-               return GDK_SUCCEED;
+               return snapshot_lazy_copy_file(plan, ".vaultkey", 
statbuf.st_size);
        }
        if (errno == ENOENT) {
                // No .vaultkey? Fine.
@@ -3498,6 +3508,7 @@ snapshot_vaultkey(stream *plan, const ch
        GDKsyserror("Error stat'ing %s", path);
        return GDK_FAIL;
 }
+
 static gdk_return
 bl_snapshot(sqlstore *store, stream *plan)
 {
@@ -3508,14 +3519,19 @@ bl_snapshot(sqlstore *store, stream *pla
 
        // Farm 0 is always the persistent farm.
        db_dir = GDKfilepath(0, NULL, "", NULL);
+       if (db_dir == NULL)
+               return GDK_FAIL;
        db_dir_len = strlen(db_dir);
        if (db_dir[db_dir_len - 1] == DIR_SEP)
                db_dir[db_dir_len - 1] = '\0';
 
-       mnstr_printf(plan, "%s\n", db_dir);
-
-       // Please monetdbd
-       mnstr_printf(plan, "w 0 .uplog\n");
+       if (mnstr_printf(plan, "%s\n", db_dir) < 0 ||
+               // Please monetdbd
+               mnstr_printf(plan, "w 0 .uplog\n") < 0) {
+               GDKerror("%s", mnstr_peek_error(plan));
+               ret = GDK_FAIL;
+               goto end;
+       }
 
        ret = snapshot_vaultkey(plan, db_dir);
        if (ret != GDK_SUCCEED)
@@ -3535,8 +3551,7 @@ bl_snapshot(sqlstore *store, stream *pla
 
        ret = GDK_SUCCEED;
 end:
-       if (db_dir)
-               GDKfree(db_dir);
+       GDKfree(db_dir);
        return ret;
 }
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2389,7 +2389,7 @@ tar_write_header_field(char **cursor_ptr
 #define TAR_BLOCK_SIZE (512)
 
 // Write a tar header to the given stream.
-static gdk_return
+static gdk_return __attribute__((__warn_unused_result__))
 tar_write_header(stream *tarfile, const char *path, time_t mtime, size_t size)
 {
        char buf[TAR_BLOCK_SIZE] = {0};
@@ -2443,7 +2443,7 @@ tar_write_header(stream *tarfile, const 
  * multiple of TAR_BLOCK_SIZE.  Make sure all writes are in multiples
  * of TAR_BLOCK_SIZE.
  */
-static gdk_return
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to