From 6ef8b80ac0d7a8bfa843b224f1b10f728be8b019 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Mon, 13 Aug 2018 12:01:18 -0400 Subject: [PATCH] DEBUG FIX --- ldap/servers/slapd/back-ldbm/back-ldbm.h | 2 + ldap/servers/slapd/back-ldbm/cache.c | 61 +++++++++++++++++++--- ldap/servers/slapd/back-ldbm/ldbm_delete.c | 3 ++ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/ldap/servers/slapd/back-ldbm/back-ldbm.h b/ldap/servers/slapd/back-ldbm/back-ldbm.h index 79115fe12..a772ba4bb 100644 --- a/ldap/servers/slapd/back-ldbm/back-ldbm.h +++ b/ldap/servers/slapd/back-ldbm/back-ldbm.h @@ -340,6 +340,8 @@ struct backentry void *ep_id_link; /* tables used for */ void *ep_uuid_link; /* looking up entries */ PRMonitor *ep_mutexp; /* protection for mods; make it reentrant */ + int retry_count; /* DEBUG - entry cache crash ticket 49905 */ + }; /* From ep_type through ep_size MUST be identical to backcommon */ diff --git a/ldap/servers/slapd/back-ldbm/cache.c b/ldap/servers/slapd/back-ldbm/cache.c index a27505c4b..1feeb9f75 100644 --- a/ldap/servers/slapd/back-ldbm/cache.c +++ b/ldap/servers/slapd/back-ldbm/cache.c @@ -15,6 +15,8 @@ #include "back-ldbm.h" +#include /* DEBUG - entry cache crash ticket 49905 */ + #ifdef DEBUG #define LDAP_CACHE_DEBUG /* #define LDAP_CACHE_DEBUG_LRU * causes slowdown */ @@ -144,6 +146,14 @@ entry_same_dn(const void *e, const void *k) struct backentry *be = (struct backentry *)e; const char *ndn = slapi_sdn_get_ndn(backentry_get_sdn(be)); + if (ndn == NULL) { + /* DEBUG - entry cache crash ticket 49905 */ + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", + "Invalid cache entry matching (%s), cache entry retry_count (%d) state (%d), do not crash, and move on....\n", + (char *)k, be->retry_count, be->ep_state ); + return 666; + } + return (strcmp(ndn, (char *)k) == 0); } @@ -187,20 +197,30 @@ add_hash(Hashtable *ht, void *key, uint32_t keylen, void *entry, void **alt) { u_long val, slot; void *e; + int rc = 0; val = HASH_VALUE(key, keylen); slot = (val % ht->size); /* first, check if this key is already in the table */ e = ht->slot[slot]; while (e) { - if ((*ht->testfn)(e, key)) { - /* ack! already in! */ - if (alt) - *alt = e; - return 0; + if ((rc = (*ht->testfn)(e, key))) { + if (rc != 666) { + /* ack! already in! */ + if (alt) + *alt = e; + return 0; + } } e = HASH_NEXT(ht, e); } + if (rc == 666 ){ + /* DEBUG - entry cache crash ticket 49905 */ + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", "Removing old invalid hash entry...\n"); + remove_hash(ht, key, keylen); + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", "Add new hash entry...\n"); + } + /* ok, it's not already there, so add it */ HASH_NEXT(ht, entry) = ht->slot[slot]; ht->slot[slot] = entry; @@ -1270,6 +1290,26 @@ cache_find_uuid(struct cache *cache, const char *uuid) } #endif +/* DEBUG - entry cache crash ticket 49905 */ +void +print_trace (void) +{ + void *array[10]; + size_t size; + char **strings; + size_t i; + + size = backtrace (array, 10); + strings = backtrace_symbols (array, size); + + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", "Printing stack trace: (%lu)\n", size); + + for (i = 0; i < size; i++) + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", " - %s\n", strings[i]); + free (strings); +} + + /* add an entry to the cache */ static int entrycache_add_int(struct cache *cache, struct backentry *e, int state, struct backentry **alt) @@ -1333,13 +1373,18 @@ entrycache_add_int(struct cache *cache, struct backentry *e, int state, struct b } } else { if (my_alt->ep_state & ENTRY_STATE_CREATING) { - LOG("the entry %s is reserved (ep_state: 0x%x, state: 0x%x)\n", ndn, e->ep_state, state); + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", + "entrycache_add_int - The entry (%s) is reserved (ep_state: 0x%x, state: 0x%x) Setting the ODD state for the cache entry (retry_count %d - alt: %d)\n", + ndn, e->ep_state, state, e->retry_count, my_alt->retry_count); + print_trace(); e->ep_state |= ENTRY_STATE_NOTINCACHE; cache_unlock(cache); return -1; } else if (state != 0) { - LOG("the entry %s already exists. cannot reserve it. (ep_state: 0x%x, state: 0x%x)\n", - ndn, e->ep_state, state); + slapi_log_err(SLAPI_LOG_ALERT, "DEBUG", + "entrycache_add_int2 - the entry (%s) already exists. cannot reserve it. (ep_state: 0x%x, state: 0x%x) Setting the ODD state for the cache entry (retry_count %d - alt: %d)\n", + ndn, e->ep_state, state, e->retry_count, my_alt->retry_count); + print_trace(); e->ep_state |= ENTRY_STATE_NOTINCACHE; cache_unlock(cache); return -1; diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c index 3a27fd071..abff763e7 100644 --- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c +++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c @@ -197,6 +197,8 @@ ldbm_back_delete(Slapi_PBlock *pb) if (create_tombstone_entry) { slapi_sdn_set_ndn_byval(&nscpEntrySDN, slapi_sdn_get_ndn(slapi_entry_get_sdn(e->ep_entry))); + tombstone->retry_count = retry_count; /* DEBUG - entry cache crash ticket 49905 */ + /* reset tombstone entry */ if (original_tombstone) { /* must duplicate tombstone before returning it to cache, @@ -217,6 +219,7 @@ ldbm_back_delete(Slapi_PBlock *pb) } tombstone = original_tombstone; original_tombstone = tmptombstone; + tombstone->retry_count = retry_count; /* DEBUG - entry cache crash ticket 49905 */ tmptombstone = NULL; } else { slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_delete", -- 2.17.1