12 #include <PT_server_prototypes.h>
42 bool atRoot = (at == root);
47 if (atRoot) new_root = at;
63 if (loc[height-1] ==
PT_QU) {
82 while (loc[height] == loc_ref[height]) {
103 if (loc[height-1] ==
PT_QU) {
113 pt_assert(loc[height] != loc_ref[height]);
139 uint32_t c = *((uint32_t*)(seq+pos));
140 if (c == 0x2E2E2E2E) {
145 if (c == 0x2D2D2D2D) {
154 unsigned char c = seq[pos];
229 fprintf(stderr,
"%s was not completely saved:\n", whatTree);
251 #if defined(PTM_TRACE_MAX_MEM_USAGE)
252 static void dump_memusage() {
254 printf(
"\n------------------------------ dump_memusage:\n");
fflush(stdout);
258 pid_t pid = getpid();
262 printf(
"Warning: %s\n", error);
265 printf(
"------------------------------ dump_memusage [end]\n");
275 const char *passname()
const {
277 case 0:
return "pass";
278 case 1:
return "Level-I-passes";
279 case 2:
return "Level-II-passes";
280 case 3:
return "Level-III-passes";
281 case 4:
return "Level-IV-passes";
289 PartitionSpec(
int passes_,
size_t memuse_,
int depth_) : passes(passes_), memuse(memuse_), depth(depth_) {}
293 if (!passes)
return false;
294 if (!other.passes)
return true;
302 cmp = other.memuse-memuse;
304 cmp = other.passes-passes;
306 cmp = other.depth-depth;
311 cmp = other.passes-passes;
313 cmp = other.depth-depth;
315 cmp = other.memuse-memuse;
325 "Estimated memory usage for %i %s: %s%s\n",
329 memuse>max_kb_usable ?
" (would swap)" :
"");
348 if (maxPasses >= forced_passes) {
352 #if defined(PTM_TRACE_PARTITION_DETECTION)
359 for (
int passes = 1; passes <= maxPasses; ++passes) {
363 #if defined(PTM_TRACE_PARTITION_DETECTION)
380 " You try to build a ptserver from a very big database!\n"
382 " The memory installed on your machine would require to build the ptserver\n"
383 " in more than %i passes (the maximum allowed number of passes).\n"
385 " As a result the build of this server may cause your machine to swap huge\n"
386 " amounts of memory and will possibly run for days, weeks or even months.\n"
387 "\n", allowed_passes);
407 char *t2name = ARB_calloc<char>(strlen(tname) + 2);
408 sprintf(t2name,
"%s%%", tname);
410 FILE *out = fopen(t2name,
"w");
420 GB_warningf(
"%s\nOther users might get problems when they try to access this file.", sm_error);
440 printf(
"Memory available for build: %s\n",
GBS_readable_size(available_memory*1024,
"b"));
442 int forcedPasses = 0;
444 const char *forced =
GB_getenv(
"ARB_PTS_FORCE_PASSES");
446 int f = atoi(forced);
449 printf(
"Warning: Forcing %i passes (by envvar ARB_PTS_FORCE_PASSES='%s')\n", forcedPasses, forced);
474 const char *
seq = &*seqPtr;
478 for (
int rel = pid.
get_size() - 1; rel >= 0; rel--) {
487 #if defined(PTM_TRACE_MAX_MEM_USAGE)
494 #ifdef PTM_DEBUG_NODES
498 while (partition.
next());
506 bool need64bit =
false;
510 if (last_obj >= 0xffffffff) need64bit =
true;
525 long info_size = pos-info_pos;
561 if (error) pass_progress.
done();
569 char *starpos = strstr(related,
".arb.pt");
572 strcpy(starpos,
".*");
581 if (lserror) fprintf(stderr,
"Warning: %s\n", lserror);
603 printf(
"- mapping ptindex ('%s', %s) from disk\n", tname,
GBS_readable_size(size,
"b"));
604 FILE *in = fopen(tname,
"r");
626 void TEST_PrefixProbabilities() {
631 const double EPS = 0.00001;
684 : len(strlen(readable)),
689 const char *
seq()
const {
return compressed.
get_seq(); }
692 void TEST_MarkedPrefixes() {
734 #define VAL_64_32_BITDEP(val64,val32) (val64)
735 #else // !defined(ARB_64)
736 #define VAL_64_32_BITDEP(val64,val32) (val32)
746 const int BASES_100k = 100000;
765 TEST_EXPECT_EQUAL(P16.estimate_max_kb_for_any_pass(BASES_100k), VAL_64_32_BITDEP(440583, 205015));
805 TEST_EXPECT_EQUAL(P13.estimate_max_kb_for_any_pass(BASES_100k), VAL_64_32_BITDEP(440687, 205101));
835 TEST_EXPECT_EQUAL(P12.estimate_max_kb_for_any_pass(BASES_100k), VAL_64_32_BITDEP(440679, 205095));
899 static arb_test::match_expectation decides_on_passes(
ULONG bp,
size_t avail_mem_kb,
int expected_passes,
int expected_depth,
size_t expected_passsize,
size_t expected_memuse,
bool expect_to_swap) {
900 size_t ARM_size_kb = bp/1800;
909 bool decided_to_swap = decided_memuse>avail_mem_kb;
918 return all().ofgroup(expected);
921 #define TEST_DECIDES_PASSES(bp,memkb,expected_passes,expected_depth,expected_passsize,expected_memuse,expect_to_swap) \
922 TEST_EXPECTATION(decides_on_passes(bp, memkb, expected_passes, expected_depth, expected_passsize, expected_memuse, expect_to_swap))
924 #define TEST_DECIDES_PASSES__BROKEN(bp,memkb,expected_passes,expected_depth,expected_passsize,expected_memuse,expect_to_swap) \
925 TEST_EXPECTATION__BROKEN(decides_on_passes(bp, memkb, expected_passes, expected_depth, expected_passsize, expected_memuse, expect_to_swap))
927 void TEST_SLOW_decide_passes_to_use() {
931 const ULONG BP_SILVA_108_REF = 891481251ul;
932 const ULONG BP_SILVA_108_PARC = BP_SILVA_108_REF * (2492653/618442.0);
933 const ULONG BP_SILVA_108_40K = 56223289ul;
934 const ULONG BP_SILVA_108_12K = 17622233ul;
936 const ULONG MINI_PC = 2 *GB;
937 const ULONG SMALL_PC = 4 *GB;
939 const ULONG SMALL_SERVER = 12 *GB;
940 const ULONG MEDIUM_SERVER = 20 *GB;
941 const ULONG BIG_SERVER = 64 *GB;
942 const ULONG HUGE_SERVER = 128 *GB;
964 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MEM1, 1, 0, 3593147643UL, 21318473, 0);
965 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MEM2, 2, 1, 1858375961, 13356142, 0);
966 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MEM3, 4, 2, 985573522, 9350115, 0);
967 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MEM4, 11, 4, 333053234, 6355149, 0);
969 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEM1, 1, 0, 891481251, 5620314, 0);
970 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEM2, 1, 0, 891481251, 5620314, 0);
971 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEM3, 1, 0, 891481251, 5620314, 0);
972 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEM4, 1, 0, 891481251, 5620314, 0);
973 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEM5, 2, 1, 461074103, 3644812, 0);
974 TEST_DECIDES_PASSES(BP_SILVA_108_REF, LMEM1, 4, 3, 230472727, 2586388, 0);
975 TEST_DECIDES_PASSES(BP_SILVA_108_REF, LMEM2, 8, 3, 123505999, 2095427, 0);
976 TEST_DECIDES_PASSES(BP_SILVA_108_REF, LMEM3, 111, 4, 11443798, 1581079, 0);
978 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM1, 1, 0, 56223289, 767008, 0);
979 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM2, 1, 0, 56223289, 767008, 0);
980 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM3, 1, 0, 56223289, 767008, 0);
981 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM4, 1, 0, 56223289, 767008, 0);
982 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM5, 1, 0, 56223289, 767008, 0);
983 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM6, 2, 1, 29078685, 642419, 0);
984 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM7, 194, 4, 502032, 511256, SWAPS);
986 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MINI_PC, 194, 4, 32084148, 4973748, SWAPS);
987 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MINI_PC, 111, 4, 11443798, 1581079, 0);
988 TEST_DECIDES_PASSES(BP_SILVA_108_40K, MINI_PC, 1, 0, 56223289, 767008, 0);
989 TEST_DECIDES_PASSES(BP_SILVA_108_12K, MINI_PC, 1, 0, 17622233, 542715, 0);
991 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, SMALL_PC, 194, 4, 32084148, 4973748, SWAPS);
992 TEST_DECIDES_PASSES(BP_SILVA_108_REF, SMALL_PC, 2, 1, 461074103, 3644812, 0);
993 TEST_DECIDES_PASSES(BP_SILVA_108_40K, SMALL_PC, 1, 0, 56223289, 767008, 0);
994 TEST_DECIDES_PASSES(BP_SILVA_108_12K, SMALL_PC, 1, 0, 17622233, 542715, 0);
996 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, SMALL_SERVER, 3, 3, 1217700425, 10415541, 0);
997 TEST_DECIDES_PASSES(BP_SILVA_108_REF, SMALL_SERVER, 1, 0, 891481251, 5620314, 0);
998 TEST_DECIDES_PASSES(BP_SILVA_108_40K, SMALL_SERVER, 1, 0, 56223289, 767008, 0);
999 TEST_DECIDES_PASSES(BP_SILVA_108_12K, SMALL_SERVER, 1, 0, 17622233, 542715, 0);
1001 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MEDIUM_SERVER, 2, 1, 1858375961, 13356142, 0);
1002 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEDIUM_SERVER, 1, 0, 891481251, 5620314, 0);
1003 TEST_DECIDES_PASSES(BP_SILVA_108_40K, MEDIUM_SERVER, 1, 0, 56223289, 767008, 0);
1004 TEST_DECIDES_PASSES(BP_SILVA_108_12K, MEDIUM_SERVER, 1, 0, 17622233, 542715, 0);
1006 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, BIG_SERVER, 1, 0, 3593147643UL, 21318473, 0);
1007 TEST_DECIDES_PASSES(BP_SILVA_108_REF, BIG_SERVER, 1, 0, 891481251, 5620314, 0);
1008 TEST_DECIDES_PASSES(BP_SILVA_108_40K, BIG_SERVER, 1, 0, 56223289, 767008, 0);
1009 TEST_DECIDES_PASSES(BP_SILVA_108_12K, BIG_SERVER, 1, 0, 17622233, 542715, 0);
1011 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, HUGE_SERVER, 1, 0, 3593147643UL, 21318473, 0);
1012 TEST_DECIDES_PASSES(BP_SILVA_108_REF, HUGE_SERVER, 1, 0, 891481251, 5620314, 0);
1013 TEST_DECIDES_PASSES(BP_SILVA_108_40K, HUGE_SERVER, 1, 0, 56223289, 767008, 0);
1014 TEST_DECIDES_PASSES(BP_SILVA_108_12K, HUGE_SERVER, 1, 0, 17622233, 542715, 0);
1016 #else // !defined(ARB_64) => only test for situations with at most 4Gb
1019 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MEM5, 2, 1, 461074103, 2831431, 0);
1020 TEST_DECIDES_PASSES(BP_SILVA_108_REF, LMEM1, 3, 2, 328766946, 2327527, 0);
1021 TEST_DECIDES_PASSES(BP_SILVA_108_REF, LMEM2, 4, 2, 244526639, 2006690, 0);
1022 TEST_DECIDES_PASSES(BP_SILVA_108_REF, LMEM3, 7, 4, 129515581, 1568659, 0);
1024 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM1, 1, 0, 56223289, 473837, 0);
1025 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM2, 1, 0, 56223289, 473837, 0);
1026 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM3, 1, 0, 56223289, 473837, 0);
1027 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM4, 1, 0, 56223289, 473837, 0);
1028 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM5, 1, 0, 56223289, 473837, 0);
1029 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM6, 1, 0, 56223289, 473837, 0);
1030 TEST_DECIDES_PASSES(BP_SILVA_108_40K, LMEM7, 2, 1, 29078685, 370454, 0);
1032 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, MINI_PC, 194, 4, 32084148, 3835929, SWAPS);
1033 TEST_DECIDES_PASSES(BP_SILVA_108_REF, MINI_PC, 7, 4, 129515581, 1568659, 0);
1034 TEST_DECIDES_PASSES(BP_SILVA_108_40K, MINI_PC, 1, 0, 56223289, 473837, 0);
1035 TEST_DECIDES_PASSES(BP_SILVA_108_12K, MINI_PC, 1, 0, 17622233, 289125, 0);
1037 TEST_DECIDES_PASSES(BP_SILVA_108_PARC, SMALL_PC, 194, 4, 32084148, 3835929, SWAPS);
1038 TEST_DECIDES_PASSES(BP_SILVA_108_REF, SMALL_PC, 2, 1, 461074103, 2831431, 0);
1039 TEST_DECIDES_PASSES(BP_SILVA_108_40K, SMALL_PC, 1, 0, 56223289, 473837, 0);
1040 TEST_DECIDES_PASSES(BP_SILVA_108_12K, SMALL_PC, 1, 0, 17622233, 289125, 0);
1045 void NOTEST_SLOW_maybe_build_tree() {
1048 char dbarg[] =
"-D" "extra_pt_src.arb";
1049 char *testDB = dbarg+2;
1050 const char *resultPT =
"extra_pt_src.arb.pt";
1051 const char *expectedPT =
"extra_pt_src.arb_expected.pt";
1055 char pname[] =
"fake_pt_server";
1056 char barg[] =
"-build";
1068 #if defined(TEST_AUTO_UPDATE)
1069 TEST_COPY_FILE(resultPT, expectedPT);
1070 #else // !defined(TEST_AUTO_UPDATE)
1076 #endif // UNIT_TESTS
struct probe_input_data * data
GB_ERROR GB_begin_transaction(GBDATA *gbd)
long PTD_save_upper_tree(FILE *out, POS_TREE1 *&node, long pos, long &node_pos, ARB_ERROR &error)
GB_ERROR GBK_system(const char *system_command)
void PT_add_to_chain(POS_TREE1 *node, const DataLoc &loc)
#define PT_SERVER_VERSION
GB_ERROR GB_commit_transaction(GBDATA *gbd)
void GB_warning(const char *message)
void PT_dump_POS_TREE_recursive(PT *pt, const char *prefix, FILE *out)
#define TEST_EXPECT_SIMILAR(expr, want, epsilon)
void PTD_put_int(FILE *out, ULONG i)
void PTD_delete_saved_node(POS_TREE1 *&node)
#define PT_MIN_TREE_HEIGHT
Partition partition() const
void set_position(int abs_pos, int rel_pos)
GB_ERROR GB_IO_error(const char *action, const char *filename)
char * ARB_strdup(const char *str)
void PTD_put_longlong(FILE *out, ULONG i)
const char * GBS_global_string(const char *templat,...)
ARB_ERROR PTD_read_leafs_from_disk(const char *fname, POS_TREE2 *&root_ptr)
static Partition decide_passes_to_use(size_t overallBases, size_t max_kb_usable, int forced_passes)
ARB_ERROR enter_stage_1_build_tree(PT_main *, const char *tname, ULONG ARM_size_kb)
int GB_unlink(const char *path)
probe_statistic_struct stat
int number_of_passes() const
long GB_size_of_file(const char *path)
#define ARRAY_ELEMS(array)
bool willUseMoreThan(size_t max_kb_usable) const
#define PT_POS_TREE_HEIGHT
size_t estimate_max_kb_for_any_pass(size_t overall_base_count) const
const char * get_seq() const
bool isBetterThan(const PartitionSpec &other, size_t max_kb_usable) const
void createFrom(const unsigned char *const seq, const size_t length)
void PTD_put_byte(FILE *out, ULONG i)
void enter_stage(Stage stage_)
GB_ERROR GB_await_error()
void GB_warningf(const char *templat,...)
#define PT_MAX_PARTITION_DEPTH
long PTD_write_leafs_to_disk(FILE *out, POS_TREE1 *const node, long pos, long *node_pos, ARB_ERROR &error)
size_t max_probes_for_passes(const PrefixProbabilities &prob, int passes_wanted, size_t overall_base_count)
void GBK_terminate(const char *error) __ATTR__NORETURN
#define pt_assert_stage(s)
PartitionSpec(int passes_, size_t memuse_, int depth_)
size_t estimate_max_probes_for_any_pass(size_t overall_base_count) const
GB_ERROR GB_move_file(const char *oldpath, const char *newpath)
const char * GBS_readable_size(unsigned long long size, const char *unit_suffix)
void PT_init_cache_sizes(Stage stage)
static void error(const char *msg)
GB_ERROR GB_abort_transaction(GBDATA *gbd)
expectation_group & add(const expectation &e)
void check_tree_was_saved(POS_TREE1 *node, const char *whatTree, bool completely, ARB_ERROR &error)
void print_info(FILE *out, size_t max_kb_usable) const
POS_TREE1 * PT_leaf_to_chain(POS_TREE1 *node)
POS_TREE1 * PT_create_leaf(POS_TREE1 **pfather, PT_base base, const DataLoc &loc)
static POS_TREE1 * build_pos_tree(POS_TREE1 *const root, const ReadableDataLoc &loc)
int ARB_main(int argc, char *argv[])
PT * PT_read_son(PT *node, PT_base base)
GB_ERROR GB_set_mode_of_file(const char *path, long mode)
void get_abs_align_pos(char *seq, int &pos)
static long save_lower_subtree(FILE *out, POS_TREE1 *node, long pos, int height, ARB_ERROR &error)
#define __ATTR__REDUCED_OPTIMIZE
GB_CSTR GB_getenv(const char *env)
static bool all_sons_saved(POS_TREE1 *node)
fputs(TRACE_PREFIX, stderr)
GB_ULONG GB_get_usable_memory(void)
str readable(const copy< T > &v)
static long write_subtree(FILE *out, POS_TREE1 *node, long pos, long *node_pos, ARB_ERROR &error)
#define TEST_EXPECT_FILES_EQUAL(f1, f2)
void PTD_debug_nodes(void)
POS_TREE2 *& TREE_ROOT2()
int get_prefix_count() const
bool GB_is_regularfile(const char *path)
bool contains(const char *probe) const
void GBS_add_ptserver_logentry(const char *entry)
static long save_upper_tree(FILE *out, POS_TREE1 *node, long pos, long &node_pos, ARB_ERROR &error)
ARB_ERROR enter_stage_2_load_tree(PT_main *, const char *tname)
size_t max_kb_for_passes(const PrefixProbabilities &prob, int passes_wanted, size_t overall_base_count)
#define TEST_EXPECT_EQUAL(expr, want)
void PTD_put_short(FILE *out, ULONG i)
bool has_unsaved_sons(POS_TREE1 *node)
long PTD_save_lower_tree(FILE *out, POS_TREE1 *node, long pos, ARB_ERROR &error)
char * GBS_global_string_copy(const char *templat,...)
POS_TREE1 * PT_change_leaf_to_node(POS_TREE1 *node)