Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic sharding : setup metadata and remote tables. Create/delete #4971

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bbinc/cdb2_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#define MAX_SPNAME MAXTABLELEN
#define MAX_SPVERSION_LEN 80
#define MAXTABLELEN 32
#define MAXPARTITIONS 32
#define MAXPARTITIONLEN (1 + (MAX_DBNAME_LENGTH + MAXTABLELEN)) /* partitions of the form <database>.<table> */
#define MAXTAGLEN 64
#define REPMAX 32
/* Maximum buffer length for generated key name. */
Expand Down
5 changes: 5 additions & 0 deletions bbinc/consistent_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ enum ch_err {
CH_ERR_DUP = 4
};

enum ch_hash_func_type {
CH_HASH_SHA = 1,
CH_HASH_MD5 = 2,
CH_HASH_CRC = 3
};
struct consistent_hash_node {
uint8_t *data;
size_t data_len;
Expand Down
6 changes: 6 additions & 0 deletions bdb/bdb_schemachange.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ int bdb_llog_partition(bdb_state_type *bdb_state, tran_type *tran, char *name,
return bdb_llog_scdone_tran(bdb_state, views, tran, name, strlen(name) + 1,
bdberr);
}

int bdb_llog_hash_partition(bdb_state_type *bdb_state, tran_type *tran, char *name, int *bdberr)
{
return bdb_llog_scdone_tran(bdb_state, hash_views, tran, name, strlen(name) + 1, bdberr);
}

int bdb_llog_luareload(bdb_state_type *bdb_state, int wait, int *bdberr)
{
return bdb_llog_scdone(bdb_state, luareload, NULL, 0, wait, bdberr);
Expand Down
4 changes: 3 additions & 1 deletion bdb/bdb_schemachange.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ typedef enum scdone {
add_queue_file, // 22
del_queue_file, // 23
alias_table, // 24
alias // 25
alias, // 25
hash_views // 25
} scdone_t;

#define BDB_BUMP_DBOPEN_GEN(type, msg) \
Expand All @@ -73,6 +74,7 @@ int bdb_llog_views(bdb_state_type *bdb_state, char *name, int wait,
int *bdberr);
int bdb_llog_partition(bdb_state_type *bdb_state, tran_type *tran, char *name,
int *bdberr);
int bdb_llog_hash_partition(bdb_state_type *bdb_state, tran_type *tran, char *name, int *bdberr);
int bdb_llog_rowlocks(bdb_state_type *, scdone_t, int *bdberr);
int bdb_llog_genid_format(bdb_state_type *, scdone_t, int *bdberr);
int bdb_reload_rowlocks(bdb_state_type *, scdone_t, int *bdberr);
Expand Down
1 change: 1 addition & 0 deletions db/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ set(src
machclass.c
osqluprec.c
macc_glue.c
hash_partition.c
${PROJECT_BINARY_DIR}/protobuf/bpfunc.pb-c.c
${PROJECT_SOURCE_DIR}/tools/cdb2_dump/cdb2_dump.c
${PROJECT_SOURCE_DIR}/tools/cdb2_load/cdb2_load.c
Expand Down
23 changes: 21 additions & 2 deletions db/comdb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ double gbl_sql_cost_error_threshold = -1;

int gbl_parallel_recovery_threads = 0;

int gbl_fdb_resolve_local = 0;
int gbl_fdb_resolve_local = 1;
int gbl_fdb_allow_cross_classes = 0;
uint64_t gbl_sc_headroom = 10;
/*---COUNTS---*/
Expand Down Expand Up @@ -818,6 +818,7 @@ int gbl_hostname_refresh_time = 60;
int gbl_pstack_self = 1;

char *gbl_cdb2api_policy_override = NULL;
int gbl_create_remote_tables = 0;

int close_all_dbs_tran(tran_type *tran);

Expand Down Expand Up @@ -2412,6 +2413,15 @@ int llmeta_load_timepart(struct dbenv *dbenv)
return thedb->timepart_views ? 0 : -1;
}

int llmeta_load_hash_partitions(struct dbenv *dbenv)
{
logmsg(LOGMSG_INFO, "Loading hash-based partitions\n");
Pthread_rwlock_init(&hash_partition_lk, NULL);
dbenv->hash_partition_views = hash_create_all_views();

return dbenv->hash_partition_views ? 0 : -1;
}

/* replace the table names and dbnums saved in the low level meta table with the
* ones in the dbenv. returns 0 on success and anything else otherwise */
int llmeta_set_tables(tran_type *tran, struct dbenv *dbenv)
Expand Down Expand Up @@ -4144,6 +4154,12 @@ static int init(int argc, char **argv)
unlock_schema_lk();
return -1;
}

if (llmeta_load_hash_partitions(thedb)) {
logmsg(LOGMSG_ERROR, "could not load hash partitions\n");
unlock_schema_lk();
return -1;
}

if (llmeta_load_queues(thedb)) {
logmsg(LOGMSG_FATAL, "could not load queues from the low level meta "
Expand Down Expand Up @@ -6343,7 +6359,10 @@ int comdb2_reload_schemas(void *dbenv, void *inlsn)
logmsg(LOGMSG_ERROR, "could not load time partitions\n");
abort();
}

if (llmeta_load_hash_partitions(thedb)) {
logmsg(LOGMSG_FATAL, "could not load mod based shards\n");
abort();
}
if ((rc = bdb_get_rowlocks_state(&rlstate, tran, &bdberr)) != 0) {
logmsg(LOGMSG_ERROR, "Get rowlocks llmeta failed, rc=%d bdberr=%d\n",
rc, bdberr);
Expand Down
13 changes: 7 additions & 6 deletions db/comdb2.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,11 +969,11 @@ struct dbenv {
int incoh_notcoherent;
uint32_t incoh_file, incoh_offset;
timepart_views_t *timepart_views;

struct time_metric *service_time;
struct time_metric *queue_depth;
struct time_metric *concurrent_queries;
struct time_metric *connections;
hash_t *hash_partition_views;
struct time_metric* service_time;
struct time_metric* queue_depth;
struct time_metric* concurrent_queries;
struct time_metric* connections;
struct time_metric *sql_queue_time;
struct time_metric *handle_buf_queue_time;
struct time_metric *watchdog_time;
Expand Down Expand Up @@ -1908,7 +1908,7 @@ extern int gbl_dohsql_pool_thr_slack;
extern int gbl_dohsql_sc_max_threads;
extern int gbl_sockbplog;
extern int gbl_sockbplog_sockpool;

extern int gbl_sharding_ddl_verbose;
extern int gbl_logical_live_sc;

extern int gbl_test_io_errors;
Expand Down Expand Up @@ -3739,4 +3739,5 @@ void get_disable_skipscan_all();

void get_client_origin(char *out, size_t outlen, struct sqlclntstate *clnt);

extern pthread_rwlock_t hash_partition_lk;
#endif /* !INCLUDED_COMDB2_H */
1 change: 0 additions & 1 deletion db/db_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ int gbl_old_column_names = 1;
int gbl_enable_sq_flattening_optimization = 1;
int gbl_mask_internal_tunables = 1;
int gbl_allow_readonly_runtime_mod = 0;

size_t gbl_cached_output_buffer_max_bytes = 8 * 1024 * 1024; /* 8 MiB */
int gbl_sqlite_sorterpenalty = 5;
int gbl_file_permissions = 0660;
Expand Down
4 changes: 4 additions & 0 deletions db/db_tunables.h
Original file line number Diff line number Diff line change
Expand Up @@ -2483,4 +2483,8 @@ REGISTER_TUNABLE("sc_status_max_rows", "Max number of rows returned in comdb2_sc
REGISTER_TUNABLE("rep_process_pstack_time", "pstack the server if rep_process runs longer than time specified in secs (Default: 30s)",
TUNABLE_INTEGER, &gbl_rep_process_pstack_time, 0, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("sql_recover_time", "Number of msec before checking if SQL has waiters. 0 will disable. (Default: 10ms)", TUNABLE_INTEGER, &gbl_sql_recover_time, 0, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("sharding_ddl_verbose",
"Print debug information for sharded DDL operations",
TUNABLE_BOOLEAN, &gbl_sharding_ddl_verbose, 0, NULL, NULL, NULL,
NULL);
#endif /* _DB_TUNABLES_H */
Empty file added db/dohast.h
Empty file.
2 changes: 1 addition & 1 deletion db/fdb_fend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ static int check_table_fdb(fdb_t *fdb, fdb_tbl_t *tbl, int initial,
return rc;
}

static enum mach_class get_fdb_class(const char **p_dbname, int *local,
enum mach_class get_fdb_class(const char **p_dbname, int *local,
int *lvl_override)
{
const char *dbname = *p_dbname;
Expand Down
2 changes: 2 additions & 0 deletions db/fdb_fend.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,5 +485,7 @@ void fdb_init_disttxn(sqlclntstate *clnt);
*/
int fdb_2pc_set(sqlclntstate *clnt, fdb_t *fdb, cdb2_hndl_tp *hndl);

enum mach_class get_fdb_class(const char **p_dbname, int *local,
int *lvl_override);
#endif

Loading