Changeset: a4e56273cf4c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a4e56273cf4c
Modified Files:
cmake/monetdb-defines.cmake
gdk/gdk_bbp.c
gdk/gdk_logger.c
gdk/gdk_system.c
gdk/gdk_system.h
monetdb_config.h.in
sql/backends/monet5/sql_scenario.c
sql/storage/store.c
Branch: Dec2023
Log Message:
When printing USR1 info, if a needed lock is held, wait a second and try again.
We try using a lock function with timeout, but if not available, we just
sleep for a second.
diffs (199 lines):
diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -124,6 +124,7 @@ function(monetdb_configure_defines)
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
check_function_exists("pthread_kill" HAVE_PTHREAD_KILL)
+ check_function_exists("pthread_mutex_timedlock"
HAVE_PTHREAD_MUTEX_TIMEDLOCK)
check_function_exists("pthread_setname_np" HAVE_PTHREAD_SETNAME_NP)
check_function_exists("pthread_sigmask" HAVE_PTHREAD_SIGMASK)
cmake_pop_check_state()
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -4936,6 +4936,15 @@ BBPtmlock(void)
BBPtmlockFinish();
}
+static bool
+BBPtrytmlock(int ms)
+{
+ if (!MT_lock_trytime(&GDKtmLock, ms))
+ return false;
+ BBPtmlockFinish();
+ return true;
+}
+
void
BBPtmunlock(void)
{
@@ -4959,7 +4968,10 @@ BBPprintinfo(void)
} bats[2][2][2][2][2] = {0};
int nbats = 0;
- BBPtmlock();
+ if (!BBPtrytmlock(1000)) {
+ printf("BBP is currently locked, so no BAT information\n");
+ return;
+ }
bat sz = (bat) ATOMIC_GET(&BBPsize);
for (bat i = 1; i < sz; i++) {
MT_lock_set(&GDKswapLock(i));
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1113,6 +1113,7 @@ log_create_types_file(logger *lg, const
#define rotation_lock(lg) MT_lock_set(&(lg)->rotation_lock)
#define rotation_unlock(lg) MT_lock_unset(&(lg)->rotation_lock)
+#define rotation_trylock(lg, ms) MT_lock_trytime(&(lg)->rotation_lock, ms)
static gdk_return
log_open_output(logger *lg)
@@ -3540,8 +3541,11 @@ log_tstart(logger *lg, bool flushnow, ul
void
log_printinfo(logger *lg)
{
+ if (!rotation_trylock(lg, 1000)) {
+ printf("Logger is currently locked, so no logger
information\n");
+ return;
+ }
printf("logger %s:\n", lg->fn);
- rotation_lock(lg);
printf("current log file "ULLFMT", last handled log file "ULLFMT"\n",
lg->id, lg->saved_id);
printf("current transaction id %d, saved transaction id %d\n",
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -239,6 +239,7 @@ struct mtthread mainthread = {
static pthread_mutex_t posthread_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t threadkey;
#define thread_lock() pthread_mutex_lock(&posthread_lock)
+#define thread_lock_try() (pthread_mutex_trylock(&posthread_lock) == 0)
#define thread_unlock() pthread_mutex_unlock(&posthread_lock)
#define thread_self() pthread_getspecific(threadkey)
#define thread_setself(self) pthread_setspecific(threadkey, self)
@@ -246,6 +247,7 @@ static pthread_key_t threadkey;
static CRITICAL_SECTION winthread_cs;
static DWORD threadkey = TLS_OUT_OF_INDEXES;
#define thread_lock() EnterCriticalSection(&winthread_cs)
+#define thread_lock_try() (TryEnterCriticalSection(&winthread_cs) != 0)
#define thread_unlock() LeaveCriticalSection(&winthread_cs)
#define thread_self() TlsGetValue(threadkey)
#define thread_setself(self) TlsSetValue(threadkey, self)
@@ -285,7 +287,23 @@ void
dump_threads(void)
{
char buf[1024];
- thread_lock();
+#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(HAVE_CLOCK_GETTIME)
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec++; /* give it a second */
+ if (pthread_mutex_timedlock(&posthread_lock, &ts) != 0) {
+ printf("Threads are currently locked, so no thread
information\n");
+ return;
+ }
+#else
+ if (!thread_lock_try()) {
+ MT_sleep_ms(1000);
+ if (!thread_lock_try()) {
+ printf("Threads are currently locked, so no thread
information\n");
+ return;
+ }
+ }
+#endif
if (!GDK_TRACER_TEST(M_DEBUG, THRD))
printf("Threads:\n");
for (struct mtthread *t = mtthreads; t; t = t->next) {
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -497,6 +497,24 @@ typedef struct MT_Lock {
#define MT_lock_try(l) (pthread_mutex_trylock(&(l)->lock) == 0 &&
(_DBG_LOCK_LOCKER(l), true))
+#if defined(__GNUC__) && defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) &&
defined(HAVE_CLOCK_GETTIME)
+#define MT_lock_trytime(l, ms) \
+ ({ \
+ struct timespec ts; \
+ clock_gettime(CLOCK_REALTIME, &ts); \
+ ts.tv_nsec += (ms % 1000) * 1000000; \
+ if (ts.tv_nsec >= 1000000000) { \
+ ts.tv_nsec -= 1000000000; \
+ ts.tv_sec++; \
+ } \
+ ts.tv_sec += (ms / 1000); \
+ int ret = pthread_mutex_timedlock(&(l)->lock, &ts); \
+ if (ret == 0) \
+ _DBG_LOCK_LOCKER(l); \
+ ret == 0; \
+ })
+#endif
+
#define MT_lock_set(l) \
do { \
_DBG_LOCK_COUNT_0(l); \
@@ -509,6 +527,7 @@ typedef struct MT_Lock {
_DBG_LOCK_LOCKER(l); \
_DBG_LOCK_COUNT_2(l); \
} while (0)
+
#define MT_lock_unset(l) \
do { \
_DBG_LOCK_UNLOCKER(l); \
@@ -626,6 +645,11 @@ typedef pthread_key_t MT_TLS_t;
#endif
+#ifndef MT_lock_trytime
+/* simplistic way to try lock with timeout: just sleep */
+#define MT_lock_trytime(l, ms) (MT_lock_try(l) || (MT_sleep_ms(ms),
MT_lock_try(l)))
+#endif
+
gdk_export gdk_return MT_alloc_tls(MT_TLS_t *newkey);
gdk_export void MT_tls_set(MT_TLS_t key, void *val);
gdk_export void *MT_tls_get(MT_TLS_t key);
diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -175,6 +175,7 @@
#cmakedefine HAVE_UNAME 1
// #cmakedefine HAVE_SEMTIMEDOP
#cmakedefine HAVE_PTHREAD_KILL 1
+#cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK 1
#cmakedefine HAVE_PTHREAD_SETNAME_NP 1
#cmakedefine HAVE_PTHREAD_SIGMASK 1
#cmakedefine HAVE_GETOPT 1
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -99,7 +99,10 @@ CLIENTprintinfo(void)
char trbuf[64];
struct tm tm;
- MT_lock_set(&mal_contextLock);
+ if (!MT_lock_trytime(&mal_contextLock, 1000)) {
+ printf("Clients are currently locked, so no client
information\n");
+ return;
+ }
printf("Clients:\n");
for (Client c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) {
switch (c->mode) {
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -7408,7 +7408,10 @@ sql_trans_convert_partitions(sql_trans *
void
store_printinfo(sqlstore *store)
{
- MT_lock_set(&store->commit);
+ if (!MT_lock_trytime(&store->commit, 1000)) {
+ printf("WAL is currently locked, so no WAL information\n");
+ return;
+ }
printf("WAL:\n");
printf("SQL store oldest pending "ULLFMT"\n", store->oldest_pending);
log_printinfo(store->logger);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]