📄 gdk_storage.c
字号:
BAT *b = DESCload(bid); int ret = 0; int vv = 1; if (b == NULL) { return NULL; } /* LOAD bun heap */ if (b->htype != TYPE_void || b->ttype != TYPE_void) { vv = 0; ret = HEAPload(b->batBuns, nme, "buns", b->batRestricted == BAT_READ); if (ret < 0) { return NULL; } } else { b->batBuns->base = (char *) 1; } /* LOAD head heap */ if (ATOMvarsized(b->htype) && ret >= 0) { ret |= HEAPload(b->hheap, nme, "hheap", b->batRestricted == BAT_READ); if (ret < 0) { HEAPfree(b->batBuns); return NULL; } if (BATatoms[b->htype].atomHeapCheck == HEAP_check) { HEAP_init(b->hheap, b->htype); } else if (ATOMstorage(b->htype) == TYPE_str) { strCleanHash(b->hheap, (b->GDKversion != GDKLIBRARY)); /* ensure consistency */ } } /* LOAD tail heap */ if (ATOMvarsized(b->ttype) && ret >= 0) { ret |= HEAPload(b->theap, nme, "theap", b->batRestricted == BAT_READ); if (ret < 0) { if (b->hheap) HEAPfree(b->hheap); HEAPfree(b->batBuns); return NULL; } if (BATatoms[b->ttype].atomHeapCheck == HEAP_check) { HEAP_init(b->theap, b->ttype); } else if (ATOMstorage(b->ttype) == TYPE_str) { strCleanHash(b->theap, (b->GDKversion != GDKLIBRARY)); /* ensure consistency */ } } /* handle fatal errors */ if (ret < 0) { if (!vv) HEAPfree(b->batBuns); if (b->hheap) HEAPfree(b->hheap); if (b->theap) HEAPfree(b->theap); return NULL; } if (b->GDKversion != GDKLIBRARY) { b->GDKversion = GDKLIBRARY; b->batDirtydesc = 1; } /* initialize descriptor */ b->batMapdirty = ret; /* heap mode changed during load? */ b->batDirtydesc = FALSE; b->batParentid = 0; b->batSharecnt = 0; DELTAload(b); /* load succeeded; register it in BBP */ BBPcacheit(b); if (!DELTAdirty(b)) { ALIGNcommit(b); } b->batDirtydesc |= b->batMapdirty; /* if some heap mode changed, make desc dirty */ b->batMapbuns = b->batBuns->storage; if (b->hheap) b->batMaphheap = b->hheap->storage; if (b->theap) b->batMaptheap = b->theap->storage; if ((b->batRestricted == BAT_WRITE && (GDKdebug & 2)) || (GDKdebug & 8)) { ++b->batSharecnt; BATpropcheck(b, BATPROPS_CHECK); --b->batSharecnt; } return (i < 0) ? BATmirror(b) : b;}BAT *BATload(str nme){ str s = strrchr(nme, DIR_SEP); bat i = BBPindex(s ? s + 1 : nme); BAT *b = BBP_cache(i); if (i == 0 || b != NULL) { return b; /* inexistent bat or already loaded */ } return BATload_intern(i);}#line 675 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"#line 689 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"intBATdelete(BAT *b){ bat bid = ABS(b->batCacheid); str o = BBP_physical(bid); BAT *loaded = BBP_cache(bid); int vv = (!b->htype && !b->ttype); if (loaded) { b = loaded; HASHdestroy(b); GDKfree(BATmirror(b)); BBP_cache(-b->batCacheid) = NULL; } if (b->batCopiedtodisk) { IODEBUG THRprintf(GDKout, "#BATdelete %s\n", o); if (GDKunlink(BATDIR, o, "desc")) { GDKwarning("BATdelete(%s): descriptor\n", BATgetId(b)); } } if (b->batCopiedtodisk || (b->batBuns->storage & STORE_MMAP)) { if ((b->htype != TYPE_void || b->ttype != TYPE_void) && HEAPdelete(b->batBuns, o, "buns") && b->batCopiedtodisk) GDKwarning("BATdelete(%s): bun heap\n", BATgetId(b)); } else if (b->batBuns->base && !vv) { HEAPfree(b->batBuns); } if (b->hheap) { if (b->batCopiedtodisk || (b->hheap->storage & STORE_MMAP)) { if (HEAPdelete(b->hheap, o, "hheap") && b->batCopiedtodisk) GDKwarning("BATdelete(%s): head heap\n", BATgetId(b)); } else { HEAPfree(b->hheap); } } if (b->theap) { if (b->batCopiedtodisk || (b->theap->storage & STORE_MMAP)) { if (HEAPdelete(b->theap, o, "theap") && b->batCopiedtodisk) GDKwarning("BATdelete(%s): tail heap\n", BATgetId(b)); } else { HEAPfree(b->theap); } } b->batCopiedtodisk = FALSE; return 0;}#line 792 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"#define LINE(s, X) do { \ int n=X-1; \ if (stream_write(s, "#", 1, 1) != 1) \ break; \ while(n-->0) \ if (stream_write(s, "-", 1, 1) != 1) \ break; \ if (!stream_errnr(s)) \ stream_write(s, "#\n", 2, 1); \ } while (0)#define TABS(s, X) do { \ int n=X; \ while (n-->0) \ if (stream_write(s, "\t", 1, 1) != 1) \ break; \ } while (0)typedef int (*strFcn) (str *s, int *len, ptr val);typedef struct { int tabs; /* tab width of output */ strFcn format; /* tostr function */ /* dynamic fields, set by print_format */ str buf; /* tail value as string */ str tpe; /* type of this column as string */ int size; /* size of buf */ int len; /* strlen(buf) */} col_format_t;static intprint_nil(char **dst, int *len, ptr dummy){ (void) dummy; if (*len < 3) { if (*dst) GDKfree(*dst); *dst = (char *) GDKmalloc(*len = 40); } strcpy(*dst, "nil"); return 3;}#define printfcn(b) ((b->ttype==TYPE_void && b->tseqbase==oid_nil)?\ print_nil:BATatoms[b->ttype].atomToStr)static intprint_tabwidth(BAT *b, str title, col_format_t *c){ strFcn tostr = printfcn(b); size_t cnt = BATcount(b); int max, t = BATttype(b); c->tpe = ATOMname(b->ttype); c->buf = (char *) GDKmalloc(c->size = strLen(title)); max = (int) MAX((2 + strlen(c->tpe)), strlen(title)); if (t >= 0 && t < GDKatomcnt && tostr) { size_t off = BUNindex(b, BUNfirst(b)); int k; size_t j, i, probe = MIN(cnt, MAX(200, MIN(1024, cnt / 100))); for (i = 0; i < probe; i++) { j = off + ((probe == cnt) ? i : (rand() % MIN(16384, cnt))); k = (*tostr) (&c->buf, &c->size, BUNtail(b, BUNptr(b, j))); if (k > max) max = k; } } strcpy(c->buf, title); max += 2; /* account for ", " separator */ /* if (max > 60) max = 60; */ return 1 + (max - 1) / 8;}static voidprint_line(stream *s, col_format_t **l){ col_format_t *c = *(l++); if (stream_write(s, "[ ", 2, 1) != 1) return; if (c->format) { if (stream_write(s, c->buf, c->len, 1) != 1) return; if (stream_write(s, ",", 1, 1) != 1) return; TABS(s, c->tabs - ((c->len + 3) / 8)); if (stream_errnr(s)) return; if (c->tabs * 8 >= c->len + 3 && stream_write(s, " ", 1, 1) != 1) return; if (stream_write(s, " ", 1, 1) != 1) return; } for (c = *l; *(++l); c = *l) { if (!c->format) continue; if (stream_write(s, c->buf, c->len, 1) != 1) return; if (stream_write(s, ",", 1, 1) != 1) return; TABS(s, c->tabs - ((c->len + 3) / 8)); if (stream_errnr(s)) return; if (c->tabs * 8 >= c->len + 3 && stream_write(s, " ", 1, 1) != 1) return; if (stream_write(s, " ", 1, 1) != 1) return; } if (stream_write(s, c->buf, c->len, 1) != 1) return; TABS(s, c->tabs - ((c->len + 2) / 8)); if (stream_errnr(s)) return; stream_printf(s, " ]\n");}static voidprint_format(col_format_t *c, ptr v){ if (c->format) c->len = (*c->format) (&c->buf, &c->size, v);}#line 945 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"static intprint_header(int argc, col_format_t *argv, stream *s){ int k; #line 926 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" k = 1; if (stream_write(s, "# ", 2, 1) != 1) return -1; if (argv[0].format) { #line 917 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" str buf = 0?argv[0].tpe:argv[0].buf; /* contains column title */ int len = (int) strlen(buf); if (stream_write(s, buf, len, 1) != 1) return -1; TABS(s, argv[0].tabs-((0+len-1)/8)); if (stream_errnr(s)) return -1;#line 930 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" } for (;;) { #line 917 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" str buf = 0?argv[k].tpe:argv[k].buf; /* contains column title */ int len = (int) strlen(buf); if (stream_write(s, buf, len, 1) != 1) return -1; TABS(s, argv[k].tabs-((0+len-1)/8)); if (stream_errnr(s)) return -1;#line 933 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" if (k++ >= argc) break; } if(0) { if (stream_printf(s, " # type\n") < 0) return -1; } else { if (stream_printf(s, " # name\n") < 0) return -1; }#line 950 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" #line 926 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" k = 1; if (stream_write(s, "# ", 2, 1) != 1) return -1; if (argv[0].format) { #line 917 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" str buf = 2?argv[0].tpe:argv[0].buf; /* contains column title */ int len = (int) strlen(buf); if (stream_write(s, buf, len, 1) != 1) return -1; TABS(s, argv[0].tabs-((2+len-1)/8)); if (stream_errnr(s)) return -1;#line 930 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" } for (;;) { #line 917 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" str buf = 2?argv[k].tpe:argv[k].buf; /* contains column title */ int len = (int) strlen(buf); if (stream_write(s, buf, len, 1) != 1) return -1; TABS(s, argv[k].tabs-((2+len-1)/8)); if (stream_errnr(s)) return -1;#line 933 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" if (k++ >= argc) break; } if(2) { if (stream_printf(s, " # type\n") < 0) return -1; } else { if (stream_printf(s, " # name\n") < 0) return -1; }#line 951 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" return 0;}#line 958 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"intBATprint(BAT *b){ ERRORcheck(b == NULL, "BATprint: BAT expected"); return BATmultiprintf(GDKstdout, 2, &b, TRUE, 0, 1);}intBATprintf(stream *s, BAT *b){ ERRORcheck(b == NULL, "BATprintf: BAT expected"); return BATmultiprintf(s, 2, &b, TRUE, 0, 1);}#line 978 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"intBATmultiprintf(stream *s, /* output stream */ int argc, /* #ncolumns = #nbats + */ BAT *argv[], /* the bats 2b printed */ int printhead, /* boolean: print the head column? */ int order, /* respect order of bat X (X=0 is none) */ int printorder /* boolean: print the orderby column? */ ){ col_format_t *c = (col_format_t *) alloca((unsigned) (argc * sizeof(col_format_t))); col_format_t **cp = (col_format_t **) alloca((unsigned) ((argc + 1) * sizeof(void *))); ColFcn *value_fcn = (ColFcn *) alloca((unsigned) (argc * sizeof(ColFcn))); int ret = 0, j, total = 0;#line 996 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" cp[argc] = NULL; /* terminator */ cp[0] = c; memset(c, 0, (argc--) * sizeof(col_format_t));#line 1002 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" value_fcn[0] = (ColFcn) print_format; if (printhead) { BAT *b = BATmirror(argv[0]); total = c[0].tabs = print_tabwidth(b, b->tident, c + 0); c[0].format = printfcn(b); } for (j = 0; j < argc; j++, total += c[j].tabs) { cp[j + 1] = c + (j + 1); if (!printorder && order==j+1) c[j + 1].format = NULL; else c[j + 1].format = printfcn(argv[j]); c[j + 1].tabs = print_tabwidth(argv[j], argv[j]->tident, c + (j + 1)); value_fcn[j + 1] = (ColFcn) print_format; } total = 2 + (total * 8);#line 1022 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" ret = -1; LINE(s, total); if (stream_errnr(s)) goto cleanup; if (print_header(argc, c, s) < 0) goto cleanup; LINE(s, total); if (stream_errnr(s)) goto cleanup; else if (argc == 1) { BAT *b = argv[0]; BUN p, q; BATloop(b, p, q) { print_format(cp[0], BUNhead(b, p)); print_format(cp[1], BUNtail(b, p)); print_line(s, cp); if (stream_errnr(s)) goto cleanup; } MULTIJOIN_LEAD(ret) = 1; MULTIJOIN_SORTED(ret) = (BAThordered(b) & 1); MULTIJOIN_KEY(ret) = b->hkey; MULTIJOIN_SYNCED(ret) = 1; } else { ret = BATmultijoin(argc, argv, (RowFcn) print_line, (void *) s, value_fcn, (void **) cp, order); }#line 1052 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx" cleanup: for (j = 0; j <= argc; j++) { if (c[j].buf) GDKfree(c[j].buf); } return ret;}#line 1061 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_storage.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -