1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2009 Oracle. All rights reserved. 5 * 6 */ 7using System; 8using System.Collections.Generic; 9using System.Text; 10using BerkeleyDB.Internal; 11 12namespace BerkeleyDB { 13 /// <summary> 14 /// A class representing configuration parameters for a 15 /// <see cref="DatabaseEnvironment"/>'s locking subsystem. 16 /// </summary> 17 public class LockingConfig { 18 private byte[,] _conflicts; 19 private int _nmodes; 20 /// <summary> 21 /// The locking conflicts matrix. 22 /// </summary> 23 /// <remarks> 24 /// <para> 25 /// If Conflicts is never set, a standard conflicts array is used; see 26 /// Standard Lock Modes in the Programmer's Reference Guide for more 27 /// information. 28 /// </para> 29 /// <para> 30 /// Conflicts parameter is an nmodes by nmodes array. A non-0 value for 31 /// the array element indicates that requested_mode and held_mode 32 /// conflict: 33 /// <code> 34 /// conflicts[requested_mode][held_mode] 35 /// </code> 36 /// </para> 37 /// <para>The not-granted mode must be represented by 0.</para> 38 /// <para> 39 /// If the database environment already exists when 40 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of 41 /// Conflicts will be ignored. 42 /// </para> 43 /// </remarks> 44 public byte[,] Conflicts { 45 get { return _conflicts; } 46 set { 47 double sz; 48 sz = Math.Sqrt(value.Length); 49 if (Math.Truncate(sz) == sz) { 50 _conflicts = value; 51 _nmodes = (int)sz; 52 } else 53 throw new ArgumentException("Conflicts matrix must be square."); 54 } 55 } 56 57 private uint _maxlockers; 58 internal bool maxLockersIsSet; 59 /// <summary> 60 /// The maximum number of simultaneous locking entities supported by the 61 /// Berkeley DB environment 62 /// </summary> 63 /// <remarks> 64 /// <para> 65 /// This value is used by <see cref="DatabaseEnvironment.Open"/> to 66 /// estimate how much space to allocate for various lock-table data 67 /// structures. The default value is 1000 lockers. For specific 68 /// information on configuring the size of the lock subsystem, see 69 /// Configuring locking: sizing the system in the Programmer's Reference 70 /// Guide. 71 /// </para> 72 /// <para> 73 /// If the database environment already exists when 74 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of 75 /// MaxLockers will be ignored. 76 /// </para> 77 /// </remarks> 78 public uint MaxLockers { 79 get { return _maxlockers; } 80 set { 81 maxLockersIsSet = true; 82 _maxlockers = value; 83 } 84 } 85 private uint _maxlocks; 86 internal bool maxLocksIsSet; 87 /// <summary> 88 /// The maximum number of locks supported by the Berkeley DB 89 /// environment. 90 /// </summary> 91 /// <remarks> 92 /// <para> 93 /// This value is used by <see cref="DatabaseEnvironment.Open"/> to 94 /// estimate how much space to allocate for various lock-table data 95 /// structures. The default value is 1000 lockers. For specific 96 /// information on configuring the size of the lock subsystem, see 97 /// Configuring locking: sizing the system in the Programmer's Reference 98 /// Guide. 99 /// </para> 100 /// <para> 101 /// If the database environment already exists when 102 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of 103 /// MaxLocks will be ignored. 104 /// </para> 105 /// </remarks> 106 public uint MaxLocks { 107 get { return _maxlocks; } 108 set { 109 maxLocksIsSet = true; 110 _maxlocks = value; 111 } 112 } 113 private uint _maxobjects; 114 internal bool maxObjectsIsSet; 115 /// <summary> 116 /// The maximum number of locked objects supported by the Berkeley DB 117 /// environment. 118 /// </summary> 119 /// <remarks> 120 /// <para> 121 /// This value is used by <see cref="DatabaseEnvironment.Open"/> to 122 /// estimate how much space to allocate for various lock-table data 123 /// structures. The default value is 1000 lockers. For specific 124 /// information on configuring the size of the lock subsystem, see 125 /// Configuring locking: sizing the system in the Programmer's Reference 126 /// Guide. 127 /// </para> 128 /// <para> 129 /// If the database environment already exists when 130 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of 131 /// MaxObjects will be ignored. 132 /// </para> 133 /// </remarks> 134 public uint MaxObjects { 135 get { return _maxobjects; } 136 set { 137 maxObjectsIsSet = true; 138 _maxobjects = value; 139 } 140 } 141 private uint _partitions; 142 internal bool partitionsIsSet; 143 /// <summary> 144 /// The number of lock table partitions in the Berkeley DB environment. 145 /// </summary> 146 /// <remarks> 147 /// <para> 148 /// The default value is 10 times the number of CPUs on the system if 149 /// there is more than one CPU. Increasing the number of partitions can 150 /// provide for greater throughput on a system with multiple CPUs and 151 /// more than one thread contending for the lock manager. On single 152 /// processor systems more than one partition may increase the overhead 153 /// of the lock manager. Systems often report threading contexts as 154 /// CPUs. If your system does this, set the number of partitions to 1 to 155 /// get optimal performance. 156 /// </para> 157 /// <para> 158 /// If the database environment already exists when 159 /// <see cref="DatabaseEnvironment.Open"/> is called, the value of 160 /// Partitions will be ignored. 161 /// </para> 162 /// </remarks> 163 public uint Partitions { 164 get { return _partitions; } 165 set { 166 partitionsIsSet = true; 167 _partitions = value; 168 } 169 } 170 171 /// <summary> 172 /// If non-null, the deadlock detector is to be run whenever a lock 173 /// conflict occurs, lock request(s) should be rejected according to the 174 /// specified policy. 175 /// </summary> 176 /// <remarks> 177 /// <para> 178 /// As transactions acquire locks on behalf of a single locker ID, 179 /// rejecting a lock request associated with a transaction normally 180 /// requires the transaction be aborted. 181 /// </para> 182 /// </remarks> 183 public DeadlockPolicy DeadlockResolution; 184 } 185} 186