]> git.sur5r.net Git - openldap/blob - doc/guide/admin/syncrepl.sdf
Fix typo
[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.
17
18 Syncrepl provides a stateful replication which supports both the
19 pull-based and the push-based synchronizations and does not mandate
20 the use of the history store.
21
22 Syncrepl keeps track of the status of the replication content by
23 maintaining and exchanging synchronization cookies. Because the
24 syncrepl consumer and provider maintain their content status,
25 the consumer can poll the provider content to perform incremental
26 synchronization by asking the entries required to make the consumer
27 replica up-to-date with the provider content. Syncrepl also enables
28 convenient management of replicas by maintaining replica status.
29 The consumer replica can be constructed from a consumer-side or a
30 provider-side backup at any synchronization status. Syncrepl can
31 automatically resynchronize the consumer replica up-to-date with the
32 current provider content.
33
34 Syncrepl supports both the pull-based and the
35 push-based synchronization. In its basic refreshOnly mode synchronization,
36 the provider uses a pull-based synchronization where the consumer servers
37 need not be tracked and no history information is maintained.
38 The information required for the provider to process periodic polling
39 requests is contained in the synchronization cookie of the request itself.
40 To optimize the pull-based synchronization, syncrepl utilizes the present
41 phase of the LDAP Sync protocol as well as its delete phase, instead of
42 falling back on frequent full reloads. To further optimize the pull-based
43 synchronization, the provider can maintain a per-scope session log
44 as the history store. In its refreshAndPersist mode of synchronization,
45 the provider uses a push-based synchronization. The provider keeps
46 track of the consumer servers that have requested the persistent search
47 and sends them necessary updates as the provider replication content
48 gets modified.
49
50 With syncrepl, a consumer server can create a replica without changing
51 provider's configurations and without restarting the provider server,
52 if the consumer server has appropriate access privileges for the
53 DIT fragment to be replicated. The consumer server can stop the
54 replication also without the need for provider-side changes and restart.
55
56 Syncrepl supports both partial and sparse replications.
57 The shadow DIT fragment is defined by a general
58 search criteria consisting of base, scope, filter, and attribute list.
59 The replica content is also subject to the access privileges
60 of the bind identity of the syncrepl replication connection.
61
62
63 H2: The LDAP Content Synchronization Protocol
64
65 The LDAP Sync protocol allows a client to maintain a synchronized copy
66 of a DIT fragment. The LDAP Sync operation is defined as a set of
67 controls and other protocol elements which extend the LDAP search
68 operation. This section introduces the LDAP Content Sync protocol
69 only briefly. For more information, refer to the Internet Draft
70 {{The LDAP Content Synchronization Operation
71 <draft-zeilenga-ldup-sync-05.txt>}}.
72
73 The LDAP Sync protocol supports both polling and listening for
74 changes by defining two respective synchronization operations:
75 {{refreshOnly}} and {{refreshAndPersist}}.
76 The polling is implemented by the {{refreshOnly}} operation.
77 The client copy is synchronized to the server copy at the time of polling.
78 The server finishes the search operation by returning {{SearchResultDone}}
79 at the end of the search operation as in the normal search.
80 The listening is implemented by the {{refreshAndPersist}} operation.
81 Instead of finishing the search after returning all entries currently
82 matching the search criteria, the synchronization search remains
83 persistent in the server. Subsequent updates to the synchronization content
84 in the server have additional entry updates be sent to the client.
85
86 The {{refreshOnly}} operation and the refresh stage of the
87 {{refreshAndPersist}} operation can be performed by 
88 a present phase or a delete phase.
89
90 In the present phase, the server sends the client the entries updated
91 within the search scope since the last synchronization. The server sends
92 all requested attributes, be it changed or not, of the updated entries.
93 For each unchanged entry which remains in the scope,
94 the server sends a present message consisting only of the name of the
95 entry and the synchronization control representing state present.
96 The present message does not contain any attributes of the entry.
97 After the client receives all update and present entries,
98 it can reliably determine the new client copy by adding the entries
99 added to the server, by replacing the entries modified at the server,
100 and by deleting entries in the client copy which have not
101 been updated nor specified as being present at the server.
102
103 The transmission of the updated entries in the delete phase is 
104 the same as in the present phase. The server sends all the requested
105 attributes of the entries updated within the search scope since the
106 last synchronization to the client. In the delete phase, however,
107 the server sends a delete message for each entry deleted from the
108 search scope, instead of sending present messages.
109 The delete message consists only of the name of the entry
110 and the synchronization control representing state delete.
111 The new client copy can be determined by adding, modifying, and
112 removing entries according to the synchronization control
113 attached to the {{SearchResultEntry}} message.
114
115 In the case that the LDAP Sync server maintains a history store
116 and can determine which entries are scoped out of the client
117 copy since the last synchronization time, the server can use
118 the delete phase. If the server does not maintain any history store,
119 cannot determine the scoped-out entries from the history store,
120 or the history store does not cover the outdated synchronization
121 state of the client, the server should use the present phase.
122 The use of the present phase is much more efficient than a full
123 content reload in terms of the synchronization traffic.
124 To reduce the synchronization traffic further,
125 the LDAP Sync protocol also provides several optimizations
126 such as the transmission of the normalized {{EX:entryUUID}}s and the
127 transmission of the multiple {{EX:entryUUIDs}} in a single
128 {{syncIdSet}} message.
129
130 At the end of the {{refreshOnly}} synchronization,
131 the server sends a synchronization cookie to the client as a state
132 indicator of the client copy after the synchronization is completed.
133 The client will present the received cookie when it requests
134 the next incremental synchronization to the server.
135
136 When {{refreshAndPersist}} synchronization is used,
137 the server sends a synchronization cookie at the end of the
138 refresh stage by sending a Sync Info message with TRUE refreshDone.
139 It also sends a synchronization cookie by attaching it to
140 {{SearchResultEntry}} generated in the persist stage of the
141 synchronization search. During the persist stage, the server
142 can also send a Sync Info message containing the synchronization
143 cookie at any time the server wants to update the client-side state
144 indicator.  The server also updates a synchronization indicator
145 of the client at the end of the persist stage.
146
147 In the LDAP Sync protocol, entries are uniquely identified by
148 the {{EX:entryUUID}} attribute value. It can function as a reliable
149 identifier of the entry. The DN of the entry, on the other hand,
150 can be changed over time and hence cannot be considered as the reliable
151 identifier.  The {{EX:entryUUID}} is attached to each {{SearchResultEntry}}
152 or {{SearchResultReference}} as a part of the synchronization control.
153
154
155 H2: Syncrepl Details
156
157 The syncrepl engine utilizes both the {{refreshOnly}} and the
158 {{refreshAndPersist}} operations of the LDAP Sync protocol.
159 If a syncrepl specification is included in a database definition,
160 {{slapd}} (8) launches a syncrepl engine as a {{slapd}} (8) thread
161 and schedules its execution. If the {{refreshOnly}} operation is
162 specified, the syncrepl engine will be rescheduled at the interval
163 time after a synchronization operation is completed.
164 If the {{refreshAndPersist}} operation is specified, the engine will
165 remain active and process the persistent synchronization messages
166 from the provider.
167
168 The syncrepl engine utilizes both the present phase and the
169 delete phase of the refresh synchronization. It is possible to
170 configure a per-scope session log in the provider server
171 which stores the {{EX:entryUUID}}s and the names of a finite
172 number of entries deleted from a replication content.
173 Multiple replicas of single provider content share the same
174 per-scope session log. The syncrepl engine uses the delete phase
175 if the session log is present and the state of the consumer
176 server is recent enough that no session log entries are truncated
177 after the last synchronization of the client.
178 The syncrepl engine uses the present phase if no session log
179 is configured for the replication content or if the
180 consumer replica is too outdated to be covered by the session log.
181 The current design of the session log store is memory based, so
182 the information contained in the session log is not persistent
183 over multiple provider invocations. It is not currently supported
184 to access the session log store by using LDAP operations. It is
185 also not currently supported to impose access control to the session log.
186
187 As a further optimization, even in the case the synchronization search
188 is not associated with any session log, no entries will be transmitted
189 to the consumer server when there has been no update in the replication
190 context.
191
192 While {{slapd}} (8) can function as the LDAP Sync provider only
193 when it is configured with either {{back-bdb}} or {{back-hdb}} backend,
194 the syncrepl engine, which is a consumer-side replication engine,
195 can work with any backends.
196
197 The LDAP Sync provider maintains {{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 {{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:syncreplCookie}} attribute of the immediate child entry of
209 the context suffix whose DN is {{cn=ldapsync,<suffix>}} and
210 object class is {{EX:syncProviderSubentry}}.
211
212 The consumer stores its replica state, which is the provider's
213 {{EX:contextCSN}} received as a synchronization cookie,
214 in the {{EX:syncreplCookie}} attribute of the immediate child
215 of the context suffix whose DN is {{cn=syncrepl<rid>,<suffix>}}
216 and object class is {{EX:syncConsumerSubentry}}.
217 The replica state maintained by a consumer server is used as the
218 synchronization state indicator when it performs subsequent incremental
219 synchronization with the provider server. It is also used as a
220 provider-side synchronization state indicator when it functions as
221 a secondary provider server in a cascading replication configuration.
222 <rid> is the replica ID uniquely identifying the replica locally in the
223 syncrepl consumer server. <rid> is an integer which has no more than
224 three decimal digits.
225
226 Because a general search filter can be used in the syncrepl specification,
227 not all entries in the context will be returned as the synchronization content.
228 The syncrepl engine creates a glue entry to fill in the holes
229 in the replica context if any part of the replica content is
230 subordinate to the holes. The glue entries will not be returned
231 as the search result unless {{ManageDsaIT}} control is provided.
232
233 It is possible to retrieve {{EX:syncProviderSubentry}} and
234 {{EX:syncConsumerSubentry}} by performing an LDAP search with
235 the respective entries as the base object and with the base scope.
236
237
238 H2: Configuring Syncrepl
239
240 Because syncrepl is a consumer-side replication engine, the syncrepl
241 specification is defined in {{slapd.conf}} (5) of the consumer server,
242 not in the provider server's configuration file.
243 The initial loading of the replica content can be performed either
244 by starting the syncrepl engine with no synchronization cookie
245 or by populating the consumer replica by adding and demoting an
246 {{TERM:LDIF}} file dumped as a backup at the provider.
247 {{slapadd}} (8) supports the replica promotion and demotion.
248
249 When loading from a backup, it is not required to perform the initial
250 loading from the up-to-date backup of the provider content. The syncrepl
251 engine will automatically synchronize the initial consumer replica to
252 the current provider content. As a result, it is not required
253 to stop the provider server in order to avoid the replica inconsistency
254 caused by the updates to the provider content during the
255 content backup and loading process.
256
257 When replicating a large scale directory, especially in a bandwidth
258 constrained environment, it is advised to load the consumer replica
259 from a backup instead of performing a full initial load using syncrepl.
260
261 H3: Set up the provider slapd
262
263 There is no special {{slapd.conf}} (5) directive for the provider
264 syncrepl server except for the session log directive.  Because the
265 LDAP Sync search is subject to access control, proper access control
266 privileges should be set up for the replicated content.
267
268 When creating a provider database from the {{TERM:LDIF}} file using
269 {{slapadd}} (8), {{EX:contextCSN}} and the {{EX:syncProviderSubentry}}
270 entry must be created. {{slapadd -p -w}} will create
271 a new {{EX:contextCSN}} from the {{EX:entryCSN}}s of the added entries.
272 It is also possible to create the {{EX:syncProviderSubentry}} with
273 an appropriate {{EX:contextCSN}} value by directly including it
274 in the ldif file. {{slapadd -p}} will preserve the provider's
275 contextCSN or will change it to the consumer's contextCSN
276 if it is to promote a replica to the provider's content.
277 The {{EX:syncProviderSubentry}} can be included in the ldif output
278 when {{slapcat}} (8) is given the {{-m}} flag;
279 the {{EX:syncConsumerSubentry}} can be retrieved by the {{-k}}
280 flag of {{slapcat}} (8).
281
282 The session log is configured by
283
284 >       sessionlog <sid> <limit>
285
286 directive, where {{<sid>}} is the ID of the per-scope session log
287 in the provider server and {{<limit>}} is the maximum number of
288 session log entries the session log store can record. {{<sid>}}
289 is an integer no longer than 3 decimal digits. If the consumer
290 server sends a synchronization cookie containing {{sid=<sid>}}
291 where {{<sid>}} matches the session log ID specified in the directive,
292 the LDAP Sync search is to utilize the session log store.
293
294 H3: Set up the consumer slapd
295
296 The syncrepl replication is specified in the database section
297 of {{slapd.conf}} (5) for the replica context.
298 The syncrepl engine is backend independent and the directive
299 can be defined with any database type.
300
301 >       syncrepl rid=123
302 >               provider=ldap://provider.example.com:389
303 >               type=refreshOnly
304 >               interval=01:00:00:00
305 >               searchbase="dc=example,dc=com"
306 >               filter="(objectClass=organizationalPerson)"
307 >               scope=sub
308 >               attrs="cn,sn,ou,telephoneNumber,title,l"
309 >               schemachecking=off
310 >               updatedn="cn=replica,dc=example,dc=com"
311 >               bindmethod=simple
312 >               binddn="cn=syncuser,dc=example,dc=com"
313 >               credentials=secret
314
315 In this example, the consumer will connect to the provider slapd
316 at port 389 of {{FILE:ldap://provider.example.com}} to perform a
317 polling ({{refreshOnly}}) mode of synchronization once a day.  It will
318 bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple authentication
319 with password "secret".  Note that the access control privilege of
320 {{EX:cn=syncuser,dc=example,dc=com}} should be set appropriately 
321 in the provider to retrieve the desired replication content.
322 The consumer will write to its database with the privilege of the
323 {{EX:cn=replica,dc=example,dc=com}} entry as specified in the
324 {{EX:updatedn=}} directive. The {{EX:updatedn}} entry should have
325 write permission to the replica content.
326
327 The synchronization search in the above example will search for the
328 entries whose objectClass is organizationalPerson in the entire subtree
329 rooted at {{EX:dc=example,dc=com}}. The requested attributes are
330 {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}},
331 {{EX:title}}, and {{EX:l}}. The schema checking is turned off, so
332 that the consumer {{slapd}} (8) will not enforce entry schema checking
333 when it process updates from the provider {{slapd}} (8).
334
335 For more detailed information on the syncrepl directive,
336 see the {{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}}
337 chapter of this admin guide.
338                      
339 H3: Start the provider and the consumer slapd
340
341 The provider {{slapd}} (8) is not required to be restarted.
342 {{contextCSN}} is automatically generated as needed:
343 it might originally contained in the {{TERM:LDIF}} file,
344 generated by {{slapadd}} (8), generated upon changes in the context,
345 or generated when the first LDAP Sync search arrived at the provider.
346
347 When starting a consumer {{slapd}} (8), it is possible to provide a
348 synchronization cookie as the {{-c cookie}} command line option
349 in order to start the synchronization from a specific state.
350 The cookie is a comma separated list of name=value pairs. Currently
351 supported syncrepl cookie fields are {{csn=<csn>}}, {{sid=<sid>}}, and
352 {{rid=<rid>}}. {{<csn>}} represents the current synchronization state
353 of the consumer replica. {{<sid>}} is the identity of the per-scope
354 session log to which this consumer will be associated. {{<rid>}} identifies
355 a consumer replica locally within the consumer server. It is used to relate
356 the cookie to the syncrepl definition in {{slapd.conf}} (5) which has
357 the matching replica identifier.
358 Both {{<sid>}} and {{<rid>}} have no more than 3 decimal digits.
359 The command line cookie overrides the synchronization cookie
360 stored in the consumer replica database.