| | |
| | | import java.nio.channels.FileChannel; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.opends.server.backends.pluggable.Importer.IndexManager; |
| | | |
| | |
| | | private final ByteBuffer cache; |
| | | |
| | | /** Next fields are the fetched record data. */ |
| | | private Integer indexID; |
| | | private ImportRecord record; |
| | | private final ByteStringBuilder keyBuffer = new ByteStringBuilder(128); |
| | | private RecordState recordState = RecordState.START; |
| | | |
| | |
| | | */ |
| | | public Integer getIndexID() |
| | | { |
| | | if (indexID == null) |
| | | if (record == null) |
| | | { |
| | | try |
| | | { |
| | |
| | | throw new RuntimeException(ex); |
| | | } |
| | | } |
| | | return indexID; |
| | | return record != null ? record.getIndexID() : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | break; |
| | | } |
| | | |
| | | indexID = getInt(); |
| | | int indexID = getInt(); |
| | | ByteString key = toKey(); |
| | | record = ImportRecord.from(key, indexID); |
| | | |
| | | recordState = RecordState.NEED_INSERT_ID_SET; |
| | | } |
| | | |
| | | private ByteString toKey() throws IOException |
| | | { |
| | | ensureData(20); |
| | | int keyLen = getInt(); |
| | | ensureData(keyLen); |
| | | keyBuffer.clear().append(cache, keyLen); |
| | | |
| | | recordState = RecordState.NEED_INSERT_ID_SET; |
| | | return keyBuffer.toByteString(); |
| | | } |
| | | |
| | | private int getInt() throws IOException |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Compares this buffer with the provided key and index ID. |
| | | * |
| | | * @param key |
| | | * The key. |
| | | * @param indexID |
| | | * The index ID. |
| | | * @return true if this buffer represent the same key and indexID, false otherwise. |
| | | */ |
| | | boolean sameKeyAndIndexID(final ByteStringBuilder key, Integer indexID) |
| | | { |
| | | ensureRecordFetched(); |
| | | return Importer.indexComparator.compare(keyBuffer, key) == 0 |
| | | && this.indexID.equals(indexID); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int compareTo(IndexInputBuffer o) |
| | |
| | | return 0; |
| | | } |
| | | |
| | | ensureRecordFetched(); |
| | | o.ensureRecordFetched(); |
| | | |
| | | int cmp = Importer.indexComparator.compare(keyBuffer, o.keyBuffer); |
| | | int cmp = currentRecord().compareTo(o.currentRecord()); |
| | | if (cmp == 0) |
| | | { |
| | | cmp = indexID.intValue() - o.getIndexID().intValue(); |
| | | if (cmp == 0) |
| | | { |
| | | return bufferID - o.bufferID; |
| | | } |
| | | return bufferID - o.bufferID; |
| | | } |
| | | return cmp; |
| | | } |
| | | |
| | | ImportRecord currentRecord() |
| | | { |
| | | ensureRecordFetched(); |
| | | return record; |
| | | } |
| | | |
| | | private void ensureRecordFetched() |
| | | { |
| | | if (keyBuffer.length() == 0) |