Changeset: a6d22a026ea5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a6d22a026ea5
Modified Files:
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_utils.c
        sql/storage/bat/bat_utils.h
Branch: properties
Log Message:

Fix data race


diffs (77 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
@@ -2826,27 +2826,36 @@ col_stats(sql_trans *tr, sql_column *c, 
                        return ok;
                }
                bat bid = d->cs.st == ST_DICT ? d->cs.ebid : d->cs.bid;
-               if ((b = quick_descriptor(bid))) {
-                       *nonil = b->tnonil && !b->tnil;
+               if ((b = temp_descriptor(bid))) {
                        int eclass = c->type.type->eclass;
+                       BATiter bi = bat_iterator(b);
+                       *nonil = bi.nonil && !bi.nil;
 
                        if ((EC_NUMBER(eclass) || EC_VARCHAR(eclass) || 
EC_TEMP_NOFRAC(eclass) || eclass == EC_DATE) &&
-                               d->cs.ucnt == 0 && (b->tminpos != BUN_NONE || 
b->tmaxpos != BUN_NONE) && (b = temp_descriptor(bid))) {
-                               BATiter bi = bat_iterator(b);
+                               d->cs.ucnt == 0 && (bi.minpos != BUN_NONE || 
bi.maxpos != BUN_NONE)) {
                                if (bi.minpos != BUN_NONE && VALinit(min, 
bi.type, BUNtail(bi, bi.minpos)))
                                        ok |= 1;
                                if (bi.maxpos != BUN_NONE && VALinit(max, 
bi.type, BUNtail(bi, bi.maxpos)))
                                        ok |= 2;
-                               bat_iterator_end(&bi);
-                               bat_destroy(b);
                        }
+                       bat_iterator_end(&bi);
+                       bat_destroy(b);
                        /* for dict, check the offsets bat for uniqueness */
                        if (d->cs.ucnt == 0 && (d->cs.st == ST_DEFAULT || (b = 
quick_descriptor(d->cs.bid)))) {
+                               MT_lock_set(&b->theaplock);
                                *unique = b->tkey;
                                *unique_est = b->tunique_est;
+                               MT_lock_unset(&b->theaplock);
                        }
-                       if (*nonil && d->cs.ucnt > 0)
-                               *nonil &= ((b = quick_descriptor(d->cs.uvbid)) 
!= NULL) && b->tnonil && !b->tnil;
+                       if (*nonil && d->cs.ucnt > 0) {
+                               if (!(b = quick_descriptor(d->cs.uvbid))) {
+                                       *nonil = false;
+                               } else {
+                                       MT_lock_set(&b->theaplock);
+                                       *nonil &= b->tnonil && !b->tnil;
+                                       MT_lock_unset(&b->theaplock);
+                               }
+                       }
                }
        }
        return ok;
diff --git a/sql/storage/bat/bat_utils.c b/sql/storage/bat/bat_utils.c
--- a/sql/storage/bat/bat_utils.c
+++ b/sql/storage/bat/bat_utils.c
@@ -9,6 +9,14 @@
 #include "monetdb_config.h"
 #include "bat_utils.h"
 
+int
+bat_fix(BAT *b)
+{
+       if (b)
+               return BBPfix(b->batCacheid);
+       return 0;
+}
+
 void
 bat_destroy(BAT *b)
 {
diff --git a/sql/storage/bat/bat_utils.h b/sql/storage/bat/bat_utils.h
--- a/sql/storage/bat/bat_utils.h
+++ b/sql/storage/bat/bat_utils.h
@@ -24,6 +24,7 @@ extern log_bid temp_dup(log_bid b);
 extern log_bid temp_create(BAT *b);
 extern log_bid temp_copy(log_bid b, bool renew, bool temp);
 
+extern int bat_fix(BAT *b);
 extern void bat_destroy(BAT *b);
 extern BAT *bat_new(int tt, BUN size, role_t role);
 extern void bat_clear(BAT *b);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to