]> git.sur5r.net Git - openldap/blob - doc/guide/admin/proxycache.sdf
Initial proxy cache and syncrepl chapters
[openldap] / doc / guide / admin / proxycache.sdf
1 # $OpenLDAP$
2 # Copyright 2003, The OpenLDAP Foundation, All Rights Reserved.
3 # COPYING RESTRICTIONS APPLY, see COPYRIGHT.
4
5 H1: The Proxy Cache Engine
6
7 LDAP servers typically hold one or more subtrees of a DIT. Replica
8 (or shadow) servers hold shadow copies of entries held by one or
9 more master servers.  Changes are propagated from the master server
10 to replica (slave) servers using LDAP Sync or {{slurpd}}(8). An
11 LDAP cache is a special type of replica which holds entries
12 corresponding to search filters instead of subtrees.
13
14 H2: Overview
15
16 The proxy cache extension of slapd handles a search request (query)
17 by first determining whether it is contained in any cached search
18 filter. Contained requests are answered from the proxy cache's local
19 database.
20
21 E.g. {{EX:(shoesize>=9)}} is contained in {{EX:(shoesize>=8)}} and
22 {{EX:(sn=Richardson)}} is contained in {{EX:(sn=Richards*)}}
23
24 Correct matching rules and syntaxes are used while comparing
25 assertions for query containment. To simplify the query containment
26 problem, a list of cacheable "templates" (defined below) is specified
27 at configuration time. A query is cached or answered only if it
28 belongs to one of these templates. The entries corresponding to
29 cached queries are stored in the proxy cache local database while
30 its associated meta information (filter, scope, base, attributes)
31 is stored in main memory. Instead of sending a referral for requests
32 which are not contained, it acts as a proxy and obtains the result
33 by querying one or more target servers. The proxy cache extends the
34 meta backend and uses it to connect to target servers.
35
36 A template is a prototype for generating LDAP search requests.
37 Templates are described by a prototype search filter and a list of
38 attributes which are required in queries generated from the template.
39 The representation for prototype filter is similar to RFC 2254,
40 except that the assertion values are missing. Examples of prototype
41 filters are: (sn=),(&(sn=)(givenname=)) which are instantiated by
42 search filters (sn=Doe) and (&(sn=Doe)(givenname=John)) respectively.
43
44 The cache replacement policy removes the least recently used (LRU)
45 query and entries belonging to only that query. Queries are allowed
46 a maximum time to live (TTL) in the cache thus providing weak
47 consistency. A background thread periodically checks the cache for
48 expired queries and removes them.
49
50 The Proxy Cache paper
51 ({{URL:http://www.openldap.org/pub/kapurva/proxycaching.pdf}}) provides
52 design/implementation details.
53
54
55 H2: Proxy Cache Configuration
56
57 The cache configuration specific directives described below must
58 appear after the {{EX:"database meta"}} directive and before any other
59 {{EX:"database"}} declaration in {{slapd.conf}}(5).
60
61 H3: Setting cache parameters
62
63 >       cacheparams <lo_thresh> <hi_thresh> <numattrsets> <max_entries> <cc_period>
64
65 The directive enables proxy caching and sets general cache parameters.
66 Cache replacement is invoked when the cache size crosses the
67 <hi_thresh> bytes and continues till the cache size is greater than
68 <lo_thresh> bytes. Total number of attributes sets (as specified
69 by the attrset directive) is given by <numattrsets>. The entry
70 restriction for cacheable queries is specified by <max_entries>.
71 Consistency check is performed every <cc_period> duration (specified
72 in secs). In each cycle queries with expired TTLs are removed.
73
74 H3: Defining attribute sets
75
76 > attrset <index> <attrs...>
77
78 Used to associate a set of attributes to an index. Each attribute
79 set is associated with an index number from 0 to <numattrsets>-1.
80 These indices are used by the addtemplate directive to define
81 cacheable templates.
82
83 H3: Specifying cacheable templates 
84
85 > addtemplate <prototype_string> <attrset_index> <TTL>
86
87 Specifies a cacheable template and the "time to live" (in sec) <TTL>
88 for queries belonging to the template. A template is described by
89 its prototype filter string and set of required attributes identified
90 by <attrset_index>.
91
92 H3: Example
93
94 An example {{slapd.conf}}(5) for a caching server which proxies for
95 the backend server {{EX:ldap://server.mydomain.com}} and caches
96 queries with base object in the {{EX:"dc=example,dc=com"}} subtree
97 is described below,
98  
99 >       database        meta
100 >       suffix          "dc=example,dc=com" 
101 >       uri             ldap://server.mydomain.com/dc=example,dc=com
102 >       cacheparams     100000 150000 1 50 100
103 >       attrset 0 mail postaladdress telephonenumber 
104 >       addtemplate (sn=) 0 3600
105 >       addtemplate (&(sn=)(givenName=)) 0 3600
106 >       addtemplate (&(departmentNumber=)(secretary=*)) 0 3600
107     
108 A different name space is associated with the local cache database.
109 E.g if the local database suffix is {{EX:"dc=example,dc=com,cn=cache"}},
110 then following rewriting rules need to be defined to translate
111 between master and cache database naming contexts.
112
113 >       rewriteEngine   on
114 >       rewriteContext  cacheResult 
115 >       rewriteRule     "(.*)dc=example,dc=com" "%1dc=example,dc=com,cn=cache" ":"
116 >       rewriteContext  cacheBase
117 >       rewriteRule     "(.*)dc=example,dc=com" "%1dc=example,dc=com,cn=cache" ":"
118 >       rewriteContext  cacheReturn 
119 >       rewriteRule     "(.*)dc=example,dc=com,cn=cache" "%1dc=example,dc=com" ":"
120     
121 Finally, the local database for storing cached entries can be declared
122 as follows:
123  
124 >       database        ldbm
125 >       suffix          "dc=example,dc=com,cn=cache" 
126 >       #other database specific directives
127
128 The proxy cache database instance could be either {{TERM:BDB}} or
129 {{TERM:LDBM}}. A script for demonstrating the proxy cache
130 ({{FILE:test019-proxycaching}}) functionality is provided in the
131 tests/scripts directory of the distribution.
132
133