Changeset: adc3bce56004 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/adc3bce56004
Modified Files:
sql/storage/store.c
Branch: Jul2021
Log Message:
Initialize and destroy atomic (pointer) variables.
diffs (290 lines):
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -156,6 +156,7 @@ idx_destroy(sqlstore *store, sql_idx * i
if (ATOMIC_PTR_GET(&i->data))
store->storage_api.destroy_idx(store, i);
+ ATOMIC_PTR_DESTROY(&i->data);
_DELETE(i->base.name);
_DELETE(i);
}
@@ -187,6 +188,7 @@ column_destroy(sqlstore *store, sql_colu
return;
if (ATOMIC_PTR_GET(&c->data))
store->storage_api.destroy_col(store, c);
+ ATOMIC_PTR_DESTROY(&c->data);
_DELETE(c->min);
_DELETE(c->max);
_DELETE(c->def);
@@ -209,6 +211,7 @@ table_destroy(sqlstore *store, sql_table
return;
if (isTable(t))
store->storage_api.destroy_del(store, t);
+ ATOMIC_PTR_DESTROY(&t->data);
/* cleanup its parts */
list_destroy2(t->members, store);
ol_destroy(t->idxs, store);
@@ -445,6 +448,7 @@ load_idx(sql_trans *tr, sql_table *t, re
ni->columns = list_new(tr->sa, (fdestroy) &kc_destroy);
ni->t = t;
ni->key = NULL;
+ ATOMIC_PTR_INIT(&ni->data, NULL);
if (isTable(ni->t) && idx_has_column(ni->type))
store->storage_api.create_idx(tr, ni);
@@ -550,6 +554,7 @@ load_column(sql_trans *tr, sql_table *t,
st = (char*)store->table_api.table_fetch_value(rt_cols,
find_sql_column(columns, "storage"));
if (!strNil(st))
c->storage_type = SA_STRDUP(tr->sa, st);
+ ATOMIC_PTR_INIT(&c->data, NULL);
c->t = t;
if (isTable(c->t))
store->storage_api.create_col(tr, c);
@@ -707,10 +712,12 @@ load_table(sql_trans *tr, sql_schema *s,
t->triggers = ol_new(tr->sa, (destroy_fptr) &trigger_destroy, store);
if (isMergeTable(t) || isReplicaTable(t))
t->members = list_new(tr->sa, (fdestroy) &part_destroy);
+ ATOMIC_PTR_INIT(&t->data, NULL);
if (isTable(t)) {
if (store->storage_api.create_del(tr, t) != LOG_OK) {
TRC_DEBUG(SQL_STORE, "Load table '%s' is missing
'deletes'", t->base.name);
+ ATOMIC_PTR_DESTROY(&t->data);
return NULL;
}
}
@@ -751,8 +758,10 @@ load_table(sql_trans *tr, sql_schema *s,
if (ntid != t->base.id)
break;
sql_column* next = load_column(tr, t, rt_cols);
- if (next == NULL)
+ if (next == NULL) {
+ table_destroy(store, t);
return NULL;
+ }
if (ol_add(t->columns, &next->base)) {
table_destroy(store, t);
return NULL;
@@ -804,6 +813,7 @@ load_table(sql_trans *tr, sql_schema *s,
if (!k || ol_add(t->triggers, &k->base) ||
os_add(s->triggers, tr, k->base.name, dup_base(&k->base))) {
table_destroy(store, t);
+ return NULL;
}
}
return t;
@@ -1459,6 +1469,7 @@ bootstrap_create_column(sql_trans *tr, s
if (ol_add(t->columns, &col->base))
return NULL;
+ ATOMIC_PTR_INIT(&col->data, NULL);
if (isTable(col->t))
store->storage_api.create_col(tr, col);
return col;
@@ -1491,6 +1502,7 @@ create_sql_table_with_id(sql_allocator *
t->s = NULL;
t->properties = properties;
memset(&t->part, 0, sizeof(t->part));
+ ATOMIC_PTR_INIT(&t->data, NULL);
return t;
}
@@ -1639,6 +1651,7 @@ bootstrap_create_table(sql_trans *tr, sq
return NULL;
}
if (os_add(s->tables, tr, name, &t->base)) {
+ table_destroy(store, t);
return NULL;
}
return t;
@@ -2821,11 +2834,14 @@ column_dup(sql_trans *tr, sql_column *oc
c->storage_type = NULL;
if (oc->storage_type)
c->storage_type = SA_STRDUP(sa, oc->storage_type);
+ ATOMIC_PTR_INIT(&c->data, NULL);
if (isTable(c->t)) {
if (isTempTable(c->t)) {
- if ((res = store->storage_api.create_col(tr, c)))
+ if ((res = store->storage_api.create_col(tr, c))) {
+ ATOMIC_PTR_DESTROY(&c->data);
return res;
+ }
} else {
ATOMIC_PTR_SET(&c->data,
store->storage_api.col_dup(oc));
}
@@ -2916,11 +2932,14 @@ idx_dup(sql_trans *tr, sql_idx * i, sql_
ni->t = t;
ni->type = i->type;
ni->key = NULL;
+ ATOMIC_PTR_INIT(&ni->data, NULL);
if (isTable(i->t)) {
if (isTempTable(i->t)) {
- if ((res = store->storage_api.create_idx(tr, ni)))
+ if ((res = store->storage_api.create_idx(tr, ni))) {
+ ATOMIC_PTR_DESTROY(&ni->data);
return res;
+ }
} else {
ATOMIC_PTR_SET(&ni->data,
store->storage_api.idx_dup(i));
}
@@ -2932,6 +2951,7 @@ idx_dup(sql_trans *tr, sql_idx * i, sql_
list_append(ni->columns, kc_dup(tr, okc, t));
}
if (isGlobal(t) && (res = os_add(t->s->idxs, tr, ni->base.name,
dup_base(&ni->base)))) {
+ ATOMIC_PTR_DESTROY(&ni->data);
return res;
}
*ires = ni;
@@ -3039,6 +3059,7 @@ table_dup(sql_trans *tr, sql_table *ot,
t->pkey = NULL;
t->s = s;
t->sz = ot->sz;
+ ATOMIC_PTR_INIT(&t->data, NULL);
if (isGlobal(t) && (res = os_add(t->s->tables, tr, t->base.name,
&t->base)))
goto cleanup;
@@ -3103,6 +3124,7 @@ table_dup(sql_trans *tr, sql_table *ot,
cleanup:
if (res) {
+ ATOMIC_PTR_DESTROY(&t->data);
t = NULL;
}
*tres = t;
@@ -3216,6 +3238,7 @@ sql_trans_copy_idx( sql_trans *tr, sql_t
ni->t = t;
ni->type = i->type;
ni->key = NULL;
+ ATOMIC_PTR_INIT(&ni->data, NULL);
if (i->type == hash_idx && list_length(i->columns) == 1)
unique = 1;
@@ -3243,11 +3266,15 @@ sql_trans_copy_idx( sql_trans *tr, sql_t
if (isDeclaredTable(i->t))
if (!isDeclaredTable(t) && isTable(ni->t) &&
idx_has_column(ni->type))
- if ((res = store->storage_api.create_idx(tr, ni)))
+ if ((res = store->storage_api.create_idx(tr, ni))) {
+ ATOMIC_PTR_DESTROY(&ni->data);
return res;
+ }
if (!isDeclaredTable(t))
- if ((res = store->table_api.table_insert(tr, sysidx,
&ni->base.id, &t->base.id, &ni->type, &ni->base.name)))
+ if ((res = store->table_api.table_insert(tr, sysidx,
&ni->base.id, &t->base.id, &ni->type, &ni->base.name))) {
+ ATOMIC_PTR_DESTROY(&ni->data);
return res;
+ }
if (ires)
*ires = ni;
@@ -3341,10 +3368,13 @@ sql_trans_copy_column( sql_trans *tr, sq
if ((res = ol_add(t->columns, &col->base)))
return res;
+ ATOMIC_PTR_INIT(&col->data, NULL);
if (isDeclaredTable(c->t))
if (isTable(t))
- if ((res = store->storage_api.create_col(tr, col)))
+ if ((res = store->storage_api.create_col(tr, col))) {
+ ATOMIC_PTR_DESTROY(&col->data);
return res;
+ }
if (!isDeclaredTable(t)) {
char *strnil = (char*)ATOMnilptr(TYPE_str);
@@ -3352,11 +3382,14 @@ sql_trans_copy_column( sql_trans *tr, sq
&col->type.digits, &col->type.scale,
&t->base.id,
(col->def) ? &col->def : &strnil,
&col->null, &col->colnr,
(col->storage_type) ?
&col->storage_type : &strnil))) {
+ ATOMIC_PTR_DESTROY(&col->data);
return res;
}
if (c->type.type->s) /* column depends on type */
- if ((res = sql_trans_create_dependency(tr,
c->type.type->base.id, col->base.id, TYPE_DEPENDENCY)))
+ if ((res = sql_trans_create_dependency(tr,
c->type.type->base.id, col->base.id, TYPE_DEPENDENCY))) {
+ ATOMIC_PTR_DESTROY(&col->data);
return res;
+ }
}
if (cres)
*cres = col;
@@ -5374,8 +5407,10 @@ sql_trans_create_table(sql_trans *tr, sq
t->persistence = SQL_REMOTE;
if (isTable(t))
- if (store->storage_api.create_del(tr, t) != LOG_OK)
+ if (store->storage_api.create_del(tr, t) != LOG_OK) {
+ ATOMIC_PTR_DESTROY(&t->data);
return NULL;
+ }
if (isPartitionedByExpressionTable(t)) {
t->part.pexp = SA_ZNEW(tr->sa, sql_expression);
t->part.pexp->type = *sql_bind_localtype("void"); /* leave it
non-initialized, at the backend the copy of this table will get the type */
@@ -5386,8 +5421,10 @@ sql_trans_create_table(sql_trans *tr, sq
if (!isDeclaredTable(t)) {
char *strnil = (char*)ATOMnilptr(TYPE_str);
if (store->table_api.table_insert(tr, systable, &t->base.id,
&t->base.name, &s->base.id,
- (t->query) ?
&t->query : &strnil, &t->type, &t->system, &ca, &t->access))
+
(t->query) ? &t->query : &strnil, &t->type, &t->system, &ca, &t->access)) {
+ ATOMIC_PTR_DESTROY(&t->data);
return NULL;
+ }
}
return t;
}
@@ -5538,6 +5575,7 @@ create_sql_column_with_id(sql_allocator
if (ol_add(t->columns, &col->base))
return NULL;
+ ATOMIC_PTR_INIT(&col->data, NULL);
return col;
}
@@ -5633,19 +5671,25 @@ sql_trans_create_column(sql_trans *tr, s
col = create_sql_column_with_id(tr->sa, next_oid(tr->store), t, name,
tpe);
if (isTable(col->t))
- if (store->storage_api.create_col(tr, col) != LOG_OK)
+ if (store->storage_api.create_col(tr, col) != LOG_OK) {
+ ATOMIC_PTR_DESTROY(&col->data);
return NULL;
+ }
if (!isDeclaredTable(t)) {
char *strnil = (char*)ATOMnilptr(TYPE_str);
if (store->table_api.table_insert(tr, syscolumn, &col->base.id,
&col->base.name, &col->type.type->base.name, &col->type.digits,
&col->type.scale,
- &t->base.id, (col->def) ? &col->def : &strnil,
&col->null, &col->colnr, (col->storage_type) ? &col->storage_type : &strnil))
+
&t->base.id, (col->def) ? &col->def : &strnil, &col->null, &col->colnr,
(col->storage_type) ? &col->storage_type : &strnil)) {
+ ATOMIC_PTR_DESTROY(&col->data);
return NULL;
+ }
}
if (tpe->type->s) {/* column depends on type */
sql_trans_create_dependency(tr, tpe->type->base.id,
col->base.id, TYPE_DEPENDENCY);
- if (!isNew(tpe->type) && (res = sql_trans_add_dependency(tr,
tpe->type->base.id, ddl)))
+ if (!isNew(tpe->type) && (res = sql_trans_add_dependency(tr,
tpe->type->base.id, ddl))) {
+ ATOMIC_PTR_DESTROY(&col->data);
return NULL;
+ }
}
return col;
}
@@ -6325,11 +6369,14 @@ sql_trans_create_idx(sql_trans *tr, sql_
if (os_add(t->s->idxs, tr, ni->base.name, dup_base(&ni->base)))
return NULL;
+ ATOMIC_PTR_INIT(&ni->data, NULL);
if (!isDeclaredTable(t) && isTable(ni->t) && idx_has_column(ni->type))
store->storage_api.create_idx(tr, ni);
if (!isDeclaredTable(t))
- if (store->table_api.table_insert(tr, sysidx, &ni->base.id,
&t->base.id, &ni->type, &ni->base.name))
+ if (store->table_api.table_insert(tr, sysidx, &ni->base.id,
&t->base.id, &ni->type, &ni->base.name)) {
+ ATOMIC_PTR_DESTROY(&ni->data);
return NULL;
+ }
return ni;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list