mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
17.46.2013 cec016958f29b8849a1768e588e1d728d621af49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS
 */
package org.opends.server.replication.server.changelog.api;
 
import java.util.Map;
import java.util.Set;
 
import org.opends.server.config.ConfigException;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.protocol.UpdateMsg;
 
/**
 * The changelogDB stores the replication data on persistent storage.
 * <p>
 * This interface allows to:
 * <ul>
 * <li>set the storage directory and the purge interval</li>
 * <li>get access to the {@link ChangeNumberIndexDB}</li>
 * <li>query or control the replication domain database(s) (composed of one or
 * more ReplicaDBs)</li>
 * <li>query/update each ReplicaDB</li>
 * </ul>
 */
public interface ChangelogDB
{
 
  // DB control methods
 
  /**
   * Set the directory to be used by the replication database.
   *
   * @param dbDirName
   *          the directory for use by the replication database
   * @throws ConfigException
   *           if a problem occurs opening the directory
   */
  void setReplicationDBDirectory(String dbDirName) throws ConfigException;
 
  /**
   * Get the replication server database directory. This is used by tests to do
   * some cleanup.
   *
   * @return the database directory name
   */
  String getDBDirName();
 
  /**
   * Initializes the replication database.
   */
  void initializeDB();
 
  /**
   * Sets the purge delay for the replication database. This purge delay is a
   * best effort.
   *
   * @param delayInMillis
   *          the purge delay in milliseconds
   */
  void setPurgeDelay(long delayInMillis);
 
  /**
   * Shutdown the replication database.
   */
  void shutdownDB();
 
  /**
   * Returns a new {@link ChangeNumberIndexDB} object.
   *
   * @return a new {@link ChangeNumberIndexDB} object
   * @throws ChangelogException
   *           If a database problem happened
   */
  ChangeNumberIndexDB newChangeNumberIndexDB() throws ChangelogException;
 
  // Domain methods
 
  /**
   * Returns the serverIds for the servers that are or have been part of the
   * provided replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @return a set of integers holding the serverIds
   */
  Set<Integer> getDomainServerIds(String baseDn);
 
  /**
   * Get the number of changes for the specified replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @return the number of changes.
   */
  long getDomainChangesCount(String baseDn);
 
  /**
   * Returns the FIRST {@link CSN}s of each serverId for the specified
   * replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @return a {serverId => FIRST CSN} Map
   */
  Map<Integer, CSN> getDomainFirstCSNs(String baseDn);
 
  /**
   * Returns the LAST {@link CSN}s of each serverId for the specified
   * replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @return a {serverId => LAST CSN} Map
   */
  Map<Integer, CSN> getDomainLastCSNs(String baseDn);
 
  /**
   * Retrieves the latest trim date for the specified replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @return the domain latest trim date
   */
  long getDomainLatestTrimDate(String baseDn);
 
  /**
   * Shutdown the specified replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   */
  void shutdownDomain(String baseDn);
 
  /**
   * Clear DB and shutdown for the specified replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   */
  void clearDomain(String baseDn);
 
  // serverId methods
 
  /**
   * Return the number of changes between 2 provided {@link CSN}s for the
   * specified serverId and replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @param serverId
   *          the serverId on which to act
   * @param from
   *          The lower (older) CSN
   * @param to
   *          The upper (newer) CSN
   * @return The computed number of changes
   */
  long getCount(String baseDn, int serverId, CSN from, CSN to);
 
  /**
   * Returns the {@link CSN} situated immediately after the specified
   * {@link CSN} for the specified serverId and replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @param serverId
   *          the serverId for which we want the information
   * @param startAfterCSN
   *          The position where the iterator must start
   * @return a new ReplicationIterator that allows to browse the db managed by
   *         this dbHandler and starting at the position defined by a given CSN.
   */
  CSN getCSNAfter(String baseDn, int serverId, CSN startAfterCSN);
 
  /**
   * Generates a non empty {@link ReplicaDBCursor} for the specified serverId
   * and replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @param serverId
   *          the serverId on which to act
   * @param startAfterCSN
   *          The position where the iterator must start
   * @return a {@link ReplicaDBCursor} if the ReplicaDB is not empty, null
   *         otherwise
   */
  ReplicaDBCursor getCursorFrom(String baseDn, int serverId, CSN startAfterCSN);
 
  /**
   * for the specified serverId and replication domain.
   *
   * @param baseDn
   *          the replication domain baseDn
   * @param serverId
   *          the serverId on which to act
   * @param updateMsg
   *          the update message to publish to the replicaDB
   * @return true if a db had to be created to publish this message
   * @throws ChangelogException
   *           If a database problem happened
   */
  boolean publishUpdateMsg(String baseDn, int serverId, UpdateMsg updateMsg)
      throws ChangelogException;
 
}