001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2013-2014 ForgeRock AS
025 */
026package org.opends.server.replication.server.changelog.api;
027
028
029/**
030 * This class stores an index of all the changes seen by this server in the form
031 * of {@link ChangeNumberIndexRecord}s. The records are sorted by a global
032 * ordering as defined in the CSN class. The index links a
033 * <code>changeNumber</code> to the corresponding CSN. The CSN then links to a
034 * corresponding change in one of the ReplicaDBs.
035 *
036 * @see <a href=
037 * "https://wikis.forgerock.org/confluence/display/OPENDJ/OpenDJ+Domain+Names"
038 * >OpenDJ Domain Names</a> for more information about the changelog.
039 * @see <a href= "http://tools.ietf.org/html/draft-good-ldap-changelog-04"
040 * >OpenDJ Domain Names</a> for more information about the changeNumber.
041 */
042public interface ChangeNumberIndexDB
043{
044
045  /**
046   * Returns the last generated change number.
047   *
048   * @return the last generated change number
049   */
050  long getLastGeneratedChangeNumber();
051
052  /**
053   * Get the oldest record stored in this DB.
054   *
055   * @return Returns the oldest {@link ChangeNumberIndexRecord} in this DB, null
056   *         when the DB is empty or closed
057   * @throws ChangelogException
058   *           if a database problem occurs.
059   */
060  ChangeNumberIndexRecord getOldestRecord() throws ChangelogException;
061
062  /**
063   * Get the newest record stored in this DB.
064   *
065   * @return Returns the newest {@link ChangeNumberIndexRecord} in this DB, null
066   *         when the DB is empty or closed
067   * @throws ChangelogException
068   *           if a database problem occurs.
069   */
070  ChangeNumberIndexRecord getNewestRecord() throws ChangelogException;
071
072  /**
073   * Add an update to the list of messages that must be saved to this DB managed
074   * by this DB and return the changeNumber associated to this record.
075   * <p>
076   * Note: this method disregards the changeNumber in the provided record.
077   *
078   * @param record
079   *          The {@link ChangeNumberIndexRecord} to add to this DB.
080   * @return the change number associated to this record on adding to this DB
081   * @throws ChangelogException
082   *           if a database problem occurs.
083   */
084  long addRecord(ChangeNumberIndexRecord record) throws ChangelogException;
085
086  /**
087   * Generate a new {@link DBCursor} that allows to browse the db managed by
088   * this object and starting at the position defined by a given changeNumber.
089   *
090   * @param startChangeNumber
091   *          The position where the iterator must start.
092   * @return a new DBCursor that allows to browse this DB managed by
093   *         this object and starting at the position defined by a given
094   *         changeNumber.
095   * @throws ChangelogException
096   *           if a database problem occurs.
097   */
098  DBCursor<ChangeNumberIndexRecord> getCursorFrom(long startChangeNumber)
099      throws ChangelogException;
100
101}