| 1 |
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en"> |
| 2 |
|
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" |
| 6 |
content="text/html; charset=iso-8859-1"> |
| 7 |
<meta name="GENERATOR" |
| 8 |
content="Mozilla/4.76 [en] (X11; U; FreeBSD 4.3-RELEASE i386) [Netscape]"> |
| 9 |
<title>Master Lease</title> |
| 10 |
</head> |
| 11 |
<body> |
| 12 |
<center> |
| 13 |
<h1>Master Leases for Berkeley DB</h1> |
| 14 |
</center> |
| 15 |
<center><i>Susan LoVerso</i> <br> |
| 16 |
<i>[email protected]</i> <br> |
| 17 |
<i>Rev 1.1</i><br> |
| 18 |
<i>2007 Feb 2</i><br> |
| 19 |
</center> |
| 20 |
<p><br> |
| 21 |
</p> |
| 22 |
<h2>What are Master Leases?</h2> |
| 23 |
A master lease is a mechanism whereby clients grant master-ship rights |
| 24 |
to a site and that master, by holding lease rights can provide a |
| 25 |
guarantee of durability to a replication group for a given period of |
| 26 |
time. By granting a lease to a master, |
| 27 |
a client will not participate in an election to elect a new |
| 28 |
master until that granted master lease has expired. By holding a |
| 29 |
collection of granted leases, a master will be able to supply |
| 30 |
authoritative read requests to applications. By holding leases a |
| 31 |
read operation on a master can guarantee several things to the |
| 32 |
application:<br> |
| 33 |
<ol> |
| 34 |
<li>Authoritative reads: a guarantee that the data being read by the |
| 35 |
application is durable and can never be rolled back.</li> |
| 36 |
<li>Freshness: a guarantee that the data being read by the |
| 37 |
application <b>at the master</b> is |
| 38 |
not stale.</li> |
| 39 |
<li>Master viability: a guarantee that a current master with valid |
| 40 |
leases will not encounter a duplicate master situation.<br> |
| 41 |
</li> |
| 42 |
</ol> |
| 43 |
<h2>Requirements</h2> |
| 44 |
The requirements of DB to support this include:<br> |
| 45 |
<ul> |
| 46 |
<li>After turning them on, users can choose to ignore them in reads |
| 47 |
or not.</li> |
| 48 |
<li>We are providing read authority on the master only. A |
| 49 |
read on a client is equivalent to a read while ignoring leases.</li> |
| 50 |
<li>We guarantee that data committed on a master <b>that has been |
| 51 |
read by an application on the |
| 52 |
master</b> will not be rolled back. Data read on a client or |
| 53 |
while ignoring leases <i>or data |
| 54 |
successfully updated/committed but not read,</i> |
| 55 |
may be rolled back.<br> |
| 56 |
</li> |
| 57 |
<li>A master will not return successfully from a read operation |
| 58 |
unless it holds a |
| 59 |
majority of leases unless leases are ignored.</li> |
| 60 |
<li>Master leases will remove the possibility of a current/correct |
| 61 |
master being "shot down" by DUPMASTER. <b>NOTE: Old/Expired |
| 62 |
masters may discover a |
| 63 |
later master and return DUPMASTER to the application however.</b><br> |
| 64 |
</li> |
| 65 |
<li>Any send callback failure must result in premature lease |
| 66 |
expiration on the master.<br> |
| 67 |
</li> |
| 68 |
<li>Users who change the system clock during master leases void the |
| 69 |
guarantee and may get undefined behavior. We assume time always |
| 70 |
runs forward. <br> |
| 71 |
</li> |
| 72 |
<li>Clients are forbidden from participating in elections while they |
| 73 |
have an outstanding lease granted to another site.</li> |
| 74 |
<li>Clients are forbidden from accepting a new master while they have |
| 75 |
an outstanding lease granted to another site.</li> |
| 76 |
<li>Clients are forbidden from upgrading themselves to master while |
| 77 |
they have an outstanding lease granted to another site.</li> |
| 78 |
<li>When asked for a lease grant explicitly by the master, the client |
| 79 |
cannot grant the lease to the master unless the LSN in the master's |
| 80 |
request has been processed by this client.<br> |
| 81 |
</li> |
| 82 |
</ul> |
| 83 |
The requirements of the |
| 84 |
application using leases include:<br> |
| 85 |
<ul> |
| 86 |
<li>Users must implement (Base API users on their own, RepMgr users |
| 87 |
via configuration) a majority (or larger) ACK policy. <br> |
| 88 |
</li> |
| 89 |
<li>The application must use the election mechanism to decide a master. |
| 90 |
It may not simply declare a site master.</li> |
| 91 |
<li>The send callback must return an error if the majority ACK policy |
| 92 |
is not met for PERM records.</li> |
| 93 |
<li>Users must set the number of sites in the group.</li> |
| 94 |
<li>Using leases in a replication group is all-or-none. |
| 95 |
Therefore, if a site knows it is using leases, it can assume other |
| 96 |
sites are also.<br> |
| 97 |
</li> |
| 98 |
<li>All applications that care about read guarantees must forward or |
| 99 |
perform all reads on the master. Reading on the client means a |
| 100 |
read ignoring leases. </li> |
| 101 |
</ul> |
| 102 |
<p>There are some open questions |
| 103 |
remaining.</p> |
| 104 |
<ul> |
| 105 |
<li>There is one major showstopper issue, see Crashing - Potential |
| 106 |
problem near the end of the document. We need a better solution |
| 107 |
than the one shown there (writing to disk every time a lease is |
| 108 |
granted). Perhaps just documenting that durability means it must be |
| 109 |
flushed to disk before success to avoid that situation?<br> |
| 110 |
</li> |
| 111 |
<li>What about db->join? Users can call join, but the calls |
| 112 |
on the join cursor to get the data would be subject to leases and |
| 113 |
therefore protected. Ok, this is not an open question.</li> |
| 114 |
<li>What about other read-like operations? Clearly <i> |
| 115 |
DB->get, DB->pget, DBC->get, |
| 116 |
DBC->pget</i> need lease checks. However, other APIs use |
| 117 |
keys. <i>DB->key_range</i> |
| 118 |
provides an estimate only so it shouldn't need lease checks. <i> |
| 119 |
DB->stat</i> provides exact counts |
| 120 |
to <i>bt_nkeys</i> and <i>bt_ndata</i> fields. Are those |
| 121 |
fields considered authoritative that providing those values implies a |
| 122 |
durability guarantee and therefore <i>DB->stat</i> |
| 123 |
should be subject to lease verification? <i>DBC->count</i> |
| 124 |
provides a count for |
| 125 |
the number of data items associated with a key. Is this |
| 126 |
authoritative information? This is similar to stat - should it be |
| 127 |
subject to lease verification?<br> |
| 128 |
</li> |
| 129 |
<li>Do we require master lease checks on write operations? I |
| 130 |
think lease checks are not needed on write operations. It doesn't |
| 131 |
add correctness and adds a lot of complexity (checking leases in put, |
| 132 |
del, and cursors, then what about rename, remove, etc).<br> |
| 133 |
</li> |
| 134 |
<li>Do master leases give an iron-clad guarantee of never rolling |
| 135 |
back a transaction? No, but it should mean that a committed transaction |
| 136 |
can never be <b>read</b> on a master |
| 137 |
unless the lease is valid. A committed transaction on a master |
| 138 |
that has never been presented to the application may get rolled back.<br> |
| 139 |
</li> |
| 140 |
<li>Do we need to quarantine or prevent reads on an ex-master until |
| 141 |
sync-up is done? No. A master that is simply downgraded to |
| 142 |
client or crashes and reboots is now a client. Reading from that |
| 143 |
client is the same as saying Ignore Leases.</li> |
| 144 |
<li>What about adding and removing sites while leases are |
| 145 |
active? This is SR 14778. A consistent <i>nsites</i> value |
| 146 |
is required by master |
| 147 |
leases. It isn't |
| 148 |
clear to me what a master is |
| 149 |
supposed to do if the value of nsites gets smaller while leases are |
| 150 |
active. Perhaps it leaves its larger table intact and simply |
| 151 |
checks for a smaller number of granted leases?<br> |
| 152 |
</li> |
| 153 |
<li>Can users turn leases off? No. There is no planned <i>turn |
| 154 |
leases off</i> API.</li> |
| 155 |
<li>Clock skew will be a percentage. However, the smallest, 1%, |
| 156 |
is probably rather large for clock skew. Percentage was chosen |
| 157 |
for simplicity and similarity to other APIs. What granularity is |
| 158 |
appropriate here?</li> |
| 159 |
</ul> |
| 160 |
<h2>API Changes</h2> |
| 161 |
The API changes that are visible |
| 162 |
to the user are fairly minimal. |
| 163 |
There are a few API calls they need to make to configure master leases |
| 164 |
and then there is the API call to turn them on. There is also a |
| 165 |
new flag to existing APIs to allow read operations to ignore leases and |
| 166 |
return data that |
| 167 |
may be non-durable potentially.<br> |
| 168 |
<h3>Lease Timeout<br> |
| 169 |
</h3> |
| 170 |
There is a new timout the user |
| 171 |
must configure for leases called <b>DB_REP_LEASE_TIMEOUT</b>. |
| 172 |
This timeout will be new to |
| 173 |
the <i>dbenv->rep_set_timeout</i> method. The <b>DB_REP_LEASE_TIMEOUT</b> |
| 174 |
has no default and it is required that the user configure a timeout |
| 175 |
before they turn on leases (obviously, this timeout need not be set of |
| 176 |
leases will not be used). That timeout is the amount of time |
| 177 |
the lease is valid on the master and how long it is granted |
| 178 |
on the client. This timeout must be the same |
| 179 |
value on all sites (like log file size). The timeout used when |
| 180 |
refreshing leases is the <b>DB_REP_ACK_TIMEOUT</b> |
| 181 |
for RepMgr application. For Base API applications, lease |
| 182 |
refreshes will use the same mechanism as <b>PERM</b> messages and they |
| 183 |
should |
| 184 |
have no additional burden. This timeout is used for lease |
| 185 |
refreshment and is the amount of time a reader will wait to refresh |
| 186 |
leases before returning failure to the application from a read |
| 187 |
operation.<br> |
| 188 |
<br> |
| 189 |
This timeout will be both stored |
| 190 |
with its original value, and also |
| 191 |
converted to a <i>db_timespec</i> |
| 192 |
using the <b>DB_TIMEOUT_TO_TIMESPEC</b> |
| 193 |
macro and have the clock skew accounted for and stored in the shared |
| 194 |
rep structure:<br> |
| 195 |
<pre>db_timeout_t lease_timeout;<br>db_timespec lease_duration;<br></pre> |
| 196 |
NOTE: By sending the lease refresh during DB operations, we are |
| 197 |
forcing/assuming that the operation's process has a replication |
| 198 |
transport function set. That is obviously the case for write |
| 199 |
operations, but would it be a burden for read processes (on a |
| 200 |
master)? I think mostly not, but if we need leases for <i> |
| 201 |
DB->stat</i> then we need to |
| 202 |
document it as it is certainly possible for an application to have a |
| 203 |
separate or dedicated <i>stat</i> |
| 204 |
application or attempt to use <i>db_stat</i> |
| 205 |
(which will not work if leases must be checked).<br> |
| 206 |
<br> |
| 207 |
Leases should be checked after the local operation so that we don't |
| 208 |
have a window/boundary if we were to check leases first, get |
| 209 |
descheduled, the lose our lease and then perform the operation. |
| 210 |
Do the operation, then check leases before returning to the user.<br> |
| 211 |
<h3>Using Leases</h3> |
| 212 |
There is a new API that the user must call to tell the system to use |
| 213 |
the lease mechanism. The method must be called before the |
| 214 |
application calls <i>dbenv->rep_start</i> |
| 215 |
or <i>dbenv->repmgr_start</i>. |
| 216 |
This new |
| 217 |
method is:<br> |
| 218 |
<br> |
| 219 |
<pre> dbenv->rep_set_lease(DB_ENV *dbenv, u_int32_t clock_scale_factor, u_int32_t flags)<br> |
| 220 |
</pre> |
| 221 |
The <i>clock_scale_factor</i> |
| 222 |
parameter is interpreted as a percentage, greater than 100 (to transmit |
| 223 |
a floating point number as an integer to the API) that represents the |
| 224 |
maximum shkew between any two sites' clocks. That is, a <span |
| 225 |
style="font-style: italic;">clock_scale_factor</span> of 150 suggests |
| 226 |
that the greatest discrepancy between clocks is that one runs 50% |
| 227 |
faster than the others. Both the |
| 228 |
master and client sides |
| 229 |
compensate for possible clock skew. The master uses the value to |
| 230 |
compensate in case the replica has a slow clock and replicas compensate |
| 231 |
in case they have a fast clock. This scaling factor will need to |
| 232 |
be divided by 100 on all sites to truly represent the percentage for |
| 233 |
adjustments made to time values.<br> |
| 234 |
<br> |
| 235 |
Assume the slowest replica's clock is a factor of <i>clock_scale_factor</i> |
| 236 |
slower than the |
| 237 |
fastest clock. Using that assumption, if the fastest clock goes |
| 238 |
from time t1 to t2 in X |
| 239 |
seconds, the slowest clock does it in (<i>clock_scale_factor</i> / 100) |
| 240 |
* X seconds.<br> |
| 241 |
<br> |
| 242 |
The <i>flags</i> parameter is not |
| 243 |
currently used.<br> |
| 244 |
<br> |
| 245 |
When the <i>dbenv->rep_set_lease</i> |
| 246 |
method is called, we will set a configuration flag indicating that |
| 247 |
leases are turned on:<br> |
| 248 |
<b>#define REP_C_LEASE <value></b>. |
| 249 |
We will also record the <b>u_int32_t |
| 250 |
clock_skew</b> value passed in. The <i>rep_set_lease</i> method |
| 251 |
will not allow |
| 252 |
calls after <i>rep_start. </i>If |
| 253 |
multiple calls are made prior to calling <i>rep_start</i> then later |
| 254 |
calls will |
| 255 |
overwrite the earlier clock skew value. <br> |
| 256 |
<br> |
| 257 |
We need a new flag to prevent calling <i>rep_set_lease</i> |
| 258 |
after <i>rep_start</i>. The |
| 259 |
simplest solution would be to reject the call to |
| 260 |
<i>rep_set_lease |
| 261 |
</i>if<b> |
| 262 |
REP_F_CLIENT</b> |
| 263 |
or <b>REP_F_MASTER</b> is set. |
| 264 |
However that does not work in the cases where a site cleanly closes its |
| 265 |
environment and then opens without running recovery. The |
| 266 |
replication state will still be set. The prevention will be |
| 267 |
implemented as:<br> |
| 268 |
<pre>#define REP_F_START_CALLED <some bit value><br></pre> |
| 269 |
In __rep_start, at the end:<br> |
| 270 |
<pre>if (ret == 0 ) {<br> REP_SYSTEM_LOCK<br> F_SET(rep, REP_F_START_CALLED)<br> REP_SYSTEM_UNLOCK<br>}</pre> |
| 271 |
In <i>__rep_env_refresh</i>, if we |
| 272 |
are the last reference closing the env (we already check for that):<br> |
| 273 |
<pre>F_CLR(rep, REP_F_START_CALLED);</pre> |
| 274 |
In order to avoid run-time floating point operations |
| 275 |
on <i>db_timespec</i> structures, |
| 276 |
when a site is declared as a client or master in <i>rep_start</i> we |
| 277 |
will pre-compute the |
| 278 |
lease duration based on the integer-based clock skew and the |
| 279 |
integer-based lease timeout. A master should set a replica's |
| 280 |
lease expiration to the <b>start time of |
| 281 |
the sent message + |
| 282 |
(lease_timeout / clock_scale_factor)</b> in case the replica has a |
| 283 |
slow clock. Replicas extend their leases to <b>received message |
| 284 |
time + (lease_timeout * |
| 285 |
clock_scale_factor)</b> in case this replica has a fast clock. |
| 286 |
Therefore, the computation will be as follows if the site is becoming a |
| 287 |
master:<br> |
| 288 |
<pre>db_timeout_t tmp;<br>tmp = (db_timeout_t)((double)rep->lease_timeout / ((double)rep->clock_skew / (double)100));<br>rep->lease_duration = DB_TIMEOUT_TO_TIMESPEC(&tmp);<br></pre> |
| 289 |
Similarly, on a client the computation is:<br> |
| 290 |
<pre>tmp = (db_timeout_t)((double)rep->lease_timeout * ((double)rep->clock_skew / (double)100));<br></pre> |
| 291 |
When a site changes state, its lease duration will change based on |
| 292 |
whether it is becoming a master or client and it will be recomputed |
| 293 |
from the original values. Note that these computations, coupled |
| 294 |
with the fact that the lease on the master is computed based on the |
| 295 |
master's time that it sent the message means that leases on the master |
| 296 |
are more conservatively computed than on the clients.<br> |
| 297 |
<br> |
| 298 |
The <i>dbenv->rep_set_lease</i> |
| 299 |
method must be called after <i>dbenv->open</i>, |
| 300 |
similar to <i>dbenv->rep_set_config</i>. |
| 301 |
The reason is so that we can check that this is a replication |
| 302 |
environment and we have access to the replication shared memory region.<br> |
| 303 |
<h3>Read Operations<br> |
| 304 |
</h3> |
| 305 |
Authoritative read operations on the master with leases enabled will |
| 306 |
abide by leases by default. We will provide a flag that allows an |
| 307 |
operation on a master to ignore leases. <b>All read operations |
| 308 |
on a client imply |
| 309 |
ignoring leases.</b> If an application wants authoritative reads |
| 310 |
they must forward the read requests to the master and it is the |
| 311 |
application's responsibility to provide the forwarding. |
| 312 |
The consensus was that forcing <span style="font-weight: bold;">DB_IGNORE_LEASE</span> |
| 313 |
on client read operations (with leases enabled, obviously) was too |
| 314 |
heavy handed. Read operations on the client will ignore leases, |
| 315 |
but do no special flag checking.<br> |
| 316 |
<br> |
| 317 |
The flag will be called <b>DB_IGNORE_LEASE</b> |
| 318 |
and it will be a flag that can be OR'd into the DB access method and |
| 319 |
cursor operation values. It will be similar to the <b>DB_READ_UNCOMMITTED</b> |
| 320 |
flag. |
| 321 |
<br> |
| 322 |
</b>The methods that will |
| 323 |
adhere to leases are:<br> |
| 324 |
<ul> |
| 325 |
<li><i>Db->get</i></li> |
| 326 |
<li><i>Db->pget</i></li> |
| 327 |
<li><i>Dbc->get</i></li> |
| 328 |
<li><i>Dbc->pget</i></li> |
| 329 |
</ul> |
| 330 |
The code that will check leases for a client reading would look |
| 331 |
something |
| 332 |
like this, if we decide to become heavy-handed:<br> |
| 333 |
<pre>if (IS_REP_CLIENT(dbenv)) {<br> [get to rep structure]<br> if (FLD_ISSET(rep->config, REP_C_LEASE) && !LF_ISSET(DB_IGNORE_LEASE)) {<br> db_err("Read operations must ignore leases or go to master");<br> ret = EINVAL;<br> goto err;<br> }<br>}<br></pre> |
| 334 |
On the master, the new code to abide by leases is more complex. |
| 335 |
After the call to perform the operation we will check the lease. |
| 336 |
In that checking code, the master will see if it has a valid |
| 337 |
lease. If so, then all is well. If not, it will try to |
| 338 |
refresh the leases. If that refresh attempt results in leases, |
| 339 |
all is well. If the refresh attempt does not get leases, then the |
| 340 |
master cannot respond to the read as an authority and we return an |
| 341 |
error. The new error is called <b>DB_REP_LEASE_EXPIRED</b>. |
| 342 |
The location of the master lease check is down after the internal call |
| 343 |
to read the data is successful:<br> |
| 344 |
<pre>if (IS_REP_MASTER(dbenv) && !LF_ISSET(DB_IGNORE_LEASE)) {<br> [get to rep structure]<br> if (FLD_ISSET(rep->config, REP_C_LEASE) &&<br> (ret = __rep_lease_check(dbenv)) != 0) {<br> /*<br> * We don't hold the lease.<br> */<br> goto err;<br> }<br>}<br></pre> |
| 345 |
See below for the details of <i>__rep_lease_check</i>.<br> |
| 346 |
<br> |
| 347 |
Also note that if leases (or replication) are not configured, then <span |
| 348 |
style="font-weight: bold;">DB_IGNORE_LEASE</span> is a no-op. It |
| 349 |
is ignored (and won't error) if used when leases are not in |
| 350 |
effect. The reason is so that we can generically set that flag in |
| 351 |
utility programs like <span style="font-style: italic;">db_dump</span> |
| 352 |
that walk the database with a cursor. Note that <span |
| 353 |
style="font-style: italic;">db_dump</span> is the only utility that |
| 354 |
reads with a cursor.<span style="font-style: italic;"><span |
| 355 |
style="font-style: italic;"></span></span><br> |
| 356 |
<h3><b>Nsites |
| 357 |
and Elections</b></h3> |
| 358 |
The call to <i>dbenv->rep_set_nsites</i> |
| 359 |
must be performed before the call to <i>dbenv->rep_start</i> |
| 360 |
or <i>dbenv->repmgr_start</i>. |
| 361 |
This document assumes either that <b>SR |
| 362 |
14778</b> gets resolved, or assumes that the value of <i>nsites</i> is |
| 363 |
immutable. The |
| 364 |
master and all clients need to know how many sites and leases are in |
| 365 |
the group. Clients need to know for elections. The master |
| 366 |
needs to know for the size of the lease table and to know what value a |
| 367 |
majority of the group is. <b>[Until |
| 368 |
14778 is resolved, the master lease work must assume <i>nsites</i> is |
| 369 |
immutable and will |
| 370 |
therefore enforce that this is called before <i>rep_start</i> using |
| 371 |
the same mechanism |
| 372 |
as <i>rep_set_lease</i>.]</b><br> |
| 373 |
<br> |
| 374 |
Elections and leases need to agree on the number of sites in the |
| 375 |
group. Therefore, when leases are in effect on clients, all calls |
| 376 |
to <i>dbenv->rep_elect</i> must |
| 377 |
set the <i>nsites</i> parameter to |
| 378 |
0. The <i>rep_elect</i> code |
| 379 |
path will return <b>EINVAL</b> if <b>REP_C_LEASE</b> is set and <i>nsites</i> |
| 380 |
is non-0. |
| 381 |
<h2>Lease Management</h2> |
| 382 |
<h3>Message Changes</h3> |
| 383 |
In order for clients to grant leases to the master a new message type |
| 384 |
must be added for that purpose. This will be the <b>REP_LEASE_GRANT</b> |
| 385 |
message. |
| 386 |
Granting leases will be a result of applying a <b>DB_REP_PERMANENT</b> |
| 387 |
record and therefore we |
| 388 |
do not need any additional message in order for a master to request a |
| 389 |
lease grant. The <b>REP_LEASE_GRANT</b> |
| 390 |
message will pass a structure as its message DBT:<br> |
| 391 |
<pre>struct __rep_lease_grant {<br> db_timespec msg_time;<br>#ifdef DIAGNOSTIC<br> db_timespec expire_time;<br>#endif<br>} REP_GRANT_INFO;<br></pre> |
| 392 |
In the <b>REP_LEASE_GRANT</b> |
| 393 |
message, the client is actually giving the master several pieces of |
| 394 |
information. We only need the echoed <i>msg_time</i> in this |
| 395 |
structure because |
| 396 |
everything else is already sent. The client is really sending the |
| 397 |
master:<br> |
| 398 |
<ul> |
| 399 |
<li>Its EID (parameter to <span style="font-style: italic;">rep_send_message</span> |
| 400 |
and <span style="font-style: italic;">rep_process_message</span>)<br> |
| 401 |
</li> |
| 402 |
<li>The PERM LSN this message acknowledged (sent in the control |
| 403 |
message)</li> |
| 404 |
<li>Unique identifier echoed back to master (<i>msg_time</i> sent in |
| 405 |
message as above)</li> |
| 406 |
</ul> |
| 407 |
On the client, we always maintain the maximum PERM LSN already in <i>lp->max_perm_lsn</i>. |
| 408 |
<h3>Local State Management</h3> |
| 409 |
Each client must maintain a <i>db_timespec</i> |
| 410 |
timestamp containing the expiration of its granted lease. This |
| 411 |
field will be in the replication shared memory structure:<br> |
| 412 |
<pre>db_timespec grant_expire;<br></pre> |
| 413 |
This timestamp already takes into account the clock skew. All |
| 414 |
new fields must be initialized when the region is created. Whenever we |
| 415 |
grant our master lease and want to send the <b>REP_LEASE_GRANT</b> |
| 416 |
message, this value |
| 417 |
will be updated. It will be used in the following way: |
| 418 |
<pre>db_timespec mytime;<br>DB_LSN perm_lsn;<br>DBT lease_dbt;<br>REP_GRANT_INFO gi;<br><br><br>timespecclear(&mytime);<br>timespecclear(&newgrant);<br>memset(&lease_dbt, 0, sizeof(lease_dbt));<br>memset(&gi, 0, sizeof(gi));<br>__os_gettime(dbenv, &mytime);<br>timespecadd(&mytime, &rep->lease_duration);<br>MUTEX_LOCK(rep->clientdb_mutex);<br>perm_lsn = lp->max_perm_lsn;<br>MUTEX_UNLOCK(rep->clientdb_mutex);<br>REP_SYSTEM_LOCK(dbenv);<br>if (timespeccmp(mytime, rep->grant_expire, >))<br> rep->grant_expire = mytime;<br>gi.msg_time = msg->msg_time;<br>#ifdef DIAGNOSTIC<br>gi.expire_time = rep->grant_expire;<br>#endif<br>lease_dbt.data = &gi;<br>lease_dbt.size = sizeof(gi);<br>REP_SYSTEM_UNLOCK(dbenv);<br>__rep_send_message(dbenv, eid, REP_LEASE_GRANT, &perm_lsn, &lease_dbt, 0, 0);<br></pre> |
| 419 |
This updating of the lease grant will occur in the <b>PERM</b> code |
| 420 |
path when we have |
| 421 |
successfully applied the permanent record.<br> |
| 422 |
<h3>Maintaining Leases on the |
| 423 |
Master/Rep_start</h3> |
| 424 |
The master maintains a lease table that it checks when fulfilling a |
| 425 |
read request that is subject to leases. This table is initialized |
| 426 |
when a site calls<i> |
| 427 |
dbenv->rep_start(DB_MASTER)</i> and the site is undergoing a role |
| 428 |
change (i.e. a master making additional calls to <i>dbenv->rep_start(DB_MASTER)</i> |
| 429 |
does |
| 430 |
not affect an already existing table).<br> |
| 431 |
<br> |
| 432 |
When a non-master site becomes master, it must do two things related to |
| 433 |
leases on a role change. First, a client cannot upgrade to master |
| 434 |
while it has an outstanding lease granted to another site. If a |
| 435 |
client attempts to do so, an error, <b>EINVAL</b>, |
| 436 |
will be returned. The only way this should happen is if the |
| 437 |
application simply declares a site master, instead of using |
| 438 |
elections. Elections will already wait for leases to expire |
| 439 |
before proceeding. (See below.) |
| 440 |
<br> |
| 441 |
<br> |
| 442 |
Second, once we are proceeding with becoming a master, the site must |
| 443 |
allocate the table it will use to maintain lease information. |
| 444 |
This table will be sized based on <i>nsites</i> |
| 445 |
and it will be an array of the following structure:<br> |
| 446 |
<pre>struct {<br> int eid; /* EID of client site. */<br> db_timespec start_time; /* Unique time ID client echoes back on grants. */<br> db_timespec end_time; /* Master's lease expiration time. */<br> DB_LSN lease_lsn; /* Durable LSN this lease applies to. */<br> u_int32_t flags; /* Unused for now?? */<br>} REP_LEASE_ENTRY;<br></pre> |
| 447 |
<h3>Granting Leases</h3> |
| 448 |
It is the burden of the application to make sure that all sites in the |
| 449 |
group |
| 450 |
are using leases, or none are. Therefore, when a client processes |
| 451 |
a <b>PERM</b> |
| 452 |
log record that arrived from the master, it will grant its lease |
| 453 |
automatically if that record is permanent (i.e. <b>DB_REP_ISPERM</b> |
| 454 |
is being returned), |
| 455 |
and leases are configured. A client will not send a |
| 456 |
lease grant when it is processing log records (even <b>PERM</b> |
| 457 |
ones) it receives from other clients that use client-to-client |
| 458 |
synchronization. The reason is that the master requires a unique |
| 459 |
time-of-msg ID (see below) that the client echoes back in its lease |
| 460 |
grant and it will not have such an ID from another client.<br> |
| 461 |
<br> |
| 462 |
The master stores a time-of-msg ID in each message and the client |
| 463 |
simply echoes it back to the master. In its lease table, it does |
| 464 |
keep the base |
| 465 |
time-of-msg for a valid lease. When <b>REP_LEASE_GRANT</b> |
| 466 |
message comes in, |
| 467 |
the master does a number of things:<br> |
| 468 |
<ol> |
| 469 |
<li>Pulls the echoed timespec from the client message, into <i>msg_time</i>.<br> |
| 470 |
</li> |
| 471 |
<li>Finds the entry in its lease table for the client's EID. It |
| 472 |
walks the table searching for the ID. EIDs of <span |
| 473 |
style="font-weight: bold;">DB_EID_INVALID</span> are |
| 474 |
illegal. Either the master will find the entry, or it will find |
| 475 |
an empty slot in the table (i.e. it is still populating the table with |
| 476 |
leases).</li> |
| 477 |
<li>If this is a previously unknown site lease, the master |
| 478 |
initializes the entry by copying to the <i>eid</i>, <i>start_time, </i>and |
| 479 |
<i>lease_lsn</i> fields. The master |
| 480 |
also computes the <i>end_time</i> |
| 481 |
based on the adjusted <i>rep->lease_duration</i>.</li> |
| 482 |
<li>If this is a lease from a previously known site, the master must |
| 483 |
perform <i>timespeccmp(&msg_time, |
| 484 |
&table[i].start_time, >)</i> and only update the <i>end_time</i> |
| 485 |
of the lease when this is |
| 486 |
a more recent message. If it is a more recent message, then we |
| 487 |
should update |
| 488 |
the <i>lease_lsn</i> to the LSN in |
| 489 |
the message.</li> |
| 490 |
<li>Since lease durations are computed taking the clock skew into |
| 491 |
account, clients compute them based on the current time and the master |
| 492 |
computes it based on original sending time, for diagnostic purposes |
| 493 |
only, I also plan to send the client's expiration time. The |
| 494 |
client errs on the side of computing a larger lease expiration time and |
| 495 |
the master errs on the side of computing a smaller duration. |
| 496 |
Since both are taking the clock skew |
| 497 |
into account, the client's ending expiration time should never be |
| 498 |
smaller than |
| 499 |
the master's computed expiration time or their value for clock skew may |
| 500 |
not be correct.<br> |
| 501 |
</li> |
| 502 |
</ol> |
| 503 |
Any log records (new or resent) that originate from the master and |
| 504 |
result in <b>DB_REP_ISPERM</b> get an |
| 505 |
ack.<br> |
| 506 |
<br> |
| 507 |
<h3>Refreshing Leases</h3> |
| 508 |
Leases get refreshed when a master receives a <b>REP_LEASE_GRANT</b> |
| 509 |
message from a client. There are three pieces to lease |
| 510 |
refreshment. <br> |
| 511 |
<h4>Lazy Lease Refreshing on Read<br> |
| 512 |
</h4> |
| 513 |
If the master discovers that leases are |
| 514 |
expired during the read operation, it attempts to refresh its |
| 515 |
collection of lease grants. It does this by calling a new |
| 516 |
function <i>__rep_lease_refresh</i>. |
| 517 |
This function is very similar to the already-existing function <i>__rep_flush</i>. |
| 518 |
Basically, to |
| 519 |
refresh the lease, the master simply needs to resend the last PERM |
| 520 |
record to the clients. The requirements state that when the |
| 521 |
application send function returns successfully from sending a PERM |
| 522 |
record, the majority of clients have that PERM LSN durable. We |
| 523 |
will have a new public DB error return called <b>DB_REP_LEASE_EXPIRED</b> |
| 524 |
that will be |
| 525 |
returned back to the caller if the master cannot assert its |
| 526 |
authority. The code will look something like this:<br> |
| 527 |
<pre>/*<br> * Use lp->max_perm_lsn on the master (currently not used on the master)<br> * to keep track of the last PERM record written through the logging system.<br> * need to initialize lp->max_perm_lsn in rep_start on role_chg.<br> */<br>call __rep_send_message on the last PERM record the master wrote, with DB_REP_PERMANENT<br>if failure<br> expire leases<br> return lease expired error to caller<br>else /* success */<br> recheck lease table<br> /*<br> * We need to recheck the lease table because the client<br> * lease grant messages may not be processed yet, or got<br> * lost, or racing with the application's ACK messages or<br> * whatever. <br> */<br> if we have a majority of valid leases<br> return success<br> else<br> return lease expired error to caller <br></pre> |
| 528 |
<h4>Ongoing Update Refreshment<br> |
| 529 |
</h4> |
| 530 |
Second is having the master indicate to |
| 531 |
the client it needs to send a lease grant in response to the current |
| 532 |
PERM log message. The problem is |
| 533 |
that acknowledgements must contain a master-supplied message timestamp |
| 534 |
that the client sends back to the master. We need to modify the |
| 535 |
structure of the log record messages when leases are configured |
| 536 |
so |
| 537 |
that when a PERM message is sent, the master sends, and the client |
| 538 |
expects, the message timestamp. There are three fairly |
| 539 |
straightforward and different implementations to consider.<br> |
| 540 |
<ol> |
| 541 |
<li>Adding the timestamp to the <b>REP_CONTROL</b> |
| 542 |
structure. If this option is chosen, then the code trivially |
| 543 |
sends back the timestamp in the client's reply. There is no |
| 544 |
special processing done by either side with the message contents. |
| 545 |
So, on a PERM log record, the master will send a non-zero |
| 546 |
timestamp. On a normal log record the timestamp will be zero or |
| 547 |
some known invalid value. If the client sees a non-zero |
| 548 |
timestamp, it sends a <b>REP_LEASE_GRANT</b> |
| 549 |
with the <i>lp->max_perm_lsn</i> |
| 550 |
after applying that log record. If it is zero, then the client |
| 551 |
does nothing different. The advantage is ease of code. The |
| 552 |
disadvantage is that for mixed version systems, the client is now |
| 553 |
dealing with different sized control structures. We would have to |
| 554 |
retain the old control structure so that during a mixed version group |
| 555 |
the (upgraded) clients can use, expect and send old control structures |
| 556 |
to the master. This is unfortunate, so let's consider additional |
| 557 |
implementations that don't require modifying the control structure.<br> |
| 558 |
</li> |
| 559 |
<li>Adding a new <b>REPCTL_LEASE</b> |
| 560 |
flag to the list of flags for the control structure, but do not change |
| 561 |
the control structure fields. When a master wants to send a |
| 562 |
message that needs a lease ack, it sets the flag. Additionally, |
| 563 |
instead of simply sending a log record DBT as the <i>rec</i> parameter |
| 564 |
for replication, we |
| 565 |
would send a new structure that had the timestamp first and then the |
| 566 |
record (similar to the bulk transfer buffer). The advantage of |
| 567 |
this is that the control structure does not change. Disadvantages |
| 568 |
include more special-cased code in the normal code path where we have |
| 569 |
to check the flag. If the flag is set we have to extract the |
| 570 |
timestamp value and massage the incoming data to pass on the real log |
| 571 |
record to <i>rep_apply</i>. On |
| 572 |
bulk transfer, we would just add the timestamp into the buffer. |
| 573 |
On normal transfers, it would incur an additional data copy on the |
| 574 |
master side. That is unfortunate. Additionally, if this |
| 575 |
record needs to be stored in the temp db, we need some way to get it |
| 576 |
back again later or <span style="font-style: italic;">rep_apply</span> |
| 577 |
would have to extract the timestamp out when it processed the record |
| 578 |
(either live or from the temp db).<br> |
| 579 |
</li> |
| 580 |
<li>Adding a different message type, such as <b>REP_LOG_ACK</b>. |
| 581 |
Similarly to <b>REP_LOG_MORE</b> this message would be a |
| 582 |
special-case version of a log record. We would extract out the |
| 583 |
timestamp and then handle as a normal log record. This |
| 584 |
implementation is rejected because it actually would require three new |
| 585 |
message types: <b>REP_LOG_ACK, |
| 586 |
REP_LOG_ACK_MORE, REP_BULK_LOG_ACK</b>. That is just too ugly |
| 587 |
to contemplate.</li> |
| 588 |
</ol> |
| 589 |
<b>[Slight digression:</b> it occurs |
| 590 |
to me while writing about #2 and #3 above, that our implementation of |
| 591 |
all of the *_MORE messages could really be implemented with a <b>REPCTL_MORE</b> |
| 592 |
flag instead of a |
| 593 |
separate message type. We should clean that up and simplify the |
| 594 |
messages but not part of master leases. Hmm, taking that thought |
| 595 |
process further, we really could get rid of the <b>REP_BULK_*</b> |
| 596 |
messages as well if we |
| 597 |
added a <b>REPCTL_BULK</b> |
| 598 |
flag. I think we should definitely do it for the *_MORE |
| 599 |
messages. I am not sure we should do it for bulk because the |
| 600 |
structure of the incoming data record is vastly different.]<br> |
| 601 |
<br> |
| 602 |
Of these options, I believe that modifying the control structure is the |
| 603 |
best alternative. The handling of the old structure will be very |
| 604 |
isolated to code dealing with old versions and is far less complicated |
| 605 |
than injecting the timestamp into the log record DBT and doing a data |
| 606 |
copy. Actually, I will likely combine #1 and the flag from #2 |
| 607 |
above. I will have the <b>REPCTL_LEASE</b> |
| 608 |
flag that indicates a lease grant reply is expected and have the |
| 609 |
timestamp in the control structure. |
| 610 |
Also I will probably add in a spare field or two for future use in the <b>REP_CONTROL</b> |
| 611 |
structure.<br> |
| 612 |
<h4>Gap processing</h4> |
| 613 |
No matter which implementation we choose for ongoing lease refreshment, |
| 614 |
gap processing must be considered. The code above assumes the |
| 615 |
timestamps will be placed on PERM records only. Normal log |
| 616 |
records will not have a timestamp, nor a flag or anything else like |
| 617 |
that. However, any log message can fill a gap on a client and |
| 618 |
result in the processing of that normal log record to return <b>DB_REP_ISPERM</b> |
| 619 |
because later records |
| 620 |
were also processed.<br> |
| 621 |
<br> |
| 622 |
The current implementation should work fine in that case because when |
| 623 |
we store the message in the client temp db we store both the control |
| 624 |
DBT and the record DBT. Therefore, when a normal record fills a |
| 625 |
gap, the later PERM record, when retrieved will look just like it did |
| 626 |
when it arrived. The client will have access to the LSN, and the |
| 627 |
timestamp, etc. However, it does mean that sending the <b>REP_LEASE_GRANT</b> |
| 628 |
message must take |
| 629 |
place down in <i>__rep_apply</i> |
| 630 |
because that is the only place we have access to the contents of those |
| 631 |
stored records with the timestamps.<br> |
| 632 |
<br> |
| 633 |
There are two logical choices to consider for granting the lease when |
| 634 |
processing an update. As we process (either a live record or one |
| 635 |
read from the temp db after filling a gap) a PERM message, we send the <b>REP_LEASE_GRANT</b> |
| 636 |
message for each |
| 637 |
PERM record we successfully apply. Or, second, we keep track of |
| 638 |
the largest timestamp of all PERM records we've processed and at the |
| 639 |
end of the function after we've applied all records, we send back a |
| 640 |
single lease grant with the <i>max_perm_lsn</i> |
| 641 |
and a new <i>max_lease_timestamp</i> |
| 642 |
value to the master. The first is easier to implement, the second |
| 643 |
results in possibly slightly fewer messages at the expense of more |
| 644 |
bookkeeping on the client.<br> |
| 645 |
<br> |
| 646 |
A third, more complicated option would be to have the message timestamp |
| 647 |
on all records, but grants are only sent on the PERM messages. A |
| 648 |
reason to do this is that the later timestamp of a normal log record |
| 649 |
would be used as the timestamp sent in the reply and the master would |
| 650 |
get a more up to date timestamp value and a longer lease. <br> |
| 651 |
<br> |
| 652 |
If we change the <span style="font-weight: bold;">REP_CONTROL</span> |
| 653 |
structure to include the timestamp, we potentially break or at least |
| 654 |
need to revisit the gap processing algorithm. That code assumes |
| 655 |
that the control and record elements for the same LSN look the same |
| 656 |
each and every time. The code stores the <span |
| 657 |
style="font-style: italic;">control</span> DBT as the key and the <span |
| 658 |
style="font-style: italic;">rec</span> DBT as the data. We use a |
| 659 |
specialized compare function to sort based on the LSN in the control |
| 660 |
DBT. With master leases, the same record transmitted by a master |
| 661 |
multiple times or client for the same LSN will be different because the |
| 662 |
timestamp field will not be the same. Therefore, the client will |
| 663 |
end up with duplicate entries in the temp database for the same |
| 664 |
LSN. Both solutions (adding the timestamp to <span |
| 665 |
style="font-weight: bold;">REP_CONTROL</span> and adding a <span |
| 666 |
style="font-weight: bold;">REPCTL_LEASE</span> flag) can yield |
| 667 |
duplicate entries. The flag would cause the same record from the |
| 668 |
master and client to be different as well.<br> |
| 669 |
<h4>Handling Incoming Lease Grants<br> |
| 670 |
</h4> |
| 671 |
The third piece of lease management is handling the incoming <b>REP_LEASE_GRANT</b> |
| 672 |
message on the |
| 673 |
master. When this message is received, the master must do the |
| 674 |
following:<br> |
| 675 |
<pre>REP_SYSTEM_LOCK<br>msg_timestamp = cntrl->timestamp;<br>client_lease = __rep_lease_entry(dbenv, client eid)<br>if (client_lease == NULL)<br> initial lease for this site, DB_ASSERT there is space in the table<br> add this to the table if there is space<br>} else <br> compare msg_timestamp with client_lease->start_time<br> if (msg_timestamp is more recent && msg_lsn >= lease LSN)<br> update entry in table<br>REP_SYSTEM_UNLOCK<br></pre> |
| 676 |
<h3>Expiring Leases</h3> |
| 677 |
Leases can expire in two ways. First they can expire naturally |
| 678 |
due to the passage of time. When checking leases, if the current |
| 679 |
time is later than the lease entry's <i>end_time</i> |
| 680 |
then the lease is expired. Second, they can be forced with a |
| 681 |
premature expiration when the application's transport function returns |
| 682 |
an error. In the first case, there is nothing to do, in the |
| 683 |
second case we need to manipulate the <i>end_time</i> |
| 684 |
so that all future lease checks fail. Since the lease <i>start_time</i> |
| 685 |
is guaranteed to not be in the future we will have a function <i>__rep_lease_expire</i> |
| 686 |
that will:<br> |
| 687 |
<pre>REP_SYSTEM_LOCK<br>for each entry in the lease table<br> entry->end_time = entry->start_time;<br>REP_SYSTEM_UNLOCK<br></pre> |
| 688 |
Is there a potential race or problem with prematurely expiring |
| 689 |
leases? Consider an application that enforces an ALL |
| 690 |
acknowledgement policy for PERM records in its transport |
| 691 |
callback. There are four clients and three send the PERM ack to |
| 692 |
the application. The callback returns an error to the master DB |
| 693 |
code. The DB code will now prematurely expire its leases. |
| 694 |
However, at approximately the same time the three clients are also |
| 695 |
sending their <span style="font-weight: bold;">REP_LEASE_GRANT</span> |
| 696 |
messages to the master. There is a race between the master |
| 697 |
processing those messages and the thread handling the callback failure |
| 698 |
expiring the table. This is only an issue if the messages arrive |
| 699 |
after the table has been expired.<br> |
| 700 |
<br> |
| 701 |
Let's assume all three clients send their grants after the master |
| 702 |
expires the table. If we accept those grants and then a read |
| 703 |
occurs the read will succeed since the master has a majority of leases |
| 704 |
even though the callback failed earlier. Is that a problem? |
| 705 |
The lease code is using a majority and the application policy is using |
| 706 |
something other value. It feels like this should be okay since |
| 707 |
the data is held by leases on a majority. Should we consider |
| 708 |
having the lease checking threshold be the same as the permanent ack |
| 709 |
policy? That is difficult because Base API users implement |
| 710 |
whatever they want and DB does not know what it is.<br> |
| 711 |
<h3>Checking Leases</h3> |
| 712 |
When a read operation on the master completes, the last thing we need |
| 713 |
to do is verify the master leases. We've already discussed |
| 714 |
refreshing them when they are expired above. We need two things |
| 715 |
for a lease to be valid. It must be within the timeframe of the |
| 716 |
lease grant and the lease must be valid for the last PERM record |
| 717 |
LSN. Here is the logic |
| 718 |
for checking the validity of leases in <i>__rep_lease_check</i>:<br> |
| 719 |
<pre>#define MAX_REFRESH_TRIES 3<br>DB_LSN lease_lsn;<br>REP_LEASE_ENTRY *entry;<br>u_int32_t min_leases, valid_leases;<br>db_timespec cur_time;<br>int ret, tries;<br><br> tries = 0;<br>retry:<br> ret = 0;<br> LOG_SYSTEM_LOCK<br> lease_lsn = lp->lsn<br> LOG_SYSTEM_UNLOCK<br> REP_SYSTEM_LOCK<br> min_leases = rep->nsites / 2;<br> __os_gettime(dbenv, &cur_time);<br> for (entry = head of table, valid_leases = 0; entry != NULL && valid_leases < min_leases; entry++)<br> if (timespec_cmp(&entry->end_time, &cur_time) >= 0 && log_compare(&entry->lsn, lease_lsn) == 0)<br> valid_leases++;<br> REP_SYSTEM_UNLOCK<br> if (valid_leases < min_leases) {<br> ret =__rep_lease_refresh(dbenv, ...);<br> /*<br> * If we are successful, we need to recheck the leases because <br> * the lease grant messages may have raced with the PERM<br> * acknowledgement. Give those messages a chance to arrive.<br> */<br> if (ret == 0) {<br> if (tries <= MAX_REFRESH_TRIES) {<br> /*<br> * If we were successful sending, but not successful in racing the<br> * message thread, yield the processor so that message<br> * threads may have a chance to run.<br> */<br> if (tries > 0)<br> /* __os_sleep instead?? */<br> __os_yield()<br> tries++;<br> goto retry;<br> } else<br> ret = DB_RET_LEASE_EXPIRED;<br> }<br> }<br> return (ret);</pre> |
| 720 |
If the master has enough valid leases it returns success. If it |
| 721 |
does not have enough, it attempts to refresh them. This attempt |
| 722 |
may fail if sending the PERM record does not receive sufficient |
| 723 |
acks. If we do receive sufficient acknowledgements we may still |
| 724 |
find that scheduling of message threads means the master hasn't yet |
| 725 |
processed the incoming <b>REP_LEASE_GRANT</b> |
| 726 |
messages yet. We will retry a couple times (possibly |
| 727 |
parameterized) if the master discovers that situation. <br> |
| 728 |
<h2>Elections</h2> |
| 729 |
When a client grants a lease to a master, it gives up the right to |
| 730 |
participate in an election until that grant expires. If we are |
| 731 |
the master and <i>dbenv->rep_elect</i> |
| 732 |
is called, it should return, no matter what, like it does today. |
| 733 |
If we are a client and <i>rep_elect</i> |
| 734 |
is called special processing takes place when leases are in |
| 735 |
effect. First, the easy case is if the lease granted by this |
| 736 |
client has already expired, then the client goes directly into the |
| 737 |
election as normal. If a valid lease grant is outstanding to a |
| 738 |
master, this site cannot participate in an election until that grant |
| 739 |
expires. We have at least two options when a site calls the <i>dbenv->rep_elect</i> |
| 740 |
API while |
| 741 |
leases are in effect.<br> |
| 742 |
<ol> |
| 743 |
<li>The simplest coding solution for DB would be simply to refuse to |
| 744 |
participate in the election if this site has a current lease granted to |
| 745 |
a master. We would detect this situation and return EINVAL. |
| 746 |
This is correct behavior and trivial to implement. The |
| 747 |
disadvantage of this solution is that the application would then be |
| 748 |
responsible for repeatedly attempting an election until the lease grant |
| 749 |
expired.<br> |
| 750 |
</li> |
| 751 |
<li>The more satisfying solution is for DB to wait the remaining time |
| 752 |
for the grant. If this client hears from the master during that |
| 753 |
time the election does not take place and the call to <i>rep_elect</i> |
| 754 |
returns with the |
| 755 |
information for the current/old master.</li> |
| 756 |
</ol> |
| 757 |
<h3>Election Code Changes</h3> |
| 758 |
The code changes to support leases in the election code are fairly |
| 759 |
isolated. First if leases are configured, we must verify the <i>nsites</i> |
| 760 |
parameter is set to 0. |
| 761 |
Second, in <i>__rep_elect_init</i> |
| 762 |
we must not overwrite the value of <i>rep->nsites</i> |
| 763 |
for leases because it is controlled by the <i>dbenv->rep_set_nsites</i> |
| 764 |
API. |
| 765 |
These changes are small and easy to understand.<br> |
| 766 |
<br> |
| 767 |
The more complicated code will be the client code when it has an |
| 768 |
outstanding lease granted. The client will wait for the current |
| 769 |
lease grant to expire before proceeding with the election. The |
| 770 |
client will only do so if it does not hear from the master for the |
| 771 |
remainder of the lease grant time. If the client hears from the |
| 772 |
master, it returns and does not begin participating in the |
| 773 |
election. A new election phase, <b>REP_EPHASE0</b> |
| 774 |
will exist so that the call to <i>__rep_wait</i> |
| 775 |
can detect if a master responds. The client, while waiting for |
| 776 |
the lease grant to expire, will send a <b>REP_MASTER_REQ</b> |
| 777 |
message so that the master will respond with a <b>REP_NEWMASTER</b> |
| 778 |
message and thus, |
| 779 |
allow the client to know the master exists. However, it is also |
| 780 |
desirable that if the master |
| 781 |
replies to the client, the master wants the client to update its lease |
| 782 |
grant. <br> |
| 783 |
<br> |
| 784 |
Recall that the <b>REP_NEWMASTER</b> |
| 785 |
message does not result in a lease grant from the client. The |
| 786 |
client responds when it processes a PERM record that has the <b>REPCTL_LEASE</b> |
| 787 |
flag set in the message |
| 788 |
with its lease grant up to the given LSN. Therefore, we want the |
| 789 |
client's <b>REP_MASTER_REQ</b> to |
| 790 |
yield both the discovery of the existing master and have the master |
| 791 |
refresh its leases. The client will also use the <b>REPCTL_LEASE</b> |
| 792 |
flag in its <b>REP_MASTER_REQ</b> message to the |
| 793 |
master. This flag will serve as the indicator to the master that |
| 794 |
it needs to deal with leases and both send the <b>REP_NEWMASTER</b> |
| 795 |
message and refresh |
| 796 |
the lease.<br> |
| 797 |
The code will work as follows:<br> |
| 798 |
<pre>if (leases_configured && (my_grant_still_valid || lease_never_granted) {<br> if (lease_never_granted)<br> wait_time = lease_timeout<br> else<br> wait_time = grant_expiration - current_time<br> F_SET(REP_F_EPHASE0);<br> __rep_send_message(..., REP_MASTER_REQ, ... REPCTL_LEASE);<br> ret = __rep_wait(..., REP_F_EPHASE0);<br> if (we found a master)<br> return<br>} /* if we don't return, fall out and proceed with election */<br></pre> |
| 799 |
On the master side, the code handling the <b>REP_MASTER_REQ</b> will |
| 800 |
do:<br> |
| 801 |
<pre>if (I am master) {<br> ...<br> __rep_send_message(REP_NEWMASTER...)<br> if (F_ISSET(rp, REPCTL_LEASE))<br> __rep_lease_refresh(...)<br>}<br></pre> |
| 802 |
Other minor implementation details are that<i> __rep_elect_done</i> |
| 803 |
must also clear |
| 804 |
the <b>REP_F_EPHASE0</b> flag. |
| 805 |
We also, obviously, need to define <b>REP_F_EPHASE0</b> |
| 806 |
in the list of replication flags. Note that the client's call to <i>__rep_wait</i> |
| 807 |
will return upon |
| 808 |
receiving the <b>REP_NEWMASTER</b> |
| 809 |
message. The client will independently refresh its lease when it |
| 810 |
receives the log record from the master's call to refresh the lease.<br> |
| 811 |
<br> |
| 812 |
Again, similar to what I suggested above, the code could simply assume |
| 813 |
global leases are configured, and instead of having the <b>REPCTL_LEASE</b> |
| 814 |
flag at all, the master |
| 815 |
assumes that it needs to refresh leases because it has them configured, |
| 816 |
not because it is specified in the <b>REP_MASTER_REQ</b> |
| 817 |
message it is processing. Right now I don't think every possible |
| 818 |
<b>REP_MASTER_REQ</b> message should result in a lease grant request.<br> |
| 819 |
<h4>Elections and Quiescient Systems</h4> |
| 820 |
It is possible that a master is slow or the client is close to its |
| 821 |
expiration time, or that the master is quiescient and all leases are |
| 822 |
currently expired, but nothing much is going on anyway, yet some client |
| 823 |
calls <i>__rep_elect</i> at that |
| 824 |
time. In the code above, we will not send the <b>REP_MASTER_REQ</b> |
| 825 |
because the lease is |
| 826 |
not valid. The client will simply proceed directly to sending the |
| 827 |
<b>REP_VOTE1</b> message, throwing all |
| 828 |
other clients into an election. The master is still master and |
| 829 |
should stay that way. Currently in response to a vote message, a |
| 830 |
master will broadcast out a <b>REP_NEWMASTER</b> |
| 831 |
to assert its mastership. That causes the election to |
| 832 |
complete. However, if desired the master may want to proactively |
| 833 |
refresh its leases. This situation indicates to me that the |
| 834 |
master should choose to refresh leases based on configuration, not a |
| 835 |
flag sent from the client. I believe anytime the master asserts |
| 836 |
its mastership via sending a <b>REP_NEWMASTER</b> |
| 837 |
message that I need to add code to proactively refresh leases at that |
| 838 |
time.<br> |
| 839 |
<h2>Other Implementation Details</h2> |
| 840 |
<h3>Role Changes<br> |
| 841 |
</h3> |
| 842 |
When a site changes its role via a call to <i>rep_start</i> in either |
| 843 |
direction, we |
| 844 |
must take action when leases are configured. There are three |
| 845 |
types of role changes that all need changes to deal with leases:<br> |
| 846 |
<ol> |
| 847 |
<li><i>A master downgrading to a |
| 848 |
client.</i> When a master downgrades to a client, it can do so |
| 849 |
immediately after it has proactively expired all existing leases it |
| 850 |
holds. This situation is similar to an error from the send |
| 851 |
callback, and it effectively cancels all outstanding leases held on |
| 852 |
this site. Note that if this master expires its leases, it does |
| 853 |
not have any effect on when the clients' lease grants expire on the |
| 854 |
client side. The clients must still wait their full expected |
| 855 |
grant time.<br> |
| 856 |
</li> |
| 857 |
<li><i>A client upgrading to master.</i> |
| 858 |
If a client is upgrading to a master but it has an outstanding lease |
| 859 |
granted to another site, the code will return an <b>EINVAL</b> |
| 860 |
error. This situation |
| 861 |
only arises if the application simply declares this site master. |
| 862 |
If a site wins an election then the election itself should have waited |
| 863 |
long enough for the granted lease to expire and this state should not |
| 864 |
arise then.</li> |
| 865 |
<li><i>A client finding a new master.</i> |
| 866 |
When a client discovers a new and different master, via a <b>REP_NEWMASTER</b> |
| 867 |
message then the |
| 868 |
client cannot accept that new master until its current lease grant |
| 869 |
expires. This situation should only occur when a site declares |
| 870 |
itself master without an election and that site's lease grant expires |
| 871 |
before this client's grant expires. However, it is <b>possible</b> |
| 872 |
for this situation to arise |
| 873 |
with elections also. If we have 5 sites holding an election and 4 |
| 874 |
of those sites have leases expire at about the same time T, and this |
| 875 |
site's lease expires at time T+N and the election timeout is < N, |
| 876 |
then those 4 sites may hold an election and elect a master without this |
| 877 |
site's participation. A client in this situation must call <i>__rep_wait</i> |
| 878 |
with the time remaining |
| 879 |
on its lease. If the lease is expired after waiting the remaining |
| 880 |
time, then the client can accept this new master. If the lease |
| 881 |
was refreshed during the waiting period then the client does not accept |
| 882 |
this new master and returns.<br> |
| 883 |
</li> |
| 884 |
</ol> |
| 885 |
<h3>DUPMASTER</h3> |
| 886 |
A duplicate master situation can occur if an old master becomes |
| 887 |
disconnected from the rest of the group, that group elects a new master |
| 888 |
and then the partition is resolved. The requirement for master |
| 889 |
leases is that this situation will not cause the newly elected, |
| 890 |
rightful master to receive the <b>DB_REP_DUPMASTER</b> |
| 891 |
return. It is okay for the old master to get that return |
| 892 |
value. When a dual master situation exists, the following will |
| 893 |
happen:<br> |
| 894 |
<ul> |
| 895 |
<li><i>On the current master and all |
| 896 |
current clients</i> - If the current master receives an update |
| 897 |
message or other conflicting message from the old master then that |
| 898 |
message will be ignored because the generation number is out of date.</li> |
| 899 |
<li><i>On the old master</i> - If |
| 900 |
the old master receives an update message from the current master, or |
| 901 |
any other message with a later generation from any site, the new |
| 902 |
generation number will trigger this site to return <b>DB_REP_DUPMASTER</b>. |
| 903 |
However, |
| 904 |
instead of broadcasting out the <b>REP_DUPMASTER</b> |
| 905 |
message to shoot down others as well, this site, if leases are |
| 906 |
configured, will call <i>__rep_lease_check</i> |
| 907 |
and if they are expired, return the error. It should be |
| 908 |
impossible for us to receive a later generation message and still hold |
| 909 |
a majority of master leases. Something is seriously wrong and we |
| 910 |
will <b>DB_ASSERT</b> this situation |
| 911 |
cannot happen.<br> |
| 912 |
</li> |
| 913 |
</ul> |
| 914 |
<h3>Client to Client Synchronization</h3> |
| 915 |
One question to ask is how lease grants interact with client-to-client |
| 916 |
synchronization. The only answer is that they do not. A client |
| 917 |
that is sending log records to another client cannot request the |
| 918 |
receiving client refresh its lease with the master. That client |
| 919 |
does not have a timestamp it can use for the master and clock skew |
| 920 |
makes it meaningless between machines. Therefore, sites that use |
| 921 |
client-to-client synchronization will likely see more lease refreshment |
| 922 |
during the read path and leases will be refreshed during live updates |
| 923 |
only. Of course, if a client supplies log records that fill a |
| 924 |
gap, and the later log records stored came from the master in a live |
| 925 |
update then the client will respond as per the discussion on Gap |
| 926 |
Processing above.<br> |
| 927 |
<h2>Interaction Matrix</h2> |
| 928 |
If leases are granted (by a client) or held (by a master) what should |
| 929 |
the following APIs and messages do?<br> |
| 930 |
<br> |
| 931 |
Other:<br> |
| 932 |
log_archive: Leases do not affect log_archive. OK.<br> |
| 933 |
dbenv->close: OK.<br> |
| 934 |
crash during lease grant and restart: <b>Potential |
| 935 |
problem here. See discussion below</b>.<br> |
| 936 |
<br> |
| 937 |
Rep Base API method:<br> |
| 938 |
rep_elect: Already discussed above. Must wait for lease to expire.<br> |
| 939 |
rep_flush: Master only, OK - this will be the basis for refreshing |
| 940 |
leases.<br> |
| 941 |
rep_get_*: Not affected by leases.<br> |
| 942 |
rep_process_message: Generally OK. We'll discuss each message |
| 943 |
below.<br> |
| 944 |
rep_set_config: OK.<br> |
| 945 |
rep_set_limit: OK<br> |
| 946 |
rep_set_nsites: Must be called before <i>rep_start</i> |
| 947 |
and <i>nsites</i> is immutable until |
| 948 |
14778 is resolved.<br> |
| 949 |
rep_set_priority: OK<br> |
| 950 |
rep_set_timeout: OK. Used to set lease timeout.<br> |
| 951 |
rep_set_transport: OK.<br> |
| 952 |
rep_start(MASTER): Role changes are discussed above. Make sure |
| 953 |
duplicate rep_start calls are no-ops for leases.<br> |
| 954 |
rep_start(CLIENT): Role changes are discussed above. Make sure |
| 955 |
duplicate calls are no-ops for leases.<br> |
| 956 |
rep_stat: OK.<br> |
| 957 |
rep_sync: Should not be able to happen. Client cannot accept new |
| 958 |
master with outstanding lease grant. Add DB_ASSERT here.<br> |
| 959 |
<br> |
| 960 |
REP_ALIVE: OK.<br> |
| 961 |
REP_ALIVE_REQ: OK.<br> |
| 962 |
REP_ALL_REQ: OK.<br> |
| 963 |
REP_BULK_LOG: OK. Clients check to send ACK.<br> |
| 964 |
REP_BULK_PAGE: Should never process one with lease granted. Add |
| 965 |
DB_ASSERT.<br> |
| 966 |
REP_DUPMASTER: Should never happen, this is what leases are supposed to |
| 967 |
prevent. See above.<br> |
| 968 |
REP_LOG: OK. Clients check to send ACK.<br> |
| 969 |
REP_LOG_MORE: OK. Clients check to send ACK.<br> |
| 970 |
REP_LOG_REQ: OK.<br> |
| 971 |
REP_MASTER_REQ: OK.<br> |
| 972 |
REP_NEWCLIENT: OK.<br> |
| 973 |
REP_NEWFILE: OK. Clients check to send ACK.<br> |
| 974 |
REP_NEWMASTER: See above.<br> |
| 975 |
REP_NEWSITE: OK.<br> |
| 976 |
REP_PAGE: OK. Should never process one with lease granted. |
| 977 |
Add DB_ASSERT.<br> |
| 978 |
REP_PAGE_FAIL: OK. Should never process one with lease |
| 979 |
granted. Add DB_ASSERT.<br> |
| 980 |
REP_PAGE_MORE: OK. Should never process one with lease |
| 981 |
granted. Add DB_ASSERT.<br> |
| 982 |
REP_PAGE_REQ: OK.<br> |
| 983 |
REP_REREQUEST: OK.<br> |
| 984 |
REP_UPDATE: OK. Should never process one with lease |
| 985 |
granted. Add DB_ASSERT.<br> |
| 986 |
REP_UPDATE_REQ: OK. This is a master-only message.<br> |
| 987 |
REP_VERIFY: OK. Should never process one with lease |
| 988 |
granted. Add DB_ASSERT.<br> |
| 989 |
REP_VERIFY_FAIL: OK. Should never process one with lease |
| 990 |
granted. Add DB_ASSERT.<br> |
| 991 |
REP_VERIFY_REQ: OK.<br> |
| 992 |
REP_VOTE1: OK. See Election discussion above. It is |
| 993 |
possible to receive one with a lease granted. Client cannot send |
| 994 |
one with an outstanding lease however.<br> |
| 995 |
REP_VOTE2: OK. See Election discussion above. It is |
| 996 |
possible to receive one with a lease granted.<br> |
| 997 |
<br> |
| 998 |
If the following method or message processing is in progress and a |
| 999 |
client wants to grant a lease, what should it do? Let's examine |
| 1000 |
what this means. The client wanting to grant a lease simply means |
| 1001 |
it is responding to the receipt of a <b>REP_LOG</b> |
| 1002 |
(or its variants) message and applying a log record. Therefore, |
| 1003 |
we need to consider a thread processing a log message racing with these |
| 1004 |
other actions.<br> |
| 1005 |
<br> |
| 1006 |
Other:<br> |
| 1007 |
log_archive: OK. <br> |
| 1008 |
dbenv->close: User error. User should not be closing the env |
| 1009 |
while other threads are using that handle. Should have no effect |
| 1010 |
if a 2nd dbenv handle to same env is closed.<br> |
| 1011 |
<br> |
| 1012 |
Rep Base API method:<br> |
| 1013 |
rep_elect: See Election discussion above. <i>rep_elect</i> |
| 1014 |
should wait and may grant |
| 1015 |
lease while election is in progress.<br> |
| 1016 |
rep_flush: Should not be called on client.<br> |
| 1017 |
rep_get_*: OK.<br> |
| 1018 |
rep_process_message: Generally OK. See handling each message |
| 1019 |
below.<br> |
| 1020 |
rep_set_config: OK.<br> |
| 1021 |
rep_set_limit: OK.<br> |
| 1022 |
rep_set_nsites: Must be called before <i>rep_start</i> |
| 1023 |
until 14778 is resolved.<br> |
| 1024 |
rep_set_priority: OK.<br> |
| 1025 |
rep_set_timeout: OK.<br> |
| 1026 |
rep_set_transport: OK.<br> |
| 1027 |
rep_start(MASTER): OK, can't happen - already protect racing <i>rep_start</i> |
| 1028 |
and <i>rep_process_message</i>.<br> |
| 1029 |
rep_start(CLIENT): OK, can't happen - already protect racing <i>rep_start</i> |
| 1030 |
and <i>rep_process_message</i>.<br> |
| 1031 |
rep_stat: OK.<br> |
| 1032 |
rep_sync: Shouldn't happen because client cannot grant leases during |
| 1033 |
sync-up. Incoming log message ignored.<br> |
| 1034 |
<br> |
| 1035 |
REP_ALIVE: OK.<br> |
| 1036 |
REP_ALIVE_REQ: OK.<br> |
| 1037 |
REP_ALL_REQ: OK.<br> |
| 1038 |
REP_BULK_LOG: OK.<br> |
| 1039 |
REP_BULK_PAGE: OK. Incoming log message ignored during internal |
| 1040 |
init.<br> |
| 1041 |
REP_DUPMASTER: Shouldn't happen. See DUPMASTER discussion above.<br> |
| 1042 |
REP_LOG: OK.<br> |
| 1043 |
REP_LOG_MORE: OK.<br> |
| 1044 |
REP_LOG_REQ: OK.<br> |
| 1045 |
REP_MASTER_REQ: OK.<br> |
| 1046 |
REP_NEWCLIENT: OK.<br> |
| 1047 |
REP_NEWFILE: OK.<br> |
| 1048 |
REP_NEWMASTER: See above. If a client accepts a new master |
| 1049 |
because its lease grant expired, then that master sends a message |
| 1050 |
requesting the lease grant, this client will not process the log record |
| 1051 |
if it is in sync-up recovery, or it may after the master switch is |
| 1052 |
complete and the client doesn't need sync-up recovery. Basically, |
| 1053 |
just uses existing log record processing/newmaster infrastructure.<br> |
| 1054 |
REP_NEWSITE: OK.<br> |
| 1055 |
REP_PAGE: OK. Receiving a log record during internal init PAGE |
| 1056 |
phase should ignore log record.<br> |
| 1057 |
REP_PAGE_FAIL: OK.<br> |
| 1058 |
REP_PAGE_MORE: OK.<br> |
| 1059 |
REP_PAGE_REQ: OK.<br> |
| 1060 |
REP_REREQUEST: OK.<br> |
| 1061 |
REP_UPDATE: OK. Receiving a log record during internal init |
| 1062 |
should ignore log record.<br> |
| 1063 |
REP_UPDATE_REQ: OK - master-only message.<br> |
| 1064 |
REP_VERIFY: OK. Receiving a log record during verify phase |
| 1065 |
ignores log record.<br> |
| 1066 |
REP_VERIFY_FAIL: OK.<br> |
| 1067 |
REP_VERIFY_REQ: OK.<br> |
| 1068 |
REP_VOTE1: OK. This client is processing someone else's vote when |
| 1069 |
the lease request comes in. That is fine. We protect our |
| 1070 |
own election and lease interaction in <i>__rep_elect</i>.<br> |
| 1071 |
REP_VOTE2: OK.<br> |
| 1072 |
<h4>Crashing - Potential Problem<br> |
| 1073 |
</h4> |
| 1074 |
It appears there is one area where we could have a problem. I |
| 1075 |
believe that crashes can cause us to break our guarantee on durability, |
| 1076 |
authoritative reads and inability to elect duplicate masters. |
| 1077 |
Consider this scenario:<br> |
| 1078 |
<ol> |
| 1079 |
<li>A master and 4 clients are all up and running.</li> |
| 1080 |
<li>The master commits a txn and all 4 clients refresh their lease |
| 1081 |
grants at time T.</li> |
| 1082 |
<li>All 4 clients have the txn and log records in the cache. |
| 1083 |
None are flushing to disk.</li> |
| 1084 |
<li>All 4 clients have responded to the PERM messages as well as |
| 1085 |
refreshed their lease with the master.</li> |
| 1086 |
<li>All 4 clients hit the same application coding error and crash |
| 1087 |
(machine/OS stays up).</li> |
| 1088 |
<li>Master authoritatively reads data in txn from step 2.</li> |
| 1089 |
<li>All 4 clients restart the application and run recovery, thus the |
| 1090 |
txn from step 2 is lost on all clients because it isn't any logs.<span |
| 1091 |
style="font-weight: bold;"></span><br> |
| 1092 |
</li> |
| 1093 |
<li>A network partition happens and the master is alone on its side.</li> |
| 1094 |
<li>All 4 clients are on the other side and elect a new master.</li> |
| 1095 |
<li>Partition resolves itself and we have duplicate masters, where |
| 1096 |
the former master still holds all valid lease grants.<span |
| 1097 |
style="font-weight: bold;"></span><br> |
| 1098 |
</li> |
| 1099 |
</ol> |
| 1100 |
Therefore, we have broken both guarantees. In step 6 the data is |
| 1101 |
really not durable and we've given it to the user. One can argue |
| 1102 |
that if this is an issue the application better be syncing somewhere if |
| 1103 |
they really want durability. However, worse than that is that we |
| 1104 |
have a legitimate DUPMASTER situation in step 10 where both masters |
| 1105 |
hold valid leases. The reason is that all lease knowledge is in |
| 1106 |
the shared memory and that is lost when the app restarts and runs |
| 1107 |
recovery.<br> |
| 1108 |
<br> |
| 1109 |
How can we solve this? The obvious solution is (ugh, yet another) |
| 1110 |
durable BDB-owned file with some information in it, such as the current |
| 1111 |
lease expiration time so that rebooting after a crash leaves the |
| 1112 |
knowledge that the lease was granted. However, writing and |
| 1113 |
syncing every lease grant on every client out to disk is far too |
| 1114 |
expensive.<br> |
| 1115 |
<br> |
| 1116 |
A second possible solution is to have clients wait a full lease timeout |
| 1117 |
before entering an election the first time. This solution solves the |
| 1118 |
DUPMASTER issue, but not the non-authoritative read. This |
| 1119 |
solution naturally falls out of elections and leases really. If a |
| 1120 |
client has never granted a lease, it should be considered as having to |
| 1121 |
wait a full lease timeout before entering an election. |
| 1122 |
Applications already know that leases impact elections and this does |
| 1123 |
not seem so bad as it is only on the first election.<br> |
| 1124 |
<br> |
| 1125 |
Is it sufficient to document that the authoritative read is only as |
| 1126 |
authoritative as the durability guarantees they make on the sites that |
| 1127 |
indicate it is permanent? Yes, I believe this is sufficient. If |
| 1128 |
the application says it is permanent and it really isn't, then the |
| 1129 |
application is at fault. Believing the application when it |
| 1130 |
indicates with the PERM response that it is permanent avoids the |
| 1131 |
authoritative problem. <br> |
| 1132 |
<h2>Upgrade/Mixed Versions</h2> |
| 1133 |
Clearly leases cannot be used with mixed version sites since masters |
| 1134 |
running older releases will not have any knowledge of lease |
| 1135 |
support. What considerations are needed in the lease code for |
| 1136 |
mixed versions?<br> |
| 1137 |
<br> |
| 1138 |
First if the <b>REP_CONTROL</b> |
| 1139 |
structure changes, we need to maintain and use an old version of the |
| 1140 |
structure for talking to older clients and masters. The |
| 1141 |
implementation of this would be similar to the way we manage for old <b>REP_VOTE_INFO</b> |
| 1142 |
structures. |
| 1143 |
Second any new messages need translation table entries added. |
| 1144 |
Third, if we are assuming global leases then clearly any mixed versions |
| 1145 |
cannot have leases configured, and leases cannot be used in mixed |
| 1146 |
version groups. Maintaining two versions of the control structure |
| 1147 |
is not necessary if we choose a different style of implementation and |
| 1148 |
don't change the control structure.<br> |
| 1149 |
<br> |
| 1150 |
However, then how could an old application both run continuously, |
| 1151 |
upgrade to the new release and take advantage of leases without taking |
| 1152 |
down the entire application? I believe it is possible for clients |
| 1153 |
to be configured for leases but be subject to the master regarding |
| 1154 |
leases, yet the master code can assume that if it has leases |
| 1155 |
configured, all client sites do as well. In several places above |
| 1156 |
I suggested that a client could make a choice based on either a new <b>REPCTL_LEASE</b> |
| 1157 |
flag or simply having |
| 1158 |
leases turned on locally. If we choose to use the flag, then we |
| 1159 |
can support leases with mixed versions. The upgraded clients can |
| 1160 |
configure leases and they simply will not be granted until the old |
| 1161 |
master is upgraded and send PERM message with the flag indicating it |
| 1162 |
wants a lease grant. The client will not grant a lease until such |
| 1163 |
time. The clients, while having the leases configured, will not |
| 1164 |
grant a lease until told to do so and will simply have an expired |
| 1165 |
lease. Then, when the old master finally upgrades, it too can |
| 1166 |
configure leases and suddenly all sites are using them. I believe |
| 1167 |
this should work just fine and I will need to make sure a client's |
| 1168 |
granting of leases is only in response to the master asking for a |
| 1169 |
grant. If the master never asks, then the client has them |
| 1170 |
configured, but doesn't grant them.<br> |
| 1171 |
<h2>Testing</h2> |
| 1172 |
Clearly any user-facing API changes will need the equivalent reflection |
| 1173 |
in the Tcl API for testing, under CONFIG_TEST.<br> |
| 1174 |
<br> |
| 1175 |
I am sure the list of tests will grow but off the top of my head:<br> |
| 1176 |
Basic test: have N sites all configure leases, run some, read on |
| 1177 |
master, etc.<br> |
| 1178 |
Refresh test: Perform update on master, sleep until past expiration, |
| 1179 |
read on master and make sure leases are refreshed/read successful<br> |
| 1180 |
Error test: Test error conditions (reading on client with leases but no |
| 1181 |
ignore flag, calling after rep_start, etc)<br> |
| 1182 |
Read test: Test reading on both client and master both with and without |
| 1183 |
the IGNORE flag. Test that data read with the ignore flag can be |
| 1184 |
rolled back.<br> |
| 1185 |
Dupmaster test: Force a DUPMASTER situation and verify that the newer |
| 1186 |
master cannot get DUPMASTER error.<br> |
| 1187 |
Election test: Call election while grant is outstanding and master |
| 1188 |
exists.<br> |
| 1189 |
Call election while grant is outstanding and master does not exist.<br> |
| 1190 |
Call election after expiration on quiescient system with master |
| 1191 |
existing.<br> |
| 1192 |
Run with a group where some members have leases configured and other do |
| 1193 |
not to make sure we get errors instead of dumping core.<br> |
| 1194 |
<br> |
| 1195 |
<small><br> |
| 1196 |
</small> |
| 1197 |
</body> |
| 1198 |
</html> |