/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace BerkeleyDB {
///
/// A class representing configuration parameters for a
/// 's replication subsystem.
///
public class ReplicationConfig {
///
/// Instantiate a new ReplicationConfig object with default
/// configuration values.
///
public ReplicationConfig() {
AutoInit = true;
Elections = true;
RepmgrSitesConfig = new List();
}
#region Config Flags
///
/// If true, the replication master sends groups of records to the
/// clients in a single network transfer
///
public bool BulkTransfer;
///
/// If true, the client delays synchronizing to a newly declared
/// master (defaults to false). Clients configured in this way
/// remain unsynchronized until the application calls
/// .
///
public bool DelayClientSync;
///
/// If true, replication only stores the internal information in-memory
/// and cannot keep persistent state across a site crash or reboot. By
/// default, it is false and replication creates files in the
/// environment home directory to preserve the internal information.
/// This configuration flag can only be set before the
/// is opened.
///
public bool InMemory;
///
/// If true, master leases are used for this site (defaults to
/// false).
///
///
/// Configuring this option may result in a
/// when attempting to read entries
/// from a database after the site's master lease has expired.
///
public bool UseMasterLeases;
///
/// If true, the replication master automatically re-initializes
/// outdated clients (defaults to true).
///
public bool AutoInit;
///
/// If true, Berkeley DB method calls that would normally block while
/// clients are in recovery will return errors immediately (defaults to
/// false).
///
public bool NoBlocking;
///
/// If true, the Replication Manager observes the strict "majority"
/// rule in managing elections, even in a group with only 2 sites. This
/// means the client in a 2-site group is unable to take over as
/// master if the original master fails or becomes disconnected. (See
/// the Elections section in the Berkeley DB Reference Guide for more
/// information.) Both sites in the replication group should have the
/// same value for this parameter.
///
public bool Strict2Site;
///
/// If true, Replication Manager automatically runs elections to
/// choose a new master when the old master appears to
/// have become disconnected (defaults to true).
///
public bool Elections;
///
/// This flag is used to specify the preferred master site in a
/// replication group operating in preferred master mode. A preferred
/// master replication group must contain only two sites, with one site
/// specified as the preferred master site and the other site specified
/// as the client site. The preferred master site operates as the
/// master site whenever possible.
///
public bool PrefmasMaster;
///
/// This flag is used to specify the client site in a replication group
/// operating in preferred master mode. A preferred master replication
/// group must contain only two sites, with one site specified as the
/// preferred master site and the other site specified as the client
/// site. The client site in a preferred master replication group takes
/// over temporarily as master when the preferred master site is
/// unavailable.
///
public bool PrefmasClient;
#endregion Config Flags
#region Timeout Values
private uint _ackTimeout;
internal bool ackTimeoutIsSet;
///
/// The amount of time the replication manager's transport function
/// waits to collect enough acknowledgments from replication group
/// clients, before giving up and returning a failure indication. The
/// default wait time is 1 second.
///
public uint AckTimeout {
get { return _ackTimeout; }
set {
_ackTimeout = value;
ackTimeoutIsSet = true;
}
}
private uint _checkpointDelay;
internal bool checkpointDelayIsSet;
///
/// The amount of time a master site delays between completing a
/// checkpoint and writing a checkpoint record into the log.
///
///
/// This delay allows clients to complete their own checkpoints before
/// the master requires completion of them. The default is 30 seconds.
/// If all databases in the environment, and the environment's
/// transaction log, are configured to reside in-memory (never preserved
/// to disk), then, although checkpoints are still necessary, the delay
/// is not useful and should be set to 0.
///
public uint CheckpointDelay {
get { return _checkpointDelay; }
set {
_checkpointDelay = value;
checkpointDelayIsSet = true;
}
}
private uint _connectionRetry;
internal bool connectionRetryIsSet;
///
/// The amount of time the replication manager waits before trying
/// to re-establish a connection to another site after a communication
/// failure. The default wait time is 30 seconds.
///
public uint ConnectionRetry {
get { return _connectionRetry; }
set {
_connectionRetry = value;
connectionRetryIsSet = true;
}
}
private uint _electionTimeout;
internal bool electionTimeoutIsSet;
///
/// The timeout period for an election. The default timeout is 2
/// seconds.
///
public uint ElectionTimeout {
get { return _electionTimeout; }
set {
_electionTimeout = value;
electionTimeoutIsSet = true;
}
}
private uint _electionRetry;
internal bool electionRetryIsSet;
///
/// Configure the amount of time the replication manager waits
/// before retrying a failed election. The default wait time is 10
/// seconds.
///
public uint ElectionRetry {
get { return _electionRetry; }
set {
_electionRetry = value;
electionRetryIsSet = true;
}
}
private uint _fullElectionTimeout;
internal bool fullElectionTimeoutIsSet;
///
/// An optional configuration timeout period to wait for full election
/// participation the first time the replication group finds a master.
/// By default this option is turned off and normal election timeouts
/// are used. (See the Elections section in the Berkeley DB Reference
/// Guide for more information.)
///
public uint FullElectionTimeout {
get { return _fullElectionTimeout; }
set {
_fullElectionTimeout = value;
fullElectionTimeoutIsSet = true;
}
}
private uint _heartbeatMonitor;
internal bool heartbeatMonitorIsSet;
///
/// The amount of time the replication manager, running at a client
/// site, waits for some message activity on the connection from the
/// master (heartbeats or other messages) before concluding that the
/// connection has been lost. When 0 (the default), no monitoring is
/// performed.
///
public uint HeartbeatMonitor {
get { return _heartbeatMonitor; }
set {
_heartbeatMonitor = value;
heartbeatMonitorIsSet = true;
}
}
private uint _heartbeatSend;
internal bool heartbeatSendIsSet;
///
/// The frequency at which the replication manager, running at a master
/// site, broadcasts a heartbeat message in an otherwise idle system.
/// When 0 (the default), no heartbeat messages are sent.
///
public uint HeartbeatSend {
get { return _heartbeatSend; }
set {
_heartbeatSend = value;
heartbeatSendIsSet = true;
}
}
private uint _leaseTimeout;
internal bool leaseTimeoutIsSet;
///
/// The amount of time a client grants its master lease to a master.
/// When using master leases all sites in a replication group must use
/// the same lease timeout value. There is no default value. If leases
/// are desired, this method must be called prior to calling
/// or
/// .
///
public uint LeaseTimeout {
get { return _leaseTimeout; }
set {
_leaseTimeout = value;
leaseTimeoutIsSet = true;
}
}
#endregion Timeout Values
private uint _clockskewFast;
private uint _clockskewSlow;
internal bool clockskewIsSet;
///
/// The value, relative to , of the fastest
/// clock in the group of sites.
///
public uint ClockskewFast { get { return _clockskewFast; } }
///
/// The value of the slowest clock in the group of sites.
///
public uint ClockskewSlow { get { return _clockskewSlow; } }
///
/// Set the clock skew ratio among replication group members based on
/// the fastest and slowest measurements among the group for use with
/// master leases.
///
///
///
/// Calling this method is optional, the default values for clock skew
/// assume no skew. The user must also configure leases via
/// . Additionally, the user must also
/// set the master lease timeout via and
/// the number of sites in the replication group via
/// . These settings may be configured in any
/// order. For a description of the clock skew values, see Clock skew
/// in the Berkeley DB Programmer's Reference Guide. For a description
/// of master leases, see Master leases in the Berkeley DB Programmer's
/// Reference Guide.
///
///
/// These arguments can be used to express either raw measurements of a
/// clock timing experiment or a percentage across machines. For
/// instance a group of sites have a 2% variance, then
/// should be set to 102, and
/// should be set to 100. Or, for a 0.03%
/// difference, you can use 10003 and 10000 respectively.
///
///
///
/// The value, relative to , of the fastest clock
/// in the group of sites.
///
///
/// The value of the slowest clock in the group of sites.
///
public void Clockskew(uint fast, uint slow) {
clockskewIsSet = true;
_clockskewSlow = slow;
_clockskewFast = fast;
}
private uint _nsites;
internal bool nsitesIsSet;
///
/// The total number of sites in the replication group.
///
///
///
/// This setting is typically used by applications which use the
/// Berkeley DB library "replication manager" support. (However, see
/// also , the
/// description of the nsites parameter.)
///
///
public uint NSites {
get { return _nsites; }
set {
_nsites = value;
nsitesIsSet = true;
}
}
private uint _priority;
internal bool priorityIsSet;
///
/// The database environment's priority in replication group elections.
/// A special value of 0 indicates that this environment cannot be a
/// replication group master. If not configured, then a default value
/// of 100 is used.
///
public uint Priority {
get { return _priority; }
set {
_priority = value;
priorityIsSet = true;
}
}
private ReplicationViewDelegate replicationView;
internal bool repViewIsSet;
///
/// Create a replication view and specify the function to determine
/// whether a database file is replicated to the local site.
///
///
/// If it is null, the replication view is a full view and all database
/// files are replicated to the local site. Otherwise it is a partial
/// view and only some database files are replicated to the local site.
///
public ReplicationViewDelegate ReplicationView {
get { return replicationView; }
set {
repViewIsSet = true;
replicationView = value;
}
}
private uint _retransmissionRequestMin;
private uint _retransmissionRequestMax;
internal bool retransmissionRequestIsSet;
///
/// The minimum number of microseconds a client waits before requesting
/// retransmission.
///
public uint RetransmissionRequestMin {
get { return _retransmissionRequestMin; }
}
///
/// The maximum number of microseconds a client waits before requesting
/// retransmission.
///
public uint RetransmissionRequestMax {
get { return _retransmissionRequestMax; }
}
///
/// Set a threshold for the minimum and maximum time that a client waits
/// before requesting retransmission of a missing message.
///
///
///
/// If the client detects a gap in the sequence of incoming log records
/// or database pages, Berkeley DB waits for at least
/// microseconds before requesting retransmission
/// of the missing record. Berkeley DB doubles that amount before
/// requesting the same missing record again, and so on, up to a
/// maximum threshold of microseconds.
///
///
/// These values are thresholds only. Replication Manager applications
/// use these values to determine when to automatically request
/// retransmission of missing messages. For Base API applications,
/// Berkeley DB has no thread available in the library as a timer, the
/// threshold is only checked when a thread enters the Berkeley DB
/// library to process an incoming replication message. Any amount of
/// time may have passed since the last message arrived and Berkeley DB
/// only checks whether the amount of time since a request was made is
/// beyond the threshold value or not.
///
///
/// By default the minimum is 40000 and the maximum is 1280000 (1.28
/// seconds). These defaults are fairly arbitrary and the application
/// likely needs to adjust these. The values should be based on expected
/// load and performance characteristics of the master and client host
/// platforms and transport infrastructure as well as round-trip message
/// time.
///
///
/// The minimum number of microseconds a client waits before requesting
/// retransmission.
///
///
/// The maximum number of microseconds a client waits before requesting
/// retransmission.
///
public void RetransmissionRequest(uint min, uint max) {
retransmissionRequestIsSet = true;
_retransmissionRequestMin = min;
_retransmissionRequestMax = max;
}
private uint _gbytes;
private uint _bytes;
internal bool transmitLimitIsSet;
///
/// The gigabytes component of the byte-count limit on the amount of
/// data that is transmitted from a site in response to a single
/// message processed by
/// .
///
public uint TransmitLimitGBytes { get { return _gbytes; } }
///
/// The bytes component of the byte-count limit on the amount of data
/// that is transmitted from a site in response to a single
/// message processed by
/// .
///
public uint TransmitLimitBytes { get { return _bytes; } }
///
/// Set a byte-count limit on the amount of data that is
/// transmitted from a site in response to a single message processed by
/// . The limit is
/// not a hard limit, and the record that exceeds the limit is the last
/// record to be sent.
///
///
///
/// Record transmission throttling is turned on by default with a limit
/// of 10MB.
///
///
/// If both and are
/// zero, then the transmission limit is turned off.
///
///
///
/// The number of gigabytes which, when added to
/// , specifies the maximum number of bytes that
/// are sent in a single call to
/// .
///
///
/// The number of bytes which, when added to
/// , specifies the maximum number of bytes
/// that are sent in a single call to
/// .
///
public void TransmitLimit(uint GBytes, uint Bytes) {
transmitLimitIsSet = true;
_gbytes = GBytes;
_bytes = Bytes;
}
private uint _inqmaxgbytes;
private uint _inqmaxbytes;
internal bool repmgrIncomingQueueMaxIsSet;
///
/// The gigabytes component of the maximum amount of dynamic memory
/// used by the Replication Manager incoming queue.
///
public uint RepmgrIncomingQueueMaxGBytes { get { return _inqmaxgbytes; } }
///
/// The bytes component of the maximum amount of dynamic memory
/// used by the Replication Manager incoming queue.
///
public uint RepmgrIncomingQueueMaxBytes { get { return _inqmaxbytes; } }
///
/// Set a byte-count limit on the maximum amount of dynamic memory
/// used by the Replication Manager incoming queue.
///
///
///
/// By default, the Replication Manager incoming queue size has a
/// limit of 100MB.
///
///
/// If both and are
/// zero, then the Replication Manager incoming queue size is limited
/// by available heap memory.
///
///
///
/// The number of gigabytes which, when added to
/// , specifies the maximum amount of dynamic
/// memory used by the Replication Manager incoming queue.
///
///
/// The number of bytes which, when added to
/// , specifies the maximum amount of dynamic
/// memory used by the Replication Manager incoming queue.
///
public void RepmgrIncomingQueueMax(uint GBytes, uint Bytes) {
repmgrIncomingQueueMaxIsSet = true;
_inqmaxgbytes = GBytes;
_inqmaxbytes = Bytes;
}
///
/// The delegate used to transmit data using the replication
/// application's communication infrastructure.
///
public ReplicationTransportDelegate Transport;
///
/// Specify how master and client sites handle the acknowledgment of
/// replication messages which is necessary for "permanent" records.
/// The current implementation requires all sites in a replication group
/// to configure the same acknowledgement policy.
///
///
public AckPolicy RepMgrAckPolicy;
///
/// A list of site configurations.
///
public List RepmgrSitesConfig;
}
}