Changeset: ba7ad0186586 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ba7ad0186586
Modified Files:
sql/storage/bat/bat_storage.c
sql/storage/store.c
Branch: Feb2013
Log Message:
way more stricked table_validate. This will heart concurrency but solves
the continues story with inconsistent dbs.
See also bug 3233
diffs (188 lines):
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
@@ -342,8 +342,7 @@ append_col(sql_trans *tr, sql_column *c,
{
sql_delta *bat = c->data;
- /* appends only write (isn't save!, ie also set read times) */
- c->base.rtime = c->t->base.rtime = c->t->s->base.rtime = tr->rtime =
tr->stime;
+ /* appends only write */
c->base.wtime = c->t->base.wtime = c->t->s->base.wtime = tr->wtime =
tr->wstime;
if (tpe == TYPE_bat)
delta_append_bat(bat, i);
@@ -356,8 +355,7 @@ append_idx(sql_trans *tr, sql_idx * i, v
{
sql_delta *bat = i->data;
- /* appends only write (isn't save!, ie also set read times) */
- i->base.rtime = i->t->base.rtime = i->t->s->base.rtime = tr->rtime =
tr->stime;
+ /* appends only write */
i->base.wtime = i->t->base.wtime = i->t->s->base.wtime = tr->wtime =
tr->wstime;
if (tpe == TYPE_bat)
delta_append_bat(bat, ib);
@@ -517,6 +515,7 @@ load_delta(sql_delta *bat, int bid, int
bat->bid = temp_create(b);
bat->ibase = BATcount(b);
bat->cnt = bat->ibase;
+ bat->ucnt = 0;
bat->ubid = e_ubat(type);
bat->ibid = e_bat(type);
return LOG_OK;
@@ -676,7 +675,7 @@ create_col(sql_trans *tr, sql_column *c)
} else if (bat && bat->ibid && !isTempTable(c->t)) {
return new_persistent_bat(tr, c->data, c->t->sz);
} else if (!bat->ibid) {
- sql_column *fc;
+ sql_column *fc = NULL;
size_t cnt = 0;
/* alter ? */
@@ -1492,6 +1491,7 @@ tr_update_delta( sql_trans *tr, sql_delt
/* should be insert_inserted */
BATins(cu, ups, TRUE);
BATreplace(cu, ups, TRUE);
+ obat->ucnt = BATcount(cu);
BATcleanProps(cu);
bat_destroy(cu);
}
@@ -1502,6 +1502,8 @@ tr_update_delta( sql_trans *tr, sql_delt
obat->ubid = e_ubat(cur->ttype);
temp_destroy(cbat->ubid);
cbat->ubid = e_ubat(cur->ttype);
+ cbat->ucnt = 0;
+ obat->ucnt = 0;
} else {
BATcommit(ups);
}
@@ -1560,11 +1562,13 @@ update_table(sql_trans *tr, sql_table *f
if (!cc->base.wtime)
continue;
+ assert(oc->base.wtime < cc->base.wtime);
tr_update_delta(tr, oc->data, cc->data, SNAPSHOT_MINSIZE);
- if (cc->base.rtime)
- oc->base.rtime = tr->stime;
- oc->base.wtime = tr->wstime;
+ if (oc->base.rtime < cc->base.rtime)
+ oc->base.rtime = cc->base.rtime;
+ if (oc->base.wtime < cc->base.wtime)
+ oc->base.wtime = cc->base.wtime;
cc->base.rtime = cc->base.wtime = 0;
}
if (ok == LOG_OK && tt->idxs.set) {
@@ -1578,12 +1582,18 @@ update_table(sql_trans *tr, sql_table *f
tr_update_delta(tr, oi->data, ci->data,
SNAPSHOT_MINSIZE);
- if (ci->base.rtime)
- oi->base.rtime = tr->stime;
- oi->base.wtime = tr->wstime;
+ if (oi->base.rtime < ci->base.rtime)
+ oi->base.rtime = ci->base.rtime;
+ if (oi->base.wtime < ci->base.wtime)
+ oi->base.wtime = ci->base.wtime;
ci->base.rtime = ci->base.wtime = 0;
}
}
+ if (tt->base.rtime < ft->base.rtime)
+ tt->base.rtime = ft->base.rtime;
+ if (tt->base.wtime < ft->base.wtime)
+ tt->base.wtime = ft->base.wtime;
+ ft->base.rtime = ft->base.wtime = 0;
return ok;
}
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2172,7 +2172,7 @@ static sql_trans *
trans_init(sql_trans *t, backend_stack stk, sql_trans *ot)
{
t->wtime = t->rtime = 0;
- t->stime = ot->wstime;
+ t->stime = ot->wtime;
t->wstime = timestamp ();
t->schema_updates = 0;
t->dropped = NULL;
@@ -2275,13 +2275,13 @@ rollforward_changeset_updates(sql_trans
if (tbn) {
sql_base *tb = tbn->data;
+ ok = rollforward_updates(tr,
fb, tb, mode);
+
/* update timestamps */
- if (apply && fb->rtime &&
tr->stime > tb->rtime)
- tb->rtime = tr->stime;
- if (apply && fb->wtime &&
tr->wstime > tb->wtime)
- tb->wtime = tr->wstime;
-
- ok = rollforward_updates(tr,
fb, tb, mode);
+ if (apply && fb->rtime &&
fb->rtime > tb->rtime)
+ tb->rtime = fb->rtime;
+ if (apply && fb->wtime &&
fb->wtime > tb->wtime)
+ tb->wtime = fb->wtime;
}
}
if (apply)
@@ -2306,8 +2306,10 @@ rollforward_changeset_updates(sql_trans
cs_add(ts, r, TR_NEW);
else
ok = LOG_ERR;
- fb->rtime = fb->wtime = 0;
- fb->flag = TR_OLD;
+ if (apply) {
+ fb->rtime = fb->wtime =
0;
+ fb->flag = TR_OLD;
+ }
}
} else if (!rollforward_creates(tr, fb, mode)) {
ok = LOG_ERR;
@@ -2663,9 +2665,6 @@ rollforward_update_table(sql_trans *tr,
ok = store_funcs.log_table(tr, ft, tt);
} else if (mode == R_APPLY) {
assert(cs_size(&tt->columns) == cs_size(&ft->columns));
- if (ft->base.rtime)
- tt->base.rtime = tr->stime;
- tt->base.wtime = tr->wstime;
if (bs_debug)
fprintf(stderr, "#update table %s\n", tt->base.name);
ok = store_funcs.update_table(tr, ft, tt);
@@ -2797,28 +2796,24 @@ validate_tables(sql_schema *s, sql_schem
ot = find_sql_table(os, t->base.name);
if (ot && isTable(ot) && isTable(t)) {
- if ((t->base.wtime && (t->base.wtime >
ot->base.rtime && (t->base.wtime > ot->base.wtime))) &&
- (t->base.rtime && t->base.rtime >
ot->base.wtime))
- continue;
- if ((t->base.wtime && (t->base.wtime <
ot->base.rtime || (t->base.wtime < ot->base.wtime && t->base.rtime))) ||
- (t->base.rtime && t->base.rtime <
ot->base.wtime))
+ if ((t->base.wtime && (t->base.wtime <
ot->base.rtime || t->base.wtime < ot->base.wtime)) ||
+ (t->base.rtime && (t->base.rtime <
ot->base.wtime)))
+ return 0;
for (o = t->columns.set->h, p =
ot->columns.set->h; o && p; o = o->next, p = p->next) {
sql_column *c = o->data;
sql_column *oc = p->data;
+ if (!c->base.wtime && !c->base.rtime)
+ continue;
+
/* t wrote, ie. check read and write
time */
/* read or write after t's write */
if (c->base.wtime && (c->base.wtime <
oc->base.rtime
- /* allow for late
appends, ie
- * wtime but no
rtime
- */
- || (c->base.wtime
< oc->base.wtime && c->base.rtime))) {
+ || c->base.wtime <
oc->base.wtime))
return 0;
- }
/* commited write before t's read */
- if (c->base.rtime && c->base.rtime <
oc->base.wtime) {
+ if (c->base.rtime && c->base.rtime <
oc->base.wtime)
return 0;
- }
}
}
}
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list