Changeset: 480434bbbc28 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=480434bbbc28
Modified Files:
gdk/gdk_logger.c
gdk/gdk_storage.c
sql/server/rel_optimizer.c
sql/server/sql_env.c
sql/storage/bat/bat_storage.c
sql/storage/store.c
Branch: unlock
Log Message:
cleanup now we don't depend on the active transactions
diffs (truncated from 323 to 300 lines):
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -884,7 +884,8 @@ logger_read_transaction(logger *lg)
int ok = 1;
int dbg = GDKdebug;
- GDKdebug &= ~(CHECKMASK|PROPMASK);
+ if (!lg->flushing)
+ GDKdebug &= ~(CHECKMASK|PROPMASK);
while (err == LOG_OK && (ok=log_read_format(lg, &l))) {
if (l.flag == 0 && l.id == 0) {
@@ -967,7 +968,8 @@ logger_read_transaction(logger *lg)
}
while (tr)
tr = tr_abort(lg, tr);
- GDKdebug = dbg;
+ if (!lg->flushing)
+ GDKdebug = dbg;
if (!ok)
return LOG_EOF;
return err;
@@ -979,10 +981,8 @@ logger_readlog(logger *lg, char *filenam
log_return err = LOG_OK;
time_t t0, t1;
struct stat sb;
- int dbg = GDKdebug;
assert(!lg->inmemory);
- GDKdebug &= ~(CHECKMASK|PROPMASK);
if (lg->debug & 1) {
fprintf(stderr, "#logger_readlog opening %s\n", filename);
@@ -1026,7 +1026,6 @@ logger_readlog(logger *lg, char *filenam
printf("# Finished reading the write-ahead log '%s'\n",
filename);
fflush(stdout);
}
- GDKdebug = dbg;
/* we cannot distinguish errors from incomplete transactions
* (even if we would log aborts in the logs). So we simply
* abort and move to the next log file */
@@ -1629,6 +1628,7 @@ logger_load(int debug, const char *fn, c
}
needcommit = true;
}
+ dbg = GDKdebug;
GDKdebug &= ~CHECKMASK;
if (needcommit && bm_commit(lg) != GDK_SUCCEED) {
GDKerror("Logger_new: commit failed");
@@ -1855,7 +1855,7 @@ logger_flush(logger *lg)
lng
logger_changes(logger *lg)
{
- return (lg->id - lg->saved_id);
+ return (lg->id - lg->saved_id - 1);
}
int
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -828,6 +828,7 @@ BATload_intern(bat bid, bool lock)
b = DESCload(bid);
if (b == NULL) {
+ assert(0);
return NULL;
}
@@ -835,6 +836,7 @@ BATload_intern(bat bid, bool lock)
if (b->ttype != TYPE_void) {
if (HEAPload(&b->theap, nme, "tail", b->batRestricted ==
BAT_READ) != GDK_SUCCEED) {
HEAPfree(&b->theap, false);
+ assert(0);
return NULL;
}
assert(b->theap.size >> b->tshift <= BUN_MAX);
@@ -848,6 +850,7 @@ BATload_intern(bat bid, bool lock)
if (HEAPload(b->tvheap, nme, "theap", b->batRestricted ==
BAT_READ) != GDK_SUCCEED) {
HEAPfree(&b->theap, false);
HEAPfree(b->tvheap, false);
+ assert(0);
return NULL;
}
if (ATOMstorage(b->ttype) == TYPE_str) {
@@ -867,6 +870,7 @@ BATload_intern(bat bid, bool lock)
HEAPfree(&b->theap, false);
if (b->tvheap)
HEAPfree(b->tvheap, false);
+ assert(0);
return NULL;
}
return b;
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -8665,7 +8665,6 @@ rel_dicttable(mvc *sql, sql_column *c, c
return rel;
}
-/* rewrite merge tables into union of base tables and call optimizer again */
static sql_rel *
rel_add_dicts(mvc *sql, sql_rel *rel, int *changes)
{
diff --git a/sql/server/sql_env.c b/sql/server/sql_env.c
--- a/sql/server/sql_env.c
+++ b/sql/server/sql_env.c
@@ -60,7 +60,7 @@ sql_update_var(mvc *m, sql_schema *s, co
if (sgn > (VAR_UPCAST) GDK_int_max)
throw(SQL,"sql.update_var", SQLSTATE(42000)
"Value too large for '%s.%s'\n", s->base.name, name);
- if (strcmp(name, "debug") == 0)
+ if (0 && strcmp(name, "debug") == 0)
m->debug = (int) sgn;
else if (strcmp(name, "current_timezone") == 0)
m->timezone = (int) sgn;
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -2047,7 +2047,7 @@ tr_log_cs( sql_trans *tr, column_storage
for (; segs; segs=segs->next) {
if (segs->owner == tr) {
BAT *ins = temp_descriptor(cs->bid);
- assert(ATOMIC_GET(&store_nr_active)>0);
+ assert(ins);
ok = log_bat(bat_logger, ins, id, segs->start,
segs->end-segs->start);
bat_destroy(ins);
}
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2046,97 +2046,6 @@ store_init(int debug, store_type store,
return store_load(stk);
}
-// All this must only be accessed while holding the flush_lock.
-// The exception is flush_now, which can be set by anyone at any
-// time and therefore needs some special treatment.
-static struct {
- // These two are inputs, set from outside the store_manager
- bool enabled;
- ATOMIC_TYPE flush_now;
- // These are state set from within the store_manager
- bool working;
- int countdown_ms;
- unsigned int cycle;
- char *reason_to;
- char *reason_not_to;
-} flusher = {
- .flush_now = ATOMIC_VAR_INIT(0),
- .enabled = true,
-};
-
-static void
-flusher_new_cycle(void)
-{
- int cycle_time = GDKdebug & FORCEMITOMASK ? 500 : 50000;
-
- // do not touch .enabled and .flush_now, those are inputs
- flusher.working = false;
- flusher.countdown_ms = cycle_time;
- flusher.cycle += 1;
- flusher.reason_to = NULL;
- flusher.reason_not_to = NULL;
-}
-
-/* Determine whether this is a good moment to flush the log.
- * Note: this function clears flusher.flush_now if it was set,
- * so if it returns true you must either flush the log or
- * set flush_log to true again, otherwise the request will
- * be lost.
- *
- * This is done this way because flush_now can be set at any time
- * without first obtaining flush_lock. To avoid time-of-check-to-time-of-use
- * issues, this function both checks and clears the flag.
- */
-static bool
-flusher_should_run(void)
-{
- // We will flush if we have a reason to and no reason not to.
- char *reason_to = NULL, *reason_not_to = NULL;
-
- if (flusher.countdown_ms <= 0)
- reason_to = "timer expired";
-
- if (logger_funcs.changes() >= 0)
- reason_to = "changes";
- else
- reason_not_to = "no changes";
-
- // Read and clear flush_now. If we decide not to flush
- // we'll put it back.
- bool my_flush_now = (bool) ATOMIC_XCG(&flusher.flush_now, 0);
- if (my_flush_now) {
- reason_to = "user request";
- reason_not_to = NULL;
- }
-
- if (ATOMIC_GET(&store_nr_active) > 0)
- reason_not_to = "awaiting idle time";
-
- if (!flusher.enabled && !my_flush_now)
- reason_not_to = "disabled";
-
- bool do_it = (reason_to && !reason_not_to);
-
- TRC_DEBUG_IF(SQL_STORE)
- {
- if (reason_to != flusher.reason_to || reason_not_to !=
flusher.reason_not_to) {
- TRC_DEBUG_ENDIF(SQL_STORE, "Store flusher: %s, reason
to flush: %s, reason not to: %s\n",
-
do_it ? "flushing" : "not flushing",
-
reason_to ? reason_to : "none",
-
reason_not_to ? reason_not_to : "none");
- }
- }
-
- flusher.reason_to = reason_to;
- flusher.reason_not_to = reason_not_to;
-
- // Remember the request for next time.
- if (!do_it && my_flush_now)
- ATOMIC_SET(&flusher.flush_now, 1);
-
- return do_it;
-}
-
void
store_exit(void)
{
@@ -2144,13 +2053,6 @@ store_exit(void)
TRC_DEBUG(SQL_STORE, "Store locked\n");
- /* busy wait till the logmanager is ready */
- while (flusher.working) {
- MT_lock_unset(&flush_lock);
- MT_sleep_ms(100);
- MT_lock_set(&flush_lock);
- }
-
if (gtrans) {
MT_lock_unset(&flush_lock);
sequences_exit();
@@ -2189,10 +2091,10 @@ store_apply_deltas(void)
{
int res = LOG_OK;
- flusher.working = true;
/* make sure we reset all transactions on re-activation */
//gtrans->wstime = timestamp();
/* cleanup drop tables, columns and idxs first */
+ if (0)
trans_cleanup(gtrans);
res = logger_funcs.flush();
@@ -2207,28 +2109,13 @@ store_apply_deltas(void)
sql_trans_destroy(gtrans, false);
gtrans = ntrans;
}
- flusher.working = false;
-
return res;
}
-/* Call while holding flush_lock */
-static void
-wait_until_flusher_idle(void)
-{
- while (flusher.working) {
- const int sleeptime = 100;
- MT_lock_unset(&flush_lock);
- MT_sleep_ms(sleeptime);
- MT_lock_set(&flush_lock);
- }
-}
void
store_suspend_log(void)
{
MT_lock_set(&flush_lock);
- flusher.enabled = false;
- wait_until_flusher_idle();
MT_lock_unset(&flush_lock);
}
@@ -2236,7 +2123,6 @@ void
store_resume_log(void)
{
MT_lock_set(&flush_lock);
- flusher.enabled = true;
MT_lock_unset(&flush_lock);
}
@@ -2251,12 +2137,9 @@ store_manager(void)
while (!GDKexiting()) {
int res;
- if (!flusher_should_run()) {
+ if (logger_funcs.changes() <= 0) {
const int sleeptime = 100;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list