3 provide API to do non-blocking locks for single or all databases
5 Copyright (C) Amitay Isaacs 2012
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/>.
21 #include "system/filesys.h"
22 #include "system/network.h"
27 #include "lib/tdb_wrap/tdb_wrap.h"
28 #include "lib/util/dlinklist.h"
29 #include "lib/util/debug.h"
30 #include "lib/util/samba_util.h"
31 #include "lib/util/sys_rw.h"
33 #include "ctdb_private.h"
35 #include "common/common.h"
36 #include "common/logging.h"
39 * Non-blocking Locking API
41 * 1. Create a child process to do blocking locks.
42 * 2. Once the locks are obtained, signal parent process via fd.
43 * 3. Invoke registered callback routine with locking status.
44 * 4. If the child process cannot get locks within certain time,
45 * execute an external script to debug.
47 * ctdb_lock_record() - get a lock on a record
48 * ctdb_lock_db() - get a lock on a DB
50 * auto_mark - whether to mark/unmark DBs in before/after callback
51 * = false is used for freezing databases for
52 * recovery since the recovery cannot start till
53 * databases are locked on all the nodes.
54 * = true is used for record locks.
62 static const char * const lock_type_str
[] = {
69 /* lock_context is the common part for a lock request */
71 struct lock_context
*next
, *prev
;
73 struct ctdb_context
*ctdb
;
74 struct ctdb_db_context
*ctdb_db
;
78 struct lock_request
*request
;
81 struct tevent_fd
*tfd
;
82 struct tevent_timer
*ttimer
;
83 struct timeval start_time
;
88 /* lock_request is the client specific part for a lock request */
90 struct lock_context
*lctx
;
91 void (*callback
)(void *, bool);
96 int ctdb_db_iterator(struct ctdb_context
*ctdb
, ctdb_db_handler_t handler
,
99 struct ctdb_db_context
*ctdb_db
;
102 for (ctdb_db
= ctdb
->db_list
; ctdb_db
; ctdb_db
= ctdb_db
->next
) {
103 ret
= handler(ctdb_db
, private_data
);
113 * lock all databases - mark only
115 static int db_lock_mark_handler(struct ctdb_db_context
*ctdb_db
,
118 int tdb_transaction_write_lock_mark(struct tdb_context
*);
120 DEBUG(DEBUG_INFO
, ("marking locked database %s\n", ctdb_db
->db_name
));
122 if (tdb_transaction_write_lock_mark(ctdb_db
->ltdb
->tdb
) != 0) {
123 DEBUG(DEBUG_ERR
, ("Failed to mark (transaction lock) database %s\n",
128 if (tdb_lockall_mark(ctdb_db
->ltdb
->tdb
) != 0) {
129 DEBUG(DEBUG_ERR
, ("Failed to mark (all lock) database %s\n",
137 int ctdb_lockdb_mark(struct ctdb_db_context
*ctdb_db
)
139 if (!ctdb_db_frozen(ctdb_db
)) {
141 ("Attempt to mark database locked when not frozen\n"));
145 return db_lock_mark_handler(ctdb_db
, NULL
);
149 * lock all databases - unmark only
151 static int db_lock_unmark_handler(struct ctdb_db_context
*ctdb_db
,
154 int tdb_transaction_write_lock_unmark(struct tdb_context
*);
156 DEBUG(DEBUG_INFO
, ("unmarking locked database %s\n", ctdb_db
->db_name
));
158 if (tdb_transaction_write_lock_unmark(ctdb_db
->ltdb
->tdb
) != 0) {
159 DEBUG(DEBUG_ERR
, ("Failed to unmark (transaction lock) database %s\n",
164 if (tdb_lockall_unmark(ctdb_db
->ltdb
->tdb
) != 0) {
165 DEBUG(DEBUG_ERR
, ("Failed to unmark (all lock) database %s\n",
173 int ctdb_lockdb_unmark(struct ctdb_db_context
*ctdb_db
)
175 if (!ctdb_db_frozen(ctdb_db
)) {
177 ("Attempt to unmark database locked when not frozen\n"));
181 return db_lock_unmark_handler(ctdb_db
, NULL
);
184 static void ctdb_lock_schedule(struct ctdb_context
*ctdb
);
187 * Destructor to kill the child locking process
189 static int ctdb_lock_context_destructor(struct lock_context
*lock_ctx
)
191 if (lock_ctx
->request
) {
192 lock_ctx
->request
->lctx
= NULL
;
194 if (lock_ctx
->child
> 0) {
195 ctdb_kill(lock_ctx
->ctdb
, lock_ctx
->child
, SIGTERM
);
196 if (lock_ctx
->type
== LOCK_RECORD
) {
197 DLIST_REMOVE(lock_ctx
->ctdb_db
->lock_current
, lock_ctx
);
199 DLIST_REMOVE(lock_ctx
->ctdb
->lock_current
, lock_ctx
);
201 if (lock_ctx
->ctdb_db
->lock_num_current
== 0) {
202 ctdb_fatal(NULL
, "Lock count is 0 before decrement\n");
204 lock_ctx
->ctdb_db
->lock_num_current
--;
205 CTDB_DECREMENT_STAT(lock_ctx
->ctdb
, locks
.num_current
);
206 CTDB_DECREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_current
);
208 if (lock_ctx
->type
== LOCK_RECORD
) {
209 DLIST_REMOVE(lock_ctx
->ctdb_db
->lock_pending
, lock_ctx
);
211 DLIST_REMOVE(lock_ctx
->ctdb
->lock_pending
, lock_ctx
);
213 CTDB_DECREMENT_STAT(lock_ctx
->ctdb
, locks
.num_pending
);
214 CTDB_DECREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_pending
);
217 ctdb_lock_schedule(lock_ctx
->ctdb
);
224 * Destructor to remove lock request
226 static int ctdb_lock_request_destructor(struct lock_request
*lock_request
)
228 if (lock_request
->lctx
== NULL
) {
232 lock_request
->lctx
->request
= NULL
;
233 TALLOC_FREE(lock_request
->lctx
);
239 * Process all the callbacks waiting for lock
241 * If lock has failed, callback is executed with locked=false
243 static void process_callbacks(struct lock_context
*lock_ctx
, bool locked
)
245 struct lock_request
*request
;
246 bool auto_mark
= lock_ctx
->auto_mark
;
248 if (auto_mark
&& locked
) {
249 switch (lock_ctx
->type
) {
251 tdb_chainlock_mark(lock_ctx
->ctdb_db
->ltdb
->tdb
, lock_ctx
->key
);
255 (void)ctdb_lockdb_mark(lock_ctx
->ctdb_db
);
260 request
= lock_ctx
->request
;
262 /* Since request may be freed in the callback, unset the lock
263 * context, so request destructor will not free lock context.
265 request
->lctx
= NULL
;
268 /* Since request may be freed in the callback, unset the request */
269 lock_ctx
->request
= NULL
;
271 request
->callback(request
->private_data
, locked
);
278 switch (lock_ctx
->type
) {
280 tdb_chainlock_unmark(lock_ctx
->ctdb_db
->ltdb
->tdb
, lock_ctx
->key
);
284 ctdb_lockdb_unmark(lock_ctx
->ctdb_db
);
289 talloc_free(lock_ctx
);
293 static int lock_bucket_id(double t
)
295 double ms
= 1.e
-3, s
= 1;
300 } else if (t
< 10*ms
) {
302 } else if (t
< 100*ms
) {
304 } else if (t
< 1*s
) {
306 } else if (t
< 2*s
) {
308 } else if (t
< 4*s
) {
310 } else if (t
< 8*s
) {
312 } else if (t
< 16*s
) {
314 } else if (t
< 32*s
) {
316 } else if (t
< 64*s
) {
326 * Callback routine when the required locks are obtained.
327 * Called from parent context
329 static void ctdb_lock_handler(struct tevent_context
*ev
,
330 struct tevent_fd
*tfd
,
334 struct lock_context
*lock_ctx
;
340 lock_ctx
= talloc_get_type_abort(private_data
, struct lock_context
);
342 /* cancel the timeout event */
343 TALLOC_FREE(lock_ctx
->ttimer
);
345 t
= timeval_elapsed(&lock_ctx
->start_time
);
346 id
= lock_bucket_id(t
);
348 /* Read the status from the child process */
349 if (sys_read(lock_ctx
->fd
[0], &c
, 1) != 1) {
352 locked
= (c
== 0 ? true : false);
355 /* Update statistics */
356 CTDB_INCREMENT_STAT(lock_ctx
->ctdb
, locks
.num_calls
);
357 CTDB_INCREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_calls
);
360 CTDB_INCREMENT_STAT(lock_ctx
->ctdb
, locks
.buckets
[id
]);
361 CTDB_UPDATE_LATENCY(lock_ctx
->ctdb
, lock_ctx
->ctdb_db
,
362 lock_type_str
[lock_ctx
->type
], locks
.latency
,
363 lock_ctx
->start_time
);
365 CTDB_UPDATE_DB_LATENCY(lock_ctx
->ctdb_db
, lock_type_str
[lock_ctx
->type
], locks
.latency
, t
);
366 CTDB_INCREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.buckets
[id
]);
368 CTDB_INCREMENT_STAT(lock_ctx
->ctdb
, locks
.num_failed
);
369 CTDB_INCREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_failed
);
372 process_callbacks(lock_ctx
, locked
);
375 struct lock_log_entry
{
376 struct db_hash_context
*lock_log
;
378 unsigned long log_sec
;
379 struct tevent_timer
*timer
;
382 static int lock_log_fetch_parser(uint8_t *keybuf
, size_t keylen
,
383 uint8_t *databuf
, size_t datalen
,
386 struct lock_log_entry
**entry
=
387 (struct lock_log_entry
**)private_data
;
389 if (datalen
!= sizeof(struct lock_log_entry
*)) {
393 *entry
= talloc_get_type_abort(*(void **)databuf
,
394 struct lock_log_entry
);
398 static void lock_log_cleanup(struct tevent_context
*ev
,
399 struct tevent_timer
*ttimer
,
400 struct timeval current_time
,
403 struct lock_log_entry
*entry
= talloc_get_type_abort(
404 private_data
, struct lock_log_entry
);
409 ret
= db_hash_delete(entry
->lock_log
, entry
->key
.dptr
,
417 static bool lock_log_skip(struct tevent_context
*ev
,
418 struct db_hash_context
*lock_log
,
419 TDB_DATA key
, unsigned long elapsed_sec
)
421 struct lock_log_entry
*entry
= NULL
;
424 ret
= db_hash_fetch(lock_log
, key
.dptr
, key
.dsize
,
425 lock_log_fetch_parser
, &entry
);
428 entry
= talloc_zero(lock_log
, struct lock_log_entry
);
433 entry
->lock_log
= lock_log
;
435 entry
->key
.dptr
= talloc_memdup(entry
, key
.dptr
, key
.dsize
);
436 if (entry
->key
.dptr
== NULL
) {
440 entry
->key
.dsize
= key
.dsize
;
442 entry
->log_sec
= elapsed_sec
;
443 entry
->timer
= tevent_add_timer(ev
, entry
,
444 timeval_current_ofs(30, 0),
445 lock_log_cleanup
, entry
);
446 if (entry
->timer
== NULL
) {
451 ret
= db_hash_add(lock_log
, key
.dptr
, key
.dsize
,
453 sizeof(struct lock_log_entry
*));
461 } else if (ret
== EINVAL
) {
463 ret
= db_hash_delete(lock_log
, key
.dptr
, key
.dsize
);
470 } else if (ret
== 0) {
472 if (elapsed_sec
<= entry
->log_sec
) {
476 entry
->log_sec
= elapsed_sec
;
478 TALLOC_FREE(entry
->timer
);
479 entry
->timer
= tevent_add_timer(ev
, entry
,
480 timeval_current_ofs(30, 0),
481 lock_log_cleanup
, entry
);
482 if (entry
->timer
== NULL
) {
483 ret
= db_hash_delete(lock_log
, key
.dptr
, key
.dsize
);
499 static char **debug_locks_args(TALLOC_CTX
*mem_ctx
,
500 struct lock_context
*lock_ctx
)
502 int tdb_flags
= tdb_get_flags(lock_ctx
->ctdb_db
->ltdb
->tdb
);
503 char **args
= str_list_make_empty(mem_ctx
);
505 str_list_add_printf(&args
, "debug_locks");
506 str_list_add_printf(&args
, "%d", lock_ctx
->child
);
507 str_list_add_printf(&args
,
509 (lock_ctx
->type
== LOCK_RECORD
) ? "RECORD" : "DB");
510 str_list_add_printf(&args
, "%s", lock_ctx
->ctdb_db
->db_path
);
512 str_list_add_printf(&args
,
513 (tdb_flags
& TDB_MUTEX_LOCKING
) ? "MUTEX"
519 * Callback routine when required locks are not obtained within timeout
520 * Called from parent context
522 static void ctdb_lock_timeout_handler(struct tevent_context
*ev
,
523 struct tevent_timer
*ttimer
,
524 struct timeval current_time
,
527 static char debug_locks
[PATH_MAX
+1] = "";
528 struct lock_context
*lock_ctx
;
529 struct ctdb_context
*ctdb
;
537 lock_ctx
= talloc_get_type_abort(private_data
, struct lock_context
);
538 ctdb
= lock_ctx
->ctdb
;
540 elapsed_time
= timeval_elapsed(&lock_ctx
->start_time
);
542 /* For database locks, always log */
543 if (lock_ctx
->type
== LOCK_DB
) {
545 ("Unable to get DB lock on database %s for "
547 lock_ctx
->ctdb_db
->db_name
, elapsed_time
));
551 /* For record locks, check if we have already logged */
552 skip
= lock_log_skip(ev
, lock_ctx
->ctdb_db
->lock_log
,
553 lock_ctx
->key
, (unsigned long)elapsed_time
);
555 goto skip_lock_debug
;
558 keystr
= hex_encode_talloc(lock_ctx
, lock_ctx
->key
.dptr
,
559 lock_ctx
->key
.dsize
);
561 ("Unable to get RECORD lock on database %s for %.0lf seconds"
563 lock_ctx
->ctdb_db
->db_name
, elapsed_time
,
564 keystr
? keystr
: ""));
567 /* If a node stopped/banned, don't spam the logs */
568 if (ctdb
->nodes
[ctdb
->pnn
]->flags
& NODE_FLAGS_INACTIVE
) {
569 goto skip_lock_debug
;
574 ok
= ctdb_set_helper("lock debugging helper",
581 DBG_WARNING("Unable to setup lock debugging\n");
582 goto skip_lock_debug
;
585 args
= debug_locks_args(lock_ctx
, lock_ctx
);
589 execvp(debug_locks
, args
);
593 ctdb_track_child(ctdb
, pid
);
595 D_WARNING("No memory for debug locks args\n");
600 /* reset the timeout timer */
601 // talloc_free(lock_ctx->ttimer);
602 lock_ctx
->ttimer
= tevent_add_timer(ctdb
->ev
,
604 timeval_current_ofs(10, 0),
605 ctdb_lock_timeout_handler
,
609 static char **lock_helper_args(TALLOC_CTX
*mem_ctx
,
610 struct lock_context
*lock_ctx
,
613 int tdb_flags
= tdb_get_flags(lock_ctx
->ctdb_db
->ltdb
->tdb
);
614 char **args
= str_list_make_empty(mem_ctx
);
616 str_list_add_printf(&args
, "%d", getpid());
617 str_list_add_printf(&args
, "%d", fd
);
618 str_list_add_printf(&args
,
620 (lock_ctx
->type
== LOCK_RECORD
) ? "RECORD" : "DB");
622 str_list_add_printf(&args
, "%s", lock_ctx
->ctdb_db
->db_path
);
623 str_list_add_printf(&args
, "0x%x", tdb_flags
);
625 if (lock_ctx
->type
== LOCK_RECORD
) {
626 if (lock_ctx
->key
.dsize
== 0) {
627 str_list_add_printf(&args
, "NULL");
629 char *hex
= hex_encode_talloc(mem_ctx
,
631 lock_ctx
->key
.dsize
);
636 str_list_add_printf(&args
, "%s", hex
);
645 * Find a lock request that can be scheduled
647 static struct lock_context
*ctdb_find_lock_context(struct ctdb_context
*ctdb
)
649 struct lock_context
*lock_ctx
, *next_ctx
;
650 struct ctdb_db_context
*ctdb_db
;
652 /* First check if there are database lock requests */
654 for (lock_ctx
= ctdb
->lock_pending
; lock_ctx
!= NULL
;
655 lock_ctx
= next_ctx
) {
657 if (lock_ctx
->request
!= NULL
) {
658 /* Found a lock context with a request */
662 next_ctx
= lock_ctx
->next
;
664 DEBUG(DEBUG_INFO
, ("Removing lock context without lock "
666 DLIST_REMOVE(ctdb
->lock_pending
, lock_ctx
);
667 CTDB_DECREMENT_STAT(ctdb
, locks
.num_pending
);
668 CTDB_DECREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_pending
);
669 talloc_free(lock_ctx
);
672 /* Next check database queues */
673 for (ctdb_db
= ctdb
->db_list
; ctdb_db
; ctdb_db
= ctdb_db
->next
) {
674 if (ctdb_db
->lock_num_current
==
675 ctdb
->tunable
.lock_processes_per_db
) {
679 for (lock_ctx
= ctdb_db
->lock_pending
; lock_ctx
!= NULL
;
680 lock_ctx
= next_ctx
) {
682 next_ctx
= lock_ctx
->next
;
684 if (lock_ctx
->request
!= NULL
) {
688 DEBUG(DEBUG_INFO
, ("Removing lock context without "
690 DLIST_REMOVE(ctdb_db
->lock_pending
, lock_ctx
);
691 CTDB_DECREMENT_STAT(ctdb
, locks
.num_pending
);
692 CTDB_DECREMENT_DB_STAT(ctdb_db
, locks
.num_pending
);
693 talloc_free(lock_ctx
);
701 * Schedule a new lock child process
702 * Set up callback handler and timeout handler
704 static void ctdb_lock_schedule(struct ctdb_context
*ctdb
)
706 struct lock_context
*lock_ctx
;
709 static char prog
[PATH_MAX
+1] = "";
712 if (!ctdb_set_helper("lock helper",
715 CTDB_HELPER_BINDIR
, "ctdb_lock_helper")) {
716 ctdb_die(ctdb
, __location__
717 " Unable to set lock helper\n");
720 /* Find a lock context with requests */
721 lock_ctx
= ctdb_find_lock_context(ctdb
);
722 if (lock_ctx
== NULL
) {
726 lock_ctx
->child
= -1;
727 ret
= pipe(lock_ctx
->fd
);
729 DEBUG(DEBUG_ERR
, ("Failed to create pipe in ctdb_lock_schedule\n"));
733 set_close_on_exec(lock_ctx
->fd
[0]);
735 /* Create data for child process */
736 tmp_ctx
= talloc_new(lock_ctx
);
737 if (tmp_ctx
== NULL
) {
738 DEBUG(DEBUG_ERR
, ("Failed to allocate memory for helper args\n"));
739 close(lock_ctx
->fd
[0]);
740 close(lock_ctx
->fd
[1]);
744 if (! ctdb
->do_setsched
) {
745 ret
= setenv("CTDB_NOSETSCHED", "1", 1);
748 ("Failed to set CTDB_NOSETSCHED variable\n"));
752 /* Create arguments for lock helper */
753 args
= lock_helper_args(tmp_ctx
, lock_ctx
, lock_ctx
->fd
[1]);
755 DEBUG(DEBUG_ERR
, ("Failed to create lock helper args\n"));
756 close(lock_ctx
->fd
[0]);
757 close(lock_ctx
->fd
[1]);
758 talloc_free(tmp_ctx
);
762 lock_ctx
->child
= ctdb_vfork_exec(lock_ctx
,
765 talloc_array_length(args
),
766 (const char *const *)args
);
767 if (lock_ctx
->child
== -1) {
768 DEBUG(DEBUG_ERR
, ("Failed to create a child in ctdb_lock_schedule\n"));
769 close(lock_ctx
->fd
[0]);
770 close(lock_ctx
->fd
[1]);
771 talloc_free(tmp_ctx
);
776 close(lock_ctx
->fd
[1]);
778 talloc_free(tmp_ctx
);
780 /* Set up timeout handler */
781 lock_ctx
->ttimer
= tevent_add_timer(ctdb
->ev
,
783 timeval_current_ofs(10, 0),
784 ctdb_lock_timeout_handler
,
786 if (lock_ctx
->ttimer
== NULL
) {
787 ctdb_kill(ctdb
, lock_ctx
->child
, SIGTERM
);
788 lock_ctx
->child
= -1;
789 close(lock_ctx
->fd
[0]);
793 /* Set up callback */
794 lock_ctx
->tfd
= tevent_add_fd(ctdb
->ev
,
800 if (lock_ctx
->tfd
== NULL
) {
801 TALLOC_FREE(lock_ctx
->ttimer
);
802 ctdb_kill(ctdb
, lock_ctx
->child
, SIGTERM
);
803 lock_ctx
->child
= -1;
804 close(lock_ctx
->fd
[0]);
807 tevent_fd_set_auto_close(lock_ctx
->tfd
);
809 /* Move the context from pending to current */
810 if (lock_ctx
->type
== LOCK_RECORD
) {
811 DLIST_REMOVE(lock_ctx
->ctdb_db
->lock_pending
, lock_ctx
);
812 DLIST_ADD_END(lock_ctx
->ctdb_db
->lock_current
, lock_ctx
);
814 DLIST_REMOVE(ctdb
->lock_pending
, lock_ctx
);
815 DLIST_ADD_END(ctdb
->lock_current
, lock_ctx
);
817 CTDB_DECREMENT_STAT(lock_ctx
->ctdb
, locks
.num_pending
);
818 CTDB_INCREMENT_STAT(lock_ctx
->ctdb
, locks
.num_current
);
819 lock_ctx
->ctdb_db
->lock_num_current
++;
820 CTDB_DECREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_pending
);
821 CTDB_INCREMENT_DB_STAT(lock_ctx
->ctdb_db
, locks
.num_current
);
826 * Lock record / db depending on type
828 static struct lock_request
*ctdb_lock_internal(TALLOC_CTX
*mem_ctx
,
829 struct ctdb_context
*ctdb
,
830 struct ctdb_db_context
*ctdb_db
,
833 void (*callback
)(void *, bool),
838 struct lock_context
*lock_ctx
= NULL
;
839 struct lock_request
*request
;
841 if (callback
== NULL
) {
842 DEBUG(DEBUG_WARNING
, ("No callback function specified, not locking\n"));
846 lock_ctx
= talloc_zero(ctdb
, struct lock_context
);
847 if (lock_ctx
== NULL
) {
848 DEBUG(DEBUG_ERR
, ("Failed to create a new lock context\n"));
852 if ((request
= talloc_zero(mem_ctx
, struct lock_request
)) == NULL
) {
853 talloc_free(lock_ctx
);
857 lock_ctx
->type
= type
;
858 lock_ctx
->ctdb
= ctdb
;
859 lock_ctx
->ctdb_db
= ctdb_db
;
860 lock_ctx
->key
.dsize
= key
.dsize
;
862 lock_ctx
->key
.dptr
= talloc_memdup(lock_ctx
, key
.dptr
, key
.dsize
);
863 if (lock_ctx
->key
.dptr
== NULL
) {
864 DEBUG(DEBUG_ERR
, (__location__
"Memory allocation error\n"));
865 talloc_free(lock_ctx
);
866 talloc_free(request
);
869 lock_ctx
->key_hash
= ctdb_hash(&key
);
871 lock_ctx
->key
.dptr
= NULL
;
873 lock_ctx
->priority
= priority
;
874 lock_ctx
->auto_mark
= auto_mark
;
876 lock_ctx
->request
= request
;
877 lock_ctx
->child
= -1;
879 /* Non-record locks are required by recovery and should be scheduled
880 * immediately, so keep them at the head of the pending queue.
882 if (lock_ctx
->type
== LOCK_RECORD
) {
883 DLIST_ADD_END(ctdb_db
->lock_pending
, lock_ctx
);
885 DLIST_ADD_END(ctdb
->lock_pending
, lock_ctx
);
887 CTDB_INCREMENT_STAT(ctdb
, locks
.num_pending
);
889 CTDB_INCREMENT_DB_STAT(ctdb_db
, locks
.num_pending
);
892 /* Start the timer when we activate the context */
893 lock_ctx
->start_time
= timeval_current();
895 request
->lctx
= lock_ctx
;
896 request
->callback
= callback
;
897 request
->private_data
= private_data
;
899 talloc_set_destructor(request
, ctdb_lock_request_destructor
);
900 talloc_set_destructor(lock_ctx
, ctdb_lock_context_destructor
);
902 ctdb_lock_schedule(ctdb
);
909 * obtain a lock on a record in a database
911 struct lock_request
*ctdb_lock_record(TALLOC_CTX
*mem_ctx
,
912 struct ctdb_db_context
*ctdb_db
,
915 void (*callback
)(void *, bool),
918 return ctdb_lock_internal(mem_ctx
,
931 * obtain a lock on a database
933 struct lock_request
*ctdb_lock_db(TALLOC_CTX
*mem_ctx
,
934 struct ctdb_db_context
*ctdb_db
,
936 void (*callback
)(void *, bool),
939 return ctdb_lock_internal(mem_ctx
,