Changeset: deb1764c366c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=deb1764c366c
Modified Files:
sql/backends/monet5/sql.mx
sql/backends/monet5/sql_result.c
sql/include/sql_catalog.h
sql/storage/bat/bat_storage.c
sql/storage/restrict/restrict_storage.c
sql/storage/store.c
sql/test/leaks/Tests/check0.stable.out
sql/test/leaks/Tests/temp2.stable.out
sql/test/leaks/Tests/temp3.stable.out
Branch: Feb2013
Log Message:
ported fixes for the concurrency problems.
diffs (truncated from 1110 to 300 lines):
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -6630,7 +6630,7 @@ str SQLcluster1(Client cntxt, MalBlkPtr
if ( t == NULL)
throw(SQL,"sql.cluster","42S02!Table missing");
tr = m->session->tr;
- t->base.wtime = s->base.wtime = tr->wtime = tr->stime;
+ t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
/* actually build the hash on the multi-column primary key */
@@ -6668,7 +6668,8 @@ str SQLcluster1(Client cntxt, MalBlkPtr
d->bid = 0;
d->ibase = 0;
d->ibid = bid; /* use the insert bat */
- c->base.wtime = c->base.rtime = tr->stime;
+ c->base.wtime = tr->wstime;
+ c->base.rtime = tr->stime;
}
/* bat was cleared */
t->cleared = 1;
@@ -6705,7 +6706,7 @@ SQLcluster2(Client cntxt, MalBlkPtr mb,
throw(SQL,"sql.cluster","42S02!Table missing");
tr = m->session->tr;
- t->base.wtime = s->base.wtime = tr->wtime = tr->stime;
+ t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
for (o = t->columns.set->h; o; o = o->next) {
sql_delta *d;
@@ -6744,7 +6745,8 @@ SQLcluster2(Client cntxt, MalBlkPtr mb,
d->ibase = 0;
d->ibid = bid; /* use the insert bat */
- c->base.wtime = c->base.rtime = tr->stime;
+ c->base.wtime = tr->wstime;
+ c->base.rtime = tr->stime;
}
/* bat was cleared */
t->cleared = 1;
@@ -6804,7 +6806,7 @@ vacuum(Client cntxt, MalBlkPtr mb, MalSt
}
tr = m->session->tr;
- t->base.wtime = s->base.wtime = tr->wtime = tr->stime;
+ t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
/* get the deletions BAT*/
@@ -6851,7 +6853,8 @@ vacuum(Client cntxt, MalBlkPtr mb, MalSt
d->ibase = 0;
d->cnt -= dbat->cnt;
d->ibid = bids[i]; /* use the insert bat */
- c->base.wtime = c->base.rtime = tr->stime;
+ c->base.wtime = tr->wstime;
+ c->base.rtime = tr->stime;
}
BATclear(del, TRUE);
BBPreleaseref(del->batCacheid);
@@ -7032,7 +7035,8 @@ compression(Client cntxt, MalBlkPtr mb,
d->bid = 0;
d->ibase = 0;
d->ibid = e->batCacheid; /* use the insert bat */
- c->base.wtime = c->base.rtime = tr->stime;
+ c->base.wtime = tr->wstime;
+ c->base.rtime = tr->stime;
snprintf(buf,BUFSIZ,"%s/%s/%s/0", *sch, *tbl, c->base.name);
if (compr)
msg = DICTcompress(&ret, &nme, &b->batCacheid);
@@ -7044,7 +7048,7 @@ compression(Client cntxt, MalBlkPtr mb,
}
/* bat was cleared */
t->cleared = 1;
- t->base.wtime = s->base.wtime = tr->wtime = tr->stime;
+ t->base.wtime = s->base.wtime = tr->wtime = tr->wstime;
t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
return msg;
}
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -692,10 +692,8 @@ mvc_import_table(Client cntxt, mvc *m, b
BAT *b = store_funcs.bind_col(m->session->tr,
c, RDONLY);
sql_delta *d = c->data;
- c->base.wtime = c->t->base.wtime =
c->t->s->base.wtime = m->session->tr->wtime = m->session->tr->stime;
- d->cnt = BATcount(b);
- d->ibase = BATcount(b);
-
+ c->base.wtime = t->base.wtime =
t->s->base.wtime = m->session->tr->wtime = m->session->tr->wstime;
+ d->ibase = d->cnt = BATcount(b);
BBPunfix(b->batCacheid);
}
}
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -193,7 +193,8 @@ typedef size_t backend_stack;
typedef struct sql_trans {
char *name;
- int stime; /* transaction time stamp (aka start time) */
+ int stime; /* read transaction time stamp */
+ int wstime; /* write transaction time stamp */
int rtime;
int wtime;
int schema_number; /* schema timestamp */
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
@@ -248,7 +248,7 @@ update_col(sql_trans *tr, sql_column *c,
{
sql_delta *bat = c->data;
- c->base.wtime = c->t->base.wtime = c->t->s->base.wtime = tr->wtime =
tr->stime;
+ c->base.wtime = c->t->base.wtime = c->t->s->base.wtime = tr->wtime =
tr->wstime;
c->base.rtime = c->t->base.rtime = c->t->s->base.rtime = tr->rtime =
tr->stime;
if (tpe == TYPE_bat)
delta_update_bat(bat, tids, upd, isNew(c));
@@ -261,7 +261,7 @@ update_idx(sql_trans *tr, sql_idx * i, v
{
sql_delta *bat = i->data;
- i->base.wtime = i->t->base.wtime = i->t->s->base.wtime = tr->wtime =
tr->stime;
+ i->base.wtime = i->t->base.wtime = i->t->s->base.wtime = tr->wtime =
tr->wstime;
i->base.rtime = i->t->base.rtime = i->t->s->base.rtime = tr->rtime =
tr->stime;
if (tpe == TYPE_bat)
delta_update_bat(bat, tids, upd, isNew(i));
@@ -272,12 +272,17 @@ update_idx(sql_trans *tr, sql_idx * i, v
void
delta_append_bat( sql_delta *bat, BAT *i )
{
- BAT *b = temp_descriptor(bat->ibid);
+ BAT *c = BBPquickdesc(bat->bid, 0), *b;
+
+ if (!BATcount(i))
+ return ;
+ b = temp_descriptor(bat->ibid);
if (bat->cached) {
bat_destroy(bat->cached);
bat->cached = NULL;
}
+ assert(!c || BATcount(c) == bat->ibase);
if (!isEbat(b)){
/* try to use mmap() */
if (BATcount(b)+BATcount(i) > (BUN) REMAP_PAGE_MAXSIZE) {
@@ -292,6 +297,7 @@ delta_append_bat( sql_delta *bat, BAT *i
}
BATappend(b, i, TRUE);
bat->cnt += BATcount(i);
+ assert(BUNlast(b) > b->batInserted);
bat_destroy(b);
}
@@ -299,11 +305,13 @@ void
delta_append_val( sql_delta *bat, void *i )
{
BAT *b = temp_descriptor(bat->ibid);
+ BAT *c = BBPquickdesc(bat->bid, 0);
if (bat->cached) {
bat_destroy(bat->cached);
bat->cached = NULL;
}
+ assert(!c || BATcount(c) == bat->ibase);
if (isEbat(b)) {
bat_destroy(b);
temp_destroy(bat->ibid);
@@ -311,6 +319,7 @@ delta_append_val( sql_delta *bat, void *
b = temp_descriptor(bat->ibid);
}
BUNappend(b, i, TRUE);
+ assert(BUNlast(b) > b->batInserted);
bat->cnt ++;
bat_destroy(b);
}
@@ -321,7 +330,7 @@ append_col(sql_trans *tr, sql_column *c,
sql_delta *bat = c->data;
/* appends only write */
- c->base.wtime = c->t->base.wtime = c->t->s->base.wtime = tr->wtime =
tr->stime;
+ 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);
else
@@ -334,7 +343,7 @@ append_idx(sql_trans *tr, sql_idx * i, v
sql_delta *bat = i->data;
/* appends only write */
- i->base.wtime = i->t->base.wtime = i->t->s->base.wtime = tr->wtime =
tr->stime;
+ 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);
else
@@ -406,7 +415,7 @@ delete_tab(sql_trans *tr, sql_table * t,
}
/* deletes only write */
- t->base.wtime = t->s->base.wtime = tr->wtime = tr->stime;
+ t->base.wtime = t->s->base.wtime = tr->wtime = tr->wstime;
if (tpe == TYPE_bat)
delta_delete_bat(bat, ib);
else
@@ -1185,7 +1194,7 @@ BATcleanProps( BAT *b )
}
static int
-gtr_update_delta( sql_trans *tr, sql_delta *cbat)
+gtr_update_delta( sql_trans *tr, sql_delta *cbat, int *changes)
{
int ok = LOG_OK;
BAT *ups, *ins, *cur;
@@ -1197,6 +1206,7 @@ gtr_update_delta( sql_trans *tr, sql_del
ins = temp_descriptor(cbat->ibid);
/* any inserts */
if (BUNlast(ins) > BUNfirst(ins)) {
+ (*changes)++;
if (BATcount(cur)+BATcount(ins) > (BUN) REMAP_PAGE_MAXSIZE) {
/* try to use mmap() */
BATmmap(cur, STORE_MMAP, STORE_MMAP,
STORE_MMAP, STORE_MMAP, 1);
}
@@ -1209,66 +1219,89 @@ gtr_update_delta( sql_trans *tr, sql_del
}
bat_destroy(ins);
- ups = temp_descriptor(cbat->ubid);
- /* any updates */
- if (BUNlast(ups) > BUNfirst(ups)) {
- void_replace_bat(cur, ups, TRUE);
- temp_destroy(cbat->ubid);
- cbat->ubid = e_ubat(cur->ttype);
+ if (cbat->ucnt) {
+ ups = temp_descriptor(cbat->ubid);
+ /* any updates */
+ if (BUNlast(ups) > BUNfirst(ups)) {
+ (*changes)++;
+ void_replace_bat(cur, ups, TRUE);
+ temp_destroy(cbat->ubid);
+ cbat->ubid = e_ubat(cur->ttype);
+ cbat->ucnt = 0;
+ }
+ bat_destroy(ups);
}
- bat_destroy(ups);
bat_destroy(cur);
return ok;
}
static int
-gtr_update_table(sql_trans *tr, sql_table *t)
+gtr_update_table(sql_trans *tr, sql_table *t, int *tchanges)
{
int ok = LOG_OK;
node *n;
for (n = t->columns.set->h; ok == LOG_OK && n; n = n->next) {
+ int changes = 0;
sql_column *c = n->data;
if (!c->base.wtime)
continue;
- ok = gtr_update_delta(tr, c->data);
+ ok = gtr_update_delta(tr, c->data, &changes);
+ if (changes)
+ c->base.wtime = tr->wstime;
+ (*tchanges) |= changes;
}
if (ok == LOG_OK && t->idxs.set) {
for (n = t->idxs.set->h; ok == LOG_OK && n; n = n->next) {
+ int changes = 0;
sql_idx *ci = n->data;
/* some indices have no bats */
if (!ci->base.wtime)
continue;
- ok = gtr_update_delta(tr, ci->data);
+ ok = gtr_update_delta(tr, ci->data, &changes);
+ if (changes)
+ ci->base.wtime = tr->wstime;
+ (*tchanges) |= changes;
}
}
+ if (*tchanges)
+ t->base.wtime = tr->wstime;
return ok;
}
-typedef int (*gtr_update_table_fptr)( sql_trans *tr, sql_table *t);
+typedef int (*gtr_update_table_fptr)( sql_trans *tr, sql_table *t, int
*changes);
static int
-_gtr_update( sql_trans *tr, gtr_update_table_fptr gtr_update_table_f )
+_gtr_update( sql_trans *tr, gtr_update_table_fptr gtr_update_table_f)
{
- int ok = LOG_OK;
+ int ok = LOG_OK, tchanges = 0;
node *sn;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list