1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.mitosis.store;
21
22
23 import org.apache.directory.mitosis.common.CSN;
24 import org.apache.directory.mitosis.common.CSNVector;
25 import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
26 import org.apache.directory.mitosis.operation.Operation;
27 import org.apache.directory.server.core.DirectoryService;
28 import org.apache.directory.shared.ldap.name.LdapDN;
29
30 import javax.naming.Name;
31 import java.util.Set;
32 import java.util.UUID;
33
34 /**
35 * Provides an abstract storage that stores data required to perform
36 * replication, such as {@link UUID}-{@link LdapDN} mapping and
37 * LDAP {@link Operation}s. It also calculates the Update Vector (UV)
38 * and the Purge Vector (PV) of a replica.
39 *
40 * @author The Apache Directory Project (dev@directory.apache.org)
41 * @version $Rev$, $Date#
42 */
43 public interface ReplicationStore
44 {
45 /**
46 * Opens this storage.
47 */
48 void open( DirectoryService directoryService, ReplicationConfiguration cfg );
49
50
51 /**
52 * Closes this storage and releases the resources allocated when it's
53 * opened.
54 */
55 void close();
56
57
58 /**
59 * Returns the {@link ReplicaId} of the {@link ReplicaId} that this storage
60 * is associated with.
61 */
62 String getReplicaId();
63
64
65 /**
66 * Returns the set of {@link ReplicaId}s of the {@link ReplicaId}s that
67 * belongs to the same cluster.
68 */
69 Set<String> getKnownReplicaIds();
70
71
72 // UUID to DN table operations
73 /**
74 * Finds the {@link Name} of an entry with the specified {@link UUID}.
75 */
76 Name getDN( UUID uuid );
77
78
79 /**
80 * Associates the specified name and UUID so a user can
81 * find an entry's name from a UUID.
82 */
83 boolean putUUID( UUID uuid, Name dn );
84
85
86 /**
87 * Removed the specified UUID mapping from this storage.
88 * @return <tt>true</tt> if and only if the mapping has been removed
89 */
90 boolean removeUUID( UUID uuid );
91
92
93 // Log entry operations
94 /**
95 * Puts the specified operation into this storage.
96 */
97 void putLog( Operation operation );
98
99
100 /**
101 * Queries all operations that is greater than the specified {@link CSN}.
102 *
103 * @param inclusive <tt>true</tt> if you want to include <tt>fromCSN</tt>
104 * itself in the result set.
105 */
106 ReplicationLogIterator getLogs( CSN fromCSN, boolean inclusive );
107
108
109 /**
110 * Queries all operations that is greater than the specified
111 * {@link CSNVector}.
112 *
113 * @param inclusive <tt>true</tt> if you want to include
114 * <tt>updateVector</tt> itself in the result set.
115 */
116 ReplicationLogIterator getLogs( CSNVector updateVector, boolean inclusive );
117
118
119 /**
120 * Removes all operations that is less than the specified {@link CSN}.
121 *
122 * @param inclusive <tt>true</tt> if you want to delete the
123 * <tt>toCSN</tt> itself, too.
124 * @return the number of deleted {@link Operation}s
125 */
126 int removeLogs( CSN toCSN, boolean inclusive );
127
128
129 /**
130 * Returns the number of {@link Operation}s logged in this storage.
131 */
132 int getLogSize();
133
134
135 /**
136 * Returns the number of {@link Operation}s logged by
137 * the {@link ReplicaId} with the specified {@link ReplicaId}
138 * in this storage .
139 */
140 int getLogSize( String replicaId );
141
142
143 /**
144 * Calculates the Update Vector (UV) from this storage.
145 */
146 CSNVector getUpdateVector();
147
148
149 /**
150 * Calculates the Purge Vector (PV) from this storage.
151 */
152 CSNVector getPurgeVector();
153 }