1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

add push/pull of tdb and a control to copy a tdb from one node to

another node

(This used to be ctdb commit c313daff4c1362cd08a9f682ce04cab312678038)
This commit is contained in:
Ronnie Sahlberg 2007-04-30 00:58:27 +10:00
parent f67a79ad8e
commit eacfcaf437
7 changed files with 170 additions and 147 deletions

View File

@ -179,7 +179,7 @@ struct ctdb_context *ctdb_cmdline_client(struct event_context *ev)
}
/* get our config */
ret = ctdb_get_config(ctdb);
ret = ctdb_ctrl_get_config(ctdb);
if (ret != 0) {
DEBUG(0,(__location__ " Failed to get ctdb config\n"));
talloc_free(ctdb);

View File

@ -461,7 +461,7 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
ctdb_daemon_connect_wait(ctdb);
/* get other config variables */
ctdb_get_config(ctdb);
ctdb_ctrl_get_config(ctdb);
}
/*
@ -711,7 +711,7 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
/*
a process exists call. Returns 0 if process exists, -1 otherwise
*/
int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid)
int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid)
{
int ret;
TDB_DATA data;
@ -734,7 +734,7 @@ int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid)
/*
get remote status
*/
int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status)
int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status)
{
int ret;
TDB_DATA data;
@ -764,7 +764,7 @@ int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status
/*
get vnn map from a remote node
*/
int ctdb_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap)
int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap)
{
int ret;
TDB_DATA data, outdata;
@ -796,7 +796,7 @@ int ctdb_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn
/*
get the recovery mode of a remote node
*/
int ctdb_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode)
int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode)
{
int ret;
TDB_DATA data, outdata;
@ -819,7 +819,7 @@ int ctdb_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recm
/*
set the recovery mode of a remote node
*/
int ctdb_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode)
int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode)
{
int ret;
TDB_DATA data, outdata;
@ -843,7 +843,7 @@ int ctdb_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmo
/*
get a list of databases off a remote node
*/
int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap)
int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap)
{
int ret;
TDB_DATA data, outdata;
@ -879,7 +879,7 @@ int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid
/*
get a list of nodes (vnn and flags ) from a remote node
*/
int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap)
{
int ret;
@ -911,7 +911,7 @@ int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
/*
set vnn map on a node
*/
int ctdb_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap)
int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap)
{
int ret;
TDB_DATA *data, outdata;
@ -940,9 +940,9 @@ int ctdb_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn
}
/*
get all keys for a specific database
get all keys and records for a specific database
*/
int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys)
int ctdb_ctrl_pulldb(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys)
{
int i, ret;
TDB_DATA indata, outdata;
@ -953,22 +953,23 @@ int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TA
indata.dptr = (unsigned char *)&dbid;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GET_KEYS, indata,
CTDB_CONTROL_PULL_DB, indata,
mem_ctx, &outdata, &res);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for getkeys failed\n"));
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
return -1;
}
keys->num= *((uint32_t *)(&outdata.dptr[0]));
keys->keys=talloc_array(mem_ctx, TDB_DATA, keys->num);
keys->dbid = ((uint32_t *)(&outdata.dptr[0]))[0];
keys->num = ((uint32_t *)(&outdata.dptr[0]))[1];
keys->keys =talloc_array(mem_ctx, TDB_DATA, keys->num);
keys->headers=talloc_array(mem_ctx, struct ctdb_ltdb_header, keys->num);
keys->lmasters=talloc_array(mem_ctx, uint32_t, keys->num);
keys->data=talloc_array(mem_ctx, TDB_DATA, keys->num);
/* loop over all key/data pairs */
ptr=&outdata.dptr[4];
ptr=&outdata.dptr[8];
for(i=0;i<keys->num;i++){
uint32_t len;
TDB_DATA *key, *data;
@ -1001,10 +1002,41 @@ int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TA
return 0;
}
/*
copy a tdb from one node to another node
*/
int ctdb_ctrl_copydb(struct ctdb_context *ctdb, uint32_t sourcenode, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx)
{
int ret;
TDB_DATA indata, outdata;
int32_t res;
indata.dsize = sizeof(uint32_t);
indata.dptr = (unsigned char *)&dbid;
ret = ctdb_control(ctdb, sourcenode, 0,
CTDB_CONTROL_PULL_DB, indata,
mem_ctx, &outdata, &res);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
return -1;
}
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_PUSH_DB, outdata,
mem_ctx, NULL, &res);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for pushdb failed\n"));
return -1;
}
return 0;
}
/*
change dmaster for all keys in the database to the new value
*/
int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster)
int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster)
{
int ret;
TDB_DATA indata, outdata;
@ -1030,7 +1062,7 @@ int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *me
/*
delete all records from a tdb
*/
int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid)
int ctdb_ctrl_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid)
{
int ret;
TDB_DATA indata, outdata;
@ -1052,36 +1084,10 @@ int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_c
return 0;
}
/*
pull a db from a remote node
*/
int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t from_vnn)
{
int ret;
TDB_DATA indata, outdata;
int32_t res;
indata.dsize = 2*sizeof(uint32_t);
indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2);
((uint32_t *)(&indata.dptr[0]))[0] = dbid;
((uint32_t *)(&indata.dptr[0]))[1] = from_vnn;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_PULL_DB, indata,
mem_ctx, &outdata, &res);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
return -1;
}
return 0;
}
/*
ping a node, return number of clients connected
*/
int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode)
int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode)
{
int ret;
int32_t res;
@ -1098,7 +1104,7 @@ int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode)
/*
get ctdb config
*/
int ctdb_get_config(struct ctdb_context *ctdb)
int ctdb_ctrl_get_config(struct ctdb_context *ctdb)
{
int ret;
int32_t res;
@ -1130,7 +1136,7 @@ int ctdb_get_config(struct ctdb_context *ctdb)
/*
find the real path to a ltdb
*/
int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx,
int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx,
const char **path)
{
int ret;
@ -1160,7 +1166,7 @@ int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx
/*
get debug level on a node
*/
int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level)
int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level)
{
int ret;
int32_t res;
@ -1185,7 +1191,7 @@ int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *
/*
set debug level on a node
*/
int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level)
int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level)
{
int ret;
int32_t res;
@ -1218,7 +1224,7 @@ uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ct
map = talloc(mem_ctx, struct ctdb_node_map);
CTDB_NO_MEMORY_VOID(ctdb, map);
ret = ctdb_getnodemap(ctdb, CTDB_CURRENT_NODE, map, map);
ret = ctdb_ctrl_getnodemap(ctdb, CTDB_CURRENT_NODE, map, map);
if (ret != 0) {
talloc_free(map);
return NULL;

View File

@ -99,8 +99,8 @@ static int traverse_getkeys(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data
ptr=outdata->dptr=talloc_realloc_size(outdata, outdata->dptr, len);
ptr+=outdata->dsize;
outdata->dsize=len;
/* number of records is stored as the first 4 bytes */
(*((uint32_t *)(&outdata->dptr[0])))++;
/* number of records is stored as the second 4 bytes */
((uint32_t *)(&outdata->dptr[0]))[1]++;
*((uint32_t *)ptr)=ctdb_lmaster(ctdb_db->ctdb, &key);
ptr+=4;
@ -253,7 +253,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
return 0;
}
case CTDB_CONTROL_GET_KEYS: {
case CTDB_CONTROL_PULL_DB: {
uint32_t dbid;
struct ctdb_db_context *ctdb_db;
struct getkeys_params params;
@ -265,9 +265,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
return -1;
}
outdata->dsize = sizeof(uint32_t);
outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, 1);
*((uint32_t *)(&outdata->dptr[0]))=0;
outdata->dsize = 2* sizeof(uint32_t);
outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, 2);
((uint32_t *)(&outdata->dptr[0]))[0]=dbid;
((uint32_t *)(&outdata->dptr[0]))[1]=0;
params.ctdb_db = ctdb_db;
params.outdata = outdata;
@ -317,11 +318,16 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
return 0;
}
case CTDB_CONTROL_PULL_DB: {
uint32_t dbid, from_vnn;
case CTDB_CONTROL_PUSH_DB: {
uint32_t dbid, num;
struct ctdb_db_context *ctdb_db;
struct ctdb_key_list keys;
unsigned char *ptr;
int i, ret;
TDB_DATA key, data;
struct ctdb_ltdb_header header;
outdata->dsize = 0;
outdata->dptr = NULL;
dbid = ((uint32_t *)(&indata.dptr[0]))[0];
ctdb_db = find_ctdb_db(ctdb, dbid);
@ -330,31 +336,41 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
return -1;
}
from_vnn = ((uint32_t *)(&indata.dptr[0]))[1];
num = ((uint32_t *)(&indata.dptr[0]))[1];
outdata->dsize = 0;
outdata->dptr = NULL;
ptr=&indata.dptr[8];
for(i=0;i<num;i++){
/* skip the lmaster*/
ptr+=4;
ret = ctdb_getkeys(ctdb, from_vnn, dbid, outdata, &keys);
if (ret != 0) {
DEBUG(0, (__location__ "Unable to pull keys from node %u\n", from_vnn));
return -1;
}
for(i=0;i<keys.num;i++){
ret = ctdb_ltdb_lock(ctdb_db, keys.keys[i]);
/* key */
key.dsize=*((uint32_t *)ptr);
ptr+=4;
key.dptr=ptr;
ptr+=(key.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
/* header */
memcpy(&header, ptr, sizeof(struct ctdb_ltdb_header));
ptr+=(sizeof(struct ctdb_ltdb_header)+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
/* data */
data.dsize=*((uint32_t *)ptr);
ptr+=4;
data.dptr=ptr;
ptr+=(data.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
ret = ctdb_ltdb_lock(ctdb_db, key);
if (ret != 0) {
DEBUG(0, (__location__ "Unable to lock db\n"));
ctdb_ltdb_unlock(ctdb_db, keys.keys[i]);
return -1;
}
ret = ctdb_ltdb_store(ctdb_db, keys.keys[i], &keys.headers[i], keys.data[i]);
ret = ctdb_ltdb_store(ctdb_db, key, &header, data);
if (ret != 0) {
DEBUG(0, (__location__ "Unable to store record\n"));
ctdb_ltdb_unlock(ctdb_db, keys.keys[i]);
ctdb_ltdb_unlock(ctdb_db, key);
return -1;
}
ctdb_ltdb_unlock(ctdb_db, keys.keys[i]);
ctdb_ltdb_unlock(ctdb_db, key);
}
return 0;

View File

@ -213,11 +213,11 @@ struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
struct ctdb_status;
int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status);
int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status);
struct ctdb_vnn_map;
int ctdb_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
int ctdb_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
/* table that contains a list of all dbids on a node
*/
@ -225,7 +225,7 @@ struct ctdb_dbid_map {
uint32_t num;
uint32_t *dbids;
};
int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap);
int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap);
/* table that contains a list of all nodes a ctdb knows about and their
@ -239,43 +239,40 @@ struct ctdb_node_map {
uint32_t num;
struct ctdb_node_and_flags *nodes;
};
int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap);
struct ctdb_key_list {
uint32_t dbid;
uint32_t num;
TDB_DATA *keys;
struct ctdb_ltdb_header *headers;
uint32_t *lmasters;
TDB_DATA *data;
};
int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys);
int ctdb_ctrl_pulldb(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys);
int ctdb_ctrl_copydb(struct ctdb_context *ctdb, uint32_t sourcenode, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx);
int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode);
int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
int ctdb_get_config(struct ctdb_context *ctdb);
int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
/*
change dmaster for all keys in the database to the new value
*/
int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
/*
delete all records from a tdb
*/
int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid);
/*
pull a db from a remote node
*/
int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t from_vnn);
int ctdb_ctrl_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid);
#define CTDB_RECOVERY_NORMAL 0
@ -283,11 +280,11 @@ int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ct
/*
get the recovery mode of a remote node
*/
int ctdb_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode);
int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode);
/*
set the recovery mode of a remote node
*/
int ctdb_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode);
int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode);
uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
uint32_t *num_nodes);

View File

@ -253,10 +253,10 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
CTDB_CONTROL_SET_DEBUG,
CTDB_CONTROL_GET_DBMAP,
CTDB_CONTROL_GET_NODEMAP,
CTDB_CONTROL_GET_KEYS,
CTDB_CONTROL_SET_DMASTER,
CTDB_CONTROL_CLEAR_DB,
CTDB_CONTROL_PULL_DB,
CTDB_CONTROL_PUSH_DB,
CTDB_CONTROL_GET_RECMODE,
CTDB_CONTROL_SET_RECMODE,
CTDB_CONTROL_STATUS_RESET};

View File

@ -138,7 +138,7 @@ int main(int argc, const char *argv[])
ctdb_connect_wait(ctdb);
/* find the full path to the database file */
ctdb_getdbpath(ctdb, ctdb_db->db_id, ctdb_db, &path);
ctdb_ctrl_getdbpath(ctdb, ctdb_db->db_id, ctdb_db, &path);
printf("path to database:[%s]\n",path);
ZERO_STRUCT(call);

View File

@ -43,10 +43,10 @@ static void usage(void)
printf(" setvnnmap <vnn> <generation> <numslots> <lmaster>*\n");
printf(" getdbmap <vnn> lists databases on a node\n");
printf(" getnodemap <vnn> lists nodes known to a ctdb daemon\n");
printf(" getkeys <vnn> <dbid> lists all keys in a remote tdb\n");
printf(" catdb <vnn> <dbid> lists all keys in a remote tdb\n");
printf(" cpdb <fromvnn> <tovnn> <dbid> lists all keys in a remote tdb\n");
printf(" setdmaster <vnn> <dbid> <dmaster> sets new dmaster for all records in the database\n");
printf(" cleardb <vnn> <dbid> deletes all records in a db\n");
printf(" pulldb <vnn> <dbid> <from vnn> pull a db from a remote node\n");
printf(" getrecmode <vnn> get recovery mode\n");
printf(" setrecmode <vnn> <mode> set recovery mode\n");
exit(1);
@ -68,7 +68,7 @@ static int control_process_exists(struct ctdb_context *ctdb, int argc, const cha
return -1;
}
ret = ctdb_process_exists(ctdb, vnn, pid);
ret = ctdb_ctrl_process_exists(ctdb, vnn, pid);
if (ret == 0) {
printf("%u:%u exists\n", vnn, pid);
} else {
@ -131,7 +131,7 @@ static int control_status_all(struct ctdb_context *ctdb)
uint32_t *v2 = (uint32_t *)&status;
uint32_t num_ints =
offsetof(struct ctdb_status, __last_counter) / sizeof(uint32_t);
ret = ctdb_status(ctdb, nodes[i], &s1);
ret = ctdb_ctrl_status(ctdb, nodes[i], &s1);
if (ret != 0) {
printf("Unable to get status from node %u\n", nodes[i]);
return ret;
@ -168,7 +168,7 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
vnn = strtoul(argv[0], NULL, 0);
ret = ctdb_status(ctdb, vnn, &status);
ret = ctdb_ctrl_status(ctdb, vnn, &status);
if (ret != 0) {
printf("Unable to get status from node %u\n", vnn);
return ret;
@ -242,7 +242,7 @@ static int control_getvnnmap(struct ctdb_context *ctdb, int argc, const char **a
vnn = strtoul(argv[0], NULL, 0);
vnnmap = talloc_zero(ctdb, struct ctdb_vnn_map);
ret = ctdb_getvnnmap(ctdb, vnn, vnnmap);
ret = ctdb_ctrl_getvnnmap(ctdb, vnn, vnnmap);
if (ret != 0) {
printf("Unable to get vnnmap from node %u\n", vnn);
return ret;
@ -270,7 +270,7 @@ static int control_getrecmode(struct ctdb_context *ctdb, int argc, const char **
vnn = strtoul(argv[0], NULL, 0);
ret = ctdb_getrecmode(ctdb, vnn, &recmode);
ret = ctdb_ctrl_getrecmode(ctdb, vnn, &recmode);
if (ret != 0) {
printf("Unable to get recmode from node %u\n", vnn);
return ret;
@ -296,7 +296,7 @@ static int control_setrecmode(struct ctdb_context *ctdb, int argc, const char **
vnn = strtoul(argv[0], NULL, 0);
recmode = strtoul(argv[0], NULL, 0);
ret = ctdb_setrecmode(ctdb, vnn, recmode);
ret = ctdb_ctrl_setrecmode(ctdb, vnn, recmode);
if (ret != 0) {
printf("Unable to set recmode on node %u\n", vnn);
return ret;
@ -308,7 +308,7 @@ static int control_setrecmode(struct ctdb_context *ctdb, int argc, const char **
/*
display remote list of keys for a tdb
*/
static int control_getkeys(struct ctdb_context *ctdb, int argc, const char **argv)
static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn, dbid;
int i, j, ret;
@ -323,12 +323,12 @@ static int control_getkeys(struct ctdb_context *ctdb, int argc, const char **arg
dbid = strtoul(argv[1], NULL, 0);
mem_ctx = talloc_new(ctdb);
ret = ctdb_getkeys(ctdb, vnn, dbid, mem_ctx, &keys);
ret = ctdb_ctrl_pulldb(ctdb, vnn, dbid, mem_ctx, &keys);
if (ret != 0) {
printf("Unable to get keys from node %u\n", vnn);
return ret;
}
printf("Number of keys:%d\n",keys.num);
printf("Number of keys:%d in dbid:0x%08x\n",keys.num,keys.dbid);
for(i=0;i<keys.num;i++){
printf("key:");
for(j=0;j<keys.keys[i].dsize;j++){
@ -346,6 +346,34 @@ static int control_getkeys(struct ctdb_context *ctdb, int argc, const char **arg
return 0;
}
/*
copy a db from one node to another
*/
static int control_cpdb(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t fromvnn, tovnn, dbid;
int ret;
TALLOC_CTX *mem_ctx;
if (argc < 3) {
usage();
}
fromvnn = strtoul(argv[0], NULL, 0);
tovnn = strtoul(argv[1], NULL, 0);
dbid = strtoul(argv[2], NULL, 0);
mem_ctx = talloc_new(ctdb);
ret = ctdb_ctrl_copydb(ctdb, fromvnn, tovnn, dbid, mem_ctx);
if (ret != 0) {
printf("Unable to copy db from node %u to node %u\n", fromvnn, tovnn);
return ret;
}
talloc_free(mem_ctx);
return 0;
}
/*
display a list of the databases on a remote ctdb
*/
@ -362,7 +390,7 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar
vnn = strtoul(argv[0], NULL, 0);
dbmap = talloc_zero(ctdb, struct ctdb_dbid_map);
ret = ctdb_getdbmap(ctdb, vnn, dbmap);
ret = ctdb_ctrl_getdbmap(ctdb, vnn, dbmap);
if (ret != 0) {
printf("Unable to get dbids from node %u\n", vnn);
talloc_free(dbmap);
@ -373,7 +401,7 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar
for(i=0;i<dbmap->num;i++){
const char *path;
ctdb_getdbpath(ctdb, dbmap->dbids[i], dbmap, &path);
ctdb_ctrl_getdbpath(ctdb, dbmap->dbids[i], dbmap, &path);
printf("dbid:0x%08x path:%s\n", dbmap->dbids[i], path);
}
talloc_free(dbmap);
@ -396,7 +424,7 @@ static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char **
vnn = strtoul(argv[0], NULL, 0);
nodemap = talloc_zero(ctdb, struct ctdb_node_map);
ret = ctdb_getnodemap(ctdb, vnn, nodemap, nodemap);
ret = ctdb_ctrl_getnodemap(ctdb, vnn, nodemap, nodemap);
if (ret != 0) {
printf("Unable to get nodemap from node %u\n", vnn);
talloc_free(nodemap);
@ -436,7 +464,7 @@ static int control_setvnnmap(struct ctdb_context *ctdb, int argc, const char **a
vnnmap->map[i] = strtoul(argv[3+i], NULL, 0);
}
ret = ctdb_setvnnmap(ctdb, vnn, vnnmap);
ret = ctdb_ctrl_setvnnmap(ctdb, vnn, vnnmap);
if (ret != 0) {
printf("Unable to set vnnmap for node %u\n", vnn);
return ret;
@ -460,7 +488,7 @@ static int control_setdmaster(struct ctdb_context *ctdb, int argc, const char **
dbid = strtoul(argv[1], NULL, 0);
dmaster = strtoul(argv[2], NULL, 0);
ret = ctdb_setdmaster(ctdb, vnn, ctdb, dbid, dmaster);
ret = ctdb_ctrl_setdmaster(ctdb, vnn, ctdb, dbid, dmaster);
if (ret != 0) {
printf("Unable to set dmaster for node %u db:0x%08x\n", vnn, dbid);
return ret;
@ -483,7 +511,7 @@ static int control_cleardb(struct ctdb_context *ctdb, int argc, const char **arg
vnn = strtoul(argv[0], NULL, 0);
dbid = strtoul(argv[1], NULL, 0);
ret = ctdb_cleardb(ctdb, vnn, ctdb, dbid);
ret = ctdb_ctrl_cleardb(ctdb, vnn, ctdb, dbid);
if (ret != 0) {
printf("Unable to clear db for node %u db:0x%08x\n", vnn, dbid);
return ret;
@ -491,30 +519,6 @@ static int control_cleardb(struct ctdb_context *ctdb, int argc, const char **arg
return 0;
}
/*
pull all records from a remote database to the local node
*/
static int control_pulldb(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn, dbid, fromvnn;
int ret;
if (argc < 3) {
usage();
}
vnn = strtoul(argv[0], NULL, 0);
dbid = strtoul(argv[1], NULL, 0);
fromvnn = strtoul(argv[2], NULL, 0);
ret = ctdb_pulldb(ctdb, vnn, ctdb, dbid, fromvnn);
if (ret != 0) {
printf("Unable to pull db for node %u db:0x%08x\n", vnn, dbid);
return ret;
}
return 0;
}
/*
ping all node
*/
@ -529,7 +533,7 @@ static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
for (i=0;i<num_nodes;i++) {
struct timeval tv = timeval_current();
ret = ctdb_ping(ctdb, nodes[i]);
ret = ctdb_ctrl_ping(ctdb, nodes[i]);
if (ret == -1) {
printf("Unable to get ping response from node %u\n", nodes[i]);
} else {
@ -556,7 +560,7 @@ static int control_debuglevel(struct ctdb_context *ctdb, int argc, const char **
for (i=0;i<num_nodes;i++) {
uint32_t level;
ret = ctdb_get_debuglevel(ctdb, nodes[i], &level);
ret = ctdb_ctrl_get_debuglevel(ctdb, nodes[i], &level);
if (ret != 0) {
printf("Unable to get debuglevel response from node %u\n",
nodes[i]);
@ -586,7 +590,7 @@ static int control_debug(struct ctdb_context *ctdb, int argc, const char **argv)
if (strcmp(argv[0], "all") != 0) {
vnn = strtoul(argv[0], NULL, 0);
ret = ctdb_set_debuglevel(ctdb, vnn, level);
ret = ctdb_ctrl_set_debuglevel(ctdb, vnn, level);
if (ret != 0) {
printf("Unable to set debug level on node %u\n", vnn);
}
@ -597,7 +601,7 @@ static int control_debug(struct ctdb_context *ctdb, int argc, const char **argv)
nodes = ctdb_get_connected_nodes(ctdb, ctdb, &num_nodes);
CTDB_NO_MEMORY(ctdb, nodes);
for (i=0;i<num_nodes;i++) {
ret = ctdb_set_debuglevel(ctdb, nodes[i], level);
ret = ctdb_ctrl_set_debuglevel(ctdb, nodes[i], level);
if (ret != 0) {
printf("Unable to set debug level on node %u\n", nodes[i]);
break;
@ -671,16 +675,16 @@ int main(int argc, const char *argv[])
ret = control_getdbmap(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "getnodemap") == 0) {
ret = control_getnodemap(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "getkeys") == 0) {
ret = control_getkeys(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "catdb") == 0) {
ret = control_catdb(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "cpdb") == 0) {
ret = control_cpdb(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "setvnnmap") == 0) {
ret = control_setvnnmap(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "setdmaster") == 0) {
ret = control_setdmaster(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "cleardb") == 0) {
ret = control_cleardb(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "pulldb") == 0) {
ret = control_pulldb(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "getrecmode") == 0) {
ret = control_getrecmode(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "setrecmode") == 0) {