| | |
| | | |
| | | // DB initialization |
| | | db = new DraftCNDB(dbenv); |
| | | firstChangeNumber = getChangeNumber(db.readFirstCNIndexData()); |
| | | lastChangeNumber = getChangeNumber(db.readLastCNIndexData()); |
| | | firstChangeNumber = getChangeNumber(db.readFirstRecord()); |
| | | lastChangeNumber = getChangeNumber(db.readLastRecord()); |
| | | |
| | | // Trimming thread |
| | | thread = new DirectoryThread(this, "Replication DraftCN db"); |
| | |
| | | DirectoryServer.registerMonitorProvider(dbMonitor); |
| | | } |
| | | |
| | | private long getChangeNumber(CNIndexData cnIndexData) |
| | | throws ChangelogException |
| | | private long getChangeNumber(CNIndexRecord record) throws ChangelogException |
| | | { |
| | | if (cnIndexData != null) |
| | | if (record != null) |
| | | { |
| | | return cnIndexData.getChangeNumber(); |
| | | return record.getChangeNumber(); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void add(CNIndexData cnIndexData) throws ChangelogException |
| | | public void addRecord(CNIndexRecord record) throws ChangelogException |
| | | { |
| | | db.addEntry(cnIndexData); |
| | | db.addRecord(record); |
| | | |
| | | if (debugEnabled()) |
| | | TRACER.debugInfo("In DraftCNDbhandler.add, added: " + cnIndexData); |
| | | TRACER.debugInfo("In DraftCNDbhandler.add, added: " + record); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CNIndexData getFirstCNIndexData() throws ChangelogException |
| | | public CNIndexRecord getFirstRecord() throws ChangelogException |
| | | { |
| | | return db.readFirstCNIndexData(); |
| | | return db.readFirstRecord(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CNIndexData getLastCNIndexData() throws ChangelogException |
| | | public CNIndexRecord getLastRecord() throws ChangelogException |
| | | { |
| | | return db.readLastCNIndexData(); |
| | | return db.readLastRecord(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public boolean isEmpty() throws ChangelogException |
| | | { |
| | | return getLastCNIndexData() == null; |
| | | return getLastRecord() == null; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | // From the draftCNDb change record, get the domain and CSN |
| | | final CNIndexData data = cursor.currentData(); |
| | | final String baseDN = data.getBaseDN(); |
| | | final CNIndexRecord record = cursor.currentRecord(); |
| | | final String baseDN = record.getBaseDN(); |
| | | if (baseDNToClear != null && baseDNToClear.equalsIgnoreCase(baseDN)) |
| | | { |
| | | cursor.delete(); |
| | |
| | | continue; |
| | | } |
| | | |
| | | final CSN csn = data.getCSN(); |
| | | final CSN csn = record.getCSN(); |
| | | final ServerState startState = domain.getStartState(); |
| | | final CSN fcsn = startState.getCSN(csn.getServerId()); |
| | | |
| | | final long currentChangeNumber = data.getChangeNumber(); |
| | | final long currentChangeNumber = record.getChangeNumber(); |
| | | |
| | | if (csn.older(fcsn)) |
| | | { |
| | |
| | | { |
| | | Map<String, ServerState> csnStartStates = |
| | | MultiDomainServerState.splitGenStateToServerStates( |
| | | data.getPreviousCookie()); |
| | | record.getPreviousCookie()); |
| | | csnVector = csnStartStates.get(baseDN); |
| | | |
| | | if (debugEnabled()) |
| | |
| | | |
| | | try |
| | | { |
| | | CNIndexData firstCNData = db.readFirstCNIndexData(); |
| | | String firstCN = String.valueOf(firstCNData.getChangeNumber()); |
| | | CNIndexRecord firstCNRecord = db.readFirstRecord(); |
| | | String firstCN = String.valueOf(firstCNRecord.getChangeNumber()); |
| | | attributes.add(Attributes.create("first-draft-changenumber", firstCN)); |
| | | } |
| | | catch (ChangelogException e) |
| | |
| | | |
| | | try |
| | | { |
| | | CNIndexData lastCNData = db.readLastCNIndexData(); |
| | | if (lastCNData != null) |
| | | CNIndexRecord lastCNRecord = db.readLastRecord(); |
| | | if (lastCNRecord != null) |
| | | { |
| | | String lastCN = String.valueOf(lastCNData.getChangeNumber()); |
| | | String lastCN = String.valueOf(lastCNRecord.getChangeNumber()); |
| | | attributes.add(Attributes.create("last-draft-changenumber", lastCN)); |
| | | } |
| | | } |
| | |
| | | public void clear() throws ChangelogException |
| | | { |
| | | db.clear(); |
| | | firstChangeNumber = getChangeNumber(db.readFirstCNIndexData()); |
| | | lastChangeNumber = getChangeNumber(db.readLastCNIndexData()); |
| | | firstChangeNumber = getChangeNumber(db.readFirstRecord()); |
| | | lastChangeNumber = getChangeNumber(db.readLastRecord()); |
| | | } |
| | | |
| | | private ReentrantLock lock = new ReentrantLock(); |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CNIndexData getCNIndexData(long changeNumber) |
| | | public CNIndexRecord getRecord(long changeNumber) |
| | | throws ChangelogException |
| | | { |
| | | DraftCNDBCursor cursor = null; |
| | | try |
| | | { |
| | | cursor = db.openReadCursor(changeNumber); |
| | | return cursor.currentData(); |
| | | return cursor.currentRecord(); |
| | | } |
| | | finally |
| | | { |