IndexInputBuffer.java revision f0a048d41a13eca4cba405da9403c2469ca3d1ea
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* The buffer class is used to process a buffer from the temporary index files
* during phase 2 processing.
*/
{
/** Possible states while reading a record. */
private static enum RecordState
{
}
static final long UNDEFINED_SIZE = -1;
private final IndexManager indexMgr;
private final FileChannel channel;
private final long begin;
private final long end;
private final int bufferID;
private long offset;
private final ByteBuffer cache;
/** Next fields are the fetched record data. */
/**
* Creates a new index input buffer.
*
* @param indexMgr
* The index manager.
* @param channel
* The index file channel.
* @param begin
* The position of the start of the buffer in the scratch file.
* @param end
* The position of the end of the buffer in the scratch file.
* @param bufferID
* The buffer ID.
* @param cacheSize
* The cache size.
* @throws IOException
* If an IO error occurred when priming the cache.
*/
{
this.offset = 0;
loadCache();
}
private void loadCache() throws IOException
{
long bytesToRead;
{
}
else
{
}
int bytesRead = 0;
while (bytesRead < bytesToRead)
{
}
}
/**
* Returns {@code true} if this buffer has more data.
*
* @return {@code true} if this buffer has more data.
* @throws IOException
* If an IO error occurred.
*/
public boolean hasMoreData() throws IOException
{
}
/**
* Returns the length of the next key.
*
* @return The length of the next key.
*/
public int getKeyLen()
{
}
/**
* Fetches the next key into the provided byte buffer.
*
* @param b
* A buffer where to fetch the key
*/
public void fetchKey(ByteBuffer b)
{
}
/**
* Returns the index ID of the next record.
*
* @return The index ID of the next record.
*/
public Integer getIndexID()
{
{
try
{
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
}
return indexID;
}
/**
* Reads the next record from the buffer, skipping any remaining data in the
* current record.
*
* @throws IOException
* If an IO error occurred.
*/
public void fetchNextRecord() throws IOException
{
switch (recordState)
{
case START:
// Nothing to skip.
break;
case NEED_INSERT_ID_SET:
// The previous record's ID sets were not read, so skip them both.
break;
case NEED_DELETE_ID_SET:
// The previous record's delete ID set was not read, so skip it.
break;
}
readKey();
}
private void readKey() throws IOException
{
ensureData(20);
{
}
}
private int getInt() throws IOException
{
ensureData(4);
}
/**
* Reads the next ID set from the record and merges it with the provided ID
* set.
*
* @param idSet
* The ID set to be merged.
* @throws IOException
* If an IO error occurred.
*/
{
{
throw new IllegalStateException();
}
ensureData(20);
p += len;
for (int k = 0; k < keyCount; k++)
{
if (ensureData(9))
{
}
p += len;
// idSet will be null if skipping.
{
if (entryID == UNDEFINED_SIZE)
{
}
else
{
}
}
}
switch (recordState)
{
case START:
throw new IllegalStateException();
case NEED_INSERT_ID_SET:
break;
case NEED_DELETE_ID_SET:
break;
}
}
{
{
loadCache();
return true;
}
{
loadCache();
return true;
}
return false;
}
/**
* Compares this buffer with the provided key and index ID.
*
* @param cKey
* The key.
* @param cIndexID
* The index ID.
* @return A negative number if this buffer is less than the provided key and
* index ID, a positive number if this buffer is greater, or zero if
* it is the same.
*/
{
int cmp = Importer.indexComparator.compare(keyBuf.array(), 0, keyBuf.limit(), cKey.array(), cKey.limit());
if (cmp == 0)
{
}
return 1;
}
/** {@inheritDoc} */
public int compareTo(IndexInputBuffer o)
{
// used in remove.
if (this == o)
{
return 0;
}
o.ensureRecordFetched();
if (cmp == 0)
{
if (cmp == 0)
{
}
}
return cmp;
}
private void ensureRecordFetched()
{
{
getIndexID();
}
}
}