int main(int argc, char *argv[]) { unsigned int i, j; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT }; plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 1); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { bool array[NUM_RECORDS]; tdb = tdb_open("run-check-callback.tdb", flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr); ok1(tdb); if (!tdb) continue; ok1(store_records(tdb)); for (j = 0; j < NUM_RECORDS; j++) array[j] = false; ok1(tdb_check(tdb, check, array) == TDB_SUCCESS); for (j = 0; j < NUM_RECORDS; j++) if (!array[j]) break; ok1(j == NUM_RECORDS); tdb_close(tdb); } ok1(tap_log_messages == 0); return exit_status(); }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" }, { "delete-pct", 'p', POPT_ARG_INT, &delete_pct, 0, "delete_pct", "integer" }, POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; poptContext pc; struct event_context *ev; pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { default: fprintf(stderr, "Invalid option %s: %s\n", poptBadOption(pc, 0), poptStrerror(opt)); exit(1); } } /* setup the remaining options for the main program to use */ extra_argv = poptGetArgs(pc); if (extra_argv) { extra_argv++; while (extra_argv[extra_argc]) extra_argc++; } ev = event_context_init(NULL); ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0)); if (ctdb == NULL) { printf("failed to connect to daemon\n"); exit(1); } /* attach to a specific database */ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb", false, 0); if (!ctdb_db) { printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); exit(1); } store_records(ctdb, ev); return 0; }
int TestBackupMultiDataDir(CuTest *ct) { DB_ENV *dbenv; DB *dbp; DBTYPE dtype; struct handlers *info; int has_callback; u_int32_t flag; dtype = DB_BTREE; info = ct->context; has_callback = 0; flag = DB_BACKUP_CLEAN | DB_CREATE | DB_BACKUP_FILES; /* Step 1: set up directories and make DB_CONFIG. */ CuAssert(ct, "setup_dir", setup_dir(2, data_dirs) == 0); CuAssert(ct, "make_dbconfig", make_dbconfig("set_data_dir DATA1") == 0); /* Step 2: open db handle. */ CuAssert(ct,"open_dbp", open_dbp(&dbenv, &dbp, dtype, 2, data_dirs, data_dirs[0], NULL, 0, NULL) == 0); info->dbenvp = dbenv; info->dbp = dbp; /* Step 3: store records into db. */ CuAssert(ct, "store_records", store_records(dbp, 1) == 0); CuAssert(ct, "DB->sync", dbp->sync(dbp, 0) == 0); /* Step 4: backup the whole environment without callbacks. */ CuAssert(ct, "backup_env", backup_env(ct, dbenv, flag, has_callback) == 0); /* * Step 5: check backup result. * 5a: verify db files are in BACKUP/DATA1. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 0, data_dirs[0], data_dirs[0]) == 0); /* 5b: verify that data_dirs are in backupdir. */ CuAssert(ct, "__os_exist", __os_exists(NULL, "BACKUP/DATA1", 0) == 0); CuAssert(ct, "__os_exist", __os_exists(NULL, "BACKUP/DATA2", 0) == 0); /* 5c: verify that log files are in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 1, NULL, NULL) == 0); /* 5d: verify that DB_CONFIG is in BACKUP_DIR. */ CuAssert(ct, "verify_dbconfig", verify_dbconfig(1) == 0); return (0); }
int TestBackupSetLogDir(CuTest *ct) { DB_ENV *dbenv; DB *dbp; DBTYPE dtype; struct handlers *info; char *dirs[2]; int has_callback = 1; u_int32_t flag; dtype = DB_BTREE; info = ct->context; has_callback = 1; flag = DB_BACKUP_CLEAN | DB_CREATE | DB_BACKUP_FILES; dirs[0] = LOG_DIR; dirs[1] = NULL; /* Step 1: set up directories and make DB_CONFIG. */ CuAssert(ct, "setup_dir", setup_dir(1, dirs) == 0); CuAssert(ct, "make_dbconfig", make_dbconfig("set_lg_dir LOG") == 0); /* Step 2: open db handle. */ CuAssert(ct,"open_dbp", open_dbp(&dbenv, &dbp, dtype, 0, NULL, NULL, LOG_DIR, 0, NULL) == 0); info->dbenvp = dbenv; info->dbp = dbp; /* Step 3: store records into db. */ CuAssert(ct, "store_records", store_records(dbp, 1) == 0); CuAssert(ct, "DB->sync", dbp->sync(dbp, 0) == 0); /* Step 4: backup the whole environment with callbacks. */ CuAssert(ct, "backup_env", backup_env(ct, dbenv, flag, has_callback) == 0); /* * Step 5: check backup result. * 5a: verify the db file is in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 0, NULL, NULL) == 0); /* 5b: verify that log files are in BACKUP/LOG. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 1, LOG_DIR, LOG_DIR) == 0); /* 5c: verify that DB_CONFIG is in BACKUP_DIR. */ CuAssert(ct, "verify_dbconfig", verify_dbconfig(1) == 0); return (0); }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" }, POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; poptContext pc; struct event_context *ev; pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { default: fprintf(stderr, "Invalid option %s: %s\n", poptBadOption(pc, 0), poptStrerror(opt)); exit(1); } } /* talloc_enable_leak_report_full(); */ /* setup the remaining options for the main program to use */ extra_argv = poptGetArgs(pc); if (extra_argv) { extra_argv++; while (extra_argv[extra_argc]) extra_argc++; } ev = event_context_init(NULL); ctdb = ctdb_cmdline_client(ev); /* attach to a specific database */ ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0); if (!ctdb_db) { printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); exit(1); } printf("Waiting for cluster\n"); while (1) { uint32_t recmode=1; ctdb_ctrl_getrecmode(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); if (recmode == 0) break; event_loop_once(ev); } store_records(ctdb, ev); return 0; }
int main(int argc, char *argv[]) { unsigned int i, j; int num; struct trav_data td; TDB_DATA k; struct tdb_context *tdb; union tdb_attribute seed_attr; enum TDB_ERROR ecode; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT }; seed_attr.base.attr = TDB_ATTRIBUTE_SEED; seed_attr.base.next = &tap_log_attr; seed_attr.seed.seed = 6334326220117065685ULL; plan_tests(sizeof(flags) / sizeof(flags[0]) * (NUM_RECORDS*6 + (NUM_RECORDS-1)*3 + 22) + 1); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { tdb = tdb_open("run-traverse.tdb", flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600, &seed_attr); ok1(tdb); if (!tdb) continue; ok1(tdb_firstkey(tdb, &k) == TDB_ERR_NOEXIST); /* One entry... */ k.dptr = (unsigned char *)# k.dsize = sizeof(num); num = 0; ok1(tdb_store(tdb, k, k, TDB_INSERT) == 0); ok1(tdb_firstkey(tdb, &k) == TDB_SUCCESS); ok1(k.dsize == sizeof(num)); ok1(memcmp(k.dptr, &num, sizeof(num)) == 0); ok1(tdb_nextkey(tdb, &k) == TDB_ERR_NOEXIST); /* Two entries. */ k.dptr = (unsigned char *)# k.dsize = sizeof(num); num = 1; ok1(tdb_store(tdb, k, k, TDB_INSERT) == 0); ok1(tdb_firstkey(tdb, &k) == TDB_SUCCESS); ok1(k.dsize == sizeof(num)); memcpy(&num, k.dptr, sizeof(num)); ok1(num == 0 || num == 1); ok1(tdb_nextkey(tdb, &k) == TDB_SUCCESS); ok1(k.dsize == sizeof(j)); memcpy(&j, k.dptr, sizeof(j)); ok1(j == 0 || j == 1); ok1(j != num); ok1(tdb_nextkey(tdb, &k) == TDB_ERR_NOEXIST); /* Clean up. */ k.dptr = (unsigned char *)# k.dsize = sizeof(num); num = 0; ok1(tdb_delete(tdb, k) == 0); num = 1; ok1(tdb_delete(tdb, k) == 0); /* Now lots of records. */ ok1(store_records(tdb)); td.calls = 0; num = tdb_traverse(tdb, trav, &td); ok1(num == NUM_RECORDS); ok1(td.calls == NUM_RECORDS); /* Simple loop should match tdb_traverse */ for (j = 0, ecode = tdb_firstkey(tdb, &k); j < td.calls; j++) { int val; ok1(ecode == TDB_SUCCESS); ok1(k.dsize == sizeof(val)); memcpy(&val, k.dptr, k.dsize); ok1(td.records[j] == val); ecode = tdb_nextkey(tdb, &k); } /* But arbitrary orderings should work too. */ for (j = td.calls-1; j > 0; j--) { k.dptr = (unsigned char *)&td.records[j-1]; k.dsize = sizeof(td.records[j-1]); k = dup_key(k); ok1(tdb_nextkey(tdb, &k) == TDB_SUCCESS); ok1(k.dsize == sizeof(td.records[j])); ok1(memcmp(k.dptr, &td.records[j], k.dsize) == 0); free(k.dptr); } /* Even delete should work. */ for (j = 0, ecode = tdb_firstkey(tdb, &k); ecode != TDB_ERR_NOEXIST; j++) { ok1(ecode == TDB_SUCCESS); ok1(k.dsize == 4); ok1(tdb_delete(tdb, k) == 0); ecode = tdb_nextkey(tdb, &k); } diag("delete using first/nextkey gave %u of %u records", j, NUM_RECORDS); ok1(j == NUM_RECORDS); tdb_close(tdb); } ok1(tap_log_messages == 0); return exit_status(); }
int TestBackupPartitionDB(CuTest *ct) { DB_ENV *dbenv; DB *dbp; DBT key1, key2, keys[2]; DBTYPE dtype; struct handlers *info; int has_callback; u_int32_t flag, value1, value2; dtype = DB_BTREE; info = ct->context; has_callback = 0; flag = DB_BACKUP_CLEAN | DB_CREATE | DB_BACKUP_SINGLE_DIR; /* Step 1: set up directories and make DB_CONFIG. */ CuAssert(ct, "setup_dir", setup_dir(1, data_dirs) == 0); CuAssert(ct, "make_dbconfig", make_dbconfig("set_data_dir DATA1") == 0); /* Make the partition keys. */ memset(&key1, 0, sizeof(DBT)); memset(&key2, 0, sizeof(DBT)); value1 = 8; key1.data = &value1; key1.size = sizeof(value1); value2 = 16; key2.data = &value2; key2.size = sizeof(value2); keys[0] = key1; keys[1] = key2; /* Step 2: open db handle. */ CuAssert(ct,"open_dbp", open_dbp(&dbenv, &dbp, dtype, 1, data_dirs, data_dirs[0], NULL, 3, keys) == 0); info->dbenvp = dbenv; info->dbp = dbp; /* Step 3: store records into db. */ CuAssert(ct, "store_records", store_records(dbp, 1) == 0); CuAssert(ct, "DB->sync", dbp->sync(dbp, 0) == 0); /* Step 4: backup the whole environment into a single directory. */ CuAssert(ct, "backup_env", backup_env(ct, dbenv, flag, has_callback) == 0); /* * Step 5: check backup result. * 5a: verify db files are in BACKUP/DATA1. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 1, 0, data_dirs[0], NULL) == 0); /* 5b: verify that creation directory is not in BACKUPD_DIR. */ CuAssert(ct, "__os_exist", __os_exists(NULL, "BACKUP/DATA", 0) != 0); /* 5c: verify log files are in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 1, NULL, NULL) == 0); /* 5d: verify that DB_CONFIG is not in BACKUP_DIR. */ CuAssert(ct, "verify_dbconfig", verify_dbconfig(0) == 0); return (0); }
int TestBackupSimpleEnvWithConfig(CuTest *ct) { DB_ENV *dbenv; DB *dbp; DBTYPE dtype; struct handlers *info; char **names; int cnt, has_callback; time_t end_time, secs1, secs2, start_time; u_int32_t flag, value; dtype = DB_BTREE; info = ct->context; has_callback = 0; flag = DB_EXCL; end_time = secs1 = secs2 = start_time = 0; /* Step 1: set up directories. */ CuAssert(ct, "setup_dir", setup_dir(0, NULL) == 0); /* Step 2: open db handle. */ CuAssert(ct, "open_dbp", open_dbp(&dbenv, &dbp, dtype, 0, NULL, NULL, NULL, 0, NULL) == 0); info->dbenvp = dbenv; info->dbp = dbp; /* * Step 3: store records into db so that there is more than * 1 data page in the db. */ CuAssert(ct, "store_records", store_records(dbp, 10) == 0); CuAssert(ct, "DB->sync", dbp->sync(dbp, 0) == 0); /* * Step 4: verify the backup handle is NULL, * since we never configure the backup. */ CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, &value) == EINVAL); /* * Step 5: backup without any backup configs. * 5a: backup only the db file without callbacks and record the time. */ start_time = time(NULL); CuAssert(ct, "backup_db", backup_db(ct, dbenv, BACKUP_DB, flag, has_callback) == 0); end_time = time(NULL); secs1 = end_time - start_time; /* 5b: verify db file is in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 0, NULL, NULL) == 0); /* 5c: verify that no other files are in BACKUP_DIR. */ CuAssert(ct, "__os_dirlist", __os_dirlist(NULL, BACKUP_DIR, 0, &names, &cnt) == 0); CuAssert(ct, "too many files in backupdir", cnt == 1); /* Clean up the backup directory. */ setup_envdir(BACKUP_DIR, 1); /* * Step 6: backup with backup configs. * 6a: configure the backup handle: use direct I/O to write pages to * the disk, the backup buffer size is 256 bytes (which is smaller * than the db page size), the number of pages * to read before pausing is 1, and the number of seconds to sleep * between batches of reads is 1. */ CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, 1) == 0); CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_SIZE, 256) == 0); CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_READ_COUNT, 1) == 0); CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_READ_SLEEP, US_PER_SEC / 2) == 0); /* * 6b: backup only the db file without callbacks and * record the time. */ start_time = time(NULL); CuAssert(ct, "backup_db", backup_db(ct, dbenv, BACKUP_DB, flag, has_callback) == 0); end_time = time(NULL); secs2 = end_time - start_time; /* 6c: verify db file is in BACKUP_DIR. */ CuAssert(ct, "verify_db_log", verify_db_log(dtype, 0, 0, NULL, NULL) == 0); /* 6d: no other files are in BACKUP_DIR. */ CuAssert(ct, "__os_dirlist", __os_dirlist(NULL, BACKUP_DIR, 0, &names, &cnt) == 0); CuAssert(ct, "too many files in backupdir", cnt == 1); /* 6e: verify the backup config. */ CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_READ_SLEEP, &value) == 0); CuAssertTrue(ct, value == US_PER_SEC / 2); /* * Verify the backup config DB_BACKUP_READ_SLEEP works. That is with * the configuration, backup pauses for a number of microseconds * between batches of reads. So for the same backup content, the backup * time with the configuration should be longer than that without it. */ CuAssertTrue(ct, secs2 > secs1); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_READ_COUNT, &value) == 0); CuAssertTrue(ct, value == 1); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_SIZE, &value) == 0); CuAssertTrue(ct, value == 256); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, &value) == 0); CuAssertTrue(ct, value == 1); /* * Step 7: re-configure the backup write direct config and * verify the new config value. */ CuAssert(ct, "DB_ENV->set_backup_config", dbenv->set_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, 0) == 0); CuAssert(ct, "DB_ENV->get_backup_config", dbenv->get_backup_config(dbenv, DB_BACKUP_WRITE_DIRECT, &value) == 0); CuAssertTrue(ct, value == 0); return (0); }