Skip to content

Commit cb166c2

Browse files
author
Aakash Arayambeth
committed
generic sharding : setup metadata and remote tables. Create/delete
Signed-off-by: Aakash Arayambeth <[email protected]>
1 parent 070d116 commit cb166c2

35 files changed

+1862
-42
lines changed

Diff for: bbinc/cdb2_constants.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#define MAX_SPNAME MAXTABLELEN
3737
#define MAX_SPVERSION_LEN 80
3838
#define MAXTABLELEN 32
39+
#define MAXPARTITIONS 32
40+
#define MAXPARTITIONLEN (1 + (MAX_DBNAME_LENGTH + MAXTABLELEN)) /* partitions of the form <database>.<table> */
3941
#define MAXTAGLEN 64
4042
#define REPMAX 32
4143
/* Maximum buffer length for generated key name. */

Diff for: bbinc/consistent_hash.h

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ enum ch_err {
1515
CH_ERR_DUP = 4
1616
};
1717

18+
enum ch_hash_func_type {
19+
CH_HASH_SHA = 1,
20+
CH_HASH_MD5 = 2,
21+
CH_HASH_CRC = 3
22+
};
1823
struct consistent_hash_node {
1924
uint8_t *data;
2025
size_t data_len;

Diff for: bdb/bdb_schemachange.c

+6
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ int bdb_llog_partition(bdb_state_type *bdb_state, tran_type *tran, char *name,
353353
return bdb_llog_scdone_tran(bdb_state, views, tran, name, strlen(name) + 1,
354354
bdberr);
355355
}
356+
357+
int bdb_llog_hash_partition(bdb_state_type *bdb_state, tran_type *tran, char *name, int *bdberr)
358+
{
359+
return bdb_llog_scdone_tran(bdb_state, hash_views, tran, name, strlen(name) + 1, bdberr);
360+
}
361+
356362
int bdb_llog_luareload(bdb_state_type *bdb_state, int wait, int *bdberr)
357363
{
358364
return bdb_llog_scdone(bdb_state, luareload, NULL, 0, wait, bdberr);

Diff for: bdb/bdb_schemachange.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ typedef enum scdone {
5151
add_queue_file, // 22
5252
del_queue_file, // 23
5353
alias_table, // 24
54-
alias // 25
54+
alias, // 25
55+
hash_views // 25
5556
} scdone_t;
5657

5758
#define BDB_BUMP_DBOPEN_GEN(type, msg) \
@@ -73,6 +74,7 @@ int bdb_llog_views(bdb_state_type *bdb_state, char *name, int wait,
7374
int *bdberr);
7475
int bdb_llog_partition(bdb_state_type *bdb_state, tran_type *tran, char *name,
7576
int *bdberr);
77+
int bdb_llog_hash_partition(bdb_state_type *bdb_state, tran_type *tran, char *name, int *bdberr);
7678
int bdb_llog_rowlocks(bdb_state_type *, scdone_t, int *bdberr);
7779
int bdb_llog_genid_format(bdb_state_type *, scdone_t, int *bdberr);
7880
int bdb_reload_rowlocks(bdb_state_type *, scdone_t, int *bdberr);

Diff for: db/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ set(src
110110
machclass.c
111111
osqluprec.c
112112
macc_glue.c
113+
hash_partition.c
113114
${PROJECT_BINARY_DIR}/protobuf/bpfunc.pb-c.c
114115
${PROJECT_SOURCE_DIR}/tools/cdb2_dump/cdb2_dump.c
115116
${PROJECT_SOURCE_DIR}/tools/cdb2_load/cdb2_load.c

Diff for: db/comdb2.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ double gbl_sql_cost_error_threshold = -1;
492492

493493
int gbl_parallel_recovery_threads = 0;
494494

495-
int gbl_fdb_resolve_local = 0;
495+
int gbl_fdb_resolve_local = 1;
496496
int gbl_fdb_allow_cross_classes = 0;
497497
uint64_t gbl_sc_headroom = 10;
498498
/*---COUNTS---*/
@@ -816,6 +816,7 @@ int gbl_hostname_refresh_time = 60;
816816
int gbl_pstack_self = 1;
817817

818818
char *gbl_cdb2api_policy_override = NULL;
819+
int gbl_create_remote_tables = 0;
819820

820821
int close_all_dbs_tran(tran_type *tran);
821822

@@ -2410,6 +2411,15 @@ int llmeta_load_timepart(struct dbenv *dbenv)
24102411
return thedb->timepart_views ? 0 : -1;
24112412
}
24122413

2414+
int llmeta_load_hash_partitions(struct dbenv *dbenv)
2415+
{
2416+
logmsg(LOGMSG_INFO, "Loading hash-based partitions\n");
2417+
Pthread_rwlock_init(&hash_partition_lk, NULL);
2418+
dbenv->hash_partition_views = hash_create_all_views();
2419+
2420+
return dbenv->hash_partition_views ? 0 : -1;
2421+
}
2422+
24132423
/* replace the table names and dbnums saved in the low level meta table with the
24142424
* ones in the dbenv. returns 0 on success and anything else otherwise */
24152425
int llmeta_set_tables(tran_type *tran, struct dbenv *dbenv)
@@ -4143,6 +4153,12 @@ static int init(int argc, char **argv)
41434153
unlock_schema_lk();
41444154
return -1;
41454155
}
4156+
4157+
if (llmeta_load_hash_partitions(thedb)) {
4158+
logmsg(LOGMSG_ERROR, "could not load hash partitions\n");
4159+
unlock_schema_lk();
4160+
return -1;
4161+
}
41464162

41474163
if (llmeta_load_queues(thedb)) {
41484164
logmsg(LOGMSG_FATAL, "could not load queues from the low level meta "
@@ -6342,7 +6358,10 @@ int comdb2_reload_schemas(void *dbenv, void *inlsn)
63426358
logmsg(LOGMSG_ERROR, "could not load time partitions\n");
63436359
abort();
63446360
}
6345-
6361+
if (llmeta_load_hash_partitions(thedb)) {
6362+
logmsg(LOGMSG_FATAL, "could not load mod based shards\n");
6363+
abort();
6364+
}
63466365
if ((rc = bdb_get_rowlocks_state(&rlstate, tran, &bdberr)) != 0) {
63476366
logmsg(LOGMSG_ERROR, "Get rowlocks llmeta failed, rc=%d bdberr=%d\n",
63486367
rc, bdberr);

Diff for: db/comdb2.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -969,11 +969,11 @@ struct dbenv {
969969
int incoh_notcoherent;
970970
uint32_t incoh_file, incoh_offset;
971971
timepart_views_t *timepart_views;
972-
973-
struct time_metric *service_time;
974-
struct time_metric *queue_depth;
975-
struct time_metric *concurrent_queries;
976-
struct time_metric *connections;
972+
hash_t *hash_partition_views;
973+
struct time_metric* service_time;
974+
struct time_metric* queue_depth;
975+
struct time_metric* concurrent_queries;
976+
struct time_metric* connections;
977977
struct time_metric *sql_queue_time;
978978
struct time_metric *handle_buf_queue_time;
979979
struct time_metric *watchdog_time;
@@ -3734,4 +3734,5 @@ void get_disable_skipscan_all();
37343734

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

3737+
extern pthread_rwlock_t hash_partition_lk;
37373738
#endif /* !INCLUDED_COMDB2_H */

Diff for: db/db_tunables.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ int gbl_old_column_names = 1;
523523
int gbl_enable_sq_flattening_optimization = 1;
524524
int gbl_mask_internal_tunables = 1;
525525
int gbl_allow_readonly_runtime_mod = 0;
526-
527526
size_t gbl_cached_output_buffer_max_bytes = 8 * 1024 * 1024; /* 8 MiB */
528527
int gbl_sqlite_sorterpenalty = 5;
529528
int gbl_file_permissions = 0660;
@@ -557,6 +556,7 @@ extern int gbl_altersc_latency_inc;
557556
extern int gbl_sc_history_max_rows;
558557
extern int gbl_sc_status_max_rows;
559558
extern int gbl_rep_process_pstack_time;
559+
extern int gbl_create_remote_tables;
560560

561561
extern void set_snapshot_impl(snap_impl_enum impl);
562562
extern const char *snap_impl_str(snap_impl_enum impl);

Diff for: db/db_tunables.h

+3
Original file line numberDiff line numberDiff line change
@@ -2465,4 +2465,7 @@ REGISTER_TUNABLE("sc_status_max_rows", "Max number of rows returned in comdb2_sc
24652465
TUNABLE_INTEGER, &gbl_sc_status_max_rows, 0, NULL, NULL, NULL, NULL);
24662466
REGISTER_TUNABLE("rep_process_pstack_time", "pstack the server if rep_process runs longer than time specified in secs (Default: 30s)",
24672467
TUNABLE_INTEGER, &gbl_rep_process_pstack_time, 0, NULL, NULL, NULL, NULL);
2468+
REGISTER_TUNABLE("create_remote_tables",
2469+
"while creating a sharded table, create tables (shards) on the remote databases as well (default: off)",
2470+
TUNABLE_BOOLEAN, &gbl_create_remote_tables, 0, NULL, NULL, NULL, NULL);
24682471
#endif /* _DB_TUNABLES_H */

Diff for: db/dohast.h

Whitespace-only changes.

0 commit comments

Comments
 (0)