syncindex.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "stdinc.h"
  2. #include "dat.h"
  3. #include "fns.h"
  4. static int verbose;
  5. void
  6. usage(void)
  7. {
  8. fprint(2, "usage: syncindex [-v] [-B blockcachesize] config\n");
  9. threadexitsall("usage");
  10. }
  11. Config conf;
  12. void
  13. threadmain(int argc, char *argv[])
  14. {
  15. u32int bcmem, icmem;
  16. bcmem = 0;
  17. icmem = 0;
  18. ARGBEGIN{
  19. case 'B':
  20. bcmem = unittoull(EARGF(usage()));
  21. break;
  22. case 'I':
  23. icmem = unittoull(EARGF(usage()));
  24. break;
  25. case 'v':
  26. verbose++;
  27. break;
  28. default:
  29. usage();
  30. break;
  31. }ARGEND
  32. if(argc != 1)
  33. usage();
  34. ventifmtinstall();
  35. if(initventi(argv[0], &conf) < 0)
  36. sysfatal("can't init venti: %r");
  37. if(mainindex->bloom && loadbloom(mainindex->bloom) < 0)
  38. sysfatal("can't load bloom filter: %r");
  39. if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
  40. bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
  41. if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
  42. initdcache(bcmem);
  43. initlumpcache(1*1024*1024, 1024/8);
  44. initicache(icmem);
  45. initicachewrite();
  46. if(mainindex->bloom)
  47. startbloomproc(mainindex->bloom);
  48. if(verbose)
  49. printindex(2, mainindex);
  50. if(syncindex(mainindex) < 0)
  51. sysfatal("failed to sync index=%s: %r", mainindex->name);
  52. flushicache();
  53. flushdcache();
  54. threadexitsall(0);
  55. }