Changeset: 1f666ca11550 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1f666ca11550
Modified Files:
sql/storage/bat/bat_logger.c
sql/storage/store.c
Branch: pax-log
Log Message:
Merge with default.
diffs (truncated from 386 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
@@ -19,6 +19,7 @@
#define CATALOG_JUN2020_MMT 52206 /* only in Jun2020-mmt */
#define CATALOG_OCT2020 52205 /* first in Oct2020 */
#define CATALOG_JUL2021 52300 /* first in Jul2021 */
+#define CATALOG_JAN2022 52301 /* first in Jan2022 */
/* Note, CATALOG version 52300 is the first one where the basic system
* tables (the ones created in store.c) have fixed and unchangeable
@@ -71,6 +72,14 @@ bl_preversion(sqlstore *store, int oldve
}
#endif
+#ifdef CATALOG_JAN2022
+ if (oldversion == CATALOG_JAN2022) {
+ /* upgrade to default releases */
+ store->catalog_version = oldversion;
+ return GDK_SUCCEED;
+ }
+#endif
+
return GDK_FAIL;
}
@@ -3169,17 +3178,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;
@@ -3207,26 +3220,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");
@@ -3244,7 +3256,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];
@@ -3255,7 +3267,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;
@@ -3266,7 +3279,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;
@@ -3275,7 +3289,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];
@@ -3296,8 +3310,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);
@@ -3312,8 +3325,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);
@@ -3327,7 +3339,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];
@@ -3335,6 +3347,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) {
@@ -3352,7 +3365,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) {
@@ -3370,21 +3383,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;
@@ -3426,13 +3439,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 */
@@ -3441,6 +3454,10 @@ snapshot_bats(stream *plan, const char *
break;
}
}
+ if (n < 0) {
+ GDKerror("%s", mnstr_peek_error(cat));
+ return GDK_FAIL;
+ }
end:
if (cat) {
@@ -3455,7 +3472,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";
@@ -3473,13 +3490,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];
@@ -3492,8 +3512,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.
@@ -3503,6 +3522,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)
{
@@ -3513,14 +3533,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)
@@ -3540,8 +3565,7 @@ bl_snapshot(sqlstore *store, stream *pla
ret = GDK_SUCCEED;
end:
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]