]> git.sur5r.net Git - openldap/blob - doc/guide/admin/syncrepl.sdf
Minor tweaks
[openldap] / doc / guide / admin / syncrepl.sdf
1 # $OpenLDAP$
2 # Copyright 2003, The OpenLDAP Foundation, All Rights Reserved.
3 # COPYING RESTRICTIONS APPLY, see COPYRIGHT.
4
5 H1: LDAP Sync Replication
6
7 The LDAP Sync replication engine, syncrepl for short, is a consumer-side
8 replication engine that enables the consumer LDAP server to maintain
9 a shadow copy of a DIT fragment. A syncrepl engine resides at the
10 consumer-side as one of the {{slapd}} (8) threads. It creates and
11 maintains a consumer replica by connecting to the replication provider
12 to perform the initial DIT content load followed either by
13 periodic content polling or by timely updates upon content changes.
14
15 Syncrepl uses the LDAP Content Synchronization (or LDAP Sync for short)
16 protocol as the replica synchronization protocol.  It provides a stateful
17 replication which supports both 
18 pull-based and push-based synchronization and does not mandate
19 the use of a history store.
20
21 Syncrepl keeps track of the status of the replication content by
22 maintaining and exchanging synchronization cookies. Because the
23 syncrepl consumer and provider maintain their content status,
24 the consumer can poll the provider content to perform incremental
25 synchronization by asking for the entries required to make the consumer
26 replica up-to-date with the provider content. Syncrepl also enables
27 convenient management of replicas by maintaining replica status.
28 The consumer replica can be constructed from a consumer-side or a
29 provider-side backup at any synchronization status. Syncrepl can
30 automatically resynchronize the consumer replica up-to-date with the
31 current provider content.
32
33 Syncrepl supports both pull-based and 
34 push-based synchronization. In its basic refreshOnly synchronization mode,
35 the provider uses pull-based synchronization where the consumer servers
36 need not be tracked and no history information is maintained.
37 The information required for the provider to process periodic polling
38 requests is contained in the synchronization cookie of the request itself.
39 To optimize the pull-based synchronization, syncrepl utilizes the present
40 phase of the LDAP Sync protocol as well as its delete phase, instead of
41 falling back on frequent full reloads. To further optimize the pull-based
42 synchronization, the provider can maintain a per-scope session log
43 as a history store. In its refreshAndPersist mode of synchronization,
44 the provider uses a push-based synchronization. The provider keeps
45 track of the consumer servers that have requested a persistent search
46 and sends them necessary updates as the provider replication content
47 gets modified.
48
49 With syncrepl, a consumer server can create a replica without changing
50 the provider's configurations and without restarting the provider server,
51 if the consumer server has appropriate access privileges for the
52 DIT fragment to be replicated. The consumer server can stop the
53 replication also without the need for provider-side changes and restart.
54
55 Syncrepl supports both partial and sparse replications.
56 The shadow DIT fragment is defined by a general
57 search criteria consisting of base, scope, filter, and attribute list.
58 The replica content is also subject to the access privileges
59 of the bind identity of the syncrepl replication connection.
60
61
62 H2: The LDAP Content Synchronization Protocol
63
64 The LDAP Sync protocol allows a client to maintain a synchronized copy
65 of a DIT fragment. The LDAP Sync operation is defined as a set of
66 controls and other protocol elements which extend the LDAP search
67 operation. This section introduces the LDAP Content Sync protocol
68 only briefly. For more information, refer to the Internet Draft
69 {{The LDAP Content Synchronization Operation
70 <draft-zeilenga-ldup-sync-05.txt>}}.
71
72 The LDAP Sync protocol supports both polling and listening for
73 changes by defining two respective synchronization operations:
74 {{refreshOnly}} and {{refreshAndPersist}}.
75 Polling is implemented by the {{refreshOnly}} operation.
76 The client copy is synchronized to the server copy at the time of polling.
77 The server finishes the search operation by returning {{SearchResultDone}}
78 at the end of the search operation as in the normal search.
79 The listening is implemented by the {{refreshAndPersist}} operation.
80 Instead of finishing the search after returning all entries currently
81 matching the search criteria, the synchronization search remains
82 persistent in the server. Subsequent updates to the synchronization content
83 in the server cause additional entry updates to be sent to the client.
84
85 The {{refreshOnly}} operation and the refresh stage of the
86 {{refreshAndPersist}} operation can be performed with 
87 a present phase or a delete phase.
88
89 In the present phase, the server sends the client the entries updated
90 within the search scope since the last synchronization. The server sends
91 all requested attributes, be it changed or not, of the updated entries.
92 For each unchanged entry which remains in the scope,
93 the server sends a present message consisting only of the name of the
94 entry and the synchronization control representing state present.
95 The present message does not contain any attributes of the entry.
96 After the client receives all update and present entries,
97 it can reliably determine the new client copy by adding the entries
98 added to the server, by replacing the entries modified at the server,
99 and by deleting entries in the client copy which have not
100 been updated nor specified as being present at the server.
101
102 The transmission of the updated entries in the delete phase is 
103 the same as in the present phase. The server sends all the requested
104 attributes of the entries updated within the search scope since the
105 last synchronization to the client. In the delete phase, however,
106 the server sends a delete message for each entry deleted from the
107 search scope, instead of sending present messages.
108 The delete message consists only of the name of the entry
109 and the synchronization control representing state delete.
110 The new client copy can be determined by adding, modifying, and
111 removing entries according to the synchronization control
112 attached to the {{SearchResultEntry}} message.
113
114 In the case that the LDAP Sync server maintains a history store
115 and can determine which entries are scoped out of the client
116 copy since the last synchronization time, the server can use
117 the delete phase. If the server does not maintain any history store,
118 cannot determine the scoped-out entries from the history store,
119 or the history store does not cover the outdated synchronization
120 state of the client, the server should use the present phase.
121 The use of the present phase is much more efficient than a full
122 content reload in terms of the synchronization traffic.
123 To reduce the synchronization traffic further,
124 the LDAP Sync protocol also provides several optimizations
125 such as the transmission of the normalized {{EX:entryUUID}}s and the
126 transmission of multiple {{EX:entryUUIDs}} in a single
127 {{syncIdSet}} message.
128
129 At the end of the {{refreshOnly}} synchronization,
130 the server sends a synchronization cookie to the client as a state
131 indicator of the client copy after the synchronization is completed.
132 The client will present the received cookie when it requests
133 the next incremental synchronization to the server.
134
135 When {{refreshAndPersist}} synchronization is used,
136 the server sends a synchronization cookie at the end of the
137 refresh stage by sending a Sync Info message with TRUE refreshDone.
138 It also sends a synchronization cookie by attaching it to
139 {{SearchResultEntry}} generated in the persist stage of the
140 synchronization search. During the persist stage, the server
141 can also send a Sync Info message containing the synchronization
142 cookie at any time the server wants to update the client-side state
143 indicator.  The server also updates a synchronization indicator
144 of the client at the end of the persist stage.
145
146 In the LDAP Sync protocol, entries are uniquely identified by
147 the {{EX:entryUUID}} attribute value. It can function as a reliable
148 identifier of the entry. The DN of the entry, on the other hand,
149 can be changed over time and hence cannot be considered as the reliable
150 identifier.  The {{EX:entryUUID}} is attached to each {{SearchResultEntry}}
151 or {{SearchResultReference}} as a part of the synchronization control.
152
153
154 H2: Syncrepl Details
155
156 The syncrepl engine utilizes both the {{refreshOnly}} and the
157 {{refreshAndPersist}} operations of the LDAP Sync protocol.
158 If a syncrepl specification is included in a database definition,
159 {{slapd}} (8) launches a syncrepl engine as a {{slapd}} (8) thread
160 and schedules its execution. If the {{refreshOnly}} operation is
161 specified, the syncrepl engine will be rescheduled at the interval
162 time after a synchronization operation is completed.
163 If the {{refreshAndPersist}} operation is specified, the engine will
164 remain active and process the persistent synchronization messages
165 from the provider.
166
167 The syncrepl engine utilizes both the present phase and the
168 delete phase of the refresh synchronization. It is possible to
169 configure a per-scope session log in the provider server
170 which stores the {{EX:entryUUID}}s of a finite
171 number of entries deleted from a replication content.
172 Multiple replicas of single provider content share the same
173 per-scope session log. The syncrepl engine uses the delete phase
174 if the session log is present and the state of the consumer
175 server is recent enough that no session log entries are truncated
176 after the last synchronization of the client.
177 The syncrepl engine uses the present phase if no session log
178 is configured for the replication content or if the
179 consumer replica is too outdated to be covered by the session log.
180 The current design of the session log store is memory based, so
181 the information contained in the session log is not persistent
182 over multiple provider invocations. It is not currently supported
183 to access the session log store by using LDAP operations. It is
184 also not currently supported to impose access control to the session log.
185
186 As a further optimization, even in the case the synchronization search
187 is not associated with any session log, no entries will be transmitted
188 to the consumer server when there has been no update in the replication
189 context.
190
191 The syncrepl engine, which is a consumer-side replication engine,
192 can work with any backends. The LDAP Sync provider can be configured
193 as an overlay on any backend, but works best with the {{back-bdb}} or
194 {{back-hdb}} backend. The provider can not support refreshAndPersist
195 mode on {{back-ldbm}} due to limits in that backend's locking architecture.
196
197 The LDAP Sync provider maintains a {{EX:contextCSN}} for each
198 database as the current synchronization state indicator of the
199 provider content.  It is the largest {{EX:entryCSN}} in the provider
200 context such that no transactions for an entry having
201 smaller {{EX:entryCSN}} value remains outstanding.
202 The {{EX:contextCSN}} could not just be set to the largest issued
203 {{EX:entryCSN}} because {{EX:entryCSN}} is obtained before
204 a transaction starts and transactions are not committed in the
205 issue order.
206
207 The provider stores the {{EX:contextCSN}} of a context in the
208 {{EX:contextCSN}} attribute of the context suffix entry. The attribute
209 is not written to the database after every update operation though;
210 instead it is maintained primarily in memory. At database start time
211 the provider reads the last saved {{EX:contextCSN}} into memory and
212 uses the in-memory copy exclusively thereafter. By default, changes
213 to the {{EX:contextCSN}} as a result of database updates will not be
214 written to the database until the server is cleanly shut down. A
215 checkpoint facility exists to cause the contextCSN to be written
216 out more frequently if desired.
217
218 Note that at startup time, if the
219 provider is unable to read a {{EX:contextCSN}} from the suffix entry,
220 it will scan the entire database to determine the value, and this
221 scan may take quite a long time on a large database. When a {{EX:contextCSN}}
222 value is read, the database will still be scanned for any {{EX:entryCSN}}
223 values greater than it, to make sure the {{EX:contextCSN}} value truly
224 reflects the greatest committed {{EX:entryCSN}} in the database. On
225 databases which support inequality indexing, setting an eq index
226 on the {{EX:entryCSN}} attribute and configuring {{contextCSN}} checkpoints
227 will greatly speed up this scanning step.
228
229 If no {{EX:contextCSN}} can be determined by reading and scanning the
230 database, a new value will be generated. Also, if scanning the database
231 yielded a greater {{EX:entryCSN}} than was previously recorded in the
232 suffix entry's {{EX:contextCSN}} attribute, a checkpoint will be immediately
233 written with the new value.
234
235 The consumer stores its replica state, which is the provider's
236 {{EX:contextCSN}} received as a synchronization cookie,
237 in the {{EX:syncreplCookie}} attribute of the immediate child
238 of the context suffix whose DN is {{cn=syncrepl<rid>,<suffix>}}
239 and object class is {{EX:syncConsumerSubentry}}.
240 The replica state maintained by a consumer server is used as the
241 synchronization state indicator when it performs subsequent incremental
242 synchronization with the provider server. It is also used as a
243 provider-side synchronization state indicator when it functions as
244 a secondary provider server in a cascading replication configuration.
245 <rid> is the replica ID uniquely identifying the replica locally in the
246 syncrepl consumer server. <rid> is an integer which has no more than
247 three decimal digits.
248
249 It is possible to retrieve the
250 {{EX:syncConsumerSubentry}} by performing an LDAP search with
251 the respective entry as the base object and with the base scope.
252
253 Because a general search filter can be used in the syncrepl specification,
254 some entries in the context may be omitted from the synchronization content.
255 The syncrepl engine creates a glue entry to fill in the holes
256 in the replica context if any part of the replica content is
257 subordinate to the holes. The glue entries will not be returned
258 as the search result unless {{ManageDsaIT}} control is provided.
259
260 Also as a consequence of the search filter used in the syncrepl
261 specification, it is possible for a modification to remove an
262 entry from the replication scope even though the entry has not
263 been deleted on the provider. Logically the entry must be deleted on the
264 consumer but in {{refreshOnly}} mode the provider cannot detect
265 and propagate this change without the use of the session log.
266
267 H2: Configuring Syncrepl
268
269 Because syncrepl is a consumer-side replication engine, the syncrepl
270 specification is defined in {{slapd.conf}} (5) of the consumer server,
271 not in the provider server's configuration file.
272 The initial loading of the replica content can be performed either
273 by starting the syncrepl engine with no synchronization cookie
274 or by populating the consumer replica by adding and demoting an
275 {{TERM:LDIF}} file dumped as a backup at the provider.
276 {{slapadd}} (8) supports the replica promotion and demotion.
277
278 When loading from a backup, it is not required to perform the initial
279 loading from the up-to-date backup of the provider content. The syncrepl
280 engine will automatically synchronize the initial consumer replica to
281 the current provider content. As a result, it is not required
282 to stop the provider server in order to avoid the replica inconsistency
283 caused by the updates to the provider content during the
284 content backup and loading process.
285
286 When replicating a large scale directory, especially in a bandwidth
287 constrained environment, it is advised to load the consumer replica
288 from a backup instead of performing a full initial load using syncrepl.
289
290 H3: Set up the provider slapd
291
292 The provider is implemented as an overlay, so the overlay itself must
293 first be configured in {{slapd.conf}} (5) before it can be used. The
294 provider has only two configuration directives, for setting checkpoints
295 on the {{EX:contextCSN}} and for configuring the session log.
296 Because the
297 LDAP Sync search is subject to access control, proper access control
298 privileges should be set up for the replicated content.
299
300 The {{EX:contextCSN}} checkpoint is configured by the
301
302 >       syncprov-checkpoint <ops> <minutes>
303
304 directive. Checkpoints are only tested after successful write operations.
305 If {{<ops>}} operations or more than {{<minutes>}} time has passed
306 since the last checkpoint, a new checkpoint is performed.
307
308 The session log is configured by the
309
310 >       syncprov-sessionlog <sid> <size>
311
312 directive, where {{<sid>}} is the ID of the per-scope session log
313 in the provider server and {{<size>}} is the maximum number of
314 session log entries the session log can record. {{<sid>}}
315 is an integer no longer than 3 decimal digits. If the consumer
316 server sends a synchronization cookie containing {{sid=<sid>}}
317 where {{<sid>}} matches the session log ID specified in the directive,
318 the LDAP Sync search is to utilize the session log.
319
320 Note that using the session log requires searching on the {{entryUUID}}
321 attribute. Setting an eq index on this attribute will greatly
322 benefit the performance of the session log on the provider.
323
324 A more complete example of the {{slapd.conf}} content is thus:
325
326 >       database bdb
327 >       suffix dc=Example,dc=com
328 >       directory /var/ldap/db
329 >       index objectclass,entryCSN,entryUUID eq
330 >
331 >       overlay syncprov
332 >       syncprov-checkpoint 100 10
333 >       syncprov-sessionlog 0 100
334
335
336 H3: Set up the consumer slapd
337
338 The syncrepl replication is specified in the database section
339 of {{slapd.conf}} (5) for the replica context.
340 The syncrepl engine is backend independent and the directive
341 can be defined with any database type.
342
343 >       syncrepl rid=123
344 >               provider=ldap://provider.example.com:389
345 >               type=refreshOnly
346 >               interval=01:00:00:00
347 >               searchbase="dc=example,dc=com"
348 >               filter="(objectClass=organizationalPerson)"
349 >               scope=sub
350 >               attrs="cn,sn,ou,telephoneNumber,title,l"
351 >               schemachecking=off
352 >               updatedn="cn=replica,dc=example,dc=com"
353 >               bindmethod=simple
354 >               binddn="cn=syncuser,dc=example,dc=com"
355 >               credentials=secret
356
357 In this example, the consumer will connect to the provider slapd
358 at port 389 of {{FILE:ldap://provider.example.com}} to perform a
359 polling ({{refreshOnly}}) mode of synchronization once a day.  It will
360 bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple authentication
361 with password "secret".  Note that the access control privilege of
362 {{EX:cn=syncuser,dc=example,dc=com}} should be set appropriately 
363 in the provider to retrieve the desired replication content.
364 The consumer will write to its database with the privilege of the
365 {{EX:cn=replica,dc=example,dc=com}} entry as specified in the
366 {{EX:updatedn=}} directive. The {{EX:updatedn}} entry should have
367 write permission to the replica content.
368
369 The synchronization search in the above example will search for the
370 entries whose objectClass is organizationalPerson in the entire subtree
371 rooted at {{EX:dc=example,dc=com}}. The requested attributes are
372 {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}},
373 {{EX:title}}, and {{EX:l}}. The schema checking is turned off, so
374 that the consumer {{slapd}} (8) will not enforce entry schema checking
375 when it process updates from the provider {{slapd}} (8).
376
377 For more detailed information on the syncrepl directive,
378 see the {{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}}
379 chapter of this admin guide.
380                      
381 H3: Start the provider and the consumer slapd
382
383 The provider {{slapd}} (8) is not required to be restarted.
384 {{contextCSN}} is automatically generated as needed:
385 it might originally contained in the {{TERM:LDIF}} file,
386 generated by {{slapadd}} (8), generated upon changes in the context,
387 or generated when the first LDAP Sync search arrived at the provider.
388
389 When starting a consumer {{slapd}} (8), it is possible to provide a
390 synchronization cookie as the {{-c cookie}} command line option
391 in order to start the synchronization from a specific state.
392 The cookie is a comma separated list of name=value pairs. Currently
393 supported syncrepl cookie fields are {{csn=<csn>}}, {{sid=<sid>}}, and
394 {{rid=<rid>}}. {{<csn>}} represents the current synchronization state
395 of the consumer replica. {{<sid>}} is the identity of the per-scope
396 session log to which this consumer will be associated. {{<rid>}} identifies
397 a consumer replica locally within the consumer server. It is used to relate
398 the cookie to the syncrepl definition in {{slapd.conf}} (5) which has
399 the matching replica identifier.
400 Both {{<sid>}} and {{<rid>}} have no more than 3 decimal digits.
401 The command line cookie overrides the synchronization cookie
402 stored in the consumer replica database.