2 Unix SMB/CIFS implementation.
3 Database interface wrapper around ctdbd
4 Copyright (C) Volker Lendecke 2007-2009
5 Copyright (C) Michael Adam 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/filesys.h"
23 #include "lib/tdb_wrap/tdb_wrap.h"
25 #include "dbwrap/dbwrap.h"
26 #include "dbwrap/dbwrap_ctdb.h"
27 #include "dbwrap/dbwrap_rbt.h"
28 #include "lib/param/param.h"
30 #ifdef CLUSTER_SUPPORT
33 * It is not possible to include ctdb.h and tdb_compat.h (included via
34 * some other include above) without warnings. This fixes those
42 #ifdef typesafe_cb_preargs
43 #undef typesafe_cb_preargs
46 #ifdef typesafe_cb_postargs
47 #undef typesafe_cb_postargs
51 #include "ctdb_private.h"
52 #include "ctdbd_conn.h"
53 #include "dbwrap/dbwrap.h"
54 #include "dbwrap/dbwrap_private.h"
55 #include "dbwrap/dbwrap_ctdb.h"
59 struct db_ctdb_transaction_handle
{
60 struct db_ctdb_ctx
*ctx
;
62 * we store the writes done under a transaction:
64 struct ctdb_marshall_buffer
*m_write
;
71 struct db_context
*db
;
72 struct tdb_wrap
*wtdb
;
74 struct db_ctdb_transaction_handle
*transaction
;
75 struct g_lock_ctx
*lock_ctx
;
79 struct db_ctdb_ctx
*ctdb_ctx
;
80 struct ctdb_ltdb_header header
;
81 struct timeval lock_time
;
84 static NTSTATUS
tdb_error_to_ntstatus(struct tdb_context
*tdb
)
86 enum TDB_ERROR tret
= tdb_error(tdb
);
88 return map_nt_error_from_tdb(tret
);
91 struct db_ctdb_ltdb_parse_state
{
92 void (*parser
)(TDB_DATA key
, struct ctdb_ltdb_header
*header
,
93 TDB_DATA data
, void *private_data
);
97 static int db_ctdb_ltdb_parser(TDB_DATA key
, TDB_DATA data
,
100 struct db_ctdb_ltdb_parse_state
*state
=
101 (struct db_ctdb_ltdb_parse_state
*)private_data
;
103 if (data
.dsize
< sizeof(struct ctdb_ltdb_header
)) {
107 key
, (struct ctdb_ltdb_header
*)data
.dptr
,
108 make_tdb_data(data
.dptr
+ sizeof(struct ctdb_ltdb_header
),
109 data
.dsize
- sizeof(struct ctdb_ltdb_header
)),
110 state
->private_data
);
114 static NTSTATUS
db_ctdb_ltdb_parse(
115 struct db_ctdb_ctx
*db
, TDB_DATA key
,
116 void (*parser
)(TDB_DATA key
, struct ctdb_ltdb_header
*header
,
117 TDB_DATA data
, void *private_data
),
120 struct db_ctdb_ltdb_parse_state state
;
123 state
.parser
= parser
;
124 state
.private_data
= private_data
;
126 ret
= tdb_parse_record(db
->wtdb
->tdb
, key
, db_ctdb_ltdb_parser
,
129 return NT_STATUS_NOT_FOUND
;
134 struct db_ctdb_ltdb_fetch_state
{
135 struct ctdb_ltdb_header
*header
;
141 static void db_ctdb_ltdb_fetch_parser(
142 TDB_DATA key
, struct ctdb_ltdb_header
*header
,
143 TDB_DATA data
, void *private_data
)
145 struct db_ctdb_ltdb_fetch_state
*state
=
146 (struct db_ctdb_ltdb_fetch_state
*)private_data
;
148 if (state
->header
!= NULL
) {
149 memcpy(state
->header
, header
, sizeof(struct ctdb_ltdb_header
));
151 if (state
->data
== NULL
) {
154 state
->data
->dsize
= data
.dsize
;
155 if (data
.dsize
== 0) {
156 state
->data
->dptr
= NULL
;
159 state
->data
->dptr
= talloc_memdup(state
->mem_ctx
, data
.dptr
,
161 if (state
->data
->dptr
== NULL
) {
168 * fetch a record from the tdb, separating out the header
169 * information and returning the body of the record.
171 static NTSTATUS
db_ctdb_ltdb_fetch(struct db_ctdb_ctx
*db
,
173 struct ctdb_ltdb_header
*header
,
177 struct db_ctdb_ltdb_fetch_state state
;
180 state
.header
= header
;
181 state
.mem_ctx
= mem_ctx
;
185 status
= db_ctdb_ltdb_parse(db
, key
, db_ctdb_ltdb_fetch_parser
,
187 if (!NT_STATUS_IS_OK(status
)) {
192 header
->dmaster
= (uint32_t)-1;
198 return NT_STATUS_NO_MEMORY
;
204 * Store a record together with the ctdb record header
205 * in the local copy of the database.
207 static NTSTATUS
db_ctdb_ltdb_store(struct db_ctdb_ctx
*db
,
209 struct ctdb_ltdb_header
*header
,
212 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
216 rec
.dsize
= data
.dsize
+ sizeof(struct ctdb_ltdb_header
);
217 rec
.dptr
= (uint8_t *)talloc_size(tmp_ctx
, rec
.dsize
);
219 if (rec
.dptr
== NULL
) {
220 talloc_free(tmp_ctx
);
221 return NT_STATUS_NO_MEMORY
;
224 memcpy(rec
.dptr
, header
, sizeof(struct ctdb_ltdb_header
));
225 memcpy(sizeof(struct ctdb_ltdb_header
) + (uint8_t *)rec
.dptr
, data
.dptr
, data
.dsize
);
227 ret
= tdb_store(db
->wtdb
->tdb
, key
, rec
, TDB_REPLACE
);
229 talloc_free(tmp_ctx
);
231 return (ret
== 0) ? NT_STATUS_OK
232 : tdb_error_to_ntstatus(db
->wtdb
->tdb
);
237 form a ctdb_rec_data record from a key/data pair
239 static struct ctdb_rec_data
*db_ctdb_marshall_record(TALLOC_CTX
*mem_ctx
, uint32_t reqid
,
241 struct ctdb_ltdb_header
*header
,
245 struct ctdb_rec_data
*d
;
247 length
= offsetof(struct ctdb_rec_data
, data
) + key
.dsize
+
248 data
.dsize
+ sizeof(*header
);
249 d
= (struct ctdb_rec_data
*)talloc_size(mem_ctx
, length
);
255 d
->keylen
= key
.dsize
;
256 memcpy(&d
->data
[0], key
.dptr
, key
.dsize
);
258 d
->datalen
= data
.dsize
+ sizeof(*header
);
259 memcpy(&d
->data
[key
.dsize
], header
, sizeof(*header
));
260 memcpy(&d
->data
[key
.dsize
+sizeof(*header
)], data
.dptr
, data
.dsize
);
265 /* helper function for marshalling multiple records */
266 static struct ctdb_marshall_buffer
*db_ctdb_marshall_add(TALLOC_CTX
*mem_ctx
,
267 struct ctdb_marshall_buffer
*m
,
271 struct ctdb_ltdb_header
*header
,
274 struct ctdb_rec_data
*r
;
275 size_t m_size
, r_size
;
276 struct ctdb_marshall_buffer
*m2
= NULL
;
278 r
= db_ctdb_marshall_record(talloc_tos(), reqid
, key
, header
, data
);
285 m
= (struct ctdb_marshall_buffer
*)talloc_zero_size(
286 mem_ctx
, offsetof(struct ctdb_marshall_buffer
, data
));
293 m_size
= talloc_get_size(m
);
294 r_size
= talloc_get_size(r
);
296 m2
= (struct ctdb_marshall_buffer
*)talloc_realloc_size(
297 mem_ctx
, m
, m_size
+ r_size
);
303 memcpy(m_size
+ (uint8_t *)m2
, r
, r_size
);
312 /* we've finished marshalling, return a data blob with the marshalled records */
313 static TDB_DATA
db_ctdb_marshall_finish(struct ctdb_marshall_buffer
*m
)
316 data
.dptr
= (uint8_t *)m
;
317 data
.dsize
= talloc_get_size(m
);
322 loop over a marshalling buffer
324 - pass r==NULL to start
325 - loop the number of times indicated by m->count
327 static struct ctdb_rec_data
*db_ctdb_marshall_loop_next(struct ctdb_marshall_buffer
*m
, struct ctdb_rec_data
*r
,
329 struct ctdb_ltdb_header
*header
,
330 TDB_DATA
*key
, TDB_DATA
*data
)
333 r
= (struct ctdb_rec_data
*)&m
->data
[0];
335 r
= (struct ctdb_rec_data
*)(r
->length
+ (uint8_t *)r
);
343 key
->dptr
= &r
->data
[0];
344 key
->dsize
= r
->keylen
;
347 data
->dptr
= &r
->data
[r
->keylen
];
348 data
->dsize
= r
->datalen
;
349 if (header
!= NULL
) {
350 data
->dptr
+= sizeof(*header
);
351 data
->dsize
-= sizeof(*header
);
355 if (header
!= NULL
) {
356 if (r
->datalen
< sizeof(*header
)) {
359 *header
= *(struct ctdb_ltdb_header
*)&r
->data
[r
->keylen
];
366 * CTDB transaction destructor
368 static int db_ctdb_transaction_destructor(struct db_ctdb_transaction_handle
*h
)
372 status
= g_lock_unlock(h
->ctx
->lock_ctx
, h
->lock_name
);
373 if (!NT_STATUS_IS_OK(status
)) {
374 DEBUG(0, ("g_lock_unlock failed for %s: %s\n", h
->lock_name
,
382 * CTDB dbwrap API: transaction_start function
383 * starts a transaction on a persistent database
385 static int db_ctdb_transaction_start(struct db_context
*db
)
387 struct db_ctdb_transaction_handle
*h
;
389 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
392 if (!db
->persistent
) {
393 DEBUG(0,("transactions not supported on non-persistent database 0x%08x\n",
398 if (ctx
->transaction
) {
399 ctx
->transaction
->nesting
++;
400 DEBUG(5, (__location__
" transaction start on db 0x%08x: nesting %d -> %d\n",
401 ctx
->db_id
, ctx
->transaction
->nesting
- 1, ctx
->transaction
->nesting
));
405 h
= talloc_zero(db
, struct db_ctdb_transaction_handle
);
407 DEBUG(0,(__location__
" oom for transaction handle\n"));
413 h
->lock_name
= talloc_asprintf(h
, "transaction_db_0x%08x",
414 (unsigned int)ctx
->db_id
);
415 if (h
->lock_name
== NULL
) {
416 DEBUG(0, ("talloc_asprintf failed\n"));
422 * Wait a day, i.e. forever...
424 status
= g_lock_lock(ctx
->lock_ctx
, h
->lock_name
, G_LOCK_WRITE
,
425 timeval_set(86400, 0));
426 if (!NT_STATUS_IS_OK(status
)) {
427 DEBUG(0, ("g_lock_lock failed: %s\n", nt_errstr(status
)));
432 talloc_set_destructor(h
, db_ctdb_transaction_destructor
);
434 ctx
->transaction
= h
;
436 DEBUG(5,(__location__
" transaction started on db 0x%08x\n", ctx
->db_id
));
441 static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer
*buf
,
443 struct ctdb_ltdb_header
*pheader
,
447 struct ctdb_rec_data
*rec
= NULL
;
448 struct ctdb_ltdb_header h
;
461 * Walk the list of records written during this
462 * transaction. If we want to read one we have already
463 * written, return the last written sample. Thus we do not do
464 * a "break;" for the first hit, this record might have been
468 for (i
=0; i
<buf
->count
; i
++) {
469 TDB_DATA tkey
, tdata
;
471 struct ctdb_ltdb_header hdr
;
475 rec
= db_ctdb_marshall_loop_next(buf
, rec
, &reqid
, &hdr
, &tkey
,
481 if (tdb_data_equal(key
, tkey
)) {
493 data
.dptr
= (uint8_t *)talloc_memdup(mem_ctx
, data
.dptr
,
495 if ((data
.dsize
!= 0) && (data
.dptr
== NULL
)) {
501 if (pheader
!= NULL
) {
509 fetch a record inside a transaction
511 static NTSTATUS
db_ctdb_transaction_fetch(struct db_ctdb_ctx
*db
,
513 TDB_DATA key
, TDB_DATA
*data
)
515 struct db_ctdb_transaction_handle
*h
= db
->transaction
;
519 found
= pull_newest_from_marshall_buffer(h
->m_write
, key
, NULL
,
525 status
= db_ctdb_ltdb_fetch(h
->ctx
, key
, NULL
, mem_ctx
, data
);
527 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
535 * Fetch a record from a persistent database
536 * without record locking and without an active transaction.
538 * This just fetches from the local database copy.
539 * Since the databases are kept in syc cluster-wide,
540 * there is no point in doing a ctdb call to fetch the
541 * record from the lmaster. It does even harm since migration
542 * of records bump their RSN and hence render the persistent
543 * database inconsistent.
545 static NTSTATUS
db_ctdb_fetch_persistent(struct db_ctdb_ctx
*db
,
547 TDB_DATA key
, TDB_DATA
*data
)
551 status
= db_ctdb_ltdb_fetch(db
, key
, NULL
, mem_ctx
, data
);
553 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
560 static NTSTATUS
db_ctdb_store_transaction(struct db_record
*rec
, TDB_DATA data
, int flag
);
561 static NTSTATUS
db_ctdb_delete_transaction(struct db_record
*rec
);
563 static struct db_record
*db_ctdb_fetch_locked_transaction(struct db_ctdb_ctx
*ctx
,
567 struct db_record
*result
;
570 if (!(result
= talloc(mem_ctx
, struct db_record
))) {
571 DEBUG(0, ("talloc failed\n"));
575 result
->private_data
= ctx
->transaction
;
577 result
->key
.dsize
= key
.dsize
;
578 result
->key
.dptr
= (uint8_t *)talloc_memdup(result
, key
.dptr
,
580 if (result
->key
.dptr
== NULL
) {
581 DEBUG(0, ("talloc failed\n"));
586 result
->store
= db_ctdb_store_transaction
;
587 result
->delete_rec
= db_ctdb_delete_transaction
;
589 if (pull_newest_from_marshall_buffer(ctx
->transaction
->m_write
, key
,
590 NULL
, result
, &result
->value
)) {
594 ctdb_data
= tdb_fetch_compat(ctx
->wtdb
->tdb
, key
);
595 if (ctdb_data
.dptr
== NULL
) {
596 /* create the record */
597 result
->value
= tdb_null
;
601 result
->value
.dsize
= ctdb_data
.dsize
- sizeof(struct ctdb_ltdb_header
);
602 result
->value
.dptr
= NULL
;
604 if ((result
->value
.dsize
!= 0)
605 && !(result
->value
.dptr
= (uint8_t *)talloc_memdup(
606 result
, ctdb_data
.dptr
+ sizeof(struct ctdb_ltdb_header
),
607 result
->value
.dsize
))) {
608 DEBUG(0, ("talloc failed\n"));
612 SAFE_FREE(ctdb_data
.dptr
);
617 static int db_ctdb_record_destructor(struct db_record
**recp
)
619 struct db_record
*rec
= talloc_get_type_abort(*recp
, struct db_record
);
620 struct db_ctdb_transaction_handle
*h
= talloc_get_type_abort(
621 rec
->private_data
, struct db_ctdb_transaction_handle
);
622 int ret
= h
->ctx
->db
->transaction_commit(h
->ctx
->db
);
624 DEBUG(0,(__location__
" transaction_commit failed\n"));
630 auto-create a transaction for persistent databases
632 static struct db_record
*db_ctdb_fetch_locked_persistent(struct db_ctdb_ctx
*ctx
,
637 struct db_record
*rec
, **recp
;
639 res
= db_ctdb_transaction_start(ctx
->db
);
644 rec
= db_ctdb_fetch_locked_transaction(ctx
, mem_ctx
, key
);
646 ctx
->db
->transaction_cancel(ctx
->db
);
650 /* destroy this transaction when we release the lock */
651 recp
= talloc(rec
, struct db_record
*);
653 ctx
->db
->transaction_cancel(ctx
->db
);
658 talloc_set_destructor(recp
, db_ctdb_record_destructor
);
664 stores a record inside a transaction
666 static NTSTATUS
db_ctdb_transaction_store(struct db_ctdb_transaction_handle
*h
,
667 TDB_DATA key
, TDB_DATA data
)
669 TALLOC_CTX
*tmp_ctx
= talloc_new(h
);
671 struct ctdb_ltdb_header header
;
675 /* we need the header so we can update the RSN */
677 if (!pull_newest_from_marshall_buffer(h
->m_write
, key
, &header
,
680 rec
= tdb_fetch_compat(h
->ctx
->wtdb
->tdb
, key
);
682 if (rec
.dptr
!= NULL
) {
683 memcpy(&header
, rec
.dptr
,
684 sizeof(struct ctdb_ltdb_header
));
685 rec
.dsize
-= sizeof(struct ctdb_ltdb_header
);
688 * a special case, we are writing the same
689 * data that is there now
691 if (data
.dsize
== rec
.dsize
&&
693 rec
.dptr
+ sizeof(struct ctdb_ltdb_header
),
696 talloc_free(tmp_ctx
);
703 header
.dmaster
= get_my_vnn();
706 h
->m_write
= db_ctdb_marshall_add(h
, h
->m_write
, h
->ctx
->db_id
, 0, key
, &header
, data
);
707 if (h
->m_write
== NULL
) {
708 DEBUG(0,(__location__
" Failed to add to marshalling record\n"));
709 talloc_free(tmp_ctx
);
710 return NT_STATUS_NO_MEMORY
;
713 talloc_free(tmp_ctx
);
719 a record store inside a transaction
721 static NTSTATUS
db_ctdb_store_transaction(struct db_record
*rec
, TDB_DATA data
, int flag
)
723 struct db_ctdb_transaction_handle
*h
= talloc_get_type_abort(
724 rec
->private_data
, struct db_ctdb_transaction_handle
);
727 status
= db_ctdb_transaction_store(h
, rec
->key
, data
);
732 a record delete inside a transaction
734 static NTSTATUS
db_ctdb_delete_transaction(struct db_record
*rec
)
736 struct db_ctdb_transaction_handle
*h
= talloc_get_type_abort(
737 rec
->private_data
, struct db_ctdb_transaction_handle
);
740 status
= db_ctdb_transaction_store(h
, rec
->key
, tdb_null
);
745 * Fetch the db sequence number of a persistent db directly from the db.
747 static NTSTATUS
db_ctdb_fetch_db_seqnum_from_db(struct db_ctdb_ctx
*db
,
751 const char *keyname
= CTDB_DB_SEQNUM_KEY
;
754 struct ctdb_ltdb_header header
;
755 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
757 if (seqnum
== NULL
) {
758 return NT_STATUS_INVALID_PARAMETER
;
761 key
= string_term_tdb_data(keyname
);
763 status
= db_ctdb_ltdb_fetch(db
, key
, &header
, mem_ctx
, &data
);
764 if (!NT_STATUS_IS_OK(status
) &&
765 !NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
))
770 status
= NT_STATUS_OK
;
772 if (data
.dsize
!= sizeof(uint64_t)) {
777 *seqnum
= *(uint64_t *)data
.dptr
;
780 TALLOC_FREE(mem_ctx
);
785 * Store the database sequence number inside a transaction.
787 static NTSTATUS
db_ctdb_store_db_seqnum(struct db_ctdb_transaction_handle
*h
,
791 const char *keyname
= CTDB_DB_SEQNUM_KEY
;
795 key
= string_term_tdb_data(keyname
);
797 data
.dptr
= (uint8_t *)&seqnum
;
798 data
.dsize
= sizeof(uint64_t);
800 status
= db_ctdb_transaction_store(h
, key
, data
);
808 static int db_ctdb_transaction_commit(struct db_context
*db
)
810 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
814 struct db_ctdb_transaction_handle
*h
= ctx
->transaction
;
815 uint64_t old_seqnum
, new_seqnum
;
819 DEBUG(0,(__location__
" transaction commit with no open transaction on db 0x%08x\n", ctx
->db_id
));
823 if (h
->nested_cancel
) {
824 db
->transaction_cancel(db
);
825 DEBUG(5,(__location__
" Failed transaction commit after nested cancel\n"));
829 if (h
->nesting
!= 0) {
831 DEBUG(5, (__location__
" transaction commit on db 0x%08x: nesting %d -> %d\n",
832 ctx
->db_id
, ctx
->transaction
->nesting
+ 1, ctx
->transaction
->nesting
));
836 if (h
->m_write
== NULL
) {
838 * No changes were made, so don't change the seqnum,
839 * don't push to other node, just exit with success.
845 DEBUG(5,(__location__
" transaction commit on db 0x%08x\n", ctx
->db_id
));
848 * As the last db action before committing, bump the database sequence
849 * number. Note that this undoes all changes to the seqnum records
850 * performed under the transaction. This record is not meant to be
851 * modified by user interaction. It is for internal use only...
853 rets
= db_ctdb_fetch_db_seqnum_from_db(ctx
, &old_seqnum
);
854 if (!NT_STATUS_IS_OK(rets
)) {
855 DEBUG(1, (__location__
" failed to fetch the db sequence number "
856 "in transaction commit on db 0x%08x\n", ctx
->db_id
));
861 new_seqnum
= old_seqnum
+ 1;
863 rets
= db_ctdb_store_db_seqnum(h
, new_seqnum
);
864 if (!NT_STATUS_IS_OK(rets
)) {
865 DEBUG(1, (__location__
"failed to store the db sequence number "
866 " in transaction commit on db 0x%08x\n", ctx
->db_id
));
872 /* tell ctdbd to commit to the other nodes */
873 rets
= ctdbd_control_local(messaging_ctdbd_connection(),
874 CTDB_CONTROL_TRANS3_COMMIT
,
876 db_ctdb_marshall_finish(h
->m_write
),
877 NULL
, NULL
, &status
);
878 if (!NT_STATUS_IS_OK(rets
) || status
!= 0) {
880 * The TRANS3_COMMIT control should only possibly fail when a
881 * recovery has been running concurrently. In any case, the db
882 * will be the same on all nodes, either the new copy or the
883 * old copy. This can be detected by comparing the old and new
884 * local sequence numbers.
886 rets
= db_ctdb_fetch_db_seqnum_from_db(ctx
, &new_seqnum
);
887 if (!NT_STATUS_IS_OK(rets
)) {
888 DEBUG(1, (__location__
" failed to refetch db sequence "
889 "number after failed TRANS3_COMMIT\n"));
894 if (new_seqnum
== old_seqnum
) {
895 /* Recovery prevented all our changes: retry. */
898 if (new_seqnum
!= (old_seqnum
+ 1)) {
899 DEBUG(0, (__location__
" ERROR: new_seqnum[%lu] != "
900 "old_seqnum[%lu] + (0 or 1) after failed "
901 "TRANS3_COMMIT - this should not happen!\n",
902 (unsigned long)new_seqnum
,
903 (unsigned long)old_seqnum
));
908 * Recovery propagated our changes to all nodes, completing
909 * our commit for us - succeed.
916 h
->ctx
->transaction
= NULL
;
925 static int db_ctdb_transaction_cancel(struct db_context
*db
)
927 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
929 struct db_ctdb_transaction_handle
*h
= ctx
->transaction
;
932 DEBUG(0,(__location__
" transaction cancel with no open transaction on db 0x%08x\n", ctx
->db_id
));
936 if (h
->nesting
!= 0) {
938 h
->nested_cancel
= true;
939 DEBUG(5, (__location__
" transaction cancel on db 0x%08x: nesting %d -> %d\n",
940 ctx
->db_id
, ctx
->transaction
->nesting
+ 1, ctx
->transaction
->nesting
));
944 DEBUG(5,(__location__
" Cancel transaction on db 0x%08x\n", ctx
->db_id
));
946 ctx
->transaction
= NULL
;
952 static NTSTATUS
db_ctdb_store(struct db_record
*rec
, TDB_DATA data
, int flag
)
954 struct db_ctdb_rec
*crec
= talloc_get_type_abort(
955 rec
->private_data
, struct db_ctdb_rec
);
957 return db_ctdb_ltdb_store(crec
->ctdb_ctx
, rec
->key
, &(crec
->header
), data
);
962 #ifdef HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL
963 static NTSTATUS
db_ctdb_send_schedule_for_deletion(struct db_record
*rec
)
966 struct ctdb_control_schedule_for_deletion
*dd
;
969 struct db_ctdb_rec
*crec
= talloc_get_type_abort(
970 rec
->private_data
, struct db_ctdb_rec
);
972 indata
.dsize
= offsetof(struct ctdb_control_schedule_for_deletion
, key
) + rec
->key
.dsize
;
973 indata
.dptr
= talloc_zero_array(crec
, uint8_t, indata
.dsize
);
974 if (indata
.dptr
== NULL
) {
975 DEBUG(0, (__location__
" talloc failed!\n"));
976 return NT_STATUS_NO_MEMORY
;
979 dd
= (struct ctdb_control_schedule_for_deletion
*)(void *)indata
.dptr
;
980 dd
->db_id
= crec
->ctdb_ctx
->db_id
;
981 dd
->hdr
= crec
->header
;
982 dd
->keylen
= rec
->key
.dsize
;
983 memcpy(dd
->key
, rec
->key
.dptr
, rec
->key
.dsize
);
985 status
= ctdbd_control_local(messaging_ctdbd_connection(),
986 CTDB_CONTROL_SCHEDULE_FOR_DELETION
,
987 crec
->ctdb_ctx
->db_id
,
988 CTDB_CTRL_FLAG_NOREPLY
, /* flags */
993 talloc_free(indata
.dptr
);
995 if (!NT_STATUS_IS_OK(status
) || cstatus
!= 0) {
996 DEBUG(1, (__location__
" Error sending local control "
997 "SCHEDULE_FOR_DELETION: %s, cstatus = %d\n",
998 nt_errstr(status
), cstatus
));
999 if (NT_STATUS_IS_OK(status
)) {
1000 status
= NT_STATUS_UNSUCCESSFUL
;
1008 static NTSTATUS
db_ctdb_delete(struct db_record
*rec
)
1014 * We have to store the header with empty data. TODO: Fix the
1020 status
= db_ctdb_store(rec
, data
, 0);
1021 if (!NT_STATUS_IS_OK(status
)) {
1025 #ifdef HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL
1026 status
= db_ctdb_send_schedule_for_deletion(rec
);
1032 static int db_ctdb_record_destr(struct db_record
* data
)
1034 struct db_ctdb_rec
*crec
= talloc_get_type_abort(
1035 data
->private_data
, struct db_ctdb_rec
);
1038 DEBUG(10, (DEBUGLEVEL
> 10
1039 ? "Unlocking db %u key %s\n"
1040 : "Unlocking db %u key %.20s\n",
1041 (int)crec
->ctdb_ctx
->db_id
,
1042 hex_encode_talloc(data
, (unsigned char *)data
->key
.dptr
,
1045 tdb_chainunlock(crec
->ctdb_ctx
->wtdb
->tdb
, data
->key
);
1047 threshold
= lp_ctdb_locktime_warn_threshold();
1048 if (threshold
!= 0) {
1049 double timediff
= timeval_elapsed(&crec
->lock_time
);
1050 if ((timediff
* 1000) > threshold
) {
1053 key
= hex_encode_talloc(data
,
1054 (unsigned char *)data
->key
.dptr
,
1056 DEBUG(0, ("Held tdb lock on db %s, key %s %f seconds\n",
1057 tdb_name(crec
->ctdb_ctx
->wtdb
->tdb
), key
,
1066 * Check whether we have a valid local copy of the given record,
1067 * either for reading or for writing.
1069 static bool db_ctdb_can_use_local_copy(TDB_DATA ctdb_data
, bool read_only
)
1071 struct ctdb_ltdb_header
*hdr
;
1073 if (ctdb_data
.dptr
== NULL
)
1076 if (ctdb_data
.dsize
< sizeof(struct ctdb_ltdb_header
))
1079 hdr
= (struct ctdb_ltdb_header
*)ctdb_data
.dptr
;
1081 #ifdef HAVE_CTDB_WANT_READONLY_DECL
1082 if (hdr
->dmaster
!= get_my_vnn()) {
1083 /* If we're not dmaster, it must be r/o copy. */
1084 return read_only
&& (hdr
->flags
& CTDB_REC_RO_HAVE_READONLY
);
1088 * If we want write access, no one may have r/o copies.
1090 return read_only
|| !(hdr
->flags
& CTDB_REC_RO_HAVE_DELEGATIONS
);
1092 return (hdr
->dmaster
== get_my_vnn());
1096 static struct db_record
*fetch_locked_internal(struct db_ctdb_ctx
*ctx
,
1097 TALLOC_CTX
*mem_ctx
,
1101 struct db_record
*result
;
1102 struct db_ctdb_rec
*crec
;
1105 int migrate_attempts
= 0;
1108 if (!(result
= talloc(mem_ctx
, struct db_record
))) {
1109 DEBUG(0, ("talloc failed\n"));
1113 if (!(crec
= talloc_zero(result
, struct db_ctdb_rec
))) {
1114 DEBUG(0, ("talloc failed\n"));
1115 TALLOC_FREE(result
);
1119 result
->db
= ctx
->db
;
1120 result
->private_data
= (void *)crec
;
1121 crec
->ctdb_ctx
= ctx
;
1123 result
->key
.dsize
= key
.dsize
;
1124 result
->key
.dptr
= (uint8_t *)talloc_memdup(result
, key
.dptr
,
1126 if (result
->key
.dptr
== NULL
) {
1127 DEBUG(0, ("talloc failed\n"));
1128 TALLOC_FREE(result
);
1133 * Do a blocking lock on the record
1137 if (DEBUGLEVEL
>= 10) {
1138 char *keystr
= hex_encode_talloc(result
, key
.dptr
, key
.dsize
);
1139 DEBUG(10, (DEBUGLEVEL
> 10
1140 ? "Locking db %u key %s\n"
1141 : "Locking db %u key %.20s\n",
1142 (int)crec
->ctdb_ctx
->db_id
, keystr
));
1143 TALLOC_FREE(keystr
);
1147 ? tdb_chainlock_nonblock(ctx
->wtdb
->tdb
, key
)
1148 : tdb_chainlock(ctx
->wtdb
->tdb
, key
);
1150 DEBUG(3, ("tdb_chainlock failed\n"));
1151 TALLOC_FREE(result
);
1155 result
->store
= db_ctdb_store
;
1156 result
->delete_rec
= db_ctdb_delete
;
1157 talloc_set_destructor(result
, db_ctdb_record_destr
);
1159 ctdb_data
= tdb_fetch_compat(ctx
->wtdb
->tdb
, key
);
1162 * See if we have a valid record and we are the dmaster. If so, we can
1163 * take the shortcut and just return it.
1166 if (!db_ctdb_can_use_local_copy(ctdb_data
, false)) {
1167 SAFE_FREE(ctdb_data
.dptr
);
1168 tdb_chainunlock(ctx
->wtdb
->tdb
, key
);
1169 talloc_set_destructor(result
, NULL
);
1171 if (tryonly
&& (migrate_attempts
!= 0)) {
1172 DEBUG(5, ("record migrated away again\n"));
1173 TALLOC_FREE(result
);
1177 migrate_attempts
+= 1;
1179 DEBUG(10, ("ctdb_data.dptr = %p, dmaster = %u (%u) %u\n",
1180 ctdb_data
.dptr
, ctdb_data
.dptr
?
1181 ((struct ctdb_ltdb_header
*)ctdb_data
.dptr
)->dmaster
: -1,
1184 ((struct ctdb_ltdb_header
*)ctdb_data
.dptr
)->flags
: 0));
1186 status
= ctdbd_migrate(messaging_ctdbd_connection(), ctx
->db_id
,
1188 if (!NT_STATUS_IS_OK(status
)) {
1189 DEBUG(5, ("ctdb_migrate failed: %s\n",
1190 nt_errstr(status
)));
1191 TALLOC_FREE(result
);
1194 /* now its migrated, try again */
1198 if (migrate_attempts
> 10) {
1199 DEBUG(0, ("db_ctdb_fetch_locked for %s key %s needed %d "
1200 "attempts\n", tdb_name(ctx
->wtdb
->tdb
),
1201 hex_encode_talloc(talloc_tos(),
1202 (unsigned char *)key
.dptr
,
1207 GetTimeOfDay(&crec
->lock_time
);
1209 memcpy(&crec
->header
, ctdb_data
.dptr
, sizeof(crec
->header
));
1211 result
->value
.dsize
= ctdb_data
.dsize
- sizeof(crec
->header
);
1212 result
->value
.dptr
= NULL
;
1214 if ((result
->value
.dsize
!= 0)
1215 && !(result
->value
.dptr
= (uint8_t *)talloc_memdup(
1216 result
, ctdb_data
.dptr
+ sizeof(crec
->header
),
1217 result
->value
.dsize
))) {
1218 DEBUG(0, ("talloc failed\n"));
1219 TALLOC_FREE(result
);
1222 SAFE_FREE(ctdb_data
.dptr
);
1227 static struct db_record
*db_ctdb_fetch_locked(struct db_context
*db
,
1228 TALLOC_CTX
*mem_ctx
,
1231 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
1232 struct db_ctdb_ctx
);
1234 if (ctx
->transaction
!= NULL
) {
1235 return db_ctdb_fetch_locked_transaction(ctx
, mem_ctx
, key
);
1238 if (db
->persistent
) {
1239 return db_ctdb_fetch_locked_persistent(ctx
, mem_ctx
, key
);
1242 return fetch_locked_internal(ctx
, mem_ctx
, key
, false);
1245 static struct db_record
*db_ctdb_try_fetch_locked(struct db_context
*db
,
1246 TALLOC_CTX
*mem_ctx
,
1249 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
1250 struct db_ctdb_ctx
);
1252 if (ctx
->transaction
!= NULL
) {
1253 return db_ctdb_fetch_locked_transaction(ctx
, mem_ctx
, key
);
1256 if (db
->persistent
) {
1257 return db_ctdb_fetch_locked_persistent(ctx
, mem_ctx
, key
);
1260 return fetch_locked_internal(ctx
, mem_ctx
, key
, true);
1264 fetch (unlocked, no migration) operation on ctdb
1266 static NTSTATUS
db_ctdb_fetch(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
1267 TDB_DATA key
, TDB_DATA
*data
)
1269 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
1270 struct db_ctdb_ctx
);
1274 if (ctx
->transaction
) {
1275 return db_ctdb_transaction_fetch(ctx
, mem_ctx
, key
, data
);
1278 if (db
->persistent
) {
1279 return db_ctdb_fetch_persistent(ctx
, mem_ctx
, key
, data
);
1282 /* try a direct fetch */
1283 ctdb_data
= tdb_fetch_compat(ctx
->wtdb
->tdb
, key
);
1286 * See if we have a valid record and we are the dmaster. If so, we can
1287 * take the shortcut and just return it.
1288 * we bypass the dmaster check for persistent databases
1290 if (db_ctdb_can_use_local_copy(ctdb_data
, true)) {
1292 * We have a valid local copy - avoid the ctdb protocol op
1294 data
->dsize
= ctdb_data
.dsize
- sizeof(struct ctdb_ltdb_header
);
1296 data
->dptr
= (uint8_t *)talloc_memdup(
1297 mem_ctx
, ctdb_data
.dptr
+sizeof(struct ctdb_ltdb_header
),
1300 SAFE_FREE(ctdb_data
.dptr
);
1302 if (data
->dptr
== NULL
) {
1303 return NT_STATUS_NO_MEMORY
;
1305 return NT_STATUS_OK
;
1308 SAFE_FREE(ctdb_data
.dptr
);
1311 * We weren't able to get it locally - ask ctdb to fetch it for us.
1312 * If we already had *something*, it's probably worth making a local
1315 status
= ctdbd_fetch(messaging_ctdbd_connection(), ctx
->db_id
, key
,
1317 ctdb_data
.dsize
>= sizeof(struct ctdb_ltdb_header
));
1318 if (!NT_STATUS_IS_OK(status
)) {
1319 DEBUG(5, ("ctdbd_fetch failed: %s\n", nt_errstr(status
)));
1325 static NTSTATUS
db_ctdb_parse_record(struct db_context
*db
, TDB_DATA key
,
1326 void (*parser
)(TDB_DATA key
,
1328 void *private_data
),
1334 status
= db_ctdb_fetch(db
, talloc_tos(), key
, &data
);
1335 if (!NT_STATUS_IS_OK(status
)) {
1338 parser(key
, data
, private_data
);
1339 TALLOC_FREE(data
.dptr
);
1340 return NT_STATUS_OK
;
1343 struct traverse_state
{
1344 struct db_context
*db
;
1345 int (*fn
)(struct db_record
*rec
, void *private_data
);
1350 static void traverse_callback(TDB_DATA key
, TDB_DATA data
, void *private_data
)
1352 struct traverse_state
*state
= (struct traverse_state
*)private_data
;
1353 struct db_record
*rec
;
1354 TALLOC_CTX
*tmp_ctx
= talloc_new(state
->db
);
1355 /* we have to give them a locked record to prevent races */
1356 rec
= db_ctdb_fetch_locked(state
->db
, tmp_ctx
, key
);
1357 if (rec
&& rec
->value
.dsize
> 0) {
1358 state
->fn(rec
, state
->private_data
);
1360 talloc_free(tmp_ctx
);
1363 static int traverse_persistent_callback(TDB_CONTEXT
*tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
,
1366 struct traverse_state
*state
= (struct traverse_state
*)private_data
;
1367 struct db_record
*rec
;
1368 TALLOC_CTX
*tmp_ctx
= talloc_new(state
->db
);
1372 * Skip the __db_sequence_number__ key:
1373 * This is used for persistent transactions internally.
1375 if (kbuf
.dsize
== strlen(CTDB_DB_SEQNUM_KEY
) + 1 &&
1376 strcmp((const char*)kbuf
.dptr
, CTDB_DB_SEQNUM_KEY
) == 0)
1381 /* we have to give them a locked record to prevent races */
1382 rec
= db_ctdb_fetch_locked(state
->db
, tmp_ctx
, kbuf
);
1383 if (rec
&& rec
->value
.dsize
> 0) {
1384 ret
= state
->fn(rec
, state
->private_data
);
1388 talloc_free(tmp_ctx
);
1392 /* wrapper to use traverse_persistent_callback with dbwrap */
1393 static int traverse_persistent_callback_dbwrap(struct db_record
*rec
, void* data
)
1395 return traverse_persistent_callback(NULL
, rec
->key
, rec
->value
, data
);
1399 static int db_ctdb_traverse(struct db_context
*db
,
1400 int (*fn
)(struct db_record
*rec
,
1401 void *private_data
),
1405 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
1406 struct db_ctdb_ctx
);
1407 struct traverse_state state
;
1411 state
.private_data
= private_data
;
1414 if (db
->persistent
) {
1415 struct tdb_context
*ltdb
= ctx
->wtdb
->tdb
;
1418 /* for persistent databases we don't need to do a ctdb traverse,
1419 we can do a faster local traverse */
1420 ret
= tdb_traverse(ltdb
, traverse_persistent_callback
, &state
);
1424 if (ctx
->transaction
&& ctx
->transaction
->m_write
) {
1426 * we now have to handle keys not yet
1427 * present at transaction start
1429 struct db_context
*newkeys
= db_open_rbt(talloc_tos());
1430 struct ctdb_marshall_buffer
*mbuf
= ctx
->transaction
->m_write
;
1431 struct ctdb_rec_data
*rec
=NULL
;
1435 if (newkeys
== NULL
) {
1439 for (i
=0; i
<mbuf
->count
; i
++) {
1441 rec
=db_ctdb_marshall_loop_next(mbuf
, rec
,
1444 SMB_ASSERT(rec
!= NULL
);
1446 if (!tdb_exists(ltdb
, key
)) {
1447 dbwrap_store(newkeys
, key
, tdb_null
, 0);
1450 status
= dbwrap_traverse(newkeys
,
1451 traverse_persistent_callback_dbwrap
,
1454 talloc_free(newkeys
);
1455 if (!NT_STATUS_IS_OK(status
)) {
1463 status
= ctdbd_traverse(ctx
->db_id
, traverse_callback
, &state
);
1464 if (!NT_STATUS_IS_OK(status
)) {
1470 static NTSTATUS
db_ctdb_store_deny(struct db_record
*rec
, TDB_DATA data
, int flag
)
1472 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1475 static NTSTATUS
db_ctdb_delete_deny(struct db_record
*rec
)
1477 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1480 static void traverse_read_callback(TDB_DATA key
, TDB_DATA data
, void *private_data
)
1482 struct traverse_state
*state
= (struct traverse_state
*)private_data
;
1483 struct db_record rec
;
1486 rec
.store
= db_ctdb_store_deny
;
1487 rec
.delete_rec
= db_ctdb_delete_deny
;
1488 rec
.private_data
= state
->db
;
1489 state
->fn(&rec
, state
->private_data
);
1493 static int traverse_persistent_callback_read(TDB_CONTEXT
*tdb
, TDB_DATA kbuf
, TDB_DATA dbuf
,
1496 struct traverse_state
*state
= (struct traverse_state
*)private_data
;
1497 struct db_record rec
;
1500 * Skip the __db_sequence_number__ key:
1501 * This is used for persistent transactions internally.
1503 if (kbuf
.dsize
== strlen(CTDB_DB_SEQNUM_KEY
) + 1 &&
1504 strcmp((const char*)kbuf
.dptr
, CTDB_DB_SEQNUM_KEY
) == 0)
1511 rec
.store
= db_ctdb_store_deny
;
1512 rec
.delete_rec
= db_ctdb_delete_deny
;
1513 rec
.private_data
= state
->db
;
1515 if (rec
.value
.dsize
<= sizeof(struct ctdb_ltdb_header
)) {
1516 /* a deleted record */
1519 rec
.value
.dsize
-= sizeof(struct ctdb_ltdb_header
);
1520 rec
.value
.dptr
+= sizeof(struct ctdb_ltdb_header
);
1523 return state
->fn(&rec
, state
->private_data
);
1526 static int db_ctdb_traverse_read(struct db_context
*db
,
1527 int (*fn
)(struct db_record
*rec
,
1528 void *private_data
),
1532 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
1533 struct db_ctdb_ctx
);
1534 struct traverse_state state
;
1538 state
.private_data
= private_data
;
1541 if (db
->persistent
) {
1542 /* for persistent databases we don't need to do a ctdb traverse,
1543 we can do a faster local traverse */
1544 return tdb_traverse_read(ctx
->wtdb
->tdb
, traverse_persistent_callback_read
, &state
);
1547 status
= ctdbd_traverse(ctx
->db_id
, traverse_read_callback
, &state
);
1548 if (!NT_STATUS_IS_OK(status
)) {
1554 static int db_ctdb_get_seqnum(struct db_context
*db
)
1556 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(db
->private_data
,
1557 struct db_ctdb_ctx
);
1558 return tdb_get_seqnum(ctx
->wtdb
->tdb
);
1561 static void db_ctdb_id(struct db_context
*db
, const uint8_t **id
,
1564 struct db_ctdb_ctx
*ctx
= talloc_get_type_abort(
1565 db
->private_data
, struct db_ctdb_ctx
);
1567 *id
= (uint8_t *)&ctx
->db_id
;
1568 *idlen
= sizeof(ctx
->db_id
);
1571 struct db_context
*db_open_ctdb(TALLOC_CTX
*mem_ctx
,
1573 int hash_size
, int tdb_flags
,
1574 int open_flags
, mode_t mode
,
1575 enum dbwrap_lock_order lock_order
)
1577 struct db_context
*result
;
1578 struct db_ctdb_ctx
*db_ctdb
;
1580 struct ctdbd_connection
*conn
;
1581 struct loadparm_context
*lp_ctx
;
1582 struct ctdb_db_priority prio
;
1586 if (!lp_clustering()) {
1587 DEBUG(10, ("Clustering disabled -- no ctdb\n"));
1591 if (!(result
= talloc_zero(mem_ctx
, struct db_context
))) {
1592 DEBUG(0, ("talloc failed\n"));
1593 TALLOC_FREE(result
);
1597 if (!(db_ctdb
= talloc(result
, struct db_ctdb_ctx
))) {
1598 DEBUG(0, ("talloc failed\n"));
1599 TALLOC_FREE(result
);
1603 db_ctdb
->transaction
= NULL
;
1604 db_ctdb
->db
= result
;
1606 conn
= messaging_ctdbd_connection();
1608 DEBUG(1, ("Could not connect to ctdb\n"));
1609 TALLOC_FREE(result
);
1613 if (!NT_STATUS_IS_OK(ctdbd_db_attach(conn
, name
, &db_ctdb
->db_id
, tdb_flags
))) {
1614 DEBUG(0, ("ctdbd_db_attach failed for %s\n", name
));
1615 TALLOC_FREE(result
);
1619 db_path
= ctdbd_dbpath(conn
, db_ctdb
, db_ctdb
->db_id
);
1621 result
->persistent
= ((tdb_flags
& TDB_CLEAR_IF_FIRST
) == 0);
1622 result
->lock_order
= lock_order
;
1624 /* only pass through specific flags */
1625 tdb_flags
&= TDB_SEQNUM
;
1627 /* honor permissions if user has specified O_CREAT */
1628 if (open_flags
& O_CREAT
) {
1629 chmod(db_path
, mode
);
1632 prio
.db_id
= db_ctdb
->db_id
;
1633 prio
.priority
= lock_order
;
1635 status
= ctdbd_control_local(
1636 conn
, CTDB_CONTROL_SET_DB_PRIORITY
, 0, 0,
1637 make_tdb_data((uint8_t *)&prio
, sizeof(prio
)),
1638 NULL
, NULL
, &cstatus
);
1640 if (!NT_STATUS_IS_OK(status
) || (cstatus
!= 0)) {
1641 DEBUG(1, ("CTDB_CONTROL_SET_DB_PRIORITY failed: %s, %d\n",
1642 nt_errstr(status
), cstatus
));
1643 TALLOC_FREE(result
);
1647 lp_ctx
= loadparm_init_s3(db_path
, loadparm_s3_helpers());
1649 db_ctdb
->wtdb
= tdb_wrap_open(db_ctdb
, db_path
, hash_size
, tdb_flags
,
1651 talloc_unlink(db_path
, lp_ctx
);
1652 if (db_ctdb
->wtdb
== NULL
) {
1653 DEBUG(0, ("Could not open tdb %s: %s\n", db_path
, strerror(errno
)));
1654 TALLOC_FREE(result
);
1657 talloc_free(db_path
);
1659 if (result
->persistent
) {
1660 db_ctdb
->lock_ctx
= g_lock_ctx_init(db_ctdb
,
1661 ctdb_conn_msg_ctx(conn
));
1662 if (db_ctdb
->lock_ctx
== NULL
) {
1663 DEBUG(0, ("g_lock_ctx_init failed\n"));
1664 TALLOC_FREE(result
);
1669 result
->private_data
= (void *)db_ctdb
;
1670 result
->fetch_locked
= db_ctdb_fetch_locked
;
1671 result
->try_fetch_locked
= db_ctdb_try_fetch_locked
;
1672 result
->parse_record
= db_ctdb_parse_record
;
1673 result
->traverse
= db_ctdb_traverse
;
1674 result
->traverse_read
= db_ctdb_traverse_read
;
1675 result
->get_seqnum
= db_ctdb_get_seqnum
;
1676 result
->transaction_start
= db_ctdb_transaction_start
;
1677 result
->transaction_commit
= db_ctdb_transaction_commit
;
1678 result
->transaction_cancel
= db_ctdb_transaction_cancel
;
1679 result
->id
= db_ctdb_id
;
1680 result
->stored_callback
= NULL
;
1682 DEBUG(3,("db_open_ctdb: opened database '%s' with dbid 0x%x\n",
1683 name
, db_ctdb
->db_id
));
1688 #else /* CLUSTER_SUPPORT */
1690 struct db_context
*db_open_ctdb(TALLOC_CTX
*mem_ctx
,
1692 int hash_size
, int tdb_flags
,
1693 int open_flags
, mode_t mode
,
1694 enum dbwrap_lock_order lock_order
)
1696 DEBUG(3, ("db_open_ctdb: no cluster support!\n"));