The C# MasterConnection Class

MasterConnection extends the Connection class for HA master applications. A replication master should use this class instead of Connection and configure replication through MasterConnection.Parameters and SetReplicationMode().

For an overview see page C# Classes

Class Definition

    public class MasterConnection : Connection
    {
        public const int MCO_HAMODE_MULTIPROCESS_COMMIT = 0x2;
        public const int MCO_HAMODE_ASYNCH = 0x4;
        public const int MCO_HAMODE_MCAST = 0x8;
        public const int MCO_HAMODE_MCAST_RELIABLE = 0x10;
        public const int MCO_HAMODE_HOTSYNCH = 0x20;
        public const int MCO_HAMODE_STATEFUL_REPLICATION = 0x40;
        public const int MCO_HAMODE_BINEVOLUTION = 0x80;

        public delegate void ErrorHandlerDelegate(MCO_RET_E errorCode, int replicaNo);

        public class Parameters
        {
            public int CommitTimeout;
            public int InitialTimeout;
            public int DetachTimeout;
            public int SynchTimeout;
            public int ModeFlags;
            public int MaxReplicas;
            public int TransLogLength;
            public Database.Device AsyncBuf;
            public int McastPort;
            public string McastAddr;
            public int HotsyncMsgObjects;
            public int HotsyncMsgSize;
            public int HotsyncDelay;
            public int Quorum;
            public ErrorHandlerDelegate ErrorHandler;
            public Database.SSLParameters SSLParameters;
            public int CompressionLevel;
        }

        public struct ReplicaAddress
        {
            public string ip;
            public int port;
        }

        public void SetReplicationMode(MasterConnection.Parameters param);
        public bool AttachReplica(string masterPort, int timeout);
        public void DetachReplica(int index);
        public void DetachAllReplicas();
        public void SetTransWindowSize(int size);
        public void CommitWindow();
        public void SetQuorum(int quorum);
        public int GetNumberOfReplicas();
        public ReplicaAddress GetReplicaAddress(int replicaNo);
        public void KeepAlive(int timeout);
        public void StopReplication();
        public bool AsyncSendDataToReplicas();
        public void TransCommitSync();
        public void EnableFilter(bool enabled);
        public int GetMode();
        public Database.HAChannelInfo GetReplicaInfo(int no);
    }

Methods

Parameters
Configuration container for HA replication mode. Important fields include ModeFlags, MaxReplicas, AsyncBuf, Quorum, ErrorHandler, and SSLParameters.
SetReplicationMode(MasterConnection.Parameters param)
Initializes HA replication for the master connection using the specified parameters. Typical master startup begins with this call.
AttachReplica(string masterPort, int timeout)
Waits for a replica connection request on the specified master address. Returns true if a replica attaches before the timeout expires.
DetachReplica(int index)
Detaches the replica identified by its current index.
DetachAllReplicas()
Detaches all replicas currently connected to the master.
SetTransWindowSize(int size)
Sets the transaction packet size used by synchronous replication. Larger windows reduce confirmations but allow replicas to lag farther behind the master.
CommitWindow()
Forces replicas to confirm the current transaction packet when windowed replication is in use.
SetQuorum(int quorum)
Sets the minimum number of connected replicas required for the master to accept write transactions at runtime.
GetNumberOfReplicas()
Returns the current number of replicas attached to the master.
GetReplicaAddress(int replicaNo)
Returns the IP address and port for the specified replica connection.
GetReplicaInfo(int no)
Returns HA channel statistics for the specified replica.
KeepAlive(int timeout)
Sends a keep-alive signal to replicas.
StopReplication()
Stops the HA replication subsystem for this master connection.
AsyncSendDataToReplicas()
Sends buffered transaction data to replicas when asynchronous replication mode is enabled.
TransCommitSync()
Synchronizes committed transactions produced by other master processes attached to the same shared-memory database.
EnableFilter(bool enabled)
Enables or disables replication filtering for classes marked as local.
GetMode()
Returns the current HA mode flags for the master connection.

Typical usage: create MasterConnection, configure a MasterConnection.Parameters instance, call SetReplicationMode(), accept or manage replica connections, and finally call Disconnect() or Dispose() to release HA resources.