The C# Sniffer Class

Sniffer exposes the eXtremeDB recovery API used to inspect live database connections, detect stale or dead connections, and trigger cleanup in shared-memory or other multi-process configurations. It is primarily intended for watchdog-style recovery code rather than normal database access.

For an overview see page C# Classes

Class Definition

    public class Sniffer
    {
        public const int MCO_SNIFFER_INSPECT_ACTIVE_CONNECTIONS = 0x00;
        public const int MCO_SNIFFER_INSPECT_ACTIVE_TRANSACTIONS = 0x01;
        public const int MCO_SNIFFER_INSPECT_HANGED_TRANSACTIONS = 0x02;

        public interface IConnIterator
        {
            bool IsConnectionAlive(byte[] context, long transNo);
        }

        public Sniffer(Connection con);
        public void IterateConnections(IConnIterator iterator, int policy);

        public bool IsProcessAlive(int procID);
        public static bool IsProcessAlive(Connection con, int procID);
        public static bool IsProcessAlive(Database db, int procID);

        public int GetCurrentProcessID();
        public static int GetCurrentProcessID(Connection con);
        public static int GetCurrentProcessID(Database db);

        public byte[] ProcessIDtoBytes(int procID);
        public static byte[] ProcessIDtoBytes(Connection con, int procID);
        public static byte[] ProcessIDtoBytes(Database db, int procID);

        public int BytesToProcessID(byte[] connectionContext);
        public static int BytesToProcessID(Connection con, byte[] connectionContext);
        public static int BytesToProcessID(Database db, byte[] connectionContext);

        public int GetProcessIDSize();
        public static int GetProcessIDSize(Connection con);
        public static int GetProcessIDSize(Database db);
    }

Member Descriptions

Sniffer class
Provides a managed wrapper around the eXtremeDB sniffer functionality used to inspect connections and recover from dead or stale connections in multi-process database deployments.
MCO_SNIFFER_INSPECT_ACTIVE_CONNECTIONS
Sniffer policy that inspects all active database connections.
MCO_SNIFFER_INSPECT_ACTIVE_TRANSACTIONS
Sniffer policy that inspects only connections that currently have active transactions.
MCO_SNIFFER_INSPECT_HANGED_TRANSACTIONS
Sniffer policy that inspects connections with active transactions whose transaction number has not changed since the previous sniffer invocation. This policy is intended for hung-transaction detection and should be used with a carefully chosen polling interval.
IConnIterator interface
Application callback interface used by IterateConnections() to decide whether an inspected connection is still alive.
IConnIterator.IsConnectionAlive(byte[] context, long transNo)
Called for each inspected connection. context is the raw connection-context buffer stored with that connection, and transNo is the current transaction number. Return true if the connection is alive, or false to report the connection as dead and allow recovery cleanup to proceed for that connection.
Sniffer(Connection con)
Creates a sniffer helper bound to the specified connection. The sniffer runs in the context of this connection and uses its wrapper and database runtime information.
IterateConnections(IConnIterator, int)
Invokes the sniffer over the database connections visible through the associated connection and calls the supplied iterator for each inspected connection according to the selected policy.
IsProcessAlive(... overloads)
Checks whether a process with the specified process identifier is still alive. Instance and static overloads are provided for convenience.
GetCurrentProcessID(... overloads)
Returns the current process identifier in the representation expected by the runtime on the current platform.
ProcessIDtoBytes(... overloads)
Converts a process identifier to a byte buffer using the runtime-specific size of mco_process_t. This is the form commonly stored in the connection context when sniffer-based recovery is used.
BytesToProcessID(... overloads)
Converts a connection-context byte buffer back to a process identifier according to the runtime-specific size of mco_process_t. Throws ArgumentException if the buffer size does not match the expected context size.
GetProcessIDSize(... overloads)
Returns the size, in bytes, of the process identifier type used by the runtime. Use this value for Database.Parameters.ConnectionContextSize when process identifiers are stored in connection contexts for sniffer-based recovery.
Connection Context Requirement
When the application uses process identifiers as connection context, set Database.Parameters.ConnectionContextSize to Sniffer.GetProcessIDSize(...) before opening the database, then create each connection with Sniffer.ProcessIDtoBytes(...) as its context.
Typical Workflow
A common pattern is to start a watchdog thread, open a dedicated connection with a process-ID context, create a Sniffer on that connection, periodically call IterateConnections(), and use IsProcessAlive() inside IConnIterator.IsConnectionAlive() to decide whether cleanup is needed.
Use Cases and Limits
The sniffer is useful for cleaning up stale connections after process failure outside a runtime call, or after normal application termination that leaves connections or transactions open. It is not intended to repair internal runtime inconsistencies caused by a crash while a database runtime call is executing.
Related Guides and Samples
See Database Recovery from Failed Processes, Database Recovery from Failed Processes in C, and the C# samples createdb sniffer and ConnectCtx.