Skip to content

Commit

Permalink
generic sharding : setup metadata and remote tables. Create/delete
Browse files Browse the repository at this point in the history
Signed-off-by: Aakash Arayambeth <[email protected]>
  • Loading branch information
Aakash Arayambeth committed Jan 18, 2025
1 parent 070d116 commit cb166c2
Show file tree
Hide file tree
Showing 35 changed files with 1,862 additions and 42 deletions.
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 @@ -110,6 +110,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 @@ -492,7 +492,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 @@ -816,6 +816,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 @@ -2410,6 +2411,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 @@ -4143,6 +4153,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 @@ -6342,7 +6358,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
11 changes: 6 additions & 5 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 @@ -3734,4 +3734,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 */
2 changes: 1 addition & 1 deletion db/db_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,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 Expand Up @@ -557,6 +556,7 @@ extern int gbl_altersc_latency_inc;
extern int gbl_sc_history_max_rows;
extern int gbl_sc_status_max_rows;
extern int gbl_rep_process_pstack_time;
extern int gbl_create_remote_tables;

extern void set_snapshot_impl(snap_impl_enum impl);
extern const char *snap_impl_str(snap_impl_enum impl);
Expand Down
3 changes: 3 additions & 0 deletions db/db_tunables.h
Original file line number Diff line number Diff line change
Expand Up @@ -2465,4 +2465,7 @@ REGISTER_TUNABLE("sc_status_max_rows", "Max number of rows returned in comdb2_sc
TUNABLE_INTEGER, &gbl_sc_status_max_rows, 0, NULL, NULL, NULL, NULL);
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("create_remote_tables",
"while creating a sharded table, create tables (shards) on the remote databases as well (default: off)",
TUNABLE_BOOLEAN, &gbl_create_remote_tables, 0, NULL, NULL, NULL, NULL);
#endif /* _DB_TUNABLES_H */
Empty file added db/dohast.h
Empty file.
Loading

0 comments on commit cb166c2

Please sign in to comment.