Changeset: 6a85126b4323 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6a85126b4323
Modified Files:
gdk/gdk_orderidx.c
monetdb5/modules/mal/tablet.c
Branch: default
Log Message:
Fix some data races.
diffs (123 lines):
diff --git a/gdk/gdk_orderidx.c b/gdk/gdk_orderidx.c
--- a/gdk/gdk_orderidx.c
+++ b/gdk/gdk_orderidx.c
@@ -76,57 +76,54 @@ BATcheckorderidx(BAT *b)
if (b == NULL)
return false;
- /* we don't need the lock just to read the value b->torderidx */
+ MT_lock_set(&b->batIdxLock);
if (b->torderidx == (Heap *) 1) {
- /* but when we want to change it, we need the lock */
- assert(!GDKinmemory(b->theap->farmid));
- MT_lock_set(&b->batIdxLock);
- if (b->torderidx == (Heap *) 1) {
- Heap *hp;
- const char *nme = BBP_physical(b->batCacheid);
- int fd;
+ Heap *hp;
+ const char *nme = BBP_physical(b->batCacheid);
+ int fd;
- b->torderidx = NULL;
- if ((hp = GDKzalloc(sizeof(*hp))) != NULL &&
- (hp->farmid = BBPselectfarm(b->batRole, b->ttype,
orderidxheap)) >= 0) {
- strconcat_len(hp->filename,
- sizeof(hp->filename),
- nme, ".torderidx", NULL);
- hp->storage = hp->newstorage = STORE_INVALID;
+ assert(!GDKinmemory(b->theap->farmid));
+ b->torderidx = NULL;
+ if ((hp = GDKzalloc(sizeof(*hp))) != NULL &&
+ (hp->farmid = BBPselectfarm(b->batRole, b->ttype,
orderidxheap)) >= 0) {
+ strconcat_len(hp->filename,
+ sizeof(hp->filename),
+ nme, ".torderidx", NULL);
+ hp->storage = hp->newstorage = STORE_INVALID;
- /* check whether a persisted orderidx can be
found */
- if ((fd = GDKfdlocate(hp->farmid, nme, "rb+",
"torderidx")) >= 0) {
- struct stat st;
- oid hdata[ORDERIDXOFF];
+ /* check whether a persisted orderidx can be found */
+ if ((fd = GDKfdlocate(hp->farmid, nme, "rb+",
"torderidx")) >= 0) {
+ struct stat st;
+ oid hdata[ORDERIDXOFF];
- if (read(fd, hdata, sizeof(hdata)) ==
sizeof(hdata) &&
- hdata[0] == (
+ if (read(fd, hdata, sizeof(hdata)) ==
sizeof(hdata) &&
+ hdata[0] == (
#ifdef PERSISTENTIDX
- ((oid) 1 << 24) |
+ ((oid) 1 << 24) |
#endif
- ORDERIDX_VERSION) &&
- hdata[1] == (oid) BATcount(b) &&
- (hdata[2] == 0 || hdata[2] == 1) &&
- fstat(fd, &st) == 0 &&
- st.st_size >= (off_t) (hp->size =
hp->free = (ORDERIDXOFF + hdata[1]) * SIZEOF_OID) &&
- HEAPload(hp, nme, "torderidx",
false) == GDK_SUCCEED) {
- close(fd);
- ATOMIC_INIT(&hp->refs, 1);
- b->torderidx = hp;
- TRC_DEBUG(ACCELERATOR,
"BATcheckorderidx(" ALGOBATFMT "): reusing persisted orderidx\n",
ALGOBATPAR(b));
- MT_lock_unset(&b->batIdxLock);
- return true;
- }
+ ORDERIDX_VERSION) &&
+ hdata[1] == (oid) BATcount(b) &&
+ (hdata[2] == 0 || hdata[2] == 1) &&
+ fstat(fd, &st) == 0 &&
+ st.st_size >= (off_t) (hp->size = hp->free
= (ORDERIDXOFF + hdata[1]) * SIZEOF_OID) &&
+ HEAPload(hp, nme, "torderidx", false) ==
GDK_SUCCEED) {
close(fd);
- /* unlink unusable file */
- GDKunlink(hp->farmid, BATDIR, nme,
"torderidx");
+ ATOMIC_INIT(&hp->refs, 1);
+ b->torderidx = hp;
+ TRC_DEBUG(ACCELERATOR,
"BATcheckorderidx(" ALGOBATFMT "): reusing persisted orderidx\n",
ALGOBATPAR(b));
+ MT_lock_unset(&b->batIdxLock);
+ return true;
}
+ close(fd);
+ /* unlink unusable file */
+ GDKunlink(hp->farmid, BATDIR, nme, "torderidx");
}
- GDKfree(hp);
- GDKclrerr(); /* we're not currently interested in
errors */
}
- MT_lock_unset(&b->batIdxLock);
+ GDKfree(hp);
+ GDKclrerr(); /* we're not currently interested in errors */
}
+ MT_lock_unset(&b->batIdxLock);
+
ret = b->torderidx != NULL;
if (ret)
TRC_DEBUG(ACCELERATOR, "BATcheckorderidx(" ALGOBATFMT "):
already has orderidx, waited " LLFMT " usec\n", ALGOBATPAR(b), GDKusec() - t);
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -1839,10 +1839,13 @@ SQLload_file(Client cntxt, Tablet *as, b
/* producer should stop */
task.maxrow = cnt;
task.state = ENDOFCOPY;
+ task.ateof = true;
}
if (task.ateof && task.top[task.cur] < task.limit && cnt !=
task.maxrow)
break;
task.top[task.cur] = 0;
+ if (cnt == task.maxrow)
+ task.ateof = true;
MT_sema_up(&task.producer);
}
@@ -1850,7 +1853,6 @@ SQLload_file(Client cntxt, Tablet *as, b
cnt = BATcount(task.as->format[firstcol].c);
- task.ateof = true;
task.state = ENDOFCOPY;
/* TRC_DEBUG(MAL_SERVER, "Activate sync on disk\n");*/
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]