Skip to content

Commit cbd3520

Browse files
committed
CDRIVER-1198: Use strings for server and topology types in SDAM transition logs
1 parent 70f6365 commit cbd3520

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

src/mongoc/mongoc-server-description-private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void
9595
mongoc_server_description_set_election_id (mongoc_server_description_t *description,
9696
const bson_oid_t *election_id);
9797

98+
const char *
99+
mongoc_server_description_type_string (const mongoc_server_description_t *description);
100+
98101
void
99102
mongoc_server_description_update_rtt (mongoc_server_description_t *server,
100103
int64_t new_time);

src/mongoc/mongoc-server-description.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,48 @@ mongoc_server_description_type (const mongoc_server_description_t *description)
310310
return description->type;
311311
}
312312

313+
/*
314+
*--------------------------------------------------------------------------
315+
*
316+
* mongoc_server_description_type_string --
317+
*
318+
* Get this server's type, one of the types defined in the Server
319+
* Discovery And Monitoring Spec, as a string.
320+
*
321+
* Returns:
322+
* A string denoting this server's type.
323+
*
324+
*--------------------------------------------------------------------------
325+
*/
326+
327+
const char *
328+
mongoc_server_description_type_string (const mongoc_server_description_t *description)
329+
{
330+
switch (description->type) {
331+
case MONGOC_SERVER_UNKNOWN:
332+
return "Unknown";
333+
case MONGOC_SERVER_STANDALONE:
334+
return "Standalone";
335+
case MONGOC_SERVER_MONGOS:
336+
return "Mongos";
337+
case MONGOC_SERVER_POSSIBLE_PRIMARY:
338+
return "PossiblePrimary";
339+
case MONGOC_SERVER_RS_PRIMARY:
340+
return "RSPrimary";
341+
case MONGOC_SERVER_RS_SECONDARY:
342+
return "RSSecondary";
343+
case MONGOC_SERVER_RS_ARBITER:
344+
return "RSArbiter";
345+
case MONGOC_SERVER_RS_OTHER:
346+
return "RSOther";
347+
case MONGOC_SERVER_RS_GHOST:
348+
return "RSGhost";
349+
default:
350+
MONGOC_ERROR ("Invalid mongoc_server_description_t type\n");
351+
return "Invalid";
352+
}
353+
}
354+
313355
/*
314356
*--------------------------------------------------------------------------
315357
*

src/mongoc/mongoc-topology-description.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,46 @@ gSDAMTransitionTable[MONGOC_SERVER_DESCRIPTION_TYPES][MONGOC_TOPOLOGY_DESCRIPTIO
13671367
}
13681368
};
13691369

1370+
/*
1371+
*--------------------------------------------------------------------------
1372+
*
1373+
* _mongoc_topology_description_type_string --
1374+
*
1375+
* Get this topology's type, one of the types defined in the Server
1376+
* Discovery And Monitoring Spec, as a string.
1377+
*
1378+
* NOTE: this method should only be called while holding the mutex on
1379+
* the owning topology object.
1380+
*
1381+
* Returns:
1382+
* A string.
1383+
*
1384+
* Side effects:
1385+
* None.
1386+
*
1387+
*--------------------------------------------------------------------------
1388+
*/
1389+
static const char *
1390+
_mongoc_topology_description_type_string (mongoc_topology_description_t *topology)
1391+
{
1392+
switch (topology->type) {
1393+
case MONGOC_TOPOLOGY_UNKNOWN:
1394+
return "Unknown";
1395+
case MONGOC_TOPOLOGY_SHARDED:
1396+
return "Sharded";
1397+
case MONGOC_TOPOLOGY_RS_NO_PRIMARY:
1398+
return "RSNoPrimary";
1399+
case MONGOC_TOPOLOGY_RS_WITH_PRIMARY:
1400+
return "RSWithPrimary";
1401+
case MONGOC_TOPOLOGY_SINGLE:
1402+
return "Single";
1403+
case MONGOC_TOPOLOGY_DESCRIPTION_TYPES:
1404+
default:
1405+
MONGOC_ERROR ("Invalid mongoc_topology_description_type_t type\n");
1406+
return "Invalid";
1407+
}
1408+
}
1409+
13701410
/*
13711411
*--------------------------------------------------------------------------
13721412
*
@@ -1403,9 +1443,9 @@ mongoc_topology_description_handle_ismaster (
14031443
error);
14041444

14051445
if (gSDAMTransitionTable[sd->type][topology->type]) {
1406-
TRACE("Transitioning to %d for %d", topology->type, sd->type);
1446+
TRACE("Transitioning to %s for %s", _mongoc_topology_description_type_string(topology), mongoc_server_description_type_string(sd));
14071447
gSDAMTransitionTable[sd->type][topology->type] (topology, sd);
14081448
} else {
1409-
TRACE("No transition entry to %d for %d", topology->type, sd->type);
1449+
TRACE("No transition entry to %s for %s", _mongoc_topology_description_type_string(topology), mongoc_server_description_type_string(sd));
14101450
}
14111451
}

0 commit comments

Comments
 (0)