The C# ReplicaConnection Class

ReplicaConnection extends the Connection class for HA replica applications. A replica should use this class instead of Connection and typically configure replication through ReplicaConnection.Parameters before calling AttachMaster().

For an overview see page C# Classes

Class Definition

    public class ReplicaConnection : Connection
    {
        // ===== HA MODE FLAGS (constants) =====
        public const int MCO_HAMODE_FORCE_MASTER = 0x4000;
        public const int MCO_HAMODE_FORCE_SYNC = 0x10000;
        public const int MCO_HAMODE_SEND_RESTLIST = 0x20000;
        public const int MCO_HAMODE_EXPLICIT_WRITE_ACCESS = 0x40000;

        // ===== NESTED ENUM: NotificationCode =====
        public enum NotificationCode {
            Connected, ConnectFailed, DbEqual, DbLoadBegin, DbLoadFailed,
            DbLoadOK, CommitFailed, ReplicaStopped, DbCreationFailed,
            HotSync, HotSyncEnd, StatefulSync, StatefulSyncEnd,
            MasterDbExtended, MasterDbCleaned
        }

        // ===== NESTED DELEGATE =====
        public delegate void ReplicaNotifyDelegate(NotificationCode code, long param);

        // ===== NESTED CLASS: Parameters =====
        public class Parameters
        {
            public const int MSEC = 1000;

            // Configuration Fields
            public int CommitTimeout;
            public int InitialTimeout;
            public int WaitDataTimeout;
            public int RepeatCounter;
            public int McastPort;
            public String McastAddr;
            public Database.CommitPolicy InitialCommitPolicy;
            public int InitialObjsInTrans;
            public int BatchCommitLength;
            public int BatchCommitBSize;
            public int BatchCommitPeriod;
            public int ModeFlags;
            public ReplicaNotifyDelegate NotifyDelegate;
            public String CancelpointAddr;
            public TransIterator.Iterator Iterator;
            public Database.SSLParameters SSLParameters;
            public int CompressionLevel;

            // Constructors
            public Parameters();
            public Parameters(int mode);
        }

        // ===== CONSTRUCTOR =====
        public ReplicaConnection(Database db);

        // ===== REPLICATION CONTROL METHODS =====
        public bool AttachMaster(String connectionString, Parameters parameters, int timeout);
        public void StopReplication();
        public void EnableFilter(bool enabled);
        public void Cancel(String cancelAddr, int timeout);
    }

Member Descriptions

MCO_HAMODE_FORCE_MASTER
Flag: switch to master role after initial synchronization completes. Use when the replica should automatically promote itself if the master becomes unavailable.
MCO_HAMODE_FORCE_SYNC
Flag: force synchronous replication mode. Transactions on the master wait for acknowledgment from this replica before committing, providing stronger consistency at the cost of latency.
MCO_HAMODE_SEND_RESTLIST
Flag: send the list of registered REST interfaces from the replica to the master during connection setup. This can be used for dynamic REST endpoint synchronization in HA deployments.
MCO_HAMODE_EXPLICIT_WRITE_ACCESS
Flag: do not restore WRITE access automatically when the master disconnects. This allows application logic to control write enablement explicitly during failover.
NotificationCode enum
Replication lifecycle events reported via ReplicaNotifyDelegate, including connection status, synchronization progress, commit failures, replica stop notifications, and master database state changes.
ReplicaNotifyDelegate
Callback delegate for receiving replication notifications. Signature: void(NotificationCode code, long param).
Parameters class
Configuration container for HA replica connection tuning. It controls timeouts, batching, multicast settings, notification callbacks, compression, and failover-related behavior.
Parameters.CommitTimeout / WaitDataTimeout / RepeatCounter
CommitTimeout is the commit timeout, WaitDataTimeout is the wait time for incoming data, and RepeatCounter controls how many times a commit is retried if the master does not answer. These values let the application balance responsiveness and network tolerance.
Parameters.InitialTimeout / InitialCommitPolicy / InitialObjsInTrans
Initial synchronization settings: maximum wait time (InitialTimeout), disk commit policy during initial synchronization (InitialCommitPolicy), and number of objects per transaction (InitialObjsInTrans).
Parameters.BatchCommitLength / BatchCommitBSize / BatchCommitPeriod
Replica-side commit batching settings: maximum merged transaction count, maximum merged byte size, and maximum delay period in milliseconds. These controls can improve throughput by merging incoming changes on the replica side.
Parameters.McastPort / McastAddr
Multicast settings for replication transport: multicast port and multicast group address for one-to-many replication topologies.
Parameters.ModeFlags
Bitmask combining MCO_HAMODE_* constants to control replica behavior, including failover, synchronization mode, REST-list transfer, and write-access policy.
Parameters.NotifyDelegate / CancelpointAddr / Iterator
Advanced hooks for custom replication control: notification callback, cancelpoint address, and transaction iterator for fine-grained replication behavior. See TransIterator for the built-in JSON iterator classes.
Parameters.SSLParameters / CompressionLevel
Security and performance settings: SSL/TLS configuration (SSLParameters) and network compression level (CompressionLevel, 0-9, where 0 disables compression).
Parameters() / Parameters(int mode)
Constructors initializing parameters with default values. The overload accepts the initial ModeFlags bitmask. Defaults include a 10-second commit timeout, a 60-second initial synchronization timeout, delayed initial commits, 100 objects per transaction during initial synchronization, a multicast address of 224.0.0.1, and no multicast port.
ReplicaConnection(Database)
Creates a replica connection instance for the specified database. The database is typically opened with Database.Mode.HighAvailabilitySupport. Call AttachMaster() to begin replication.
AttachMaster(String, Parameters, int)
Attaches the replica to the master application. For TCP/UDP transport, connectionString is typically "host:port" (for example, "192.168.0.1:10000"). Returns true when the master is connected successfully and false if the connection cannot be established within the specified timeout.
StopReplication()
Terminates the replica's wait for updates from the master. The replica stops receiving new transactions but retains its current database state.
EnableFilter(bool)
Enables or disables replication filtering for classes marked as local. This allows replica-specific local data to coexist with replicated classes.
Cancel(String, int)
Instantly interrupts replication processing using the specified cancelpoint address and timeout. This is useful for administrative interruption or failover handling.
HA Prerequisites
Replica applications typically open the database with Database.Mode.HighAvailabilitySupport. If SSL is used, initialize the SSL layer and populate Parameters.SSLParameters before calling AttachMaster().
Replication Workflow
Typical usage: create ReplicaConnection -> configure Parameters -> optionally assign NotifyDelegate -> call AttachMaster() -> process replicated data -> call StopReplication() or Disconnect() when shutting down.
Thread Safety
ReplicaConnection instances are not thread-safe. Use one instance per thread. The underlying Connection base class enforces thread-affinity for database operations.
Failover Considerations
Use MCO_HAMODE_FORCE_MASTER and MCO_HAMODE_EXPLICIT_WRITE_ACCESS with care. Automatic promotion and write-restoration behavior should match the application's failover policy.