1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

ctdb-tools: Allow attach for replicated databases

... and update the output from various database query commands.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-03-02 17:36:59 +11:00 committed by Martin Schwenke
parent 006c1b6811
commit d74eb9577d
6 changed files with 70 additions and 37 deletions

View File

@ -1363,14 +1363,22 @@ DB Statistics: locking.tdb
<refsect2>
<title>getdbmap</title>
<para>
This command lists all clustered TDB databases that the CTDB daemon has attached to. Some databases are flagged as PERSISTENT, this means that the database stores data persistently and the data will remain across reboots. One example of such a database is secrets.tdb where information about how the cluster was joined to the domain is stored.
This command lists all clustered TDB databases that the CTDB
daemon has attached to. Some databases are flagged as PERSISTENT,
this means that the database stores data persistently and the
data will remain across reboots. One example of such a database
is secrets.tdb where information about how the cluster was joined
to the domain is stored. Some database are flagged as REPLICATED,
this means that the data in that database is replicated across all
the nodes. But the data will not remain across reboots. This
type of database is used by CTDB to store it's internal state.
</para>
<para>
If a PERSISTENT database is not in a healthy state the database is
flagged as UNHEALTHY. If there's at least one completely healthy node running in
the cluster, it's possible that the content is restored by a recovery
run automaticly. Otherwise an administrator needs to analyze the
problem.
If a PERSISTENT database is not in a healthy state the database
is flagged as UNHEALTHY. If there's at least one completely
healthy node running in the cluster, it's possible that the
content is restored by a recovery run automaticly. Otherwise an
administrator needs to analyze the problem.
</para>
<para>
See also "ctdb getdbstatus", "ctdb backupdb", "ctdb restoredb",
@ -1378,7 +1386,10 @@ DB Statistics: locking.tdb
and (if samba or tdb-utils are installed) "tdbtool check".
</para>
<para>
Most databases are not persistent and only store the state information that the currently running samba daemons need. These databases are always wiped when ctdb/samba starts and when a node is rebooted.
Most databases are not persistent and only store the state
information that the currently running samba daemons need. These
databases are always wiped when ctdb/samba starts and when a
node is rebooted.
</para>
<refsect3>
@ -1755,7 +1766,7 @@ HEALTH: NO-HEALTHY-NODES - ERROR - Backup of corrupted TDB in '/usr/local/var/li
</refsect2>
<refsect2>
<title>attach <parameter>DBNAME</parameter> [persistent]</title>
<title>attach <parameter>DBNAME</parameter> [persistent|replicated]</title>
<para>
Create a new CTDB database called DBNAME and attach to it on
all nodes.

View File

@ -23,6 +23,7 @@ dbid: 0x7a19d84d
name: locking.tdb
path: /var/run/ctdb/DB_DIR/locking.tdb.0
PERSISTENT: no
REPLICATED: no
STICKY: no
READONLY: yes
HEALTH: OK
@ -34,6 +35,7 @@ dbid: 0x4e66c2b2
name: brlock.tdb
path: /var/run/ctdb/DB_DIR/brlock.tdb.0
PERSISTENT: no
REPLICATED: no
STICKY: yes
READONLY: no
HEALTH: OK
@ -45,6 +47,7 @@ dbid: 0x4d2a432b
name: g_lock.tdb
path: /var/run/ctdb/DB_DIR/g_lock.tdb.0
PERSISTENT: no
REPLICATED: no
STICKY: no
READONLY: no
HEALTH: OK
@ -56,6 +59,7 @@ dbid: 0x7132c184
name: secrets.tdb
path: /var/lib/ctdb/persistent/secrets.tdb.0
PERSISTENT: yes
REPLICATED: no
STICKY: no
READONLY: no
HEALTH: OK
@ -67,6 +71,7 @@ dbid: 0x6cf2837d
name: registry.tdb
path: /var/lib/ctdb/persistent/registry.tdb.0
PERSISTENT: yes
REPLICATED: no
STICKY: no
READONLY: no
HEALTH: OK

View File

@ -23,6 +23,7 @@ dbid: 0x7a19d84d
name: locking.tdb
path: /var/run/ctdb/DB_DIR/locking.tdb.1
PERSISTENT: no
REPLICATED: no
STICKY: no
READONLY: yes
HEALTH: OK
@ -34,6 +35,7 @@ dbid: 0x4e66c2b2
name: brlock.tdb
path: /var/run/ctdb/DB_DIR/brlock.tdb.1
PERSISTENT: no
REPLICATED: no
STICKY: yes
READONLY: no
HEALTH: OK
@ -45,6 +47,7 @@ dbid: 0x4d2a432b
name: g_lock.tdb
path: /var/run/ctdb/DB_DIR/g_lock.tdb.1
PERSISTENT: no
REPLICATED: no
STICKY: no
READONLY: no
HEALTH: OK
@ -56,6 +59,7 @@ dbid: 0x7132c184
name: secrets.tdb
path: /var/lib/ctdb/persistent/secrets.tdb.1
PERSISTENT: yes
REPLICATED: no
STICKY: no
READONLY: no
HEALTH: OK
@ -67,6 +71,7 @@ dbid: 0x6cf2837d
name: registry.tdb
path: /var/lib/ctdb/persistent/registry.tdb.1
PERSISTENT: yes
REPLICATED: no
STICKY: no
READONLY: no
HEALTH: OK

View File

@ -19,7 +19,7 @@ DBMAP
EOF
required_result 1 <<EOF
Cannot set READONLY on persistent DB
READONLY can be set only on volatile DB
EOF
simple_test secrets.tdb

View File

@ -19,7 +19,7 @@ DBMAP
EOF
required_result 1 <<EOF
Cannot set STICKY on persistent DB
STICKY can be set only on volatile DB
EOF
simple_test secrets.tdb

View File

@ -1902,7 +1902,7 @@ static int control_getdbmap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
}
if (options.machinereadable == 1) {
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
options.sep,
"ID", options.sep,
"Name", options.sep,
@ -1910,7 +1910,8 @@ static int control_getdbmap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
"Persistent", options.sep,
"Sticky", options.sep,
"Unhealthy", options.sep,
"Readonly", options.sep);
"Readonly", options.sep,
"Replicated", options.sep);
} else {
printf("Number of databases:%d\n", dbmap->num);
}
@ -1922,6 +1923,7 @@ static int control_getdbmap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
bool persistent;
bool readonly;
bool sticky;
bool replicated;
uint32_t db_id;
db_id = dbmap->dbs[i].db_id;
@ -1950,9 +1952,10 @@ static int control_getdbmap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
persistent = dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT;
readonly = dbmap->dbs[i].flags & CTDB_DB_FLAGS_READONLY;
sticky = dbmap->dbs[i].flags & CTDB_DB_FLAGS_STICKY;
replicated = dbmap->dbs[i].flags & CTDB_DB_FLAGS_REPLICATED;
if (options.machinereadable == 1) {
printf("%s0x%08X%s%s%s%s%s%d%s%d%s%d%s%d%s\n",
printf("%s0x%08X%s%s%s%s%s%d%s%d%s%d%s%d%s%d%s\n",
options.sep,
db_id, options.sep,
name, options.sep,
@ -1960,13 +1963,15 @@ static int control_getdbmap(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
!! (persistent), options.sep,
!! (sticky), options.sep,
!! (health), options.sep,
!! (readonly), options.sep);
!! (readonly), options.sep,
!! (replicated), options.sep);
} else {
printf("dbid:0x%08x name:%s path:%s%s%s%s%s\n",
printf("dbid:0x%08x name:%s path:%s%s%s%s%s%s\n",
db_id, name, path,
persistent ? " PERSISTENT" : "",
sticky ? " STICKY" : "",
readonly ? " READONLY" : "",
replicated ? " REPLICATED" : "",
health ? " UNHEALTHY" : "");
}
@ -2009,11 +2014,12 @@ static int control_getdbstatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
}
printf("dbid: 0x%08x\nname: %s\npath: %s\n", db_id, db_name, db_path);
printf("PERSISTENT: %s\nSTICKY: %s\nREADONLY: %s\nHEALTH: %s\n",
printf("PERSISTENT: %s\nREPLICATED: %s\nSTICKY: %s\nREADONLY: %s\n",
(db_flags & CTDB_DB_FLAGS_PERSISTENT ? "yes" : "no"),
(db_flags & CTDB_DB_FLAGS_REPLICATED ? "yes" : "no"),
(db_flags & CTDB_DB_FLAGS_STICKY ? "yes" : "no"),
(db_flags & CTDB_DB_FLAGS_READONLY ? "yes" : "no"),
(db_health ? db_health : "OK"));
(db_flags & CTDB_DB_FLAGS_READONLY ? "yes" : "no"));
printf("HEALTH: %s\n", (db_health ? db_health : "OK"));
return 0;
}
@ -2349,6 +2355,8 @@ static int control_attach(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
db_flags = CTDB_DB_FLAGS_READONLY;
} else if (strcmp(argv[1], "sticky") == 0) {
db_flags = CTDB_DB_FLAGS_STICKY;
} else if (strcmp(argv[1], "replicated") == 0) {
db_flags = CTDB_DB_FLAGS_REPLICATED;
} else {
usage("attach");
}
@ -2436,10 +2444,10 @@ static int control_detach(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
continue;
}
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
if (db_flags &
(CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED)) {
fprintf(stderr,
"Persistent database %s cannot be detached\n",
argv[0]);
"Only volatile databases can be detached\n");
return 1;
}
@ -4843,8 +4851,8 @@ static int control_setdbreadonly(TALLOC_CTX *mem_ctx,
return 1;
}
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
fprintf(stderr, "Cannot set READONLY on persistent DB\n");
if (db_flags & (CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED)) {
fprintf(stderr, "READONLY can be set only on volatile DB\n");
return 1;
}
@ -4872,8 +4880,8 @@ static int control_setdbsticky(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
fprintf(stderr, "Cannot set STICKY on persistent DB\n");
if (db_flags & (CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED)) {
fprintf(stderr, "STICKY can be set only on volatile DB\n");
return 1;
}
@ -4904,8 +4912,9 @@ static int control_pfetch(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (! (db_flags & CTDB_DB_FLAGS_PERSISTENT)) {
fprintf(stderr, "DB %s is not a persistent database\n",
if (! (db_flags &
(CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED))) {
fprintf(stderr, "Transactions not supported on DB %s\n",
db_name);
return 1;
}
@ -4963,8 +4972,9 @@ static int control_pstore(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (! (db_flags & CTDB_DB_FLAGS_PERSISTENT)) {
fprintf(stderr, "DB %s is not a persistent database\n",
if (! (db_flags &
(CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED))) {
fprintf(stderr, "Transactions not supported on DB %s\n",
db_name);
return 1;
}
@ -5033,8 +5043,9 @@ static int control_pdelete(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (! (db_flags & CTDB_DB_FLAGS_PERSISTENT)) {
fprintf(stderr, "DB %s is not a persistent database\n",
if (! (db_flags &
(CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED))) {
fprintf(stderr, "Transactions not supported on DB %s\n",
db_name);
return 1;
}
@ -5168,8 +5179,9 @@ static int control_ptrans(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (! (db_flags & CTDB_DB_FLAGS_PERSISTENT)) {
fprintf(stderr, "DB %s is not a persistent database\n",
if (! (db_flags &
(CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED))) {
fprintf(stderr, "Transactions not supported on DB %s\n",
db_name);
return 1;
}
@ -5391,7 +5403,7 @@ static int control_readkey(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
if (db_flags & (CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED)) {
fprintf(stderr, "DB %s is not a volatile database\n",
db_name);
return 1;
@ -5442,7 +5454,7 @@ static int control_writekey(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
if (db_flags & (CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED)) {
fprintf(stderr, "DB %s is not a volatile database\n",
db_name);
return 1;
@ -5502,7 +5514,7 @@ static int control_deletekey(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
if (db_flags & (CTDB_DB_FLAGS_PERSISTENT | CTDB_DB_FLAGS_REPLICATED)) {
fprintf(stderr, "DB %s is not a volatile database\n",
db_name);
return 1;
@ -6014,7 +6026,7 @@ static const struct ctdb_cmd {
{ "getdebug", control_getdebug, false, true,
"get debug level", NULL },
{ "attach", control_attach, false, false,
"attach a database", "<dbname> [persistent]" },
"attach a database", "<dbname> [persistent|replicated]" },
{ "detach", control_detach, false, false,
"detach database(s)", "<dbname|dbid> ..." },
{ "dumpmemory", control_dumpmemory, false, true,