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-2015 ForgeRock AS 025 */ 026package org.opends.server.replication.server.changelog.api; 027 028import org.opends.server.replication.common.CSN; 029import org.opends.server.types.DN; 030 031/** 032 * This class stores an index of all the changes seen by this server in the form 033 * of {@link ChangeNumberIndexRecord}s. The records are sorted by a global 034 * ordering as defined in the CSN class. The index links a 035 * <code>changeNumber</code> to the corresponding CSN. The CSN then links to a 036 * corresponding change in one of the ReplicaDBs. 037 * 038 * @see <a href= 039 * "https://wikis.forgerock.org/confluence/display/OPENDJ/OpenDJ+Domain+Names" 040 * >OpenDJ Domain Names</a> for more information about the changelog. 041 * @see <a href= "http://tools.ietf.org/html/draft-good-ldap-changelog-04" 042 * >OpenDJ Domain Names</a> for more information about the changeNumber. 043 */ 044public interface ChangeNumberIndexDB 045{ 046 047 /** 048 * Returns the last generated change number. 049 * 050 * @return the last generated change number 051 */ 052 long getLastGeneratedChangeNumber(); 053 054 /** 055 * Get the oldest record stored in this DB. 056 * 057 * @return Returns the oldest {@link ChangeNumberIndexRecord} in this DB, null 058 * when the DB is empty or closed 059 * @throws ChangelogException 060 * if a database problem occurs. 061 */ 062 ChangeNumberIndexRecord getOldestRecord() throws ChangelogException; 063 064 /** 065 * Get the newest record stored in this DB. 066 * 067 * @return Returns the newest {@link ChangeNumberIndexRecord} in this DB, null 068 * when the DB is empty or closed 069 * @throws ChangelogException 070 * if a database problem occurs. 071 */ 072 ChangeNumberIndexRecord getNewestRecord() throws ChangelogException; 073 074 /** 075 * Add an update to the list of messages that must be saved to this DB managed 076 * by this DB and return the changeNumber associated to this record. 077 * <p> 078 * Note: this method disregards the changeNumber in the provided record. 079 * 080 * @param record 081 * The {@link ChangeNumberIndexRecord} to add to this DB. 082 * @return the change number associated to this record on adding to this DB 083 * @throws ChangelogException 084 * if a database problem occurs. 085 */ 086 long addRecord(ChangeNumberIndexRecord record) throws ChangelogException; 087 088 /** 089 * Generate a new {@link DBCursor} that allows to browse the db managed by 090 * this object and starting at the position defined by a given changeNumber. 091 * 092 * @param startChangeNumber 093 * The position where the iterator must start. 094 * @return a new DBCursor that allows to browse this DB managed by 095 * this object and starting at the position defined by a given 096 * changeNumber. 097 * @throws ChangelogException 098 * if a database problem occurs. 099 */ 100 DBCursor<ChangeNumberIndexRecord> getCursorFrom(long startChangeNumber) 101 throws ChangelogException; 102 103 /** 104 * Resets ChangeNumber index to the given number and CSN. 105 * @param newFirstCN 106 * the new change number to appear as first change in the external changelog 107 * @param baseDN 108 * the new record for the first change 109 * @param newFirstCSN 110 * the CSN of the new first change 111 * @throws ChangelogException 112 * if an error occurs during reset 113 */ 114 void resetChangeNumberTo(long newFirstCN, DN baseDN, CSN newFirstCSN) throws ChangelogException; 115}